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:com.wandrell.example.swss.test.util.factory.SecureSoapMessages.java

private static final SOAPMessage getMessageToSign(final String pathBase) throws SOAPException, IOException {
    final SOAPMessage soapMessage;
    final SOAPPart soapPart;
    final SOAPEnvelope soapEnvelope;
    final SOAPHeader soapHeader;
    final SOAPHeaderElement secElement;
    final SOAPElement binaryTokenElement;

    soapMessage = SoapMessageUtils.getMessage(pathBase);
    soapPart = soapMessage.getSOAPPart();
    soapEnvelope = soapPart.getEnvelope();
    soapHeader = soapEnvelope.getHeader();

    secElement = soapHeader.addHeaderElement(soapEnvelope.createName("Security", "wsse",
            "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"));
    binaryTokenElement = secElement.addChildElement(soapEnvelope.createName("BinarySecurityToken", "wsse",
            "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"));
    binaryTokenElement.setAttribute("EncodingType",
            "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary");
    binaryTokenElement.setAttribute("ValueType",
            "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3");

    return soapMessage;
}

From source file:com.intuit.tank.http.soap.SOAPRequest.java

public SOAPRequest(HttpClient client) {
    super(client);

    try {/*from   ww  w .  java2 s.c  o m*/
        MessageFactory messageFactory = MessageFactory.newInstance();
        SOAPMessage message = messageFactory.createMessage();
        SOAPPart soapPart = message.getSOAPPart();

        this.soapEnvelope = soapPart.getEnvelope();
        this.soapBody = soapEnvelope.getBody();
    } catch (Exception ex) {

    }
}

From source file:com.nortal.jroad.client.service.callback.XRoadMessageCallback.java

public void doWithMessage(WebServiceMessage message) {
    SaajSoapMessage saajMessage = (SaajSoapMessage) message;
    try {//from  w  w  w  . j  a  v  a2  s.c o  m
        // Add attachments
        if (attachments != null) {
            for (XRoadAttachment attachment : attachments) {
                saajMessage.addAttachment("<" + attachment.getCid() + ">", attachment,
                        attachment.getContentType());
            }
        }
        SOAPMessage soapmess = saajMessage.getSaajMessage();
        SOAPEnvelope env = soapmess.getSOAPPart().getEnvelope();

        protocolVersionStrategy.addNamespaces(env);
        protocolVersionStrategy.addXTeeHeaderElements(env, serviceConfiguration);
    } catch (SOAPException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.drools.server.CxfSoapClientServerTest.java

@org.junit.Test
public void test1() throws Exception {
    ClassPathXmlApplicationContext springContext = new ClassPathXmlApplicationContext(
            "classpath:beans-test.xml");

    SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
    SOAPBody body = soapMessage.getSOAPPart().getEnvelope().getBody();
    QName payloadName = new QName("http://soap.jax.drools.org", "execute", "ns1");

    body.addBodyElement(payloadName);/*  ww w  .j a v  a2 s .  co m*/

    String cmd = "";
    cmd += "<batch-execution lookup=\"ksession1\">\n";
    cmd += "  <insert out-identifier=\"message\">\n";
    cmd += "      <org.drools.server.Message>\n";
    cmd += "         <text>Helllo World</text>\n";
    cmd += "      </org.drools.server.Message>\n";
    cmd += "   </insert>\n";
    cmd += "</batch-execution>\n";

    body.addTextNode(cmd);

    CamelServerApp test = new CamelServerApp();
    String response = test.execute(soapMessage, (CamelContext) springContext.getBean("camel-client-ctx"));

    assertTrue(response.contains("execution-results"));
    assertTrue(response.contains("echo"));
    springContext.stop();
}

From source file:org.kie.camel.component.cxf.CxfSoapTest.java

@Test
public void test1() throws Exception {
    SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
    SOAPBody body = soapMessage.getSOAPPart().getEnvelope().getBody();
    QName payloadName = new QName("http://soap.jax.drools.org", "execute", "ns1");

    body.addBodyElement(payloadName);/*  w  w  w  .j ava 2s .  c  om*/

    String cmd = "";
    cmd += "<batch-execution lookup=\"ksession1\">\n";
    cmd += "  <insert out-identifier=\"salaboy\" disconnected=\"true\">\n";
    cmd += "      <org.kie.pipeline.camel.Person>\n";
    cmd += "         <name>salaboy</name>\n";
    cmd += "         <age>27</age>\n";
    cmd += "      </org.kie.pipeline.camel.Person>\n";
    cmd += "   </insert>\n";
    cmd += "   <fire-all-rules/>\n";
    cmd += "</batch-execution>\n";

    body.addTextNode(cmd);

    Object object = this.context.createProducerTemplate().requestBody("direct://http", soapMessage);
    OutputStream out = new ByteArrayOutputStream();
    out = new ByteArrayOutputStream();
    soapMessage = (SOAPMessage) object;
    soapMessage.writeTo(out);
    String response = out.toString();
    assertTrue(response.contains("fact-handle identifier=\"salaboy\""));
}

From source file:fi.vrk.xroad.catalog.lister.WsdlCdataInterceptor.java

@Override
public boolean handleResponse(MessageContext messageContext, Object o) throws Exception {

    WebServiceMessage response = messageContext.getResponse();

    SaajSoapMessage saajSoapMessage = (SaajSoapMessage) response;
    SOAPMessage soapMessage = saajSoapMessage.getSaajMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();
    SOAPEnvelope envelope = soapPart.getEnvelope();
    SOAPBody body = envelope.getBody();
    Iterator responses = body/*from  w w  w . j  a v a2s.  co  m*/
            .getChildElements(new QName("http://xroad.vrk.fi/xroad-catalog-lister", "GetWsdlResponse"));
    while (responses.hasNext()) {
        Node wsdlResponse = (Node) responses.next();
        NodeList children = wsdlResponse.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            Node child = children.item(i);
            if (child.getLocalName().equals("wsdl")) {
                CDATASection cdat = soapPart.createCDATASection(child.getFirstChild().getNodeValue());
                child.removeChild(child.getFirstChild());
                child.appendChild(cdat);
            }
        }
    }
    return true;
}

From source file:org.drools.camel.component.cxf.CxfSoapTest.java

@Test
public void test1() throws Exception {

    SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
    SOAPBody body = soapMessage.getSOAPPart().getEnvelope().getBody();
    QName payloadName = new QName("http://soap.jax.drools.org", "execute", "ns1");

    body.addBodyElement(payloadName);/*from   w w w.j a va2 s .  c  o  m*/

    String cmd = "";
    cmd += "<batch-execution lookup=\"ksession1\">\n";
    cmd += "  <insert out-identifier=\"salaboy\" disconnected=\"true\">\n";
    cmd += "      <org.drools.pipeline.camel.Person>\n";
    cmd += "         <name>salaboy</name>\n";
    cmd += "         <age>27</age>\n";
    cmd += "      </org.drools.pipeline.camel.Person>\n";
    cmd += "   </insert>\n";
    cmd += "   <fire-all-rules/>\n";
    cmd += "</batch-execution>\n";

    body.addTextNode(cmd);

    Object object = this.context.createProducerTemplate().requestBody("direct://http", soapMessage);

    OutputStream out = new ByteArrayOutputStream();
    out = new ByteArrayOutputStream();
    soapMessage = (SOAPMessage) object;
    soapMessage.writeTo(out);
    String response = out.toString();
    assertTrue(response.contains("fact-handle identifier=\"salaboy\""));
}

From source file:au.com.ors.rest.controller.AutoCheckController.java

private SOAPMessage createSOAPRequest(String driverLicenseNumber, String fullName, String postCode)
        throws Exception {
    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage soapMessage = messageFactory.createMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();

    String serverURI = "http://soap.ors.com.au/pdv";

    SOAPEnvelope envelope = soapPart.getEnvelope();
    envelope.addNamespaceDeclaration("pdv", serverURI);

    SOAPBody soapBody = envelope.getBody();
    SOAPElement soapElement = soapBody.addChildElement("PDVCheckRequestMsg", "pdv");
    SOAPElement soapElementChild1 = soapElement.addChildElement("driverLicenseNumber", "pdv");
    soapElementChild1.addTextNode(driverLicenseNumber);
    SOAPElement soapElementChild2 = soapElement.addChildElement("fullName", "pdv");
    soapElementChild2.addTextNode(fullName);
    SOAPElement soapElementChild3 = soapElement.addChildElement("postCode", "pdv");
    soapElementChild3.addTextNode(postCode);

    // MimeHeaders headers = soapMessage.getMimeHeaders();
    // headers.addHeader(S, value);
    soapMessage.saveChanges();/*from   ww w .j av  a 2s. c om*/

    System.out.println("Request SOAP Message:");
    soapMessage.writeTo(System.out);
    return soapMessage;
}

From source file:com.polivoto.networking.SoapClient.java

private SOAPMessage createSOAPRequest() throws SOAPException, IOException {
    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage soapMessage = messageFactory.createMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();

    String serverURI = "http://votingservice.develops.capiz.org";

    // SOAP Envelope
    SOAPEnvelope envelope = soapPart.getEnvelope();
    envelope.addNamespaceDeclaration("example", serverURI);

    /* El siguiente es un ejemplo tomado de donde me bas para armar la solicitud.
    Constructed SOAP Request Message:/*  w  ww.j a v a  2 s  . co m*/
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:example="http://ws.cdyne.com/">
    <SOAP-ENV:Header/>
    <SOAP-ENV:Body>
        <example:VerifyEmail>
            <example:email>mutantninja@gmail.com</example:email>
            <example:LicenseKey>123</example:LicenseKey>
        </example:VerifyEmail>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
     */

    // SOAP Body
    SOAPBody soapBody = envelope.getBody();
    SOAPElement soapBodyElem = soapBody.addChildElement("serviceChooser", "example");
    SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("json", "example");
    soapBodyElem1.addTextNode(json.toString());
    MimeHeaders headers = soapMessage.getMimeHeaders();
    headers.addHeader("SOAPAction", serverURI + "serviceChooser");
    soapMessage.saveChanges();
    return soapMessage;
}

From source file:be.fedict.hsm.client.WSSecuritySOAPHandler.java

private void handleOutboundMessage(SOAPMessageContext context) throws SOAPException, WSSecurityException {

    if (null == this.privateKey) {
        LOG.warn("no adding a WS-Security header");
        return;/*  w  w  w .ja  va  2s .co m*/
    }

    SOAPMessage soapMessage = context.getMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();
    soapMessage.getSOAPHeader();
    WSSecHeader wsSecHeader = new WSSecHeader();
    wsSecHeader.setMustUnderstand(true);
    wsSecHeader.insertSecurityHeader(soapPart);

    WSSecTimestamp wsSecTimeStamp = new WSSecTimestamp();
    wsSecTimeStamp.prepare(soapPart);
    wsSecTimeStamp.prependToHeader(wsSecHeader);

    WSSecurityCrypto crypto = new WSSecurityCrypto(this.privateKey, this.certificate);
    WSSConfig wssConfig = new WSSConfig();
    WSSecSignature sign = new WSSecSignature(wssConfig);
    sign.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE);
    sign.prepare(soapPart, crypto, wsSecHeader);
    String bstId = sign.getBSTTokenId();
    sign.appendBSTElementToHeader(wsSecHeader);
    sign.setDigestAlgo("http://www.w3.org/2001/04/xmlenc#sha256");
    sign.setSignatureAlgorithm("http://www.w3.org/2001/04/xmldsig-more#rsa-sha256");
    Vector<WSEncryptionPart> signParts = new Vector<WSEncryptionPart>();
    signParts.add(new WSEncryptionPart(wsSecTimeStamp.getId()));
    signParts.add(new WSEncryptionPart(WSConstants.ELEM_BODY, WSConstants.URI_SOAP12_ENV, ""));
    signParts.add(new WSEncryptionPart(bstId));
    sign.addReferencesToSign(signParts, wsSecHeader);
    List<Reference> referenceList = sign.addReferencesToSign(signParts, wsSecHeader);
    sign.computeSignature(referenceList, false, null);
}