Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   *  Copyright (c) xlightweb.org, 2008 - 2010. All rights reserved.
   *
   *  This library is free software; you can redistribute it and/or
   *  modify it under the terms of the GNU Lesser General Public
   *  License as published by the Free Software Foundation; either
   *  version 2.1 of the License, or (at your option) any later version.
   *
   *  This library is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  *  Lesser General Public License for more details.
  *
  *  You should have received a copy of the GNU Lesser General Public
  *  License along with this library; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
  * Please refer to the LGPL license at: http://www.gnu.org/copyleft/lesser.txt
  * The latest copy of this software may be found on http://www.xlightweb.org/
  */
 package org.xlightweb.client;
 
 
 
 
 import java.net.URI;
 
 
 
Higher level client-side abstraction of the client side endpoint. Internally, the HttpClient uses a pool of org.xlightweb.client.HttpClientConnection to perform the requests. Example:
   HttpClient httpClient = new HttpClient();
   
   // set some properties
   httpClient.setFollowsRedirect(true);  
   httpClient.setAutoHandleCookies(false);
   // ...
   
   // perform a synchronous call 
   IHttpResponse response = httpClient.call(new GetRequest("http://www.gmx.com/index.html"));
   System.out.println(response.getStatus());
   
   BlockingBodyDataSource bodyChannel = response.getBlockingBody();
   System.out.println(bodyChannel.readString());
   
   
   // perform an asynchronous request
   MyResponseHandler respHdl = new MyResponseHandler();
   httpClient.send(new HttpRequestHeader("GET", "http://www.gmx.com/index.html"), respHdl);
   
   //..
   
   httpClient.close(); 
 
The HttpClient is thread-safe

Author(s):
grro@xlightweb.org
 
 public class XHttpClient extends HttpClient {
    
    
    
constructor

Parameters:
interceptors interceptor
 
     public XHttpClient(IHttpRequestHandler... interceptors) {
         super(interceptors);
     }
    
    
    
    
constructor

Parameters:
sslCtx the ssl context to use
 
     public XHttpClient(SSLContext sslCtx) {
         super(sslCtx);
     }

    
    
constructor

Parameters:
sslCtx the ssl context to use
interceptors the interceptors
    public XHttpClient(SSLContext sslCtxIHttpRequestHandler... interceptors) {
        super(sslCtxinterceptors);
    }
    
    public IWebSocketConnection openWebSocketConnection(String uriStringthrows IOException {
        return openWebSocketConnection(uriString, (Stringnull);
    }
    
    public IWebSocketConnection openWebSocketConnection(String uriStringString protocolthrows IOException {
        return openWebSocketConnection(uriStringprotocolnull);
    }
    
    public IWebSocketConnection openWebSocketConnection(String uriStringIWebSocketHandler webSocketHandlerthrows IOException {
        return openWebSocketConnection(uriStringnullwebSocketHandler);
    }
    
    
    public IWebSocketConnection openWebSocketConnection(String uriStringString protocolIWebSocketHandler webSocketHandlerthrows IOException {
        URI uri = URI.create(uriString);
        
        int port = uri.getPort();
        if (port == -1) {
            if (uri.getScheme().toLowerCase().equals("wss")) {
                port = 443;
            } else {
                port = 80;
            }
        }
        
        INonBlockingConnection tcpCon;
        if (uri.getScheme().toLowerCase().equals("wss")) {
            tcpCon = getHttpClientConnectionPool().getUnderlyingConnectionPool().getNonBlockingConnection(uri.getHost(), porttrue);
        } else {
            tcpCon = getHttpClientConnectionPool().getUnderlyingConnectionPool().getNonBlockingConnection(uri.getHost(), port);            
        }
        return new WebSocketConnection(tcpConuriprotocolwebSocketHandler); 
    }	
New to GrepCode? Check out our FAQ X