Java 类org.apache.http.message.BasicHeaderElementIterator 实例源码

项目:lams    文件:DefaultConnectionKeepAliveStrategy.java   
public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
    if (response == null) {
        throw new IllegalArgumentException("HTTP response may not be null");
    }
    HeaderElementIterator it = new BasicHeaderElementIterator(
            response.headerIterator(HTTP.CONN_KEEP_ALIVE));
    while (it.hasNext()) {
        HeaderElement he = it.nextElement();
        String param = he.getName();
        String value = he.getValue();
        if (value != null && param.equalsIgnoreCase("timeout")) {
            try {
                return Long.parseLong(value) * 1000;
            } catch(NumberFormatException ignore) {
            }
        }
    }
    return -1;
}
项目:iotplatform    文件:WebhookMsgHandler.java   
@Override
public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
  HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
  while (it.hasNext()) {
    HeaderElement he = it.nextElement();
    String param = he.getName();
    String value = he.getValue();
    if (value != null && param.equalsIgnoreCase("timeout")) {
      long timeout = Long.parseLong(value) * 1000;
      if (timeout > 20 * 1000) {
        return 20 * 1000;
      } else {
        return timeout;
      }
    }
  }
  return 5 * 1000;
}
项目:stocator    文件:SwiftConnectionManager.java   
@Override
public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
  // Honor 'keep-alive' header
  HeaderElementIterator it = new BasicHeaderElementIterator(
      response.headerIterator(HTTP.CONN_KEEP_ALIVE));
  while (it.hasNext()) {
    HeaderElement he = it.nextElement();
    String param = he.getName();
    String value = he.getValue();
    if (value != null && param.equalsIgnoreCase("timeout")) {
      try {
        return Long.parseLong(value) * 1000;
      } catch (NumberFormatException ignore) {
        // Do nothing
      }
    }
  }
  // otherwise keep alive for 30 seconds
  return 30 * 1000;
}
项目:axon-eventstore    文件:DefaultConnectionKeepAliveStrategy.java   
@Override
public long getKeepAliveDuration(final HttpResponse response, final HttpContext context) {
   Args.notNull(response, "HTTP response");
   final HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
   while (it.hasNext()) {
      final HeaderElement he = it.nextElement();
      final String param = he.getName();
      final String value = he.getValue();
      if (value != null && param.equalsIgnoreCase("timeout")) {
         try {
            return Long.parseLong(value) * 1000;
         } catch (final NumberFormatException ignore) {
            LOGGER.warn("keep alive timeout could not be parsed: param=" + param + " value:" + value, ignore);
         }
      }
   }
   return DEFAULT_KEEP_ALIVE;
}
项目:remote-files-sync    文件:DefaultConnectionKeepAliveStrategyHC4.java   
public long getKeepAliveDuration(final HttpResponse response, final HttpContext context) {
    Args.notNull(response, "HTTP response");
    final HeaderElementIterator it = new BasicHeaderElementIterator(
            response.headerIterator(HTTP.CONN_KEEP_ALIVE));
    while (it.hasNext()) {
        final HeaderElement he = it.nextElement();
        final String param = he.getName();
        final String value = he.getValue();
        if (value != null && param.equalsIgnoreCase("timeout")) {
            try {
                return Long.parseLong(value) * 1000;
            } catch(final NumberFormatException ignore) {
            }
        }
    }
    return -1;
}
项目:http-fetcher    文件:SimpleHttpFetcher.java   
public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
    if (response == null) {
        throw new IllegalArgumentException("HTTP response may not be null");
    }
    HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
    while (it.hasNext()) {
        HeaderElement he = it.nextElement();
        String param = he.getName();
        String value = he.getValue();
        if (value != null && param.equalsIgnoreCase("timeout")) {
            try {
                return Long.parseLong(value) * 1000;
            } catch (NumberFormatException ignore) {
            }
        }
    }
    return DEFAULT_KEEP_ALIVE_DURATION;
}
项目:gluu    文件:UmaProtectionService.java   
@Override
public long getKeepAliveDuration(HttpResponse httpResponse, HttpContext httpContext) {

    HeaderElementIterator headerElementIterator = new BasicHeaderElementIterator(httpResponse.headerIterator(HTTP.CONN_KEEP_ALIVE));

    while (headerElementIterator.hasNext()) {

        HeaderElement headerElement = headerElementIterator.nextElement();

        String name = headerElement.getName();
        String value = headerElement.getValue();

        if (value != null && name.equalsIgnoreCase("timeout")) {
            return Long.parseLong(value) * 1000;
        }
    }

    // Set own keep alive duration if server does not have it
    return applicationConfiguration.getRptConnectionPoolCustomKeepAliveTimeout() * 1000;
}
项目:purecloud-iot    文件:DefaultConnectionKeepAliveStrategy.java   
@Override
public long getKeepAliveDuration(final HttpResponse response, final HttpContext context) {
    Args.notNull(response, "HTTP response");
    final HeaderElementIterator it = new BasicHeaderElementIterator(
            response.headerIterator(HTTP.CONN_KEEP_ALIVE));
    while (it.hasNext()) {
        final HeaderElement he = it.nextElement();
        final String param = he.getName();
        final String value = he.getValue();
        if (value != null && param.equalsIgnoreCase("timeout")) {
            try {
                return Long.parseLong(value) * 1000;
            } catch(final NumberFormatException ignore) {
            }
        }
    }
    return -1;
}
项目:Visit    文件:DefaultConnectionKeepAliveStrategyHC4.java   
public long getKeepAliveDuration(final HttpResponse response, final HttpContext context) {
    Args.notNull(response, "HTTP response");
    final HeaderElementIterator it = new BasicHeaderElementIterator(
            response.headerIterator(HTTP.CONN_KEEP_ALIVE));
    while (it.hasNext()) {
        final HeaderElement he = it.nextElement();
        final String param = he.getName();
        final String value = he.getValue();
        if (value != null && param.equalsIgnoreCase("timeout")) {
            try {
                return Long.parseLong(value) * 1000;
            } catch(final NumberFormatException ignore) {
            }
        }
    }
    return -1;
}
项目:galileo-agent-java    文件:AnalyticsConnKeepAliveStrategy.java   
@Override
public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
    HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
    while (it.hasNext()) {
        HeaderElement he = it.nextElement();
        String param = he.getName();
        String value = he.getValue();
        if (value != null && param.equalsIgnoreCase("timeout")) {
            try {
                return Long.parseLong(value) * 1000;
            } catch (NumberFormatException ignore) {
            }
        }
    }
    return keepAliveTime * 1000;
}
项目:ache    文件:SimpleHttpFetcher.java   
public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
    if (response == null) {
        throw new IllegalArgumentException("HTTP response may not be null");
    }
    HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
    while (it.hasNext()) {
        HeaderElement he = it.nextElement();
        String param = he.getName();
        String value = he.getValue();
        if (value != null && param.equalsIgnoreCase("timeout")) {
            try {
                return Long.parseLong(value) * 1000;
            } catch (NumberFormatException ignore) {
            }
        }
    }
    return DEFAULT_KEEP_ALIVE_DURATION;
}
项目:java-bandwidth    文件:BandwidthClient.java   
private ConnectionKeepAliveStrategy getStrategy() {
    return new ConnectionKeepAliveStrategy() {
        @Override
        public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
            HeaderElementIterator it = new BasicHeaderElementIterator
                    (response.headerIterator(HTTP.CONN_KEEP_ALIVE));
            while (it.hasNext()) {
                HeaderElement he = it.nextElement();
                String param = he.getName();
                String value = he.getValue();
                if (value != null && param.equalsIgnoreCase
                        ("timeout")) {
                    return Long.parseLong(value) * 1000;
                }
            }
            return 5 * 1000;
        }
    };
}
项目:oxTrust    文件:UmaPermissionService.java   
@Override
public long getKeepAliveDuration(HttpResponse httpResponse, HttpContext httpContext) {

    HeaderElementIterator headerElementIterator = new BasicHeaderElementIterator(httpResponse.headerIterator(HTTP.CONN_KEEP_ALIVE));

    while (headerElementIterator.hasNext()) {

        HeaderElement headerElement = headerElementIterator.nextElement();

        String name = headerElement.getName();
        String value = headerElement.getValue();

        if (value != null && name.equalsIgnoreCase("timeout")) {
            return Long.parseLong(value) * 1000;
        }
    }

    // Set own keep alive duration if server does not have it
    return appConfiguration.getRptConnectionPoolCustomKeepAliveTimeout() * 1000;
}
项目:data-prep    文件:HttpClient.java   
/**
 * @return The connection keep alive strategy.
 */
private ConnectionKeepAliveStrategy getKeepAliveStrategy() {

    return (response, context) -> {
        // Honor 'keep-alive' header
        HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
        while (it.hasNext()) {
            HeaderElement he = it.nextElement();
            String param = he.getName();
            String value = he.getValue();
            if (value != null && "timeout".equalsIgnoreCase(param)) {
                try {
                    return Long.parseLong(value) * 1000;
                } catch(NumberFormatException ignore) {
                    // let's move on the next header value
                    break;
                }
            }
        }
        // otherwise use the default value
        return defaultKeepAlive * 1000;
    };
}
项目:cJUnit-mc626    文件:DefaultConnectionKeepAliveStrategy.java   
public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
    if (response == null) {
        throw new IllegalArgumentException("HTTP response may not be null");
    }
    HeaderElementIterator it = new BasicHeaderElementIterator(
            response.headerIterator(HTTP.CONN_KEEP_ALIVE));
    while (it.hasNext()) {
        HeaderElement he = it.nextElement();
        String param = he.getName(); 
        String value = he.getValue();
        if (value != null && param.equalsIgnoreCase("timeout")) {
            try {
                return Long.parseLong(value) * 1000;
            } catch(NumberFormatException ignore) {
            }
        }
    }
    return -1;
}
项目:basis-java-api    文件:BasisDownload.java   
public void authenticate(String username, String password) throws 
        IOException {  

    HttpResponse response = Request.Post("https://app.mybasis.com/login")
        .bodyForm(Form.form().add("username",  username).add("password",  password).build())
        .execute().returnResponse();        

    /* find the access token */ 
    HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator("Set-Cookie"));                
    while (it.hasNext()) {
        HeaderElement elem = it.nextElement(); 
        if (elem.getName().equals("access_token")) { 
            accessToken = elem.getValue(); 
            return; 
        }
    }

    /* we didn't find an access token, we couldnt login. */ 
    throw new IOException("Unable to login");
}
项目:disconf    文件:HttpClientKeepAliveStrategy.java   
@Override
public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
    HeaderElementIterator it = new BasicHeaderElementIterator(
            response.headerIterator(HTTP.CONN_KEEP_ALIVE));
    while (it.hasNext()) {
        HeaderElement he = it.nextElement();
        String param = he.getName();
        String value = he.getValue();
        if (value != null && param.equalsIgnoreCase("timeout")) {
            try {
                return Long.parseLong(value) * 1000;
            } catch (NumberFormatException ignore) {
            }
        }
    }
    return keepAliveTimeOut * 1000;
}
项目:ZTLib    文件:DefaultConnectionKeepAliveStrategyHC4.java   
public long getKeepAliveDuration(final HttpResponse response, final HttpContext context) {
    Args.notNull(response, "HTTP response");
    final HeaderElementIterator it = new BasicHeaderElementIterator(
            response.headerIterator(HTTP.CONN_KEEP_ALIVE));
    while (it.hasNext()) {
        final HeaderElement he = it.nextElement();
        final String param = he.getName();
        final String value = he.getValue();
        if (value != null && param.equalsIgnoreCase("timeout")) {
            try {
                return Long.parseLong(value) * 1000;
            } catch(final NumberFormatException ignore) {
            }
        }
    }
    return -1;
}
项目:ReKognitionJavaSDK    文件:HttpManager.java   
private ConnectionKeepAliveStrategy getKeepAliveStrategy(final long defaultVal) {
    return new ConnectionKeepAliveStrategy() {
        @Override
        public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
            HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
            while (it.hasNext()) {
                HeaderElement he = it.nextElement();
                String param = he.getName();
                String value = he.getValue();
                if (value != null && param.equalsIgnoreCase("timeout")) {
                    return Long.parseLong(value) * 1000;
                }
            }
            return defaultVal;
        }
    };
}
项目:dropbox-java-sdk    文件:AbstractSession.java   
@Override
public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
    // Keep-alive for the shorter of 20 seconds or what the server specifies.
    long timeout = KEEP_ALIVE_DURATION_SECS * 1000;

    HeaderElementIterator i = new BasicHeaderElementIterator(
            response.headerIterator(HTTP.CONN_KEEP_ALIVE));
    while (i.hasNext()) {
        HeaderElement element = i.nextElement();
        String name = element.getName();
        String value = element.getValue();
        if (value != null && name.equalsIgnoreCase("timeout")) {
            try {
                timeout = Math.min(timeout, Long.parseLong(value) * 1000);
            } catch (NumberFormatException e) {}
        }
    }

    return timeout;
}
项目:framework    文件:HttpClientUtil.java   
public HttpClient getHttpClient() {
    if (httpClient == null) {
        synchronized (this) {
            if (httpClient == null) {
                if (pool == null) { //初始化pool
                    try {
                        afterPropertiesSet();
                    } catch (Exception e) {
                        logger.error(e.getMessage(), e);
                    }
                }

                HttpClientBuilder httpClientBuilder = HttpClients.custom();
                httpClientBuilder.setConnectionManager(pool);
                httpClientBuilder.setDefaultRequestConfig(RequestConfig.custom().setConnectTimeout(conntimeout).setSocketTimeout(sotimeout).build());
                httpClientBuilder.setKeepAliveStrategy(new ConnectionKeepAliveStrategy() {
                    public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
                        HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
                        while (it.hasNext()) {
                            HeaderElement he = it.nextElement();
                            String param = he.getName();
                            String value = he.getValue();
                            if (value != null && param.equalsIgnoreCase("timeout")) {
                                try {
                                    return Long.parseLong(value) * 1000;
                                } catch (NumberFormatException ignore) {
                                }
                            }
                        }
                        // 否则保持活动5秒
                        return 5 * 1000;
                    }
                });
                httpClient = httpClientBuilder.build();
            }
        }
    }
    return httpClient;
}
项目:xproject    文件:HttpClientUtils.java   
public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
    HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
    while (it.hasNext()) {
        HeaderElement he = it.nextElement();
        String param = he.getName();
        String value = he.getValue();
        if (value != null && param.equalsIgnoreCase("timeout")) {
            try {
                return Long.parseLong(value) * 1000;
            } catch(NumberFormatException ignore) {
            }
        }
    }
    return 30 * 1000; //默认30秒
}
项目:codePay    文件:SafeHttpClient.java   
@SuppressWarnings("deprecation")
public SafeHttpClient() {

    HttpParams httpParams = new BasicHttpParams();
    httpParams.setParameter(ClientPNames.CONNECTION_MANAGER_FACTORY_CLASS_NAME, factoryClassName);
    // 设置最大连接数
    ConnManagerParams.setMaxTotalConnections(httpParams, maxTotalConnections);
    // 设置获取连接的最大等待时间
    ConnManagerParams.setTimeout(httpParams, waitTimeout);
    // 设置每个路由最大连接数
    ConnPerRouteBean connPerRoute = new ConnPerRouteBean(maxRouteConnections);
    ConnManagerParams.setMaxConnectionsPerRoute(httpParams, connPerRoute);
    // 设置连接超时时间
    HttpConnectionParams.setConnectionTimeout(httpParams, connectTimeout);
    // 设置读取超时时间
    HttpConnectionParams.setSoTimeout(httpParams, readTimeout);
    HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1);
    this.setParams(httpParams);
    this.setKeepAliveStrategy(new ConnectionKeepAliveStrategy() {
        public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
            HeaderElementIterator it =
                    new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
            while (it.hasNext()) {
                HeaderElement he = it.nextElement();
                String param = he.getName();
                String value = he.getValue();
                if (value != null && param.equalsIgnoreCase("timeout")) {
                    try {
                        return Long.parseLong(value) * 1000;
                    } catch (NumberFormatException ignore) {
                    }
                }
            }
            return 5 * 1000;
        }
    });
    this.getConnectionManager();
}
项目:chronix.examples    文件:PoolingHttpClient.java   
@Override
public long getKeepAliveDuration(HttpResponse response,
        HttpContext context) {
    HeaderElementIterator it = new BasicHeaderElementIterator(
            response.headerIterator(HTTP.CONN_KEEP_ALIVE));
    while (it.hasNext()) {
        HeaderElement he = it.nextElement();
        String param = he.getName();
        String value = he.getValue();
        if (value != null && param.equalsIgnoreCase("timeout")) {
            return Long.parseLong(value) * 1000;
        }
    }
    return keepAlive;
}
项目:artifactory    文件:HttpClientConfigurator.java   
/**
 * provide a custom keep-alive strategy
 *
 * @return keep-alive strategy to be used for connection pool
 */
private ConnectionKeepAliveStrategy getConnectionKeepAliveStrategy() {
    return new ConnectionKeepAliveStrategy() {
        @Override
        public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
            // Honor 'keep-alive' header
            HeaderElementIterator it = new BasicHeaderElementIterator(
                    response.headerIterator(HTTP.CONN_KEEP_ALIVE));
            while (it.hasNext()) {
                HeaderElement he = it.nextElement();
                String param = he.getName();
                String value = he.getValue();
                if (value != null && param.equalsIgnoreCase("timeout")) {
                    try {
                        return Long.parseLong(value) * 1000;
                    } catch (NumberFormatException ignore) {
                    }
                }
            }
            HttpHost target = (HttpHost) context.getAttribute(
                    HttpClientContext.HTTP_TARGET_HOST);
            if ("www.naughty-server.com".equalsIgnoreCase(target.getHostName())) {
                return 5 * 1000;
            } else {
                return 30 * 1000;
            }
        }
    };
}
项目:arangodb-java-driver    文件:HttpConnection.java   
private long getKeepAliveDuration(final HttpResponse response) {
    final HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
    while (it.hasNext()) {
        final HeaderElement he = it.nextElement();
        final String param = he.getName();
        final String value = he.getValue();
        if (value != null && "timeout".equalsIgnoreCase(param)) {
            try {
                return Long.parseLong(value) * 1000L;
            } catch (final NumberFormatException ignore) {
            }
        }
    }
    return 30L * 1000L;
}
项目:irond    文件:ChannelThread.java   
/**
 * just look for gzip somewhere and if it's there, use it. ugly.
 *
 * @param req
 * @return
 */
private boolean clientAcceptsGzip(HttpRequest req) {
    HeaderElementIterator it =
        new BasicHeaderElementIterator(req.headerIterator("Accept-Encoding"));
    while (it.hasNext()) {
        HeaderElement element = it.nextElement();
        if (element.getName().contains("gzip")) {
            return true;
        }
    }
    return false;
}
项目:irond    文件:ChannelThread.java   
/**
 * just look for gzip somewhere and if it's there, use it. ugly.
 */
private boolean isReqEntityGzipped(HttpRequest req) {
    HeaderElementIterator it =
        new BasicHeaderElementIterator(req.headerIterator("Content-Encoding"));
    while (it.hasNext()) {
        HeaderElement element = it.nextElement();
        if (element.getName().contains("gzip")) {
            return true;
        }
    }
    return false;
}
项目:dubbo2    文件:RestProtocol.java   
protected <T> T doRefer(Class<T> serviceType, URL url) throws RpcException {
        if (connectionMonitor == null) {
            connectionMonitor = new ConnectionMonitor();
        }

        // TODO more configs to add

        PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager();
        // 20 is the default maxTotal of current PoolingClientConnectionManager
        connectionManager.setMaxTotal(url.getParameter(Constants.CONNECTIONS_KEY, 20));
        connectionManager.setDefaultMaxPerRoute(url.getParameter(Constants.CONNECTIONS_KEY, 20));

        connectionMonitor.addConnectionManager(connectionManager);

//        BasicHttpContext localContext = new BasicHttpContext();

        DefaultHttpClient httpClient = new DefaultHttpClient(connectionManager);

        httpClient.setKeepAliveStrategy(new ConnectionKeepAliveStrategy() {
            public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
                HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
                while (it.hasNext()) {
                    HeaderElement he = it.nextElement();
                    String param = he.getName();
                    String value = he.getValue();
                    if (value != null && param.equalsIgnoreCase("timeout")) {
                        return Long.parseLong(value) * 1000;
                    }
                }
                // TODO constant
                return 30 * 1000;
            }
        });

        HttpParams params = httpClient.getParams();
        // TODO currently no xml config for Constants.CONNECT_TIMEOUT_KEY so we directly reuse Constants.TIMEOUT_KEY for now
        HttpConnectionParams.setConnectionTimeout(params, url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT));
        HttpConnectionParams.setSoTimeout(params, url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT));
        HttpConnectionParams.setTcpNoDelay(params, true);
        HttpConnectionParams.setSoKeepalive(params, true);

        ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(httpClient/*, localContext*/);

        ResteasyClient client = new ResteasyClientBuilder().httpEngine(engine).build();
        clients.add(client);

        client.register(RpcContextFilter.class);
        for (String clazz : Constants.COMMA_SPLIT_PATTERN.split(url.getParameter(Constants.EXTENSION_KEY, ""))) {
            if (!StringUtils.isEmpty(clazz)) {
                try {
                    client.register(Thread.currentThread().getContextClassLoader().loadClass(clazz.trim()));
                } catch (ClassNotFoundException e) {
                    throw new RpcException("Error loading JAX-RS extension class: " + clazz.trim(), e);
                }
            }
        }

        // TODO protocol
        ResteasyWebTarget target = client.target("http://" + url.getHost() + ":" + url.getPort() + "/" + getContextPath(url));
        return target.proxy(serviceType);
    }
项目:dubbox-hystrix    文件:RestProtocol.java   
protected <T> T doRefer(Class<T> serviceType, URL url) throws RpcException {
        if (connectionMonitor == null) {
            connectionMonitor = new ConnectionMonitor();
        }

        // TODO more configs to add

        PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager();
        // 20 is the default maxTotal of current PoolingClientConnectionManager
        connectionManager.setMaxTotal(url.getParameter(Constants.CONNECTIONS_KEY, 20));
        connectionManager.setDefaultMaxPerRoute(url.getParameter(Constants.CONNECTIONS_KEY, 20));

        connectionMonitor.addConnectionManager(connectionManager);

//        BasicHttpContext localContext = new BasicHttpContext();

        DefaultHttpClient httpClient = new DefaultHttpClient(connectionManager);

        httpClient.setKeepAliveStrategy(new ConnectionKeepAliveStrategy() {
            public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
                HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
                while (it.hasNext()) {
                    HeaderElement he = it.nextElement();
                    String param = he.getName();
                    String value = he.getValue();
                    if (value != null && param.equalsIgnoreCase("timeout")) {
                        return Long.parseLong(value) * 1000;
                    }
                }
                // TODO constant
                return 30 * 1000;
            }
        });

        HttpParams params = httpClient.getParams();
        // TODO currently no xml config for Constants.CONNECT_TIMEOUT_KEY so we directly reuse Constants.TIMEOUT_KEY for now
        HttpConnectionParams.setConnectionTimeout(params, url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT));
        HttpConnectionParams.setSoTimeout(params, url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT));
        HttpConnectionParams.setTcpNoDelay(params, true);
        HttpConnectionParams.setSoKeepalive(params, true);

        ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(httpClient/*, localContext*/);

        ResteasyClient client = new ResteasyClientBuilder().httpEngine(engine).build();
        clients.add(client);

        client.register(RpcContextFilter.class);
        for (String clazz : Constants.COMMA_SPLIT_PATTERN.split(url.getParameter(Constants.EXTENSION_KEY, ""))) {
            if (!StringUtils.isEmpty(clazz)) {
                try {
                    client.register(Thread.currentThread().getContextClassLoader().loadClass(clazz.trim()));
                } catch (ClassNotFoundException e) {
                    throw new RpcException("Error loading JAX-RS extension class: " + clazz.trim(), e);
                }
            }
        }

        // TODO protocol
        ResteasyWebTarget target = client.target("http://" + url.getHost() + ":" + url.getPort() + "/" + getContextPath(url));
        return target.proxy(serviceType);
    }
项目:dubbocloud    文件:RestProtocol.java   
protected <T> T doRefer(Class<T> serviceType, URL url) throws RpcException {
        if (connectionMonitor == null) {
            connectionMonitor = new ConnectionMonitor();
        }

        // TODO more configs to add

        PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager();
        // 20 is the default maxTotal of current PoolingClientConnectionManager
        connectionManager.setMaxTotal(url.getParameter(Constants.CONNECTIONS_KEY, 20));
        connectionManager.setDefaultMaxPerRoute(url.getParameter(Constants.CONNECTIONS_KEY, 20));

        connectionMonitor.addConnectionManager(connectionManager);

//        BasicHttpContext localContext = new BasicHttpContext();

        DefaultHttpClient httpClient = new DefaultHttpClient(connectionManager);

        httpClient.setKeepAliveStrategy(new ConnectionKeepAliveStrategy() {
            public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
                HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
                while (it.hasNext()) {
                    HeaderElement he = it.nextElement();
                    String param = he.getName();
                    String value = he.getValue();
                    if (value != null && param.equalsIgnoreCase("timeout")) {
                        return Long.parseLong(value) * 1000;
                    }
                }
                // TODO constant
                return 30 * 1000;
            }
        });

        HttpParams params = httpClient.getParams();
        // TODO currently no xml config for Constants.CONNECT_TIMEOUT_KEY so we directly reuse Constants.TIMEOUT_KEY for now
        HttpConnectionParams.setConnectionTimeout(params, url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT));
        HttpConnectionParams.setSoTimeout(params, url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT));
        HttpConnectionParams.setTcpNoDelay(params, true);
        HttpConnectionParams.setSoKeepalive(params, true);

        ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(httpClient/*, localContext*/);

        ResteasyClient client = new ResteasyClientBuilder().httpEngine(engine).build();
        clients.add(client);

        client.register(RpcContextFilter.class);
        for (String clazz : Constants.COMMA_SPLIT_PATTERN.split(url.getParameter(Constants.EXTENSION_KEY, ""))) {
            if (!StringUtils.isEmpty(clazz)) {
                try {
                    client.register(Thread.currentThread().getContextClassLoader().loadClass(clazz.trim()));
                } catch (ClassNotFoundException e) {
                    throw new RpcException("Error loading JAX-RS extension class: " + clazz.trim(), e);
                }
            }
        }

        // TODO protocol
        ResteasyWebTarget target = client.target("http://" + url.getHost() + ":" + url.getPort() + "/" + getContextPath(url));
        return target.proxy(serviceType);
    }
项目:dubbos    文件:RestProtocol.java   
protected <T> T doRefer(Class<T> serviceType, URL url) throws RpcException {
        if (connectionMonitor == null) {
            connectionMonitor = new ConnectionMonitor();
        }

        // TODO more configs to add

        PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager();
        // 20 is the default maxTotal of current PoolingClientConnectionManager
        connectionManager.setMaxTotal(url.getParameter(Constants.CONNECTIONS_KEY, 20));
        connectionManager.setDefaultMaxPerRoute(url.getParameter(Constants.CONNECTIONS_KEY, 20));

        connectionMonitor.addConnectionManager(connectionManager);

//        BasicHttpContext localContext = new BasicHttpContext();

        DefaultHttpClient httpClient = new DefaultHttpClient(connectionManager);

        httpClient.setKeepAliveStrategy(new ConnectionKeepAliveStrategy() {
            public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
                HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
                while (it.hasNext()) {
                    HeaderElement he = it.nextElement();
                    String param = he.getName();
                    String value = he.getValue();
                    if (value != null && param.equalsIgnoreCase("timeout")) {
                        return Long.parseLong(value) * 1000;
                    }
                }
                // TODO constant
                return 30 * 1000;
            }
        });

        HttpParams params = httpClient.getParams();
        // TODO currently no xml config for Constants.CONNECT_TIMEOUT_KEY so we directly reuse Constants.TIMEOUT_KEY for now
        HttpConnectionParams.setConnectionTimeout(params, url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT));
        HttpConnectionParams.setSoTimeout(params, url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT));
        HttpConnectionParams.setTcpNoDelay(params, true);
        HttpConnectionParams.setSoKeepalive(params, true);

        ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(httpClient/*, localContext*/);

        ResteasyClient client = new ResteasyClientBuilder().httpEngine(engine).build();
        clients.add(client);

        client.register(RpcContextFilter.class);
        for (String clazz : Constants.COMMA_SPLIT_PATTERN.split(url.getParameter(Constants.EXTENSION_KEY, ""))) {
            if (!StringUtils.isEmpty(clazz)) {
                try {
                    client.register(Thread.currentThread().getContextClassLoader().loadClass(clazz.trim()));
                } catch (ClassNotFoundException e) {
                    throw new RpcException("Error loading JAX-RS extension class: " + clazz.trim(), e);
                }
            }
        }

        // TODO protocol
        ResteasyWebTarget target = client.target("http://" + url.getHost() + ":" + url.getPort() + "/" + getContextPath(url));
        return target.proxy(serviceType);
    }
项目:dubbox    文件:RestProtocol.java   
protected <T> T doRefer(Class<T> serviceType, URL url) throws RpcException {
        if (connectionMonitor == null) {
            connectionMonitor = new ConnectionMonitor();
        }

        // TODO more configs to add

        PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager();
        // 20 is the default maxTotal of current PoolingClientConnectionManager
        connectionManager.setMaxTotal(url.getParameter(Constants.CONNECTIONS_KEY, 20));
        connectionManager.setDefaultMaxPerRoute(url.getParameter(Constants.CONNECTIONS_KEY, 20));

        connectionMonitor.addConnectionManager(connectionManager);

//        BasicHttpContext localContext = new BasicHttpContext();

        DefaultHttpClient httpClient = new DefaultHttpClient(connectionManager);

        httpClient.setKeepAliveStrategy(new ConnectionKeepAliveStrategy() {
            public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
                HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
                while (it.hasNext()) {
                    HeaderElement he = it.nextElement();
                    String param = he.getName();
                    String value = he.getValue();
                    if (value != null && param.equalsIgnoreCase("timeout")) {
                        return Long.parseLong(value) * 1000;
                    }
                }
                // TODO constant
                return 30 * 1000;
            }
        });

        HttpParams params = httpClient.getParams();
        // TODO currently no xml config for Constants.CONNECT_TIMEOUT_KEY so we directly reuse Constants.TIMEOUT_KEY for now
        HttpConnectionParams.setConnectionTimeout(params, url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT));
        HttpConnectionParams.setSoTimeout(params, url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT));
        HttpConnectionParams.setTcpNoDelay(params, true);
        HttpConnectionParams.setSoKeepalive(params, true);

        ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(httpClient/*, localContext*/);

        ResteasyClient client = new ResteasyClientBuilder().httpEngine(engine).build();
        clients.add(client);

        client.register(RpcContextFilter.class);
        for (String clazz : Constants.COMMA_SPLIT_PATTERN.split(url.getParameter(Constants.EXTENSION_KEY, ""))) {
            if (!StringUtils.isEmpty(clazz)) {
                try {
                    client.register(Thread.currentThread().getContextClassLoader().loadClass(clazz.trim()));
                } catch (ClassNotFoundException e) {
                    throw new RpcException("Error loading JAX-RS extension class: " + clazz.trim(), e);
                }
            }
        }

        // TODO protocol
        ResteasyWebTarget target = client.target("http://" + url.getHost() + ":" + url.getPort() + "/" + getContextPath(url));
        return target.proxy(serviceType);
    }
项目:dubbo-rpc-rest    文件:RestProtocol.java   
protected <T> T doRefer(Class<T> serviceType, URL url) throws RpcException {
    if (connectionMonitor == null) {
        connectionMonitor = new ConnectionMonitor();
    }

    // TODO more configs to add

    PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager();
    // 20 is the default maxTotal of current PoolingClientConnectionManager
    connectionManager.setMaxTotal(url.getParameter(Constants.CONNECTIONS_KEY, 20));
    connectionManager.setDefaultMaxPerRoute(url.getParameter(Constants.CONNECTIONS_KEY, 20));

    connectionMonitor.addConnectionManager(connectionManager);

    // BasicHttpContext localContext = new BasicHttpContext();

    DefaultHttpClient httpClient = new DefaultHttpClient(connectionManager);

    httpClient.setKeepAliveStrategy(new ConnectionKeepAliveStrategy() {
        public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
            HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
            while (it.hasNext()) {
                HeaderElement he = it.nextElement();
                String param = he.getName();
                String value = he.getValue();
                if (value != null && param.equalsIgnoreCase("timeout")) {
                    return Long.parseLong(value) * 1000;
                }
            }
            // TODO constant
            return 30 * 1000;
        }
    });

    HttpParams params = httpClient.getParams();
    // TODO currently no xml config for Constants.CONNECT_TIMEOUT_KEY so we directly reuse Constants.TIMEOUT_KEY for now
    HttpConnectionParams.setConnectionTimeout(params, url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT));
    HttpConnectionParams.setSoTimeout(params, url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT));
    HttpConnectionParams.setTcpNoDelay(params, true);
    HttpConnectionParams.setSoKeepalive(params, true);

    ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(httpClient/* , localContext */);

    ResteasyClient client = new ResteasyClientBuilder().httpEngine(engine).build();
    clients.add(client);

    client.register(RpcContextFilter.class);
    for (String clazz : Constants.COMMA_SPLIT_PATTERN.split(url.getParameter(Constants.EXTENSION_KEY, ""))) {
        if (!StringUtils.isEmpty(clazz)) {
            try {
                client.register(Thread.currentThread().getContextClassLoader().loadClass(clazz.trim()));
            } catch (ClassNotFoundException e) {
                throw new RpcException("Error loading JAX-RS extension class: " + clazz.trim(), e);
            }
        }
    }

    // dubbo 服务多版本
    String version = url.getParameter(Constants.VERSION_KEY);
    String versionPath = "";
    if (StringUtils.isNotEmpty(version)) {
        versionPath = version + "/";
    }
    // TODO protocol
    ResteasyWebTarget target = client.target("http://" + url.getHost() + ":" + url.getPort() + "/" + versionPath + getContextPath(url));
    return target.proxy(serviceType);
}
项目:IOT-Espressif-Android    文件:EspHttpClient.java   
private void init()
{
    BasicHttpParams params = new BasicHttpParams();
    params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, CONNECTION_TIMEOUT);
    params.setParameter(CoreConnectionPNames.SO_TIMEOUT, SO_TIMEOUT);
    params.setParameter("timemout", 6);
    this.setParams(params);
    // set keep alive strategy
    this.setKeepAliveStrategy(new ConnectionKeepAliveStrategy()
    {
        public long getKeepAliveDuration(HttpResponse response, HttpContext context)
        { // Honor 'keep-alive' header
            HeaderElementIterator it =
                new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
            while (it.hasNext())
            {
                HeaderElement he = it.nextElement();
                String param = he.getName();
                String value = he.getValue();
                if (value != null && param.equalsIgnoreCase("timeout"))
                {
                    try
                    {
                        return Long.parseLong(value) * 1000;
                    }
                    catch (NumberFormatException ignore)
                    {
                    }
                }
            }
            Integer timeout = (Integer)context.getAttribute("timeout");
            if (timeout != null)
            {
                return timeout.longValue();
            }
            HttpHost target = (HttpHost)context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
            if ("iot.espressif.cn".equalsIgnoreCase(target.getHostName()))
            {
                // Keep alive for 30 seconds when connecting to server
                return 30 * 1000;
            }
            else
            {
                // otherwise keep alive for 8 seconds when connection to device
                return 10 * 1000;
            }
        }
    });
}
项目:LetUsGo-Server    文件:RestProtocol.java   
protected <T> T doRefer(Class<T> serviceType, URL url) throws RpcException {
        if (connectionMonitor == null) {
            connectionMonitor = new ConnectionMonitor();
        }

        // TODO more configs to add

        PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager();
        // 20 is the default maxTotal of current PoolingClientConnectionManager
        connectionManager.setMaxTotal(url.getParameter(Constants.CONNECTIONS_KEY, 20));
        connectionManager.setDefaultMaxPerRoute(url.getParameter(Constants.CONNECTIONS_KEY, 20));

        connectionMonitor.addConnectionManager(connectionManager);

//        BasicHttpContext localContext = new BasicHttpContext();

        DefaultHttpClient httpClient = new DefaultHttpClient(connectionManager);

        httpClient.setKeepAliveStrategy(new ConnectionKeepAliveStrategy() {
            public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
                HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
                while (it.hasNext()) {
                    HeaderElement he = it.nextElement();
                    String param = he.getName();
                    String value = he.getValue();
                    if (value != null && param.equalsIgnoreCase("timeout")) {
                        return Long.parseLong(value) * 1000;
                    }
                }
                // TODO constant
                return 30 * 1000;
            }
        });

        HttpParams params = httpClient.getParams();
        // TODO currently no xml config for Constants.CONNECT_TIMEOUT_KEY so we directly reuse Constants.TIMEOUT_KEY for now
        HttpConnectionParams.setConnectionTimeout(params, url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT));
        HttpConnectionParams.setSoTimeout(params, url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT));
        HttpConnectionParams.setTcpNoDelay(params, true);
        HttpConnectionParams.setSoKeepalive(params, true);

        ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(httpClient/*, localContext*/);

        ResteasyClient client = new ResteasyClientBuilder().httpEngine(engine).build();
        clients.add(client);

        client.register(RpcContextFilter.class);
        for (String clazz : Constants.COMMA_SPLIT_PATTERN.split(url.getParameter(Constants.EXTENSION_KEY, ""))) {
            if (!StringUtils.isEmpty(clazz)) {
                try {
                    client.register(Thread.currentThread().getContextClassLoader().loadClass(clazz.trim()));
                } catch (ClassNotFoundException e) {
                    throw new RpcException("Error loading JAX-RS extension class: " + clazz.trim(), e);
                }
            }
        }

        // TODO protocol
        ResteasyWebTarget target = client.target("http://" + url.getHost() + ":" + url.getPort() + "/" + getContextPath(url));
        return target.proxy(serviceType);
    }
项目:dangdangdotcom    文件:RestProtocol.java   
protected <T> T doRefer(Class<T> serviceType, URL url) throws RpcException {
        if (connectionMonitor == null) {
            connectionMonitor = new ConnectionMonitor();
        }

        // TODO more configs to add

        PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager();
        // 20 is the default maxTotal of current PoolingClientConnectionManager
        connectionManager.setMaxTotal(url.getParameter(Constants.CONNECTIONS_KEY, 20));
        connectionManager.setDefaultMaxPerRoute(url.getParameter(Constants.CONNECTIONS_KEY, 20));

        connectionMonitor.addConnectionManager(connectionManager);

//        BasicHttpContext localContext = new BasicHttpContext();

        DefaultHttpClient httpClient = new DefaultHttpClient(connectionManager);

        httpClient.setKeepAliveStrategy(new ConnectionKeepAliveStrategy() {
            public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
                HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
                while (it.hasNext()) {
                    HeaderElement he = it.nextElement();
                    String param = he.getName();
                    String value = he.getValue();
                    if (value != null && param.equalsIgnoreCase("timeout")) {
                        return Long.parseLong(value) * 1000;
                    }
                }
                // TODO constant
                return 30 * 1000;
            }
        });

        HttpParams params = httpClient.getParams();
        // TODO currently no xml config for Constants.CONNECT_TIMEOUT_KEY so we directly reuse Constants.TIMEOUT_KEY for now
        HttpConnectionParams.setConnectionTimeout(params, url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT));
        HttpConnectionParams.setSoTimeout(params, url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT));
        HttpConnectionParams.setTcpNoDelay(params, true);
        HttpConnectionParams.setSoKeepalive(params, true);

        ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(httpClient/*, localContext*/);

        ResteasyClient client = new ResteasyClientBuilder().httpEngine(engine).build();
        clients.add(client);

        for (String clazz : Constants.COMMA_SPLIT_PATTERN.split(url.getParameter(Constants.EXTENSION_KEY, ""))) {
            if (!StringUtils.isEmpty(clazz)) {
                try {
                    client.register(Thread.currentThread().getContextClassLoader().loadClass(clazz.trim()));
                } catch (ClassNotFoundException e) {
                    throw new RpcException("Error loading JAX-RS extension class: " + clazz.trim(), e);
                }
            }
        }

        // TODO protocol
        ResteasyWebTarget target = client.target("http://" + url.getHost() + ":" + url.getPort() + "/" + getContextPath(url));
        return target.proxy(serviceType);
    }
项目:jweevely    文件:JweevelyClient.java   
public static String oneJweevelyClient(CloseableHttpClient httpclient,
        HttpPost httppost, String password, String inputStr, String identify)
        throws ClientProtocolException, IOException {

    populateCookiesValue(httppost, password, inputStr);

    CloseableHttpResponse response = httpclient.execute(httppost);

    cleanHttpPost(httppost);

    try {
        HeaderElementIterator het = new BasicHeaderElementIterator(
                response.headerIterator("Set-Cookie"));
        while (het.hasNext()) {
            HeaderElement elem = het.nextElement();
            // System.out.println(elem.getName()+"----"+ elem.getValue());

            if (elem.getName().equals("rlp")) {

                String rlp_value = elem.getValue();

                if (rlp_value != null && !rlp_value.isEmpty()) {

                    BuiltIn.setUriAbsolutePath(rlp_value);

                    // when first login, print the currentfile and docRoot.
                    System.out.println(BuiltIn.CURRENTFILE + "\t"
                            + BuiltIn.uriAbsolutePath);
                    System.out.println(BuiltIn.DOCROOT + "\t"
                            + BuiltIn.doc_root);
                    break;
                }
            }
        }
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            // long len = entity.getContentLength();
            // if (len != -1 && len < 2048 * 2) {
            String responseContents = EntityUtils.toString(entity);
            int div_start = responseContents.indexOf("<" + identify + ">")
                    + ("<" + identify + ">").length();
            int div_end = responseContents.indexOf("</" + identify + ">");
            if (div_end >= div_start) {
                return responseContents.substring(div_start, div_end);
            }
            return "<" + identify + ">page not return contents.</"
                    + identify + ">\n";
            // } else {
            // System.out.println(responseContents);
            // return "contents are too huge.\n";
            // }
        } else {
            return "";
        }
    } finally {
        response.close();
    }
}
项目:irond    文件:BasicChannelAuth.java   
@Override
public void authenticate(HttpRequest request) throws ChannelAuthException {
    HeaderElementIterator it =
        new BasicHeaderElementIterator(request.headerIterator("Authorization"));
    HeaderElement elem;

    if(it.hasNext()){
        elem = it.nextElement();
    } else {
        throw new ChannelAuthException("no authorization field found");
    }

    // split the value of the Authorization header. split[0] should be
    // basic and split[1] the base64 stuff.
    String split[] = elem.getName().split(" ");

    if (split.length != 2 || !split[0].equals("Basic")) {
        throw new ChannelAuthException("Bad Authorization header value!");
    }

    String base64 = split[1];
    String[] creds = new String(Base64.decodeBase64(base64)).split(":");

    if(creds.length != 2){
        throw new ChannelAuthException("Wrong credentials, not authenticated!");
    }

    String user = creds[0];
    String pass = creds[1];

    if(!mBasicAuthProvider.verify(user, pass)){
        throw new ChannelAuthException("Bad username/password");
    } else {
        ClientIdentifier newClId = new ClientIdentifier(user);
        // this checks, whether the username is the same as given on the
        // first call. If this is the first call, set the mClientId field
        // appropriately.
        if (mClientId != null) {
            if (!mClientId.equals(newClId)) {
                throw new ChannelAuthException("Username/password was changed");
            }
        } else {
            mClientId = newClId;
        }
    }
}