Example usage for javax.xml.soap SOAPMessage saveChanges

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

Introduction

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

Prototype

public abstract void saveChanges() throws SOAPException;

Source Link

Document

Updates this SOAPMessage object with all the changes that have been made to it.

Usage

From source file:edu.duke.cabig.c3pr.webservice.studyimportexport.impl.StudyImportExportImpl.java

/**
 * Creates the import study response./*from  w w  w.j  av  a 2s . c o m*/
 *
 * @return the sOAP message
 * @throws SOAPException the sOAP exception
 */
private SOAPMessage createImportStudyResponse() throws SOAPException {
    MessageFactory mf = MessageFactory.newInstance();
    SOAPMessage response = mf.createMessage();
    SOAPBody body = response.getSOAPBody();
    body.addChildElement(new QName(SERVICE_NS, "ImportStudyResponse"));
    response.saveChanges();
    return response;
}

From source file:backend.Weather.java

private SOAPMessage createSOAPRequest() throws Exception {
    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage soapMessage = messageFactory.createMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();
    String serverURI = "http://ws.cdyne.com/";
    SOAPEnvelope envelope = soapPart.getEnvelope();

    SOAPBody soapBody = envelope.getBody();
    SOAPElement soapBodyElem = soapBody.addChildElement("GetCityWeatherByZIP");
    QName attributeName = new QName("xmlns");
    soapBodyElem.addAttribute(attributeName, "http://ws.cdyne.com/WeatherWS/");
    SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("ZIP");
    soapBodyElem1.addTextNode("02215");
    soapMessage.saveChanges();
    return soapMessage;

}

From source file:SendSOAPMessage.java

/**
 * send a simple soap message with JAXM API.
 *//*w  w w  .j  av  a2 s  .  c  o m*/
public void sendMessage(String url) {

    try {
        /**
         * Construct a default SOAP message factory.
         */
        MessageFactory mf = MessageFactory.newInstance();
        /**
         * Create a SOAP message object.
         */
        SOAPMessage soapMessage = mf.createMessage();
        /**
         * Get SOAP part.
         */
        SOAPPart soapPart = soapMessage.getSOAPPart();
        /**
         * Get SOAP envelope.
         */
        SOAPEnvelope soapEnvelope = soapPart.getEnvelope();

        /**
         * Get SOAP body.
         */
        SOAPBody soapBody = soapEnvelope.getBody();

        /**
         * Add child element with the specified name.
         */
        SOAPElement element = soapBody.addChildElement("HelloWorld");

        /**
         * Add text message
         */
        element.addTextNode("Welcome to SunOne Web Services!");

        soapMessage.saveChanges();

        /**
         * Construct a default SOAP connection factory.
         */
        SOAPConnectionFactory connectionFactory = SOAPConnectionFactory.newInstance();

        /**
         * Get SOAP connection.
         */
        SOAPConnection soapConnection = connectionFactory.createConnection();

        /**
         * Construct endpoint object.
         */
        URLEndpoint endpoint = new URLEndpoint(url);

        /**
         * Send SOAP message.
         */
        SOAPMessage resp = soapConnection.call(soapMessage, endpoint);

        /**
         * Print response to the std output.
         */
        resp.writeTo(System.out);

        /**
         * close the connection
         */
        soapConnection.close();

    } catch (java.io.IOException ioe) {
        ioe.printStackTrace();
    } catch (SOAPException soape) {
        soape.printStackTrace();
    }
}

From source file:com.fortify.bugtracker.tgt.archer.connection.ArcherAuthenticatingRestConnection.java

public Long addValueToValuesList(Long valueListId, String value) {
    LOG.info("[Archer] Adding value '" + value + "' to value list id " + valueListId);
    // Adding items to value lists is not supported via REST API, so we need to revert to SOAP API
    // TODO Simplify this method?
    // TODO Make this method more fail-safe (like checking for the correct response element)?
    Long result = null;//from w w w  . j  a va2  s.c om
    try {
        MessageFactory messageFactory = MessageFactory.newInstance();
        SOAPMessage message = messageFactory.createMessage();
        SOAPPart soapPart = message.getSOAPPart();
        SOAPEnvelope envelope = soapPart.getEnvelope();
        SOAPBody body = envelope.getBody();
        SOAPElement bodyElement = body.addChildElement(
                envelope.createName("CreateValuesListValue", "", "http://archer-tech.com/webservices/"));
        bodyElement.addChildElement("sessionToken").addTextNode(tokenProviderRest.getToken());
        bodyElement.addChildElement("valuesListId").addTextNode(valueListId + "");
        bodyElement.addChildElement("valuesListValueName").addTextNode(value);
        message.saveChanges();

        SOAPMessage response = executeRequest(HttpMethod.POST,
                getBaseResource().path("/ws/field.asmx").request()
                        .header("SOAPAction", "\"http://archer-tech.com/webservices/CreateValuesListValue\"")
                        .accept("text/xml"),
                Entity.entity(message, "text/xml"), SOAPMessage.class);
        @SuppressWarnings("unchecked")
        Iterator<Object> it = response.getSOAPBody().getChildElements();
        while (it.hasNext()) {
            Object o = it.next();
            if (o instanceof SOAPElement) {
                result = new Long(((SOAPElement) o).getTextContent());
            }
        }
        System.out.println(response);
    } catch (SOAPException e) {
        throw new RuntimeException("Error executing SOAP request", e);
    }
    return result;
}

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();

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

From source file:edu.unc.lib.dl.services.TripleStoreManagerMulgaraImpl.java

private String sendTQL(String query) {
    log.info(query);/*www.java  2  s .c  om*/
    String result = null;
    try {
        // First create the connection
        SOAPConnectionFactory soapConnFactory = SOAPConnectionFactory.newInstance();
        SOAPConnection connection = soapConnFactory.createConnection();

        // 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();
        SOAPMessage 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.jdom.Document jdomDoc = builder.build(reply.getSOAPBody().getOwnerDocument());
                log.info(new XMLOutputter().outputString(jdomDoc));
            }
        } else {
            NodeList nl = reply.getSOAPPart().getEnvelope().getBody().getElementsByTagNameNS("*",
                    "executeQueryToStringReturn");
            if (nl.getLength() > 0) {
                result = nl.item(0).getTextContent();
            }
            log.debug(result);
        }
    } catch (SOAPException e) {
        throw new Error("Cannot query triple store at " + this.getItqlEndpointURL(), e);
    }
    return result;
}

From source file:com.usps.UspsServlet.java

private SOAPMessage createSOAPRequest(String parameter) {
    SOAPMessage soapMessage = null;
    try {//from w  w  w  .ja  v a2 s .  c om
        MessageFactory messageFactory = MessageFactory.newInstance();
        soapMessage = messageFactory.createMessage();
        SOAPPart soapPart = soapMessage.getSOAPPart();

        // SOAP Envelope
        SOAPEnvelope envelope = soapPart.getEnvelope();
        envelope.addNamespaceDeclaration("xsd", "http://www.w3.org/2001/XMLSchema");
        envelope.addNamespaceDeclaration("upss", "http://www.ups.com/XMLSchema/XOLTWS/UPSS/v1.0");
        envelope.addNamespaceDeclaration("wsf", "http://www.ups.com/schema/wsf");
        envelope.addNamespaceDeclaration("xsi", "http://www.w3.org/2001/XMLSchema-instance");
        envelope.addNamespaceDeclaration("common", "http://www.ups.com/XMLSchema/XOLTWS/Common/v1.0");

        // SOAP Body Generated Here
        // all of the nodes below are mandatory
        // if any optional nodes are desired refer to the ECHO API or SOAPUI for
        // exact Node names
        SOAPBody soapBody = envelope.getBody();

        MimeHeaders headers = soapMessage.getMimeHeaders();
        headers.addHeader("Security", "wsse");

        soapMessage.saveChanges();

        /* Print the request message */
        System.out.print("Request SOAP Message:");
        soapMessage.writeTo(System.out);

    } catch (SOAPException | IOException ex) {
        Logger.getLogger(UspsServlet.class.getName()).log(Level.SEVERE, null, ex);
    }
    return soapMessage;
}

From source file:eu.domibus.ebms3.sender.EbMS3MessageBuilder.java

public SOAPMessage buildSOAPMessage(UserMessage userMessage, SignalMessage signalMessage, LegConfiguration leg)
        throws EbMS3Exception {
    String messageId = null;//from ww w. ja va  2s  .  c om
    SOAPMessage message;
    try {
        message = this.messageFactory.createMessage();

        final Messaging messaging = this.ebMS3Of.createMessaging();
        if (userMessage != null) {
            if (userMessage.getMessageInfo() != null && userMessage.getMessageInfo().getTimestamp() == null) {
                userMessage.getMessageInfo().setTimestamp(new Date());
            }
            messageId = userMessage.getMessageInfo().getMessageId();
            messaging.setUserMessage(userMessage);
            for (PartInfo partInfo : userMessage.getPayloadInfo().getPartInfo()) {
                this.attachPayload(partInfo, message);
            }

        }
        if (signalMessage != null) {
            MessageInfo msgInfo = new MessageInfo();

            messageId = this.messageIdGenerator.generateMessageId();
            msgInfo.setMessageId(messageId);
            msgInfo.setTimestamp(new Date());

            signalMessage.setMessageInfo(msgInfo);
        }
        messaging.setSignalMessage(signalMessage);
        this.jaxbContext.createMarshaller().marshal(messaging, message.getSOAPHeader());
        message.saveChanges();

    } catch (final SAXParseException e) {
        throw new EbMS3Exception(EbMS3Exception.EbMS3ErrorCode.EBMS_0001, "Payload in body must be valid XML",
                messageId, e, null);
    } catch (final JAXBException | SOAPException | ParserConfigurationException | IOException
            | SAXException ex) {
        throw new SendMessageException(ex);
    }
    return message;
}

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://from  w  w  w .j a v a 2s . c  o 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:edu.duke.cabig.c3pr.webservice.studyimportexport.impl.StudyImportExportImpl.java

/**
 * Creates the export study response./*from   w  ww  .  j  ava 2  s.  c o  m*/
 *
 * @param study the study
 * @return the sOAP message
 * @throws SOAPException the sOAP exception
 * @throws XMLUtilityException the xML utility exception
 * @throws ParserConfigurationException the parser configuration exception
 * @throws SAXException the sAX exception
 * @throws IOException Signals that an I/O exception has occurred.
 */
private SOAPMessage createExportStudyResponse(Study study)
        throws SOAPException, XMLUtilityException, ParserConfigurationException, SAXException, IOException {
    MessageFactory mf = MessageFactory.newInstance();
    SOAPMessage response = mf.createMessage();
    SOAPBody body = response.getSOAPBody();
    SOAPElement exportStudyResponse = body.addChildElement(new QName(SERVICE_NS, "ExportStudyResponse"));
    String xml = marshaller.toXML(study);

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    factory.setSchema(SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI)
            .newSchema(XmlMarshaller.class.getResource(C3PR_DOMAIN_XSD_URL)));
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document doc = builder.parse(IOUtils.toInputStream(xml));
    Element studyEl = (Element) doc.getFirstChild();
    exportStudyResponse.appendChild(body.getOwnerDocument().importNode(studyEl, true));
    response.saveChanges();
    return response;
}