String namespace = "http://www.csapi.org/s"; SOAPHeader header = envelope.getHeader(); SOAPBody body = envelope.getBody(); QName bodyName = new QName(namespace, "syncOrderRelationResponse"); SOAPBodyElement purchaseLineItems = body.addBodyElement(bodyName); QName childName = new QName(namespace,"result"); SOAPElement product = purchaseLineItems.addChildElement(childName); product.addTextNode("0"); childName = new QName(namespace,"resultDescription"); product = purchaseLineItems.addChildElement(childName); product.addTextNode("0"); outgoingMessage.writeTo(System.out);
String namespace = "http://www.csapi.org/s"; String nsPrefix = "loc"; envelope.setAttribute("xmlns:" + nsPrefix , namespace); SOAPHeader header = envelope.getHeader(); SOAPBody body = envelope.getBody(); QName bodyName = new QName(namespace, "syncOrderRelationResponse", nsPrefix); SOAPBodyElement purchaseLineItems = body.addBodyElement(bodyName); QName childName = new QName(namespace,"result", nsPrefix); SOAPElement product = purchaseLineItems.addChildElement(childName); product.addTextNode("0"); childName = new QName(namespace,"resultDescription", nsPrefix); product = purchaseLineItems.addChildElement(childName); product.addTextNode("0");
SOAPBody body = message.getSOAPBody(); QName bodyName = new QName("http://www.webserviceX.NET", "GetAtomicNumber"); SOAPBodyElement bodyElement = body.addBodyElement(bodyName); SOAPElement symbol = bodyElement.addChildElement("MyMetal"); symbol.addTextNode("iron"); SOAPConnection connection = SOAPConnectionFactory.newInstance().createConnection(); SOAPMessage response = connection.call(message, endpoint); connection.close(); message.writeTo(System.out); System.out.println(); response.writeTo(System.out); System.out.println();
/** * Add body element to envelope. * * @param naam the naam * @throws SOAPException the soap exception */ public void addBodyElementToEnvelope(String naam) throws SOAPException { SOAPEnvelope envelope = soapMessage.getSOAPPart().getEnvelope(); SOAPElement bodyElement = soapMessage.getSOAPBody().addBodyElement(envelope.createName(naam)); this.elements.put(naam, bodyElement); }
public void process(Exchange exchange) throws Exception { byte[] body2 = (byte[]) exchange.getOut().getBody(); ByteArrayInputStream bais = new ByteArrayInputStream( body2 ); SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(); SOAPBody soapBody = soapMessage.getSOAPPart().getEnvelope().getBody(); QName payloadName = new QName( "http://soap.jax.drools.org/", "executeResponse", "ns1" ); QName responseName = new QName( "http://soap.jax.drools.org/", "return", "ns1" ); SOAPBodyElement payload = soapBody.addBodyElement( payloadName ); SOAPElement response = payload.addChildElement( responseName ); response.addTextNode( StringUtils.toString( bais ) ); ByteArrayOutputStream baos = new ByteArrayOutputStream(); soapMessage.writeTo( baos ); exchange.getOut().setBody( new String( baos.toByteArray() ) ); }
public void process(Exchange exchange) throws Exception { byte[] body2 = (byte[]) exchange.getOut().getBody(); ByteArrayInputStream bais = new ByteArrayInputStream( body2 ); SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(); SOAPBody soapBody = soapMessage.getSOAPPart().getEnvelope().getBody(); QName payloadName = new QName( "http://soap.jax.drools.org/", "executeResponse", "ns1" ); QName responseName = new QName( "http://soap.jax.drools.org/", "return", "ns1" ); SOAPBodyElement payload = soapBody.addBodyElement( payloadName ); SOAPElement response = payload.addChildElement( responseName ); response.addTextNode( StringUtils.toString( bais ) ); ByteArrayOutputStream baos = new ByteArrayOutputStream(); soapMessage.writeTo( baos ); exchange.getOut().setBody( new String( baos.toByteArray() ) ); }
/** * Add body element to envelope. * * @param naam the naam * @param prefix the prefix * @param namespaceUri the namespace uri * @throws SOAPException the soap exception */ public void addBodyElementToEnvelope(String naam, String prefix, String namespaceUri) throws SOAPException { SOAPEnvelope envelope = soapMessage.getSOAPPart().getEnvelope(); SOAPElement bodyElement = soapMessage.getSOAPBody().addBodyElement(envelope.createName(naam, prefix, namespaceUri)); this.elements.put(naam, bodyElement); }
public void process(Exchange exchange) throws Exception { InputStream is = (InputStream) exchange.getIn().getBody(); //Bad Hack - Need to remote it and fix it in Camel (if it's a camel problem) //I need to copy the results here because I loose them at the end of the method String results = StringUtils.toString( is ); if ( is != null ) { SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(); SOAPBody body = soapMessage.getSOAPPart().getEnvelope().getBody(); QName payloadName = new QName( "http://soap.jax.drools.org/", "executeResponse", "ns1" ); QName responseName = new QName( "http://soap.jax.drools.org/", "return", "ns1" ); SOAPBodyElement payload = body.addBodyElement( payloadName ); SOAPElement response = payload.addChildElement( responseName ); //Bad Hack - Need to remote it and fix it in Camel (if it's a camel problem) // response.addTextNode( StringUtils.toString( is ) ); response.addTextNode( results ); exchange.getOut().setBody( soapMessage ); } }
public void process(Exchange exchange) throws Exception { InputStream is = (InputStream) exchange.getIn().getBody(); //Bad Hack - Need to remote it and fix it in Camel (if it's a camel problem) //I need to copy the results here because I loose them at the end of the method String results = StringUtils.toString( is ); if ( is != null ) { SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(); SOAPBody body = soapMessage.getSOAPPart().getEnvelope().getBody(); QName payloadName = new QName( "http://soap.jax.drools.org/", "executeResponse", "ns1" ); QName responseName = new QName( "http://soap.jax.drools.org/", "return", "ns1" ); SOAPBodyElement payload = body.addBodyElement( payloadName ); SOAPElement response = payload.addChildElement( responseName ); //Bad Hack - Need to remote it and fix it in Camel (if it's a camel problem) // response.addTextNode( StringUtils.toString( is ) ); response.addTextNode( results ); exchange.getOut().setBody( soapMessage ); } }
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); } }
//create SOAP SOAPConnectionFactory sfc = SOAPConnectionFactory.newInstance(); SOAPConnection connection = sfc.createConnection(); SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); SOAPEnvelope soapEnvelope = soapPart.getEnvelope(); SOAPBody soapBody = soapEnvelope.getBody(); SOAPElement Header = soapBody.addBodyElement(new QName("Header")); //attribute SOAPElement Security= Header.addChildElement(new QName("Security")); SOAPElement UsernameToken= Security.addChildElement(new QName("UsernameToken")); SOAPElement Username= UsernameToken.addChildElement(new QName("Username")); SOAPElement Password= UsernameToken.addChildElement(new QName("Password")); //enter the username and password Username.addTextNode("username"); Password.addTextNode("password"); //send the soap and print out the result URL endpoint = "http://localhost:8080/soap/getMessage?wsdl"; SOAPMessage response = connection.call(soapMessage, endpoint);
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; }
private SOAPMessage createSOAPMessage(Element elem) throws Exception { String prefix = ""; MessageFactory msgFactory = MessageFactory.newInstance(); SOAPFactory factory = SOAPFactory.newInstance(); SOAPMessage message = msgFactory.createMessage(); message.getSOAPHeader().detachNode(); SOAPPart soapPart = message.getSOAPPart(); SOAPBody soapBody = soapPart.getEnvelope().getBody(); //Create the outer body element Name bodyName = factory.createName(elem.getNodeName(), prefix, UDDI_V2_NAMESPACE); SOAPBodyElement bodyElement = soapBody.addBodyElement(bodyName); bodyElement.addNamespaceDeclaration(prefix, UDDI_V2_NAMESPACE); appendAttributes(bodyElement, elem.getAttributes(), factory); appendElements(bodyElement, elem.getChildNodes(), factory); return message; }
SOAPMessage sm = MessageFactory.newInstance().createMessage(); sm.setProperty(SOAPMessage.WRITE_XML_DECLARATION, "true"); sm.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, "UTF-8"); SOAPPart sp = sm.getSOAPPart(); SOAPEnvelope se = sp.getEnvelope(); se.setEncodingStyle("http://schemas.xmlsoap.org/soap/encoding/"); se.setAttribute("xmlns:SOAP-ENC", "http://schemas.xmlsoap.org/soap/encoding/"); se.setAttribute("xmlns:soa", "http://www.sbg.com"); SOAPBody sb = sm.getSOAPBody(); SOAPBodyElement el = sb.addBodyElement(new QName("http://www.sbg.com", "response", "soa")); el.setAttribute("_ctxID", "cid=xref_members,cn=admin"); el.setAttribute("status", "OK"); SOAPElement in = el.addChildElement("response_code"); in.setValue("0000"); sm.writeTo(System.out);
private SOAPMessage encodeRequest(MessageFactory factory, String value) throws SOAPException { SOAPMessage request = factory.createMessage(); SOAPEnvelope envelope = request.getSOAPPart().getEnvelope(); request.setProperty("soapaction", ""); if (value != null) { request.getSOAPBody().addBodyElement(envelope.createName(value, "ns1", sayHi.getNamespaceURI())); } return request; }
public SOAPMessage sendMessage() throws Exception { SOAPConnectionFactory conFactory = SOAPConnectionFactory.newInstance(); SOAPConnection connection = conFactory.createConnection(); MessageFactory msgFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL); SOAPMessage msg = msgFactory.createMessage(); SOAPBodyElement bodyElement = msg.getSOAPBody().addBodyElement(new QName("urn:switchyard-quickstart:soap-mtom:1.0", "image")); bodyElement.setTextContent(imageData); return connection.call(msg, new URL(SWITCHYARD_WEB_SERVICE)); }
private SOAPMessage createSoapMessage( SOAPVersion soapVersion, String contentId ) throws SOAPException { String soapProtocol = SOAPConstants.SOAP_1_2_PROTOCOL; if ( isSoap11( soapVersion ) ) soapProtocol = SOAPConstants.SOAP_1_1_PROTOCOL; MessageFactory messageFactory = MessageFactory.newInstance( soapProtocol ); SOAPMessage message = messageFactory.createMessage(); SOAPPart soapPart = message.getSOAPPart(); SOAPEnvelope envelope = soapPart.getEnvelope(); SOAPBody body = envelope.getBody(); envelope.createName( "response", CommonNamespaces.WMS_PREFIX, CommonNamespaces.WMSNS ); Name name = envelope.createName( "response", CommonNamespaces.WMS_PREFIX, CommonNamespaces.WMSNS ); SOAPBodyElement bodyElement = body.addBodyElement( name ); bodyElement.setTextContent( contentId ); return message; }
SOAPConnectionFactory soapfactory=SOAPConnectionFactory.newInstance(); SOAPConnection soapconnection=soapfactory.createConnection(); MessageFactory messagefactory=MessageFactory.newInstance(); SOAPMessage messege=messagefactory.createMessage(); SOAPEnvelope envelop=messege.getSOAPPart().getEnvelope(); SOAPHeader header=messege.getSOAPHeader(); SOAPBody body=messege.getSOAPBody(); Name header_context=envelop.createName("context", null,"urn:zimbra"); Name auth_request=envelop.createName("AuthRequest",null,"urn:zimbraAccount"); Name account=envelop.createName("account"); Name password=envelop.createName("password"); header.addHeaderElement(header_context); SOAPBodyElement auth_body=body.addBodyElement(auth_request); auth_body.addChildElement(account).addAttribute(envelop.createName("by"),"name").addTextNode("abc");//(abc==your username) auth_body.addChildElement(password).addTextNode("1234");//(1234=your password) URL url=new URL("http://192.168.1.67/service/soap/AuthRequest"); SOAPMessage response=soapconnection.call(messege, url);
MessageFactory messageFactory = MessageFactory.newInstance(); SOAPMessage soapMessage = messageFactory.createMessage(); // Retrieve different parts SOAPPart soapPart = soapMessage.getSOAPPart(); SOAPEnvelope soapEnvelope = soapMessage.getSOAPPart().getEnvelope(); // Two ways to extract headers SOAPHeader soapHeader = soapEnvelope.getHeader(); soapHeader = soapMessage.getSOAPHeader(); // Two ways to extract body SOAPBody soapBody = soapEnvelope.getBody(); soapBody = soapMessage.getSOAPBody(); // To add some element SOAPFactory soapFactory = SOAPFactory.newInstance(); Name bodyName = soapFactory.createName("getEmployeeDetails","ns1","urn:MySoapServices"); SOAPBodyElement purchaseLineItems = soapBody.addBodyElement(bodyName); Name childName = soapFactory.createName("param1"); SOAPElement order = purchaseLineItems.addChildElement(childName); childName.addTextNode("1016577");
public SOAPMessage sendMessage() throws Exception { SOAPConnectionFactory conFactory = SOAPConnectionFactory.newInstance(); SOAPConnection connection = conFactory.createConnection(); MessageFactory msgFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL); SOAPMessage msg = msgFactory.createMessage(); SOAPBodyElement bodyElement = msg.getSOAPBody().addBodyElement(new QName("urn:switchyard-quickstart:soap-attachment:1.0", "echoImage")); bodyElement.addTextNode("cid:switchyard.png"); // CXF does not set content-type. msg.getMimeHeaders().addHeader("Content-Type", "multipart/related; type=\"text/xml\"; start=\"<root.message@cxf.apache.org>\""); msg.getSOAPPart().setContentId("<root.message@cxf.apache.org>"); AttachmentPart ap = msg.createAttachmentPart(); ap.setDataHandler(new DataHandler(new StreamDataSource())); ap.setContentId("<switchyard.png>"); msg.addAttachmentPart(ap); return connection.call(msg, new URL(SWITCHYARD_WEB_SERVICE)); }