Example usage for javax.xml.soap SOAPBody getElementsByTagNameNS

List of usage examples for javax.xml.soap SOAPBody getElementsByTagNameNS

Introduction

In this page you can find the example usage for javax.xml.soap SOAPBody getElementsByTagNameNS.

Prototype

public NodeList getElementsByTagNameNS(String namespaceURI, String localName) throws DOMException;

Source Link

Document

Returns a NodeList of all the descendant Elements with a given local name and namespace URI in document order.

Usage

From source file:be.agiv.security.handler.WSTrustHandler.java

private void handleOutboundMessage(SOAPMessageContext context) throws SOAPException {
    if (null == this.secondaryParametersNodeList) {
        return;/*from   w w  w .ja va 2 s.com*/
    }
    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:de.drv.dsrv.spoc.web.webservice.jax.ExtraSchemaValidationHandler.java

private Node getTransportElement(final SOAPBody soapBody) {

    Node transportElement = null;

    try {//w w  w .  ja v  a  2  s  . c o m
        transportElement = soapBody.getElementsByTagNameNS("*", "Transport").item(0);
    } catch (final Exception e) {
        LOG.error("Exception beim Auslesen des Transport-Elements.", e);
    }
    return transportElement;
}

From source file:edu.duke.cabig.c3pr.webservice.integration.StudyImportExportWebServiceTest.java

private void verifySuccessulImportResponse(SOAPMessage respMsg) throws SOAPException {
    SOAPPart part = respMsg.getSOAPPart();
    SOAPEnvelope env = part.getEnvelope();
    SOAPBody body = env.getBody();
    NodeList nodes = body.getElementsByTagNameNS(SERVICE_NS, "ImportStudyResponse");
    assertEquals(1, nodes.getLength());//from  ww w.ja  v  a  2 s.co m
    // element should be empty
    Element responseEl = (Element) nodes.item(0);
    assertEquals(0, responseEl.getChildNodes().getLength());
}

From source file:edu.duke.cabig.c3pr.webservice.integration.StudyImportExportWebServiceTest.java

private void doStudyExportCheck()
        throws DOMException, SOAPException, IOException, SAXException, ParserConfigurationException {
    String xmlFile = "StudyIdentifier";

    Dispatch<SOAPMessage> dispatch = getDispatch();
    SOAPMessage reqMsg = prepareExportRequestEnvelope(xmlFile);
    SOAPMessage respMsg = dispatch.invoke(reqMsg);

    SOAPPart part = respMsg.getSOAPPart();
    SOAPEnvelope env = part.getEnvelope();
    SOAPBody body = env.getBody();
    NodeList nodes = body.getElementsByTagNameNS(SERVICE_NS, "ExportStudyResponse");
    assertEquals(1, nodes.getLength());/*from  www  . java2  s  .co  m*/
    Element responseEl = (Element) nodes.item(0);
    assertEquals(1, responseEl.getChildNodes().getLength());

    Element exportedStudy = (Element) responseEl.getChildNodes().item(0);
    // this study element must match the one used to create the study in the first place
    Element originalStudy = (Element) getSOAPBodyFromXML("Study");
    assertTrue(XMLUtils.isDeepEqual(exportedStudy, originalStudy));

}

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

/**
 * Determines the operation we need to perform based on the wrapper element.
 *
 * @param body the body/* w  w w .j  a  va2  s  .c  o m*/
 * @return the request type
 */
private RequestType determineRequestType(SOAPBody body) {
    if (body.getElementsByTagNameNS(SERVICE_NS, IMPORT_STUDY_REQUEST).getLength() == 1) {
        return RequestType.IMPORT_STUDY;
    }
    if (body.getElementsByTagNameNS(SERVICE_NS, EXPORT_STUDY_REQUEST).getLength() == 1) {
        return RequestType.EXPORT_STUDY;
    }
    throw new RuntimeException("Malformed SOAP request. Please check the WSDL.");
}

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

/**
 * Process study import request./*www  . jav  a 2  s .co  m*/
 *
 * @param body the body
 * @return the sOAP message
 * @throws DOMException the dOM exception
 * @throws RuntimeException the runtime exception
 * @throws ParserConfigurationException the parser configuration exception
 * @throws C3PRCodedException the c3 pr coded exception
 * @throws SOAPException the sOAP exception
 */
private SOAPMessage processStudyImportRequest(SOAPBody body)
        throws DOMException, RuntimeException, ParserConfigurationException, C3PRCodedException, SOAPException {
    NodeList nodes = body.getElementsByTagNameNS(SERVICE_NS, IMPORT_STUDY_REQUEST);
    Node importStudyRequestNode = nodes.item(0);
    NodeList studyNodes = ((Element) importStudyRequestNode).getElementsByTagNameNS(C3PR_NS, STUDY_ELEMENT);
    if (studyNodes.getLength() != 1) {
        throw new RuntimeException("Malformed SOAP request. Please check the WSDL.");
    }
    Element study = (Element) studyNodes.item(0);

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document doc = builder.newDocument();
    doc.appendChild(doc.importNode(study, true));
    List<Study> studies = studyXMLImporterService.importStudies(doc, new ErrorsImpl());
    if (CollectionUtils.isEmpty(studies)) {
        throw new RuntimeException("No studies have been imported.");
    }
    return createImportStudyResponse();

}

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

/**
 * Process study export request.//from w w  w .ja  va 2 s .c  o  m
 *
 * @param body the body
 * @return the sOAP message
 * @throws DOMException the dOM exception
 * @throws RuntimeException the runtime exception
 * @throws ParserConfigurationException the parser configuration exception
 * @throws C3PRCodedException the c3 pr coded exception
 * @throws SOAPException the sOAP exception
 * @throws XMLUtilityException the xML utility exception
 * @throws SAXException the sAX exception
 * @throws IOException Signals that an I/O exception has occurred.
 */
private SOAPMessage processStudyExportRequest(SOAPBody body)
        throws DOMException, RuntimeException, ParserConfigurationException, C3PRCodedException, SOAPException,
        XMLUtilityException, SAXException, IOException {
    NodeList nodes = body.getElementsByTagNameNS(SERVICE_NS, EXPORT_STUDY_REQUEST);
    Node exportStudyRequestNode = nodes.item(0);
    Element studyId = (Element) getFirstChild(exportStudyRequestNode, IDENTIFIER_ELEMENT, C3PR_NS);
    if (studyId == null) {
        throw new RuntimeException("Malformed SOAP request. Please check the WSDL.");
    }
    Identifier oai = convertToOAI(studyId);
    Study study = studyRepository.getUniqueStudy(java.util.Arrays.asList(oai));
    return createExportStudyResponse(study);

}