Example usage for javax.xml.soap SOAPMessage getSOAPBody

List of usage examples for javax.xml.soap SOAPMessage getSOAPBody

Introduction

In this page you can find the example usage for javax.xml.soap SOAPMessage getSOAPBody.

Prototype

public SOAPBody getSOAPBody() throws SOAPException 

Source Link

Document

Gets the SOAP Body contained in this SOAPMessage object.

Usage

From source file:com.nortal.jroad.endpoint.AbstractXTeeBaseEndpoint.java

@SuppressWarnings("unchecked")
protected SOAPElement createXteeMessageStructure(SOAPMessage requestMessage, SOAPMessage responseMessage)
        throws Exception {
    SOAPUtil.addBaseMimeHeaders(responseMessage);
    SOAPUtil.addBaseNamespaces(responseMessage);
    if (!metaService) {
        // Assign xroad namespaces according to request
        List<String> xteeNamespaces = new ArrayList<String>();
        xteeNamespaces.add(version.getNamespaceUri());
        if (XRoadProtocolVersion.V4_0 == version) {
            xteeNamespaces.add(XTeeWsdlDefinition.XROAD_IDEN_NAMESPACE);
        }/* w  w  w .ja va2  s .  co  m*/

        Iterator<String> prefixes = requestMessage.getSOAPPart().getEnvelope().getNamespacePrefixes();
        while (prefixes.hasNext()) {
            String nsPrefix = (String) prefixes.next();
            String nsURI = requestMessage.getSOAPPart().getEnvelope().getNamespaceURI(nsPrefix).toLowerCase();
            if (xteeNamespaces.contains(nsURI)) {
                SOAPUtil.addNamespace(responseMessage, nsPrefix, nsURI);
            }
        }

        // Copy headers from request
        NodeList reqHeaders = requestMessage.getSOAPHeader().getChildNodes();
        for (int i = 0; i < reqHeaders.getLength(); i++) {
            Node reqHeader = reqHeaders.item(i);
            if (reqHeader.getNodeType() != Node.ELEMENT_NODE) {
                continue;
            }
            Node rspHeader = responseMessage.getSOAPPart().importNode(reqHeader, true);
            responseMessage.getSOAPHeader().appendChild(rspHeader);
        }
    }
    responseMessage.getSOAPPart().getEnvelope().setEncodingStyle("http://schemas.xmlsoap.org/soap/encoding/");

    Node teenusElement = SOAPUtil.getFirstNonTextChild(requestMessage.getSOAPBody());
    if (teenusElement.getPrefix() == null || teenusElement.getNamespaceURI() == null) {
        throw new IllegalStateException("Service request is missing namespace.");
    }
    SOAPUtil.addNamespace(responseMessage, teenusElement.getPrefix(), teenusElement.getNamespaceURI());

    String teenusElementName = teenusElement.getLocalName();
    if (teenusElementName.endsWith(SuffixBasedMessagesProvider.DEFAULT_REQUEST_SUFFIX)) {
        teenusElementName = teenusElementName.substring(0,
                teenusElementName.lastIndexOf(SuffixBasedMessagesProvider.DEFAULT_REQUEST_SUFFIX));
    }
    teenusElementName += SuffixBasedMessagesProvider.DEFAULT_RESPONSE_SUFFIX;
    return responseMessage.getSOAPBody().addChildElement(teenusElementName, teenusElement.getPrefix(),
            teenusElement.getNamespaceURI());
}

From source file:it.cnr.icar.eric.server.interfaces.soap.RegistryBSTServlet.java

private SOAPMessage createFaultSOAPMessage(java.lang.Throwable e, SOAPHeader sh) {
    SOAPMessage msg = null;
    if (log.isDebugEnabled()) {
        log.debug("Creating Fault SOAP Message with Throwable:", e);
    }//from w w  w  . j  a  va  2 s .  co  m
    try {
        // Will this method be "legacy" ebRS 3.0 spec-compliant and
        // return a URN as the <faultcode/> value? Default expectation
        // is of a an older client. Overridden to instead be SOAP
        // 1.1-compliant and return a QName as the faultcode value when
        // we know (for sure) client supports new approach.
        boolean legacyFaultCode = true;

        // get SOAPHeaderElement list from the received message
        // TODO: if additional capabilities are needed, move code to
        // elsewhere
        if (null != sh) {
            Iterator<?> headers = sh.examineAllHeaderElements();
            while (headers.hasNext()) {
                Object obj = headers.next();

                // confirm expected Iterator content
                if (obj instanceof SOAPHeaderElement) {
                    SOAPHeaderElement header = (SOAPHeaderElement) obj;
                    Name headerName = header.getElementName();

                    // check this SOAP header for relevant capability
                    // signature
                    if (headerName.getLocalName().equals(BindingUtility.SOAP_CAPABILITY_HEADER_LocalName)
                            && headerName.getURI().equals(BindingUtility.SOAP_CAPABILITY_HEADER_Namespace)
                            && header.getValue().equals(BindingUtility.SOAP_CAPABILITY_ModernFaultCodes)) {
                        legacyFaultCode = false;
                        // only interested in one client capability
                        break;
                    }
                }
            }
        }

        msg = MessageFactory.newInstance().createMessage();
        SOAPEnvelope env = msg.getSOAPPart().getEnvelope();
        SOAPFault fault = msg.getSOAPBody().addFault();

        // set faultCode
        String exceptionName = e.getClass().getName();
        // TODO: SAAJ 1.3 has introduced preferred QName interfaces
        Name name = env.createName(exceptionName, "ns1", BindingUtility.SOAP_FAULT_PREFIX);
        fault.setFaultCode(name);
        if (legacyFaultCode) {
            // we now have an element child, munge its text (hack alert)
            Node faultCode = fault.getElementsByTagName("faultcode").item(0);
            // Using Utility.setTextContent() implementation since Java
            // WSDP 1.5 (containing an earlier DOM API) does not
            // support Node.setTextContent().
            Utility.setTextContent(faultCode, BindingUtility.SOAP_FAULT_PREFIX + ":" + exceptionName);
        }

        // set faultString
        String errorMsg = e.getMessage();
        if (errorMsg == null) {
            errorMsg = "NULL";
        }
        fault.setFaultString(errorMsg);

        // create faultDetail with one entry
        Detail det = fault.addDetail();

        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        String str = sw.toString();

        name = env.createName("StackTrace", "rs", "urn:oasis:names:tc:ebxml-regrep:xsd:rs:3.0");
        DetailEntry de = det.addDetailEntry(name);
        de.setValue(str);
        // de.addTextNode(str);

        // TODO: Need to put baseURL for this registry here

        msg.saveChanges();
    } catch (SOAPException ex) {
        log.warn(ex, ex);
        // otherwise ignore the problem updating part of the message
    }

    return msg;
}

From source file:it.cnr.icar.eric.server.interfaces.soap.RegistrySAMLServlet.java

/**
 * This method is a copy of the respective method from RegistrySOAPServlet.
 * The SAML-based Servlet returns X.509 certificate base SOAP messages.
 * //  w  w w.ja v  a  2  s  .com
 */

private SOAPMessage createFaultSOAPMessage(java.lang.Throwable e, SOAPHeader sh) {
    SOAPMessage msg = null;

    if (log.isDebugEnabled()) {
        log.debug("Creating Fault SOAP Message with Throwable:", e);
    }

    try {
        // Will this method be "legacy" ebRS 3.0 spec-compliant and
        // return a URN as the <faultcode/> value? Default expectation
        // is of a an older client. Overridden to instead be SOAP
        // 1.1-compliant and return a QName as the faultcode value when
        // we know (for sure) client supports new approach.
        boolean legacyFaultCode = true;

        // get SOAPHeaderElement list from the received message
        // TODO: if additional capabilities are needed, move code to
        // elsewhere
        if (null != sh) {
            Iterator<?> headers = sh.examineAllHeaderElements();
            while (headers.hasNext()) {
                Object obj = headers.next();

                // confirm expected Iterator content
                if (obj instanceof SOAPHeaderElement) {
                    SOAPHeaderElement header = (SOAPHeaderElement) obj;
                    Name headerName = header.getElementName();

                    // check this SOAP header for relevant capability
                    // signature
                    if (headerName.getLocalName().equals(BindingUtility.SOAP_CAPABILITY_HEADER_LocalName)
                            && headerName.getURI().equals(BindingUtility.SOAP_CAPABILITY_HEADER_Namespace)
                            && header.getValue().equals(BindingUtility.SOAP_CAPABILITY_ModernFaultCodes)) {
                        legacyFaultCode = false;
                        // only interested in one client capability
                        break;
                    }
                }
            }
        }

        msg = MessageFactory.newInstance().createMessage();
        SOAPEnvelope env = msg.getSOAPPart().getEnvelope();
        SOAPFault fault = msg.getSOAPBody().addFault();

        // set faultCode
        String exceptionName = e.getClass().getName();

        // TODO: SAAJ 1.3 has introduced preferred QName interfaces
        Name name = env.createName(exceptionName, "ns1", BindingUtility.SOAP_FAULT_PREFIX);
        fault.setFaultCode(name);
        if (legacyFaultCode) {
            // we now have an element child, munge its text (hack alert)
            Node faultCode = fault.getElementsByTagName("faultcode").item(0);

            // Using Utility.setTextContent() implementation since Java
            // WSDP 1.5 (containing an earlier DOM API) does not
            // support Node.setTextContent().
            Utility.setTextContent(faultCode, BindingUtility.SOAP_FAULT_PREFIX + ":" + exceptionName);
        }

        // set faultString
        String errorMsg = e.getMessage();
        if (errorMsg == null) {
            errorMsg = "NULL";
        }
        fault.setFaultString(errorMsg);

        // create faultDetail with one entry
        Detail det = fault.addDetail();

        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        String str = sw.toString();

        name = env.createName("StackTrace", "rs", "urn:oasis:names:tc:ebxml-regrep:xsd:rs:3.0");

        DetailEntry de = det.addDetailEntry(name);
        de.setValue(str);
        // de.addTextNode(str);

        // TODO: Need to put baseURL for this registry here

        msg.saveChanges();

    } catch (SOAPException ex) {
        log.warn(ex, ex);
        // otherwise ignore the problem updating part of the message
    }

    return msg;
}

From source file:edu.unc.lib.dl.util.TripleStoreQueryServiceMulgaraImpl.java

private String sendTQL(String query) {
    log.debug(query);//from   w w  w.  ja v a  2s . c  o m
    String result = null;
    SOAPMessage reply = null;
    SOAPConnection connection = null;
    try {
        // Next, create the actual message
        MessageFactory messageFactory = MessageFactory.newInstance();
        SOAPMessage message = messageFactory.createMessage();
        message.getMimeHeaders().setHeader("SOAPAction", "itqlbean:executeQueryToString");
        SOAPBody soapBody = message.getSOAPPart().getEnvelope().getBody();
        soapBody.addNamespaceDeclaration("xsd", JDOMNamespaceUtil.XSD_NS.getURI());
        soapBody.addNamespaceDeclaration("xsi", JDOMNamespaceUtil.XSI_NS.getURI());
        soapBody.addNamespaceDeclaration("itqlbean", this.getItqlEndpointURL());
        SOAPElement eqts = soapBody.addChildElement("executeQueryToString", "itqlbean");
        SOAPElement queryStr = eqts.addChildElement("queryString", "itqlbean");
        queryStr.setAttributeNS(JDOMNamespaceUtil.XSI_NS.getURI(), "xsi:type", "xsd:string");
        CDATASection queryCDATA = message.getSOAPPart().createCDATASection(query);
        queryStr.appendChild(queryCDATA);
        message.saveChanges();

        // First create the connection
        SOAPConnectionFactory soapConnFactory = SOAPConnectionFactory.newInstance();
        connection = soapConnFactory.createConnection();
        reply = connection.call(message, this.getItqlEndpointURL());

        if (reply.getSOAPBody().hasFault()) {
            reportSOAPFault(reply);
            if (log.isDebugEnabled()) {
                // log the full soap body response
                DOMBuilder builder = new DOMBuilder();
                org.jdom2.Document jdomDoc = builder.build(reply.getSOAPBody().getOwnerDocument());
                log.debug(new XMLOutputter().outputString(jdomDoc));
            }
        } else {
            NodeList nl = reply.getSOAPPart().getEnvelope().getBody().getElementsByTagNameNS("*",
                    "executeQueryToStringReturn");
            if (nl.getLength() > 0) {
                result = nl.item(0).getFirstChild().getNodeValue();
            }
            log.debug(result);
        }
    } catch (SOAPException e) {
        log.error("Failed to prepare or send iTQL via SOAP", e);
        throw new RuntimeException("Cannot query triple store at " + this.getItqlEndpointURL(), e);
    } finally {
        try {
            connection.close();
        } catch (SOAPException e) {
            log.error("Failed to close SOAP connection", e);
            throw new RuntimeException(
                    "Failed to close SOAP connection for triple store at " + this.getItqlEndpointURL(), e);
        }
    }
    return result;
}

From source file:org.keycloak.testsuite.adapter.servlet.SAMLServletAdapterTest.java

@Test
public void testSuccessfulEcpFlow() throws Exception {
    Response authnRequestResponse = ClientBuilder.newClient().target(ecpSPPage.toString()).request()
            .header("Accept", "text/html; application/vnd.paos+xml")
            .header("PAOS", "ver='urn:liberty:paos:2003-08' ;'urn:oasis:names:tc:SAML:2.0:profiles:SSO:ecp'")
            .get();//from w w  w  .j ava 2s .co  m

    SOAPMessage authnRequestMessage = MessageFactory.newInstance().createMessage(null,
            new ByteArrayInputStream(authnRequestResponse.readEntity(byte[].class)));

    //printDocument(authnRequestMessage.getSOAPPart().getContent(), System.out);

    Iterator<SOAPHeaderElement> it = authnRequestMessage.getSOAPHeader().<SOAPHeaderElement>getChildElements(
            new QName("urn:oasis:names:tc:SAML:2.0:profiles:SSO:ecp", "Request"));
    SOAPHeaderElement ecpRequestHeader = it.next();
    NodeList idpList = ecpRequestHeader.getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:protocol",
            "IDPList");

    Assert.assertThat("No IDPList returned from Service Provider", idpList.getLength(), is(1));

    NodeList idpEntries = idpList.item(0).getChildNodes();

    Assert.assertThat("No IDPEntry returned from Service Provider", idpEntries.getLength(), is(1));

    String singleSignOnService = null;

    for (int i = 0; i < idpEntries.getLength(); i++) {
        Node item = idpEntries.item(i);
        NamedNodeMap attributes = item.getAttributes();
        Node location = attributes.getNamedItem("Loc");

        singleSignOnService = location.getNodeValue();
    }

    Assert.assertThat("Could not obtain SSO Service URL", singleSignOnService, notNullValue());

    Document authenticationRequest = authnRequestMessage.getSOAPBody().getFirstChild().getOwnerDocument();
    String username = "pedroigor";
    String password = "password";
    String pair = username + ":" + password;
    String authHeader = "Basic " + Base64.encodeBytes(pair.getBytes());

    Response authenticationResponse = ClientBuilder.newClient().target(singleSignOnService).request()
            .header(HttpHeaders.AUTHORIZATION, authHeader)
            .post(Entity.entity(DocumentUtil.asString(authenticationRequest), "text/xml"));

    Assert.assertThat(authenticationResponse.getStatus(), is(OK.getStatusCode()));

    SOAPMessage responseMessage = MessageFactory.newInstance().createMessage(null,
            new ByteArrayInputStream(authenticationResponse.readEntity(byte[].class)));

    //printDocument(responseMessage.getSOAPPart().getContent(), System.out);

    SOAPHeader responseMessageHeaders = responseMessage.getSOAPHeader();

    NodeList ecpResponse = responseMessageHeaders.getElementsByTagNameNS(
            JBossSAMLURIConstants.ECP_PROFILE.get(), JBossSAMLConstants.RESPONSE__ECP.get());

    Assert.assertThat("No ECP Response", ecpResponse.getLength(), is(1));

    Node samlResponse = responseMessage.getSOAPBody().getFirstChild();

    Assert.assertThat(samlResponse, notNullValue());

    ResponseType responseType = (ResponseType) SAMLParser.getInstance().parse(samlResponse);
    StatusCodeType statusCode = responseType.getStatus().getStatusCode();

    Assert.assertThat(statusCode.getValue().toString(), is(JBossSAMLURIConstants.STATUS_SUCCESS.get()));
    Assert.assertThat(responseType.getDestination(), is(ecpSPPage.toString() + "/"));
    Assert.assertThat(responseType.getSignature(), notNullValue());
    Assert.assertThat(responseType.getAssertions().size(), is(1));

    SOAPMessage samlResponseRequest = MessageFactory.newInstance().createMessage();

    samlResponseRequest.getSOAPBody().addDocument(responseMessage.getSOAPBody().extractContentAsDocument());

    ByteArrayOutputStream os = new ByteArrayOutputStream();

    samlResponseRequest.writeTo(os);

    Response serviceProviderFinalResponse = ClientBuilder.newClient().target(responseType.getDestination())
            .request().post(Entity.entity(os.toByteArray(), "application/vnd.paos+xml"));

    Map<String, NewCookie> cookies = serviceProviderFinalResponse.getCookies();

    Invocation.Builder resourceRequest = ClientBuilder.newClient().target(responseType.getDestination())
            .request();

    for (NewCookie cookie : cookies.values()) {
        resourceRequest.cookie(cookie);
    }

    Response resourceResponse = resourceRequest.get();
    Assert.assertThat(resourceResponse.readEntity(String.class), containsString("pedroigor"));
}

From source file:org.keycloak.testsuite.adapter.servlet.SAMLServletAdapterTest.java

@Test
public void testInvalidCredentialsEcpFlow() throws Exception {
    Response authnRequestResponse = ClientBuilder.newClient().target(ecpSPPage.toString()).request()
            .header("Accept", "text/html; application/vnd.paos+xml")
            .header("PAOS", "ver='urn:liberty:paos:2003-08' ;'urn:oasis:names:tc:SAML:2.0:profiles:SSO:ecp'")
            .get();/*from  w  w  w .ja v a  2s  .c  o  m*/

    SOAPMessage authnRequestMessage = MessageFactory.newInstance().createMessage(null,
            new ByteArrayInputStream(authnRequestResponse.readEntity(byte[].class)));
    Iterator<SOAPHeaderElement> it = authnRequestMessage.getSOAPHeader()
            .<SOAPHeaderElement>getChildElements(new QName("urn:liberty:paos:2003-08", "Request"));

    it.next();

    it = authnRequestMessage.getSOAPHeader().<SOAPHeaderElement>getChildElements(
            new QName("urn:oasis:names:tc:SAML:2.0:profiles:SSO:ecp", "Request"));
    SOAPHeaderElement ecpRequestHeader = it.next();
    NodeList idpList = ecpRequestHeader.getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:protocol",
            "IDPList");

    Assert.assertThat("No IDPList returned from Service Provider", idpList.getLength(), is(1));

    NodeList idpEntries = idpList.item(0).getChildNodes();

    Assert.assertThat("No IDPEntry returned from Service Provider", idpEntries.getLength(), is(1));

    String singleSignOnService = null;

    for (int i = 0; i < idpEntries.getLength(); i++) {
        Node item = idpEntries.item(i);
        NamedNodeMap attributes = item.getAttributes();
        Node location = attributes.getNamedItem("Loc");

        singleSignOnService = location.getNodeValue();
    }

    Assert.assertThat("Could not obtain SSO Service URL", singleSignOnService, notNullValue());

    Document authenticationRequest = authnRequestMessage.getSOAPBody().getFirstChild().getOwnerDocument();
    String username = "pedroigor";
    String password = "baspassword";
    String pair = username + ":" + password;
    String authHeader = "Basic " + Base64.encodeBytes(pair.getBytes());

    Response authenticationResponse = ClientBuilder.newClient().target(singleSignOnService).request()
            .header(HttpHeaders.AUTHORIZATION, authHeader)
            .post(Entity.entity(DocumentUtil.asString(authenticationRequest), "application/soap+xml"));

    Assert.assertThat(authenticationResponse.getStatus(), is(OK.getStatusCode()));

    SOAPMessage responseMessage = MessageFactory.newInstance().createMessage(null,
            new ByteArrayInputStream(authenticationResponse.readEntity(byte[].class)));
    Node samlResponse = responseMessage.getSOAPBody().getFirstChild();

    Assert.assertThat(samlResponse, notNullValue());

    StatusResponseType responseType = (StatusResponseType) SAMLParser.getInstance().parse(samlResponse);
    StatusCodeType statusCode = responseType.getStatus().getStatusCode();

    Assert.assertThat(statusCode.getStatusCode().getValue().toString(),
            is(not(JBossSAMLURIConstants.STATUS_SUCCESS.get())));
}

From source file:org.apache.axis2.jaxws.client.dispatch.BaseDispatch.java

/**
 * Given a JAXWS Message Context which contains an outbound service-requester Message for a Dispatch client,
 * determine the QName of the first body element contained in that message.
 * //from ww  w  . j  a  v a  2  s . c  o m
 * @param requestMessageCtx requestMessageCtx JAXWS Message Context containing the outbound Dispatch message
 * @return the QName of the first body element contained in the outbound Dispatch message, or null if it 
 * can not be determined.
 */
QName getBodyElementQNameFromDispatchMessage(MessageContext requestMessageCtx) {
    QName bodyElementQName = null;
    Message dispatchMessage = requestMessageCtx.getMessage();
    SOAPMessage soapMessage = dispatchMessage.getAsSOAPMessage();
    try {
        SOAPBody soapBody = soapMessage.getSOAPBody();
        Node firstElement = soapBody.getFirstChild();
        // A Doc/Lit/Bare message may not have a firsElement.  The soap:Body element may be empty if there 
        // are no arguments to the operation.
        if (firstElement != null) {
            String ns = firstElement.getNamespaceURI();
            String lp = firstElement.getLocalName();
            // A Doc/Lit/Bare message may not have a localPart on the element.  That can happen if the first element
            // is the argument value and there is no wrapper element surrounding it.
            if (lp != null) {
                bodyElementQName = new QName(ns, lp);
            }
        }
    } catch (SOAPException e) {
        if (log.isDebugEnabled()) {
            log.debug("Unabled to get the first body element from the outbound dispatch message", e);
        }
    }
    return bodyElementQName;
}

From source file:org.apache.axis2.jaxws.handler.HandlerChainProcessor.java

/**
 * Converts the Exception into an XML Fault Message that is stored on the MEPContext.
 * Note that if the forceConversion flag is true, this conversion will always occur.
 * If the checkMsg flag is true, this conversion only occurs if the Message is not already
 * a Fault (per 9,3,2.1 of the JAX-WS specification)
 * /* www . j  a va  2 s  . co  m*/
 * @param mepCtx  MEPContext
 * @param e Exception
 * @param protocol Protocol
 * @param forceConversion  If true, the Exception is always converted to a Message
 */
public static void convertToFaultMessage(MEPContext mepCtx, Exception e, Protocol protocol, boolean checkMsg) {

    // need to check if message is already a fault message or not,
    // probably by way of a flag (isFault) in the MessageContext or Message
    if (log.isDebugEnabled()) {
        log.debug("start convertToFaultMessge with exception: " + e.getClass().getName());
        log.debug(" checkMsg is : " + checkMsg);
    }

    try {
        // According to the 9.3.2.1, The message is converted into a fault only if it is not already a Fault
        Message messageFromHandler = null;
        if (checkMsg) {
            messageFromHandler = mepCtx.getMessageContext().getMessage();
        }
        if (messageFromHandler != null && messageFromHandler.isFault()) {
            if (log.isDebugEnabled()) {
                log.debug("The Message is already a SOAPFault.  The exception is not converted into a Message");
            }
        } else if (protocol == Protocol.soap11 || protocol == Protocol.soap12) {
            if (log.isDebugEnabled()) {
                log.debug("Converting Exception into a Message");
            }
            String protocolNS = (protocol == Protocol.soap11) ? SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE
                    : SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE;

            // The following set of instructions is used to avoid 
            // some unimplemented methods in the Axis2 SAAJ implementation
            XMLFault xmlFault = MethodMarshallerUtils.createXMLFaultFromSystemException(e);
            javax.xml.soap.MessageFactory mf = SAAJFactory.createMessageFactory(protocolNS);
            SOAPMessage message = mf.createMessage();
            SOAPBody body = message.getSOAPBody();
            SOAPFault soapFault = XMLFaultUtils.createSAAJFault(xmlFault, body);

            MessageFactory msgFactory = (MessageFactory) FactoryRegistry.getFactory(MessageFactory.class);
            Message msg = msgFactory.createFrom(message);
            mepCtx.setMessage(msg);

        } else {
            WebServiceException wse = ExceptionFactory
                    .makeWebServiceException(Messages.getMessage("cFaultMsgErr"));
            if (log.isDebugEnabled()) {
                log.debug("end convertToFaultMessge due to error ", wse);
            }
            throw wse;
        }

    } catch (Exception ex) {
        WebServiceException wse = ExceptionFactory.makeWebServiceException(ex);
        if (log.isDebugEnabled()) {
            log.debug("end convertToFaultMessge due to error ", wse);
        }
        throw wse;
    }

}

From source file:org.apache.hise.engine.jaxws.HISEJaxWSClient.java

@Transactional
public Node invoke(Node message, Node epr) {
    try {/*from  ww w .j  av a  2s  .  c  o m*/

        Dispatch<SOAPMessage> dispatch = destinationService.createDispatch(destinationPort, SOAPMessage.class,
                Service.Mode.MESSAGE);

        String address = getAddressFromEpr(epr);
        if (!address.equals("")) {
            __log.debug("sending to address " + address);
            dispatch.getRequestContext().put(Dispatch.ENDPOINT_ADDRESS_PROPERTY, address);
        }

        SOAPMessage m;
        m = messageFactory.createMessage();
        Document doc = m.getSOAPBody().getOwnerDocument();
        m.getSOAPBody().appendChild(doc.importNode(message, true));
        return dispatch.invoke(m).getSOAPBody();
    } catch (SOAPException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.apache.hise.engine.jaxws.HISEJaxWSService.java

@Transactional
public SOAPMessage invoke(final SOAPMessage request) {
    try {//from   w  ww.j  av  a2  s . co m
        // TransactionStatus tx = transactionManager.getTransaction(new DefaultTransactionDefinition());
        //                    assert transactionManager.isValidateExistingTransaction();
        MessageContext c = context.getMessageContext();
        Object operationInfo = c.get("org.apache.cxf.service.model.OperationInfo");
        QName operation = (QName) operationInfo.getClass().getMethod("getName").invoke(operationInfo);
        QName portType = (QName) c.get("javax.xml.ws.wsdl.interface");
        QName operation2 = (QName) c.get("javax.xml.ws.wsdl.operation");

        Element body = request.getSOAPBody();
        __log.debug("invoking " + request + " operation:" + operation + " portType:" + portType + " operation2:"
                + operation2);
        Node approveResponseHeader = hiseEngine.receive(HISEJaxWSService.this, portType,
                operation.getLocalPart(), body, request.getSOAPHeader());
        SOAPMessage m = messageFactory.createMessage();

        Document doc = m.getSOAPHeader().getOwnerDocument();
        if (approveResponseHeader != null) {
            m.getSOAPHeader().appendChild(doc.importNode(approveResponseHeader, true));
        }
        return m;
    } catch (Exception e) {
        throw new RuntimeException("Error during receiving message ", e);
    }
}