List of utility methods to do SOAP Message
Document | createDoc(SOAPMessage soapMsg) create Doc Source src = soapMsg.getSOAPPart().getContent(); TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); DOMResult result = new DOMResult(); transformer.transform(src, result); return (Document) result.getNode(); |
SOAPFaultException | createException(String code, String message) create Exception SOAPFault fault = soapFactory.createFault(); fault.setFaultCode(new QName(code)); fault.setFaultString(message); return new SOAPFaultException(fault); |
SOAPMessage | createFault(String message) Given a string message, create a SOAPFault MessageFactory messageFactory = MessageFactory.newInstance(); SOAPMessage msg = messageFactory.createMessage(); SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope(); SOAPBody body = envelope.getBody(); SOAPFault fault = body.addFault(); fault.setFaultCode("Server"); fault.setFaultActor("urn:picketlink"); fault.setFaultString(message); ... |
SOAPFaultException | createSOAPFault(SOAPFault fault, Throwable cause) create SOAP Fault SOAPFaultException sfe = new SOAPFaultException(fault); if (isEnableFaultDetail()) { sfe.initCause(cause); } else { sfe.initCause(new Exception()); return sfe; |
SOAPMessage | createSOAPRequestForPartnerCategories(String userId) create SOAP Request For Partner Categories MessageFactory messageFactory = MessageFactory.newInstance(); SOAPMessage soapMessage = messageFactory.createMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); String serverURI = "http://service.entitlement.siemens.com"; SOAPEnvelope envelope = soapPart.getEnvelope(); envelope.addNamespaceDeclaration("ser", serverURI); envelope.addNamespaceDeclaration("xsi", "http://www.w3.org/2001/XMLSchema-instance"); SOAPBody soapBody = envelope.getBody(); ... |
void | ensureNamespaceDeclared(SOAPElement elem, String namespaceURI, String prefix) ensure Namespace Declared if (prefix == null || prefix.length() == 0) { if (namespaceURI == null || namespaceURI.length() == 0) return; if (!namespaceURI.equals(elem.getNamespaceURI(""))) { elem.addNamespaceDeclaration("", namespaceURI); } else { if (namespaceURI == null || namespaceURI.length() == 0) ... |
String | ensureNamespaceDeclared(SOAPElement element, String prefix, String nsURI) Ensures the given namespace is declared in the scope of the given element. if (prefix.length() == 0) { prefix = getNamespacePrefix(element, nsURI); if (prefix == null) { prefix = "valueNS"; element.addNamespaceDeclaration(prefix, nsURI); else if (!nsURI.equals(element.getNamespaceURI(prefix))) { ... |
Document | extractXMLPayloadFromSOAPMessage(SOAPMessage messageSOAP) Extracts the payload from a SOAP message. for (Iterator iter = messageSOAP.getSOAPBody().getChildElements(); iter.hasNext();) { Object child = iter.next(); if (child instanceof SOAPBodyElement) { Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); Node node = doc.importNode((SOAPBodyElement) child, true); doc.appendChild(node); return doc; return null; |
String | getAttachmentContentType(SOAPMessage message) Returns the content type of the first SOAP attachment or null if there's no attachments. if (message.countAttachments() == 0) { return null; AttachmentPart att = (AttachmentPart) message.getAttachments().next(); return att.getContentType(); |
SOAPBody | getBody(SOAPMessage m) get Body try { return m.getSOAPBody(); } catch (UnsupportedOperationException ex) { return m.getSOAPPart().getEnvelope().getBody(); |