Java 类org.apache.http.impl.DefaultConnectionReuseStrategy 实例源码

项目:lams    文件:ProxyClient.java   
public ProxyClient(final HttpParams params) {
    super();
    if (params == null) {
        throw new IllegalArgumentException("HTTP parameters may not be null");
    }
    this.httpProcessor = new ImmutableHttpProcessor(new HttpRequestInterceptor[] {
            new RequestContent(),
            new RequestTargetHost(),
            new RequestClientConnControl(),
            new RequestUserAgent(),
            new RequestProxyAuthentication()
    } );
    this.requestExec = new HttpRequestExecutor();
    this.proxyAuthStrategy = new ProxyAuthenticationStrategy();
    this.authenticator = new HttpAuthenticator();
    this.proxyAuthState = new AuthState();
    this.authSchemeRegistry = new AuthSchemeRegistry();
    this.authSchemeRegistry.register(AuthPolicy.BASIC, new BasicSchemeFactory());
    this.authSchemeRegistry.register(AuthPolicy.DIGEST, new DigestSchemeFactory());
    this.authSchemeRegistry.register(AuthPolicy.NTLM, new NTLMSchemeFactory());
    this.authSchemeRegistry.register(AuthPolicy.SPNEGO, new SPNegoSchemeFactory());
    this.authSchemeRegistry.register(AuthPolicy.KERBEROS, new KerberosSchemeFactory());
    this.reuseStrategy = new DefaultConnectionReuseStrategy();
    this.params = params;
}
项目:educational-plugin    文件:EduStepicClient.java   
@NotNull
static HttpClientBuilder getBuilder() {
  final HttpClientBuilder builder = HttpClients.custom().setSSLContext(CertificateManager.getInstance().getSslContext()).
    setMaxConnPerRoute(100000).setConnectionReuseStrategy(DefaultConnectionReuseStrategy.INSTANCE);

  final HttpConfigurable proxyConfigurable = HttpConfigurable.getInstance();
  final List<Proxy> proxies = proxyConfigurable.getOnlyBySettingsSelector().select(URI.create(EduStepicNames.STEPIC_URL));
  final InetSocketAddress address = proxies.size() > 0 ? (InetSocketAddress)proxies.get(0).address() : null;
  if (address != null) {
    builder.setProxy(new HttpHost(address.getHostName(), address.getPort()));
  }
  final ConfirmingTrustManager trustManager = CertificateManager.getInstance().getTrustManager();
  try {
    SSLContext sslContext = SSLContext.getInstance("TLS");
    sslContext.init(null, new TrustManager[]{trustManager}, new SecureRandom());
    builder.setSSLContext(sslContext);
  }
  catch (NoSuchAlgorithmException | KeyManagementException e) {
    LOG.error(e.getMessage());
  }
  return builder;
}
项目: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);

}
项目:jcurl    文件:HCNIOEngine.java   
private CloseableHttpAsyncClient createCloseableHttpAsyncClient() throws Exception {
        HttpAsyncClientBuilder builder = HttpAsyncClientBuilder.create();
        builder.useSystemProperties();
        builder.setSSLContext(SSLContext.getDefault());
        builder.setConnectionReuseStrategy(DefaultConnectionReuseStrategy.INSTANCE);
        builder.setMaxConnPerRoute(2);
        builder.setMaxConnTotal(2);
        builder.setDefaultRequestConfig(RequestConfig
            .custom()
            .setConnectionRequestTimeout(1000)
            .setConnectTimeout(2000)
            .setSocketTimeout(2000)
        .build()
        );
//        builder.setHttpProcessor()
        CloseableHttpAsyncClient hc = builder.build();
        hc.start();
        return hc;
    }
项目:purecloud-iot    文件:ProxyClient.java   
/**
 * @since 4.3
 */
public ProxyClient(
        final HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory,
        final ConnectionConfig connectionConfig,
        final RequestConfig requestConfig) {
    super();
    this.connFactory = connFactory != null ? connFactory : ManagedHttpClientConnectionFactory.INSTANCE;
    this.connectionConfig = connectionConfig != null ? connectionConfig : ConnectionConfig.DEFAULT;
    this.requestConfig = requestConfig != null ? requestConfig : RequestConfig.DEFAULT;
    this.httpProcessor = new ImmutableHttpProcessor(
            new RequestTargetHost(), new RequestClientConnControl(), new RequestUserAgent());
    this.requestExec = new HttpRequestExecutor();
    this.proxyAuthStrategy = new ProxyAuthenticationStrategy();
    this.authenticator = new HttpAuthenticator();
    this.proxyAuthState = new AuthState();
    this.authSchemeRegistry = new AuthSchemeRegistry();
    this.authSchemeRegistry.register(AuthSchemes.BASIC, new BasicSchemeFactory());
    this.authSchemeRegistry.register(AuthSchemes.DIGEST, new DigestSchemeFactory());
    this.authSchemeRegistry.register(AuthSchemes.NTLM, new NTLMSchemeFactory());
    this.authSchemeRegistry.register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory());
    this.authSchemeRegistry.register(AuthSchemes.KERBEROS, new KerberosSchemeFactory());
    this.reuseStrategy = new DefaultConnectionReuseStrategy();
}
项目: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);
}
项目: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);
}
项目:contrail-java-api    文件:ApiConnectorImpl.java   
private void initHttpClient() {
    _params = new SyncBasicHttpParams();
    HttpProtocolParams.setVersion(_params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(_params, "UTF-8");
    HttpProtocolParams.setUseExpectContinue(_params, false);
    HttpProtocolParams.setHttpElementCharset(_params, "UTF-8");

    _httpproc = new ImmutableHttpProcessor(new HttpRequestInterceptor[] {
            // Required protocol interceptors
            new BasicHttpProcessor(),
            new RequestConnControl(),
            new RequestContent(),
            new RequestDate(),
            new RequestTargetHost(),
            // Recommended protocol interceptors
            new RequestUserAgent(),
            new RequestExpectContinue()
    });
    _httpexecutor = new HttpRequestExecutor();
    _httpcontext = new BasicHttpContext(null);
    _connection = new DefaultHttpClientConnection();
    _connectionStrategy = new DefaultConnectionReuseStrategy();
}
项目:lams    文件:SystemDefaultHttpClient.java   
@Override
protected ConnectionReuseStrategy createConnectionReuseStrategy() {
    String s = System.getProperty("http.keepAlive");
    if ("true".equalsIgnoreCase(s)) {
        return new DefaultConnectionReuseStrategy();
    } else {
        return new NoConnectionReuseStrategy();
    }
}
项目:BUbiNG    文件:FetchingThread.java   
/** Creates a new fetching thread.
 *
 * @param frontier a reference to the {@link Frontier}.
 * @param index  the index of this thread (only for logging purposes).
 */
public FetchingThread(final Frontier frontier, final int index) throws NoSuchAlgorithmException, IllegalArgumentException, IOException {
    setName(this.getClass().getSimpleName() + '-' + index);
    setPriority(Thread.MIN_PRIORITY); // Low priority; there will be thousands of this guys around.
    this.frontier = frontier;

    final BasicHttpClientConnectionManager connManager = new BasicHttpClientConnectionManagerWithAlternateDNS(frontier.rc.dnsResolver);
    connManager.closeIdleConnections(0, TimeUnit.MILLISECONDS);
    connManager.setConnectionConfig(ConnectionConfig.custom().setBufferSize(8 * 1024).build()); // TODO: make this configurable

    cookieStore = new BasicCookieStore();

    BasicHeader[] headers = {
        new BasicHeader("From", frontier.rc.userAgentFrom),
        new BasicHeader("Accept","text/html,application/xhtml+xml,application/xml;q=0.95,text/*;q=0.9,*/*;q=0.8")
    };

    httpClient = HttpClients.custom()
            .setSSLContext(frontier.rc.acceptAllCertificates ? TRUST_ALL_CERTIFICATES_SSL_CONTEXT : TRUST_SELF_SIGNED_SSL_CONTEXT)
            .setConnectionManager(connManager)
            .setConnectionReuseStrategy(frontier.rc.keepAliveTime == 0 ? NoConnectionReuseStrategy.INSTANCE : DefaultConnectionReuseStrategy.INSTANCE)
            .setUserAgent(frontier.rc.userAgent)
            .setDefaultCookieStore(cookieStore)
            .setDefaultHeaders(ObjectArrayList.wrap(headers))
            .build();
        fetchData = new FetchData(frontier.rc);
}
项目: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);
}
项目:PhET    文件:ElementalReverseProxy.java   
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();
}
项目: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 ProxyHandler(
        final HttpHost target,
        final HttpProcessor httpproc,
        final HttpRequestExecutor httpexecutor) {
    super();
    this.target = target;
    this.httpproc = httpproc;
    this.httpexecutor = httpexecutor;
    this.connStrategy = DefaultConnectionReuseStrategy.INSTANCE;
}
项目:java-binrepo-proxy    文件:HttpCoreTransportServer.java   
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;
}
项目:Android_CCTV    文件:TinyHttpServer.java   
protected RequestListener() throws Exception {

            mHttpService = new org.apache.http.protocol.HttpService(
                    mHttpProcessor, 
                    new DefaultConnectionReuseStrategy(), 
                    new DefaultHttpResponseFactory());
            mHttpService.setHandlerResolver(mRegistry);
            mHttpService.setParams(mParams);

        }
项目:purecloud-iot    文件:SystemDefaultHttpClient.java   
@Override
protected ConnectionReuseStrategy createConnectionReuseStrategy() {
    final String s = System.getProperty("http.keepAlive", "true");
    if ("true".equalsIgnoreCase(s)) {
        return new DefaultConnectionReuseStrategy();
    } else {
        return new NoConnectionReuseStrategy();
    }
}
项目:purecloud-iot    文件:MinimalHttpClient.java   
public MinimalHttpClient(
        final HttpClientConnectionManager connManager) {
    super();
    this.connManager = Args.notNull(connManager, "HTTP connection manager");
    this.requestExecutor = new MinimalClientExec(
            new HttpRequestExecutor(),
            connManager,
            DefaultConnectionReuseStrategy.INSTANCE,
            DefaultConnectionKeepAliveStrategy.INSTANCE);
    this.params = new BasicHttpParams();
}
项目:esper    文件:EsperHttpServiceClassic.java   
public void start(EPServiceProviderSPI engine) throws IOException {
    this.serversocket = new ServerSocket(this.getServiceConfig().getPort());
    this.parameters = new BasicHttpParams();
    this.parameters
            .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 = setupRegistry(engine);

    // Set up the HTTP service
    this.httpService = new HttpService(
            httpproc,
            new DefaultConnectionReuseStrategy(),
            new DefaultHttpResponseFactory());
    this.httpService.setParams(this.parameters);
    this.httpService.setHandlerResolver(reqistry);

    runnable = new EsperHttpServiceClassicRunnable(this.getServiceName(), serversocket, parameters, httpService);
    socketThread = new Thread(runnable);
    socketThread.setDaemon(true);
    socketThread.start();
}
项目:esper    文件:SupportHTTPServer.java   
public void start() throws Exception {
    if (serversocket != null) {
        throw new RuntimeException("Server socket already initialized");
    }

    this.serversocket = new ServerSocket(port);
    this.parameters = new BasicHttpParams();
    this.parameters
            .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 registery = new HttpRequestHandlerRegistry();
    registery.register("*", new SupportHTTPServerReqestHandler());

    // Set up the HTTP service
    this.httpService = new HttpService(
            httpproc,
            new DefaultConnectionReuseStrategy(),
            new DefaultHttpResponseFactory());
    this.httpService.setParams(this.parameters);
    this.httpService.setHandlerResolver(registery);

    runnable = new EsperHttpServiceClassicRunnable("regressionTestService", serversocket, parameters, httpService);
    socketThread = new Thread(runnable);
    socketThread.setDaemon(true);
    socketThread.start();
}
项目:GemFire-WAN-REST-example    文件:HttpDispatcher.java   
public HttpDispatcher() {
    // change properly
    RequestConfig config = RequestConfig.custom()
            .setConnectTimeout(TIMEOUT)
            .setSocketTimeout(TIMEOUT)
            .build();

    this.httpClient = HttpClients.custom()
            .setRequestExecutor(new HttpRequestExecutor())
            .setConnectionReuseStrategy(DefaultConnectionReuseStrategy.INSTANCE)
            .setKeepAliveStrategy(DefaultConnectionKeepAliveStrategy.INSTANCE)
            .disableAutomaticRetries()
            .setDefaultRequestConfig(config)
            .build();
}
项目: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);
}
项目:carbon-platform-integration    文件: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;
    listener.submit(new HttpListener());
}
项目: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);
}
项目:spydroid-ipcamera    文件:TinyHttpServer.java   
protected RequestListener() throws Exception {

            mHttpService = new org.apache.http.protocol.HttpService(
                    mHttpProcessor, 
                    new DefaultConnectionReuseStrategy(), 
                    new DefaultHttpResponseFactory());
            mHttpService.setHandlerResolver(mRegistry);
            mHttpService.setParams(mParams);

        }
项目:jntlm    文件:UpgradedConnectionAwareReusingStrategy.java   
@Override
public boolean keepAlive(HttpResponse response, HttpContext context) {
    if (((UpgradableHttpContext) context).isConnectionUpgraded()) {
        return true;
    } else {
        return DefaultConnectionReuseStrategy.INSTANCE.keepAlive(response, context);
    }
}
项目:ecg_over_rtp    文件:TinyHttpServer.java   
protected RequestListener() throws Exception {

            mHttpService = new org.apache.http.protocol.HttpService(
                    mHttpProcessor, 
                    new DefaultConnectionReuseStrategy(), 
                    new DefaultHttpResponseFactory());
            mHttpService.setHandlerResolver(mRegistry);
            mHttpService.setParams(mParams);

        }
项目: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));
    }
项目:jsonrpc4j    文件:JsonRpcHttpAsyncClient.java   
private void initialize() {
    if (initialized.getAndSet(true)) {
        return;
    }
    IOReactorConfig.Builder config = createConfig();
    // params.setParameter(CoreProtocolPNames.USER_AGENT, "jsonrpc4j/1.0");
    final ConnectingIOReactor ioReactor = createIoReactor(config);
    createSslContext();
    int socketBufferSize = Integer.getInteger("com.googlecode.jsonrpc4j.async.socket.buffer", 8 * 1024);
    final ConnectionConfig connectionConfig = ConnectionConfig.custom().setBufferSize(socketBufferSize).build();
    BasicNIOConnFactory nioConnFactory = new BasicNIOConnFactory(sslContext, null, connectionConfig);
    pool = new BasicNIOConnPool(ioReactor, nioConnFactory, Integer.getInteger("com.googlecode.jsonrpc4j.async.connect.timeout", 30000));
    pool.setDefaultMaxPerRoute(Integer.getInteger("com.googlecode.jsonrpc4j.async.max.inflight.route", 500));
    pool.setMaxTotal(Integer.getInteger("com.googlecode.jsonrpc4j.async.max.inflight.total", 500));

    Thread t = new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                HttpAsyncRequestExecutor protocolHandler = new HttpAsyncRequestExecutor();
                IOEventDispatch ioEventDispatch = new DefaultHttpClientIODispatch(protocolHandler, sslContext, connectionConfig);
                ioReactor.execute(ioEventDispatch);
            } catch (InterruptedIOException ex) {
                System.err.println("Interrupted");
            } catch (IOException e) {
                System.err.println("I/O error: " + e.getMessage());
            }
        }
    }, "jsonrpc4j HTTP IOReactor");

    t.setDaemon(true);
    t.start();

    HttpProcessor httpProcessor = new ImmutableHttpProcessor(new RequestContent(), new RequestTargetHost(), new RequestConnControl(), new RequestUserAgent(), new RequestExpectContinue(false));
    requester = new HttpAsyncRequester(httpProcessor, new DefaultConnectionReuseStrategy());
}
项目:snowizard    文件:SnowizardClient.java   
/**
 * Get a new CloseableHttpClient
 * 
 * @return CloseableHttpClient
 */
public static CloseableHttpClient newHttpClient() {
    final SocketConfig socketConfig = SocketConfig.custom()
            .setSoKeepAlive(Boolean.TRUE).setTcpNoDelay(Boolean.TRUE)
            .setSoTimeout(SOCKET_TIMEOUT_MS).build();

    final PoolingHttpClientConnectionManager manager = new PoolingHttpClientConnectionManager();
    manager.setDefaultMaxPerRoute(MAX_HOSTS);
    manager.setMaxTotal(MAX_HOSTS);
    manager.setDefaultSocketConfig(socketConfig);

    final RequestConfig requestConfig = RequestConfig.custom()
            .setConnectTimeout(CONNECTION_TIMEOUT_MS)
            .setCookieSpec(CookieSpecs.IGNORE_COOKIES)
            .setStaleConnectionCheckEnabled(Boolean.FALSE)
            .setSocketTimeout(SOCKET_TIMEOUT_MS).build();

    final CloseableHttpClient client = HttpClients
            .custom()
            .disableRedirectHandling()
            .setConnectionManager(manager)
            .setDefaultRequestConfig(requestConfig)
            .setConnectionReuseStrategy(
                    new DefaultConnectionReuseStrategy())
            .setConnectionBackoffStrategy(new DefaultBackoffStrategy())
            .setRetryHandler(
                    new DefaultHttpRequestRetryHandler(MAX_RETRIES, false))
            .setKeepAliveStrategy(new DefaultConnectionKeepAliveStrategy())
            .build();
    return client;
}
项目: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);
}
项目:lams    文件:AbstractHttpClient.java   
protected ConnectionReuseStrategy createConnectionReuseStrategy() {
    return new DefaultConnectionReuseStrategy();
}
项目:PhET    文件:ElementalHttpGet.java   
public static void main(String[] args) throws Exception {

    HttpParams params = new SyncBasicHttpParams();
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, "UTF-8");
    HttpProtocolParams.setUserAgent(params, "HttpComponents/1.1");
    HttpProtocolParams.setUseExpectContinue(params, true);

    HttpProcessor httpproc = new ImmutableHttpProcessor(new HttpRequestInterceptor[] {
            // Required protocol interceptors
            new RequestContent(),
            new RequestTargetHost(),
            // Recommended protocol interceptors
            new RequestConnControl(),
            new RequestUserAgent(),
            new RequestExpectContinue()});

    HttpRequestExecutor httpexecutor = new HttpRequestExecutor();

    HttpContext context = new BasicHttpContext(null);
    HttpHost host = new HttpHost("localhost", 8080);

    DefaultHttpClientConnection conn = new DefaultHttpClientConnection();
    ConnectionReuseStrategy connStrategy = new DefaultConnectionReuseStrategy();

    context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
    context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, host);

    try {

        String[] targets = {
                "/",
                "/servlets-examples/servlet/RequestInfoExample", 
                "/somewhere%20in%20pampa"};

        for (int i = 0; i < targets.length; i++) {
            if (!conn.isOpen()) {
                Socket socket = new Socket(host.getHostName(), host.getPort());
                conn.bind(socket, params);
            }
            BasicHttpRequest request = new BasicHttpRequest("GET", targets[i]);
            System.out.println(">> Request URI: " + request.getRequestLine().getUri());

            request.setParams(params);
            httpexecutor.preProcess(request, httpproc, context);
            HttpResponse response = httpexecutor.execute(request, conn, context);
            response.setParams(params);
            httpexecutor.postProcess(response, httpproc, context);

            System.out.println("<< Response: " + response.getStatusLine());
            System.out.println(EntityUtils.toString(response.getEntity()));
            System.out.println("==============");
            if (!connStrategy.keepAlive(response, context)) {
                conn.close();
            } else {
                System.out.println("Connection kept alive...");
            }
        }
    } finally {
        conn.close();
    }
}
项目:PhET    文件:ElementalHttpPost.java   
public static void main(String[] args) throws Exception {

    HttpParams params = new SyncBasicHttpParams();
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, "UTF-8");
    HttpProtocolParams.setUserAgent(params, "HttpComponents/1.1");
    HttpProtocolParams.setUseExpectContinue(params, true);

    HttpProcessor httpproc = new ImmutableHttpProcessor(new HttpRequestInterceptor[] {
            // Required protocol interceptors
            new RequestContent(),
            new RequestTargetHost(),
            // Recommended protocol interceptors
            new RequestConnControl(),
            new RequestUserAgent(),
            new RequestExpectContinue()});

    HttpRequestExecutor httpexecutor = new HttpRequestExecutor();

    HttpContext context = new BasicHttpContext(null);

    HttpHost host = new HttpHost("localhost", 8080);

    DefaultHttpClientConnection conn = new DefaultHttpClientConnection();
    ConnectionReuseStrategy connStrategy = new DefaultConnectionReuseStrategy();

    context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
    context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, host);

    try {

        HttpEntity[] requestBodies = {
                new StringEntity(
                        "This is the first test request", "UTF-8"),
                new ByteArrayEntity(
                        "This is the second test request".getBytes("UTF-8")),
                new InputStreamEntity(
                        new ByteArrayInputStream(
                                "This is the third test request (will be chunked)"
                                .getBytes("UTF-8")), -1)
        };

        for (int i = 0; i < requestBodies.length; i++) {
            if (!conn.isOpen()) {
                Socket socket = new Socket(host.getHostName(), host.getPort());
                conn.bind(socket, params);
            }
            BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", 
                    "/servlets-examples/servlet/RequestInfoExample");
            request.setEntity(requestBodies[i]);
            System.out.println(">> Request URI: " + request.getRequestLine().getUri());

            request.setParams(params);
            httpexecutor.preProcess(request, httpproc, context);
            HttpResponse response = httpexecutor.execute(request, conn, context);
            response.setParams(params);
            httpexecutor.postProcess(response, httpproc, context);

            System.out.println("<< Response: " + response.getStatusLine());
            System.out.println(EntityUtils.toString(response.getEntity()));
            System.out.println("==============");
            if (!connStrategy.keepAlive(response, context)) {
                conn.close();
            } else {
                System.out.println("Connection kept alive...");
            }
        }
    } finally {
        conn.close();
    }        
}
项目: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    文件:NHttpClient.java   
public static void main(String[] args) throws Exception {
    HttpParams params = new SyncBasicHttpParams();
    params
        .setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000)
        .setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000)
        .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
        .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
        .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
        .setParameter(CoreProtocolPNames.USER_AGENT, "HttpComponents/1.1");

    final ConnectingIOReactor ioReactor = new DefaultConnectingIOReactor(2, params);

    HttpProcessor httpproc = new ImmutableHttpProcessor(new HttpRequestInterceptor[] {
            new RequestContent(),
            new RequestTargetHost(),
            new RequestConnControl(),
            new RequestUserAgent(),
            new RequestExpectContinue()});

    // We are going to use this object to synchronize between the 
    // I/O event and main threads
    CountDownLatch requestCount = new CountDownLatch(3);

    BufferingHttpClientHandler handler = new BufferingHttpClientHandler(
            httpproc,
            new MyHttpRequestExecutionHandler(requestCount),
            new DefaultConnectionReuseStrategy(),
            params);

    handler.setEventListener(new EventLogger());

    final IOEventDispatch ioEventDispatch = new DefaultClientIOEventDispatch(handler, params);

    Thread t = new Thread(new Runnable() {

        public void run() {
            try {
                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");
        }

    });
    t.start();

    SessionRequest[] reqs = new SessionRequest[3];
    reqs[0] = ioReactor.connect(
            new InetSocketAddress("www.yahoo.com", 80), 
            null, 
            new HttpHost("www.yahoo.com"),
            new MySessionRequestCallback(requestCount));
    reqs[1] = ioReactor.connect(
            new InetSocketAddress("www.google.com", 80), 
            null,
            new HttpHost("www.google.ch"),
            new MySessionRequestCallback(requestCount));
    reqs[2] = ioReactor.connect(
            new InetSocketAddress("www.apache.org", 80), 
            null,
            new HttpHost("www.apache.org"),
            new MySessionRequestCallback(requestCount));

    // Block until all connections signal
    // completion of the request execution
    requestCount.await();

    System.out.println("Shutting down I/O reactor");

    ioReactor.shutdown();

    System.out.println("Done");
}
项目: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");
}