`
sillycat
  • 浏览: 2477342 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

SOAP AXIS2 with HTTPS

    博客分类:
  • SOA
 
阅读更多
SOAP AXIS2 with HTTPS

1. sample configuration on tomcat7.0
server.xml

    <Connector port="443" protocol="HTTP/1.1" SSLEnabled="true"
               maxThreads="150" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS"
               keystoreFile="d:\tool\apache-tomcat-7.0.16\tomcat.jks"
               keystorePass="xxxxxx"/>

2. configuration in axis2.xml
    <transportSender name="https"
                     class="org.apache.axis2.transport.http.CommonsHTTPTransportSender">
        <parameter name="PROTOCOL">HTTP/1.1</parameter>
        <parameter name="Transfer-Encoding">chunked</parameter>
        <parameter name="port">443</parameter>
    </transportSender>

That is all for the server side.

3. Client side
We can call the https SOAP server with our client like this:
@Test
public void weatherService()
{
RPCServiceClient serviceClient = null;
       try
        {
        //http://www.httpdebugger.com/download.html
        String HTTPS_URL = "https://server/easyaxis/services/WeatherService";
        String HTTP_URL = "http://server:8080/easyaxis/services/WeatherService";
       
            serviceClient = new RPCServiceClient();
            Options options = serviceClient.getOptions();
            EndpointReference targetEPR = new EndpointReference(HTTP_URL);
            options.setTimeOutInMilliSeconds(1800000); // 10000 seconds
            options.setProperty(HTTPConstants.CHUNKED, Boolean.FALSE);
            options.setProperty(HTTPConstants.SO_TIMEOUT, 1800000);
            options.setProperty(HTTPConstants.CONNECTION_TIMEOUT, 1800000);
            options.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Boolean.TRUE);
            // client.getOptions().setProperty(HTTPConstants.AUTO_RELEASE_CONNECTION, Boolean.TRUE);
            options.setExceptionToBeThrownOnSOAPFault(true);
            options.setTo(targetEPR);
           
            //SSL
            System.setProperty("javax.net.ssl.trustStore","d:\\tool\\apache-tomcat-7.0.16\\tomcat.jks");
            System.setProperty("javax.net.ssl.trustStorePassword","D1gby!");
           
            // Setting the weather
            QName opSetWeather = new QName("http://services.weather.axis2.sillycat.com", "setWeather");
            Weather w = new Weather();
            w.setTemperature((float) 39.3);
            w.setForecast("Cloudy with showers");
            w.setRain(true);
            w.setHowMuchRain((float) 4.5);
            Object[] opSetWeatherArgs = new Object[] { w };

            serviceClient.invokeRobust(opSetWeather, opSetWeatherArgs);

            // Getting the weather
            QName opGetWeather = new QName("http://services.weather.axis2.sillycat.com", "getWeather");
            Object[] opGetWeatherArgs = new Object[] {};
            @SuppressWarnings("rawtypes")
Class[] returnTypes = new Class[] { Weather.class };
            Object[] response = serviceClient.invokeBlocking(opGetWeather, opGetWeatherArgs, returnTypes);

            Weather result = (Weather) response[0];

            if (result == null)
            {
                System.out.println("Weather didn't initialize!");
                return;
            }
            // Displaying the result
            System.out.println("Temperature               : " + result.getTemperature());
            System.out.println("Forecast                  : " + result.getForecast());
            System.out.println("Rain                      : " + result.isRain());
            System.out.println("How much rain (in inches) : " + result.getHowMuchRain());
        }
        catch (Exception e)
        {
            System.out.println("error:" + e);
        }
        finally
        {
            try
            {
                // clear up
                serviceClient.cleanupTransport();
            }
            catch (Exception e)
            {
                System.out.println("error:" + e);
            }
        }
    }

4. Moniters

First of all, we can use the HttpAnalyzer to watch the data, but it only work for the HTTP, not HTTPS.

Then I tried the SOAP monitor. That works.

references:
http://shivendra-tripathi.blogspot.com/2010/11/enabling-ssl-for-axis2-service-and.html
http://axis.apache.org/axis2/java/core/docs/http-transport.html#httpsupport
http://www.opensubscriber.com/message/axis-dev@ws.apache.org/8077606.html
http://techtidbitsbyshiv.blogspot.com/2010/11/axis2java-client-code-for-basic.html


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics