33import java .io .EOFException ;
44import java .io .IOException ;
55import java .io .UnsupportedEncodingException ;
6+ import java .net .SocketTimeoutException ;
67import java .net .URISyntaxException ;
78import java .time .LocalDate ;
89import java .time .LocalDateTime ;
4243import org .apache .http .client .entity .UrlEncodedFormEntity ;
4344import org .apache .http .client .methods .RequestBuilder ;
4445import org .apache .http .client .utils .URIBuilder ;
46+ import org .apache .http .conn .ConnectTimeoutException ;
4547import org .apache .http .conn .HttpHostConnectException ;
4648import org .apache .http .conn .ssl .NoopHostnameVerifier ;
4749import org .apache .http .entity .ByteArrayEntity ;
@@ -65,6 +67,7 @@ public class HttpClientFilter extends RequestFilterBase {
6567 * instead of converting it to a String.
6668 */
6769 private static final List <String > RAW_BODY_CONTENT_TYPE_HINTS = Arrays .asList ("image" , "pdf" , "msword" );
70+ private static final int HTTP_STATUS_EXTERNAL_TIMEOUT = 531 ;
6871
6972 private static GsonBuilder gsonBuilder = new GsonBuilder ();
7073 private static final Gson GSON = gsonBuilder
@@ -157,6 +160,12 @@ public final void execute(Request request, Response response) {
157160 } finally {
158161 response .finish ();
159162 }
163+ } catch (ConnectTimeoutException e ) {
164+ httpResponse .setStatus (HttpStatus .valueOf (HTTP_STATUS_EXTERNAL_TIMEOUT ));
165+ throw new ConnectException ("Connection timeout: " + e .getMessage (), e );
166+ } catch (SocketTimeoutException e ) {
167+ httpResponse .setStatus (HttpStatus .valueOf (HTTP_STATUS_EXTERNAL_TIMEOUT ));
168+ throw new ConnectException ("Read timeout: " + e .getMessage (), e );
160169 } catch (SSLHandshakeException e ) {
161170 throw new HttpClientConnectException ("SSL handshake failed" , e );
162171 } catch (SSLException e ) {
0 commit comments