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:be.agiv.security.handler.WSTrustHandler.java

private void handleOutboundMessage(SOAPMessageContext context) throws SOAPException {
    if (null == this.secondaryParametersNodeList) {
        return;/*  w  w  w  .  j  a va2s.c o m*/
    }
    SOAPMessage soapMessage = context.getMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();
    SOAPBody soapBody = soapMessage.getSOAPBody();
    NodeList nodeList = soapBody.getElementsByTagNameNS(WSConstants.WSTRUST_NAMESPACE, "RequestSecurityToken");
    if (0 == nodeList.getLength()) {
        return;
    }
    SOAPElement requestSecurityTokenElement = (SOAPElement) nodeList.item(0);
    String prefix = requestSecurityTokenElement.getPrefix();
    SOAPElement secondaryParametersElement = requestSecurityTokenElement.addChildElement("SecondaryParameters",
            prefix);
    for (int idx = 0; idx < this.secondaryParametersNodeList.getLength(); idx++) {
        Node node = this.secondaryParametersNodeList.item(idx);
        Node importedNode = soapPart.importNode(node, true);
        secondaryParametersElement.appendChild(importedNode);
    }
}

From source file:ee.ria.xroad.common.message.SoapParserImpl.java

protected Soap parseMessage(byte[] rawXml, SOAPMessage soap, String charset, String originalContentType)
        throws Exception {
    if (soap.getSOAPBody() == null) {
        throw new CodedException(X_MISSING_BODY, "Malformed SOAP message: body missing");
    }/*  ww w .ja  v  a  2 s . com*/

    SOAPFault fault = soap.getSOAPBody().getFault();
    if (fault != null) {
        return new SoapFault(fault, rawXml, charset);
    } else {
        return createMessage(rawXml, soap, charset, originalContentType);
    }
}

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

@RequestMapping(method = RequestMethod.POST)
@ResponseBody//from ww  w.  j  av  a  2  s. com
public ResponseEntity<AutoCheckRes> autoCheck(@RequestBody AutoCheckReq req) throws Exception {
    AutoCheckRes autoCheckRes = new AutoCheckRes(null, null);

    SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
    SOAPConnection soapConnection = soapConnectionFactory.createConnection();

    String url = "http://localhost:6060/ode/processes/AutoCheck";
    SOAPMessage soapResponse = soapConnection
            .call(createSOAPRequest(req.getDriverLicenseNumber(), req.getFullName(), req.getPostCode()), url);

    soapConnection.close();

    SOAPBody body = soapResponse.getSOAPBody();
    Node rootnode = body.getChildNodes().item(0);
    NodeList nodeList = rootnode.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); ++i) {
        Node currentNode = nodeList.item(i);
        if (currentNode.getNodeName().equals("ns:pdvResult")) {
            autoCheckRes.setPdvResult(currentNode.getTextContent());
        } else if (currentNode.getNodeName().equals("ns:crvResult")) {
            autoCheckRes.setCrvResult(currentNode.getTextContent());
        }
    }
    return new ResponseEntity<AutoCheckRes>(autoCheckRes, HttpStatus.OK);
}

From source file:de.drv.dsrv.spoc.web.webservice.jax.ExtraSchemaValidationHandler.java

@Override
public boolean handleMessage(final SOAPMessageContext context) {

    // Nur fuer den Eingang
    final Boolean isOutBound = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    if (isOutBound) {
        return true;
    }/*w  w  w  .  j  a v  a2s .  c  om*/

    // Servlet-Context speichern
    final ServletContext servletContext = (ServletContext) context.get(MessageContext.SERVLET_CONTEXT);

    SOAPBody soapBody = getSoapBody(context);

    try {

        // Pruefe SOAP-Body
        if (soapBody == null) {
            try {
                // Erstelle neue SOAP-Message mit SOAP-Body
                final SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
                soapBody = soapMessage.getSOAPBody();
                context.setMessage(soapMessage);
            } catch (final SOAPException e) {
                LOG.error("Exception beim Erstellen einer SOAP-Message.", e);
            }
            // Request ungueltig - z.B. ungueltiges XML
            throw new InvalidExtraRequestException(resourceBundle.getString(Messages.ERROR_REQUEST_NO_EXTRA));
        }

        // Hole Transport-Element
        final Node transportNode = getTransportElement(soapBody);
        if (transportNode == null) {
            // kein 'Transport'-Element, Request ungueltig
            throw new InvalidExtraRequestException(resourceBundle.getString(Messages.ERROR_REQUEST_NO_EXTRA));
        }

        // Validiere Request-XML gegen eXTra-Schema
        validateExtraRequest(transportNode, servletContext);

    } catch (final InvalidExtraRequestException e) {
        return handleException(soapBody, e.getMessage(), ExtraErrorReasonType.INVALID_REQUEST);
    } catch (final Exception e) {
        LOG.error("Unbekannter Fehler beim Request-Validierung.", e);
        return handleException(soapBody, resourceBundle.getString(Messages.ERROR_REQUEST_VALIDATION_UNKNOWN),
                ExtraErrorReasonType.UNSPECIFIED);
    }
    return true;
}

From source file:com.jkoolcloud.tnt4j.streams.custom.inputs.CastIronWsStream.java

/**
 * Resolved tags values from SOAP received response data to map parsers to be used to parse it. Tag is SOAP response
 * message method name./*from  w ww. j  av a2 s.  c  om*/
 *
 * @param data
 *            activity data item to get tags
 * @return resolved data tags array, or {@code null} if there is no tags resolved
 */
@Override
protected String[] getDataTags(Object data) {
    try (InputStream is = new ByteArrayInputStream(String.valueOf(data).getBytes())) {
        SOAPMessage request = MessageFactory.newInstance().createMessage(null, is);
        String currentMethod = request.getSOAPBody().getFirstChild().getLocalName().replace("Response", ""); // NON-NLS

        logger().log(OpLevel.DEBUG, StreamsResources.getBundle(WsStreamConstants.RESOURCE_BUNDLE_NAME),
                "CastIronStream.parser.tag.resolved", currentMethod);

        return new String[] { currentMethod };
    } catch (Exception exc) {
        logger().log(OpLevel.ERROR, StreamsResources.getBundle(WsStreamConstants.RESOURCE_BUNDLE_NAME),
                "CastIronStream.parser.tag.resolve.failed", Utils.getExceptionMessages(exc), data);
    }

    return null;
}

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

protected Document parseQuery(SOAPMessage queryMsg) throws Exception {
    Node bodyNode = SOAPUtil.getFirstNonTextChild(queryMsg.getSOAPBody());
    if (XRoadProtocolVersion.V2_0 == version) {
        bodyNode = SOAPUtil.getNodeByXPath(bodyNode, "//keha");
        if (bodyNode == null) {
            throw new IllegalStateException(
                    "Service is not metaservice, but query is missing mandatory body ('//keha\')");
        }// w  ww  .  j  a  va2s  .com
    }

    Document query = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
    bodyNode = query.importNode(bodyNode, true);
    query.appendChild(bodyNode);
    return query;
}

From source file:net.bpelunit.test.unit.TestSOAPEncoder.java

@Test
public void testEncodeRPCLiteResponseUnwrapped() throws Exception {
    Element literal = TestUtil.readLiteralData(PATH_TO_FILES + "rpclit1.xmlfrag");
    SOAPOperationCallIdentifier operation = TestUtil.getCall(PATH_TO_FILES, PARTNER_WSDL, PARTNER_OPERATION,
            SOAPOperationDirectionIdentifier.OUTPUT);
    ISOAPEncoder encoder = new RPCLiteralEncoder();
    SOAPMessage message = encoder.construct(operation, literal, BPELUnitConstants.SOAP_FAULT_CODE_CLIENT,
            BPELUnitConstants.SOAP_FAULT_DESCRIPTION);

    final Node firstChild = message.getSOAPBody().getFirstChild();
    assertEquals(XMLConstants.NULL_NS_URI, firstChild.getNamespaceURI());
    assertEquals(operation.getName() + "Response", firstChild.getLocalName());
}

From source file:net.bpelunit.test.unit.TestSOAPEncoder.java

@Test
public void testEncodeRPCLitUnwrappedWithPartsInNamespaces() throws Exception {
    Element literal = TestUtil.readLiteralData(PATH_TO_FILES + "rpclit4.xmlfrag");
    SOAPOperationCallIdentifier operation = TestUtil.getCall(PATH_TO_FILES, PARTNER_WSDL, PARTNER_OPERATION,
            SOAPOperationDirectionIdentifier.INPUT);
    ISOAPEncoder encoder = new RPCLiteralEncoder();
    SOAPMessage message = encoder.construct(operation, literal, BPELUnitConstants.SOAP_FAULT_CODE_CLIENT,
            BPELUnitConstants.SOAP_FAULT_DESCRIPTION);

    final SOAPBody soapBody = message.getSOAPBody();
    assertEquals(1, soapBody.getElementsByTagName("someFirstPart").getLength());
    assertEquals(1, soapBody.getElementsByTagName("someSecondPart").getLength());
}

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

private void reportSOAPFault(SOAPMessage reply) throws SOAPException {
    String error = reply.getSOAPBody().getFirstChild().getTextContent();
    throw new Error("There was a SOAP Fault from Mulgara: " + error);
}

From source file:com.jkoolcloud.tnt4j.streams.custom.inputs.CastIronWsStream.java

private void login(WsScenarioStep loginStep) {
    if (loginStep == null || loginStep.isEmpty()) {
        return; // TODO: ???
    }// www. j  a  v a 2s . c om

    try {
        RequestDataAndHeaders requestDataAndHeaders = new RequestDataAndHeaders()
                .resolve(fillInRequestData(loginStep.getRequests().get(0)), this);
        SOAPMessage soapRequest = createMessage(requestDataAndHeaders.getRequest(),
                requestDataAndHeaders.getHeaders(), false, this);
        logger().log(OpLevel.DEBUG, StreamsResources.getBundle(WsStreamConstants.RESOURCE_BUNDLE_NAME),
                "CastIronStream.login.request", toXMLString(soapRequest));

        SOAPMessage soapResponse = createSOAPConnection().call(soapRequest,
                fillInRequestData(loginStep.getUrlStr()));

        if (soapResponse.getSOAPBody().hasFault()) {
            logger().log(OpLevel.ERROR, StreamsResources.getBundle(WsStreamConstants.RESOURCE_BUNDLE_NAME),
                    "CastIronStream.login.failed", soapResponse.getSOAPBody().getFault().getFaultString());
        }

        String responseString = toXMLString(soapResponse);

        logger().log(OpLevel.DEBUG, StreamsResources.getBundle(WsStreamConstants.RESOURCE_BUNDLE_NAME),
                "CastIronStream.login.response", responseString);

        applyParsers(responseString, securityResponseParserTag);
    } catch (Exception exc) {
        Utils.logThrowable(logger(), OpLevel.ERROR,
                StreamsResources.getBundle(WsStreamConstants.RESOURCE_BUNDLE_NAME),
                "CastIronStream.login.failed", exc);
    }
}