Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java TCPINBundGateway-读取特定字节数_Java_Spring_Tcp_Spring Integration - Fatal编程技术网

Java TCPINBundGateway-读取特定字节数

Java 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

我应该如何实现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.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.