当前位置: 代码迷 >> Web前端 >> Tomcat+Axis2 SSL兑现
  详细解决方案

Tomcat+Axis2 SSL兑现

热度:278   发布时间:2012-10-08 19:54:56.0
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());
  }
 }
}



  相关解决方案