You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Ramesh Vishwanatham <rv...@dtcc.com> on 2008/12/03 22:15:39 UTC
Subject: AxisFault: Read timed out error with Custom Socket Factory
Hi All
I am getting "AxisFault: Read timed out error" when I override default
socket factory mechanism
mentined in one of Knowledge base article.
1) Behaviour of the client is, it pauses for sometime after the
handshakeCompleted is done and
generates exception. Below is output and exception trace:
[java] socket bound status=true
[java] socket connection status=true
[java] in handshakeCompleted method
[java] Exception in thread "main" org.apache.axis2.AxisFault: Read
timed out
[java] at
org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
[java] at
org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:193)
[java] at
org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:75)
[java] at
org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:371)
[java] at
org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:209)
[java] at
org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:448)
[java] at
org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:401)
[java] at
org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:228)
[java] at
org.apache.axis2.client.OperationClient.execute(OperationClient.java:163)
[java] at
tc.MyQuoteService2Stub.getPrice(MyQuoteService2Stub.java:183)
[java] at tc.MyNewClient.main(MyNewClient.java:59)
2) Below is the the client code:
public static void main(String [] args) throws Exception {
String url = "...";
String certFile = "...";
String password = "...";
SSLContext context =
MyKeyStoreUtil.loadCertificate(certFile,password);
MySSLSocketFactory sslFactory = new
MySSLSocketFactory(context);
Protocol myProtocolHandler = new Protocol("https",
sslFactory, 443);
MyQuoteService2Stub service = new
MyQuoteService2Stub(url);
Options opts = service._getServiceClient().getOptions();
opts.setProperty(HTTPConstants.CUSTOM_PROTOCOL_HANDLER,
myProtocolHandler);
MyQuoteService2Stub.GetPriceRequest request = new
MyQuoteService2Stub.GetPriceRequest();
String symbol = "ABC";
request.setSymbol(symbol);
MyQuoteService2Stub.GetPriceResponse response =
service.getPrice(request);
double value = response.getPrice();
System.out.println("price::" + value);
}
3) I have also written a client using HttpClient api and this program
works without any problems
and code is:
public static void main(String [] args) throws Exception {
String url = "...";
String certFile = "...";
String password = "...";
SSLContext context =
MyKeyStoreUtil.loadCertificate(certFile,password);
MySSLSocketFactory sslFactory = new
MySSLSocketFactory(context);
Protocol myProtocolHandler = new Protocol("https",
sslFactory, 443);
Protocol.registerProtocol("https",myProtocolHandler);
HttpClient httpclient = new HttpClient();
String soapFileName = "....";
File input = new File(soapFileName);
PostMethod post = new PostMethod(url);
RequestEntity entity = new FileRequestEntity(input,
"text/xml; charset=UTF-8");
post.setRequestEntity(entity);
post.setRequestHeader("SOAPAction", "getPrice");
int result = httpclient.executeMethod(post);
System.out.println("Response status code: " + result);
System.out.println("Response body: ");
System.out.println(post.getResponseBodyAsString());
}
4) Here is the implementation for MySSLSocketFactory:
public class MySSLSocketFactory implements ProtocolSocketFactory,
HandshakeCompletedListener {
public Socket
createSocket(String host, int port, InetAddress localAddress, int
localPort,
HttpConnectionParams params)
throws IOException, UnknownHostException,
ConnectTimeoutException {
SSLSocketFactory factory =
(SSLSocketFactory)context.getSocketFactory();
int timeout = params.getConnectionTimeout();
if(timeout == 0) {
return factory.createSocket(host, port,
localAddress,localPort);
}
else {
SSLSocket socket = (SSLSocket)
factory.createSocket();
SocketAddress localaddr = new
InetSocketAddress(localAddress,
localPort);
System.out.println("localaddr=" + localaddr);
SocketAddress remoteaddr = new
InetSocketAddress(host, port);
socket.bind(localaddr);
socket.connect(remoteaddr, timeout);
System.out.println("socket bound status=" +
socket.isBound());
System.out.println("socket connection status=" +
socket.isConnected());
socket.addHandshakeCompletedListener(this);
return socket;
}
}
public void handshakeCompleted(HandshakeCompletedEvent
handshakeCompletedEvent) {
System.out.println("in handshakeCompleted method");
}
// other methods follow
}
I have tested client with axis2 1.4.1. What I am missing and please help
me resolve this problem.
Thanks in advance
Ramesh
-----------------------------------------
________________________________________________________
DTCC DISCLAIMER: This email and any files transmitted with it are
confidential and intended solely for the use of the individual or
entity to whom they are addressed. If you have received this email
in error, please notify us immediately and delete the email and any
attachments from your system. The recipient should check this email
and any attachments for the presence of viruses. The company
accepts no liability for any damage caused by any virus transmitted
by this email.