Java 类javax.xml.soap.Node 实例源码

项目:programacaoweb    文件:UsuarioHandlerMessage.java   
@Override
public boolean handleMessage(SOAPMessageContext context) {
    Boolean request = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    if (!request) {
        try {
            SOAPMessage msg = context.getMessage();
            SOAPEnvelope env = msg.getSOAPPart().getEnvelope();
            SOAPHeader header = env.getHeader();
            if (header == null) {
                header = env.addHeader();
                return false;
            }
            Node node = (Node) header.getElementsByTagName("token").item(0);
            String token = node.getChildNodes().item(0).getNodeValue();
            if (token != null && token.equals("Kalango Lab")) {
                System.out.println("Token válido");
                return true;
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
    return true;
}
项目:JavaMainRepo    文件:EntityRepository.java   
public ArrayList<T> load() throws Exception {
    ArrayList<T> entities = new ArrayList<T>();

    File fXmlFile = new File(this.xmlFilename);
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
    Document doc = dBuilder.parse(fXmlFile);
    doc.getDocumentElement().normalize();

    NodeList nodeList = doc.getElementsByTagName(this.entityTag);

    for (int i = 0; i < nodeList.getLength(); i++) {
        org.w3c.dom.Node node = nodeList.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            Element element = (Element) node;
            entities.add(getEntityFromXmlElement(element));
        }
    }
    return entities;
}
项目:FEFEditor    文件:GuiData.java   
protected GuiData() {
    try {
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();

        Document doc = dBuilder.parse(FEFEditor.class.getResourceAsStream("data/xml/FileTypes.xml"));
        doc.getDocumentElement().normalize();
        NodeList nList = doc.getDocumentElement().getElementsByTagName("FatesTypes").item(0).getChildNodes();
        for (int x = 0; x < nList.getLength(); x++) {
            if (nList.item(x).getNodeType() == Node.ELEMENT_NODE)
                baseTypes.add(nList.item(x).getAttributes().getNamedItem("name").getNodeValue());
        }
        nList = doc.getDocumentElement().getElementsByTagName("DLC").item(0).getChildNodes();
        for (int x = 0; x < nList.getLength(); x++) {
            if (nList.item(x).getNodeType() == Node.ELEMENT_NODE)
                dlcTypes.add(nList.item(x).getAttributes().getNamedItem("name").getNodeValue());
        }
        nList = doc.getDocumentElement().getElementsByTagName("Awakening").item(0).getChildNodes();
        for (int x = 0; x < nList.getLength(); x++) {
            if (nList.item(x).getNodeType() == Node.ELEMENT_NODE)
                awakeningTypes.add(nList.item(x).getAttributes().getNamedItem("name").getNodeValue());
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
项目:oscm    文件:SoapRequestParserTest.java   
@Test
public void parseApiVersion_ctmg_1_8() throws Exception {
    // given
    SOAPPart part = mock(SOAPPart.class);
    SOAPEnvelope envelope = mock(SOAPEnvelope.class);
    SOAPHeader soapHeader = mock(SOAPHeader.class);
    List<Node> version = new ArrayList<Node>();
    Node node = mock(Node.class);
    doReturn("testVersion").when(node).getValue();
    version.add(node);
    Iterator<?> it = version.iterator();
    doReturn(it).when(soapHeader).extractHeaderElements(
            eq("ctmg.service.version"));
    doReturn(soapHeader).when(envelope).getHeader();
    doReturn(envelope).when(part).getEnvelope();
    doReturn(part).when(message).getSOAPPart();
    // when
    String result = SoapRequestParser.parseApiVersion(context);

    // then
    assertEquals("testVersion", result);
}
项目:xrd4j    文件:ExampleAdapter.java   
/**
 * Deserializes the "request" element.
 *
 * @param requestNode request element
 * @return content of the request element
 */
@Override
protected String deserializeRequest(Node requestNode, SOAPMessage message) throws SOAPException {
    if (requestNode == null) {
        logger.warn("\"requestNode\" is null. Null is returned.");
        return null;
    }
    for (int i = 0; i < requestNode.getChildNodes().getLength(); i++) {
        // Request data is inside of "name" element
        if (requestNode.getChildNodes().item(i).getNodeType() == Node.ELEMENT_NODE
                && "name".equals(requestNode.getChildNodes().item(i).getLocalName())) {
            logger.debug("Found \"name\" element.");
            // "name" element was found - return the text content
            return requestNode.getChildNodes().item(i).getTextContent();
        }
    }
    logger.warn("No \"name\" element found. Null is returned.");
    return null;
}
项目:xrd4j    文件:ListServicesResponseDeserializer.java   
/**
 * Deserializes listMethods and allowedMethods meta service responses from
 * SOAP to list of ProducerMember objects.
 *
 * @param responseNode response element of the SOAP message
 * @param message entire SOAP message
 * @return list ProducerMember objects
 * @throws SOAPException if there's a SOAP exception
 */
@Override
protected List<ProducerMember> deserializeResponseData(Node responseNode, SOAPMessage message) throws SOAPException {
    List<ProducerMember> producers = new ArrayList<>();
    // Get list of services
    NodeList list = message.getSOAPBody().getElementsByTagNameNS(Constants.NS_XRD_URL, Constants.NS_XRD_ELEM_SERVICE);
    LOGGER.debug("Found {} {} elements from SOAP body. ", list.getLength(), Constants.NS_XRD_ELEM_SERVICE);

    for (int i = 0; i < list.getLength(); i++) {
        LOGGER.debug("Deserialize \"{}\".", Constants.NS_XRD_ELEM_SERVICE);
        // Service headers
        Map<String, String> service = SOAPHelper.nodesToMap(list.item(i).getChildNodes());
        // Service object type
        ObjectType serviceObjectType = this.deserializeObjectType((Node) list.item(i));
        try {
            producers.add(super.getProducerMember(service, serviceObjectType));
        } catch (Exception e) {
            LOGGER.error("Deserializing \"{}\" failed - skip.", Constants.NS_XRD_ELEM_SERVICE);
            LOGGER.error(e.getMessage(), e);
        }
    }
    return producers;
}
项目:xrd4j    文件:AbstractResponseDeserializer.java   
/**
 * Tries to deserialize standard SOAP error message. If a standard error
 * message is found true is returned. Otherwise false is returned.
 *
 * @param response ServiceResponse that holds the SOAPMessage
 * @return true if and only if a standard SOAP fault is found; otherwise
 * false
 * @throws SOAPException if there's a SOAP error
 */
private boolean deserializeSOAPFault(final ServiceResponse response) throws SOAPException {
    LOGGER.debug("Deserialize SOAP fault.");
    Map<String, String> fault;
    SOAPBody body = response.getSoapMessage().getSOAPBody();
    NodeList list = body.getElementsByTagNameNS("*", "Fault");
    if (list.getLength() == 1) {
        fault = SOAPHelper.nodesToMap(list.item(0).getChildNodes(), true);
        String faultCode = fault.get("FAULTCODE");
        String faultString = fault.get("FAULTSTRING");
        String faultActor = fault.get("FAULTACTOR");
        Object detail = this.deserializeFaultDetail(SOAPHelper.getNode((Node) list.item(0), "detail"));
        response.setErrorMessage(new ErrorMessage(faultCode, faultString, faultActor, detail));
        LOGGER.info("SOAP fault was succesfully deserialized.");
        return true;
    }
    LOGGER.debug("SOAP fault was not found.");
    return false;
}
项目:xrd4j    文件:AbstractServiceResponseSerializer.java   
private void processRequestNode(final SOAPBodyElement body, final ServiceResponse response,
                                final SOAPMessage soapRequest, final SOAPEnvelope envelope) throws SOAPException {
    boolean requestFound = false;
    NodeList list = soapRequest.getSOAPBody().getElementsByTagNameNS("*", response.getProducer().getServiceCode());
    if (list.getLength() == 1) {
        // Copy request from soapRequest
        requestFound = copyRequestNode((Node) list.item(0), body, response);
    }
    // It was not possible to copy the request element, so we must create it
    if (!requestFound) {
        SOAPElement temp = body.addChildElement(envelope.createName("request"));
        if (response.isAddNamespaceToRequest()) {
            LOGGER.debug("Add provider namespace to request element.");
            SOAPHelper.addNamespace(temp, response);
        }
    }
}
项目:xrd4j    文件:AbstractServiceResponseSerializer.java   
private boolean copyRequestNode(final Node node, final SOAPBodyElement body, final ServiceResponse response) {
    for (int i = 0; i < node.getChildNodes().getLength(); i++) {
        if (node.getChildNodes().item(i).getNodeType() == Node.ELEMENT_NODE
                && "request".equals(node.getChildNodes().item(i).getLocalName())) {
            Node requestNode = (Node) node.getChildNodes().item(i).cloneNode(true);
            Node importNode = (Node) body.getOwnerDocument().importNode(requestNode, true);
            body.appendChild(importNode);
            if (response.isAddNamespaceToRequest()) {
                LOGGER.debug("Add provider namespace to request element.");
                SOAPHelper.addNamespace(importNode, response);
            }
            return true;
        }
    }
    return false;
}
项目:xrd4j    文件:AbstractHeaderDeserializer.java   
/**
 * Deserializes the client element of the SOAP header to a ConsumerMember
 * object.
 *
 * @param header SOAP header to be deserialized
 * @return ConsumerMember object
 * @throws XRd4JException if there's a XRd4J error
 * @throws XRd4JMissingMemberException if ConsumerMember is missing
 */
protected final ConsumerMember deserializeConsumer(final SOAPHeader header)
        throws XRd4JException, XRd4JMissingMemberException {
    LOGGER.debug("Deserialize \"{}\".", Constants.NS_XRD_ELEM_CLIENT);
    // Client headers
    Map<String, String> client;
    // Client object type
    ObjectType clientObjectType;

    NodeList list = header.getElementsByTagNameNS(Constants.NS_XRD_URL, Constants.NS_XRD_ELEM_CLIENT);
    if (list.getLength() == 1) {
        clientObjectType = this.deserializeObjectType((Node) list.item(0));
        client = SOAPHelper.nodesToMap(list.item(0).getChildNodes());
        LOGGER.trace(ELEMENT_FOUND_LOG_PATTERN, Constants.NS_XRD_ELEM_CLIENT);
        return this.getConsumerMember(client, clientObjectType);
    }
    LOGGER.warn("\"{}\" element missing from SOAP header.", Constants.NS_XRD_ELEM_CLIENT);
    throw new XRd4JMissingMemberException("Client element is missing from SOAP header.");
}
项目:xrd4j    文件:AbstractHeaderDeserializer.java   
/**
 * Deserializes the service element of the SOAP header to a ProducerMember
 * object.
 *
 * @param header SOAP header to be deserialized
 * @return ProducerMember object
 * @throws XRd4JException if there's a XRd4J error
 * @throws XRd4JMissingMemberException if ProducerMember is missing
 */
protected final ProducerMember deserializeProducer(final SOAPHeader header)
        throws XRd4JException, XRd4JMissingMemberException {
    LOGGER.debug(DESERIALIZE_LOG_PATTERN, Constants.NS_XRD_ELEM_SERVICE);
    // Service headers
    Map<String, String> service;
    // Service object type
    ObjectType serviceObjectType;

    NodeList list = header.getElementsByTagNameNS(Constants.NS_XRD_URL, Constants.NS_XRD_ELEM_SERVICE);
    if (list.getLength() == 1) {
        serviceObjectType = this.deserializeObjectType((Node) list.item(0));
        service = SOAPHelper.nodesToMap(list.item(0).getChildNodes());
        LOGGER.trace(ELEMENT_FOUND_LOG_PATTERN, Constants.NS_XRD_ELEM_SERVICE);
        return this.getProducerMember(service, serviceObjectType);
    }
    LOGGER.warn("\"{}\" element missing from SOAP header.", Constants.NS_XRD_ELEM_SERVICE);
    throw new XRd4JMissingMemberException("Service element is missing from SOAP header.");
}
项目:xrd4j    文件:SOAPHelper.java   
/**
 * Reads installed X-Road packages and their version info from environmental
 * monitoring metrics.
 *
 * @param metrics NodeList containing "metricSet" element returned by
 * environmental monitoring service
 * @return installed X-Road packages as key-value pairs
 */
public static Map<String, String> getXRdVersionInfo(NodeList metrics) {
    LOGGER.trace("Start reading X-Road version info from metrics.");
    Map<String, String> results = new HashMap<>();
    // Check for null and empty
    if (metrics == null || metrics.getLength() == 0) {
        LOGGER.trace("Metrics set is null or empty.");
        return results;
    }
    // Loop through metrics
    for (int i = 0; i < metrics.getLength(); i++) {
        Node node = SOAPHelper.getNode((Node) metrics.item(i), "name");
        // Jump to next element if this is not Packages
        if (node == null || !Constants.NS_ENV_MONITORING_ELEM_PACKAGES.equals(node.getTextContent())) {
            continue;
        }
        // Loop through packages and add X-Road packages to results
        getXRdPackages(metrics.item(i).getChildNodes(), results);
    }
    LOGGER.trace("Metrics info read. {} X-Road packages found.", results.size());
    return results;
}
项目:xrd4j    文件:SOAPHelper.java   
/**
 * Reads installed X-Road packages and their version info from environmental
 * monitoring metrics.
 *
 * @param packages NodeList containing "metricSet" element which children
 * all the installed packages are
 * @param results Map object for results
 */
private static void getXRdPackages(NodeList packages, Map<String, String> results) {
    // Loop through packages
    for (int j = 0; j < packages.getLength(); j++) {
        // We're looking for "stringMetric" elements
        if (Constants.NS_ENV_MONITORING_ELEM_STRING_METRIC.equals(packages.item(j).getLocalName())) {
            // Get name and value
            Node name = SOAPHelper.getNode((Node) packages.item(j), "name");
            Node value = SOAPHelper.getNode((Node) packages.item(j), "value");
            // X-Road packages start with "xroad-prefix"
            if (name != null && value != null && name.getTextContent().startsWith("xroad-")) {
                results.put(name.getTextContent(), value.getTextContent());
                LOGGER.debug("X-Road package version info found: \"{}\" = \"{}\".", name.getTextContent(),
                        value.getTextContent());
            }
        }
    }
}
项目:development    文件:SoapRequestParserTest.java   
@Test
public void parseApiVersion_cm_1_8() throws Exception {
    // given
    SOAPPart part = mock(SOAPPart.class);
    SOAPEnvelope envelope = mock(SOAPEnvelope.class);
    SOAPHeader soapHeader = mock(SOAPHeader.class);
    List<Node> version = new ArrayList<Node>();
    Node node = mock(Node.class);
    doReturn("testVersion").when(node).getValue();
    version.add(node);
    Iterator<?> it = version.iterator();
    doReturn(it).when(soapHeader).extractHeaderElements(
            eq("cm.service.version"));
    doReturn(soapHeader).when(envelope).getHeader();
    doReturn(envelope).when(part).getEnvelope();
    doReturn(part).when(message).getSOAPPart();
    // when
    String result = SoapRequestParser.parseApiVersion(context);

    // then
    assertEquals("testVersion", result);
}
项目:development    文件:SoapRequestParserTest.java   
@Test
public void parseApiVersion_ctmg_1_8() throws Exception {
    // given
    SOAPPart part = mock(SOAPPart.class);
    SOAPEnvelope envelope = mock(SOAPEnvelope.class);
    SOAPHeader soapHeader = mock(SOAPHeader.class);
    List<Node> version = new ArrayList<Node>();
    Node node = mock(Node.class);
    doReturn("testVersion").when(node).getValue();
    version.add(node);
    Iterator<?> it = version.iterator();
    doReturn(it).when(soapHeader).extractHeaderElements(
            eq("ctmg.service.version"));
    doReturn(soapHeader).when(envelope).getHeader();
    doReturn(envelope).when(part).getEnvelope();
    doReturn(part).when(message).getSOAPPart();
    // when
    String result = SoapRequestParser.parseApiVersion(context);

    // then
    assertEquals("testVersion", result);
}
项目:x-road-adapter-example    文件:ExampleAdapter.java   
/**
 * Deserializes the "request" element.
 *
 * @param requestNode request element
 * @return content of the request element
 */
@Override
protected String deserializeRequest(Node requestNode, SOAPMessage message) throws SOAPException {
    if (requestNode == null) {
        logger.warn("\"requestNode\" is null. Null is returned.");
        return null;
    }
    for (int i = 0; i < requestNode.getChildNodes().getLength(); i++) {
        // Request data is inside of "name" element
        if (requestNode.getChildNodes().item(i).getNodeType() == Node.ELEMENT_NODE
                && "name".equals(requestNode.getChildNodes().item(i).getLocalName())) {
            logger.debug("Found \"name\" element.");
            // "name" element was found - return the text content
            return requestNode.getChildNodes().item(i).getTextContent();
        }
    }
    logger.warn("No \"name\" element found. Null is returned.");
    return null;
}
项目:WS-Attacker    文件:SoapUtilities.java   
private static void inputNeeded( SOAPElement ele, List<SOAPElement> l )
{
    // input is needed for leafs or for existing text-nods
    if ( !ele.hasChildNodes()
        || ( ele.getChildNodes().getLength() == 1 && ( ele.getFirstChild().getNodeType() == Node.TEXT_NODE ) ) )
    {
        // check if element is a special element that should never get input
        String namespace = ele.getNamespaceURI();
        // only add to list if element has no namspace or namespace is no
        // soap namespace
        if ( namespace == null
            || ( !namespace.equals( SOAP_11_NAMESPACE_URL ) && !namespace.equals( SOAP_12_NAMESPACE_URL ) ) )
        {
            log.trace( "Adding node " + ele.getNodeName() );
            l.add( ele );
        }
    }
    for ( SOAPElement e : getSoapChilds( ele ) )
    {
        inputNeeded( e, l );
    }
}
项目:JavaMainRepo    文件:EntityRepository.java   
public ArrayList<T> load() throws ParserConfigurationException, SAXException, IOException {

        ArrayList<T> entities = new ArrayList<T>();

        File fXmlFile = new File(this.xmlFilename);
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        Document doc = dBuilder.parse(fXmlFile);
        doc.getDocumentElement().normalize();

        NodeList nodeList = doc.getElementsByTagName(this.entityTag);

        for (int i = 0; i < nodeList.getLength(); i++) {
            org.w3c.dom.Node node = nodeList.item(i);
            if (node.getNodeType() == Node.ELEMENT_NODE) {
                Element element = (Element) node;
                entities.add(getEntityFromXmlElement(element));
            }
        }
        return entities;
    }
项目:JavaMainRepo    文件:EntityRepository.java   
public ArrayList<T> load() throws Exception {
    ArrayList<T> entities = new ArrayList<T>();

    File fXmlFile = new File(this.xmlFilename);
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
    Document doc = dBuilder.parse(fXmlFile);
    doc.getDocumentElement().normalize();

    NodeList nodeList = doc.getElementsByTagName(this.entityTag);

    for (int i = 0; i < nodeList.getLength(); i++) {
        org.w3c.dom.Node node = nodeList.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            Element element = (Element) node;
            entities.add(getEntityFromXmlElement(element));
        }
    }
    return entities;
}
项目:JavaMainRepo    文件:EntityRepository.java   
public ArrayList<T> load() throws Exception {
    ArrayList<T> entities = new ArrayList<T>();

    File fXmlFile = new File(this.xmlFilename);
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
    Document doc = dBuilder.parse(fXmlFile);
    doc.getDocumentElement().normalize();

    NodeList nodeList = doc.getElementsByTagName(this.entityTag);

    for (int i = 0; i < nodeList.getLength(); i++) {
        org.w3c.dom.Node node = nodeList.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            Element element = (Element) node;
            entities.add(getEntityFromXmlElement(element));
        }
    }
    return entities;
}
项目:JavaMainRepo    文件:EntityRepository.java   
public ArrayList<T> load() throws Exception {
    ArrayList<T> entities = new ArrayList<T>();

    File fXmlFile = new File(this.xmlFilename);
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
    Document doc = dBuilder.parse(fXmlFile);
    doc.getDocumentElement().normalize();

    NodeList nodeList = doc.getElementsByTagName(this.entityTag);

    for (int i = 0; i < nodeList.getLength(); i++) {
        org.w3c.dom.Node node = nodeList.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            Element element = (Element) node;
            entities.add(getEntityFromXmlElement(element));
        }
    }
    return entities;
}
项目:JavaMainRepo    文件:EntityRepository.java   
public ArrayList<T> load() throws ParserConfigurationException, SAXException, IOException {
ArrayList<T> entities = new ArrayList<T>();
File fXmlFile = new File(this.xmlFilename);
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = (Document) dBuilder.parse(fXmlFile);
doc.getDocumentElement().normalize();
NodeList nodeList = doc.getElementsByTagName(Constants.XML_TAGS.ANIMAL);    
for (int i = 0; i < nodeList.getLength(); i++) {
    Node node = (Node) nodeList.item(i);
    if (node.getNodeType() == Node.ELEMENT_NODE) { 
        Element element = (Element) node;
        entities.add(getEntityFromXmlElement(element));
    }
}
return entities;
}
项目:JavaMainRepo    文件:EntityRepository.java   
public ArrayList<T> load() throws ParserConfigurationException, SAXException, IOException {

        ArrayList<T> entities = new ArrayList<T>();

        File fXmlFile = new File(this.xmlFilename);
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        Document doc = dBuilder.parse(fXmlFile);
        doc.getDocumentElement().normalize();

        NodeList nodeList = doc.getElementsByTagName(this.entityTag);

        for (int i = 0; i < nodeList.getLength(); i++) {
            org.w3c.dom.Node node = nodeList.item(i);
            if (node.getNodeType() == Node.ELEMENT_NODE) {
                Element element = (Element) node;
                entities.add(getEntityFromXmlElement(element));
            }
        }
        return entities;
    }
项目:JavaMainRepo    文件:EntityRepository.java   
public ArrayList<T> load() throws ParserConfigurationException, SAXException, IOException {

        ArrayList<T> entities = new ArrayList<T>();

        File fXmlFile = new File(this.xmlFilename);
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        Document doc = dBuilder.parse(fXmlFile);
        doc.getDocumentElement().normalize();

        NodeList nodeList = doc.getElementsByTagName(this.entityTag);

        for (int i = 0; i < nodeList.getLength(); i++) {
            org.w3c.dom.Node node = nodeList.item(i);
            if (node.getNodeType() == Node.ELEMENT_NODE) {
                Element element = (Element) node;
                entities.add(getEntityFromXmlElement(element));
            }
        }
        return entities;
    }
项目:JavaMainRepo    文件:EntityRepository.java   
public ArrayList<T> load() throws ParserConfigurationException, SAXException, IOException {

        ArrayList<T> entities = new ArrayList<T>();

        File fXmlFile = new File(this.xmlFilename);
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        Document doc = dBuilder.parse(fXmlFile);
        doc.getDocumentElement().normalize();

        NodeList nodeList = doc.getElementsByTagName(this.entityTag);

        for (int i = 0; i < nodeList.getLength(); i++) {
            org.w3c.dom.Node node = nodeList.item(i);
            if (node.getNodeType() == Node.ELEMENT_NODE) {
                Element element = (Element) node;
                entities.add(getEntityFromXmlElement(element));
            }
        }
        return entities;
    }
项目:wso2-axis2    文件:XMLPartBase.java   
public QName getOperationElement() throws WebServiceException {
    try {
        if (style != Style.RPC) {
            return null;
        }
        switch (contentType) {
            case OM:
                return ((org.apache.axiom.soap.SOAPEnvelope)content).getBody().
                        getFirstElement().getQName();
            case SPINE:
                return ((XMLSpine)content).getOperationElement();
            case SOAPENVELOPE:
                Iterator it = ((SOAPEnvelope)content).getBody().getChildElements();
                while (it.hasNext()) {
                    Node node = (Node)it.next();
                    if (node instanceof SOAPElement) {
                        Name name = ((SOAPElement)node).getElementName();
                        return new QName(name.getURI(), name.getLocalName(), name.getPrefix());
                    }
                }
        }
        return null;
    } catch (SOAPException se) {
        throw ExceptionFactory.makeWebServiceException(se);
    }
}
项目:wso2-axis2    文件:SoapMessageProviderTests.java   
/**
 * Common assertion checking of the response
 * @param msg
 * @param expectedText
 * @return SOAPElement representing the data element
 */
private SOAPElement assertResponseXML(SOAPMessage msg, String expectedText) throws Exception {
    assertTrue(msg != null);
    SOAPBody body = msg.getSOAPBody();
    assertTrue(body != null);

    Node invokeElement = (Node) body.getFirstChild();
    assertTrue(invokeElement instanceof SOAPElement);
    assertEquals(SoapMessageProvider.RESPONSE_NAME, invokeElement.getLocalName());

    Node dataElement = (Node) invokeElement.getFirstChild();
    assertTrue(dataElement instanceof SOAPElement);
    assertEquals(SoapMessageProvider.RESPONSE_DATA_NAME, dataElement.getLocalName());

    // TODO AXIS2 SAAJ should (but does not) support the getTextContent();
    // String text = dataElement.getTextContent();
    String text = dataElement.getValue();
    assertEquals("Found ("+ text + ") but expected (" + expectedText + ")", expectedText, text);

    return (SOAPElement) dataElement;
}
项目:wso2-axis2    文件:SoapMessageProvider.java   
/**
 * Common assertion checking of the request
 * @param msg
 * @return SOAPElement representing the data element
 */
private SOAPElement assertRequestXML(SOAPMessage msg) throws Exception {
    assertTrue(msg != null);
    SOAPBody body = msg.getSOAPBody();
    assertTrue(body != null);

    Node invokeElement = (Node) body.getFirstChild();
    assertTrue(invokeElement instanceof SOAPElement);
    assertTrue(SoapMessageProvider.REQUEST_NAME.equals(invokeElement.getLocalName()));

    Node discElement = (Node) invokeElement.getFirstChild();
    assertTrue(discElement instanceof SOAPElement);
    assertTrue(SoapMessageProvider.REQUEST_DATA_NAME.equals(discElement.getLocalName()));

    String text = discElement.getValue();
    assertTrue(text != null);
    assertTrue(text.length() > 0);
    System.out.println("Request Message Type is:" + text);

    return (SOAPElement) discElement;
}
项目:wso2-axis2    文件:SoapMessageProviderTests.java   
/**
 * Common assertion checking of the response
 * @param msg
 * @param expectedText
 * @return SOAPElement representing the data element
 */
private SOAPElement assertResponseXML(SOAPMessage msg, String expectedText) throws Exception {
    assertTrue(msg != null);
    SOAPBody body = msg.getSOAPBody();
    assertTrue(body != null);

    Node invokeElement = (Node) body.getFirstChild();
    assertTrue(invokeElement instanceof SOAPElement);
    assertEquals(SoapMessageProvider.RESPONSE_NAME, invokeElement.getLocalName());

    Node dataElement = (Node) invokeElement.getFirstChild();
    assertTrue(dataElement instanceof SOAPElement);
    assertEquals(SoapMessageProvider.RESPONSE_DATA_NAME, dataElement.getLocalName());

    // TODO AXIS2 SAAJ should (but does not) support the getTextContent();
    // String text = dataElement.getTextContent();
    String text = dataElement.getValue();
    assertEquals("Found ("+ text + ") but expected (" + expectedText + ")", expectedText, text);

    return (SOAPElement) dataElement;
}
项目:wso2-axis2    文件:SoapMessageProvider.java   
/**
 * Common assertion checking of the request
 * @param msg
 * @return SOAPElement representing the data element
 */
private SOAPElement assertRequestXML(SOAPMessage msg) throws Exception {
    assertTrue(msg != null);
    SOAPBody body = msg.getSOAPBody();
    assertTrue(body != null);

    Node invokeElement = (Node) body.getFirstChild();
    assertTrue(invokeElement instanceof SOAPElement);
    assertTrue(SoapMessageProvider.REQUEST_NAME.equals(invokeElement.getLocalName()));

    Node discElement = (Node) invokeElement.getFirstChild();
    assertTrue(discElement instanceof SOAPElement);
    assertTrue(SoapMessageProvider.REQUEST_DATA_NAME.equals(discElement.getLocalName()));

    String text = discElement.getValue();
    assertTrue(text != null);
    assertTrue(text.length() > 0);
    TestLogger.logger.debug("Request Message Type is:" + text);

    return (SOAPElement) discElement;
}
项目:wso2-axis2    文件:AddressingProviderTests.java   
private SOAPElement assertResponseXML(SOAPMessage msg, String expectedText) throws Exception {
    assertTrue(msg != null);
    SOAPBody body = msg.getSOAPBody();
    assertTrue(body != null);

    Node invokeElement = (Node) body.getFirstChild();
    assertTrue(invokeElement instanceof SOAPElement);
    assertEquals("outMessage", invokeElement.getLocalName());

    String text = invokeElement.getValue();

    System.out.println("Received: " + text);
    assertEquals("Found ("+ text + ") but expected (" + expectedText + ")", expectedText, text);

    return (SOAPElement) invokeElement;
}
项目:wso2-axis2    文件:SOAPFaultImpl.java   
private Iterator getChildren(Iterator childIter) {
    Collection childElements = new ArrayList();
    while (childIter.hasNext()) {
        org.w3c.dom.Node domNode = (org.w3c.dom.Node)childIter.next();
        Node saajNode = toSAAJNode(domNode);
        if (!(saajNode instanceof SOAPFaultElement)) {
            // silently replace node, as per saaj 1.2 spec
            SOAPFaultElement bodyEle = new SOAPFaultElementImpl((ElementImpl)domNode);
            ((NodeImpl)domNode).setUserData(SAAJ_NODE, bodyEle, null);
            childElements.add(bodyEle);
        } else {
            childElements.add(saajNode);
        }
    }
    return childElements.iterator();
}
项目:wso2-axis2    文件:SOAPHeaderImpl.java   
private Iterator getChildren(Iterator childIter) {
    Collection childElements = new ArrayList();
    while (childIter.hasNext()) {
        org.w3c.dom.Node domNode = (org.w3c.dom.Node)childIter.next();
        Node saajNode = toSAAJNode(domNode);
        if (saajNode instanceof javax.xml.soap.Text) {
            childElements.add(saajNode);
        } else if (!(saajNode instanceof SOAPHeaderElement)) {
            // silently replace node, as per saaj 1.2 spec
            SOAPHeaderElement headerEle = new SOAPHeaderElementImpl((SOAPHeaderBlock)domNode);
            ((NodeImpl)domNode).setUserData(SAAJ_NODE, headerEle, null);
            childElements.add(headerEle);
        } else {
            childElements.add(saajNode);
        }
    }
    return childElements.iterator();
}
项目:wso2-axis2    文件:NodeImplEx.java   
/**
 * Converts or extracts the SAAJ node from the given DOM Node (domNode)
 *
 * @param domNode
 * @return the SAAJ Node corresponding to the domNode
 */
static javax.xml.soap.Node toSAAJNode(org.w3c.dom.Node domNode, Node parentNode) {
    if (domNode == null) {
        return null;
    }
    Node saajNode = (Node)((NodeImpl)domNode).getUserData(SAAJ_NODE);
    if (saajNode == null) {  // if SAAJ node has not been set in userData, try to construct it
        return toSAAJNode2(domNode, parentNode);
    }
    // update siblings for text nodes
    if (domNode instanceof org.w3c.dom.Text || domNode instanceof org.w3c.dom.Comment) {
        org.w3c.dom.Node prevSiblingDOMNode = domNode.getPreviousSibling();
        org.w3c.dom.Node nextSiblingDOMNode = domNode.getNextSibling();

        TextImplEx saajTextNode = (TextImplEx)saajNode;

        saajTextNode.setPreviousSibling(prevSiblingDOMNode);
        saajTextNode.setNextSibling(nextSiblingDOMNode);
    }
    return saajNode;
}
项目:wso2-axis2    文件:SOAPElementTest.java   
public void _testGetChildElements() throws Exception {
    SOAPElement childEle1 =
            SOAPFactoryImpl.newInstance().createElement("Child1",
                                                        "ch",
                                                        "http://test.apache.org/");
    SOAPElement childEle2 =
            SOAPFactoryImpl.newInstance().createElement("Child2",
                                                        "ch",
                                                        "http://test.apache.org/");
    childEle1.addChildElement(childEle2);
    soapEle.addChildElement(childEle1);

    QName qname = new QName("http://test.apache.org/", "Child1", "ch");
    Iterator childElements = soapEle.getChildElements(qname);


    int childCount = 0;
    while (childElements.hasNext()) {
        Node node = (Node)childElements.next();
        childCount++;
    }
    assertEquals(childCount, 2);
}
项目:wso2-axis2    文件:SOAPElementTest.java   
@Validated @Test
public void testGetChildElements2() throws Exception {
    MessageFactory fact = MessageFactory.newInstance();
    SOAPMessage message = fact.createMessage();
    SOAPPart soapPart = message.getSOAPPart();
    SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
    SOAPBody soapBody = soapEnvelope.getBody();

    Name name = soapEnvelope.createName("MyChild1");
    SOAPElement se = soapBody.addChildElement(name);
    Iterator childElementsCount = soapBody.getChildElements();
    Iterator childElements = soapBody.getChildElements();

    int childCount = 0;
    while (childElementsCount.hasNext()) {
        Node node = (Node)childElementsCount.next();
        childCount++;
    }
    assertEquals(childCount, 1);
    SOAPElement se2 = (SOAPElement)childElements.next();
    if (!se.equals(se2)) {
        fail();
    } else {
        System.out.println("SOAPElement se = se2 (expected)");
    }

    Name n = se.getElementName();
    assertEquals(n, name);
}
项目:wso2-axis2    文件:SOAPElementTest.java   
@Validated @Test
public void testGetChildElements3() throws Exception {
    MessageFactory fact = MessageFactory.newInstance();
    SOAPMessage message = fact.createMessage();
    SOAPPart soapPart = message.getSOAPPart();
    SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
    SOAPBody soapBody = soapEnvelope.getBody();

    //Name name = soapEnvelope.createName("MyChild1");
    QName name = new QName("MyChild1");
    SOAPElement se = soapBody.addChildElement(name);
    Iterator childElementsCount = soapBody.getChildElements();
    Iterator childElements = soapBody.getChildElements();

    int childCount = 0;
    while (childElementsCount.hasNext()) {
        Node node = (Node)childElementsCount.next();
        childCount++;
    }
    assertEquals(childCount, 1);
    SOAPElement se2 = (SOAPElement)childElements.next();
    assertEquals(se, se2);

    QName n = se.getElementQName();
    assertEquals(n, name);
}
项目:mappingtools    文件:SOAPClient.java   
/**
 * extract XML Elements from the response
 * @param response SOAP message from the server
 * @return array of XML Elements in the message
 * @throws SOAPException
 */
private Element[] handleResponse(SOAPMessage response) throws SOAPException
{
       SOAPBody soapBody = response.getSOAPBody();
    Vector<Element> nodes = new Vector<Element>();

       // put the reply into a Vector of Elements
    for (Iterator<?> it =  soapBody.getChildElements(); it.hasNext();)
       {
          Node next = (Node)it.next();
          if (next instanceof SOAPBodyElement) nodes.add((SOAPBodyElement)next);
       }

       // turn a Vector of Elements into an Array of Elements
    Element[] reply = new Element[nodes.size()];
       for (int i = 0; i < nodes.size(); i++) reply[i] = nodes.elementAt(i);
    return reply;
}
项目:mappingtools    文件:SOAPClient.java   
private void addNamespaces(Element el)
{
    NamedNodeMap attMap = el.getAttributes();
    for (int a = 0; a < attMap.getLength();a++)
    {
        org.w3c.dom.Node nd = attMap.item(a);
        if (nd instanceof Attr)
        {
            Attr at = (Attr)nd;
            String attName = at.getName();
            if (attName.startsWith("xmlns"))
            {
                String prefix = "";
                if (attName.length() > 6) prefix = attName.substring(6);
                String uri = at.getValue();
                namespaces.put(prefix, uri);
                //System.out.println("Recorded namespace " + prefix);  
            }
        }
    }

}
项目:oscm    文件:SoapRequestParserTest.java   
@Test
public void parseApiVersion_cm_1_8() throws Exception {
    // given
    SOAPPart part = mock(SOAPPart.class);
    SOAPEnvelope envelope = mock(SOAPEnvelope.class);
    SOAPHeader soapHeader = mock(SOAPHeader.class);
    List<Node> version = new ArrayList<Node>();
    Node node = mock(Node.class);
    doReturn("testVersion").when(node).getValue();
    version.add(node);
    Iterator<?> it = version.iterator();
    doReturn(it).when(soapHeader).extractHeaderElements(
            eq("cm.service.version"));
    doReturn(soapHeader).when(envelope).getHeader();
    doReturn(envelope).when(part).getEnvelope();
    doReturn(part).when(message).getSOAPPart();
    // when
    String result = SoapRequestParser.parseApiVersion(context);

    // then
    assertEquals("testVersion", result);
}