List of usage examples for org.apache.http.impl DefaultHttpResponseFactory DefaultHttpResponseFactory
public DefaultHttpResponseFactory()
From source file:com.limegroup.gnutella.http.HttpTestServer.java
public void execute(EventListener listener) throws IOException { BasicHttpProcessor processor = new BasicHttpProcessor(); processor.addInterceptor(new ResponseDate()); processor.addInterceptor(new ResponseServer()); processor.addInterceptor(new ResponseContent()); processor.addInterceptor(new ResponseConnControl()); AsyncNHttpServiceHandler serviceHandler = new AsyncNHttpServiceHandler(processor, new DefaultHttpResponseFactory(), new DefaultConnectionReuseStrategy(), params); serviceHandler.setEventListener(listener); serviceHandler.setHandlerResolver(this.registry); reactor = new DefaultDispatchedIOReactor(params, NIODispatcher.instance().getScheduledExecutorService()); IOEventDispatch ioEventDispatch = new DefaultServerIOEventDispatch(serviceHandler, params); reactor.execute(ioEventDispatch);//from w ww . j a va 2s . c om }
From source file:org.siddhiesb.transport.passthru.config.SourceConfiguration.java
public SourceConfiguration(Scheme scheme, WorkerPool workerPool) { super(workerPool); this.scheme = scheme; httpProcessor = new ImmutableHttpProcessor(new HttpResponseInterceptor[] { new ResponseDate(), new ResponseServer(), new ResponseContent(), new ResponseConnControl() }); responseFactory = new DefaultHttpResponseFactory(); sourceConnections = new SourceConnections(); }
From source file:com.telefonica.iot.cygnus.backends.http.HttpBackendTest.java
/** * [HttpBackend.createJsonResponse] -------- A JsonResponse object is * created if the response content-type header is 'application/json' and the * response contains a location header./*from w ww . jav a2s . c o m*/ */ @Test public void testCreateJsonResponseEverythingOK() { System.out.println(getTestTraceHead("[HttpBackend.createJsonResponse]") + "-------- A JsonResponse object is created if the response content-type header is " + "'application/json' and the response contains a location header"); HttpResponseFactory factory = new DefaultHttpResponseFactory(); HttpResponse response = factory .newHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, null), null); String responseStr = "{\"somefield1\":\"somevalue1\",\"somefield2\":\"somevalue2\"," + "\"somefield3\":\"somevalue3\"}"; try { response.setEntity(new StringEntity(responseStr)); } catch (UnsupportedEncodingException e) { System.out.println(getTestTraceHead("[HttpBackend.createJsonResponse]") + "- FAIL - There was some problem when creating the HttpResponse object"); throw new AssertionError(e.getMessage()); } // try catch response.addHeader("Content-Type", "application/json"); response.addHeader("Location", "http://someurl.org"); HttpBackend httpBackend = new HttpBackendImpl(host, port, false, false, null, null, null, null, maxConns, maxConnsPerRoute); try { JsonResponse jsonRes = httpBackend.createJsonResponse(response); try { assertTrue(jsonRes.getJsonObject() != null); System.out.println(getTestTraceHead("[HttpBackend.createJsonResponse]") + "- OK - The JsonResponse object has a Json apyload"); } catch (AssertionError e) { System.out.println(getTestTraceHead("[HttpBackend.createJsonResponse]") + "- FAIL - The JsonResponse object has not a Json payload"); throw e; } // try catch try { assertTrue(jsonRes.getLocationHeader() != null); System.out.println(getTestTraceHead("[HttpBackend.createJsonResponse]") + "- OK - The JsonResponse object has a Location header"); } catch (AssertionError e) { System.out.println(getTestTraceHead("[HttpBackend.createJsonResponse]") + "- FAIL - The JsonResponse object has not a Location header"); throw e; } // try catch } catch (Exception e) { System.out.println(getTestTraceHead("[HttpBackend.createJsonResponse]") + "- FAIL - There was some problem when creating the JsonResponse object"); throw new AssertionError(e.getMessage()); } // try catch }
From source file:niproxy.NiProxy.java
/** * Setups a monitoring http proxy and starts a non blocking listening * service based on a {@link NiProxyConfig}. This is based on the Apache * Software Foundation's example code "Basic non-blocking HTTP server" that * can be found from http://hc.apache.org/httpcomponents-core-ga/examples.html. *//* ww w . java2 s .c o m*/ public NiProxy() { HttpParams params = new SyncBasicHttpParams(); params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, NiProxyConfig.getHttpConnectionTimeout()) .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024) .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false) .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true); HttpProcessor httpproc = new ImmutableHttpProcessor(new HttpResponseInterceptor[] { new ResponseDate(), new ResponseServer(), new ResponseContent(), new ResponseConnControl() }); AsyncNHttpServiceHandler handler = new AsyncNHttpServiceHandler(httpproc, new DefaultHttpResponseFactory(), new DefaultConnectionReuseStrategy(), params); // Set up request handlers NHttpRequestHandlerRegistry registry = new NHttpRequestHandlerRegistry(); registry.register("*", NiProxyMonitor.get()); handler.setHandlerResolver(registry); // Provide an event logger handler.setEventListener(new EventLogger()); IOEventDispatch ioEventDispatch = new DefaultServerIOEventDispatch(handler, params); try { logger.info("Setting up " + NiProxyConfig.getIOReactorWorkersCount() + " IOReactor workers"); ListeningIOReactor ioReactor = new DefaultListeningIOReactor(NiProxyConfig.getIOReactorWorkersCount(), params); String host = NiProxyConfig.getNiProxyHost(); int port = NiProxyConfig.getNiProxyPort(); logger.info("Listening for connections at " + host + ":" + port); ioReactor.listen(new InetSocketAddress(host, port)); logger.info("NiProxy set up done. Launching event dispatch..."); ioReactor.execute(ioEventDispatch); } catch (Exception e) { logger.error("I/O reactor was interrupted. Exception: " + e); e.printStackTrace(); } logger.info("NiProxy server shutdown."); }
From source file:org.apache.axis2.transport.http.server.DefaultConnectionListener.java
public void run() { try {/*from w w w . j a va 2s . com*/ while (!Thread.interrupted()) { try { if (serversocket == null || serversocket.isClosed()) { if (LOG.isInfoEnabled()) { LOG.info("Listening on port " + port); } serversocket = new ServerSocket(port); serversocket.setReuseAddress(true); } LOG.debug("Waiting for incoming HTTP connection"); Socket socket = this.serversocket.accept(); if (LOG.isDebugEnabled()) { LOG.debug("Incoming HTTP connection from " + socket.getRemoteSocketAddress()); } AxisHttpConnection conn = new AxisHttpConnectionImpl(socket, this.params); try { this.connmanager.process(conn); } catch (RejectedExecutionException e) { conn.sendResponse(new DefaultHttpResponseFactory().newHttpResponse(HttpVersion.HTTP_1_0, HttpStatus.SC_SERVICE_UNAVAILABLE, new BasicHttpContext(null))); } } catch (java.io.InterruptedIOException ie) { break; } catch (Throwable ex) { if (Thread.interrupted()) { break; } if (!failureHandler.failed(this, ex)) { break; } } } } finally { destroy(); } }
From source file:com.subgraph.vega.internal.http.proxy.HttpProxy.java
public HttpProxy(int listenPort, ProxyTransactionManipulator transactionManipulator, HttpInterceptor interceptor, IHttpRequestEngine requestEngine, SSLContextRepository sslContextRepository) { this.eventHandlers = new ArrayList<IHttpInterceptProxyEventHandler>(); this.transactionManipulator = transactionManipulator; this.interceptor = interceptor; this.listenPort = listenPort; this.params = new BasicHttpParams(); this.params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 0) .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024) // .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false) .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true); BasicHttpProcessor inProcessor = new BasicHttpProcessor(); inProcessor.addInterceptor(new ResponseConnControl()); inProcessor.addInterceptor(new ResponseContentCustom()); HttpRequestHandlerRegistry registry = new HttpRequestHandlerRegistry(); registry.register("*", new ProxyRequestHandler(this, logger, requestEngine)); httpService = new VegaHttpService(inProcessor, new DefaultConnectionReuseStrategy(), new DefaultHttpResponseFactory(), registry, params, sslContextRepository); connectionList = new ArrayList<ConnectionTask>(); }
From source file:org.apache.synapse.transport.passthru.config.SourceConfiguration.java
public SourceConfiguration(ConfigurationContext configurationContext, TransportInDescription description, Scheme scheme, WorkerPool pool, PassThroughTransportMetricsCollector metrics) { super(configurationContext, description, pool, metrics); this.inDescription = description; this.scheme = scheme; httpProcessor = new ImmutableHttpProcessor(new HttpResponseInterceptor[] { new ResponseDate(), new ResponseServer(), new ResponseContent(), new ResponseConnControl() }); responseFactory = new DefaultHttpResponseFactory(); sourceConnections = new SourceConnections(); }
From source file:net.oneandone.sushi.fs.webdav.WebdavConnection.java
public WebdavConnection(Socket socket, SessionInputBuffer input, SessionOutputBuffer output, HttpParams params) {/*from www . j a va2 s. c o m*/ this.socket = socket; this.entityserializer = new EntitySerializer(new StrictContentLengthStrategy()); this.entitydeserializer = new EntityDeserializer(new LaxContentLengthStrategy()); this.input = input; this.output = output; this.responseParser = new DefaultHttpResponseParser(input, null, new DefaultHttpResponseFactory(), params); this.requestWriter = new HttpRequestWriter(output, null, params); this.metrics = new HttpConnectionMetricsImpl(input.getMetrics(), output.getMetrics()); this.open = true; }
From source file:org.wso2.carbon.automation.extensions.servers.httpserver.SimpleHttpServer.java
public void start() throws IOException { serverSocket = new ServerSocket(port); params = new BasicHttpParams(); params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, getParameter(CoreConnectionPNames.SO_TIMEOUT, 60000)) .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, getParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)) .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, getParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, 0) == 1) .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, getParameter(CoreConnectionPNames.TCP_NODELAY, 1) == 1) .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "WSO2ESB-Test-Server"); // Configure HTTP protocol processor BasicHttpProcessor httpProcessor = new BasicHttpProcessor(); httpProcessor.addInterceptor(new ResponseDate()); httpProcessor.addInterceptor(new ResponseServer()); httpProcessor.addInterceptor(new ResponseContent()); httpProcessor.addInterceptor(new ResponseConnControl()); HttpRequestHandlerRegistry registry = new HttpRequestHandlerRegistry(); registry.register("*", requestHandler); // Set up the HTTP service httpService = new HttpService(httpProcessor, new DefaultConnectionReuseStrategy(), new DefaultHttpResponseFactory(), registry, params); listener = Executors.newSingleThreadExecutor(); workerPool = Executors.newFixedThreadPool(getParameter("ThreadCount", 2)); shutdown = false;/*from www .j a v a2 s . c om*/ listener.submit(new HttpListener()); }
From source file:marytts.tools.perceptiontest.PerceptionTestHttpServer.java
public void run() { logger.info("Starting server."); System.out.println("Starting server...."); //int localPort = MaryProperties.needInteger("socket.port"); int localPort = serverPort; HttpParams params = new BasicHttpParams(); params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 0) // 0 means no timeout, any positive value means time out in miliseconds (i.e. 50000 for 50 seconds) .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"); BasicHttpProcessor httpproc = new BasicHttpProcessor(); httpproc.addInterceptor(new ResponseDate()); httpproc.addInterceptor(new ResponseServer()); httpproc.addInterceptor(new ResponseContent()); httpproc.addInterceptor(new ResponseConnControl()); BufferingHttpServiceHandler handler = new BufferingHttpServiceHandler(httpproc, new DefaultHttpResponseFactory(), new DefaultConnectionReuseStrategy(), params); // Set up request handlers HttpRequestHandlerRegistry registry = new HttpRequestHandlerRegistry(); //registry.register("/perceptionTest", new FileDataRequestHandler("perception.html")); //registry.register("/process", new FileDataRequestHandler("perception.html")); //registry.register("/perceptionTest", new UtterancePlayRequestHandler()); DataRequestHandler infoRH = new DataRequestHandler(this.testXmlName); UserRatingStorer userRatingRH = new UserRatingStorer(this.userRatingsDirectory, infoRH); registry.register("/options", infoRH); registry.register("/queryStatement", infoRH); registry.register("/process", new UtterancePlayRequestHandler(infoRH)); registry.register("/perceptionTest", new PerceptionRequestHandler(infoRH, userRatingRH)); registry.register("/userRating", new StoreRatingRequestHandler(infoRH, userRatingRH)); registry.register("*", new FileDataRequestHandler()); handler.setHandlerResolver(registry); // Provide an event logger handler.setEventListener(new EventLogger()); IOEventDispatch ioEventDispatch = new DefaultServerIOEventDispatch(handler, params); //int numParallelThreads = MaryProperties.getInteger("server.http.parallelthreads", 5); int numParallelThreads = 5; logger.info("Waiting for client to connect on port " + localPort); System.out.println("Waiting for client to connect on port " + localPort); try {/* w ww .jav a 2 s . c o m*/ ListeningIOReactor ioReactor = new DefaultListeningIOReactor(numParallelThreads, params); ioReactor.listen(new InetSocketAddress(localPort)); ioReactor.execute(ioEventDispatch); } catch (InterruptedIOException ex) { logger.info("Interrupted", ex); System.out.println("Interrupted" + ex.toString()); } catch (IOException e) { logger.info("Problem with HTTP connection ", e); System.out.println("Problem with HTTP connection " + e.toString()); } logger.debug("Shutdown"); System.out.println("Shutdown"); }