INT-1041 only falling back to default service interface at initialization time rather than in the default constructor so that getObjectType() returns null instead of inconsistent type information
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -73,14 +73,21 @@ public class GatewayProxyFactoryBean extends AbstractEndpoint implements Factory
|
||||
|
||||
private Map<String, GatewayMethodDefinition> methodToChannelMap;
|
||||
|
||||
|
||||
/**
|
||||
* Will initialize this Factory with he default instance of the 'gateway' interface
|
||||
* {@link GenericSendAndRecieveGateway} which will be used by this proxy if
|
||||
* 'service-interface' attribute is not set.
|
||||
* Create a Factory whose service interface type can be configured by setter injection.
|
||||
* If none is set, it will fall back to the default service interface type,
|
||||
* {@link GenericSendAndRecieveGateway}, upon initialization.
|
||||
*/
|
||||
public GatewayProxyFactoryBean(){
|
||||
this.serviceInterface = GenericSendAndRecieveGateway.class;
|
||||
public GatewayProxyFactoryBean() {
|
||||
// serviceInterface will be determined on demand later
|
||||
}
|
||||
|
||||
public GatewayProxyFactoryBean(Class<?> serviceInterface) {
|
||||
this.serviceInterface = serviceInterface;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the interface class that the generated proxy should implement.
|
||||
* If none is provided explicitly, the default is MessageHandler.
|
||||
@@ -91,6 +98,7 @@ public class GatewayProxyFactoryBean extends AbstractEndpoint implements Factory
|
||||
this.serviceInterface = serviceInterface;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the default request channel.
|
||||
*
|
||||
@@ -148,24 +156,35 @@ public class GatewayProxyFactoryBean extends AbstractEndpoint implements Factory
|
||||
if (this.initialized) {
|
||||
return;
|
||||
}
|
||||
Assert.notNull(this.serviceInterface, "'serviceInterface' must not be null");
|
||||
Method[] methods = this.serviceInterface.getDeclaredMethods();
|
||||
Class<?> proxyInterface = this.determineServiceInterface();
|
||||
Method[] methods = proxyInterface.getDeclaredMethods();
|
||||
for (Method method : methods) {
|
||||
MessagingGateway gateway = this.createGatewayForMethod(method);
|
||||
this.gatewayMap.put(method, gateway);
|
||||
}
|
||||
this.serviceProxy = new ProxyFactory(this.serviceInterface, this).getProxy(this.beanClassLoader);
|
||||
this.serviceProxy = new ProxyFactory(proxyInterface, this).getProxy(this.beanClassLoader);
|
||||
this.start();
|
||||
this.initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
public Object getObject() throws Exception {
|
||||
return this.serviceProxy;
|
||||
private Class<?> determineServiceInterface() {
|
||||
if (this.serviceInterface == null) {
|
||||
this.serviceInterface = GenericSendAndRecieveGateway.class;
|
||||
}
|
||||
return this.serviceInterface;
|
||||
}
|
||||
|
||||
public Class<?> getObjectType() {
|
||||
return this.serviceInterface;
|
||||
return (this.serviceInterface != null ? this.serviceInterface : null);
|
||||
}
|
||||
|
||||
public Object getObject() throws Exception {
|
||||
if (this.serviceProxy == null) {
|
||||
this.onInit();
|
||||
Assert.notNull(this.serviceProxy, "failed to initialize proxy");
|
||||
}
|
||||
return this.serviceProxy;
|
||||
}
|
||||
|
||||
public boolean isSingleton() {
|
||||
|
||||
@@ -29,6 +29,7 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.integration.channel.PollableChannel;
|
||||
@@ -290,6 +291,11 @@ public class GatewayProxyFactoryBeanTests {
|
||||
assertEquals("testBridge", event3.getComponentName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void autowiredGateway() {
|
||||
new ClassPathXmlApplicationContext("gatewayAutowiring.xml", GatewayProxyFactoryBeanTests.class);
|
||||
}
|
||||
|
||||
|
||||
public static void throwTestException() throws TestException {
|
||||
throw new TestException();
|
||||
@@ -312,4 +318,15 @@ public class GatewayProxyFactoryBeanTests {
|
||||
static class TestException extends Exception {
|
||||
}
|
||||
|
||||
|
||||
public static class TestClient {
|
||||
|
||||
private final TestService service;
|
||||
|
||||
@Autowired
|
||||
public TestClient(TestService service) {
|
||||
this.service = service;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/integration"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
|
||||
|
||||
<context:annotation-config/>
|
||||
|
||||
<beans:bean id="testClient" class="org.springframework.integration.gateway.GatewayProxyFactoryBeanTests$TestClient"/>
|
||||
|
||||
<channel id="requestChannel"/>
|
||||
|
||||
<beans:bean id="proxy" class="org.springframework.integration.gateway.GatewayProxyFactoryBean">
|
||||
<beans:property name="serviceInterface" value="org.springframework.integration.gateway.TestService"/>
|
||||
<beans:property name="defaultRequestChannel" ref="requestChannel"/>
|
||||
</beans:bean>
|
||||
|
||||
</beans:beans>
|
||||
Reference in New Issue
Block a user