SOAP AXIS2 with HTTPS

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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值