SOAPMessage message = smc.getMessage(); SOAPBody body = message.getSOAPBody(); //Then grabbing the first child node of the body and checking its name: Iterator<Node> nodes = body.getChildElements(); // get the first one if (n.getNodeName().equals("The node name for the particular operation")) { // then we have it }
@Override public boolean handleFault(SOAPMessageContext context) { if (!shouldExecute(context)) { return true; } final Span span = tracingPlugin.getTracer().scopeManager().active().span(); Tags.ERROR.set(span, Boolean.TRUE); try { final SOAPFault fault = context.getMessage().getSOAPBody().getFault(); span.setTag("soap.fault.reason", fault.getFaultString()); span.setTag("soap.fault.code", fault.getFaultCode()); } catch (SOAPException e) { logger.warn("Exception while trying to access SOAP fault (this exception was suppressed)", e); } return true; }
SOAPBody body = originalMsg.getSOAPPart().getEnvelope().getBody(); body.removeContents(); SOAPFault soapFault = body.addFault(); soapFault.setFaultActor(sf.getFault().getFaultActor()); if (sf.getFault().hasDetail()) { Node nd = originalMsg.getSOAPPart().importNode( sf.getFault().getDetail() .getFirstChild(), true); if (sf.hasDetails()) { soapFault.addDetail(); Node nd = originalMsg.getSOAPPart().importNode(sf.getDetail(), true); nd = nd.getFirstChild(); while (nd != null) { soapFault.getDetail().appendChild(nd); nd = nd.getNextSibling(); soapFault.setFaultString(exception.getMessage()); SAAJUtils.setFaultCode(soapFault, new QName("http://cxf.apache.org/faultcode", "HandleFault"));
if (m != null && !MessageUtils.isOutbound(message)) { try { SAAJUtils.getBody(m).removeContents(); W3CDOMStreamWriter writer = new W3CDOMStreamWriter(SAAJUtils.getBody(m)); StaxUtils.copy(s, writer); writer.close(); if (mode == Service.Mode.MESSAGE) { s = new DOMSource(m.getSOAPPart()); } else { s = new DOMSource(SAAJUtils.getBody(m).getFirstChild()); s = new DOMSource(msg.getSOAPPart()); } catch (Exception e) { throw new Fault(e);
MessageFactory messageFactory = MessageFactory.newInstance(); SOAPMessage soapMessage = messageFactory.createMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); SOAPEnvelope envelope = soapPart.getEnvelope(); SOAPBody soapBody = envelope.getBody(); soapBody.addDocument(soapBodyDoc); **soapBody.addNamespaceDeclaration("", serverURI);**
public SAXSource invoke(SAXSource request) { QName qn = (QName)ctx.getMessageContext().get(MessageContext.WSDL_OPERATION); if (qn == null) { throw new RuntimeException("No Operation Name"); } SAXSource response = new SAXSource(); try { SOAPMessage msg = factory.createMessage(); msg.getSOAPPart().setContent(request); SOAPBody body = msg.getSOAPBody(); Node n = body.getFirstChild(); while (n.getNodeType() != Node.ELEMENT_NODE) { n = n.getNextSibling(); } if (n.getLocalName().equals(sayHi.getLocalPart())) { response.setInputSource(sayHiInputSource); } else if (n.getLocalName().equals(greetMe.getLocalPart())) { response.setInputSource(greetMeInputSource); } } catch (Exception ex) { ex.printStackTrace(); } return response; }
protected QName getOpQName(Exchange ex, Object data) { SOAPMessageContextImpl sm = (SOAPMessageContextImpl)data; try { SOAPMessage msg = sm.getMessage(); if (msg == null) { return null; } SOAPBody body = SAAJUtils.getBody(msg); if (body == null) { return null; } org.w3c.dom.Node nd = body.getFirstChild(); while (nd != null && !(nd instanceof org.w3c.dom.Element)) { nd = nd.getNextSibling(); } if (nd != null) { return new QName(nd.getNamespaceURI(), nd.getLocalName()); } } catch (SOAPException e) { //ignore, nothing we can do } return null; }
private QName getOperationName(MessageContext msgContext) { SOAPMessageContext soapMessageContext = (SOAPMessageContext) msgContext; SOAPMessage soapMessage = soapMessageContext.getMessage(); SOAPBody soapBody; try { soapBody = soapMessage.getSOAPBody(); Node child = soapBody.getFirstChild(); String childNamespace = child.getNamespaceURI(); String childName = child.getLocalName(); return new QName(childNamespace, childName); } catch (SOAPException e) { logger.jbossWSErrorGettingOperationName(e); } return null; }
version = ((SoapMessage)msg).getVersion(); soapMessage = SAAJFactoryResolver.createMessageFactory(version).createMessage(); msg.setContent(SOAPMessage.class, soapMessage); SOAPFault soapFault = body.addFault(); soapFault.setFaultActor(sf.getFault().getFaultActor()); if (sf.getFault().hasDetail()) { Node nd = soapMessage.getSOAPPart().importNode(sf.getFault().getDetail(), true); nd = nd.getFirstChild(); soapFault.addDetail(); while (nd != null) { soapFault.getDetail().appendChild(nd); nd = nd.getNextSibling(); if (sf.hasDetails()) { soapFault.addDetail(); Node nd = soapMessage.getSOAPPart().importNode(sf.getDetail(), true); nd = nd.getFirstChild(); while (nd != null) { soapFault.getDetail().appendChild(nd); new QName("http://cxf.apache.org/faultcode", "HandlerFault")); soapFault.setFaultString(exception.getMessage());
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); } }
/** * Retrieves the first element name in the SOAP Envelope's body. * * @param soapMessage The SOAP message. * @return The first Element QName. * @throws SOAPException If the SOAP message is invalid */ public static QName getFirstBodyElement(final SOAPMessage soapMessage) throws SOAPException { QName operationName = null; SOAPBody body = soapMessage.getSOAPPart().getEnvelope().getBody(); if (body != null) { Iterator<Node> nodes = body.getChildElements(); Node node = null; while (nodes.hasNext()) { node = nodes.next(); if (node instanceof Element) { operationName = new QName(node.getNamespaceURI(), node.getLocalName()); } } } return operationName; }
soapFault = binding.getMessageFactory().createMessage() .getSOAPPart().getEnvelope().getBody().addFault(); } catch (Throwable t2) { if (!soapFault.getNamespaceURI().equals(((SoapFault)ex).getFaultCode().getNamespaceURI()) && SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE .equals(((SoapFault)ex).getFaultCode().getNamespaceURI())) { Node nd = soapFault.getOwnerDocument().importNode(((SoapFault)ex).getDetail(), true); nd = nd.getFirstChild(); soapFault.addDetail(); while (nd != null) { Node next = nd.getNextSibling(); soapFault.getDetail().appendChild(nd); nd = next;
public void addFault( com.sun.xml.wss.impl.WssSoapFaultException sfe,SOAPMessage soapMessage,boolean isSOAP12) throws SOAPException{ SOAPBody body = soapMessage.getSOAPBody(); body.removeContents(); soapMessage.removeAllAttachments(); QName faultCode = sfe.getFaultCode(); Name faultCodeName = null; if(faultCode == null){ faultCode = new QName(SOAPConstants.URI_NS_SOAP_ENVELOPE,"Client"); } if(isSOAP12){ SOAPFault fault = body.addFault(SOAPConstants.SOAP_SENDER_FAULT,sfe.getMessage()); fault.appendFaultSubcode(faultCode); }else{ body.addFault(faultCode, sfe.getMessage()); } NodeList list = soapMessage.getSOAPPart().getEnvelope().getElementsByTagNameNS(MessageConstants.WSSE_NS,MessageConstants.WSSE_SECURITY_LNAME); if(list.getLength() > 0){ Node node = list.item(0); node.getParentNode().removeChild(node); } }
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)); }
public SOAPMessage invoke(SOAPMessage request) { try { MessageFactory messageFactory = MessageFactory.newInstance(); SOAPMessage msg = messageFactory.createMessage(); msg.getSOAPBody().addFault(new QName("http://schemas.xmlsoap.org/soap/envelope/", "Server"), "Foo"); return msg; } catch (Exception e) { e.printStackTrace(); } return null; }
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)); }
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();
if (soapMessage.countAttachments() > 0) { message.put("write.attachments", Boolean.TRUE); try { MessageFactory factory = saajOut.getFactory(message); soapMessage = factory.createMessage(); SOAPPart part = soapMessage.getSOAPPart(); if (o instanceof Source) { StaxUtils.copy((Source)o, new SAAJStreamWriter(part)); DocumentFragment frag = soapMessage.getSOAPPart().createDocumentFragment(); try { Node body = SAAJUtils.getBody(soapMessage); Node nd = body.getFirstChild(); while (nd != null) { if (nd instanceof SOAPFault) { validateFault(message, (SOAPFault)nd, bop); body.removeChild(nd); nd = DOMUtils.getDomElement(nd); frag.appendChild(nd); nd = SAAJUtils.getBody(soapMessage).getFirstChild();
public SOAPMessage processSOAP(Exchange exchange) { // Since the Camel-CXF endpoint uses a list to store the parameters // and bean component uses the bodyAs expression to get the value // we'll need to deal with the parameters ourself SOAPMessage soapMessage = (SOAPMessage)exchange.getIn().getBody(List.class).get(0); if (soapMessage == null) { System.out.println("Incoming null message detected..."); return createDefaultSoapMessage("Greetings from Apache Camel!!!!", "null"); } try { SOAPPart sp = soapMessage.getSOAPPart(); SOAPEnvelope se = sp.getEnvelope(); SOAPBody sb = se.getBody(); String requestText = sb.getFirstChild().getTextContent(); System.out.println(requestText); return createDefaultSoapMessage("Greetings from Apache Camel!!!!", requestText); } catch (Exception e) { e.printStackTrace(); return createDefaultSoapMessage("Greetings from Apache Camel!!!!", e.getClass().getName()); } }
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; }