1

please, Can you help me?
All of source here it is.
(https://github.com/mcvzone/integration-tcp-test.git)

Thank you.

1. I created a spring integration-tcp-client context xml file.

    <int:gateway id="gw"
                 service-interface="com.example.demo.module.SimpleGateway"
                 default-request-channel="input"/>

    <int-ip:tcp-connection-factory id="client"
                                   type="client"
                                   host="localhost"
                                   port="1234"
                                   single-use="true"
                                   so-timeout="10000"/>

    <int:channel id="input"/>

    <int-ip:tcp-outbound-gateway id="outGateway"
                                 request-channel="input"
                                 reply-channel="clientBytes2StringChannel"
                                 connection-factory="client"
                                 request-timeout="10000"
                                 reply-timeout="10000"/>

    <int:object-to-string-transformer id="clientBytes2String"
                                      input-channel="clientBytes2StringChannel"/>

2. And I created a RestController.

@RestController
public class TcpController {
    
    final GenericXmlApplicationContext context;
    final SimpleGateway simpleGateway;
    
    public TcpController(){
        this.context = new GenericXmlApplicationContext();
        context.load("classpath:META-INF/spring/integration/tcpClientServerDemo-context.xml");
        context.registerShutdownHook();
        context.refresh();
        
        this.simpleGateway = context.getBean(SimpleGateway.class);
    }
    
    @RequestMapping("/tcp/test")
    public String test(String name) {
        //SimpleGateway simpleGateway = context.getBean(SimpleGateway.class);
        String result = simpleGateway.send(name);
        System.out.println("result : " + result);
        return result;
    }

}

3. I start spring boot and open 1234 port (new ServerSocket(1234)) and I call url.(http://localhost:8080/tcp/test)
4. It result is error.

java.lang.IllegalArgumentException: unable to determine a Message or payload parameter on method
.
.
.
at com.sun.proxy.$Proxy60.send(Unknown Source) ~[na:na]
at com.example.demo.TcpController.test(TcpController.java:25) ~[classes/:na]
neo
  • 57
  • 5

1 Answers1

0

It has started to work when I changed your code to this:

@RequestMapping("/tcp/test")
public String test(@RequestBody String name) {

Pay attention to the @RequestBody on the method param. By default Spring MVC does not know to what from the request to map into an argument for this param. So, it is left as null.

On the other hand, when the argument for that gateway call is null, Spring Integration cannot create a Message<?> to send because the payload cannot be null. Therefore you end up with such an exception.

We probably may revise that exception message to make it more obvious for end-users what is going on. Feel free to raise a GH issue on the matter!

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118