Example usage for javax.xml.soap SOAPMessage getSOAPPart

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

Introduction

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

Prototype

public abstract SOAPPart getSOAPPart();

Source Link

Document

Gets the SOAP part of this SOAPMessage object.

Usage

From source file:org.jboss.jaxr.juddi.transport.SaajTransport.java

private SOAPMessage createSOAPMessage(Element elem) throws Exception {
    String prefix = "uddi";
    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
    String uddins = IRegistry.UDDI_V2_NAMESPACE;
    Name bodyName = factory.createName(elem.getNodeName(), prefix, uddins);
    SOAPBodyElement bodyElement = soapBody.addBodyElement(bodyName);
    bodyElement.addNamespaceDeclaration(prefix, uddins);
    appendAttributes(bodyElement, elem.getAttributes(), factory);
    appendElements(bodyElement, elem.getChildNodes(), factory);
    return message;
}

From source file:org.jboss.jaxr.juddi.transport.WS4EESaajTransport.java

public Element send(Element request, URL endpointURL) throws RegistryException {
    log.debug("Request message:" + XMLUtils.toString(request));
    if ("true".equalsIgnoreCase(debugProp))
        System.out.println("Request Element:" + XMLUtils.toString(request));

    Element response = null;/*from   w ww  . j a  v a 2  s . co m*/
    try {
        MessageFactory msgFactory = MessageFactory.newInstance();
        SOAPMessage message = msgFactory.createMessage();
        message.getSOAPHeader().detachNode();
        SOAPPart soapPart = message.getSOAPPart();
        SOAPBody soapBody = soapPart.getEnvelope().getBody();
        soapBody.addChildElement(getSOAPElement(soapBody, request));
        //There seems to be a bug in the Saaj/Axis implementation that requires
        //message to be written to an output stream
        ByteArrayOutputStream by = new ByteArrayOutputStream();
        message.writeTo(by); //Does not do anything
        by.close();
        if ("true".equalsIgnoreCase(debugProp))
            message.writeTo(System.out);

        //Make the SAAJ Call now
        SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
        SOAPConnection connection = soapConnectionFactory.createConnection();
        SOAPMessage soapResponse = connection.call(message, endpointURL);
        if ("true".equalsIgnoreCase(debugProp)) {
            System.out.println("Response is:");
            soapResponse.writeTo(System.out);
        }

        soapBody = soapResponse.getSOAPBody();
        boolean hasFault = soapBody.hasFault();
        if (hasFault) {
            SOAPFault soapFault = soapBody.getFault();
            String faultStr = soapFault.getFaultCode() + "::" + soapFault.getFaultString();
            throw new RegistryException(faultStr);
        }
        response = getFirstChildElement(soapBody);
    } catch (Exception ex) {
        ex.printStackTrace();
        log.error(ex);
        throw new RegistryException(ex);
    }

    log.debug("Response message:" + XMLUtils.getText(response));

    return response;
}

From source file:org.jbpm.bpel.integration.server.SoapHandler.java

public boolean handleResponse(MessageContext messageContext) throws JAXRPCException {
    Map parts = (Map) messageContext.getProperty(MESSAGE_PARTS_PROP);
    SOAPFaultException faultException = (SOAPFaultException) messageContext.getProperty(FAULT_EXCEPTION_PROP);

    // absence of both parts and fault means one-way operation
    if (parts == null && faultException == null)
        return true;

    String operationName = (String) messageContext.getProperty(OPERATION_NAME_PROP);
    SOAPMessage soapMessage = ((SOAPMessageContext) messageContext).getMessage();

    JbpmContext jbpmContext = integrationControl.getIntegrationServiceFactory().getJbpmConfiguration()
            .createJbpmContext();/*  ww  w  . j  a v  a  2s  . c om*/
    try {
        lookupEndpointMetadata(messageContext);

        SOAPEnvelope envelope = soapMessage.getSOAPPart().getEnvelope();
        // remove existing body, it might have undesirable content
        SOAPBody body = envelope.getBody();
        body.detachNode();
        // re-create body
        body = envelope.addBody();

        if (faultException == null)
            writeOutput(operationName, soapMessage, parts);
        else {
            String faultName = (String) messageContext.getProperty(FAULT_NAME_PROP);
            writeFault(operationName, soapMessage, faultName, parts, faultException);
        }
    }
    /*
     * NO need to set jbpm context as rollback only for any exception, since operations in try-block
     * only read definitions from database
     */
    catch (SOAPException e) {
        throw new JAXRPCException("could not compose outbound soap message", e);
    } finally {
        jbpmContext.close();
    }
    return true;
}

From source file:org.jbpm.bpel.integration.soap.SoapUtilTest.java

public void testCopyChildNodes_soapDom() throws Exception {
    String xml = "<lunch xmlns:produce='urn:example:produce'" + " xmlns='urn:example:meal'>"
            + " <time>1200</time>" + " <produce:lettuce>0.1lb</produce:lettuce>"
            + " <fish:fillet xmlns:fish='urn:example:fish'>0.25lb</fish:fillet>" + " <padding xmlns=''/>"
            + "</lunch>";
    Element source = XmlUtil.parseText(xml);

    SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
    SOAPEnvelope envelope = soapMessage.getSOAPPart().getEnvelope();
    SOAPElement target = envelope.getBody().addBodyElement(envelope.createName("detail"));

    // perform the copy
    SoapUtil.copyChildNodes(target, source);

    // qualified, prefixless element
    SOAPElement time = SoapUtil.getElement(target, "urn:example:meal", "time");
    assertEquals(SoapUtil.DEFAULT_NAMESPACE_PREFIX, time.getPrefix());
    // qualified, prefixed element
    SOAPElement lettuce = SoapUtil.getElement(target, "urn:example:produce", "lettuce");
    assertEquals("produce", lettuce.getPrefix());
    // parent qualified, prefixed element
    SOAPElement fillet = SoapUtil.getElement(target, "urn:example:fish", "fillet");
    assertEquals("fish", fillet.getPrefix());
    // local element
    SOAPElement padding = SoapUtil.getElement(target, "padding");
    assertNull(padding.getPrefix());// w  w  w. j  av a2s.c  o  m
    assertNull(padding.getNamespaceURI());
}

From source file:org.jbpm.bpel.integration.soap.SoapUtilTest.java

public void testCopyChildElement_domSoap() throws Exception {
    // <soap:Envelope xmlns:soap='${SOAPConstants.URI_NS_SOAP_ENVELOPE}'>
    // <soap:Body xmlns:fish='urn:example:fish'>
    // <meal:lunch xmlns:produce='urn:example:produce'
    // xmlns:meal='urn:example:meal'>
    // <padding />
    // </meal:lunch>
    // </soap:Body>
    // </soap:Envelope>
    SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
    SOAPEnvelope envelope = soapMessage.getSOAPPart().getEnvelope();

    SOAPBody body = envelope.getBody();
    body.addNamespaceDeclaration("fish", "urn:example:fish");

    Name lunchName = envelope.createName("lunch", "meal", "urn:example:meal");
    SOAPElement lunch = body.addBodyElement(lunchName);
    lunch.addNamespaceDeclaration("produce", "urn:example:produce");
    lunch.addNamespaceDeclaration("meal", "urn:example:meal");

    SOAPElement source = SoapUtil.addChildElement(lunch, "padding");
    Element parent = XmlUtil.createElement("urn:example:meal", "lunch");

    // perform the copy
    SoapUtil.copyChildElement(parent, source);
    Element padding = XmlUtil.getElement(parent, "padding");

    // unqualified element
    assertNull(padding.getPrefix());/*  w w w . j a  v a  2 s.c  om*/

    // reload
    // parent = writeAndRead(parent);
    padding = XmlUtil.getElement(parent, "padding");

    // unqualified element
    assertNull(padding.getPrefix());
}

From source file:org.jbpm.bpel.integration.soap.SoapUtilTest.java

public void testCopy_soapDom_qualifiedNoPrefix() throws Exception {
    String xml = "<ReverseAndConcatNames xmlns='http://my.namespace'>" + " <firstName>Martin</firstName>"
            + " <secondName>Steinle</secondName>" + "</ReverseAndConcatNames>";
    Element source = XmlUtil.parseText(xml);

    SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
    SOAPEnvelope envelope = soapMessage.getSOAPPart().getEnvelope();
    SOAPElement target = envelope.getBody().addBodyElement(envelope.createName("detail"));

    // perform the copy
    SoapUtil.copy(target, source);/* w  w w . j  a v a2  s.  c o  m*/

    assertEquals("http://my.namespace", target.getNamespaceURI(SoapUtil.DEFAULT_NAMESPACE_PREFIX));
    // qualified elements
    SOAPElement firstName = SoapUtil.getElement(target, "http://my.namespace", "firstName");
    assertEquals("Martin", firstName.getValue());
    SOAPElement secondName = SoapUtil.getElement(target, "http://my.namespace", "secondName");
    assertEquals("Steinle", secondName.getValue());
}

From source file:org.libreplan.importers.TimSoapClient.java

/**
 * Creates request message to be send to the SOAP server
 *
 * @param clazz/*from w w w. j  a  v  a2 s.c om*/
 *            object to be marshaled
 * @param userName
 *            the user name
 * @param password
 *            the password
 * @return the created soap message
 * @throws SOAPException
 *             if unable to create message or envelope
 * @throws JAXBException
 *             if unable to marshal the clazz
 */
private static <T> SOAPMessage createRequest(T clazz, String userName, String password)
        throws SOAPException, JAXBException {

    SOAPMessage message = createMessage();

    addAuthorization(message, userName, password);

    SOAPEnvelope soapEnvelope = createEnvelope(message.getSOAPPart());

    SOAPBody soapBody = soapEnvelope.getBody();
    marshal(clazz, soapBody);

    message.saveChanges();

    return message;
}

From source file:org.mule.modules.paypal.util.PayPalAPIHelper.java

private static SOAPMessage createGetPalDetailsSOAPRequest(@NotNull String username, @NotNull String password,
        @NotNull String appId, String signature) throws Exception {
    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage soapMessage = messageFactory.createMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();

    // SOAP Envelope
    SOAPEnvelope envelope = soapPart.getEnvelope();

    envelope.addNamespaceDeclaration(PREFIX_1, SOAP_HEADER_CREDENTIAL_NAMESPACE_1);
    envelope.addNamespaceDeclaration(PREFIX_2, SOAP_HEADER_CREDENTIAL_NAMESPACE_2);

    SOAPHeader soapHeader = envelope.getHeader();
    if (soapHeader == null)
        soapHeader = envelope.addHeader();

    SOAPElement soapReqElement = soapHeader.addChildElement(rootStringValue, PREFIX_1);
    SOAPElement soapCredElement = soapReqElement.addChildElement(subRootStringValue, PREFIX_2);
    soapCredElement.addChildElement(appIdStringValue, PREFIX_2).addTextNode(appId);
    soapCredElement.addChildElement(usernameStringValue, PREFIX_2).addTextNode(username);
    soapCredElement.addChildElement(passwordStringValue, PREFIX_2).addTextNode(password);
    soapCredElement.addChildElement("Signature", PREFIX_2).addTextNode(signature);

    // SOAP Body//  w  ww  .j  a  v a2  s. com
    SOAPBody soapBody = envelope.getBody();
    SOAPElement soapBodyElem = soapBody.addChildElement("GetPalDetailsReq", PREFIX_1);
    SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("GetPalDetailsRequest", PREFIX_1);
    soapBodyElem1.addChildElement("Version", PREFIX_2).addTextNode("51");
    soapMessage.saveChanges();

    return soapMessage;
}

From source file:org.mule.transport.soap.axis.extensions.MuleSoapHeadersHandler.java

/**
 * Method processClientResponse//from  w  ww . j  a v a  2  s. co  m
 * 
 * @param msgContext
 */
protected void processClientResponse(MessageContext msgContext) throws Exception {
    SOAPMessage msg = msgContext.getMessage();
    if (msg == null) {
        return;
    }
    SOAPEnvelope env = msg.getSOAPPart().getEnvelope();
    MuleSoapHeaders headers = new MuleSoapHeaders(env.getHeader());

    if (headers.getCorrelationId() != null) {
        msgContext.setProperty(MuleProperties.MULE_CORRELATION_ID_PROPERTY, headers.getCorrelationId());
    }
    if (headers.getCorrelationGroup() != null) {
        msgContext.setProperty(MuleProperties.MULE_CORRELATION_GROUP_SIZE_PROPERTY,
                headers.getCorrelationGroup());
    }
    if (headers.getCorrelationSequence() != null) {
        msgContext.setProperty(MuleProperties.MULE_CORRELATION_SEQUENCE_PROPERTY,
                headers.getCorrelationSequence());
    }

    if (headers.getReplyTo() != null) {
        msgContext.setProperty(MuleProperties.MULE_REPLY_TO_PROPERTY, headers.getReplyTo());
    }
}

From source file:org.mule.transport.soap.axis.extensions.MuleSoapHeadersHandler.java

/**
 * Method processServerRequest/*from   w  ww.  j  a  v  a 2  s . c  o  m*/
 * 
 * @param msgContext
 * @throws Exception
 */
protected void processServerRequest(MessageContext msgContext) throws Exception {
    SOAPMessage msg = msgContext.getMessage();
    if (msg == null) {
        return;
    }
    MuleSoapHeaders headers = new MuleSoapHeaders(msg.getSOAPPart().getEnvelope().getHeader());
    msgContext.setProperty(MuleSoapHeaders.ENV_REQUEST_HEADERS, headers);
}