|
13 | 13 | limitations under the License. */ |
14 | 14 | package com.predic8.membrane.core.interceptor; |
15 | 15 |
|
16 | | -import com.predic8.membrane.annot.*; |
17 | | -import com.predic8.membrane.core.exchange.*; |
18 | | -import com.predic8.membrane.core.proxies.*; |
19 | | -import com.predic8.membrane.core.transport.http.*; |
20 | | -import com.predic8.membrane.core.transport.http.client.*; |
21 | | -import com.predic8.membrane.core.util.*; |
22 | | -import org.slf4j.*; |
| 16 | +import com.predic8.membrane.annot.MCAttribute; |
| 17 | +import com.predic8.membrane.annot.MCChildElement; |
| 18 | +import com.predic8.membrane.annot.MCElement; |
| 19 | +import com.predic8.membrane.core.exchange.Exchange; |
| 20 | +import com.predic8.membrane.core.proxies.AbstractServiceProxy; |
| 21 | +import com.predic8.membrane.core.transport.http.EOFWhileReadingLineException; |
| 22 | +import com.predic8.membrane.core.transport.http.HttpClient; |
| 23 | +import com.predic8.membrane.core.transport.http.ProtocolUpgradeDeniedException; |
| 24 | +import com.predic8.membrane.core.transport.http.UnableToTunnelException; |
| 25 | +import com.predic8.membrane.core.transport.http.client.HttpClientConfiguration; |
| 26 | +import com.predic8.membrane.core.util.URLUtil; |
| 27 | +import org.slf4j.Logger; |
| 28 | +import org.slf4j.LoggerFactory; |
23 | 29 |
|
24 | 30 | import java.net.*; |
25 | 31 |
|
26 | 32 | import static com.predic8.membrane.core.exceptions.ProblemDetails.*; |
27 | | -import static com.predic8.membrane.core.interceptor.Interceptor.Flow.Set.*; |
28 | | -import static com.predic8.membrane.core.interceptor.Outcome.*; |
| 33 | +import static com.predic8.membrane.core.interceptor.Interceptor.Flow.Set.REQUEST_FLOW; |
| 34 | +import static com.predic8.membrane.core.interceptor.Outcome.ABORT; |
| 35 | +import static com.predic8.membrane.core.interceptor.Outcome.RETURN; |
29 | 36 |
|
30 | 37 | /** |
31 | 38 | * @description The <i>httpClient</i> sends the request of an exchange to a Web |
@@ -83,19 +90,40 @@ public Outcome handleRequest(Exchange exc) { |
83 | 90 | httpClient.call(exc); |
84 | 91 | return RETURN; |
85 | 92 | } catch (ConnectException e) { |
86 | | - String msg = "Target %s is not reachable.".formatted(getDestination(exc)); |
| 93 | + var msg = "Target %s is not reachable.".formatted(getDestination(exc)); |
87 | 94 | log.warn("{} {}", msg, PROXIES_HINT); |
88 | 95 | gateway(router.getConfiguration().isProduction(), getDisplayName()) |
| 96 | + .title("Bad Gateway") |
89 | 97 | .addSubSee("connect") |
90 | 98 | .status(502) |
91 | 99 | .detail(msg) |
92 | 100 | .buildAndSetResponse(exc); |
93 | 101 | return ABORT; |
| 102 | + } catch (SocketException e) { |
| 103 | + internal(router.getConfiguration().isProduction(), getDisplayName()) |
| 104 | + .title("Bad Gateway") |
| 105 | + .status(502) |
| 106 | + .addSubSee("socket-exception") |
| 107 | + .detail("Error communicating with target %s. Reason: %s".formatted(exc.getDestinations(), e.getMessage())) |
| 108 | + .stacktrace(false) |
| 109 | + .buildAndSetResponse(exc); |
| 110 | + return ABORT; |
| 111 | + } catch (EOFWhileReadingLineException e) { |
| 112 | + internal(router.getConfiguration().isProduction(), getDisplayName()) |
| 113 | + .title("Bad Gateway") |
| 114 | + .status(502) |
| 115 | + .detail("Backend closed the connection before the response was complete.") |
| 116 | + .addSubSee("socket-closed") |
| 117 | + .stacktrace(false) |
| 118 | + .buildAndSetResponse(exc); |
| 119 | + return ABORT; |
94 | 120 | } catch (SocketTimeoutException e) { |
95 | 121 | // Details are logged further down in the HTTPClient |
| 122 | + log.info("Target {} is not reachable.",exc.getDestinations()); |
96 | 123 | internal(router.getConfiguration().isProduction(), getDisplayName()) |
| 124 | + .title("Gateway Timeout") |
| 125 | + .status(504) |
97 | 126 | .addSubSee("socket-timeout") |
98 | | - .detail("Target %s is not reachable.".formatted(exc.getDestinations())) |
99 | 127 | .buildAndSetResponse(exc); |
100 | 128 | return ABORT; |
101 | 129 | } catch (UnknownHostException e) { |
|
0 commit comments