Esempio n. 1
0
 public void init() throws Exception {
   client = new HttpClient();
   client.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
   client.setThreadPool(new ExecutorThreadPool(4, 256, timeout, TimeUnit.SECONDS));
   client.setTimeout(timeout);
   client.start();
 }
  /**
   * Create a http client
   *
   * @return
   * @throws Exception
   */
  private static BayeuxClient makeClient() throws Exception {
    HttpClient httpClient = new HttpClient();
    httpClient.setConnectTimeout(connectionTimeout);
    httpClient.setTimeout(readTimeout); // TODO optional parameters
    httpClient.start();

    SoapLoginUtil.login(httpClient, userName, password);
    final String sessionId = SoapLoginUtil.getSessionId();
    String endpoint = SoapLoginUtil.getEndpoint();
    System.out.println("Login successful!\nEndpoint: " + endpoint + "\nSessionid=" + sessionId);

    Map<String, Object> options = new HashMap<String, Object>();
    options.put(ClientTransport.TIMEOUT_OPTION, readTimeout);
    LongPollingTransport transport =
        new LongPollingTransport(options, httpClient) {

          @Override
          protected void customize(ContentExchange exchange) {
            super.customize(exchange);
            exchange.addRequestHeader("Authorization", "OAuth " + sessionId);
          }
        };

    BayeuxClient client = new BayeuxClient(salesforceStreamingEndpoint(endpoint), transport);
    if (useCookies) establishCookies(client, userName, sessionId);
    return client;
  }
Esempio n. 3
0
 /** Initialize the client object */
 public StockManagerHTTPProxy(String serverAddress) throws Exception {
   setServerAddress(serverAddress);
   client = new HttpClient();
   client.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
   client.setMaxConnectionsPerAddress(
       BookStoreClientConstants.CLIENT_MAX_CONNECTION_ADDRESS); // max
   // concurrent
   // connections
   // to
   // every
   // address
   client.setThreadPool(
       new QueuedThreadPool(BookStoreClientConstants.CLIENT_MAX_THREADSPOOL_THREADS)); // max
   // threads
   client.setTimeout(BookStoreClientConstants.CLIENT_MAX_TIMEOUT_MILLISECS); // seconds
   // timeout;
   // if
   // no
   // server
   // reply,
   // the
   // request
   // expires
   client.start();
 }
  // TODO: client.start() could potentially have some side effects.
  // Need to understand more of what's going on under the hood.
  @Provides
  HttpClient provideHttpClient() {
    LOGGER.info("Providing http client for connection name " + connectionName);

    HttpClient client = new HttpClient();
    client.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
    client.setConnectTimeout(timeoutOption);
    client.setTimeout(timeoutOption);

    return client;
  }