List of usage examples for org.apache.http.protocol ResponseContent ResponseContent
public ResponseContent()
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;/*ww w . jav a 2 s . c om*/ listener.submit(new HttpListener()); }
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:com.yanzhenjie.andserver.CoreThread.java
/** * Create HttpProcessor./*from w ww .j a va 2 s . c o m*/ * * @return {@link HttpProcessor}. */ private HttpProcessor createHttpProcessor() { BasicHttpProcessor httpProcessor = new BasicHttpProcessor(); httpProcessor.addInterceptor(new ResponseContent()); httpProcessor.addInterceptor(new ResponseConnControl()); httpProcessor.addInterceptor(new ResponseDate()); httpProcessor.addInterceptor(new ResponseServer()); httpProcessor.addInterceptor(new ResponseProcessCookies()); return httpProcessor; }
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 w w . jav a 2s. 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"); }
From source file:com.zotoh.maedr.device.apache.HttpIO.java
protected void onStart() throws Exception { // mostly copied from apache http tutotial... HttpParams params = new BasicHttpParams(); params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, (int) getSocetTimeoutMills()) .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024) // 8k? .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false) .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true) .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "Apache-HttpCore/4.x"); BasicHttpProcessor httpproc = new BasicHttpProcessor(); httpproc.addInterceptor(new ResponseDate()); httpproc.addInterceptor(new ResponseServer()); httpproc.addInterceptor(new ResponseContent()); httpproc.addInterceptor(new ResponseConnControl()); ConnectionReuseStrategy strategy = new DefaultConnectionReuseStrategy(); HttpResponseFactory rspFac = new DefaultHttpResponseFactory(); NHttpServiceHandler svc;// w w w.jav a2 s . com EventListener evt = new EventLogger(getId(), tlog()); if (isAsync()) { AsyncNHttpServiceHandler handler = new AsyncNHttpServiceHandler(httpproc, rspFac, strategy, params); NHttpRequestHandlerRegistry r = new NHttpRequestHandlerRegistry(); r.register("*", new HttpNRequestCB(this)); handler.setHandlerResolver(r); handler.setEventListener(evt); svc = handler; } else { StreamedHttpServiceHandler handler = new StreamedHttpServiceHandler(httpproc, rspFac, strategy, params); HttpRequestHandlerRegistry r = new HttpRequestHandlerRegistry(); r.register("*", new HttpRequestCB(this)); handler.setHandlerResolver(r); handler.setEventListener(evt); svc = handler; } IOEventDispatch disp = isSSL() ? onSSL(svc, params) : onBasic(svc, params); ListeningIOReactor ioReactor; ioReactor = new DefaultListeningIOReactor(getWorkers(), params); ioReactor.listen(new InetSocketAddress(NetUte.getNetAddr(getHost()), getPort())); _curIO = ioReactor; // start... runServer(disp, ioReactor); }
From source file:org.fourthline.cling.transport.impl.apache.HttpServerConnectionUpnpStream.java
protected HttpServerConnectionUpnpStream(ProtocolFactory protocolFactory, HttpServerConnection connection, final HttpParams params) { super(protocolFactory); this.connection = connection; this.params = params; // The Date header is recommended in UDA, need to document the requirement in StreamServer interface? httpProcessor.addInterceptor(new ResponseDate()); // The Server header is only required for Control so callers have to add it to UPnPMessage // httpProcessor.addInterceptor(new ResponseServer()); httpProcessor.addInterceptor(new ResponseContent()); httpProcessor.addInterceptor(new ResponseConnControl()); httpService = new UpnpHttpService(httpProcessor, new DefaultConnectionReuseStrategy(), new DefaultHttpResponseFactory()); httpService.setParams(params);/*from ww w . j a v a 2s.c om*/ }
From source file:com.android.unit_tests.TestHttpServer.java
public TestHttpServer() throws IOException { super();/*from w ww.j av a 2 s . c om*/ this.params = new BasicHttpParams(); this.params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 20000) .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024) .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false) .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true) .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "TEST-SERVER/1.1"); this.httpproc = new BasicHttpProcessor(); this.httpproc.addInterceptor(new ResponseDate()); this.httpproc.addInterceptor(new ResponseServer()); this.httpproc.addInterceptor(new ResponseContent()); this.httpproc.addInterceptor(new ResponseConnControl()); this.connStrategy = new DefaultConnectionReuseStrategy(); this.responseFactory = new DefaultHttpResponseFactory(); this.reqistry = new HttpRequestHandlerRegistry(); this.serversocket = new ServerSocket(0); }
From source file:us.pserver.revok.channel.HttpResponseChannel.java
/** * Init some objects for http communication. *//*from w ww . j av a2 s . co m*/ private void init() { context = HttpCoreContext.create(); processor = HttpProcessorBuilder.create().add(new ResponseServer(HttpConsts.HD_VAL_SERVER)) .add(new ResponseDate()).add(new ResponseContent()).add(new ResponseConnControl()).build(); }
From source file:org.devtcg.five.server.AbstractHttpServer.java
public void run() { if (mReqHandler == null) throw new IllegalStateException("Request handler not set."); while (Thread.interrupted() == false) { try {//from w ww. ja v a 2s . c o m Socket sock = getSocket().accept(); DefaultHttpServerConnection conn = new DefaultHttpServerConnection(); conn.bind(sock, mParams); BasicHttpProcessor proc = new BasicHttpProcessor(); proc.addInterceptor(new ResponseContent()); proc.addInterceptor(new ResponseConnControl()); HttpRequestHandlerRegistry reg = new HttpRequestHandlerRegistry(); reg.register("*", mReqHandler); HttpService svc = new HttpService(proc, new DefaultConnectionReuseStrategy(), new DefaultHttpResponseFactory()); svc.setParams(mParams); svc.setHandlerResolver(reg); WorkerThread t; synchronized (mWorkers) { t = new WorkerThread(svc, conn); mWorkers.add(t); } t.start(); } catch (IOException e) { if (!hasCanceled()) { if (LOG.isErrorEnabled()) LOG.error("I/O error initializing connection thread", e); } break; } } }
From source file:org.devtcg.five.util.streaming.LocalHttpServer.java
public void run() { if (mReqHandler == null) throw new IllegalStateException("Request handler not set."); if (mSocket == null) throw new IllegalStateException("Not bound."); Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); while (Thread.interrupted() == false) { try {/*from w w w . j a va2s.c o m*/ Socket sock = mSocket.accept(); DefaultHttpServerConnection conn = new DefaultHttpServerConnection(); conn.bind(sock, mParams); BasicHttpProcessor proc = new BasicHttpProcessor(); proc.addInterceptor(new ResponseContent()); proc.addInterceptor(new ResponseConnControl()); HttpRequestHandlerRegistry reg = new HttpRequestHandlerRegistry(); reg.register("*", mReqHandler); HttpService svc = new HttpService(proc, new DefaultConnectionReuseStrategy(), new DefaultHttpResponseFactory()); svc.setParams(mParams); svc.setHandlerResolver(reg); WorkerThread t; synchronized (mWorkers) { t = new WorkerThread(svc, conn); mWorkers.add(t); } t.setDaemon(true); t.start(); } catch (IOException e) { Log.e(TAG, "I/O error initializing connection thread: " + e.getMessage()); break; } } }