soapResponse.writeTo(System.out); MessageFactory messageFactory = MessageFactory.newInstance(); SOAPMessage soapMessage = messageFactory.createMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); SOAPEnvelope envelope = soapPart.getEnvelope(); envelope.addNamespaceDeclaration("example", serverURI); SOAPBody soapBody = envelope.getBody(); SOAPElement soapBodyElem = soapBody.addChildElement("VerifyEmail", "example"); SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("email", "example"); soapBodyElem1.addTextNode("mutantninja@gmail.com"); SOAPElement soapBodyElem2 = soapBodyElem.addChildElement("LicenseKey", "example"); soapBodyElem2.addTextNode("123"); MimeHeaders headers = soapMessage.getMimeHeaders(); headers.addHeader("SOAPAction", serverURI + "VerifyEmail"); soapMessage.saveChanges();
import javax.xml.bind.*; import javax.xml.soap.*; public class Demo { public static void main(String[] args) throws Exception { MessageFactory mf = MessageFactory.newInstance(); SOAPMessage message = mf.createMessage(); SOAPBody body = message.getSOAPBody(); Foo foo = new Foo(); foo.setBar("Hello World"); JAXBContext jc = JAXBContext.newInstance(Foo.class); Marshaller marshaller = jc.createMarshaller(); marshaller.marshal(foo, body); message.saveChanges(); message.writeTo(System.out); } }
soapFault = binding.getMessageFactory().createMessage() .getSOAPPart().getEnvelope().getBody().addFault(); } catch (Throwable t2) {
public static SOAPMessage createDefaultSoapMessage(String responseMessage, String requestMessage) { try { SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(); SOAPBody body = soapMessage.getSOAPPart().getEnvelope().getBody(); QName payloadName = new QName("http://apache.org/hello_world_soap_http/types", "greetMeResponse", "ns1"); SOAPBodyElement payload = body.addBodyElement(payloadName); SOAPElement message = payload.addChildElement("responseType"); message.addTextNode(responseMessage + " Request was " + requestMessage); return soapMessage; } catch (SOAPException e) { e.printStackTrace(); throw new RuntimeException(e); } }
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance(); this.soapConnection = soapConnectionFactory.createConnection(); MessageFactory messageFactory = MessageFactory.newInstance(); SOAPMessage soapMessage = messageFactory.createMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); // SOAP Envelope SOAPEnvelope envelope = soapPart.getEnvelope(); envelope.addNamespaceDeclaration("ser", "http://server.splat/"); // SOAP Body SOAPBody soapBody = envelope.getBody(); SOAPElement soapBodyElem = soapBody.addChildElement(operation, "ser"); int n = 0; for (Object argN : args) { SOAPElement soapBodyElemN = soapBodyElem.addChildElement("arg" + n++); soapBodyElemN.addTextNode(argN.toString()); } MimeHeaders headers = soapMessage.getMimeHeaders(); headers.addHeader("SOAPAction", "\"\""); soapMessage.saveChanges(); /* Print the request message */ debug(operation + " Request SOAP Message:\n" + traceSOAPMessage(soapMessage)); SOAPMessage soapResponse = this.soapConnection.call( soapMessage, this.url );
public void process(Exchange exchange) throws Exception { InputStream is = (InputStream) exchange.getIn().getBody(); Map<String, Object> headers = exchange.getIn().getHeaders(); MimeHeaders mimeHeaders = new MimeHeaders(); for ( String header : headers.keySet() ) { mimeHeaders.addHeader( header, (String) headers.get( header ) ); } SOAPMessage soapMessage = MessageFactory.newInstance().createMessage( mimeHeaders, is ); exchange.getOut().setBody( soapMessage.getSOAPBody().getTextContent().trim() ); exchange.getIn().setBody( soapMessage.getSOAPBody().getTextContent().trim() ); }
SOAPMessage request = mf.createMessage(); SOAPPart part = request.getSOAPPart(); SOAPEnvelope env = part.getEnvelope(); SOAPHeader header = env.getHeader(); SOAPBody body = env.getBody(); SOAPElement operation = body.addChildElement("invoke", "ns1", "http://com/ibm/was/wssample/echo/"); SOAPElement value = operation.addChildElement("arg0"); value.addTextNode("ping"); request.saveChanges();
private SOAPMessage initSOAPMessage(InputStream is) throws SOAPException, IOException { SOAPMessage msg = null; if (is != null) { msg = SAAJFactoryResolver.createMessageFactory(null).createMessage(null, is); } else { msg = SAAJFactoryResolver.createMessageFactory(null).createMessage(); } msg.setProperty(SOAPMessage.WRITE_XML_DECLARATION, "true"); msg.getSOAPPart().getEnvelope().addNamespaceDeclaration(WSDLConstants.NP_SCHEMA_XSD, WSDLConstants.NS_SCHEMA_XSD); msg.getSOAPPart().getEnvelope().addNamespaceDeclaration(WSDLConstants.NP_SCHEMA_XSI, WSDLConstants.NS_SCHEMA_XSI); return msg; } }
SOAPMessage soapMessage = messageFactory.createMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); SOAPEnvelope envelope = soapPart.getEnvelope(); envelope.removeAttribute("xmlns:SOAP-ENV"); envelope.setPrefix("soap"); envelope.addNamespaceDeclaration("xsd", "http://www.w3.org/2001/XMLSchema"); envelope.addNamespaceDeclaration("xsi", "http://www.w3.org/2001/XMLSchema-instance"); MimeHeaders mimeheaders = soapMessage.getMimeHeaders(); mimeheaders.addHeader("SOAPAction", "SendRequest"); SOAPHeader header = soapMessage.getSOAPHeader(); header.detachNode(); SOAPBody soapBody = envelope.getBody(); soapBody.setPrefix("soap"); QName xmlns = new QName("xmlns"); SOAPElement sendRequest = soapBody.addChildElement(new QName("http://tempuri.org/", "SendRequest")); sendRequest.addAttribute(xmlns, ""); SOAPElement auth = sendRequest.addChildElement(new QName("", "auth")); auth.addChildElement(new QName("http://tempuri.org/", "Login")) .addAttribute(new QName("xmlns"), "http://tempuri.org/") .addTextNode("vcm");
public void process(final Exchange exchange) throws Exception { final MessageFactory messageFactory = MessageFactory.newInstance(); final SOAPMessage inMessage = messageFactory.createMessage(null, exchange.getIn().getMandatoryBody(InputStream.class)); final Iterator<Node> it = inMessage.getSOAPBody().getChildElements(); SOAPBodyElement result = null; while (it.hasNext()) { final SOAPMessage soapMessage = messageFactory.createMessage(); final SOAPPart soapPart = soapMessage.getSOAPPart(); final SOAPEnvelope enveloppe = soapPart.getEnvelope(); enveloppe.addNamespaceDeclaration("env", "http://schemas.xmlsoap.org/soap/envelope/"); final SOAPBody soapBody = enveloppe.getBody(); final SOAPElement levelElement = soapBody.addChildElement("result").addChildElement("level"); levelElement.setTextContent(level); soapMessage.writeTo(byteArrayOutputStream); byteArrayOutputStream.close(); exchange.getOut().setBody(byteArrayOutputStream.toByteArray());
MessageFactory mf = MessageFactory.newInstance(); SOAPMessage message = mf.createMessage(); MimeHeaders mh = message.getMimeHeaders(); mh.setHeader("SOAPAction", "\"urn:schemas-microsoft-com:xml-analysis:Execute\""); SOAPPart soapPart = message.getSOAPPart(); SOAPEnvelope envelope = soapPart.getEnvelope(); SOAPBody body = envelope.getBody(); Name nEx = envelope.createName("Execute", "", XMLA_URI); SOAPElement eEx = body.addChildElement(nEx); Name nCom = envelope.createName("Command", "", XMLA_URI); SOAPElement eCommand = eEx.addChildElement(nCom); Name nSta = envelope.createName("Statement", "", XMLA_URI); SOAPElement eStatement = eCommand.addChildElement(nSta); eStatement.addTextNode(queryStr); paraList.put("AxisFormat", "TupleFormat"); addParameterList(envelope, eEx, "Properties", "PropertyList", paraList); message.saveChanges();
private SOAPMessage createEchoRequest() throws SOAPException { SOAPMessage message = messageFactory.createMessage(); SOAPEnvelope envelope = message.getSOAPPart().getEnvelope(); Name echoRequestName = envelope.createName("echoRequest", PREFIX, NAMESPACE_URI); SOAPBodyElement echoRequestElement = message.getSOAPBody() .addBodyElement(echoRequestName); echoRequestElement.setValue("Hello"); return message; }
SOAPMessage message = MessageFactory.newInstance().createMessage(); SOAPPart part = message.getSOAPPart(); SOAPEnvelope envelope = part.getEnvelope(); SOAPBody body = envelope.getBody(); .addBodyElement(envelope.createName("testXopResponse", null, "http://cxf.apache.org/mime/types")); SOAPElement name = testResponse.addChildElement("name", null, "http://cxf.apache.org/mime/types"); name.setTextContent("return detail + call detail"); SOAPElement attachinfo = testResponse.addChildElement( "attachinfo", null, "http://cxf.apache.org/mime/types"); SOAPElement include = attachinfo.addChildElement("Include", "xop", "http://www.w3.org/2004/08/xop/include"); AttachmentPart attachment = message.createAttachmentPart(dh); attachment.setContentId("mtom_xop.wsdl"); message.addAttachmentPart(attachment); System.out .println("Adding attachment: " + attachment.getContentId() + ":" + attachment.getSize()); include.addAttribute(envelope.createName("href"), "cid:" + attachment.getContentId());
MessageFactory messageFactory = MessageFactory.newInstance(); SOAPMessage soapMessage = messageFactory.createMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); SOAPEnvelope envelope = soapPart.getEnvelope(); SOAPBody soapBody = envelope.getBody(); SOAPElement soapBodyAction = soapBody.addChildElement(parameters.get("action")); parameters.remove("action"); SOAPElement soapBodyKey = soapBodyAction.addChildElement("key"); soapBodyKey.addTextNode(secretKey); while (it.hasNext()) { Entry<String, String> param = it.next(); SOAPElement soapBodyElement = soapBodyAction.addChildElement(param.getKey()); soapBodyElement.addTextNode(param.getValue()); soapResponse.writeTo(out); DocumentBuilderFactory builderfactory = DocumentBuilderFactory.newInstance(); builderfactory.setNamespaceAware(true);
soapMessage = MessageFactory.newInstance().createMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); SOAPBody soapBody = soapMessage.getSOAPBody(); SOAPEnvelope soapEnvelope = soapPart.getEnvelope(); soapEnvelope.addNamespaceDeclaration("", "$NameSpacePlaceHolder"); Name secHeaderName = soapEnvelope.createName("Security", "sec", SEC_HEADER); Name authorizationHeaderName = soapEnvelope.createName("AuthorizationData","sec", SEC_HEADER); Name auditingHeaderName = soapEnvelope.createName("InfoData","sec", SEC_HEADER); secElement.addNamespaceDeclaration("sec", SEC_HEADER); secElement.appendChild(soapPart.importNode(authnAssertion.getDOM(), true)); secElement.addChildElement(authorizationHeaderName).appendChild(soapPart.importNode(authorizationAssertion.getDOM(), true)); secElement.addChildElement(auditingHeaderName).appendChild(soapPart.importNode(auditingAssertion.getDOM(), true)); soapBody.addTextNode("$RequestXMLPlaceHolder");
MessageFactory messageFactory = MessageFactory.newInstance(); SOAPMessage soapMessage = messageFactory.createMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); SOAPEnvelope envelope = soapPart.getEnvelope(); envelope.addNamespaceDeclaration("ns", "website"); envelope.addNamespaceDeclaration("com", "website/Common"); envelope.addNamespaceDeclaration("xm", "http://www.w3.org/2005/05/xmlmime"); SOAPBody soapBody = envelope.getBody(); SOAPElement element = soapBody.addChildElement("RequestName", "ns"); SOAPElement modelElement = element.addChildElement("model", "ns"); SOAPElement soapElement = modelElement.addChildElement("keys", "ns"); soapElement.addAttribute(envelope.createName("query"), "myquery;"); modelElement.addChildElement("instance", "ns"); soapMessage.saveChanges(); soapMessage.writeTo(System.out);
private void prepareUndeploySOAP(String packageId) throws SOAPException, IOException { MessageFactory mFactory = MessageFactory.newInstance(); SOAPMessage message = mFactory.createMessage(); SOAPBody body = message.getSOAPBody(); SOAPElement xmlUndeploy = body.addChildElement(ODE_ELEMENT_UNDEPLOY); SOAPElement xmlPackageName = xmlUndeploy .addChildElement(ODE_ELEMENT_PACKAGENAME); xmlPackageName.setTextContent(packageId); ByteArrayOutputStream b = new ByteArrayOutputStream(); message.writeTo(b); fContent = b.toString(); } }
try { MessageFactory messageFactory = MessageFactory.newInstance(); SOAPMessage soapMessage = messageFactory.createMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); SOAPEnvelope envelope = soapPart.getEnvelope(); SOAPBody soapBody = envelope.getBody(); soapBody.addNamespaceDeclaration("tem", bodyNameSpace); soapBody.addDocument(soapBodyDoc); MimeHeaders headers = soapMessage.getMimeHeaders(); headers.addHeader("SOAPAction", serverURI + soapAction);; soapMessage.saveChanges();
@Test public void test() throws Exception { MessageFactory messageFactory = MessageFactory.newInstance(); SOAPMessage soapMessage = messageFactory.createMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); SOAPEnvelope soapEnvelope = soapPart.getEnvelope(); soapEnvelope.addNamespaceDeclaration("xsd", "http://www.w3.org/2001/XMLSchema"); soapEnvelope.addNamespaceDeclaration("xsi", "http://www.w3.org/2001/XMLSchema-instance"); soapEnvelope.addNamespaceDeclaration("bran", "BDetail"); SOAPBody soapBody = soapEnvelope.getBody(); SOAPElement soapElement = soapBody.addChildElement( "sentIbBTyp", "bran"); soapElement .setEncodingStyle("http://schemas.xmlsoap.org/soap/encoding/"); SOAPElement elementBankCode = soapElement.addChildElement("pBnCode"); // added missing attribute QName qname = new QName("xsi:type"); elementBankCode.addAttribute(qname, "xsd:string"); elementBankCode.setValue("234"); soapMessage.writeTo(System.out); }
@Override protected void sendAuthnRequest(HttpFacade httpFacade, SAML2AuthnRequestBuilder authnRequestBuilder, BaseSAML2BindingBuilder binding) { try { MessageFactory messageFactory = MessageFactory.newInstance(); SOAPMessage message = messageFactory.createMessage(); SOAPEnvelope envelope = message.getSOAPPart().getEnvelope(); envelope.addNamespaceDeclaration(NS_PREFIX_SAML_ASSERTION, JBossSAMLURIConstants.ASSERTION_NSURI.get()); envelope.addNamespaceDeclaration(NS_PREFIX_SAML_PROTOCOL, JBossSAMLURIConstants.PROTOCOL_NSURI.get()); envelope.addNamespaceDeclaration(NS_PREFIX_PAOS_BINDING, JBossSAMLURIConstants.PAOS_BINDING.get()); envelope.addNamespaceDeclaration(NS_PREFIX_PROFILE_ECP, JBossSAMLURIConstants.ECP_PROFILE.get()); createPaosRequestHeader(envelope); createEcpRequestHeader(envelope); SOAPBody body = envelope.getBody(); body.addDocument(binding.postBinding(authnRequestBuilder.toDocument()).getDocument()); message.writeTo(httpFacade.getResponse().getOutputStream()); } catch (Exception e) { throw new RuntimeException("Could not create AuthnRequest.", e); } }