Hi,
I tried to add a custom header to the message on the client side.
and the product service is defined asCode:<context:component-scan base-package="com.barnesandnoble.message"/> <beans:bean id="tcpSerializer" class="org.springframework.integration.ip.tcp.serializer.ByteArrayLengthHeaderSerializer"> <beans:property name="maxMessageSize" value="20480"/> </beans:bean> <beans:bean id="tcpDeserializer" class="org.springframework.integration.ip.tcp.serializer.ByteArrayLengthHeaderSerializer"> <beans:property name="maxMessageSize" value="20480"/> </beans:bean> <ip:tcp-connection-factory id="connectionFactory" serializer="tcpSerializer" deserializer="tcpDeserializer" type="client" host="${dev.message.client.message.bus.host}" port="${dev.message.client.message.bus.port}" using-nio="true" single-use="true" so-timeout="10000"/> <channel id="requestChannel"/> <channel id="replyChannel"/> <ip:tcp-outbound-gateway id="outGateway" request-channel="requestChannel" reply-channel="replyChannel" connection-factory="connectionFactory" request-timeout="10000" reply-timeout="10000"/> <gateway id="productGateway" default-request-channel="requestChannel" default-reply-channel="replyChannel" service-interface="com.barnesandnoble.message.server.iface.ProductService"> </gateway>
The client sent the message with the custom headerCode:public interface ProductService { @Gateway(requestChannel="requestChannel") void post(String productsInJSON, @Header(MessageHeader.STAGE) String stage); }
I can see the custom header in the logCode:productService.post(request, StageType.BASE.name());
But the problem is the server always complained there is no header stage.DEBUG: com.barnesandnoble.message.server.impl.ProductMess ageClient - Send request: {"products":[{"type":"BOOKS","ean":"2111251351325"}]}
DEBUG: org.springframework.integration.channel.DirectChan nel - preSend on channel 'requestChannel', message: [Payload={"products":[{"type":"BOOKS","ean":"2111251351325"}]}][Headers={timestamp=1297966333904, id=f1b8c089-1ea4-450d-ab85-1c6c531a3021, stage=BASE}]
DEBUG: org.springframework.integration.ip.tcp.TcpOutbound Gateway - org.springframework.integration.ip.tcp.TcpOutbound Gateway#0 received message: [Payload={"products":[{"type":"BOOKS","ean":"2111251351325"}]}][Headers={timestamp=1297966333904, id=f1b8c089-1ea4-450d-ab85-1c6c531a3021, stage=BASE}]
DEBUG: org.springframework.integration.ip.tcp.connection. TcpNioClientConnectionFactory - Opening new socket channel connection to localhost:8888
DEBUG: org.springframework.integration.ip.tcp.TcpOutbound Gateway - Added localhost:8888:1517879698
DEBUG: org.springframework.integration.ip.tcp.connection. TcpNioConnection - Message sent [Payload={"products":[{"type":"BOOKS","ean":"2111251351325"}]}][Headers={timestamp=1297966333904, id=f1b8c089-1ea4-450d-ab85-1c6c531a3021, stage=BASE}]
The server configuration is as follows.DEBUG - _initHandlerFor_stageRouter received message: [Payload=Products{Product{ean='2111251351325', type='BOOKS'} }][Headers={timestamp=1297966333924, id=a1defcec-7fe5-48f3-a6da-fef8d2c24e79, errorChannel=org.springframework.integration.core. MessagingTemplate$TemporaryReplyChannel@11613fe7, history=tcpProductGateway,requestChannel,productPu blishChannel, ip_address=127.0.0.1, replyChannel=org.springframework.integration.core. MessagingTemplate$TemporaryReplyChannel@11613fe7, ip_connection_seq=1, ip_hostname=localhost.localdomain, ip_tcp_remote_port=48629, ip_connection_id=localhost.localdomain:48629:43077 1672}]
2011-02-17 13:12:13,926 (pool-1-thread-15) [TcpInboundGateway.doSendAndReceive]
WARN - failure occurred in gateway sendAndReceive
org.springframework.integration.MessageHandlingExc eption: java.lang.IllegalArgumentException: required header not available: stage
at org.springframework.integration.handler.MethodInvo kingMessageProcessor.processMessage(MethodInvoking MessageProcessor.java:76)
BTW, I used Wireshark to check the tcp stream, but could not find any header information.Code:<beans:bean id="tcpSerializer" class="org.springframework.integration.ip.tcp.serializer.ByteArrayLengthHeaderSerializer"> <beans:property name="maxMessageSize" value="${message.bus.max.message.size}"/> </beans:bean> <beans:bean id="tcpDeserializer" class="org.springframework.integration.ip.tcp.serializer.ByteArrayLengthHeaderSerializer"> <beans:property name="maxMessageSize" value="${message.bus.max.message.size}"/> </beans:bean> <message-history tracked-components="*Gateway, *Channel, *Adapter"/> <ip:tcp-connection-factory id="gatewayConnectionFactory" serializer="tcpSerializer" deserializer="tcpDeserializer" type="server" pool-size="${message.bus.server.gateway.connection.pool.size}" using-nio="true" single-use="true" port="${message.bus.server.gateway.tcp.port}"/> <ip:tcp-inbound-gateway id="tcpProductGateway" connection-factory="gatewayConnectionFactory" request-channel="requestChannel" reply-channel="replyChannel" error-channel="errorChannel"/>
Do you know what was wrong here?
Thanks,
John


Reply With Quote
