如何在OSGi容器中使用JAX-WS通过HTTPS发布Web服务?

时间:2011-06-30 09:34:07

标签: java web-services jax-ws osgi

使用Java,通过HTTPS使用Web服务很容易,但是如何发布一个?

标准的JAX-WS实现不支持它。我们尝试了Jetty,但是Jetty不支持基于HTTPS的Web服务(JettyHttpServerProvider的{​​{1}}抛出createHttpsServer())。我认为这个问题应该很简单。但不知怎的,我总是在墙上奔跑。

此外这必须与OSGi一起使用所以我更喜欢大多数或所有依赖项都可以作为捆绑包使用。目前我尝试运行CXF,但它有很多非OSGi依赖项,这使得部署非常困难。

我们还需要通过证书进行客户端身份验证,但我希望一旦启用HTTPS,这将相对容易。

为什么这么重要?例如,要为Jetty提供静态内容,您只需创建一个服务器,添加任何SSL连接器即可。为什么Web服务不那么容易?

2 个答案:

答案 0 :(得分:1)

如果您使用的是spring,则可以使用以下配置。这个article on FuseSource很好地解释了配置所需的步骤。

<beans xmlns="http://www.springframework.org/schema/beans" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xmlns:sec="http://cxf.apache.org/configuration/security" 
  xmlns:http="http://cxf.apache.org/transports/http/configuration" 
  xmlns:httpj="http://cxf.apache.org/transports/http-
jetty/configuration" 
  xmlns:jaxws="http://java.sun.com/xml/ns/jaxws" 
  xsi:schemaLocation=" 
       http://cxf.apache.org/configuration/security       http: 
//cxf.apache.org/schemas/configuration/security.xsd 
            http://cxf.apache.org/transports/http/configuration
            http://cxf.apache.org/schemas/configuration/http-conf.xsd
            http://cxf.apache.org/transports/http-jetty/configuration
            http://cxf.apache.org/schemas/configuration/http-jetty.xsd
            http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-
2.0.xsd"> 


  <http:destination name="{http://package}AnInterfacePort.http- 
destination"> 
  </http:destination> 

  <httpj:engine-factory bus="cxf"> 
   <httpj:engine port="9001"> 
    <httpj:tlsServerParameters> 
      <sec:keyManagers keyPassword="password"> 
           <sec:keyStore type="JKS" password="password" 
                file="C:/certs/cherry.jks"/> 
      </sec:keyManagers> 
      <sec:trustManagers> 
          <sec:keyStore type="JKS" password="password" 
               file="C:/certs/truststore.jks"/> 
      </sec:trustManagers> 
      <sec:cipherSuitesFilter> 
        <!-- these filters ensure that a ciphersuite with 
          export-suitable or null encryption is used, 
          but exclude anonymous Diffie-Hellman key change as 
          this is vulnerable to man-in-the-middle attacks --> 
        <sec:include>.*_EXPORT_.*</sec:include> 
        <sec:include>.*_EXPORT1024_.*</sec:include> 
        <sec:include>.*_WITH_DES_.*</sec:include> 
        <sec:include>.*_WITH_NULL_.*</sec:include> 
        <sec:exclude>.*_DH_anon_.*</sec:exclude> 
      </sec:cipherSuitesFilter> 
      <sec:clientAuthentication want="true" required="true"/> 
    </httpj:tlsServerParameters> 
   </httpj:engine> 
  </httpj:engine-factory> 


  <!-- We need a bean named "cxf" --> 
  <bean id="cxf" class="org.apache.cxf.bus.CXFBusImpl"/> 
</beans> 

答案 1 :(得分:1)

我们的系统在OSGi中使用cxf和jetty,它可以在HTTPS中正常工作。

将服务发布到WebService时,不应该关注它是HTTP还是HTTPS。通过将以下属性传递给OSGi来配置您的jetty以支持HTTPS:

org.eclipse.equinox.http.jetty.http.enabled=false
org.eclipse.equinox.http.jetty.https.enabled=true
org.eclipse.equinox.http.jetty.https.port=443
org.eclipse.equinox.http.jetty.ssl.keystore=...
org.eclipse.equinox.http.jetty.ssl.password=...

您可以查看

中的其他属性
org.eclipse.equinox.http.jetty_2.0.0.v20100503.jar\OSGI-INF\metatype\config.xml

通过这样做,您可以尝试使用IE通过https访问服务的wsdl。

相关问题