Search in sources :

Example 6 with XPathExpression

use of org.springframework.xml.xpath.XPathExpression in project spring-integration by spring-projects.

the class XPathExpressionParserTests method testNamespacedStringExpression.

@Test
public void testNamespacedStringExpression() throws Exception {
    String xmlDoc = "<si-xml:xpath-expression id='xpathExpression' expression='/ns1:name' ns-prefix='ns1' ns-uri='www.example.org' />";
    XPathExpression xPathExpression = getXPathExpression(xmlDoc);
    assertEquals("outputOne", xPathExpression.evaluateAsString(XmlTestUtil.getDocumentForString("<ns1:name xmlns:ns1='www.example.org'>outputOne</ns1:name>")));
    assertEquals("", xPathExpression.evaluateAsString(XmlTestUtil.getDocumentForString("<name>outputOne</name>")));
}
Also used : XPathExpression(org.springframework.xml.xpath.XPathExpression) Test(org.junit.Test)

Example 7 with XPathExpression

use of org.springframework.xml.xpath.XPathExpression in project spring-integration by spring-projects.

the class XPathRouterTests method multipleNodeValuesAsString.

@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public /*
	 * Will return only one (the first node text in the collection), since
	 * the evaluation return type use is String (not NODESET)
	 * This test is just for sanity and the reminder that setting 'evaluateAsNode'
	 * to 'false' would still result in no exception but result will most likely be
	 * not what is expected.
	 */
void multipleNodeValuesAsString() throws Exception {
    XPathExpression expression = XPathExpressionFactory.createXPathExpression("/doc/book");
    XPathRouter router = new XPathRouter(expression);
    router.setEvaluateAsString(true);
    Object[] channelNames = router.getChannelKeys(new GenericMessage("<doc type=\"one\"><book>bOne</book><book>bTwo</book></doc>")).toArray();
    assertEquals("Wrong number of channels returned", 1, channelNames.length);
    assertEquals("Wrong channel name", "bOne", channelNames[0]);
}
Also used : XPathExpression(org.springframework.xml.xpath.XPathExpression) GenericMessage(org.springframework.messaging.support.GenericMessage) Test(org.junit.Test)

Example 8 with XPathExpression

use of org.springframework.xml.xpath.XPathExpression in project spring-integration by spring-projects.

the class XPathRouterTests method testNonNodePayload.

@Test(expected = MessagingException.class)
public void testNonNodePayload() throws Exception {
    XPathExpression expression = XPathExpressionFactory.createXPathExpression("/doc/@type");
    XPathRouter router = new XPathRouter(expression);
    router.getChannelKeys(new GenericMessage<String>("test"));
}
Also used : XPathExpression(org.springframework.xml.xpath.XPathExpression) Test(org.junit.Test)

Example 9 with XPathExpression

use of org.springframework.xml.xpath.XPathExpression in project camel by apache.

the class SpringWebserviceComponent method addConsumerConfiguration.

private void addConsumerConfiguration(String remaining, Map<String, Object> parameters, SpringWebserviceConfiguration configuration) {
    EndpointMappingType type = EndpointMappingType.getTypeFromUriPrefix(remaining);
    if (type != null) {
        LOG.debug("Building Spring Web Services consumer of type " + type);
        String lookupKey = getLookupKey(remaining, type);
        if (EndpointMappingType.BEANNAME.equals(type)) {
            addEndpointDispatcherToConfiguration(configuration, lookupKey);
        } else {
            addEndpointMappingToConfiguration(parameters, configuration);
        }
        XPathExpression xPathExpression = null;
        if (type.equals(EndpointMappingType.XPATHRESULT)) {
            String expression = getAndRemoveParameter(parameters, "expression", String.class);
            configuration.setExpression(expression);
            xPathExpression = createXPathExpression(expression);
        }
        configuration.setEndpointMappingKey(new EndpointMappingKey(type, lookupKey, xPathExpression));
    }
}
Also used : XPathExpression(org.springframework.xml.xpath.XPathExpression) EndpointMappingKey(org.apache.camel.component.spring.ws.type.EndpointMappingKey) EndpointMappingType(org.apache.camel.component.spring.ws.type.EndpointMappingType)

Example 10 with XPathExpression

use of org.springframework.xml.xpath.XPathExpression in project spring-integration by spring-projects.

the class BooleanTestXpathMessageSelectorTests method testStringWithXPathExpressionProvided.

@Test
public void testStringWithXPathExpressionProvided() {
    XPathExpression xpathExpression = XPathExpressionFactory.createXPathExpression("boolean(/one/two)");
    BooleanTestXPathMessageSelector selector = new BooleanTestXPathMessageSelector(xpathExpression);
    assertTrue(selector.accept(new GenericMessage<String>("<one><two/></one>")));
    assertFalse(selector.accept(new GenericMessage<String>("<one><three/></one>")));
}
Also used : XPathExpression(org.springframework.xml.xpath.XPathExpression) GenericMessage(org.springframework.messaging.support.GenericMessage) Test(org.junit.Test)

Aggregations

XPathExpression (org.springframework.xml.xpath.XPathExpression)21 Test (org.junit.Test)18 Document (org.w3c.dom.Document)9 GenericMessage (org.springframework.messaging.support.GenericMessage)7 Node (org.w3c.dom.Node)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 EndpointMappingKey (org.apache.camel.component.spring.ws.type.EndpointMappingKey)1 EndpointMappingType (org.apache.camel.component.spring.ws.type.EndpointMappingType)1 HttpMessageConversionException (org.springframework.http.converter.HttpMessageConversionException)1 HttpMessageNotReadableException (org.springframework.http.converter.HttpMessageNotReadableException)1 HttpMessageNotWritableException (org.springframework.http.converter.HttpMessageNotWritableException)1 XPathException (org.springframework.xml.xpath.XPathException)1