List of usage examples for javax.xml.soap SOAPConstants SOAP_1_2_PROTOCOL
String SOAP_1_2_PROTOCOL
To view the source code for javax.xml.soap SOAPConstants SOAP_1_2_PROTOCOL.
Click Source Link
From source file:org.soapfromhttp.service.CallSOAP.java
/** * Contruction dynamique de la requte SOAP * * @param pBody//from ww w .j av a2 s.c o m * @param method * @return SOAPMessage * @throws SOAPException * @throws IOException * @throws SAXException * @throws ParserConfigurationException */ private SOAPMessage createSOAPRequest(final String pBody, final String method) throws SOAPException, IOException, SAXException, ParserConfigurationException { // Prcise la version du protocole SOAP utiliser (ncessaire pour les appels de WS Externe) MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL); SOAPMessage soapMessage = messageFactory.createMessage(); MimeHeaders headers = soapMessage.getMimeHeaders(); // Prcise la mthode du WSDL interroger headers.addHeader("SOAPAction", method); // Encodage UTF-8 headers.addHeader("Content-Type", "text/xml;charset=UTF-8"); final SOAPBody soapBody = soapMessage.getSOAPBody(); // convert String into InputStream - traitement des caracres escaps > < ... (contraintes de l'affichage IHM) //InputStream is = new ByteArrayInputStream(HtmlUtils.htmlUnescape(pBody).getBytes()); InputStream is = new ByteArrayInputStream(pBody.getBytes()); DocumentBuilder builder = null; DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); // Important laisser sinon KO builderFactory.setNamespaceAware(true); try { builder = builderFactory.newDocumentBuilder(); Document document = builder.parse(is); soapBody.addDocument(document); } catch (ParserConfigurationException e) { MyLogger.log(CallSOAP.class.getName(), Level.ERROR, e.toString()); } finally { is.close(); if (builder != null) { builder.reset(); } } soapMessage.saveChanges(); return soapMessage; }
From source file:com.inbravo.scribe.rest.service.crm.ms.auth.SOAPExecutor.java
/** * Executes SOAP message/*w ww .ja v a2s . com*/ * * @param endpointUrl SOAP endpoint * @param request SOAP request * @return SOAP response message * @throws SOAPException in case of a SOAP issue * @throws IOException in case of an IO issue */ public final SOAPMessage execute(final String endpointUrl, final String request) throws Exception { if (logger.isDebugEnabled()) { logger.debug("----Inside execute endpointUrl: " + endpointUrl + " & request: " + request); } /* Create SOAP message */ final SOAPMessage message = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL) .createMessage(new MimeHeaders(), new ByteArrayInputStream(request.getBytes())); /* Execute the url */ return this.execute(endpointUrl, message); }
From source file:io.hummer.util.ws.WebServiceClient.java
public InvocationResult invoke(InvocationRequest request, int retries) throws Exception { Map<String, String> httpHeaders = extractHeaders(request.httpHeaders); int connectTimeoutMS = CONNECT_TIMEOUT_MS; int requestTimeoutMS = request.timeout ? READ_TIMEOUT_MS : READ_TIMEOUT_VERYLONG_MS; if (request.body != null) { if (request.type == RequestType.SOAP || request.type == RequestType.SOAP11) { try { return doInvokeSOAP((Element) request.getBodyAsElement(), request.soapHeaders, retries, SOAPConstants.SOAP_1_1_PROTOCOL, connectTimeoutMS, requestTimeoutMS); } catch (Exception e) { logger.debug("SOAP invocation failed: " + new ExceptionsUtil().getAllCauses(e)); throw e; }//from w w w . ja v a2 s. co m } if (request.type == RequestType.SOAP12) { try { return doInvokeSOAP((Element) request.getBodyAsElement(), request.soapHeaders, retries, SOAPConstants.SOAP_1_2_PROTOCOL, connectTimeoutMS, requestTimeoutMS); } catch (Exception e) { throw e; } } else if (request.type == RequestType.HTTP_GET) { requestTimeoutMS = request.timeout ? READ_TIMEOUT_HTTP_GET_MS : READ_TIMEOUT_HTTP_GET_VERYLONG_MS; if (logger.isDebugEnabled()) logger.debug("Request body: " + request.body); Object c = request.body; if (!(c instanceof String) && c != null) { logger.warn("Unexpected tyle " + c.getClass() + " of input body content: "); if (c instanceof Element) { xmlUtil.print((Element) c); } else { System.out.println(c); } } return doInvokeGET((String) c, httpHeaders, retries, connectTimeoutMS, requestTimeoutMS, request.cache); } else if (request.type == RequestType.HTTP_POST) return doInvokePOST(request.body, httpHeaders, retries); } else { requestTimeoutMS = request.timeout ? READ_TIMEOUT_HTTP_GET_MS : READ_TIMEOUT_HTTP_GET_VERYLONG_MS; return doInvokeGET("", httpHeaders, retries, connectTimeoutMS, requestTimeoutMS, request.cache); } return null; }
From source file:com.centurylink.mdw.hub.servlet.SoapServlet.java
/** * <p>//from w ww . ja v a 2 s. com * Gives a hint as to which version of SOAP using the rudimentary check * below. If the hint fails, it'll try the other version anyway. * </p> * <ul> * <li>SOAP 1.1 : http://schemas.xmlsoap.org/soap/envelope/</li> * <li>SOAP 1.2 : http://www.w3.org/2003/05/soap-envelope</li> * </ul> * <p> * This is on a per-request basis and can't be static since we need to * support SOAP 1.1 and 1.2 * </p> * * @param requestString * @param goodguess * @return SOAP version 1 or 2 * @throws IOException * @throws SOAPException */ private String getSoapVersion(String requestString, boolean goodguess) { String guessedVersion = SOAPConstants.SOAP_1_1_PROTOCOL; String otherVersion = SOAPConstants.SOAP_1_2_PROTOCOL; if (requestString.contains(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE)) { guessedVersion = SOAPConstants.SOAP_1_2_PROTOCOL; otherVersion = SOAPConstants.SOAP_1_1_PROTOCOL; } return goodguess ? guessedVersion : otherVersion; }
From source file:io.hummer.util.ws.WebServiceClient.java
private SOAPMessage createSOAPMessage(Element request, List<Element> headers, String protocol) throws Exception { MessageFactory mf = MessageFactory.newInstance(protocol); SOAPMessage message = mf.createMessage(); SOAPBody body = message.getSOAPBody(); // check if we have a complete soap:Envelope as request.. String ns = request.getNamespaceURI(); if (request.getTagName().contains("Envelope")) { if (ns.equals("http://schemas.xmlsoap.org/soap/envelope/")) message = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL).createMessage( new MimeHeaders(), new ByteArrayInputStream(xmlUtil.toString(request).getBytes())); if (ns.equals("http://www.w3.org/2003/05/soap-envelope")) message = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL).createMessage( new MimeHeaders(), new ByteArrayInputStream(xmlUtil.toString(request).getBytes())); } else {/* w w w . j a v a 2s. c o m*/ xmlUtil.appendChild(body, request); } for (Element h : headers) { xmlUtil.appendChild(message.getSOAPHeader(), h); } for (Element h : eprParamsAndProps) { xmlUtil.appendChild(message.getSOAPHeader(), h); } xmlUtil.appendChild(message.getSOAPHeader(), xmlUtil.toElement( "<wsa:To xmlns:wsa=\"" + EndpointReference.NS_WS_ADDRESSING + "\">" + endpointURL + "</wsa:To>")); message.saveChanges(); return message; }
From source file:com.centurylink.mdw.hub.servlet.SoapServlet.java
/** * Allow version specific factory passed in to support SOAP 1.1 and 1.2 * <b>Important</b> Faults are treated differently for 1.1 and 1.2 For 1.2 * you can't use the elementName otherwise it throws an exception * * @see http://docs.oracle.com/cd/E19159-01/819-3669/bnbip/index.html * * @param factory/*from ww w . ja v a2 s .c o m*/ * @param code * @param message * @return Xml fault string * @throws SOAPException * @throws TransformerException */ protected String createSoapFaultResponse(String soapVersion, String code, String message) throws SOAPException, TransformerException { SOAPMessage soapMessage = getSoapMessageFactory(soapVersion).createMessage(); SOAPBody soapBody = soapMessage.getSOAPBody(); /** * Faults are treated differently for 1.1 and 1.2 For 1.2 you can't use * the elementName otherwise it throws an exception * * @see http://docs.oracle.com/cd/E19159-01/819-3669/bnbip/index.html */ SOAPFault fault = null; if (soapVersion.equals(SOAPConstants.SOAP_1_1_PROTOCOL)) { // existing 1.1 functionality fault = soapBody.addFault(soapMessage.getSOAPHeader().getElementName(), message); if (code != null) fault.setFaultCode(code); } else if (soapVersion.equals(SOAPConstants.SOAP_1_2_PROTOCOL)) { /** * For 1.2 there are only a set number of allowed codes, so we can't * just use any one like what we did in 1.1. The recommended one to * use is SOAPConstants.SOAP_RECEIVER_FAULT */ fault = soapBody.addFault(SOAPConstants.SOAP_RECEIVER_FAULT, code == null ? message : code + " : " + message); } return DomHelper.toXml(soapMessage.getSOAPPart().getDocumentElement()); }
From source file:org.apache.axis2.saaj.SOAPFactoryTest.java
@Validated @Test/*from ww w .j a v a 2 s.c om*/ public void testCreateElement() { try { //SOAPFactory sf = SOAPFactory.newInstance(); SOAPFactory sf = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL); if (sf == null) { fail("createElementTest4() could not create SOAPFactory object"); } //Create QName object with localName=MyName1,prefix=MyPrefix1, uri=MyUri1 QName name = new QName("MyUri1", "MyName1", "MyPrefix1"); SOAPElement se = sf.createElement(name); assertNotNull(se); name = se.getElementQName(); String localName = name.getLocalPart(); String prefix = name.getPrefix(); String uri = name.getNamespaceURI(); if (localName == null) { fail("localName is null (expected MyName1)"); } else if (!localName.equals("MyName1")) { fail("localName is wrong (expected MyName1)"); } else if (prefix == null) { fail("prefix is null (expected MyPrefix1)"); } else if (!prefix.equals("MyPrefix1")) { fail("prefix is wrong (expected MyPrefix1)"); } else if (uri == null) { fail("uri is null (expected MyUri1)"); } else if (!uri.equals("MyUri1")) { fail("uri is wrong (expected MyUri1)"); } } catch (Exception e) { fail(); } }
From source file:org.apache.axis2.saaj.SOAPFactoryTest.java
@Validated @Test/*from www .ja va 2 s. co m*/ public void testCreateFault() { try { SOAPFactory factory = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL); //SOAPFactory factory = SOAPFactory.newInstance(); SOAPFault sf = factory.createFault("This is the fault reason.", SOAPConstants.SOAP_RECEIVER_FAULT); assertNotNull(sf); assertTrue(sf instanceof SOAPFault); QName fc = sf.getFaultCodeAsQName(); //Expect FaultCode="+SOAPConstants.SOAP_RECEIVER_FAULT Iterator i = sf.getFaultReasonTexts(); if (i == null) { log.info("Call to getFaultReasonTexts() returned null iterator"); } String reason = ""; while (i.hasNext()) { reason += (String) i.next(); } assertNotNull(reason); assertTrue(reason.indexOf("This is the fault reason.") > -1); assertTrue(fc.equals(SOAPConstants.SOAP_RECEIVER_FAULT)); } catch (SOAPException e) { fail("Caught unexpected SOAPException"); } }
From source file:org.apache.axis2.saaj.SOAPFactoryTest.java
/** for soap 1.1 */ @Validated/* w w w . j av a 2 s. c om*/ @Test public void testSOAPFaultException1() { try { SOAPFactory factory = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL); SOAPFault fault = factory.createFault("This is the fault reason.", new QName("http://MyNamespaceURI.org/", "My Fault Code")); } catch (UnsupportedOperationException e) { //Caught expected UnsupportedOperationException } catch (SOAPException e) { //Caught expected SOAPException } catch (IllegalArgumentException e) { //Caught expected IllegalArgumentException } catch (Exception e) { fail("Exception: " + e); } }
From source file:org.apache.axis2.saaj.SOAPFactoryTest.java
/** for soap 1.2 */ @Validated/* w w w.j a va 2s . co m*/ @Test public void testSOAPFaultException2() { try { SOAPFactory factory = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL); SOAPFault sf = factory.createFault("This is the fault reason.", new QName("http://MyNamespaceURI.org/", "My Fault Code")); fail("Did not throw expected SOAPException"); } catch (UnsupportedOperationException e) { //Caught expected UnsupportedOperationException } catch (SOAPException e) { //Caught expected SOAPException } catch (IllegalArgumentException e) { //Caught expected IllegalArgumentException } catch (Exception e) { fail("Exception: " + e); } }