JAX-WS Web服务,使用HTTPS端点URL而不是HTTP的负载均衡器

时间:2013-03-23 20:27:37

标签: web-services java-ee tomcat jax-ws load-balancing

我们已经公开了部署在负载均衡器后面的Tomcat实例上的Web服务。 Load-Balancer仅允许HTTPS流量,但Jax-ws端点指向HTTP WSDL URL而不是HTTPS。当客户端访问Loadbalancer HTTPS URL时,它会被重定向到HTTP,并且由于流量是在LB上阻止的,因此当客户端无法访问时,客户端会收到错误。

sun-jaxws.xml或webservice注释中是否有任何配置指定告诉JAX-WS公开HTTPS网址而不是HTTP。

以下是我的配置:

sun-jaxws.xml:

<?xml version="1.0" encoding="UTF-8"?>
<endpoints
xmlns='http://java.sun.com/xml/ns/jax-ws/ri/runtime'
version='2.0'>
<endpoint
    name='/TestService'
    implementation='com.test.service.TestServiceImpl'
    url-pattern='/TestService' />    

Annotation Config On WebService Impl class:

@WebService(serviceName="TestServiceImpl",
portName="TestService",
endpointInterface = "com.test.service.TestService",
targetNamespace="http://test.com"
)
@HandlerChain(file = "handlers.xml")
@MTOM
@XmlAccessorType(XmlAccessType.PROPERTY)
public class TestServiceImpl implements TestService{
//Implementation
}

WebService End-Point, Please see the HTTPS protocol in Browser and HTTP in the WSDL location URL, I have removed the Service and url's due to security reasons

如果有人能指出我正确的方向,那就太好了。

请在不同情况下阅读“解决方案”

2 个答案:

答案 0 :(得分:2)

另一种方法是在Tomcat的“server.xml”文件

中添加这样的行
<Connector URIEncoding="UTF-8" port="8080" protocol="HTTP/1.1" 
    connectionTimeout="20000"  scheme="https" proxyPort="443"
    redirectPort="8443" />

在这种情况下,使用HTTP将LB指向端口8080。

当客户端使用HTTPS连接到LB到端口443时,这将起作用,LB使用HTTP连接到服务器到端口8080.在这种情况下,WSDL返回

<soap:address location="https://www.yoursite.com:443/...">

重要的事情有

方案:将此属性设置为您希望通过调用 request.getScheme()返回的协议的名称。例如,您可以为SSL设置此属性为“https”连接器。默认值为“http”。

proxyPort:如果在代理配置中使用此连接器,请配置此属性以指定为 request.getServerPort()的调用返回的服务器端口。

Jax-ws使用粗体的两种方法来构建soap:address。

感谢Chino帮助我们!

答案 1 :(得分:1)

我不建议这种方法 - 更好的选择是在负载均衡器上终止SSL通信并在负载均衡器和服务器之间使用普通HTTP(除非您还需要保护平衡器和服务器之间的流量,但是我对此表示怀疑)。也就是说,您不必在两个地方设置SSL,并且当某些内容无法正常工作时会出现双重问题。因此,首先尝试以这种方式配置负载均衡器。此外,您必须在WSDL中手动重写<soap:address location="..">标记(当然,添加HTTPS地址)并从本地存储的WSDL 生成WS客户端。

如果您仍想在Tomcat上设置SSL,那么您首先必须设置密钥库 - 密钥和证书的“数据库”。 Web上有很多教程如何做,一个是here。然后,您需要通过添加以下代码段来更改Tomcat的server.xml文件:

 <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
           maxThreads="150" scheme="https" secure="true"
           keystoreFile="<PATH-TO-KEYSTORE>" keystorePass="<YOUR-KEYSTORE-PASSWORD>"
           clientAuth="false" sslProtocol="TLS"/>

最后,您需要指定您的Web服务将所有HTTP请求重定向到HTTPS侦听器 - 但是在web.xml文件中,而不是在sun-jaxws.xml中:

<user-data-constraint>
    <transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>

重启Tomcat,应该这样做。