0
votes

related question

I am sending message from REST API to SI message channel, which delegate to a sending message adapter. The message adapter send a message to TCP client. nothing needs to be return/response. My TCP client successfully received the message but the MVC controller throw an exception

Controller code

@Autowired
    MessageChannel invokeChannel;
    @RequestMapping(value="/invoke/{payload}")
    public ResponseEntity<String> sayHello(@PathVariable String payload)
    {
        //trigger gateway to send a message     
        MessagingTemplate template = new MessagingTemplate();       
        template.send(invokeChannel, new GenericMessage<String>(payload));      
        return new ResponseEntity<String>(payload, HttpStatus.OK);
    }

The Exception

java.lang.IllegalArgumentException: No converter found for return value of type: class java.lang.String org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:178) org.springframework.web.servlet.mvc.method.annotation.HttpEntityMethodProcessor.handleReturnValue(HttpEntityMethodProcessor.java:183) org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:80) org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:126) org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:814) org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:737) org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:969) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:860) javax.servlet.http.HttpServlet.service(HttpServlet.java:622) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:845) javax.servlet.http.HttpServlet.service(HttpServlet.java:729) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

I couldn't find where and what is causing this. my breakpoint at return new ResponseEntity(...) is not reached.

my webmvcconfig

@EnableWebMvc
@Configuration
@ComponentScan({ "helloworldmvc" })
public class WebappConfig extends WebMvcConfigurerAdapter {

    @Bean
    public static PropertySourcesPlaceholderConfigurer propertyConfigIn() {
        return new PropertySourcesPlaceholderConfigurer();
    }

    @Override
    public void configureMessageConverters(
            List<HttpMessageConverter<?>> converters) {
        converters.add(new MongoMessageConverter());
    }
}
2

2 Answers

1
votes

//trigger gateway to send a message

You should be sure that your flow for the template.send(invokeChannel) is really one-way. No one gateway may wait for rely there. That is for your comment like:

my breakpoint at return new ResponseEntity(...) is not reached.

If you can't reach that row of code, try to debug exactly that AbstractMessageConverterMethodProces. And there is need to figure out why producibleMediaTypes after the code:

    List<MediaType> producibleMediaTypes = getProducibleMediaTypes(servletRequest, clazz, type);

    if (value != null && producibleMediaTypes.isEmpty()) {
        throw new IllegalArgumentException("No converter found for return value of type: " + clazz);
    }

is empty. Maybe you request uses some Accept non-compatible with the String? Or your WebMvcConfigurer overrides List<HttpMessageConverter<?>> converters somehow without any String-awere converter?

1
votes

Error message:

No converter found for return value of type: class java.lang.String

It says that the MVC doesn't know which converter use to return the REST response from this service. to use the default converter which are available in spring.

Please add an annotation @ResposeBody in the method signature.