-
-
Save ajaysolleti/590dded2f565c1bdf85d to your computer and use it in GitHub Desktop.
Revisions
-
jeffbicca created this gist
Dec 2, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ import javax.xml.ws.Binding; import javax.xml.ws.BindingProvider; import javax.xml.ws.WebServiceRef; import javax.xml.ws.handler.Handler; public class WebServiceCaller implements Serializable { private static final int MINUTES = 60000; @WebServiceRef(wsdlLocation = "http://localhost/WebService.wsdl") WebService webService; public void callWebService(String userId, String ip) { Service port = captureAndConfigurePort(userId, ip); port.callMethod(); } private Service captureAndConfigurePort(String userId, String ip) { Service port = webService.getWebServicePort(); Binding binding = ((BindingProvider) port).getBinding(); List<Handler> handlerChain = binding.getHandlerChain(); handlerChain.add(new WebServiceHandler(userId, ip)); binding.setHandlerChain(handlerChain); Map<String, Object> requestContext = ((BindingProvider) port).getRequestContext(); requestContext.put("javax.xml.ws.client.receiveTimeout", 30 * MINUTES); return port; } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,50 @@ import javax.xml.soap.SOAPElement; import javax.xml.soap.SOAPEnvelope; import javax.xml.soap.SOAPException; import javax.xml.soap.SOAPHeader; import javax.xml.soap.SOAPMessage; import javax.xml.ws.handler.MessageContext; import javax.xml.ws.handler.soap.SOAPHandler; import javax.xml.ws.handler.soap.SOAPMessageContext; public class WebServiceHandler implements SOAPHandler<SOAPMessageContext> { private String userId; private String ip; public WebServiceRelatoriosHandler(String userId, String ip) { this.userId = userId; this.ip = ip; } public boolean handleMessage(SOAPMessageContext messageContext) { SOAPMessage msg = messageContext.getMessage(); if((Boolean) messageContext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY)) { try { SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope(); SOAPHeader header = envelope.addHeader(); SOAPElement el = header.addChildElement(envelope.createName("userId", "wshh", "http://mycompany.com.br/wsheaderhandlers")); el.setValue(userId); el = header.addChildElement(envelope.createName("ip", "wshh", "http://mycompany.com.br/wsheaderhandlers")); el.setValue(ip); msg.saveChanges(); } catch (SOAPException e) { return false; } } return true; } public boolean handleFault(SOAPMessageContext messageContext) { return true; } public void close(MessageContext messageContext) { } public Set getHeaders() { return new HashSet(); } }
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:via="http://mycompany.com.br/"> <soapenv:Header> <wshh:userId xmlns:wshh='http://mycompany.com.br/wsheaderhandlers'>12345</wshh:userId> <wshh:ip xmlns:wshh='http://mycompany.com.br/wsheaderhandlers'>10.10.10.10</wshh:ip> </soapenv:Header> <soapenv:Body> ... </soapenv:Body> </soapenv:Envelope>