INT-3140: Add #xpath() SpEL Function Support
JIRA: https://jira.springsource.org/browse/INT-3140 * Introduce `XPathUtils` * Add `#xpath()` tests * Add documentation INT-3140: Polishing according PR comments INT-3140 Polishing - Doc and javadoc polishing - Fix some compiler warnings (not all xpath)
This commit is contained in:
committed by
Gary Russell
parent
fa59b50bdc
commit
88de8117aa
@@ -174,6 +174,31 @@ public abstract class AbstractIntegrationNamespaceHandler implements NamespaceHa
|
||||
}
|
||||
}
|
||||
|
||||
String xpathBeanName = "xpath";
|
||||
alreadyRegistered = false;
|
||||
if (parserContext.getRegistry() instanceof ListableBeanFactory) {
|
||||
alreadyRegistered = ((ListableBeanFactory) parserContext.getRegistry()).containsBean(xpathBeanName);
|
||||
}
|
||||
else {
|
||||
alreadyRegistered = parserContext.getRegistry().isBeanNameInUse(xpathBeanName);
|
||||
}
|
||||
if (!alreadyRegistered) {
|
||||
Class<?> xpathClass = null;
|
||||
try {
|
||||
xpathClass = ClassUtils.forName(IntegrationNamespaceUtils.BASE_PACKAGE + ".xml.xpath.XPathUtils",
|
||||
parserContext.getReaderContext().getBeanClassLoader());
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
logger.debug("SpEL function '#xpath' isn't registered: there is no spring-integration-xml.jar on the classpath.");
|
||||
}
|
||||
|
||||
if (xpathClass != null) {
|
||||
IntegrationNamespaceUtils.registerSpelFunctionBean(parserContext.getRegistry(), xpathBeanName,
|
||||
IntegrationNamespaceUtils.BASE_PACKAGE + ".xml.xpath.XPathUtils", "evaluate");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.doRegisterBuiltInBeans(parserContext);
|
||||
}
|
||||
|
||||
|
||||
@@ -301,6 +301,7 @@ public class ChainParserTests {
|
||||
final AtomicReference<String> log = new AtomicReference<String>();
|
||||
when(logger.isWarnEnabled()).thenReturn(true);
|
||||
doAnswer(new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
log.set((String) invocation.getArguments()[0]);
|
||||
return null;
|
||||
@@ -394,7 +395,7 @@ public class ChainParserTests {
|
||||
assertTrue(this.beanFactory.containsBean("recipientListRouterChain$child.recipientListRouterWithinChain.handler"));
|
||||
|
||||
MessageHandlerChain chain = this.beanFactory.getBean("headerEnricherChain.handler", MessageHandlerChain.class);
|
||||
List handlers = TestUtils.getPropertyValue(chain, "handlers", List.class);
|
||||
List<?> handlers = TestUtils.getPropertyValue(chain, "handlers", List.class);
|
||||
|
||||
assertTrue(handlers.get(0) instanceof MessageTransformingHandler);
|
||||
assertEquals("headerEnricherChain$child.headerEnricherWithinChain", TestUtils.getPropertyValue(handlers.get(0), "componentName"));
|
||||
|
||||
@@ -28,14 +28,11 @@ import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.Scanner;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
|
||||
import com.jayway.jsonpath.Criteria;
|
||||
import com.jayway.jsonpath.Filter;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -51,8 +48,12 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
|
||||
import com.jayway.jsonpath.Criteria;
|
||||
import com.jayway.jsonpath.Filter;
|
||||
|
||||
/**
|
||||
* @author Artem Bilan
|
||||
* @author Gary Russell
|
||||
* @since 3.0
|
||||
*/
|
||||
@ContextConfiguration(classes = JsonPathTests.JsonPathTestsContextConfiguration.class, loader = AnnotationConfigContextLoader.class)
|
||||
@@ -69,7 +70,9 @@ public class JsonPathTests {
|
||||
public static void setUp() throws IOException {
|
||||
ClassPathResource jsonResource = new ClassPathResource("JsonPathTests.json", JsonPathTests.class);
|
||||
JSON_FILE = jsonResource.getFile();
|
||||
JSON = new Scanner(JSON_FILE).useDelimiter("\\Z").next();
|
||||
Scanner scanner = new Scanner(JSON_FILE);
|
||||
JSON = scanner.useDelimiter("\\Z").next();
|
||||
scanner.close();
|
||||
testMessage = new GenericMessage<String>(JSON);
|
||||
}
|
||||
|
||||
@@ -208,7 +211,7 @@ public class JsonPathTests {
|
||||
public static class JsonPathTestsContextConfiguration {
|
||||
|
||||
@Bean
|
||||
public Filter jsonPathFilter() {
|
||||
public Filter<?> jsonPathFilter() {
|
||||
return Filter.filter(Criteria.where("isbn").exists(true).and("category").ne("fiction"));
|
||||
}
|
||||
|
||||
|
||||
@@ -171,7 +171,7 @@ public class SpelTransformerIntegrationTests {
|
||||
|
||||
@Override
|
||||
public Class<?>[] getSpecificTargetClasses() {
|
||||
return new Class[] {Foo.class};
|
||||
return new Class<?>[] {Foo.class};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user