502 error code – BAD GATEWAY

This topic has been reported for inappropriate content

This topic has 1 reply, 2 voices, and was last updated 7 years, 2 months ago by Mark Craig.

  • Author
  • #5675

    In my installation, OpenIG doesn’t work if the system, where the backend web application is deployed, is not reachable by ping.

    The OpenIG response is 502 – BAD Gateway.

    I’m currently using OpenIG 4.0.0.

    Is it some check that has been implemented before the request is forwarded to backend?

    Thanks in advance.

     Mark Craig


    HTTP 502 Bad Gateway indicates an invalid response from the server. Since in this case there’s actually no response, it might be nicer if OpenIG could return HTTP 503 Service Unavailable or HTTP 504 Gateway Timeout (if it waits for the timeout) in this case. Perhaps it’s worth logging an RFE for that at https://bugster.forgerock.org/jira/browse/OPENIG.

    You could potentially add a ScriptableFilter to make the error HTTP 503 Service Unavailable. Here’s an example route that works on /test:

        "handler": {
            "type": "Chain",
            "config": {
                "filters": [
                        "type": "ScriptableFilter",
                        "config": {
                            "type": "application/x-groovy",
                              " // Change 'Bad Gateway' to 'Service Unavailable'
                                import org.forgerock.http.protocol.Response;
                                import org.forgerock.http.protocol.Status;
                                import org.forgerock.util.promise.ResultHandler;
                                return next.handle(context, request)
                                  .thenOnResult(new ResultHandler<Response>() {
                                      public void handleResult(final Response response) {
                                          if (response.status == Status.BAD_GATEWAY) {
                                              response.status = Status.SERVICE_UNAVAILABLE
                "handler": "ClientHandler"
        "condition": "${matches(exchange.request.uri.path, '^/test')}"

    The result for the client application looks almost the same as before but with the HTTP status code 503:

    $ curl -v http://www.example.com:8080/test
    *   Trying ::1...
    * Connected to www.example.com (::1) port 8080 (#0)
    > GET /test HTTP/1.1
    > Host: www.example.com:8080
    > User-Agent: curl/7.43.0
    > Accept: */*
    < HTTP/1.1 503 Service Unavailable
    < Date: Fri, 02 Oct 2015 06:51:04 GMT
    < Content-Length: 62
    < Server: Jetty(8.1.15.v20140411)
    * Connection #0 to host www.example.com left intact
    Failed to obtain response for http://www.example.com:8081/test
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

©2022 ForgeRock - we provide an identity and access platform to secure every online relationship for the enterprise market, educational sector and even entire countries. Click to view our privacy policy and terms of use.

Log in with your credentials

Forgot your details?