/** @testStrategy Tests conversions between SAAJ and OM SOAPEnvelopes */ public void test1() throws Exception { // Bootstrap: Create an OM SOAPEnvelope from the sample text StringReader sr = new StringReader(sampleEnvelope); XMLStreamReader inflow = inputFactory.createXMLStreamReader(sr); StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(inflow, null); org.apache.axiom.soap.SOAPEnvelope omEnvelope = builder.getSOAPEnvelope(); // Step 1: Get the SAAJConverter object from the Factory SAAJConverterFactory f = (SAAJConverterFactory) FactoryRegistry.getFactory(SAAJConverterFactory.class); SAAJConverter converter = f.getSAAJConverter(); // Step 2: Convert the OM SOAPEnvelope to an SAAJ SOAPEnvelope SOAPEnvelope saajEnvelope = converter.toSAAJ(omEnvelope); // Step 2a: Simple assertion check to ensure correctness. String name = saajEnvelope.getBody().getFirstChild().getLocalName(); assertTrue("a".equals(name)); // Step 3: Convert the SAAJ SOAPEnvelope to an OM SOAPEnvelope omEnvelope = converter.toOM(saajEnvelope); // Step 3a: Simple assertion check to ensure correctness name = omEnvelope.getBody().getFirstElement().getLocalName(); assertTrue("a".equals(name)); // Step 4: Rinse and repeat saajEnvelope = converter.toSAAJ(omEnvelope); name = saajEnvelope.getBody().getFirstChild().getLocalName(); assertTrue("a".equals(name)); omEnvelope = converter.toOM(saajEnvelope); name = omEnvelope.getBody().getFirstElement().getLocalName(); assertTrue("a".equals(name)); }
private SOAPEnvelope buildSoapEnvelope(String clientID, String value) { String targetEPR = "http://localhost:9000/soap/Service1"; String opration = "sampleOperation"; SOAPFactory soapFactory = OMAbstractFactory.getSOAP12Factory(); OMNamespace wsaNamespace = soapFactory.createOMNamespace("http://www.w3.org/2005/08/addressing", "wsa"); SOAPEnvelope envelope = soapFactory.createSOAPEnvelope(); SOAPHeader header = soapFactory.createSOAPHeader(); envelope.addChild(header); OMNamespace synNamespace = soapFactory.createOMNamespace("http://ws.apache.org/ns/synapse", "syn"); OMElement clientIDElement = soapFactory.createOMElement("ClientID", synNamespace); clientIDElement.setText(clientID); header.addChild(clientIDElement); SOAPBody body = soapFactory.createSOAPBody(); envelope.addChild(body); OMElement valueElement = soapFactory.createOMElement("Value", null); valueElement.setText(value); body.addChild(valueElement); return envelope; }
/** * Modify request body before sending to the end point. * * @param messageContext MessageContext - The message context. * @throws ConnectException if connection is failed. */ @SuppressWarnings("unchecked") public void connect(MessageContext messageContext) throws ConnectException { SOAPEnvelope envelope = messageContext.getEnvelope(); SOAPBody body = envelope.getBody(); Iterator<OMElement> nameValueListElements = body.getChildrenWithLocalName(SEARCH_BY_MODULE_TAG); try { OMElement nameValueListElement = nameValueListElements.next(); Iterator<OMElement> omElementIterator = nameValueListElement.getChildrenWithLocalName(MODULES_TAG); if (omElementIterator.hasNext()) { OMFactory omFactory = OMAbstractFactory.getOMFactory(); OMElement item = omElementIterator.next(); String moduleListString = (String) ConnectorUtils.lookupTemplateParamater(messageContext, MODULES_TAG); SugarCRMUtil.getItemElement(omFactory, messageContext, item, moduleListString); } } catch (Exception e) { log.error(SugarCRMUtil.EXCEPTION + SugarCRMUtil.getStackTraceAsString(e)); throw new ConnectException(e); } }
public void addIds( String strOperation, String strParamName, MessageContext synCtx, SynapseLog synLog) { SOAPEnvelope envelope = synCtx.getEnvelope(); OMFactory fac = OMAbstractFactory.getOMFactory(); SOAPBody body = envelope.getBody(); Iterator<OMElement> bodyChildElements = body.getChildrenWithLocalName(strOperation); if (bodyChildElements.hasNext()) { try { OMElement bodyElement = bodyChildElements.next(); Iterator<OMElement> cElements = bodyElement.getChildElements(); if (cElements != null && cElements.hasNext()) { cElements.next(); } String strSobject = (String) ConnectorUtils.lookupTemplateParamater(synCtx, strParamName); OMElement sObjects = AXIOMUtil.stringToOM(strSobject); Iterator<OMElement> sObject = sObjects.getChildElements(); OMNamespace omNsurn = fac.createOMNamespace("urn:partner.soap.sforce.com", "urn"); // Loops sObject while (sObject.hasNext()) { OMElement currentElement = sObject.next(); OMElement newElement = fac.createOMElement("ids", omNsurn); // Add the fields newElement.addChild(fac.createOMText(currentElement.getText())); bodyElement.addChild(newElement); } } catch (Exception e) { synLog.error("Saleforce adaptor - error injecting sObjects to payload : " + e); } } }
/** * Converts a given {@link Document} to an AXIOM {@link org.apache.axiom.soap.SOAPEnvelope}. * * @param document the document to be converted * @return the converted envelope * @throws IllegalArgumentException in case of errors * @see org.apache.rampart.util.Axis2Util.getSOAPEnvelopeFromDOMDocument(Document, boolean) */ public static SOAPEnvelope toEnvelope(Document document) { try { DOMImplementation implementation = document.getImplementation(); Assert.isInstanceOf(DOMImplementationLS.class, implementation); DOMImplementationLS loadSaveImplementation = (DOMImplementationLS) implementation; LSOutput output = loadSaveImplementation.createLSOutput(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); output.setByteStream(bos); LSSerializer serializer = loadSaveImplementation.createLSSerializer(); serializer.write(document, output); ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); XMLInputFactory inputFactory = StAXUtils.getXMLInputFactory(); StAXSOAPModelBuilder stAXSOAPModelBuilder = new StAXSOAPModelBuilder(inputFactory.createXMLStreamReader(bis), null); SOAPEnvelope envelope = stAXSOAPModelBuilder.getSOAPEnvelope(); // Necessary to build a correct Axiom tree, see SWS-483 envelope.serialize(new NullOutputStream()); return envelope; } catch (Exception ex) { IllegalArgumentException iaex = new IllegalArgumentException("Error in converting Document to SOAP Envelope"); iaex.initCause(ex); throw iaex; } }
/** * Invokes the bussiness logic invocation on the service implementation class * * @param msgContext the incoming message context * @param newmsgContext the response message context * @throws AxisFault on invalid method (wrong signature) or behaviour (return null) */ public void invokeBusinessLogic(MessageContext msgContext, MessageContext newmsgContext) throws AxisFault { try { // get the implementation class for the Web Service Object obj = getTheImplementationObject(msgContext); // find the WebService method Class implClass = obj.getClass(); AxisOperation opDesc = msgContext.getAxisOperation(); Method method = findOperation(opDesc, implClass); if (method == null) { throw new AxisFault( Messages.getMessage("methodDoesNotExistInOut", opDesc.getName().toString())); } OMElement result = (OMElement) method.invoke( obj, new Object[] {msgContext.getEnvelope().getBody().getFirstElement()}); SOAPFactory fac = getSOAPFactory(msgContext); SOAPEnvelope envelope = fac.getDefaultEnvelope(); if (result != null) { envelope.getBody().addChild(result); } newmsgContext.setEnvelope(envelope); } catch (Exception e) { throw AxisFault.makeFault(e); } }
public static String sendSOAP( EndpointReference soapEPR, String requestString, String action, String operation) throws Exception { ServiceClient sender = PmServiceClient.getServiceClient(); OperationClient operationClient = sender.createClient(ServiceClient.ANON_OUT_IN_OP); // creating message context MessageContext outMsgCtx = new MessageContext(); // assigning message context's option object into instance variable Options opts = outMsgCtx.getOptions(); // setting properties into option log.debug(soapEPR); opts.setTo(soapEPR); opts.setAction(action); opts.setTimeOutInMilliSeconds(180000); log.debug(requestString); SOAPEnvelope envelope = null; try { SOAPFactory fac = OMAbstractFactory.getSOAP11Factory(); envelope = fac.getDefaultEnvelope(); OMNamespace omNs = fac.createOMNamespace( "http://rpdr.partners.org/", //$NON-NLS-1$ "rpdr"); //$NON-NLS-1$ // creating the SOAP payload OMElement method = fac.createOMElement(operation, omNs); OMElement value = fac.createOMElement("RequestXmlString", omNs); // $NON-NLS-1$ value.setText(requestString); method.addChild(value); envelope.getBody().addChild(method); } catch (FactoryConfigurationError e) { log.error(e.getMessage()); throw new Exception(e); } outMsgCtx.setEnvelope(envelope); operationClient.addMessageContext(outMsgCtx); operationClient.execute(true); MessageContext inMsgtCtx = operationClient.getMessageContext("In"); // $NON-NLS-1$ SOAPEnvelope responseEnv = inMsgtCtx.getEnvelope(); OMElement soapResponse = responseEnv.getBody().getFirstElement(); // System.out.println("Sresponse: "+ soapResponse.toString()); OMElement soapResult = soapResponse.getFirstElement(); // System.out.println("Sresult: "+ soapResult.toString()); String i2b2Response = soapResult.getText(); log.debug(i2b2Response); return i2b2Response; }
public static MessageContext sendUsingSwA(String fileName, String targetEPR) throws IOException { Options options = new Options(); options.setTo(new EndpointReference(targetEPR)); options.setAction("urn:uploadFileUsingSwA"); options.setProperty(Constants.Configuration.ENABLE_SWA, Constants.VALUE_TRUE); ServiceClient sender = new ServiceClient(); sender.setOptions(options); OperationClient mepClient = sender.createClient(ServiceClient.ANON_OUT_IN_OP); MessageContext mc = new MessageContext(); System.out.println("Sending file : " + fileName + " as SwA"); FileDataSource fileDataSource = new FileDataSource(new File(fileName)); DataHandler dataHandler = new DataHandler(fileDataSource); String attachmentID = mc.addAttachment(dataHandler); SOAPFactory factory = OMAbstractFactory.getSOAP11Factory(); SOAPEnvelope env = factory.getDefaultEnvelope(); OMNamespace ns = factory.createOMNamespace("http://services.samples/xsd", "m0"); OMElement payload = factory.createOMElement("uploadFileUsingSwA", ns); OMElement request = factory.createOMElement("request", ns); OMElement imageId = factory.createOMElement("imageId", ns); imageId.setText(attachmentID); request.addChild(imageId); payload.addChild(request); env.getBody().addChild(payload); mc.setEnvelope(env); mepClient.addMessageContext(mc); mepClient.execute(true); MessageContext response = mepClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE); SOAPBody body = response.getEnvelope().getBody(); String imageContentId = body.getFirstChildWithName( new QName("http://services.samples/xsd", "uploadFileUsingSwAResponse")) .getFirstChildWithName(new QName("http://services.samples/xsd", "response")) .getFirstChildWithName(new QName("http://services.samples/xsd", "imageId")) .getText(); Attachments attachment = response.getAttachmentMap(); dataHandler = attachment.getDataHandler(imageContentId); File tempFile = File.createTempFile("swa-", ".gif"); FileOutputStream fos = new FileOutputStream(tempFile); dataHandler.writeTo(fos); fos.flush(); fos.close(); System.out.println("Saved response to file : " + tempFile.getAbsolutePath()); return response; }
public void addSobjects( String strOperation, String strParamName, MessageContext synCtx, SynapseLog synLog, String strExternalId) { SOAPEnvelope envelope = synCtx.getEnvelope(); OMFactory fac = OMAbstractFactory.getOMFactory(); SOAPBody body = envelope.getBody(); Iterator<OMElement> bodyChildElements = body.getChildrenWithLocalName(strOperation); if (bodyChildElements.hasNext()) { try { OMElement bodyElement = bodyChildElements.next(); if (strExternalId != null) { OMNamespace omNs = fac.createOMNamespace("urn:partner.soap.sforce.com", "urn"); OMElement value = fac.createOMElement("externalIDFieldName", omNs); value.addChild(fac.createOMText(strExternalId)); bodyElement.addChild(value); } String strSobject = (String) ConnectorUtils.lookupTemplateParamater(synCtx, strParamName); OMElement sObjects = AXIOMUtil.stringToOM(strSobject); Iterator<OMElement> sObject = sObjects.getChildElements(); String strType = sObjects.getAttributeValue(new QName(SalesforceUtil.SALESFORCE_CREATE_SOBJECTTYPE)); OMElement tmpElement = null; OMNamespace omNsurn = fac.createOMNamespace("urn:partner.soap.sforce.com", "urn"); OMNamespace omNsurn1 = fac.createOMNamespace("urn:sobject.partner.soap.sforce.com", "urn1"); // Loops sObject while (sObject.hasNext()) { OMElement currentElement = sObject.next(); OMElement newElement = fac.createOMElement("sObjects", omNsurn); // Add Object type if (strType != null) { tmpElement = fac.createOMElement("type", omNsurn1); tmpElement.addChild(fac.createOMText(strType)); newElement.addChild(tmpElement); } // Add the fields Iterator<OMElement> sObjectFields = currentElement.getChildElements(); while (sObjectFields.hasNext()) { OMElement sObjectField = sObjectFields.next(); tmpElement = fac.createOMElement(sObjectField.getLocalName(), omNsurn1); tmpElement.addChild(fac.createOMText(sObjectField.getText())); newElement.addChild(tmpElement); } bodyElement.addChild(newElement); } } catch (Exception e) { synLog.error("Saleforce adaptor - error injecting sObjects to payload : " + e); } } }
public static void transferFile(File file, String destinationFile) throws Exception { Options options = new Options(); options.setTo(targetEPR); options.setProperty(Constants.Configuration.ENABLE_SWA, Constants.VALUE_TRUE); options.setSoapVersionURI(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI); // Increase the time out when sending large attachments options.setTimeOutInMilliSeconds(10000); options.setTo(targetEPR); options.setAction("urn:uploadFile"); // assume the use runs this sample at // <axis2home>/samples/soapwithattachments/ dir ConfigurationContext configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem( "../../repository", null); ServiceClient sender = new ServiceClient(configContext, null); sender.setOptions(options); OperationClient mepClient = sender.createClient(ServiceClient.ANON_OUT_IN_OP); MessageContext mc = new MessageContext(); FileDataSource fileDataSource = new FileDataSource(file); // Create a dataHandler using the fileDataSource. Any implementation of // javax.activation.DataSource interface can fit here. DataHandler dataHandler = new DataHandler(fileDataSource); String attachmentID = mc.addAttachment(dataHandler); SOAPFactory fac = OMAbstractFactory.getSOAP11Factory(); SOAPEnvelope env = fac.getDefaultEnvelope(); OMNamespace omNs = fac.createOMNamespace("http://service.soapwithattachments.sample", "swa"); OMElement uploadFile = fac.createOMElement("uploadFile", omNs); OMElement nameEle = fac.createOMElement("name", omNs); nameEle.setText(destinationFile); OMElement idEle = fac.createOMElement("attchmentID", omNs); idEle.setText(attachmentID); uploadFile.addChild(nameEle); uploadFile.addChild(idEle); env.getBody().addChild(uploadFile); mc.setEnvelope(env); mepClient.addMessageContext(mc); mepClient.execute(true); MessageContext response = mepClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE); SOAPBody body = response.getEnvelope().getBody(); OMElement element = body.getFirstElement() .getFirstChildWithName( new QName("http://service.soapwithattachments.sample", "return")); System.out.println(element.getText()); }
public static SynapseMessageContext createLightweightSynapseMessageContext(String payload) throws Exception { MessageContext mc = new OldMessageContext(); SynapseConfiguration config = new SynapseConfiguration(); SynapseEnvironment env = new Axis2SynapseEnvironment(config); SynapseMessageContext synMc = Axis2SynapseMessageContextImpl.newInstance(mc, config, env); SOAPEnvelope envelope = OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope(); OMDocument omDoc = OMAbstractFactory.getSOAP11Factory().createOMDocument(); omDoc.addChild(envelope); envelope.getBody().addChild(createOMElement(payload)); synMc.setEnvelope(envelope); return synMc; }
public static OMElement getOMElement(SOAPEnvelope response) { XMLStreamReader parser = response.getXMLStreamReader(); StAXOMBuilder builder = new StAXOMBuilder(OMAbstractFactory.getOMFactory(), parser); return builder.getDocumentElement(); }
private org.apache.axiom.soap.SOAPEnvelope toEnvelope( org.apache.axiom.soap.SOAPFactory factory, com.pa.GetEmp param, boolean optimizeContent, javax.xml.namespace.QName methodQName) throws org.apache.axis2.AxisFault { try { org.apache.axiom.soap.SOAPEnvelope emptyEnvelope = factory.getDefaultEnvelope(); emptyEnvelope.getBody().addChild(param.getOMElement(com.pa.GetEmp.MY_QNAME, factory)); return emptyEnvelope; } catch (org.apache.axis2.databinding.ADBException e) { throw org.apache.axis2.AxisFault.makeFault(e); } }
public void testEmptyBodiedMessage() throws OMException, Exception { soapEnvelope = (SOAPEnvelope) OMTestUtils.getOMBuilder(getTestResource(TestConstants.EMPTY_BODY_MESSAGE)) .getDocumentElement(); OMTestUtils.walkThrough(soapEnvelope); soapEnvelope.close(false); }
public void testReallyBigMessage() throws OMException, Exception { soapEnvelope = (SOAPEnvelope) OMTestUtils.getOMBuilder(getTestResource(TestConstants.REALLY_BIG_MESSAGE)) .getDocumentElement(); OMTestUtils.walkThrough(soapEnvelope); soapEnvelope.close(false); }
private org.apache.axiom.soap.SOAPEnvelope toEnvelope( org.apache.axiom.soap.SOAPFactory factory, org.example.www.site.GetSiteResponse param, boolean optimizeContent) throws org.apache.axis2.AxisFault { try { org.apache.axiom.soap.SOAPEnvelope emptyEnvelope = factory.getDefaultEnvelope(); emptyEnvelope .getBody() .addChild(param.getOMElement(org.example.www.site.GetSiteResponse.MY_QNAME, factory)); return emptyEnvelope; } catch (org.apache.axis2.databinding.ADBException e) { throw org.apache.axis2.AxisFault.makeFault(e); } }
public void testMessageWithLotOfWhiteSpaces() throws OMException, Exception { soapEnvelope = (SOAPEnvelope) OMTestUtils.getOMBuilder(getTestResource(TestConstants.WHITESPACE_MESSAGE)) .getDocumentElement(); OMTestUtils.walkThrough(soapEnvelope); soapEnvelope.close(false); }
private void createAndSendSOAPResponse( Map<String, Object> serviceResults, String serviceName, HttpServletResponse response) throws EventHandlerException { try { // setup the response Debug.logVerbose("[EventHandler] : Setting up response message", module); String xmlResults = SoapSerializer.serialize(serviceResults); // Debug.logInfo("xmlResults ==================" + xmlResults, module); XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(xmlResults)); StAXOMBuilder resultsBuilder = new StAXOMBuilder(reader); OMElement resultSer = resultsBuilder.getDocumentElement(); // create the response soap SOAPFactory factory = OMAbstractFactory.getSOAP11Factory(); SOAPEnvelope resEnv = factory.createSOAPEnvelope(); SOAPBody resBody = factory.createSOAPBody(); OMElement resService = factory.createOMElement(new QName(serviceName + "Response")); resService.addChild(resultSer.getFirstElement()); resBody.addChild(resService); resEnv.addChild(resBody); // The declareDefaultNamespace method doesn't work see // (https://issues.apache.org/jira/browse/AXIS2-3156) // so the following doesn't work: // resService.declareDefaultNamespace(ModelService.TNS); // instead, create the xmlns attribute directly: OMAttribute defaultNS = factory.createOMAttribute("xmlns", null, ModelService.TNS); resService.addAttribute(defaultNS); // log the response message if (Debug.verboseOn()) { try { Debug.logInfo("Response Message:\n" + resEnv + "\n", module); } catch (Throwable t) { } } resEnv.serialize(response.getOutputStream()); response.getOutputStream().flush(); } catch (Exception e) { Debug.logError(e, module); throw new EventHandlerException(e.getMessage(), e); } }
private org.apache.axiom.soap.SOAPEnvelope toEnvelope( final org.apache.axiom.soap.SOAPFactory factory, final CadConsultaCadastro2Stub.NfeDadosMsg param, final boolean optimizeContent, final javax.xml.namespace.QName methodQName) throws org.apache.axis2.AxisFault { try { final org.apache.axiom.soap.SOAPEnvelope emptyEnvelope = factory.getDefaultEnvelope(); emptyEnvelope .getBody() .addChild(param.getOMElement(CadConsultaCadastro2Stub.NfeDadosMsg.MY_QNAME, factory)); return emptyEnvelope; } catch (final org.apache.axis2.databinding.ADBException e) { throw org.apache.axis2.AxisFault.makeFault(e); } }
private org.apache.axiom.soap.SOAPEnvelope toEnvelope( org.apache.axiom.soap.SOAPFactory factory, gsn.webservice.standard.RegisterQueryResponse param, boolean optimizeContent) throws org.apache.axis2.AxisFault { try { org.apache.axiom.soap.SOAPEnvelope emptyEnvelope = factory.getDefaultEnvelope(); emptyEnvelope .getBody() .addChild( param.getOMElement(gsn.webservice.standard.RegisterQueryResponse.MY_QNAME, factory)); return emptyEnvelope; } catch (org.apache.axis2.databinding.ADBException e) { throw org.apache.axis2.AxisFault.makeFault(e); } }
/** * Converts a given AXIOM {@link org.apache.axiom.soap.SOAPEnvelope} to a {@link Document}. * * @param envelope the SOAP envelope to be converted * @return the converted document * @throws IllegalArgumentException in case of errors * @see org.apache.rampart.util.Axis2Util.getDocumentFromSOAPEnvelope(SOAPEnvelope, boolean) */ public static Document toDocument(SOAPEnvelope envelope) { try { if (envelope instanceof Element) { return ((Element) envelope).getOwnerDocument(); } else { ByteArrayOutputStream bos = new ByteArrayOutputStream(); envelope.build(); envelope.serialize(bos); ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); return documentBuilderFactory.newDocumentBuilder().parse(bis); } } catch (Exception ex) { throw new IllegalArgumentException("Error in converting SOAP Envelope to Document", ex); } }
/** A utility method that copies the namepaces from the SOAPEnvelope */ private java.util.Map getEnvelopeNamespaces(org.apache.axiom.soap.SOAPEnvelope env) { java.util.Map returnMap = new java.util.HashMap(); java.util.Iterator namespaceIterator = env.getAllDeclaredNamespaces(); while (namespaceIterator.hasNext()) { org.apache.axiom.om.OMNamespace ns = (org.apache.axiom.om.OMNamespace) namespaceIterator.next(); returnMap.put(ns.getPrefix(), ns.getNamespaceURI()); } return returnMap; }
/** Simulate creating a SOAP 1.2 message when the business object provided is just the payload. */ public void testCreateSoap12FromPayload() throws Exception { // Create a SOAP 1.2 Message MessageFactory mf = (MessageFactory) FactoryRegistry.getFactory(MessageFactory.class); Message m = mf.create(Protocol.soap12); // Get the BlockFactory XMLStringBlockFactory f = (XMLStringBlockFactory) FactoryRegistry.getFactory(XMLStringBlockFactory.class); // Create a Block using the sample string as the content. This simulates // what occurs on the outbound JAX-WS dispatch<String> client Block block = f.createFrom(sampleText, null, null); // Add the block to the message as normal body content. m.setBodyBlock(block); // Assuming no handlers are installed, the next thing that will happen // is a XMLStreamReader will be requested...to go to OM. At this point the // block should be consumed. OMElement om = m.getAsOMElement(); // The block should not be consumed yet...because the message has not been read assertTrue(!block.isConsumed()); // To check that the output is correct, get the String contents of the // reader Reader2Writer r2w = new Reader2Writer(om.getXMLStreamReader()); String newText = r2w.getAsString(); TestLogger.logger.debug(newText); assertTrue(newText.contains(sampleText)); assertTrue(newText.contains("soap")); assertTrue(newText.contains("Envelope")); assertTrue(newText.contains("Body")); assertTrue(m.getProtocol().equals(Protocol.soap12)); SOAPEnvelope omSoapEnv = (SOAPEnvelope) m.getAsOMElement(); OMNamespace ns = omSoapEnv.getNamespace(); assertTrue(ns.getNamespaceURI().equals(SOAP12_NS_URI)); // The block should be consumed at this point assertTrue(block.isConsumed()); }
private org.apache.axiom.soap.SOAPEnvelope toEnvelope( org.apache.axiom.soap.SOAPFactory factory, org.wso2.carbon.billing.mgt.services.AddPaymentResponse param, boolean optimizeContent, javax.xml.namespace.QName methodQName) throws org.apache.axis2.AxisFault { try { org.apache.axiom.soap.SOAPEnvelope emptyEnvelope = factory.getDefaultEnvelope(); emptyEnvelope .getBody() .addChild( param.getOMElement( org.wso2.carbon.billing.mgt.services.AddPaymentResponse.MY_QNAME, factory)); return emptyEnvelope; } catch (org.apache.axis2.databinding.ADBException e) { throw org.apache.axis2.AxisFault.makeFault(e); } }
public void toSOAPEnvelope(SOAPEnvelope envelope) { SOAPBody body = envelope.getBody(); // detach if already exist. OMElement elem = body.getFirstChildWithName( new QName(namespaceValue, Sandesha2Constants.WSRM_COMMON.CLOSE_SEQUENCE_RESPONSE)); if (elem != null) elem.detach(); toOMElement(body); }
private boolean checkAndReplaceEnvelope(OMElement resultElement, MessageContext synCtx) { OMElement firstChild = resultElement.getFirstElement(); QName resultQName = firstChild.getQName(); if (resultQName.getLocalPart().equals("Envelope") && (resultQName.getNamespaceURI().equals(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI) || resultQName.getNamespaceURI().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI))) { SOAPEnvelope soapEnvelope = AXIOMUtils.getSOAPEnvFromOM(resultElement.getFirstElement()); if (soapEnvelope != null) { try { soapEnvelope.buildWithAttachments(); synCtx.setEnvelope(soapEnvelope); } catch (AxisFault axisFault) { handleException("Unable to attach SOAPEnvelope", axisFault, synCtx); } } } else { return false; } return true; }
/** @testStrategy Tests conversions between SAAJ and OM for normal element */ public void test2() throws Exception { // Bootstrap: Create an OM SOAPEnvelope from the sample text. StringReader sr = new StringReader(sampleEnvelope); XMLStreamReader inflow = inputFactory.createXMLStreamReader(sr); StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(inflow, null); org.apache.axiom.soap.SOAPEnvelope omEnvelope = builder.getSOAPEnvelope(); // Bootstrap: Get an OMElement from the body OMElement om = omEnvelope.getBody().getFirstElement(); // Bootstrap: Get an SAAJ Body to hold the target SOAPElement MessageFactory msgFactory = MessageFactory.newInstance(); SOAPMessage message = msgFactory.createMessage(); SOAPBody body = message.getSOAPBody(); // Step 1: Get the SAAJConverter object from the Factory SAAJConverterFactory f = (SAAJConverterFactory) FactoryRegistry.getFactory(SAAJConverterFactory.class); SAAJConverter converter = f.getSAAJConverter(); // Step 2: Convert OM to SAAJ SOAPElement se = converter.toSAAJ(om, body); // Step 2a: Verify assertTrue(se instanceof SOAPBodyElement); assertTrue(se.getLocalName().equals("a")); // Step 3: Convert SAAJ to OM om = converter.toOM(se); // Step 3a: Verify assertTrue(om.getLocalName().equals("a")); // Step 4: Rinse and Repeat se = converter.toSAAJ(om, body); assertTrue(se instanceof SOAPBodyElement); assertTrue(se.getLocalName().equals("a")); om = converter.toOM(se); assertTrue(om.getLocalName().equals("a")); }
private java.util.Map<String, String> getEnvelopeNamespaces( final org.apache.axiom.soap.SOAPEnvelope env) { final java.util.Map<String, String> returnMap = new java.util.HashMap<>(); @SuppressWarnings("rawtypes") final java.util.Iterator namespaceIterator = env.getAllDeclaredNamespaces(); while (namespaceIterator.hasNext()) { final org.apache.axiom.om.OMNamespace ns = (org.apache.axiom.om.OMNamespace) namespaceIterator.next(); returnMap.put(ns.getPrefix(), ns.getNamespaceURI()); } return returnMap; }
public void createSoapRequest(MessageContext msgCtx, Element message, Operation op) throws AxisFault { if (op == null) { throw new NullPointerException("Null operation"); } // The message can be null if the input message has no part if (op.getInput().getMessage().getParts().size() > 0 && message == null) { throw new NullPointerException("Null message."); } if (msgCtx == null) { throw new NullPointerException("Null msgCtx"); } BindingOperation bop = binding.getBindingOperation(op.getName(), null, null); if (bop == null) { throw new OdeFault("BindingOperation not found."); } BindingInput bi = bop.getBindingInput(); if (bi == null) { throw new OdeFault("BindingInput not found."); } SOAPEnvelope soapEnv = msgCtx.getEnvelope(); if (soapEnv == null) { soapEnv = soapFactory.getDefaultEnvelope(); msgCtx.setEnvelope(soapEnv); } // createSoapHeaders(soapEnv, getSOAPHeaders(bi), op.getInput().getMessage(), message); SOAPBody soapBody = getSOAPBody(bi); if (soapBody != null) { org.apache.axiom.soap.SOAPBody sb = soapEnv.getBody() == null ? soapFactory.createSOAPBody(soapEnv) : soapEnv.getBody(); createSoapBody(sb, soapBody, op.getInput().getMessage(), message, op.getName()); } }
public static org.apache.axis2.context.MessageContext attachMessage( String jsonMessage, org.apache.axis2.context.MessageContext axis2Ctx) { if (jsonMessage == null) { log.error("Cannot attach null JSON string."); return null; } AxisConfiguration axisConfig = axis2Ctx.getConfigurationContext().getAxisConfiguration(); if (axisConfig == null) { log.warn("Cannot create AxisConfiguration. AxisConfiguration is null."); return null; } try { SOAPFactory soapFactory = new SOAP12Factory(); SOAPEnvelope envelope = soapFactory.createSOAPEnvelope(); envelope.addChild(JsonUtil.newJsonPayload(axis2Ctx, jsonMessage, true, true)); axis2Ctx.setEnvelope(envelope); return axis2Ctx; } catch (Exception e) { log.error("Cannot attach message to Message Context. Error: " + e.getMessage(), e); return null; } }