Search in sources :

Example 16 with SOAPBody

use of javax.xml.soap.SOAPBody in project tomee by apache.

the class Increment method handleMessage.

public boolean handleMessage(SOAPMessageContext mc) {
    try {
        final SOAPMessage message = mc.getMessage();
        final SOAPBody body = message.getSOAPBody();
        final String localName = body.getFirstChild().getLocalName();
        if ("sumResponse".equals(localName) || "multiplyResponse".equals(localName)) {
            final Node responseNode = body.getFirstChild();
            final Node returnNode = responseNode.getFirstChild();
            final Node intNode = returnNode.getFirstChild();
            final int value = new Integer(intNode.getNodeValue());
            intNode.setNodeValue(Integer.toString(value + 1));
        }
        return true;
    } catch (SOAPException e) {
        return false;
    }
}
Also used : SOAPBody(javax.xml.soap.SOAPBody) Node(org.w3c.dom.Node) SOAPException(javax.xml.soap.SOAPException) SOAPMessage(javax.xml.soap.SOAPMessage)

Example 17 with SOAPBody

use of javax.xml.soap.SOAPBody in project webservices-axiom by apache.

the class TestAddChildElementReification method runTest.

@Override
protected void runTest() throws Throwable {
    MessageFactory mf = spec.getAdapter(FactorySelector.class).newMessageFactory(saajImplementation, false);
    SOAPBody body = mf.createMessage().getSOAPBody();
    SOAPElement child = body.addChildElement((SOAPElement) body.getOwnerDocument().createElementNS("urn:test", "p:test"));
    assertThat(child).isInstanceOf(SOAPBodyElement.class);
}
Also used : FactorySelector(org.apache.axiom.ts.saaj.FactorySelector) SOAPBody(javax.xml.soap.SOAPBody) MessageFactory(javax.xml.soap.MessageFactory) SOAPElement(javax.xml.soap.SOAPElement)

Example 18 with SOAPBody

use of javax.xml.soap.SOAPBody in project camel by apache.

the class Client method invoke.

public String invoke() throws Exception {
    // Service Qname as defined in the WSDL.
    QName serviceName = new QName("http://apache.org/hello_world_soap_http", "SOAPService");
    // Port QName as defined in the WSDL.
    QName portName = new QName("http://apache.org/hello_world_soap_http", "SoapOverHttpRouter");
    // Create a dynamic Service instance
    Service service = Service.create(serviceName);
    // Add a port to the Service
    service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, endpointAddress);
    // Create a dispatch instance
    Dispatch<SOAPMessage> dispatch = service.createDispatch(portName, SOAPMessage.class, Service.Mode.MESSAGE);
    // Use Dispatch as BindingProvider
    BindingProvider bp = dispatch;
    MessageFactory factory = ((SOAPBinding) bp.getBinding()).getMessageFactory();
    // Create SOAPMessage Request
    SOAPMessage request = factory.createMessage();
    // Request Body
    SOAPBody body = request.getSOAPBody();
    // Compose the soap:Body payload
    QName payloadName = new QName("http://apache.org/hello_world_soap_http/types", "greetMe", "ns1");
    SOAPBodyElement payload = body.addBodyElement(payloadName);
    SOAPElement message = payload.addChildElement("requestType");
    message.addTextNode("Hello Camel!!");
    System.out.println("Send out the request: Hello Camel!!");
    // Invoke the endpoint synchronously
    // Invoke endpoint operation and read response
    SOAPMessage reply = dispatch.invoke(request);
    // process the reply
    body = reply.getSOAPBody();
    QName responseName = new QName("http://apache.org/hello_world_soap_http/types", "greetMeResponse");
    SOAPElement bodyElement = (SOAPElement) body.getChildElements(responseName).next();
    String responseMessageText = bodyElement.getTextContent();
    System.out.println("Get the response: " + responseMessageText);
    return responseMessageText;
}
Also used : SOAPBody(javax.xml.soap.SOAPBody) MessageFactory(javax.xml.soap.MessageFactory) QName(javax.xml.namespace.QName) SOAPElement(javax.xml.soap.SOAPElement) Service(javax.xml.ws.Service) SOAPBinding(javax.xml.ws.soap.SOAPBinding) BindingProvider(javax.xml.ws.BindingProvider) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPBodyElement(javax.xml.soap.SOAPBodyElement)

Example 19 with SOAPBody

use of javax.xml.soap.SOAPBody in project tomcat by apache.

the class SignCode method downloadSignedFiles.

private void downloadSignedFiles(List<File> filesToSign, String id) throws SOAPException, IOException {
    log("Downloading signed files. The signing set ID is: " + id);
    SOAPMessage message = SOAP_MSG_FACTORY.createMessage();
    SOAPBody body = populateEnvelope(message, NS);
    SOAPElement getSigningSetDetails = body.addChildElement("getSigningSetDetails", NS);
    SOAPElement getSigningSetDetailsRequest = getSigningSetDetails.addChildElement("getSigningSetDetailsRequest", NS);
    addCredentials(getSigningSetDetailsRequest, this.userName, this.password, this.partnerCode);
    SOAPElement signingSetID = getSigningSetDetailsRequest.addChildElement("signingSetID", NS);
    signingSetID.addTextNode(id);
    SOAPElement returnApplication = getSigningSetDetailsRequest.addChildElement("returnApplication", NS);
    returnApplication.addTextNode("true");
    // Send the message
    SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
    SOAPConnection connection = soapConnectionFactory.createConnection();
    log("Requesting signed files from server and waiting for response");
    SOAPMessage response = connection.call(message, SIGNING_SERVICE_URL);
    log("Processing response");
    SOAPElement responseBody = response.getSOAPBody();
    // Check for success
    // Extract the signed file(s) from the ZIP
    NodeList bodyNodes = responseBody.getChildNodes();
    NodeList getSigningSetDetailsResponseNodes = bodyNodes.item(0).getChildNodes();
    NodeList returnNodes = getSigningSetDetailsResponseNodes.item(0).getChildNodes();
    String result = null;
    String data = null;
    for (int i = 0; i < returnNodes.getLength(); i++) {
        Node returnNode = returnNodes.item(i);
        if (returnNode.getLocalName().equals("result")) {
            result = returnNode.getChildNodes().item(0).getTextContent();
        } else if (returnNode.getLocalName().equals("signingSet")) {
            data = returnNode.getChildNodes().item(1).getTextContent();
        }
    }
    if (!"0".equals(result)) {
        throw new BuildException("Download failed. Result code was: " + result);
    }
    extractFilesFromApplicationString(data, filesToSign);
}
Also used : SOAPConnectionFactory(javax.xml.soap.SOAPConnectionFactory) SOAPBody(javax.xml.soap.SOAPBody) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) SOAPElement(javax.xml.soap.SOAPElement) SOAPConnection(javax.xml.soap.SOAPConnection) BuildException(org.apache.tools.ant.BuildException) SOAPMessage(javax.xml.soap.SOAPMessage)

Example 20 with SOAPBody

use of javax.xml.soap.SOAPBody in project tomcat by apache.

the class SignCode method makeSigningRequest.

private String makeSigningRequest(List<File> filesToSign) throws SOAPException, IOException {
    log("Constructing the code signing request");
    SOAPMessage message = SOAP_MSG_FACTORY.createMessage();
    SOAPBody body = populateEnvelope(message, NS);
    SOAPElement requestSigning = body.addChildElement("requestSigning", NS);
    SOAPElement requestSigningRequest = requestSigning.addChildElement("requestSigningRequest", NS);
    addCredentials(requestSigningRequest, this.userName, this.password, this.partnerCode);
    SOAPElement applicationName = requestSigningRequest.addChildElement("applicationName", NS);
    applicationName.addTextNode(this.applicationName);
    SOAPElement applicationVersion = requestSigningRequest.addChildElement("applicationVersion", NS);
    applicationVersion.addTextNode(this.applicationVersion);
    SOAPElement signingServiceName = requestSigningRequest.addChildElement("signingServiceName", NS);
    signingServiceName.addTextNode(this.signingService);
    List<String> fileNames = getFileNames(filesToSign);
    SOAPElement commaDelimitedFileNames = requestSigningRequest.addChildElement("commaDelimitedFileNames", NS);
    commaDelimitedFileNames.addTextNode(listToString(fileNames));
    SOAPElement application = requestSigningRequest.addChildElement("application", NS);
    application.addTextNode(getApplicationString(fileNames, filesToSign));
    // Send the message
    SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
    SOAPConnection connection = soapConnectionFactory.createConnection();
    log("Sending singing request to server and waiting for response");
    SOAPMessage response = connection.call(message, SIGNING_SERVICE_URL);
    log("Processing response");
    SOAPElement responseBody = response.getSOAPBody();
    // Should come back signed
    NodeList bodyNodes = responseBody.getChildNodes();
    NodeList requestSigningResponseNodes = bodyNodes.item(0).getChildNodes();
    NodeList returnNodes = requestSigningResponseNodes.item(0).getChildNodes();
    String signingSetID = null;
    String signingSetStatus = null;
    for (int i = 0; i < returnNodes.getLength(); i++) {
        Node returnNode = returnNodes.item(i);
        if (returnNode.getLocalName().equals("signingSetID")) {
            signingSetID = returnNode.getTextContent();
        } else if (returnNode.getLocalName().equals("signingSetStatus")) {
            signingSetStatus = returnNode.getTextContent();
        }
    }
    if (!signingService.contains("TEST") && !"SIGNED".equals(signingSetStatus) || signingService.contains("TEST") && !"INITIALIZED".equals(signingSetStatus)) {
        throw new BuildException("Signing failed. Status was: " + signingSetStatus);
    }
    return signingSetID;
}
Also used : SOAPConnectionFactory(javax.xml.soap.SOAPConnectionFactory) SOAPBody(javax.xml.soap.SOAPBody) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) SOAPElement(javax.xml.soap.SOAPElement) SOAPConnection(javax.xml.soap.SOAPConnection) BuildException(org.apache.tools.ant.BuildException) SOAPMessage(javax.xml.soap.SOAPMessage)

Aggregations

SOAPBody (javax.xml.soap.SOAPBody)34 SOAPMessage (javax.xml.soap.SOAPMessage)30 SOAPElement (javax.xml.soap.SOAPElement)17 SOAPException (javax.xml.soap.SOAPException)16 SOAPPart (javax.xml.soap.SOAPPart)14 MessageFactory (javax.xml.soap.MessageFactory)13 NodeList (org.w3c.dom.NodeList)12 QName (javax.xml.namespace.QName)9 SOAPEnvelope (javax.xml.soap.SOAPEnvelope)9 Element (org.w3c.dom.Element)9 StreamSource (javax.xml.transform.stream.StreamSource)8 BufferedWriter (java.io.BufferedWriter)7 InputStream (java.io.InputStream)7 OutputStreamWriter (java.io.OutputStreamWriter)7 HttpURLConnection (java.net.HttpURLConnection)7 Node (org.w3c.dom.Node)7 IOException (java.io.IOException)6 Test (org.testng.annotations.Test)6 Vector (java.util.Vector)5 SOAPHeader (javax.xml.soap.SOAPHeader)5