Reputation: 99
I'm working on java web service clients nowadays. But I'm faced a big problem for me. My problem is that: I'm generated web service client with Eclipse via its web service client generator. It generates web service through Apache Axis2. My web service java code is generated and I use it successfully with a wsdl which isn't require security header. But I cannot use it with a web service which needs a security header.
I try to get my request with fiddler2. but fiddler not capture any packet related my request. but when I print my created request and use this xml with soapui, operation is successfully perform.
increasing timeout setting not work.
what can I do?
my xml and java error is given below:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" mustUnderstand="1">
<wsse:UsernameToken>
<wsse:Username>username</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">password</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
<wsse:ReplyTo xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:Address>http://www.w3.org/2005/08/addressing/anonymous</wsse:Address>
</wsse:ReplyTo>
<wsse:MessageID xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">urn:uuid:123</wsse:MessageID>
<wsse:Action xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" mustUnderstand="1">http://www.saglik.gov.tr/KPS/2011/KPSServices/TcKimlikNoIleKisiSorgula</wsse:Action>
</soapenv:Header>
<soapenv:Body>
<ns1:TcKimlikNoIleKisiSorgula xmlns:ns1="http://www.saglik.gov.tr/KPS/2011">
<ns1:tcNo>155***58</ns1:tcNo>
</ns1:TcKimlikNoIleKisiSorgula>
</soapenv:Body>
</soapenv:Envelope>
and error message:
[INFO] Unable to sendViaPost to url[https://kps.saglik.gov.tr/services/kpsservices.svc]
java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:150)
at java.net.SocketInputStream.read(SocketInputStream.java:121)
at sun.security.ssl.InputRecord.readFully(InputRecord.java:442)
at sun.security.ssl.InputRecord.read(InputRecord.java:480)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:927)
at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:884)
at sun.security.ssl.AppInputStream.read(AppInputStream.java:102)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
at java.io.BufferedInputStream.read(BufferedInputStream.java:254)
at org.apache.commons.httpclient.HttpParser.readRawLine(HttpParser.java:78)
at org.apache.commons.httpclient.HttpParser.readLine(HttpParser.java:106)
at org.apache.commons.httpclient.HttpConnection.readLine(HttpConnection.java:1116)
at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.readLine(MultiThreadedHttpConnectionManager.java:1413)
at org.apache.commons.httpclient.HttpMethodBase.readStatusLine(HttpMethodBase.java:1973)
at org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMethodBase.java:1735)
at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1098)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:398)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
at org.apache.axis2.transport.http.AbstractHTTPSender.executeMethod(AbstractHTTPSender.java:621)
at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:193)
at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:75)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:404)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:231)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:443)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:406)
at org.apache.axis2.description.OutInAxisOperationClient$NonBlockingInvocationWorker.run(OutInAxisOperation.java:446)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
and my code is below
public static void main(String[] args){
ServiceStub stub = new ServiceStub();
ServiceClient client = stub._getServiceClient();
client.addHeader(createSecurityHeader("username", "password"));
OMNamespaceImpl wsseNS = new OMNamespaceImpl(WSConstants.WSSE_NS, WSConstants.WSSE_PREFIX);
OMFactory factory = new SOAP11Factory();
OMElementImpl replyToElement;
OMElementImpl addressElement;
OMElementImpl messageIDElement; OMElementImpl actionElement;
replyToElement = new OMElementImpl("ReplyTo", wsseNS, factory);
addressElement = new OMElementImpl("Address", wsseNS, replyToElement, factory);
addressElement.setText("http://www.w3.org/2005/08/addressing/anonymous");
client.addHeader(replyToElement);
messageIDElement = new OMElementImpl("MessageID", wsseNS, factory);
messageIDElement.setText("urn:uuid:"+123);
client.addHeader(messageIDElement);
actionElement = new OMElementImpl("Action", wsseNS, factory);
actionElement.addAttribute("mustUnderstand", "1", null);
actionElement.setText("http://www.saglik.gov.tr/KPS/2011/KPSServices/TcKimlikNoIleKisiSorgula");
client.addHeader(actionElement);
Options options = client.getOptions();
options.setProperty(HTTPConstants.CHUNKED, "false");
options.setProperty(HTTPConstants.HTTP_PROTOCOL_VERSION, HTTPConstants.HEADER_PROTOCOL_11);
TcKimlikNoIleKisiSorgula kisi = new TcKimlikNoIleKisiSorgula();
kisi.setTcNo(155*****58L);//require an long
stub.starttcKimlikNoIleKisiSorgula(kisi, callback);
}
public static OMElement createSecurityHeader(String username, String password)
{
OMNamespaceImpl wsseNS = new OMNamespaceImpl(WSConstants.WSSE_NS, WSConstants.WSSE_PREFIX);
OMFactory factory = new SOAP11Factory();
OMElementImpl securityHeader;
OMElementImpl usernameTokenElement;
OMElementImpl usernameElement;
OMElementImpl passwordElement;
// create the Security header block
securityHeader = new OMElementImpl("Security", wsseNS, factory);
securityHeader.addAttribute("mustUnderstand", "1", null);
// nest the UsernameToken in the Security header
usernameTokenElement = new OMElementImpl(WSConstants.USERNAME_TOKEN_LN, wsseNS, securityHeader, factory);
// nest the Username and Password elements
usernameElement = new OMElementImpl(WSConstants.USERNAME_LN, wsseNS, usernameTokenElement, factory);
usernameElement.setText(username);
passwordElement = new OMElementImpl(WSConstants.PASSWORD_LN, wsseNS, usernameTokenElement, factory);
passwordElement.setText(password);
passwordElement.addAttribute(WSConstants.PASSWORD_TYPE_ATTR,
WSConstants.PASSWORD_TEXT, null);
return securityHeader;
}
Upvotes: 3
Views: 16983
Reputation: 4534
I faced the same problem (I'm using axis2 web-services on wso2 esb environment).
I overcome this problem by providing additional timeout configuration:
<parameter name="SO_TIMEOUT">some_integer_value</parameter>
<parameter name="CONNECTION_TIMEOUT">some_integer_value</parameter>
This could be also specified in Options
object:
options.setProperty(HTTPConstants.SO_TIMEOUT, new Integer(timeOutInMilliSeconds));
options.setProperty(HTTPConstants.CONNECTION_TIMEOUT, new Integer(timeOutInMilliSeconds));
I used value 60000 for timeout because my web-service was expected to perform several operations with DB.
Upvotes: 1