public HttpResponse execute(HttpRequest request) throws IOException, HttpException { HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProcessor processor = new ImmutableHttpProcessor(new RequestContent()); HttpRequestExecutor executor = new HttpRequestExecutor(); HttpContext context = new BasicHttpContext(null); context.setAttribute(ExecutionContext.HTTP_CONNECTION, connection); if (!connection.isOpen()) { Socket socket = new Socket(address.getAddress(), address.getPort()); connection.bind(socket, params); } context.setAttribute(ExecutionContext.HTTP_REQUEST, request); request.setParams(params); executor.preProcess(request, processor, context); HttpResponse response = executor.execute(request, connection, context); executor.postProcess(response, processor, context); return response; }
@Deprecated public DefaultRequestDirector( final HttpRequestExecutor requestExec, final ClientConnectionManager conman, final ConnectionReuseStrategy reustrat, final ConnectionKeepAliveStrategy kastrat, final HttpRoutePlanner rouplan, final HttpProcessor httpProcessor, final HttpRequestRetryHandler retryHandler, final RedirectHandler redirectHandler, final AuthenticationHandler targetAuthHandler, final AuthenticationHandler proxyAuthHandler, final UserTokenHandler userTokenHandler, final HttpParams params) { this(LogFactory.getLog(DefaultRequestDirector.class), requestExec, conman, reustrat, kastrat, rouplan, httpProcessor, retryHandler, new DefaultRedirectStrategyAdaptor(redirectHandler), new AuthenticationStrategyAdaptor(targetAuthHandler), new AuthenticationStrategyAdaptor(proxyAuthHandler), userTokenHandler, params); }
@Deprecated public DefaultRequestDirector( final Log log, final HttpRequestExecutor requestExec, final ClientConnectionManager conman, final ConnectionReuseStrategy reustrat, final ConnectionKeepAliveStrategy kastrat, final HttpRoutePlanner rouplan, final HttpProcessor httpProcessor, final HttpRequestRetryHandler retryHandler, final RedirectStrategy redirectStrategy, final AuthenticationHandler targetAuthHandler, final AuthenticationHandler proxyAuthHandler, final UserTokenHandler userTokenHandler, final HttpParams params) { this(LogFactory.getLog(DefaultRequestDirector.class), requestExec, conman, reustrat, kastrat, rouplan, httpProcessor, retryHandler, redirectStrategy, new AuthenticationStrategyAdaptor(targetAuthHandler), new AuthenticationStrategyAdaptor(proxyAuthHandler), userTokenHandler, params); }
/** * Produces an instance of {@link ClientExecChain} to be used as a main exec. * <p> * Default implementation produces an instance of {@link MainClientExec} * </p> * <p> * For internal use. * </p> * * @since 4.4 */ protected ClientExecChain createMainExec( final HttpRequestExecutor requestExec, final HttpClientConnectionManager connManager, final ConnectionReuseStrategy reuseStrategy, final ConnectionKeepAliveStrategy keepAliveStrategy, final HttpProcessor proxyHttpProcessor, final AuthenticationStrategy targetAuthStrategy, final AuthenticationStrategy proxyAuthStrategy, final UserTokenHandler userTokenHandler) { return new MainClientExec( requestExec, connManager, reuseStrategy, keepAliveStrategy, proxyHttpProcessor, targetAuthStrategy, proxyAuthStrategy, userTokenHandler); }
public RequestListenerThread(int port, final String docroot) throws IOException { this.serversocket = new ServerSocket(port); this.params = new SyncBasicHttpParams(); this.params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000).setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024).setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false).setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true).setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1"); // Set up the HTTP protocol processor HttpProcessor httpproc = new ImmutableHttpProcessor(new HttpResponseInterceptor[]{ new ResponseDate(), new ResponseServer(), new ResponseContent(), new ResponseConnControl() }); // Set up request handlers HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry(); reqistry.register("*", new HttpFileHandler()); // Set up the HTTP service this.httpService = new HttpService( httpproc, new DefaultConnectionReuseStrategy(), new DefaultHttpResponseFactory(), reqistry, this.params); }
public LocalTestServer(HttpRequestHandler handler) { try { setUp(); HttpProcessor httpproc = HttpProcessorBuilder.create() .add(new ResponseDate()) .add(new ResponseServer(LocalServerTestBase.ORIGIN)) .add(new ResponseContent()) .add(new ResponseConnControl()) .add(new RequestBasicAuth()) .add(new ResponseBasicUnauthorized()).build(); this.serverBootstrap.setHttpProcessor(httpproc); this.serverBootstrap.registerHandler("*", handler); host = start(); } catch (Exception e) { throw new RuntimeException(e); } }
private HttpProcessor getHttpProcessor() { if (null == _httpProcessor) { final HttpProcessorBuilder httpProcessorBuilder = HttpProcessorBuilder.create(); httpProcessorBuilder.add(new ResponseDate()); httpProcessorBuilder.add(new ResponseServer(getOriginServer())); httpProcessorBuilder.add(new ResponseContent()); httpProcessorBuilder.add(new ResponseConnControl()); httpProcessorBuilder.add(getRequestInterceptorService()); httpProcessorBuilder.add(getResponseInterceptorService()); _httpProcessor = httpProcessorBuilder.build(); } return _httpProcessor; }
public void start() throws Exception { // Create HTTP protocol basic processing chain HttpProcessor httpProcessor = HttpProcessorBuilder.create() .add(new ResponseDate()).add(new ResponseContent()) .add(new ResponseConnControl()).build(); // Create server HttpAsyncService protocolHandler = new HttpAsyncService(httpProcessor, uriMapper); NHttpConnectionFactory<DefaultNHttpServerConnection> connFactory = new DefaultNHttpServerConnectionFactory(); IOEventDispatch ioEventDispatch = new DefaultHttpServerIODispatch( protocolHandler, connFactory); IOReactorConfig config = IOReactorConfig.custom() .setIoThreadCount(threads).setSoReuseAddress(true).build(); ListeningIOReactor ioReactor = new DefaultListeningIOReactor(config); // Start server ioReactor.listen(new InetSocketAddress(port)); ioReactor.execute(ioEventDispatch); }
/** This method mainly exists to make the wrapper more testable. oh, apache's insanity. */ protected RequestDirector getRequestDirector(HttpRequestExecutor requestExec, ClientConnectionManager conman, ConnectionReuseStrategy reustrat, ConnectionKeepAliveStrategy kastrat, HttpRoutePlanner rouplan, HttpProcessor httpProcessor, HttpRequestRetryHandler retryHandler, RedirectHandler redirectHandler, AuthenticationHandler targetAuthHandler, AuthenticationHandler proxyAuthHandler, UserTokenHandler stateHandler, HttpParams params ) { return new DefaultRequestDirector(requestExec, conman, reustrat, kastrat, rouplan, httpProcessor, retryHandler, redirectHandler, targetAuthHandler, proxyAuthHandler, stateHandler, params); }
public AxisHttpRequestImpl( final AxisHttpConnection conn, final HttpRequest request, final HttpProcessor httpproc, final HttpContext context) { super(); if (conn == null) { throw new IllegalArgumentException("HTTP connection may not be null"); } if (request == null) { throw new IllegalArgumentException("HTTP request may not be null"); } if (httpproc == null) { throw new IllegalArgumentException("HTTP processor may not be null"); } if (context == null) { throw new IllegalArgumentException("HTTP context may not be null"); } this.request = request; this.conn = conn; this.httpproc = httpproc; this.context = context; }
public AxisHttpResponseImpl( final AxisHttpConnection conn, final HttpResponse response, final HttpProcessor httpproc, final HttpContext context) { super(); if (response == null) { throw new IllegalArgumentException("HTTP response may not be null"); } if (conn == null) { throw new IllegalArgumentException("HTTP connection may not be null"); } if (httpproc == null) { throw new IllegalArgumentException("HTTP processor may not be null"); } if (context == null) { throw new IllegalArgumentException("HTTP context may not be null"); } this.response = response; this.conn = conn; this.httpproc = httpproc; this.context = context; }
public static void main(String[] args) throws Exception { int port = 8080; String docRoot = "D:\\svn_file\\TEST2\\150503\\web-customer"; // Set up the HTTP protocol processor HttpProcessor httpproc = HttpProcessorBuilder.create().add(new ResponseDate()) .add(new ResponseServer("Haogrgr/1.1")).add(new ResponseContent()) .add(new ResponseConnControl()).build(); // Set up request handlers UriHttpRequestHandlerMapper reqistry = new UriHttpRequestHandlerMapper(); reqistry.register("*", new HttpFileHandler(docRoot)); // Set up the HTTP service HttpService httpService = new HttpService(httpproc, reqistry); Thread t = new RequestListenerThread(port, httpService, null); t.setDaemon(false); t.start(); }
/** * Default constructor which specifies the <code>port</code> to listen to * for requests and the <code>handlers</code>, which specify how to handle * the request. * * @param port * the port to listen to * @param handlers * the handlers, which specify how to handle the different * requests * * @throws IOException * if some IO operation fails */ public RequestListenerThread(final int port, final Map<String, IHandler> handlers) throws IOException { super(port); // Set up the HTTP protocol processor final HttpProcessor httpproc = new ImmutableHttpProcessor( new HttpResponseInterceptor[] { new ResponseDate(), new ResponseServer(), new ResponseContent(), new ResponseConnControl() }); // Set up request handlers UriHttpRequestHandlerMapper registry = new UriHttpRequestHandlerMapper(); for (final Entry<String, IHandler> entry : handlers.entrySet()) { registry.register(entry.getKey(), entry.getValue()); } // Set up the HTTP service httpService = new HttpService(httpproc, registry); connFactory = DefaultBHttpServerConnectionFactory.INSTANCE; }
public RequestListenerThread(int port, final String docroot) throws IOException { this.serversocket = new ServerSocket(port); this.params = new BasicHttpParams(); this.params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 1000).setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024) .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false).setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true) .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1"); // Set up the HTTP protocol processor HttpProcessor httpproc = new BasicHttpProcessor(); // Set up request handlers HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry(); reqistry.register("*", new HttpFileHandler(docroot)); // Set up the HTTP service this.httpService = new HttpService(httpproc, new NoConnectionReuseStrategy(), new DefaultHttpResponseFactory()); this.httpService.setParams(this.params); this.httpService.setHandlerResolver(reqistry); }
/** * @deprecated (4.1) do not use */ @Deprecated protected RequestDirector createClientRequestDirector( final HttpRequestExecutor requestExec, final ClientConnectionManager conman, final ConnectionReuseStrategy reustrat, final ConnectionKeepAliveStrategy kastrat, final HttpRoutePlanner rouplan, final HttpProcessor httpProcessor, final HttpRequestRetryHandler retryHandler, final RedirectHandler redirectHandler, final AuthenticationHandler targetAuthHandler, final AuthenticationHandler proxyAuthHandler, final UserTokenHandler userTokenHandler, final HttpParams params) { return new DefaultRequestDirector( requestExec, conman, reustrat, kastrat, rouplan, httpProcessor, retryHandler, redirectHandler, targetAuthHandler, proxyAuthHandler, userTokenHandler, params); }
/** * @deprecated (4.2) do not use */ @Deprecated protected RequestDirector createClientRequestDirector( final HttpRequestExecutor requestExec, final ClientConnectionManager conman, final ConnectionReuseStrategy reustrat, final ConnectionKeepAliveStrategy kastrat, final HttpRoutePlanner rouplan, final HttpProcessor httpProcessor, final HttpRequestRetryHandler retryHandler, final RedirectStrategy redirectStrategy, final AuthenticationHandler targetAuthHandler, final AuthenticationHandler proxyAuthHandler, final UserTokenHandler userTokenHandler, final HttpParams params) { return new DefaultRequestDirector( log, requestExec, conman, reustrat, kastrat, rouplan, httpProcessor, retryHandler, redirectStrategy, targetAuthHandler, proxyAuthHandler, userTokenHandler, params); }
/** * @since 4.2 */ protected RequestDirector createClientRequestDirector( final HttpRequestExecutor requestExec, final ClientConnectionManager conman, final ConnectionReuseStrategy reustrat, final ConnectionKeepAliveStrategy kastrat, final HttpRoutePlanner rouplan, final HttpProcessor httpProcessor, final HttpRequestRetryHandler retryHandler, final RedirectStrategy redirectStrategy, final AuthenticationStrategy targetAuthStrategy, final AuthenticationStrategy proxyAuthStrategy, final UserTokenHandler userTokenHandler, final HttpParams params) { return new DefaultRequestDirector( log, requestExec, conman, reustrat, kastrat, rouplan, httpProcessor, retryHandler, redirectStrategy, targetAuthStrategy, proxyAuthStrategy, userTokenHandler, params); }
public YaaccHttpService(HttpProcessor proc, ConnectionReuseStrategy connStrategy, HttpResponseFactory responseFactory, Context context) { super(proc, connStrategy, responseFactory); this.context = context; }
@Test public void test() throws ExecutionException, InterruptedException { HttpHost target = new HttpHost("localhost"); BasicConnPool connpool = new BasicConnPool(); connpool.setMaxTotal(200); connpool.setDefaultMaxPerRoute(10); connpool.setMaxPerRoute(target, 20); Future<BasicPoolEntry> future = connpool.lease(target, null); BasicPoolEntry poolEntry = future.get(); HttpClientConnection conn = poolEntry.getConnection(); HttpProcessor httpproc = HttpProcessorBuilder.create() .add(new ResponseDate()) .add(new ResponseServer("MyServer-HTTP/1.1")) .add(new ResponseContent()) .add(new ResponseConnControl()) .build(); HttpRequestHandler myRequestHandler = new HttpRequestHandler() { public void handle( HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException { response.setStatusCode(HttpStatus.SC_OK); response.setEntity( new StringEntity("some important message", ContentType.TEXT_PLAIN)); } }; UriHttpRequestHandlerMapper handlerMapper = new UriHttpRequestHandlerMapper(); handlerMapper.register("/service/*", myRequestHandler); HttpService httpService = new HttpService(httpproc, handlerMapper); }
public RequestListenerThread(int port, final String docroot) throws IOException { this.serversocket = new ServerSocket(port); this.params = new SyncBasicHttpParams(); this.params .setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000) .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024) .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false) .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true) .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1"); // Set up the HTTP protocol processor HttpProcessor httpproc = new ImmutableHttpProcessor(new HttpResponseInterceptor[] { new ResponseDate(), new ResponseServer(), new ResponseContent(), new ResponseConnControl() }); // Set up request handlers HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry(); reqistry.register("*", new HttpFileHandler(docroot)); // Set up the HTTP service this.httpService = new HttpService( httpproc, new DefaultConnectionReuseStrategy(), new DefaultHttpResponseFactory(), reqistry, this.params); }
public ProxyHandler( final HttpHost target, final HttpProcessor httpproc, final HttpRequestExecutor httpexecutor) { super(); this.target = target; this.httpproc = httpproc; this.httpexecutor = httpexecutor; this.connStrategy = new DefaultConnectionReuseStrategy(); }
public ListeningHandler( final HttpHost targetHost, final ConnectingIOReactor connectingIOReactor, final HttpProcessor httpProcessor, final HttpResponseFactory responseFactory, final ConnectionReuseStrategy connStrategy, final HttpParams params) { super(); this.targetHost = targetHost; this.connectingIOReactor = connectingIOReactor; this.httpProcessor = httpProcessor; this.connStrategy = connStrategy; this.responseFactory = responseFactory; this.params = params; }
public ConnectingHandler( final HttpProcessor httpProcessor, final ConnectionReuseStrategy connStrategy, final HttpParams params) { super(); this.httpProcessor = httpProcessor; this.connStrategy = connStrategy; this.params = params; }
public ProxyHandler( final HttpHost target, final HttpProcessor httpproc, final HttpRequestExecutor httpexecutor) { super(); this.target = target; this.httpproc = httpproc; this.httpexecutor = httpexecutor; this.connStrategy = DefaultConnectionReuseStrategy.INSTANCE; }
public RequestListenerThread(final int port, final HttpHost target) throws IOException { this.target = target; this.serversocket = new ServerSocket(port); // Set up HTTP protocol processor for incoming connections final HttpProcessor inhttpproc = new ImmutableHttpProcessor( new HttpRequestInterceptor[] { new RequestContent(), new RequestTargetHost(), new RequestConnControl(), new RequestUserAgent("Test/1.1"), new RequestExpectContinue(true) }); // Set up HTTP protocol processor for outgoing connections final HttpProcessor outhttpproc = new ImmutableHttpProcessor( new HttpResponseInterceptor[] { new ResponseDate(), new ResponseServer("Test/1.1"), new ResponseContent(), new ResponseConnControl() }); // Set up outgoing request executor final HttpRequestExecutor httpexecutor = new HttpRequestExecutor(); // Set up incoming request handler final UriHttpRequestHandlerMapper reqistry = new UriHttpRequestHandlerMapper(); reqistry.register("*", new ProxyHandler( this.target, outhttpproc, httpexecutor)); // Set up the HTTP service this.httpService = new HttpService(inhttpproc, reqistry); }
public RequestListenerThread(final int port, final HttpHost target, final TransportHandler handler) throws IOException { this.target = target; this.serversocket = new ServerSocket(port); // Set up HTTP protocol processor for incoming connections final HttpProcessor inhttpproc = new ImmutableHttpProcessor( new HttpRequestInterceptor[] { new RequestContent(), new RequestTargetHost(), new RequestConnControl(), new RequestUserAgent("Test/1.1"), new RequestExpectContinue(true) }); // Set up HTTP protocol processor for outgoing connections final HttpProcessor outhttpproc = new ImmutableHttpProcessor( new HttpResponseInterceptor[] { new ResponseDate(), new ResponseServer("Test/1.1"), new ResponseContent(), new ResponseConnControl() }); // Set up outgoing request executor final HttpRequestExecutor httpexecutor = new HttpRequestExecutor(); // Set up incoming request handler final UriHttpRequestHandlerMapper reqistry = new UriHttpRequestHandlerMapper(); reqistry.register("*", new ProxyHandler( this.target, outhttpproc, httpexecutor, handler)); // Set up the HTTP service this.httpService = new HttpService(inhttpproc, reqistry); }
public ProxyHandler( final HttpHost target, final HttpProcessor httpproc, final HttpRequestExecutor httpexecutor, final TransportHandler handler) { super(); this.target = target; this.httpproc = httpproc; this.httpexecutor = httpexecutor; this.connStrategy = DefaultConnectionReuseStrategy.INSTANCE; this.handler = handler; }
public HttpCoreTransportClientImpl(HttpRequestExecutor httpexecutor, HttpProcessor httpproc, ConnectionReuseStrategy connStrategy, final HttpClientConnection conn, final HttpRequest request, final HttpResponse response, final HttpContext context) { this.httpexecutor = httpexecutor; this.httpproc = httpproc; this.connStrategy = connStrategy; this.conn = conn; this.request = request; this.response = response; this.context = context; }
@Override public TransportFetch httpGetOtherFile(String uri) { HttpProcessor httpproc = HttpProcessorBuilder.create() .add(new RequestContent()) .add(new RequestTargetHost()) .add(new RequestConnControl()) .add(new RequestUserAgent("Test/1.1")) .add(new RequestExpectContinue(true)).build(); try { HttpRequest ascRequest = new BasicHttpRequest("GET", uri); LOG.info("Will fetch {}", ascRequest.getRequestLine()); httpexecutor.preProcess(ascRequest, httpproc, context); final HttpResponse otherResponse = httpexecutor.execute(ascRequest, conn, context); httpexecutor.postProcess(response, httpproc, context); final byte[] otherBody = EntityUtils.toByteArray(otherResponse.getEntity()); LOG.info("Read body of {} bytes", otherBody.length, " bytes"); EntityUtils.consume(otherResponse.getEntity()); boolean keepalive = connStrategy.keepAlive(response, context); context.setAttribute(HTTP_CONN_KEEPALIVE, new Boolean(keepalive)); return new TransportFetch(otherResponse.getStatusLine().getStatusCode(), otherResponse.getStatusLine().getReasonPhrase(), otherBody); } catch (HttpException | IOException ex) { return new TransportFetch(500, ex.getLocalizedMessage(), null); } }
/** * Obtains an HTTP protocol processor with default interceptors. * * @return a protocol processor for server-side use */ protected HttpProcessor newProcessor() { return new ImmutableHttpProcessor(new HttpResponseInterceptor[] {new ResponseDate(), new ResponseServer(), new ResponseContent(), new ResponseConnControl()}); }
@Override protected HttpProcessor getBasicHttpProcessor() { List<HttpRequestInterceptor> requestInterceptors = new ArrayList<HttpRequestInterceptor>(); requestInterceptors.add(new RequestDecompressingInterceptor()); List<HttpResponseInterceptor> responseInterceptors = new ArrayList<HttpResponseInterceptor>(); responseInterceptors.add(new ResponseCompressingInterceptor()); responseInterceptors.add(new ResponseBasicUnauthorized()); ImmutableHttpProcessor httpproc = new ImmutableHttpProcessor(requestInterceptors, responseInterceptors); return httpproc; }
@Override protected HttpProcessor getBasicHttpProcessor() { List<HttpRequestInterceptor> requestInterceptors = new ArrayList<HttpRequestInterceptor>(); requestInterceptors.add(new RequestBasicAuth()); List<HttpResponseInterceptor> responseInterceptors = new ArrayList<HttpResponseInterceptor>(); responseInterceptors.add(new ResponseContent()); responseInterceptors.add(new ResponseBasicUnauthorized()); ImmutableHttpProcessor httpproc = new ImmutableHttpProcessor(requestInterceptors, responseInterceptors); return httpproc; }
@Override protected HttpProcessor getBasicHttpProcessor() { List<HttpRequestInterceptor> requestInterceptors = new ArrayList<HttpRequestInterceptor>(); requestInterceptors.add(new RequestProxyBasicAuth()); List<HttpResponseInterceptor> responseInterceptors = new ArrayList<HttpResponseInterceptor>(); responseInterceptors.add(new ResponseContent()); responseInterceptors.add(new ResponseProxyBasicUnauthorized()); ImmutableHttpProcessor httpproc = new ImmutableHttpProcessor(requestInterceptors, responseInterceptors); return httpproc; }