Java 类org.apache.http.protocol.ResponseContent 实例源码

项目:sbc-qsystem    文件:QSystemHtmlInstance.java   
private QSystemHtmlInstance() {
    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, "QSystemReportHttpServer/1.1");

    // Set up the HTTP protocol processor
    final BasicHttpProcessor httpproc = new BasicHttpProcessor();
    httpproc.addInterceptor(new ResponseDate());
    httpproc.addInterceptor(new ResponseServer());
    httpproc.addInterceptor(new ResponseContent());
    httpproc.addInterceptor(new ResponseConnControl());

    // Set up request handlers
    final HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry();
    reqistry.register("*", new HttpQSystemReportsHandler());

    // Set up the HTTP service
    this.httpService = new HttpService(
        httpproc,
        new DefaultConnectionReuseStrategy(),
        new DefaultHttpResponseFactory(), reqistry, this.params);
}
项目:yaacc-code    文件:YaaccUpnpServerService.java   
public RequestListenerThread(Context context) throws IOException, BindException {
    serversocket = new ServerSocket(PORT);
    params = new BasicHttpParams();
    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
    BasicHttpProcessor httpProcessor = new BasicHttpProcessor();
    httpProcessor.addInterceptor(new ResponseDate());
    httpProcessor.addInterceptor(new ResponseServer());
    httpProcessor.addInterceptor(new ResponseContent());
    httpProcessor.addInterceptor(new ResponseConnControl());

    // Set up the HTTP service
    this.httpService = new YaaccHttpService(httpProcessor, new DefaultConnectionReuseStrategy(), new DefaultHttpResponseFactory(), context);

}
项目:dsworkbench    文件:ReportServer.java   
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);
}
项目:gondola    文件:LocalTestServer.java   
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);
    }
}
项目:DroidDLNA    文件: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);
}
项目:dlna-for-android    文件:HttpServer.java   
public ListenerThread(InetAddress address, int port, HttpParams params,
        HttpRequestHandlerRegistry handlerRegistry) throws IOException {
    this.params = params;
    this.serverSocket = new ServerSocket(port, 0, address);

    BasicHttpProcessor httpproc = new BasicHttpProcessor();
    httpproc.addInterceptor(new ResponseDate());
    httpproc.addInterceptor(new ResponseServer());
    httpproc.addInterceptor(new ResponseContent());
    httpproc.addInterceptor(new ResponseConnControl());

    this.httpService = new HttpService(httpproc,
            new DefaultConnectionReuseStrategy(),
            new DefaultHttpResponseFactory());
    this.httpService.setParams(params);
    this.httpService.setHandlerResolver(handlerRegistry);
}
项目:Cherry    文件:WebEngine.java   
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;
}
项目:nio-benchmark    文件:AsyncServer.java   
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);
}
项目:haogrgr-test    文件:HttpSrvMain.java   
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();
}
项目:gen-server-http-listener    文件:RequestListenerThread.java   
/**
 * 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;
}
项目:outcomes    文件:TestHttpCore.java   
@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);
}
项目:PhET    文件:ElementalHttpServer.java   
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);
}
项目:cosmic    文件:ApiServer.java   
public ListenerThread(final ApiServer requestHandler, final int port) {
    try {
        _serverSocket = new ServerSocket(port);
    } catch (final IOException ioex) {
        s_logger.error("error initializing api server", ioex);
        return;
    }

    _params = new BasicHttpParams();
    _params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 30000)
           .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
    final BasicHttpProcessor httpproc = new BasicHttpProcessor();
    httpproc.addInterceptor(new ResponseDate());
    httpproc.addInterceptor(new ResponseServer());
    httpproc.addInterceptor(new ResponseContent());
    httpproc.addInterceptor(new ResponseConnControl());

    // Set up request handlers
    final HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry();
    reqistry.register("*", requestHandler);

    // Set up the HTTP service
    _httpService = new HttpService(httpproc, new NoConnectionReuseStrategy(), new DefaultHttpResponseFactory());
    _httpService.setParams(_params);
    _httpService.setHandlerResolver(reqistry);
}
项目:cosmic    文件:ClusterServiceServletContainer.java   
public ListenerThread(final HttpRequestHandler requestHandler, final int port) {
    _executor = Executors.newCachedThreadPool(new NamedThreadFactory("Cluster-Listener"));

    try {
        _serverSocket = new ServerSocket(port);
    } catch (final IOException ioex) {
        s_logger.error("error initializing cluster service servlet container", ioex);
        return;
    }

    _params = new BasicHttpParams();
    _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
    final BasicHttpProcessor httpproc = new BasicHttpProcessor();
    httpproc.addInterceptor(new ResponseDate());
    httpproc.addInterceptor(new ResponseServer());
    httpproc.addInterceptor(new ResponseContent());
    httpproc.addInterceptor(new ResponseConnControl());

    // Set up request handlers
    final HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry();
    reqistry.register("/clusterservice", requestHandler);

    // Set up the HTTP service
    _httpService = new HttpService(httpproc, new DefaultConnectionReuseStrategy(), new DefaultHttpResponseFactory());
    _httpService.setParams(_params);
    _httpService.setHandlerResolver(reqistry);
}
项目:java-binrepo-proxy    文件:ElementalReverseProxy.java   
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);
}
项目:java-binrepo-proxy    文件:HttpCoreTransportServer.java   
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);
}
项目:Camel    文件:HttpTestServer.java   
/**
 * 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()});
}
项目:Camel    文件:HttpAuthenticationTest.java   
@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;
}
项目:Camel    文件:HttpProxyServerTest.java   
@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;
}
项目:Camel    文件:HttpsAuthenticationTest.java   
@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;
}
项目:purecloud-iot    文件:TestClientAuthentication.java   
@Before @Override
public void setUp() throws Exception {
    super.setUp();
    final 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);
}
项目:purecloud-iot    文件:TestClientAuthentication.java   
@Test
public void testBasicAuthenticationSuccessOnNonRepeatablePutExpectContinue() throws Exception {
    final 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)
        .setExpectationVerifier(new AuthExpectationVerifier())
        .registerHandler("*", new AuthHandler());

    final HttpHost target = start();

    final RequestConfig config = RequestConfig.custom()
            .setExpectContinueEnabled(true)
            .build();
    final HttpPut httpput = new HttpPut("/");
    httpput.setConfig(config);
    httpput.setEntity(new InputStreamEntity(
            new ByteArrayInputStream(
                    new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 } ),
                    -1));
    final HttpClientContext context = HttpClientContext.create();
    final TestCredentialsProvider credsProvider = new TestCredentialsProvider(
            new UsernamePasswordCredentials("test", "test"));
    context.setCredentialsProvider(credsProvider);

    final HttpResponse response = this.httpclient.execute(target, httpput, context);
    final HttpEntity entity = response.getEntity();
    Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
    Assert.assertNotNull(entity);
}
项目:purecloud-iot    文件:TestClientReauthentication.java   
@Before @Override
public void setUp() throws Exception {
    super.setUp();
    final 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);
}
项目:purecloud-iot    文件:TestClientAuthenticationFallBack.java   
@Before @Override
public void setUp() throws Exception {
    super.setUp();
    final 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);
}
项目:openxds    文件:IheHttpFactory.java   
public HttpProcessor newHttpProcessor() {
    BasicHttpProcessor httpProcessor = new BasicHttpProcessor();
    httpProcessor.addInterceptor(new RequestSessionCookie());
    httpProcessor.addInterceptor(new ResponseDate());
    httpProcessor.addInterceptor(new ResponseServer());
    httpProcessor.addInterceptor(new ResponseContent());
    httpProcessor.addInterceptor(new ResponseConnControl());
    httpProcessor.addInterceptor(new ResponseSessionCookie());
    return httpProcessor;
}
项目:hssd    文件:RequestListenerThread.java   
public RequestListenerThread(int port, String docRoot)
        throws IOException {

    this.docRoot = docRoot;
    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);

    this.serversocket.setSoTimeout(3000);
}
项目:Blackhole    文件:WebServer.java   
public WebServer(Context context){
    super(SERVER_NAME);

    this.setContext(context);

    serverPort = WebServer.DEFAULT_SERVER_PORT;
    httpproc = new BasicHttpProcessor();
    httpContext = new BasicHttpContext();

       httpproc.addInterceptor(new ResponseDate());
       httpproc.addInterceptor(new ResponseServer());
       httpproc.addInterceptor(new ResponseContent());
       httpproc.addInterceptor(new ResponseConnControl());

       httpService = new HttpService(httpproc, 
                                        new DefaultConnectionReuseStrategy(),
                                        new DefaultHttpResponseFactory());


       registry = new HttpRequestHandlerRegistry();

       registry.register(ALL_PATTERN, new AssetHandler(context));
       registry.register(HOME_PATTERN, new ListingHandler(context));
       registry.register(NONE_PATTERN, new ListingHandler(context));
       registry.register(DIR_PATTERN, new ListingHandler(context));
       registry.register(FILE_PATTERN, new FileHandler(context));
       registry.register(GETAPK_PATTERN, new GetApkHandler(context));
       registry.register(UPLOAD_PATTERN, new UploadHandler(context));
       registry.register(DOWNLOAD_ALL_PATTERN, new DownloadAllHandler(context));

       httpService.setHandlerResolver(registry);
}
项目:oap    文件:NioServer.java   
@SneakyThrows
public NioServer( int port, int workers ) {
    this.port = port;
    this.mapper.register( "/static/*", new NioClasspathResourceHandler( "/static", "/WEB-INF" ) );

    val ioReactorConfig = IOReactorConfig.custom().setIoThreadCount( workers ).build();
    val httpProcessor = HttpProcessorBuilder.create()
        .add( new ResponseDate() )
        .add( new ResponseServer( "OAP Server/1.0" ) )
        .add( new ResponseContent() )
        .add( new ResponseConnControl() )
        .build();

    SSLContext sslContext = getSslContext( port );


    server = ServerBootstrap.bootstrap()
        .setListenerPort( port )
        .setServerInfo( "OAP Server/1.0" )
        .setConnectionReuseStrategy( DefaultClientConnectionReuseStrategy.INSTANCE )
        .setHttpProcessor( httpProcessor )
        .setIOReactorConfig( ioReactorConfig )
        .setSslContext( sslContext )
        .setExceptionLogger( ex -> log.debug( ex.getMessage(), ex ) )
        .setHandlerMapper( mapper )
        .create();
}
项目:OpsDev    文件:ElementalHttpServer.java   
public static void startServer(int port) {

        // 设置端口号  后期需要对端口号进行判断是否已经被占用,并把端口号信息写进模板中
        isRun = true;


        // Set up the HTTP protocol processor
        HttpProcessor httpproc = HttpProcessorBuilder.create()
                .add(new ResponseDate())
                .add(new ResponseServer("Test/1.1"))
                .add(new ResponseContent())
                .add(new ResponseConnControl()).build();

        // Set up request handlers
        UriHttpRequestHandlerMapper reqistry = new UriHttpRequestHandlerMapper();
        reqistry.register("*", new HttpFileHandler(null));

        // Set up the HTTP service
        httpService = new HttpService(httpproc, reqistry);

        SSLServerSocketFactory sf = null;

        try {
            t = new RequestListenerThread(port, httpService, sf);
        } catch (IOException e) {
            e.printStackTrace();
        }
        t.setDaemon(true);
        t.start();

    }
项目:wso2-axis2    文件:HttpFactory.java   
public HttpProcessor newHttpProcessor() {
    BasicHttpProcessor httpProcessor = new BasicHttpProcessor();
    httpProcessor.addInterceptor(new RequestSessionCookie());
    httpProcessor.addInterceptor(new ResponseDate());
    httpProcessor.addInterceptor(new ResponseServer());
    httpProcessor.addInterceptor(new ResponseContent());
    httpProcessor.addInterceptor(new ResponseConnControl());
    httpProcessor.addInterceptor(new ResponseSessionCookie());
    return httpProcessor;
}
项目:cloudstack    文件:ApiServer.java   
public ListenerThread(final ApiServer requestHandler, final int port) {
    try {
        _serverSocket = new ServerSocket(port);
    } catch (final IOException ioex) {
        s_logger.error("error initializing api server", ioex);
        return;
    }

    _params = new BasicHttpParams();
    _params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 30000)
    .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
    final BasicHttpProcessor httpproc = new BasicHttpProcessor();
    httpproc.addInterceptor(new ResponseDate());
    httpproc.addInterceptor(new ResponseServer());
    httpproc.addInterceptor(new ResponseContent());
    httpproc.addInterceptor(new ResponseConnControl());

    // Set up request handlers
    final HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry();
    reqistry.register("*", requestHandler);

    // Set up the HTTP service
    _httpService = new HttpService(httpproc, new NoConnectionReuseStrategy(), new DefaultHttpResponseFactory());
    _httpService.setParams(_params);
    _httpService.setHandlerResolver(reqistry);
}
项目:cloudstack    文件:ClusterServiceServletContainer.java   
public ListenerThread(HttpRequestHandler requestHandler, int port) {
    _executor = Executors.newCachedThreadPool(new NamedThreadFactory("Cluster-Listener"));

    try {
        _serverSocket = new ServerSocket(port);
    } catch (IOException ioex) {
        s_logger.error("error initializing cluster service servlet container", ioex);
        return;
    }

    _params = new BasicHttpParams();
    _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
    BasicHttpProcessor httpproc = new BasicHttpProcessor();
    httpproc.addInterceptor(new ResponseDate());
    httpproc.addInterceptor(new ResponseServer());
    httpproc.addInterceptor(new ResponseContent());
    httpproc.addInterceptor(new ResponseConnControl());

    // Set up request handlers
    HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry();
    reqistry.register("/clusterservice", requestHandler);

    // Set up the HTTP service
    _httpService = new HttpService(httpproc, new DefaultConnectionReuseStrategy(), new DefaultHttpResponseFactory());
    _httpService.setParams(_params);
    _httpService.setHandlerResolver(reqistry);
}
项目:opentravelmate    文件:HttpServer.java   
/**
 * Create a server socket on an available port and process the requests.
 */
public void start() throws IOException {
    // Prepare the HTTP server
    this.serverSocket = new ServerSocket(0);

    HttpParams httpParams = new BasicHttpParams()
        .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");

    BasicHttpProcessor httpProcessor = new BasicHttpProcessor();
    httpProcessor.addInterceptor(new ResponseDate());
    httpProcessor.addInterceptor(new ResponseServer());
    httpProcessor.addInterceptor(new ResponseContent());
    httpProcessor.addInterceptor(new ResponseConnControl());

    HttpRequestHandlerRegistry registry = new HttpRequestHandlerRegistry();
    for (Map.Entry<String, HttpRequestHandler> entry : requestHandlerByPattern.entrySet()) {
        registry.register(entry.getKey(), entry.getValue());
    }

    HttpService httpService = new HttpService(httpProcessor, new DefaultConnectionReuseStrategy(), new DefaultHttpResponseFactory());
    httpService.setParams(httpParams);
    httpService.setHandlerResolver(registry);

    // Handle incoming connections
    executorService.execute(new RequestListener(this.serverSocket, httpParams, httpService, executorService, exceptionListener));
    }
项目:tunebot    文件:WebServer.java   
public RequestListenerThread(int port) 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);
}
项目:PhET    文件:ElementalReverseProxy.java   
public RequestListenerThread(int port, final HttpHost target) throws IOException {
    this.target = target;
    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 HTTP protocol processor for incoming connections
    HttpProcessor inhttpproc = new ImmutableHttpProcessor(
            new HttpRequestInterceptor[] {
                    new RequestContent(),
                    new RequestTargetHost(),
                    new RequestConnControl(),
                    new RequestUserAgent(),
                    new RequestExpectContinue()
     });

    // Set up HTTP protocol processor for outgoing connections
    HttpProcessor outhttpproc = new ImmutableHttpProcessor(
            new HttpResponseInterceptor[] {
                    new ResponseDate(),
                    new ResponseServer(),
                    new ResponseContent(),
                    new ResponseConnControl()
    });

    // Set up outgoing request executor 
    HttpRequestExecutor httpexecutor = new HttpRequestExecutor();

    // Set up incoming request handler
    HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry();
    reqistry.register("*", new ProxyHandler(
            this.target, 
            outhttpproc, 
            httpexecutor));

    // Set up the HTTP service
    this.httpService = new HttpService(
            inhttpproc, 
            new DefaultConnectionReuseStrategy(), 
            new DefaultHttpResponseFactory(),
            reqistry,
            this.params);
}
项目:PhET    文件:NHttpFileServer.java   
public static void main(String[] args) throws Exception {
    if (args.length < 1) {
        System.err.println("Please specify document root directory");
        System.exit(1);
    }

    boolean useFileChannels = true;
    if (args.length >= 2) {
        String s = args[1];
        if (s.equalsIgnoreCase("disableFileChannels")) {
            useFileChannels = false;
        }
    }

    HttpParams params = new SyncBasicHttpParams();
    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, "HttpComponents/1.1");

    HttpProcessor httpproc = new ImmutableHttpProcessor(new HttpResponseInterceptor[] {
            new ResponseDate(),
            new ResponseServer(),
            new ResponseContent(),
            new ResponseConnControl()
    });

    AsyncNHttpServiceHandler handler = new AsyncNHttpServiceHandler(
            httpproc,
            new DefaultHttpResponseFactory(),
            new DefaultConnectionReuseStrategy(),
            params);

    final HttpFileHandler filehandler = new HttpFileHandler(args[0], useFileChannels);

    NHttpRequestHandlerResolver resolver = new NHttpRequestHandlerResolver() {

        public NHttpRequestHandler lookup(String requestURI) {
            return filehandler;
        }

    };

    handler.setHandlerResolver(resolver);

    // Provide an event logger
    handler.setEventListener(new EventLogger());

    IOEventDispatch ioEventDispatch = new DefaultServerIOEventDispatch(handler, params);
    ListeningIOReactor ioReactor = new DefaultListeningIOReactor(2, params);
    try {
        ioReactor.listen(new InetSocketAddress(8080));
        ioReactor.execute(ioEventDispatch);
    } catch (InterruptedIOException ex) {
        System.err.println("Interrupted");
    } catch (IOException e) {
        System.err.println("I/O error: " + e.getMessage());
    }
    System.out.println("Shutdown");
}
项目:PhET    文件:NHttpServer.java   
public static void main(String[] args) throws Exception {
    if (args.length < 1) {
        System.err.println("Please specify document root directory");
        System.exit(1);
    }
    HttpParams params = new SyncBasicHttpParams();
    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");

    HttpProcessor httpproc = new ImmutableHttpProcessor(new HttpResponseInterceptor[] {
            new ResponseDate(),
            new ResponseServer(),
            new ResponseContent(),
            new ResponseConnControl()
    });

    BufferingHttpServiceHandler handler = new BufferingHttpServiceHandler(
            httpproc,
            new DefaultHttpResponseFactory(),
            new DefaultConnectionReuseStrategy(),
            params);

    // Set up request handlers
    HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry();
    reqistry.register("*", new HttpFileHandler(args[0]));

    handler.setHandlerResolver(reqistry);

    // Provide an event logger
    handler.setEventListener(new EventLogger());

    IOEventDispatch ioEventDispatch = new DefaultServerIOEventDispatch(handler, params);
    ListeningIOReactor ioReactor = new DefaultListeningIOReactor(2, params);
    try {
        ioReactor.listen(new InetSocketAddress(8080));
        ioReactor.execute(ioEventDispatch);
    } catch (InterruptedIOException ex) {
        System.err.println("Interrupted");
    } catch (IOException e) {
        System.err.println("I/O error: " + e.getMessage());
    }
    System.out.println("Shutdown");
}
项目:PhET    文件:NHttpSSLServer.java   
public static void main(String[] args) throws Exception {
    if (args.length < 1) {
        System.err.println("Please specify document root directory");
        System.exit(1);
    }

    ClassLoader cl = NHttpSSLServer.class.getClassLoader();
    URL url = cl.getResource("test.keystore");
    KeyStore keystore  = KeyStore.getInstance("jks");
    keystore.load(url.openStream(), "nopassword".toCharArray());
    KeyManagerFactory kmfactory = KeyManagerFactory.getInstance(
            KeyManagerFactory.getDefaultAlgorithm());
    kmfactory.init(keystore, "nopassword".toCharArray());
    KeyManager[] keymanagers = kmfactory.getKeyManagers(); 
    SSLContext sslcontext = SSLContext.getInstance("TLS");
    sslcontext.init(keymanagers, null, null);

    HttpParams params = new SyncBasicHttpParams();
    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, "Jakarta-HttpComponents-NIO/1.1");

    HttpProcessor httpproc = new ImmutableHttpProcessor(new HttpResponseInterceptor[] {
            new ResponseDate(),
            new ResponseServer(),
            new ResponseContent(),
            new ResponseConnControl()
    });

    BufferingHttpServiceHandler handler = new BufferingHttpServiceHandler(
            httpproc,
            new DefaultHttpResponseFactory(),
            new DefaultConnectionReuseStrategy(),
            params);

    // Set up request handlers
    HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry();
    reqistry.register("*", new HttpFileHandler(args[0]));

    handler.setHandlerResolver(reqistry);

    // Provide an event logger
    handler.setEventListener(new EventLogger());

    IOEventDispatch ioEventDispatch = new SSLServerIOEventDispatch(
            handler, 
            sslcontext,
            params);

    ListeningIOReactor ioReactor = new DefaultListeningIOReactor(2, params);
    try {
        ioReactor.listen(new InetSocketAddress(8080));
        ioReactor.execute(ioEventDispatch);
    } catch (InterruptedIOException ex) {
        System.err.println("Interrupted");
    } catch (IOException e) {
        System.err.println("I/O error: " + e.getMessage());
    }
    System.out.println("Shutdown");
}
项目:purecloud-iot    文件:TestConnectionReuse.java   
@Test
public void testKeepAliveHeaderRespected() throws Exception {
    final HttpProcessor httpproc = HttpProcessorBuilder.create()
        .add(new ResponseDate())
            .add(new ResponseServer(LocalServerTestBase.ORIGIN))
        .add(new ResponseContent())
        .add(new ResponseConnControl())
        .add(new ResponseKeepAlive()).build();

    this.serverBootstrap.setHttpProcessor(httpproc)
            .registerHandler("/random/*", new RandomHandler());

    this.connManager.setMaxTotal(1);
    this.connManager.setDefaultMaxPerRoute(1);

    final HttpHost target = start();

    HttpResponse response = this.httpclient.execute(target, new HttpGet("/random/2000"));
    EntityUtils.consume(response.getEntity());

    Assert.assertEquals(1, this.connManager.getTotalStats().getAvailable());

    response = this.httpclient.execute(target, new HttpGet("/random/2000"));
    EntityUtils.consume(response.getEntity());

    Assert.assertEquals(1, this.connManager.getTotalStats().getAvailable());

    // Now sleep for 1.1 seconds and let the timeout do its work
    Thread.sleep(1100);
    response = this.httpclient.execute(target, new HttpGet("/random/2000"));
    EntityUtils.consume(response.getEntity());

    Assert.assertEquals(1, this.connManager.getTotalStats().getAvailable());

    // Do another request just under the 1 second limit & make
    // sure we reuse that connection.
    Thread.sleep(500);
    response = this.httpclient.execute(target, new HttpGet("/random/2000"));
    EntityUtils.consume(response.getEntity());

    Assert.assertEquals(1, this.connManager.getTotalStats().getAvailable());
}
项目:FMTech    文件:maj.java   
public final Uri a()
{
  this.a = new ServerSocket();
  this.a.bind(new InetSocketAddress(h, 0));
  long l = System.currentTimeMillis();
  double d1 = Math.random();
  String str1 = 45 + "/" + l + d1;
  String str2 = MimeTypeMap.getFileExtensionFromUrl(this.i.toString());
  if (!TextUtils.isEmpty(str2))
  {
    String str5 = String.valueOf(str1);
    str1 = 1 + String.valueOf(str5).length() + String.valueOf(str2).length() + str5 + "." + str2;
  }
  this.c = new BasicHttpParams().setBooleanParameter("http.connection.stalecheck", false).setBooleanParameter("http.tcp.nodelay", true).setIntParameter("http.socket.buffer-size", 8192);
  BasicHttpProcessor localBasicHttpProcessor = new BasicHttpProcessor();
  localBasicHttpProcessor.addInterceptor(new ResponseContent());
  localBasicHttpProcessor.addInterceptor(new ResponseConnControl());
  HttpRequestHandlerRegistry localHttpRequestHandlerRegistry = new HttpRequestHandlerRegistry();
  String str3;
  FutureTask localFutureTask;
  if (this.i != null)
  {
    str3 = this.i.toString();
    localHttpRequestHandlerRegistry.register(str1, new man(str1, str3, this.j));
    this.d = new HttpService(localBasicHttpProcessor, new DefaultConnectionReuseStrategy(), new DefaultHttpResponseFactory());
    this.d.setHandlerResolver(localHttpRequestHandlerRegistry);
    this.d.setParams(this.c);
    localFutureTask = new FutureTask(new mak(this));
    if (this.e != null) {
      break label426;
    }
    this.b = Executors.newSingleThreadExecutor();
    this.b.execute(localFutureTask);
  }
  for (;;)
  {
    String str4 = String.valueOf(h.getHostAddress());
    int k = this.a.getLocalPort();
    return Uri.parse(19 + String.valueOf(str4).length() + String.valueOf(str1).length() + "http://" + str4 + ":" + k + str1);
    str3 = null;
    break;
    label426:
    if (this.f != null) {
      this.f.cancel(true);
    }
    this.f = localFutureTask;
    this.e.execute(localFutureTask);
  }
}