List of usage examples for javax.xml.soap SOAPEnvelope getBody
public SOAPBody getBody() throws SOAPException;
From source file:org.apache.axis2.jaxws.message.util.impl.SAAJConverterImpl.java
private void _fixFaultElements(SOAPEnvelope env) { try {// ww w. j av a 2 s .com // If we have a SOAP 1.2 envelope, then there's nothing to do. if (env.getNamespaceURI().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI)) { return; } SOAPBody body = env.getBody(); if (body != null && !body.hasFault()) { if (log.isDebugEnabled()) { log.debug("No fault found. No conversion necessary."); } return; } else if (body != null && body.hasFault()) { if (log.isDebugEnabled()) { log.debug("A fault was found. Converting the fault child elements to SOAP 1.1 format"); } SOAPFault fault = body.getFault(); Iterator itr = fault.getChildElements(); while (itr.hasNext()) { SOAPElement se = (SOAPElement) itr.next(); if (se.getLocalName().equals(SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME)) { if (log.isDebugEnabled()) { log.debug("Converting: faultcode"); } // Axis2 SAAJ stores the acutal faultcode text under a SOAPFaultValue object, so we have to // get that and add it as a text node under the original element. Node value = se.getFirstChild(); if (value != null && value instanceof org.apache.axis2.saaj.SOAPElementImpl) { org.apache.axis2.saaj.SOAPElementImpl valueElement = (org.apache.axis2.saaj.SOAPElementImpl) value; ElementImpl e = valueElement.getElement(); String content = e.getText(); SOAPElement child = fault.addChildElement( new QName(se.getNamespaceURI(), SOAP11Constants.SOAP_FAULT_CODE_LOCAL_NAME)); child.addTextNode(content); se.detachNode(); } } else if (se.getLocalName().equals(SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME)) { if (log.isDebugEnabled()) { log.debug("Converting: detail"); } se.setElementQName( new QName(se.getNamespaceURI(), SOAP11Constants.SOAP_FAULT_DETAIL_LOCAL_NAME)); } else if (se.getLocalName().equals(SOAP12Constants.SOAP_FAULT_REASON_LOCAL_NAME)) { if (log.isDebugEnabled()) { log.debug("Converting: faultstring"); } se.setElementQName( new QName(se.getNamespaceURI(), SOAP11Constants.SOAP_FAULT_STRING_LOCAL_NAME)); // Axis2 SAAJ stores the acutal faultstring text under a SOAPFaultValue object, so we have to // get that and add it as a text node under the original element. Node value = se.getFirstChild(); if (value != null && value instanceof org.apache.axis2.saaj.SOAPElementImpl) { org.apache.axis2.saaj.SOAPElementImpl valueElement = (org.apache.axis2.saaj.SOAPElementImpl) value; ElementImpl e = valueElement.getElement(); String content = e.getText(); SOAPElement child = fault.addChildElement( new QName(se.getNamespaceURI(), SOAP11Constants.SOAP_FAULT_STRING_LOCAL_NAME)); child.addTextNode(content); se.detachNode(); } } } } } catch (SOAPException e) { if (log.isDebugEnabled()) { log.debug("An error occured while converting fault elements: " + e.getMessage()); } throw ExceptionFactory.makeWebServiceException(e); } }
From source file:org.energy_home.jemma.ah.internal.greenathome.GreenathomeAppliance.java
private static SOAPMessage createSOAPRequest(String date) throws Exception { MessageFactory messageFactory = MessageFactory.newInstance(); SOAPMessage soapMessage = messageFactory.createMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); String serverURI = "http://ws.i-em.eu/v4/"; // SOAP Envelope SOAPEnvelope envelope = soapPart.getEnvelope(); envelope.addNamespaceDeclaration("example", serverURI); // SOAP Body/*from w w w . ja va 2 s . c o m*/ SOAPBody soapBody = envelope.getBody(); SOAPElement soapBodyElem = soapBody.addChildElement("Get72hPlantForecast", "example"); SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("plantID", "example"); soapBodyElem1.addTextNode("telecom_02"); SOAPElement soapBodyElem2 = soapBodyElem.addChildElement("quantityID", "example"); soapBodyElem2.addTextNode("frc_pac"); SOAPElement soapBodyElem3 = soapBodyElem.addChildElement("timestamp", "example"); soapBodyElem3.addTextNode(date); SOAPElement soapBodyElem4 = soapBodyElem.addChildElement("langID", "example"); soapBodyElem4.addTextNode("en"); MimeHeaders headers = soapMessage.getMimeHeaders(); headers.addHeader("SOAPAction", serverURI + "Get72hPlantForecast"); soapMessage.saveChanges(); return soapMessage; }
From source file:org.jbpm.bpel.integration.server.SoapHandler.java
public boolean handleResponse(MessageContext messageContext) throws JAXRPCException { Map parts = (Map) messageContext.getProperty(MESSAGE_PARTS_PROP); SOAPFaultException faultException = (SOAPFaultException) messageContext.getProperty(FAULT_EXCEPTION_PROP); // absence of both parts and fault means one-way operation if (parts == null && faultException == null) return true; String operationName = (String) messageContext.getProperty(OPERATION_NAME_PROP); SOAPMessage soapMessage = ((SOAPMessageContext) messageContext).getMessage(); JbpmContext jbpmContext = integrationControl.getIntegrationServiceFactory().getJbpmConfiguration() .createJbpmContext();/*ww w.j a v a 2s. c om*/ try { lookupEndpointMetadata(messageContext); SOAPEnvelope envelope = soapMessage.getSOAPPart().getEnvelope(); // remove existing body, it might have undesirable content SOAPBody body = envelope.getBody(); body.detachNode(); // re-create body body = envelope.addBody(); if (faultException == null) writeOutput(operationName, soapMessage, parts); else { String faultName = (String) messageContext.getProperty(FAULT_NAME_PROP); writeFault(operationName, soapMessage, faultName, parts, faultException); } } /* * NO need to set jbpm context as rollback only for any exception, since operations in try-block * only read definitions from database */ catch (SOAPException e) { throw new JAXRPCException("could not compose outbound soap message", e); } finally { jbpmContext.close(); } return true; }
From source file:org.jbpm.bpel.integration.soap.SoapUtilTest.java
public void testCopyChildNodes_soapDom() throws Exception { String xml = "<lunch xmlns:produce='urn:example:produce'" + " xmlns='urn:example:meal'>" + " <time>1200</time>" + " <produce:lettuce>0.1lb</produce:lettuce>" + " <fish:fillet xmlns:fish='urn:example:fish'>0.25lb</fish:fillet>" + " <padding xmlns=''/>" + "</lunch>"; Element source = XmlUtil.parseText(xml); SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(); SOAPEnvelope envelope = soapMessage.getSOAPPart().getEnvelope(); SOAPElement target = envelope.getBody().addBodyElement(envelope.createName("detail")); // perform the copy SoapUtil.copyChildNodes(target, source); // qualified, prefixless element SOAPElement time = SoapUtil.getElement(target, "urn:example:meal", "time"); assertEquals(SoapUtil.DEFAULT_NAMESPACE_PREFIX, time.getPrefix()); // qualified, prefixed element SOAPElement lettuce = SoapUtil.getElement(target, "urn:example:produce", "lettuce"); assertEquals("produce", lettuce.getPrefix()); // parent qualified, prefixed element SOAPElement fillet = SoapUtil.getElement(target, "urn:example:fish", "fillet"); assertEquals("fish", fillet.getPrefix()); // local element SOAPElement padding = SoapUtil.getElement(target, "padding"); assertNull(padding.getPrefix());//from w w w. j a v a2 s .co m assertNull(padding.getNamespaceURI()); }
From source file:org.jbpm.bpel.integration.soap.SoapUtilTest.java
public void testCopyChildElement_domSoap() throws Exception { // <soap:Envelope xmlns:soap='${SOAPConstants.URI_NS_SOAP_ENVELOPE}'> // <soap:Body xmlns:fish='urn:example:fish'> // <meal:lunch xmlns:produce='urn:example:produce' // xmlns:meal='urn:example:meal'> // <padding /> // </meal:lunch> // </soap:Body> // </soap:Envelope> SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(); SOAPEnvelope envelope = soapMessage.getSOAPPart().getEnvelope(); SOAPBody body = envelope.getBody(); body.addNamespaceDeclaration("fish", "urn:example:fish"); Name lunchName = envelope.createName("lunch", "meal", "urn:example:meal"); SOAPElement lunch = body.addBodyElement(lunchName); lunch.addNamespaceDeclaration("produce", "urn:example:produce"); lunch.addNamespaceDeclaration("meal", "urn:example:meal"); SOAPElement source = SoapUtil.addChildElement(lunch, "padding"); Element parent = XmlUtil.createElement("urn:example:meal", "lunch"); // perform the copy SoapUtil.copyChildElement(parent, source); Element padding = XmlUtil.getElement(parent, "padding"); // unqualified element assertNull(padding.getPrefix());// www . jav a 2 s . com // reload // parent = writeAndRead(parent); padding = XmlUtil.getElement(parent, "padding"); // unqualified element assertNull(padding.getPrefix()); }
From source file:org.jbpm.bpel.integration.soap.SoapUtilTest.java
public void testCopy_soapDom_qualifiedNoPrefix() throws Exception { String xml = "<ReverseAndConcatNames xmlns='http://my.namespace'>" + " <firstName>Martin</firstName>" + " <secondName>Steinle</secondName>" + "</ReverseAndConcatNames>"; Element source = XmlUtil.parseText(xml); SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(); SOAPEnvelope envelope = soapMessage.getSOAPPart().getEnvelope(); SOAPElement target = envelope.getBody().addBodyElement(envelope.createName("detail")); // perform the copy SoapUtil.copy(target, source);//from w w w .j av a 2s . com assertEquals("http://my.namespace", target.getNamespaceURI(SoapUtil.DEFAULT_NAMESPACE_PREFIX)); // qualified elements SOAPElement firstName = SoapUtil.getElement(target, "http://my.namespace", "firstName"); assertEquals("Martin", firstName.getValue()); SOAPElement secondName = SoapUtil.getElement(target, "http://my.namespace", "secondName"); assertEquals("Steinle", secondName.getValue()); }
From source file:org.libreplan.importers.TimSoapClient.java
/** * Creates request message to be send to the SOAP server * * @param clazz//from w ww. ja va 2 s . com * object to be marshaled * @param userName * the user name * @param password * the password * @return the created soap message * @throws SOAPException * if unable to create message or envelope * @throws JAXBException * if unable to marshal the clazz */ private static <T> SOAPMessage createRequest(T clazz, String userName, String password) throws SOAPException, JAXBException { SOAPMessage message = createMessage(); addAuthorization(message, userName, password); SOAPEnvelope soapEnvelope = createEnvelope(message.getSOAPPart()); SOAPBody soapBody = soapEnvelope.getBody(); marshal(clazz, soapBody); message.saveChanges(); return message; }
From source file:org.mule.modules.paypal.util.PayPalAPIHelper.java
private static SOAPMessage createGetPalDetailsSOAPRequest(@NotNull String username, @NotNull String password, @NotNull String appId, String signature) throws Exception { MessageFactory messageFactory = MessageFactory.newInstance(); SOAPMessage soapMessage = messageFactory.createMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); // SOAP Envelope SOAPEnvelope envelope = soapPart.getEnvelope(); envelope.addNamespaceDeclaration(PREFIX_1, SOAP_HEADER_CREDENTIAL_NAMESPACE_1); envelope.addNamespaceDeclaration(PREFIX_2, SOAP_HEADER_CREDENTIAL_NAMESPACE_2); SOAPHeader soapHeader = envelope.getHeader(); if (soapHeader == null) soapHeader = envelope.addHeader(); SOAPElement soapReqElement = soapHeader.addChildElement(rootStringValue, PREFIX_1); SOAPElement soapCredElement = soapReqElement.addChildElement(subRootStringValue, PREFIX_2); soapCredElement.addChildElement(appIdStringValue, PREFIX_2).addTextNode(appId); soapCredElement.addChildElement(usernameStringValue, PREFIX_2).addTextNode(username); soapCredElement.addChildElement(passwordStringValue, PREFIX_2).addTextNode(password); soapCredElement.addChildElement("Signature", PREFIX_2).addTextNode(signature); // SOAP Body/* w w w . j a v a 2 s . co m*/ SOAPBody soapBody = envelope.getBody(); SOAPElement soapBodyElem = soapBody.addChildElement("GetPalDetailsReq", PREFIX_1); SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("GetPalDetailsRequest", PREFIX_1); soapBodyElem1.addChildElement("Version", PREFIX_2).addTextNode("51"); soapMessage.saveChanges(); return soapMessage; }
From source file:org.mule.transport.soap.axis.style.DefaultMessageService.java
public void soapRequestResponse(SOAPEnvelope req, SOAPEnvelope resp) throws SOAPException { // Echo back/* www.j a v a2s .c o m*/ logger.debug("envelopeTest Called"); SOAPBody body = resp.getBody(); Name ns0 = resp.createName("TestNS0", "ns0", "http://example.com"); Name ns1 = resp.createName("TestNS1", "ns1", "http://example.com"); SOAPElement bodyElmnt = body.addBodyElement(ns0); SOAPElement el = bodyElmnt.addChildElement(ns1); el.addTextNode("TEST RESPONSE"); }
From source file:org.openhab.binding.fritzboxtr064.internal.Tr064Comm.java
/** * Sets all required namespaces and prepares the SOAP message to send. * Creates skeleton + body data./*from w ww .j a v a 2s .co m*/ * * @param bodyData * is attached to skeleton to form entire SOAP message * @return ready to send SOAP message */ private SOAPMessage constructTr064Msg(SOAPBodyElement bodyData) { SOAPMessage soapMsg = null; try { MessageFactory msgFac; msgFac = MessageFactory.newInstance(); soapMsg = msgFac.createMessage(); soapMsg.setProperty(SOAPMessage.WRITE_XML_DECLARATION, "true"); soapMsg.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, "UTF-8"); SOAPPart part = soapMsg.getSOAPPart(); // valid for entire SOAP msg String namespace = "s"; // create suitable fbox envelope SOAPEnvelope envelope = part.getEnvelope(); envelope.setPrefix(namespace); envelope.removeNamespaceDeclaration("SOAP-ENV"); // delete standard namespace which was already set envelope.addNamespaceDeclaration(namespace, "http://schemas.xmlsoap.org/soap/envelope/"); Name nEncoding = envelope.createName("encodingStyle", namespace, "http://schemas.xmlsoap.org/soap/encoding/"); envelope.addAttribute(nEncoding, "http://schemas.xmlsoap.org/soap/encoding/"); // create empty header SOAPHeader header = envelope.getHeader(); header.setPrefix(namespace); // create body with command based on parameter SOAPBody body = envelope.getBody(); body.setPrefix(namespace); body.addChildElement(bodyData); // bodyData already prepared. Needs only be added } catch (Exception e) { logger.error("Error creating SOAP message for fbox request with data {}", bodyData); e.printStackTrace(); } return soapMsg; }