D
D
Dik_Nik2019-07-11 20:09:13
Java
Dik_Nik, 2019-07-11 20:09:13

How to read text/plain server response data in @FeignClient?

Hello. Please help me figure it out.
I have the following controller on the server

@RestController
@RequestMapping(path = "/models")
public class AppController {

    private ModelService modelService;

    @Autowired
    public AppController(ModelService modelService) {
        this.modelService = modelService;
    }

    @PostMapping(value = "/{modelName}/token")
    public String login(
            @PathVariable("modelName") String modelName,
            @RequestBody Auth auth
    ) {
        return modelService.login(modelName, auth);
    }
}

And the following client:
@FeignClient(name = "connector")
@RequestMapping(path = "/models")
public interface ApiClient {
    @RequestMapping(method = RequestMethod.GET, value = "/{modelName}/token", consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation("Getting a token for the model")
    String login(
            @PathVariable("modelName") String modelName,
            @RequestBody Auth auth
    );

}

For some reason I can't read the response from the server, which looks like this:
HTTP/1.1 200 
    Content-Type: text/plain;charset=UTF-8
    Content-Length: 4
    Date: Thu, 11 Jul 2019 16:35:18 GMT
    
    !...!

Throws Exception:
org.springframework.cloud.sleuth.instrument.web.ExceptionLoggingFilter: Uncaught exception thrown
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is feign.FeignException: Unexpected character ('!' (code 33)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
 at [Source: (BufferedReader); line: 1, column: 2] reading GET http://localhost:9091/models/123/token
  at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:982)

As I understand it, he thinks that json is coming to him. I tried to put produces = MediaType.TEXT_PLAIN_VALUE, but it didn't work. He just doesn't notice it.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question