From f4f7f40f18739bfbda2052015e1ec3cc24494635 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 4 Sep 2014 00:33:36 +0200 Subject: [PATCH] Test for actual HttpInvokerProxyFactoryBean usage with plain FactoryBean return type Issue: SPR-12141 --- ...ttpInvokerFactoryBeanIntegrationTests.java | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/spring-web/src/test/java/org/springframework/remoting/httpinvoker/HttpInvokerFactoryBeanIntegrationTests.java b/spring-web/src/test/java/org/springframework/remoting/httpinvoker/HttpInvokerFactoryBeanIntegrationTests.java index 6662037d4ca..46f712ca87b 100644 --- a/spring-web/src/test/java/org/springframework/remoting/httpinvoker/HttpInvokerFactoryBeanIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/remoting/httpinvoker/HttpInvokerFactoryBeanIntegrationTests.java @@ -27,6 +27,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Lazy; +import org.springframework.core.env.Environment; import org.springframework.remoting.support.RemoteInvocation; import org.springframework.remoting.support.RemoteInvocationResult; import org.springframework.scheduling.annotation.Async; @@ -60,6 +61,17 @@ public class HttpInvokerFactoryBeanIntegrationTests { myBean.myService.handleAsync(); } + @Test + public void withConfigurationClassWithPlainFactoryBean() { + AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); + context.register(ConfigWithPlainFactoryBean.class); + context.refresh(); + MyBean myBean = context.getBean("myBean", MyBean.class); + assertSame(context.getBean("myService"), myBean.myService); + myBean.myService.handle(); + myBean.myService.handleAsync(); + } + public interface MyService { @@ -93,7 +105,6 @@ public class HttpInvokerFactoryBeanIntegrationTests { HttpInvokerProxyFactoryBean factory = new HttpInvokerProxyFactoryBean(); factory.setServiceUrl("/svc/dummy"); factory.setServiceInterface(MyService.class); - Thread thread = Thread.currentThread(); factory.setHttpInvokerRequestExecutor(new HttpInvokerRequestExecutor() { @Override public RemoteInvocationResult executeRequest(HttpInvokerClientConfiguration config, RemoteInvocation invocation) { @@ -109,4 +120,32 @@ public class HttpInvokerFactoryBeanIntegrationTests { } } + + @Configuration + static class ConfigWithPlainFactoryBean { + + @Autowired + Environment env; + + @Bean + public MyBean myBean() { + return new MyBean(); + } + + @Bean + public FactoryBean myService() { + String name = env.getProperty("testbean.name"); + HttpInvokerProxyFactoryBean factory = new HttpInvokerProxyFactoryBean(); + factory.setServiceUrl("/svc/" + name); + factory.setServiceInterface(MyService.class); + factory.setHttpInvokerRequestExecutor(new HttpInvokerRequestExecutor() { + @Override + public RemoteInvocationResult executeRequest(HttpInvokerClientConfiguration config, RemoteInvocation invocation) { + return new RemoteInvocationResult(null); + } + }); + return factory; + } + } + }