I'm using JBoss SwitchYard to connect to secured remote SOAP web service. For some reason after the request is sent; remote web service is stopping any further communication; so I'm not receiving a response.
I need an idea or solution what could be a problem here.
Caused by: java.net.SocketException: SocketException invoking https://**********.asmx: Unexpected end of file from server
java.net.SocketException: Unexpected end of file from server
This exception implies that server already accepted your connection, which means your SSL handshake is indeed succeed. But the server closed the connection (by a TCP reset or fin) before you can get the response.
A reset is usually sent in two cases:
Usually, a persistent connection has two config:
Keep-Alive: timeout=15, max=100
timeout
means time in seconds, max
means max requests.
Let's compare the three different cases you have described:
In the third case, if I understand you right, your persistent connection is from client to proxy and from proxy to server is not clear.
client----->Proxy----->server
java -Dhttp.keepalive=false
Issue might be due to invalid header or Invalid format of SOAP request, You can try like below code
1 You need HeaderHandlerResolver
public class HeaderHandlerResolver implements HandlerResolver {
public List<Handler> getHandlerChain(PortInfo portInfo) {
List<Handler> handlerChain = new ArrayList<Handler>();
HeaderHandler hh = new HeaderHandler();
handlerChain.add(hh);
return handlerChain;
}
}
Then You need to add on HeaderHandler class
public class HeaderHandler implements SOAPHandler<SOAPMessageContext> {
public boolean handleMessage(SOAPMessageContext smc) {
Boolean outboundProperty = (Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (outboundProperty.booleanValue()) {
SOAPMessage message = smc.getMessage();
try {
SOAPEnvelope envelope = smc.getMessage().getSOAPPart().getEnvelope();
SOAPHeader header = envelope.getHeader();
header.setPrefix("soapenv");
header.setAttribute("xmlns:wsa", "http://www.w3.org/2005/08/addressing");
SOAPElement security =
header.addChildElement("Security", "wsse", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
SOAPElement usernameToken =
security.addChildElement("UsernameToken", "wsse");
usernameToken.addAttribute(new QName("xmlns:wsu"), "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
SOAPElement username =
usernameToken.addChildElement("Username", "wsse");
username.addTextNode("USERNAME");
SOAPElement password =
usernameToken.addChildElement("Password", "wsse");
password.setAttribute("Type", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText");
password.addTextNode("PASSWORD");
SOAPElement encode =
usernameToken.addChildElement("Nonce", "wsse");
encode.setAttribute("EncodingType", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary");
encode.addTextNode(generateNonce());
Calendar createdTime = new GregorianCalendar(TimeZone.getTimeZone("IST"));
Date todayDate = createdTime.getTime();
todayDate.setTime(todayDate.getTime()-20000000);
SOAPElement created = usernameToken.addChildElement("Created", "wsu");
created.addTextNode(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.sss'Z'").format(todayDate));
SOAPElement action = header.addChildElement("Action", "wsa");
//YOUR ACTION URL SHOULD BE in BELOW Text Content
action.setTextContent("SET HERE YOUR ACTION URL");
message.saveChanges();
message.writeTo(System.out);
System.out.println("");
} catch (Exception e) {
e.printStackTrace();
}
} else {
try {
//This handler does nothing with the response from the Web Service so
//we just print out the SOAP message.
SOAPMessage message = smc.getMessage();
message.writeTo(System.out);
System.out.println("");
} catch (Exception ex) {
ex.printStackTrace();
}
}
return outboundProperty;
}
public Set getHeaders() {
return null;
}
public boolean handleFault(SOAPMessageContext context) {
return true;
}
public void close(MessageContext context) {
}
private static String generateNonce() throws NoSuchAlgorithmException, NoSuchProviderException, UnsupportedEncodingException {
String dateTimeString = Long.toString(new Date().getTime());
byte[] nonceByte = dateTimeString.getBytes();
return Base64.encodeBase64String(nonceByte);
}
}
Now Finally Your Main class for call SOAP service
public class SoapClientClass {
public static void main(String[] args) {
ImplService service = new ImplService();
HeaderHandlerResolver handlerResolver = new HeaderHandlerResolver();
service.setHandlerResolver(handlerResolver);
ResponseClass port = service.getPortClass();
Response response = null;
try {
response = port.getServerMehotd("Params");
} catch (PolicyException_Exception e) {
e.printStackTrace();
} catch (ServiceException_Exception e) {
e.printStackTrace();
}
}
}
}
Also, make sure your generated code from wsdl file uptodate and server location url also correct.
Hope its resolve your problem
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With