Autowiring a HttpInvoker remote client
Long story short - I'm having trouble getting HttpInvoker remote clients wired up via autowiring and java configuration.
This is the thing I want to autowire the field of (specifically, the DbServerInfo as a HttpInvoker)
Code:
class RelayQMessageHandler implements MessageHandler {
private Logger log = LoggerFactory.getLogger(this.getClass())
@Autowired DbServerInfo dbServerInfo
void handleMessage(Message<?> message) throws MessagingException {
SmtpRelayMessage smtpMsg = message.payload as SmtpRelayMessage
log.debug "RelayQMessageHandler: $message"
String echoValue = dbServerInfo.echoString("mesasge from $smtpMsg.from")
log.info "server reply: $echoValue"
}
}
And this is the relevant part of my configuration
Code:
@Configuration
@ImportResource(["classpath:/org/st/fort/smtprelay/SmtpRelayServer.xml"])
class AppConfig {
@Bean RelayQMessageHandler relayQMessageHandler(){
RelayQMessageHandler handler = new RelayQMessageHandler()
return handler
}
}
If I put this in SmtpRelayServer.xml, everything's peachy:
Code:
<bean id="httpInvokerProxy" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
<property name="serviceUrl" value="http://localhost:4242/fort-db-server/api/myDbServerInfo2"/>
<property name="serviceInterface" value="org.st.fort.dbserver.shared.remote.DbServerInfo"/>
</bean>
But I don't like wiring my beans with XML, this is the last thing to figure out and I can get rid of the XML file completely - so I want to configure the httpinvoker via the java configuration mechanism.
The thing I found some people were recommending to do (or similar) was:
Code:
String dbInfoUrl = "http://localhost:4242/fort-db-server/api/myDbServerInfo2"
@Bean HttpInvokerProxyFactoryBean dbServerInfoProxy() {
HttpInvokerProxyFactoryBean proxy = new HttpInvokerProxyFactoryBean()
proxy.serviceInterface = DbServerInfo
proxy.serviceUrl = dbInfoUrl
return proxy
}
But that doesn't work because it will fail to autowire (spring says no beans of type DbServerInfo) - oddly though, if I grab an ApplicationContext and call "appCtx.getBean(DbServerInfo)" that will work fine. So the looking up the object by the remote interface works fine directly on the ApplicationContext - but you can't autowire by it.
So, after a fair bit of faffing about, the closest I could come up with was to add this to my AppConfig:
Code:
String dbInfoUrl = "http://localhost:4242/fort-db-server/api/myDbServerInfo2"
@Bean DbServerInfo dbServerInfo() {
HttpInvokerProxyFactoryBean proxy = new HttpInvokerProxyFactoryBean()
proxy.serviceInterface = DbServerInfo
proxy.serviceUrl = dbInfoUrl
proxy.afterPropertiesSet()
return proxy.object as DbServerInfo
}
That works and will autowire - but because we're actually creating the remote client with that afterPropertiesSet/proxy.getObject combo, I can't change the url via a PropertyOverrideConfigurern (being my much preferred configuration mechanism).
I read this post, but I couldn't see a good way to use a PropertyOverrideConfigurer with it.
I also tried to bring in this old copy of the ConfigurationSupport class to help me out: https://github.com/jbaruch/spring-ja...ration-support
It looks like it's designed to do exactly what I want, but somehow the serviceUrl of the proxy gets set to null and then the init method of the httpinvokerproxyfactory freaks out.
Any suggestions on how I can do this with the java config and have the remote proxy be autowired and override configured properly?