前提・実現したいこと
Spring Integrationにて異なるプロトコル間(HTTP通信・ソケット通信)のデータ通信*1をWebアプリとして実現したいです。
*1 クライアント -> (HTTP通信) -> Webアプリ -> (ソケット通信) -> 他サーバー
下記実装で疎通確認出来たのですが、下記設計(実装)がベストプラクティスなのかご教示頂きたいです。
DispatcherServlet -> inbound-gateway -> Channel -> ServiceActivator -> Channel -> tcp-outbound-gateway
Spring Integrationの知識が乏しく、見当違いなことを言っていたら指摘お願いします。
該当のソースコード
web.xml
<servlet> <servlet-name>appServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/servlet-config.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>appServlet</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping>
servlet-config.xml
xml
1<context:component-scan base-package="jp.co.sample"/> 2 3<int-http:inbound-gateway 4 request-channel="channel" path="/" supported-methods="POST" 5 request-payload-type="byte[]" /> 6 7<int:channel id="channel" />
SampleService.java
java
1package jp.co.sample; 2 3@EnableIntegration 4@MessageEndpoint 5public class SampleService { 6 7 @ServiceActivator(inputChannel="channel") 8 public byte[] send(byte[] requestParam) { 9 final GenericXmlApplicationContext context = SampleService.setupContext(); 10 final SampleGateway gateway = context.getBean(SampleGateway.class); 11 return gateway.send(requestParam); 12 } 13 14 public static GenericXmlApplicationContext setupContext() { 15 final GenericXmlApplicationContext context = new GenericXmlApplicationContext(); 16 context.load("classpath:META-INF/spring/integration/sample-context.xml"); 17 context.registerShutdownHook(); 18 context.refresh(); 19 return context; 20 } 21}
sample-context.xml
xml
1<context:property-placeholder 2 location="classpath*:META-INF/spring/integration/*.properties" 3 local-override="true" /> 4 5<int:gateway id="gateway" 6 service-interface="jp.co.sample.SampleGateway" 7 default-request-channel="request" error-channel="errorChannel" /> 8 9<int-ip:tcp-connection-factory 10 id="client" type="client" host="${server.host}" 11 port="${server.port}" single-use="true" so-timeout="10000" 12 serializer="byteArrayRawSerializer" 13 deserializer="byteArrayRawSerializer" /> 14 15<int:channel id="request" /> 16 17<int-ip:tcp-outbound-gateway 18 id="outGateway" request-channel="request" connection-factory="client" 19 request-timeout="10000" reply-timeout="10000" /> 20 21<bean id="byteArrayRawSerializer" 22 class="org.springframework.integration.ip.tcp.serializer.ByteArrayRawSerializer"> 23 <property name="maxMessageSize" value="100000" /> 24</bean> 25 26<int:transformer id="errorHandler" 27 input-channel="errorChannel" 28 expression="payload.failedMessage.payload + ':' + payload.cause.message" />
あなたの回答
tips
プレビュー