Search in sources :

Example 6 with Node

use of org.w3c.dom.Node in project camel by apache.

the class SoapTargetBean method invokeSoapMessage.

public SOAPMessage invokeSoapMessage(SOAPMessage request) {
    SOAPMessage response = null;
    try {
        SOAPBody body = request.getSOAPBody();
        Node n = body.getFirstChild();
        while (n.getNodeType() != Node.ELEMENT_NODE) {
            n = n.getNextSibling();
        }
        if (n.getLocalName().equals(sayHi.getLocalPart())) {
            response = sayHiResponse;
        } else if (n.getLocalName().equals(greetMe.getLocalPart())) {
            response = greetMeResponse;
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return response;
}
Also used : SOAPBody(javax.xml.soap.SOAPBody) Node(org.w3c.dom.Node) SOAPMessage(javax.xml.soap.SOAPMessage)

Example 7 with Node

use of org.w3c.dom.Node in project camel by apache.

the class CxfMessageHeadersRelayTest method validateReturnedOutOfBandHeaderWithInsertion.

protected static void validateReturnedOutOfBandHeaderWithInsertion(Map<String, Object> responseContext, boolean expect) {
    List<OutofBandHeader> hdrToTest = new ArrayList<OutofBandHeader>();
    List<Header> oobHdr = CastUtils.cast((List<?>) responseContext.get(Header.HEADER_LIST));
    if (!expect) {
        if (oobHdr == null || (oobHdr != null && oobHdr.size() == 0)) {
            return;
        }
        fail("Should have got *no* out-of-band headers, but some were found");
    }
    if (oobHdr == null) {
        fail("Should have got List of out-of-band headers");
    }
    assertTrue("HeaderHolder list expected to conain 2 object received " + oobHdr.size(), oobHdr.size() == 2);
    for (Header hdr1 : oobHdr) {
        if (hdr1.getObject() instanceof Node) {
            try {
                JAXBElement<?> job = (JAXBElement<?>) JAXBContext.newInstance(org.apache.cxf.outofband.header.ObjectFactory.class).createUnmarshaller().unmarshal((Node) hdr1.getObject());
                hdrToTest.add((OutofBandHeader) job.getValue());
            } catch (JAXBException ex) {
                ex.printStackTrace();
            }
        }
    }
    assertTrue("out-of-band header should not be null", hdrToTest.size() > 0);
    assertTrue("Expected out-of-band Header name testOobReturnHeaderName recevied :" + hdrToTest.get(0).getName(), "testOobReturnHeaderName".equals(hdrToTest.get(0).getName()));
    assertTrue("Expected out-of-band Header value testOobReturnHeaderValue recevied :" + hdrToTest.get(0).getValue(), "testOobReturnHeaderValue".equals(hdrToTest.get(0).getValue()));
    assertTrue("Expected out-of-band Header attribute testReturnHdrAttribute recevied :" + hdrToTest.get(0).getHdrAttribute(), "testReturnHdrAttribute".equals(hdrToTest.get(0).getHdrAttribute()));
    assertTrue("Expected out-of-band Header name New_testOobHeader recevied :" + hdrToTest.get(1).getName(), "New_testOobHeader".equals(hdrToTest.get(1).getName()));
    assertTrue("Expected out-of-band Header value New_testOobHeaderValue recevied :" + hdrToTest.get(1).getValue(), "New_testOobHeaderValue".equals(hdrToTest.get(1).getValue()));
    assertTrue("Expected out-of-band Header attribute testHdrAttribute recevied :" + hdrToTest.get(1).getHdrAttribute(), "testHdrAttribute".equals(hdrToTest.get(1).getHdrAttribute()));
}
Also used : SoapHeader(org.apache.cxf.binding.soap.SoapHeader) OutofBandHeader(org.apache.cxf.outofband.header.OutofBandHeader) Header(org.apache.cxf.headers.Header) Node(org.w3c.dom.Node) JAXBException(javax.xml.bind.JAXBException) ArrayList(java.util.ArrayList) OutofBandHeader(org.apache.cxf.outofband.header.OutofBandHeader) JAXBElement(javax.xml.bind.JAXBElement)

Example 8 with Node

use of org.w3c.dom.Node in project camel by apache.

the class HeaderTesterWithInsertionImpl method verifyHeader.

private void verifyHeader(Object hdr, String headerName, String headerValue) {
    if (hdr instanceof Header && ((Header) hdr).getObject() instanceof Node) {
        Header hdr1 = (Header) hdr;
        try {
            JAXBElement<?> job = (JAXBElement<?>) JAXBContext.newInstance(org.apache.cxf.outofband.header.ObjectFactory.class).createUnmarshaller().unmarshal((Node) hdr1.getObject());
            OutofBandHeader ob = (OutofBandHeader) job.getValue();
            if (!headerName.equals(ob.getName())) {
                throw new RuntimeException("test failed expected name ' + headerName + ' but found '" + ob.getName() + "'");
            }
            if (!headerValue.equals(ob.getValue())) {
                throw new RuntimeException("test failed expected name ' + headerValue + ' but found '" + ob.getValue() + "'");
            }
        } catch (JAXBException ex) {
            throw new RuntimeException("test failed", ex);
        }
    } else {
        throw new RuntimeException("test failed. Unexpected type " + hdr.getClass());
    }
}
Also used : OutofBandHeader(org.apache.cxf.outofband.header.OutofBandHeader) Header(org.apache.cxf.headers.Header) Node(org.w3c.dom.Node) JAXBException(javax.xml.bind.JAXBException) OutofBandHeader(org.apache.cxf.outofband.header.OutofBandHeader) JAXBElement(javax.xml.bind.JAXBElement)

Example 9 with Node

use of org.w3c.dom.Node in project camel by apache.

the class XPathTest method testXPathNodeResult.

public void testXPathNodeResult() throws Exception {
    Object result = xpath("/foo/bar").nodeResult().evaluate(createExchange("<foo><bar xyz='cheese'/></foo>"));
    Node node = assertIsInstanceOf(Node.class, result);
    assertNotNull(node);
    String s = context.getTypeConverter().convertTo(String.class, node);
    assertEquals("<bar xyz=\"cheese\"/>", s);
}
Also used : Node(org.w3c.dom.Node)

Example 10 with Node

use of org.w3c.dom.Node in project camel by apache.

the class CamelNamespaceHandler method parseSecureRandomParametersNode.

private Metadata parseSecureRandomParametersNode(Element element, ParserContext context) {
    LOG.trace("Parsing SecureRandomParameters {}", element);
    // now parse the key store parameters with JAXB
    Binder<Node> binder;
    try {
        binder = getJaxbContext().createBinder();
    } catch (JAXBException e) {
        throw new ComponentDefinitionException("Failed to create the JAXB binder : " + e, e);
    }
    Object value = parseUsingJaxb(element, context, binder);
    if (!(value instanceof SecureRandomParametersFactoryBean)) {
        throw new ComponentDefinitionException("Expected an instance of " + SecureRandomParametersFactoryBean.class);
    }
    SecureRandomParametersFactoryBean srfb = (SecureRandomParametersFactoryBean) value;
    String id = srfb.getId();
    MutablePassThroughMetadata factory = context.createMetadata(MutablePassThroughMetadata.class);
    factory.setId(".camelBlueprint.passThrough." + id);
    factory.setObject(new PassThroughCallable<Object>(srfb));
    MutableBeanMetadata factory2 = context.createMetadata(MutableBeanMetadata.class);
    factory2.setId(".camelBlueprint.factory." + id);
    factory2.setFactoryComponent(factory);
    factory2.setFactoryMethod("call");
    factory2.setInitMethod("afterPropertiesSet");
    factory2.setDestroyMethod("destroy");
    factory2.addProperty("blueprintContainer", createRef(context, "blueprintContainer"));
    MutableBeanMetadata ctx = context.createMetadata(MutableBeanMetadata.class);
    ctx.setId(id);
    ctx.setRuntimeClass(SecureRandomParameters.class);
    ctx.setFactoryComponent(factory2);
    ctx.setFactoryMethod("getObject");
    // must be lazy as we want CamelContext to be activated first
    ctx.setActivation(ACTIVATION_LAZY);
    LOG.trace("Parsing SecureRandomParameters done, returning {}", ctx);
    return ctx;
}
Also used : MutablePassThroughMetadata(org.apache.aries.blueprint.mutable.MutablePassThroughMetadata) MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) ExpressionNode(org.apache.camel.model.ExpressionNode) Node(org.w3c.dom.Node) JAXBException(javax.xml.bind.JAXBException) SecureRandomParametersFactoryBean(org.apache.camel.util.blueprint.SecureRandomParametersFactoryBean)

Aggregations

Node (org.w3c.dom.Node)2347 NodeList (org.w3c.dom.NodeList)1062 Element (org.w3c.dom.Element)720 Document (org.w3c.dom.Document)545 NamedNodeMap (org.w3c.dom.NamedNodeMap)333 ArrayList (java.util.ArrayList)318 DocumentBuilder (javax.xml.parsers.DocumentBuilder)202 IOException (java.io.IOException)176 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)147 Test (org.junit.Test)132 HashMap (java.util.HashMap)127 Attr (org.w3c.dom.Attr)126 SAXException (org.xml.sax.SAXException)107 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)98 HashSet (java.util.HashSet)86 InputSource (org.xml.sax.InputSource)75 XPath (javax.xml.xpath.XPath)70 List (java.util.List)67 File (java.io.File)62 ByteArrayInputStream (java.io.ByteArrayInputStream)57