N
N
Natalia2019-04-20 17:14:23
Java
Natalia, 2019-04-20 17:14:23

Why can't fetch content with the Jersey Client when Nginx is enabled?

I am writing a link shortener. For some reason there shouldn't be a redirect, so I download the content from the link using the Jersey client and serve it to the user.

private Client client = ClientBuilder.newClient();

    @GET
    @Path("{code}")
    public Response getContentLink(@PathParam("code") String code) {
        return client
                .target(shortUrlService.getCommonUrl(code)) //получение длинной ссылки из базы
                .request(MediaType.TEXT_HTML)
                .get();
    }

The long link refers to the same application. The application is running in Tomcat. Everything worked great on the test, there were problems in production.
1. Direct access to a long link works correctly.
2. Trying to load content from another application using the code above from a long link works correctly.
3. Following a short link gives an error org.apache.http.ConnectionClosedException: Premature end of chunk coded message body: closing chunk expected
and An I/O error has occurred while writing a response message entity to the container output stream.
The most obvious difference between a test server and a production server is the presence of Nginx. What could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Natalia, 2019-04-24
@nalie

In general, the problem was not in the nginx settings, but in the disposability (?) of the Response object. It is not clear why it worked on the test. Decided like this:

private Client client = ClientBuilder.newClient();

    @GET
    @Path("{code}")
    public Response getContentLink(@PathParam("code") String code) {
        Response response = client
                .target(shortUrlService.getCommonUrl(code)) //получение длинной ссылки из базы
                .request(MediaType.TEXT_HTML)
                .get();
        return Response
                .status(response.getStatus())
                .entity(response.getEntity())
                .build();
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question