Java TCPINBundGateway-读取特定字节数
我应该如何实现service activator来读取特定数量的字节 My context.xmlJava TCPINBundGateway-读取特定字节数,java,spring,tcp,spring-integration,Java,Spring,Tcp,Spring Integration,我应该如何实现service activator来读取特定数量的字节 My context.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int="http://www.springframewo
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-ip="http://www.springframework.org/schema/integration/ip"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="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.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/ip http://www.springframework.org/schema/integration/ip/spring-integration-ip.xsd">
<int:annotation-config />
<context:component-scan base-package="com.spring.integration.tcp" />
<bean id="tcpDeserializer"
class="org.springframework.integration.ip.tcp.serializer.ByteArrayLengthHeaderSerializer">
<property name="maxMessageSize" value="300" />
</bean>
<int-ip:tcp-connection-factory id="tcpConnectionFactory" type="server" port="9070" using-nio="true" deserializer="tcpDeserializer" />
<int:channel id="tcpRequestChannel" />
<int-ip:tcp-inbound-gateway id="tcpInboundGateway" connection-factory="tcpConnectionFactory" request-channel="tcpRequestChannel" />
<bean id="messageHandler" class="com.spring.integration.tcp.MessageHandler" />
<int:service-activator id="tcpServiceActivator" input-channel="tcpRequestChannel" ref="messageHandler" method="receiveAndSend" />
</beans>
我希望读取前4个字节并确定传入消息的长度(从前4个字节开始),然后读取长度由前4个字节指定的消息字节
添加反序列化程序后,我得到以下异常。虽然我发送了一个长度为161的字节数组
final byte[] data = new byte[] { 2,....};
例外情况
Sep 28, 2015 7:03:28 PM org.springframework.integration.ip.tcp.connection.TcpNetConnection handleReadException
SEVERE: Read exception localhost:54756:9070:a580527b-95bd-42c7-b1cc-e0726b433199 IOException:Message length 38159362 exceeds max message length: 300
客户机是否应该基于spring integration才能向基于spring integration的服务器发送消息?您应该将
配置为定义上的反序列化器
有关更多信息,请参阅其JavaDocs:
* The default length field is a 4 byte signed integer. During deserialization,
* negative values will be rejected.
* Other options are an unsigned byte, and unsigned short.
请参阅框架提供的标准(反)序列化程序。不要对非代码的文本使用代码格式。JavaDoc是一种代码。没有理由因为这样的原因滥用编辑权限…添加反序列化程序后出现异常。更新了问题。我看到你的问题了。不太可能,但您应该使用ByteArrayLengthHeaderSerializer.serialize在添加反序列化程序后更新的算法问题。
* The default length field is a 4 byte signed integer. During deserialization,
* negative values will be rejected.
* Other options are an unsigned byte, and unsigned short.