Tomcat+Axis2 SSL实现

给WebService 添加SSL支持


 

1.Environment

  Eclipse 3.7

  Tomcat 6.0

  Axis2 war(1.5.×)


 

2.Tomcat 设置Axis2

http://chenhailong.iteye.com/admin/blogs/905865


 

3.tomcat设置SSL

 在tomcat目录找到conf目录下service.xml

添加下面:

   <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
               maxThreads="150" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS" />





 

4.在axis2 目录下找到web.xml

添加下面:

    <servlet>
        <servlet-name>AxisServlet</servlet-name>
        <display-name>Apache-Axis Servlet</display-name>
        <servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>AxisServlet</servlet-name>
        <url-pattern>/services/*</url-pattern>
    </servlet-mapping>





 

5.在axis2目录下conf目录找到axis2.xml

添加下面:

<transportReceiver name="http" class="org.apache.axis2.transport.http.AxisServletListener">
    <parameter name="port">8080</parameter>
</transportReceiver>

<transportReceiver name="https" class="org.apache.axis2.transport.http.AxisServletListener">
    <parameter name="port">8443</parameter>
</transportReceiver>




注意:8080 是默认的,8443也是默认的

相应的Port为service.xml下配置所定


 

6.通过java生成keystore for the tomcat

%JAVA_HOME%\bin\keytool -genkey -alias tomcat -keyalg RSA

默认密码:changeit


 

7.访问web服务

https://localhost:8443/axis2/services/×××××?wsdl


 

8.用Client端访问web服务

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.namespace.QName;
  
public class TestClient {
 public static void main(String [] args) {
  try {
    String endpoint = "https://localhost:8443/axis/services/××××?wsdl";
    System.setProperty("javax.net.ssl.trustStore", 
    "store目录");
    Service service = new Service();
    Call    call    = (Call) service.createCall();
    call.setTargetEndpointAddress( new java.net.URL(endpoint) );
    call.setOperationName(new QName("echoString"));

    String ret = (String) call.invoke( new Object[] { "Hello!" } );
    System.out.println("Sent 'Hello!', got '" + ret + "'");
  } catch (Exception e) {
    System.err.println(e.toString());
  }
 }
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值