@Test public void testExecutionIOException() throws Exception { final HttpClientConnection conn = Mockito.mock(HttpClientConnection.class); final HttpRequestExecutor executor = new HttpRequestExecutor(); final HttpCoreContext context = HttpCoreContext.create(); final ClassicHttpRequest request = new BasicClassicHttpRequest(Method.GET, "/"); Mockito.doThrow(new IOException("Oopsie")).when(conn).sendRequestHeader(request); try { executor.execute(request, conn, context); Assert.fail("IOException should have been thrown"); } catch (final IOException ex) { Mockito.verify(conn).close(); } }
public ClassicHttpResponse execute( final ClassicHttpRequest request, final HttpClientConnection conn, final HttpResponseInformationCallback informationCallback, final HttpContext context) throws IOException, HttpException { Args.notNull(request, "HTTP request"); Args.notNull(conn, "Client connection"); Args.notNull(context, "HTTP context"); try { context.setAttribute(HttpCoreContext.SSL_SESSION, conn.getSSLSession()); context.setAttribute(HttpCoreContext.CONNECTION_ENDPOINT, conn.getEndpointDetails()); conn.sendRequestHeader(request); if (streamListener != null) { streamListener.onRequestHead(conn, request); } boolean expectContinue = false; final HttpEntity entity = request.getEntity(); if (entity != null) { final Header expect = request.getFirstHeader(HttpHeaders.EXPECT); expectContinue = expect != null && HeaderElements.CONTINUE.equalsIgnoreCase(expect.getValue()); if (!expectContinue) { conn.sendRequestEntity(request); } } conn.flush(); ClassicHttpResponse response = null; while (response == null) { if (expectContinue) { if (conn.isDataAvailable(this.waitForContinue)) { response = conn.receiveResponseHeader(); if (streamListener != null) { streamListener.onResponseHead(conn, response); } final int status = response.getCode(); if (status == HttpStatus.SC_CONTINUE) { response = null; conn.sendRequestEntity(request); } else if (status < HttpStatus.SC_SUCCESS) { if (informationCallback != null) { informationCallback.execute(response, conn, context); } response = null; continue; } else if (status >= HttpStatus.SC_CLIENT_ERROR){ conn.terminateRequest(request); } else { conn.sendRequestEntity(request); } } else { conn.sendRequestEntity(request); } conn.flush(); expectContinue = false; } else { response = conn.receiveResponseHeader(); if (streamListener != null) { streamListener.onResponseHead(conn, response); } final int status = response.getCode(); if (status < HttpStatus.SC_INFORMATIONAL) { throw new ProtocolException("Invalid response: " + new StatusLine(response)); } if (status < HttpStatus.SC_SUCCESS) { if (informationCallback != null && status != HttpStatus.SC_CONTINUE) { informationCallback.execute(response, conn, context); } response = null; } } } if (MessageSupport.canResponseHaveBody(request.getMethod(), response)) { conn.receiveResponseEntity(response); } return response; } catch (final HttpException | IOException | RuntimeException ex) { Closer.closeQuietly(conn); throw ex; } }
HttpRequestExecutor { public ClassicHttpResponse execute( final ClassicHttpRequest request, final HttpClientConnection conn, final HttpResponseInformationCallback informationCallback, final HttpContext context) throws IOException, HttpException { Args.notNull(request, "HTTP request"); Args.notNull(conn, "Client connection"); Args.notNull(context, "HTTP context"); try { context.setAttribute(HttpCoreContext.SSL_SESSION, conn.getSSLSession()); context.setAttribute(HttpCoreContext.CONNECTION_ENDPOINT, conn.getEndpointDetails()); conn.sendRequestHeader(request); if (streamListener != null) { streamListener.onRequestHead(conn, request); } boolean expectContinue = false; final HttpEntity entity = request.getEntity(); if (entity != null) { final Header expect = request.getFirstHeader(HttpHeaders.EXPECT); expectContinue = expect != null && HeaderElements.CONTINUE.equalsIgnoreCase(expect.getValue()); if (!expectContinue) { conn.sendRequestEntity(request); } } conn.flush(); ClassicHttpResponse response = null; while (response == null) { if (expectContinue) { if (conn.isDataAvailable(this.waitForContinue)) { response = conn.receiveResponseHeader(); if (streamListener != null) { streamListener.onResponseHead(conn, response); } final int status = response.getCode(); if (status == HttpStatus.SC_CONTINUE) { response = null; conn.sendRequestEntity(request); } else if (status < HttpStatus.SC_SUCCESS) { if (informationCallback != null) { informationCallback.execute(response, conn, context); } response = null; continue; } else if (status >= HttpStatus.SC_CLIENT_ERROR){ conn.terminateRequest(request); } else { conn.sendRequestEntity(request); } } else { conn.sendRequestEntity(request); } conn.flush(); expectContinue = false; } else { response = conn.receiveResponseHeader(); if (streamListener != null) { streamListener.onResponseHead(conn, response); } final int status = response.getCode(); if (status < HttpStatus.SC_INFORMATIONAL) { throw new ProtocolException("Invalid response: " + new StatusLine(response)); } if (status < HttpStatus.SC_SUCCESS) { if (informationCallback != null && status != HttpStatus.SC_CONTINUE) { informationCallback.execute(response, conn, context); } response = null; } } } if (MessageSupport.canResponseHaveBody(request.getMethod(), response)) { conn.receiveResponseEntity(response); } return response; } catch (final HttpException | IOException | RuntimeException ex) { Closer.closeQuietly(conn); throw ex; } } }
HttpRequestExecutor { public ClassicHttpResponse execute( final ClassicHttpRequest request, final HttpClientConnection conn, final HttpResponseInformationCallback informationCallback, final HttpContext context) throws IOException, HttpException { Args.notNull(request, "HTTP request"); Args.notNull(conn, "Client connection"); Args.notNull(context, "HTTP context"); try { context.setAttribute(HttpCoreContext.SSL_SESSION, conn.getSSLSession()); context.setAttribute(HttpCoreContext.CONNECTION_ENDPOINT, conn.getEndpointDetails()); conn.sendRequestHeader(request); if (streamListener != null) { streamListener.onRequestHead(conn, request); } boolean expectContinue = false; final HttpEntity entity = request.getEntity(); if (entity != null) { final Header expect = request.getFirstHeader(HttpHeaders.EXPECT); expectContinue = expect != null && HeaderElements.CONTINUE.equalsIgnoreCase(expect.getValue()); if (!expectContinue) { conn.sendRequestEntity(request); } } conn.flush(); ClassicHttpResponse response = null; while (response == null) { if (expectContinue) { if (conn.isDataAvailable(this.waitForContinue)) { response = conn.receiveResponseHeader(); if (streamListener != null) { streamListener.onResponseHead(conn, response); } final int status = response.getCode(); if (status == HttpStatus.SC_CONTINUE) { response = null; conn.sendRequestEntity(request); } else if (status < HttpStatus.SC_SUCCESS) { if (informationCallback != null) { informationCallback.execute(response, conn, context); } response = null; continue; } else if (status >= HttpStatus.SC_CLIENT_ERROR){ conn.terminateRequest(request); } else { conn.sendRequestEntity(request); } } else { conn.sendRequestEntity(request); } conn.flush(); expectContinue = false; } else { response = conn.receiveResponseHeader(); if (streamListener != null) { streamListener.onResponseHead(conn, response); } final int status = response.getCode(); if (status < HttpStatus.SC_INFORMATIONAL) { throw new ProtocolException("Invalid response: " + new StatusLine(response)); } if (status < HttpStatus.SC_SUCCESS) { if (informationCallback != null && status != HttpStatus.SC_CONTINUE) { informationCallback.execute(response, conn, context); } response = null; } } } if (MessageSupport.canResponseHaveBody(request.getMethod(), response)) { conn.receiveResponseEntity(response); } return response; } catch (final HttpException | IOException | RuntimeException ex) { Closer.closeQuietly(conn); throw ex; } } HttpRequestExecutor(
            final Timeout waitForContinue,
            final ConnectionReuseStrategy connReuseStrategy,
            final Http1StreamListener streamListener);  HttpRequestExecutor(final ConnectionReuseStrategy connReuseStrategy);  HttpRequestExecutor(); }
HttpRequestExecutor { public ClassicHttpResponse execute( final ClassicHttpRequest request, final HttpClientConnection conn, final HttpResponseInformationCallback informationCallback, final HttpContext context) throws IOException, HttpException { Args.notNull(request, "HTTP request"); Args.notNull(conn, "Client connection"); Args.notNull(context, "HTTP context"); try { context.setAttribute(HttpCoreContext.SSL_SESSION, conn.getSSLSession()); context.setAttribute(HttpCoreContext.CONNECTION_ENDPOINT, conn.getEndpointDetails()); conn.sendRequestHeader(request); if (streamListener != null) { streamListener.onRequestHead(conn, request); } boolean expectContinue = false; final HttpEntity entity = request.getEntity(); if (entity != null) { final Header expect = request.getFirstHeader(HttpHeaders.EXPECT); expectContinue = expect != null && HeaderElements.CONTINUE.equalsIgnoreCase(expect.getValue()); if (!expectContinue) { conn.sendRequestEntity(request); } } conn.flush(); ClassicHttpResponse response = null; while (response == null) { if (expectContinue) { if (conn.isDataAvailable(this.waitForContinue)) { response = conn.receiveResponseHeader(); if (streamListener != null) { streamListener.onResponseHead(conn, response); } final int status = response.getCode(); if (status == HttpStatus.SC_CONTINUE) { response = null; conn.sendRequestEntity(request); } else if (status < HttpStatus.SC_SUCCESS) { if (informationCallback != null) { informationCallback.execute(response, conn, context); } response = null; continue; } else if (status >= HttpStatus.SC_CLIENT_ERROR){ conn.terminateRequest(request); } else { conn.sendRequestEntity(request); } } else { conn.sendRequestEntity(request); } conn.flush(); expectContinue = false; } else { response = conn.receiveResponseHeader(); if (streamListener != null) { streamListener.onResponseHead(conn, response); } final int status = response.getCode(); if (status < HttpStatus.SC_INFORMATIONAL) { throw new ProtocolException("Invalid response: " + new StatusLine(response)); } if (status < HttpStatus.SC_SUCCESS) { if (informationCallback != null && status != HttpStatus.SC_CONTINUE) { informationCallback.execute(response, conn, context); } response = null; } } } if (MessageSupport.canResponseHaveBody(request.getMethod(), response)) { conn.receiveResponseEntity(response); } return response; } catch (final HttpException | IOException | RuntimeException ex) { Closer.closeQuietly(conn); throw ex; } } HttpRequestExecutor(
            final Timeout waitForContinue,
            final ConnectionReuseStrategy connReuseStrategy,
            final Http1StreamListener streamListener);  HttpRequestExecutor(final ConnectionReuseStrategy connReuseStrategy);  HttpRequestExecutor(); ClassicHttpResponse execute(
            final ClassicHttpRequest request,
            final HttpClientConnection conn,
            final HttpResponseInformationCallback informationCallback,
            final HttpContext context); ClassicHttpResponse execute(
            final ClassicHttpRequest request,
            final HttpClientConnection conn,
            final HttpContext context); void preProcess(
            final ClassicHttpRequest request,
            final HttpProcessor processor,
            final HttpContext context); void postProcess(
            final ClassicHttpResponse response,
            final HttpProcessor processor,
            final HttpContext context); boolean keepAlive(
            final ClassicHttpRequest request,
            final ClassicHttpResponse response,
            final HttpClientConnection connection,
            final HttpContext context); }
HttpRequestExecutor { public ClassicHttpResponse execute( final ClassicHttpRequest request, final HttpClientConnection conn, final HttpResponseInformationCallback informationCallback, final HttpContext context) throws IOException, HttpException { Args.notNull(request, "HTTP request"); Args.notNull(conn, "Client connection"); Args.notNull(context, "HTTP context"); try { context.setAttribute(HttpCoreContext.SSL_SESSION, conn.getSSLSession()); context.setAttribute(HttpCoreContext.CONNECTION_ENDPOINT, conn.getEndpointDetails()); conn.sendRequestHeader(request); if (streamListener != null) { streamListener.onRequestHead(conn, request); } boolean expectContinue = false; final HttpEntity entity = request.getEntity(); if (entity != null) { final Header expect = request.getFirstHeader(HttpHeaders.EXPECT); expectContinue = expect != null && HeaderElements.CONTINUE.equalsIgnoreCase(expect.getValue()); if (!expectContinue) { conn.sendRequestEntity(request); } } conn.flush(); ClassicHttpResponse response = null; while (response == null) { if (expectContinue) { if (conn.isDataAvailable(this.waitForContinue)) { response = conn.receiveResponseHeader(); if (streamListener != null) { streamListener.onResponseHead(conn, response); } final int status = response.getCode(); if (status == HttpStatus.SC_CONTINUE) { response = null; conn.sendRequestEntity(request); } else if (status < HttpStatus.SC_SUCCESS) { if (informationCallback != null) { informationCallback.execute(response, conn, context); } response = null; continue; } else if (status >= HttpStatus.SC_CLIENT_ERROR){ conn.terminateRequest(request); } else { conn.sendRequestEntity(request); } } else { conn.sendRequestEntity(request); } conn.flush(); expectContinue = false; } else { response = conn.receiveResponseHeader(); if (streamListener != null) { streamListener.onResponseHead(conn, response); } final int status = response.getCode(); if (status < HttpStatus.SC_INFORMATIONAL) { throw new ProtocolException("Invalid response: " + new StatusLine(response)); } if (status < HttpStatus.SC_SUCCESS) { if (informationCallback != null && status != HttpStatus.SC_CONTINUE) { informationCallback.execute(response, conn, context); } response = null; } } } if (MessageSupport.canResponseHaveBody(request.getMethod(), response)) { conn.receiveResponseEntity(response); } return response; } catch (final HttpException | IOException | RuntimeException ex) { Closer.closeQuietly(conn); throw ex; } } HttpRequestExecutor(
            final Timeout waitForContinue,
            final ConnectionReuseStrategy connReuseStrategy,
            final Http1StreamListener streamListener);  HttpRequestExecutor(final ConnectionReuseStrategy connReuseStrategy);  HttpRequestExecutor(); ClassicHttpResponse execute(
            final ClassicHttpRequest request,
            final HttpClientConnection conn,
            final HttpResponseInformationCallback informationCallback,
            final HttpContext context); ClassicHttpResponse execute(
            final ClassicHttpRequest request,
            final HttpClientConnection conn,
            final HttpContext context); void preProcess(
            final ClassicHttpRequest request,
            final HttpProcessor processor,
            final HttpContext context); void postProcess(
            final ClassicHttpResponse response,
            final HttpProcessor processor,
            final HttpContext context); boolean keepAlive(
            final ClassicHttpRequest request,
            final ClassicHttpResponse response,
            final HttpClientConnection connection,
            final HttpContext context); static final Timeout DEFAULT_WAIT_FOR_CONTINUE; }