The URL returns 504 error when called from HTTP


I have this code, to trigger some async http calls:

private CompleteRoutingResponseWrapper sendRoutingRequestString(int numOfTries, String routingRequestUrl) {
    routingRequestUrl = urlUtils.getHttpUrl(routingRequestUrl);

    CompleteRoutingResponseWrapper answer = new CompleteRoutingResponseWrapper();
    CloseableHttpClient client = HttpClientBuilder.create().build();
    CloseableHttpResponse response = null;
    try {

        Stopwatch stopWatch = Stopwatch.createStarted();
        response = client.execute(new HttpGet(routingRequestUrl));

        int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode != 200) {
            answer = retryOrHandleError(numOfTries, routingRequestUrl, answer, response, statusCode);
        } else {
            String bodyAsString = EntityUtils.toString(response.getEntity());
            answer.completeRoutingResponse = handleSuccess(bodyAsString);
            answer.latency = stopWatch.elapsed(TimeUnit.MILLISECONDS);
            handleErrorInBody(routingRequestUrl, answer, bodyAsString);
    } catch (Exception e) {
    return answer;


    public E2EResult sendBaselineRoutingRequestsInParallel(E2EResult e2EResult, List<String> routingRequestsList) {
        List<Callable<Void>> callables = new ArrayList<>();
        for (int i = 0; i < routingRequestsList.size(); i++) {
            final int position = i;
            callables.add(() -> {

//calls sendRoutingRequestString()

                synchronized (e2EResult) {
                    e2EResult.addResponse(relativePosition, requestPosition, routingResponse);
                return null;
        ExecutorService executorService = Executors.newFixedThreadPool(10);
        try {
            executorService.awaitTermination(1, TimeUnit.MINUTES);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        return e2EResult;

When the code calls this url it always return 504.
2015-04-20 12:00:27,580 [pool-6-thread-37] INFO  linqmap.routing.server.RoutingServer - ROUTING RECORDED:

however when I put it via the chrome browser I never get 504.

I thought it might be a stress issue. But even when I call only few urls in my code i get 504 for this specific url only.

What can it be? a bug in jersey for long url?

Looks like you are expecting a JSON response. I have noticed in some instances, the JSON parsing might have issues especially with embedded Jersey container, such as running it as part of a JUnit test.

When you run the URL directly against the browser, you are not parsing the JSON since you are just displaying the result in JSON by the browser. Browser's are very resilient to handling JSON.

Check and ensure that your code that is responsible for building the JSON object is doing it correctly.