For IntelliJ IDEA,
Android Studio or Eclipse



private void myMethod () {SOAPEnvelope s =
SOAPMessage sOAPMessage;sOAPMessage.getSOAPPart().getEnvelope()
SOAPPart sOAPPart;sOAPPart.getEnvelope()
SOAPPart sOAPPart;sOAPPart.getEnvelope()
- Smart code suggestions by Codota
}
/** Create the SOAP-1.1 message */ protected SOAPMessage createMessage(OperationMetaData opMetaData) throws SOAPException { SOAPMessage soapMessage = msgFactory.createMessage(); Use encStyle = opMetaData.getEndpointMetaData().getEncodingStyle(); if (Use.ENCODED.equals(encStyle)) { SOAPEnvelope soapEnvelope = soapMessage.getSOAPPart().getEnvelope(); soapEnvelope.addNamespaceDeclaration(Constants.PREFIX_SOAP11_ENC, Constants.URI_SOAP11_ENC); } return soapMessage; }
public SoapMessageBuilder addNamespace(String prefix, String ns) { try { envelope.addNamespaceDeclaration(prefix, ns); } catch (SOAPException e) { throw new RuntimeException("Could not add namespace to SOAP Envelope.", e); } return this; }
SOAPEnvelope envelope = soapPart.getEnvelope(); envelope.addNamespaceDeclaration("xsi","http://www.w3.org/2001/XMLSchema-instance"); SOAPBody soapBody = envelope.getBody(); SOAPElement soapBodyElem = soapBody.addChildElement( "GetUserInfo" ); SOAPElement soapBodyElem1 = soapBodyElem.addChildElement( "ArgComKey" ); soapBodyElem1.addTextNode( "ComKey" ).setAttribute("xsi:type","xsd:integer"); SOAPElement soapBodyElem2 = soapBodyElem.addChildElement( "Arg" ); soapBodyElem2.addTextNode( "123" );
SOAPMessage message = factory.createMessage(); SOAPPart soapPart = message.getSOAPPart(); SOAPEnvelope envelope = soapPart.getEnvelope(); //add declaration here envelope.addNamespaceDeclaration("env", "http://som.org"); SOAPHeader header = envelope.getHeader(); SOAPBody body = envelope.getBody(); SOAPElement envio = body.addChildElement("envio"); envio.setPrefix("env"); //explicit declare it here for this element envio.addNamespaceDeclaration("env", "http://som.org"); SOAPElement cabecera = envio.addChildElement("cabecera","env");
MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL); SOAPMessage soapMessage = messageFactory.createMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); SOAPEnvelope soapEnvelope = soapPart.getEnvelope(); SOAPBody soapBody = soapEnvelope.getBody(); soapEnvelope.removeNamespaceDeclaration(soapEnvelope.getPrefix()); soapEnvelope.addNamespaceDeclaration("soap", "http://schemas.xmlsoap.org/soap/envelope/"); soapEnvelope.setPrefix("soap"); soapBody.setPrefix("soap"); soapEnvelope.addNamespaceDeclaration("xsi", "http://www.w3.org/2001/XMLSchema-instance"); soapEnvelope.addNamespaceDeclaration("xsd", "http://www.w3.org/2001/XMLSchema"); soapMessage.getSOAPHeader().detachNode(); soapMessage.getMimeHeaders().setHeader("SOAPAction", "http://www.example.com/TransactionProcess");
SOAPEnvelope env = sp.getEnvelope(); env.addNamespaceDeclaration("xsd", "http://www.w3.org/2001/XMLSchema"); env.addNamespaceDeclaration("xsi", "http://www.w3.org/2001/XMLSchema-instance");
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; } }
private static SOAPMessage createSOAPRequest(String documentId, String fileToUpdate) throws Exception { MessageFactory messageFactory = MessageFactory.newInstance(); SOAPMessage soapMessage = messageFactory.createMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); String serverURI = "urn:WSFS"; // change form "WSFS" to "urn:WSFS" SOAPEnvelope envelope = soapPart.getEnvelope(); envelope.addNamespaceDeclaration("urn", serverURI); // this line will add namespece in your envelope ...
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);
SOAPEnvelope envelope = soapPart.getEnvelope(); envelope.addNamespaceDeclaration("sh", serverURI ); //added code here envelope.addNamespaceDeclaration("user", "http://www.website.com/ems/soap/sh/userdata" ); envelope.addNamespaceDeclaration("ser", "http://www.website.com/ems/soap/sh/servicedata" );
public SoapMessageBuilder addNamespace(String prefix, String ns) { try { envelope.addNamespaceDeclaration(prefix, ns); } catch (SOAPException e) { throw new RuntimeException("Could not add namespace to SOAP Envelope.", e); } return this; }
public SoapMessageBuilder addNamespace(String prefix, String ns) { try { envelope.addNamespaceDeclaration(prefix, ns); } catch (SOAPException e) { throw new RuntimeException("Could not add namespace to SOAP Envelope.", e); } return this; }
SOAPEnvelope env = sp.getEnvelope(); env.addNamespaceDeclaration("xsd", "http://www.w3.org/2001/XMLSchema"); env.addNamespaceDeclaration("xsi", "http://www.w3.org/2001/XMLSchema-instance");
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; } }
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; } }