Thanks for the advice and the links.
I spent some time on this today and this is what I came up with. It mostly works, but I'm running into a few problems.
First, the channel and gateway definitions:
Code:
<int:channel id="inboundChannel"></int:channel>
<int:channel id="outboundChannel"></int:channel>
<bean id="podActivator" class="com.mcafee.orion.globaldirector.spring.PodServiceActivator">
<property name="channel" ref="outboundChannel"/>
</bean>
<http:inbound-gateway request-channel="inboundChannel" name="/{subject}" path="/{subject}" supported-methods="GET,POST">
<http:header name="subject" expression="#pathVariables.subject"/>
</http:inbound-gateway>
<http:outbound-gateway request-channel="outboundChannel" url="{outBoundGatewayUrl}" http-method="POST"
expected-response-type="java.lang.String"
reply-timeout="5000" charset="UTF-8">
<http:uri-variable name="outBoundGatewayUrl" expression="headers['X_REQUEST_URL']"/>
</http:outbound-gateway>
<int:service-activator id="notification.activator" input-channel="inboundChannel" ref="podActivator"/>
I figured a ServiceActivator was the best way to get my custom logic to determine where to dispatch the request to. For my simple test, I am just printing the message and then dispatching to a well-known URL.
Code:
@Component
public class PodServiceActivator {
private MessageChannel channel;
@ServiceActivator
public void receive( Message<?> message )
{
// send URL was http://localhost:8080/notification/c...&action=create
System.out.println("Http message: " + message );
System.out.println(message.getHeaders().get("subject"); // customer -- yay!
LinkedMultiValueMap m = (LinkedMultiValueMap) message.getPayload();
Message msg = MessageBuilder.withPayload( "<notification xmlns=" + m.get("<notification xmlns").get(0) )
.setHeader( "X_REQUEST_URL", "http://localhost:8080/bps/customer?accountNumber=9999&action=create")
.setHeader( "Content-Type", "application/text" ).build();
channel.send( msg );
}
public void setChannel( MessageChannel channel )
{
this.channel = channel;
}
}
This kinda works but there are a few problems (some misconfigurations and misunderstandings on my part, surely
)
The first is that the message is a LinkedMultiValueMap with three entries: 1->accountNumber, 2->action, and 3->my xml payload... unfortunately, when I put the message back into the channel, it comes out on the DSS all glommed together. To counter this, I have to generate a new message and parse out the xml element, but it is keyed as a string ("<notification xmlns="). Perhaps I need to specify a different mime-type?
The second problem is that when it does dispatch to the DSS, the URI '?' is escaped so the values can't be parsed correctly there...
Code:
/bps/customer%3FaccountNumber=9999&action=create)
This last issue seems to be due to a problem with UriTemplate as discussed here:
http://forum.springsource.org/showth...tbound-gateway
I don't have a good fix for this last problem, but the first part looks workable (if ugly). Now I need to figure out how to handle the responses.