Java Code Examples for org.apache.http.protocol.HttpContext

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project Fotolia-API, under directory /java/libs/httpcomponents-client-4.1.2/examples/org/apache/http/examples/client/.

Source file: ClientCustomContext.java

  19 
vote

public final static void main(String[] args) throws Exception {
  HttpClient httpclient=new DefaultHttpClient();
  try {
    CookieStore cookieStore=new BasicCookieStore();
    HttpContext localContext=new BasicHttpContext();
    localContext.setAttribute(ClientContext.COOKIE_STORE,cookieStore);
    HttpGet httpget=new HttpGet("http://www.google.com/");
    System.out.println("executing request " + httpget.getURI());
    HttpResponse response=httpclient.execute(httpget,localContext);
    HttpEntity entity=response.getEntity();
    System.out.println("----------------------------------------");
    System.out.println(response.getStatusLine());
    if (entity != null) {
      System.out.println("Response content length: " + entity.getContentLength());
    }
    List<Cookie> cookies=cookieStore.getCookies();
    for (int i=0; i < cookies.size(); i++) {
      System.out.println("Local cookie: " + cookies.get(i));
    }
    EntityUtils.consume(entity);
    System.out.println("----------------------------------------");
  }
  finally {
    httpclient.getConnectionManager().shutdown();
  }
}
 

Example 2

From project httpClient, under directory /httpclient/src/main/java/org/apache/http/impl/client/.

Source file: AbstractHttpClient.java

  18 
vote

protected HttpContext createHttpContext(){
  HttpContext context=new BasicHttpContext();
  context.setAttribute(ClientContext.SCHEME_REGISTRY,getConnectionManager().getSchemeRegistry());
  context.setAttribute(ClientContext.AUTHSCHEME_REGISTRY,getAuthSchemes());
  context.setAttribute(ClientContext.COOKIESPEC_REGISTRY,getCookieSpecs());
  context.setAttribute(ClientContext.COOKIE_STORE,getCookieStore());
  context.setAttribute(ClientContext.CREDS_PROVIDER,getCredentialsProvider());
  return context;
}
 

Example 3

From project Alerte-voirie-android, under directory /src/com/fabernovel/alertevoirie/webservice/.

Source file: AVService.java

  17 
vote

@Override protected HttpResponse[] doInBackground(ArrayList<Object>... params){
  HttpResponse[] response=new HttpResponse[2];
  int i=0;
  for (  ArrayList<Object> PicArray : params) {
    if (PicArray != null) {
      HttpClient httpClient=new DefaultHttpClient();
      HttpContext localContext=new BasicHttpContext();
      HttpPost httpPost=new HttpPost((String)PicArray.get(0));
      httpPost.addHeader("udid",(String)PicArray.get(1));
      Log.d(Constants.PROJECT_TAG,"length : " + ((String)PicArray.get(2)).length());
      httpPost.addHeader("img_comment",(String)PicArray.get(2));
      httpPost.addHeader("incident_id",(String)PicArray.get(3));
      httpPost.addHeader("type",(String)PicArray.get(4));
      if (((Boolean)PicArray.get(6)).booleanValue()) {
        httpPost.addHeader("INCIDENT_CREATION","true");
      }
      try {
        FileEntity file=new FileEntity((File)PicArray.get(5),"image/jpeg");
        file.setContentType("image/jpeg");
        httpPost.setEntity(file);
        response[i++]=httpClient.execute(httpPost,localContext);
      }
 catch (      IOException e) {
        Log.e(Constants.PROJECT_TAG,"IOException postImage",e);
      }
catch (      IllegalStateException e) {
        Log.e(Constants.PROJECT_TAG,"IllegalStateException postImage",e);
      }
    }
  }
  return response;
}
 

Example 4

From project bbb-java, under directory /src/main/java/org/mconf/bbb/api/.

Source file: JoinServiceBase.java

  17 
vote

public int standardJoin(String joinUrl){
  joinedMeeting=new JoinedMeeting();
  try {
    HttpClient client=new DefaultHttpClient();
    HttpGet method=new HttpGet(joinUrl);
    HttpContext context=new BasicHttpContext();
    HttpResponse httpResponse=client.execute(method,context);
    if (httpResponse.getStatusLine().getStatusCode() != HttpStatus.SC_OK)     log.debug("HTTP GET {} return {}",joinUrl,httpResponse.getStatusLine().getStatusCode());
    HttpUriRequest currentReq=(HttpUriRequest)context.getAttribute(ExecutionContext.HTTP_REQUEST);
    if (!currentReq.getURI().getPath().equals("/client/BigBlueButton.html")) {
      log.error("It was redirected to {} instead of /client/BigBlueButton.html: the server was branded" + " and the HTML name was changed, or it's an error. However, it will continue processing",currentReq.getURI().getPath());
    }
    HttpHost currentHost=(HttpHost)context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
    String enterUrl=currentHost.toURI() + "/bigbluebutton/api/enter";
    String enterResponse=getUrl(client,enterUrl).replace("</response>","<server>" + currentHost.toURI() + "</server></response>");
    joinedMeeting.parse(enterResponse);
  }
 catch (  Exception e) {
    e.printStackTrace();
    log.error("Can't join the url {}",joinUrl);
    return E_SERVER_UNREACHABLE;
  }
  return joinResponse();
}
 

Example 5

From project droid-fu, under directory /src/main/java/com/github/droidfu/http/.

Source file: BetterHttpRequestBase.java

  17 
vote

public BetterHttpResponse send() throws ConnectException {
  BetterHttpRequestRetryHandler retryHandler=new BetterHttpRequestRetryHandler(maxRetries);
  httpClient.setHttpRequestRetryHandler(retryHandler);
  HttpContext context=new BasicHttpContext();
  boolean retry=true;
  IOException cause=null;
  while (retry) {
    try {
      return httpClient.execute(request,this,context);
    }
 catch (    IOException e) {
      cause=e;
      retry=retryRequest(retryHandler,cause,context);
    }
catch (    NullPointerException e) {
      cause=new IOException("NPE in HttpClient" + e.getMessage());
      retry=retryRequest(retryHandler,cause,context);
    }
 finally {
      if (oldTimeout != BetterHttp.getSocketTimeout()) {
        BetterHttp.setSocketTimeout(oldTimeout);
      }
    }
  }
  ConnectException ex=new ConnectException();
  ex.initCause(cause);
  throw ex;
}
 

Example 6

From project DTE, under directory /src/cl/nic/dte/net/.

Source file: ConexionSii.java

  17 
vote

private RECEPCIONDTEDocument uploadEnvio(String rutEnvia,String rutCompania,File archivoEnviarSII,String token,String urlEnvio,String hostEnvio) throws ClientProtocolException, IOException, org.apache.http.ParseException, XmlException {
  HttpClient httpclient=new DefaultHttpClient();
  HttpPost httppost=new HttpPost(urlEnvio);
  MultipartEntity reqEntity=new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
  reqEntity.addPart("rutSender",new StringBody(rutEnvia.substring(0,rutEnvia.length() - 2)));
  reqEntity.addPart("dvSender",new StringBody(rutEnvia.substring(rutEnvia.length() - 1,rutEnvia.length())));
  reqEntity.addPart("rutCompany",new StringBody(rutCompania.substring(0,(rutCompania).length() - 2)));
  reqEntity.addPart("dvCompany",new StringBody(rutCompania.substring(rutCompania.length() - 1,rutCompania.length())));
  FileBody bin=new FileBody(archivoEnviarSII);
  reqEntity.addPart("archivo",bin);
  httppost.setEntity(reqEntity);
  BasicClientCookie cookie=new BasicClientCookie("TOKEN",token);
  cookie.setPath("/");
  cookie.setDomain(hostEnvio);
  cookie.setSecure(true);
  cookie.setVersion(1);
  CookieStore cookieStore=new BasicCookieStore();
  cookieStore.addCookie(cookie);
  httpclient.getParams().setParameter(ClientPNames.COOKIE_POLICY,CookiePolicy.RFC_2109);
  httppost.getParams().setParameter(ClientPNames.COOKIE_POLICY,CookiePolicy.BROWSER_COMPATIBILITY);
  HttpContext localContext=new BasicHttpContext();
  localContext.setAttribute(ClientContext.COOKIE_STORE,cookieStore);
  httppost.addHeader(new BasicHeader("User-Agent",Utilities.netLabels.getString("UPLOAD_SII_HEADER_VALUE")));
  HttpResponse response=httpclient.execute(httppost,localContext);
  HttpEntity resEntity=response.getEntity();
  RECEPCIONDTEDocument resp=null;
  HashMap<String,String> namespaces=new HashMap<String,String>();
  namespaces.put("","http://www.sii.cl/SiiDte");
  XmlOptions opts=new XmlOptions();
  opts.setLoadSubstituteNamespaces(namespaces);
  resp=RECEPCIONDTEDocument.Factory.parse(EntityUtils.toString(resEntity),opts);
  return resp;
}
 

Example 7

From project exo.social.client, under directory /src/main/java/org/exoplatform/social/client/core/net/.

Source file: SocialHttpClientImpl.java

  17 
vote

private SocialHttpClientImpl(ClientConnectionManager ccm,HttpParams params){
  delegate=new DefaultHttpClient(ccm,params){
    @Override protected BasicHttpProcessor createHttpProcessor(){
      BasicHttpProcessor processor=super.createHttpProcessor();
      return processor;
    }
    @Override protected HttpContext createHttpContext(){
      HttpContext context=new BasicHttpContext();
      context.setAttribute(ClientContext.AUTHSCHEME_REGISTRY,getAuthSchemes());
      context.setAttribute(ClientContext.COOKIESPEC_REGISTRY,getCookieSpecs());
      context.setAttribute(ClientContext.CREDS_PROVIDER,getCredentialsProvider());
      return context;
    }
  }
;
}
 

Example 8

From project Game_3, under directory /android/src/playn/android/.

Source file: AndroidHttpClient.java

  17 
vote

private AndroidHttpClient(ClientConnectionManager ccm,HttpParams params){
  this.delegate=new DefaultHttpClient(ccm,params){
    @Override protected BasicHttpProcessor createHttpProcessor(){
      BasicHttpProcessor processor=super.createHttpProcessor();
      processor.addRequestInterceptor(sThreadCheckInterceptor);
      return processor;
    }
    @Override protected HttpContext createHttpContext(){
      HttpContext context=new BasicHttpContext();
      context.setAttribute(ClientContext.AUTHSCHEME_REGISTRY,getAuthSchemes());
      context.setAttribute(ClientContext.COOKIESPEC_REGISTRY,getCookieSpecs());
      context.setAttribute(ClientContext.CREDS_PROVIDER,getCredentialsProvider());
      return context;
    }
  }
;
}
 

Example 9

From project AirCastingAndroidClient, under directory /src/main/java/pl/llp/aircasting/util/http/.

Source file: HttpBuilder.java

  15 
vote

private HttpRequestInterceptor preemptiveAuth(){
  return new HttpRequestInterceptor(){
    @Override public void process(    HttpRequest httpRequest,    HttpContext httpContext) throws HttpException, IOException {
      AuthState authState=(AuthState)httpContext.getAttribute(ClientContext.TARGET_AUTH_STATE);
      Credentials credentials;
      if (useLogin) {
        credentials=new UsernamePasswordCredentials(login,password);
      }
 else {
        credentials=new UsernamePasswordCredentials(settingsHelper.getAuthToken(),"X");
      }
      authState.setAuthScope(AuthScope.ANY);
      authState.setAuthScheme(new BasicScheme());
      authState.setCredentials(credentials);
    }
  }
;
}
 

Example 10

From project android-async-http, under directory /src/com/loopj/android/http/.

Source file: AsyncHttpClient.java

  15 
vote

private void sendRequest(DefaultHttpClient client,HttpContext httpContext,HttpUriRequest uriRequest,String contentType,AsyncHttpResponseHandler responseHandler,Context context){
  if (contentType != null) {
    uriRequest.addHeader("Content-Type",contentType);
  }
  Future<?> request=threadPool.submit(new AsyncHttpRequest(client,httpContext,uriRequest,responseHandler));
  if (context != null) {
    List<WeakReference<Future<?>>> requestList=requestMap.get(context);
    if (requestList == null) {
      requestList=new LinkedList<WeakReference<Future<?>>>();
      requestMap.put(context,requestList);
    }
    requestList.add(new WeakReference<Future<?>>(request));
  }
}
 

Example 11

From project android-bankdroid, under directory /src/eu/nullbyte/android/urllib/.

Source file: Urllib.java

  15 
vote

public void setKeepAliveTimeout(final int seconds){
  httpclient.setKeepAliveStrategy(new ConnectionKeepAliveStrategy(){
    @Override public long getKeepAliveDuration(    HttpResponse response,    HttpContext arg1){
      return seconds;
    }
  }
);
}
 

Example 12

From project android-client, under directory /xwiki-android-rest/src/org/xwiki/android/rest/.

Source file: HttpConnector.java

  15 
vote

/** 
 * set user credentials with manually developed preemtive Auth
 */
private void setCredentials(){
  if (isSecured) {
    preemptiveAuth=new HttpRequestInterceptor(){
      public void process(      HttpRequest request,      HttpContext context) throws HttpException, IOException {
        AuthState authState=(AuthState)context.getAttribute(ClientContext.TARGET_AUTH_STATE);
        CredentialsProvider credsProvider=(CredentialsProvider)context.getAttribute(ClientContext.CREDS_PROVIDER);
        HttpHost targetHost=(HttpHost)context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
        if (authState.getAuthScheme() == null) {
          AuthScope authScope=new AuthScope(targetHost.getHostName(),targetHost.getPort());
          Credentials creds=credsProvider.getCredentials(authScope);
          if (creds != null) {
            authState.setAuthScheme(new BasicScheme());
            authState.setCredentials(creds);
          }
        }
      }
    }
;
    client.addRequestInterceptor(preemptiveAuth,0);
    Credentials defaultcreds=new UsernamePasswordCredentials(username,password);
    client.getCredentialsProvider().setCredentials(new AuthScope(null,-1,AuthScope.ANY_REALM),defaultcreds);
  }
}
 

Example 13

From project android-rackspacecloud, under directory /extensions/httpnio/src/main/java/org/jclouds/http/httpnio/pool/.

Source file: NioHttpCommandExecutionHandler.java

  15 
vote

public HttpEntityEnclosingRequest submitRequest(HttpContext context){
  HttpCommandRendezvous<?> rendezvous=(HttpCommandRendezvous<?>)context.removeAttribute("command");
  if (rendezvous != null) {
    HttpRequest request=rendezvous.getCommand().getRequest();
    for (    HttpRequestFilter filter : request.getFilters()) {
      filter.filter(request);
    }
    logger.debug("Sending request %s: %s",request.hashCode(),request.getRequestLine());
    if (request.getPayload() != null && wire.enabled())     request.setPayload(Payloads.newPayload(wire.output(request.getPayload().getRawContent())));
    HttpEntityEnclosingRequest nativeRequest=NioHttpUtils.convertToApacheRequest(request);
    HttpUtils.logRequest(headerLog,request,">>");
    return nativeRequest;
  }
  return null;
}
 

Example 14

From project AquaNotesTest, under directory /src/com/google/android/apps/iosched/service/.

Source file: SyncService.java

  15 
vote

/** 
 * Generate and return a  {@link HttpClient} configured for general use,including setting an application-specific user-agent string.
 */
public static HttpClient getHttpClient(Context context){
  final HttpParams params=new BasicHttpParams();
  HttpConnectionParams.setConnectionTimeout(params,20 * SECOND_IN_MILLIS);
  HttpConnectionParams.setSoTimeout(params,20 * SECOND_IN_MILLIS);
  HttpConnectionParams.setSocketBufferSize(params,8192);
  HttpProtocolParams.setUserAgent(params,buildUserAgent(context));
  final DefaultHttpClient client=new DefaultHttpClient(params);
  client.addRequestInterceptor(new HttpRequestInterceptor(){
    public void process(    HttpRequest request,    HttpContext context){
      if (!request.containsHeader(HEADER_ACCEPT_ENCODING)) {
        request.addHeader(HEADER_ACCEPT_ENCODING,ENCODING_GZIP);
      }
    }
  }
);
  client.addResponseInterceptor(new HttpResponseInterceptor(){
    public void process(    HttpResponse response,    HttpContext context){
      final HttpEntity entity=response.getEntity();
      final Header encoding=entity.getContentEncoding();
      if (encoding != null) {
        for (        HeaderElement element : encoding.getElements()) {
          if (element.getName().equalsIgnoreCase(ENCODING_GZIP)) {
            response.setEntity(new InflatingEntity(response.getEntity()));
            break;
          }
        }
      }
    }
  }
);
  return client;
}
 

Example 15

From project be.norio.twunch.android, under directory /src/be/norio/twunch/android/service/.

Source file: SyncService.java

  15 
vote

/** 
 * Generate and return a  {@link HttpClient} configured for general use,including setting an application-specific user-agent string.
 */
public static HttpClient getHttpClient(Context context){
  final HttpParams params=new BasicHttpParams();
  HttpConnectionParams.setConnectionTimeout(params,20 * SECOND_IN_MILLIS);
  HttpConnectionParams.setSoTimeout(params,20 * SECOND_IN_MILLIS);
  HttpConnectionParams.setSocketBufferSize(params,8192);
  HttpProtocolParams.setUserAgent(params,buildUserAgent(context));
  final DefaultHttpClient client=new DefaultHttpClient(params);
  client.addRequestInterceptor(new HttpRequestInterceptor(){
    public void process(    HttpRequest request,    HttpContext context){
      if (!request.containsHeader(HEADER_ACCEPT_ENCODING)) {
        request.addHeader(HEADER_ACCEPT_ENCODING,ENCODING_GZIP);
      }
    }
  }
);
  client.addResponseInterceptor(new HttpResponseInterceptor(){
    public void process(    HttpResponse response,    HttpContext context){
      final HttpEntity entity=response.getEntity();
      final Header encoding=entity.getContentEncoding();
      if (encoding != null) {
        for (        HeaderElement element : encoding.getElements()) {
          if (element.getName().equalsIgnoreCase(ENCODING_GZIP)) {
            response.setEntity(new InflatingEntity(response.getEntity()));
            break;
          }
        }
      }
    }
  }
);
  return client;
}
 

Example 16

From project BF3-Battlelog, under directory /src/com/ninetwozero/battlelog/http/.

Source file: RequestHandler.java

  15 
vote

public void process(HttpResponse response,HttpContext context){
  final HttpEntity entity=response.getEntity();
  final Header encoding=entity.getContentEncoding();
  if (encoding != null) {
    for (    HeaderElement element : encoding.getElements()) {
      if (element.getName().equalsIgnoreCase(ENCODING_GZIP)) {
        response.setEntity(new InflatingEntity(response.getEntity()));
        break;
      }
    }
  }
}
 

Example 17

From project build-info, under directory /build-info-client/src/main/java/org/jfrog/build/client/.

Source file: PreemptiveHttpClient.java

  15 
vote

public void process(final HttpRequest request,final HttpContext context) throws HttpException, IOException {
  AuthState authState=(AuthState)context.getAttribute(ClientContext.TARGET_AUTH_STATE);
  if (authState.getAuthScheme() == null) {
    AuthScheme authScheme=(AuthScheme)context.getAttribute("preemptive-auth");
    CredentialsProvider credsProvider=(CredentialsProvider)context.getAttribute(ClientContext.CREDS_PROVIDER);
    HttpHost targetHost=(HttpHost)context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
    if (authScheme != null) {
      Credentials creds=credsProvider.getCredentials(new AuthScope(targetHost.getHostName(),targetHost.getPort()));
      if (creds == null) {
        throw new HttpException("No credentials for preemptive authentication");
      }
      authState.setAuthScheme(authScheme);
      authState.setCredentials(creds);
    }
  }
}
 

Example 18

From project CalendarPortlet, under directory /src/main/java/org/jasig/portlet/calendar/adapter/exchange/.

Source file: NtlmAuthHttpClient.java

  15 
vote

@Override public void process(HttpRequest request,HttpContext context) throws HttpException, IOException {
  if (request instanceof HttpEntityEnclosingRequest) {
    if (request.containsHeader(HTTP.TRANSFER_ENCODING)) {
      request.removeHeaders(HTTP.TRANSFER_ENCODING);
    }
    if (request.containsHeader(HTTP.CONTENT_LEN)) {
      request.removeHeaders(HTTP.CONTENT_LEN);
    }
  }
}
 

Example 19

From project caustic, under directory /implementation/browser-apache/src/net/caustic/http/.

Source file: ApacheBrowser.java

  15 
vote

@Override public boolean isRedirectRequested(HttpResponse response,HttpContext context){
  if (response.getStatusLine().getStatusCode() == 302) {
    return true;
  }
 else {
    return super.isRedirectRequested(response,context);
  }
}
 

Example 20

From project CityBikes, under directory /src/net/homelinux/penecoptero/android/citybikes/app/.

Source file: RESTHelper.java

  15 
vote

private static DefaultHttpClient setCredentials(DefaultHttpClient httpclient,String url,String username,String password) throws HttpException, IOException {
  HttpHost targetHost=new HttpHost(url);
  final UsernamePasswordCredentials access=new UsernamePasswordCredentials(username,password);
  httpclient.getCredentialsProvider().setCredentials(new AuthScope(targetHost.getHostName(),targetHost.getPort()),access);
  httpclient.addRequestInterceptor(new HttpRequestInterceptor(){
    @Override public void process(    HttpRequest request,    HttpContext context) throws HttpException, IOException {
      AuthState authState=(AuthState)context.getAttribute(ClientContext.TARGET_AUTH_STATE);
      if (authState.getAuthScheme() == null) {
        authState.setAuthScheme(new BasicScheme());
        authState.setCredentials(access);
      }
    }
  }
,0);
  return httpclient;
}
 

Example 21

From project cloudify, under directory /rest-client/src/main/java/org/cloudifysource/restclient/.

Source file: GSRestClient.java

  15 
vote

/** 
 * Ctor.
 * @param username Username for the HTTP client, optional.
 * @param password Password for the HTTP client, optional.
 * @param url      URL to the rest service.
 * @param version  cloudify api version of the client 
 * @throws RestException Reporting failure to create a SSL HTTP client.
 */
public GSRestClient(final String username,final String password,final URL url,final String version) throws RestException {
  this.url=url;
  this.urlStr=createUrlStr();
  if (isSSL()) {
    httpClient=getSSLHttpClient();
  }
 else {
    httpClient=new DefaultHttpClient();
  }
  httpClient.addRequestInterceptor(new HttpRequestInterceptor(){
    @Override public void process(    HttpRequest request,    HttpContext context) throws HttpException, IOException {
      request.addHeader(CloudifyConstants.REST_API_VERSION_HEADER,version);
    }
  }
);
  if (StringUtils.notEmpty(username) && StringUtils.notEmpty(password)) {
    httpClient.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY),new UsernamePasswordCredentials(username,password));
  }
}
 

Example 22

From project conference-mobile-app, under directory /android-app/src/com/google/android/apps/iosched/service/.

Source file: SyncService.java

  15 
vote

/** 
 * Generate and return a  {@link HttpClient} configured for general use,including setting an application-specific user-agent string.
 */
public static HttpClient getHttpClient(Context context){
  final HttpParams params=new BasicHttpParams();
  HttpConnectionParams.setConnectionTimeout(params,20 * SECOND_IN_MILLIS);
  HttpConnectionParams.setSoTimeout(params,20 * SECOND_IN_MILLIS);
  HttpConnectionParams.setSocketBufferSize(params,8192);
  HttpProtocolParams.setUserAgent(params,buildUserAgent(context));
  final DefaultHttpClient client=new DefaultHttpClient(params);
  client.addRequestInterceptor(new HttpRequestInterceptor(){
    public void process(    HttpRequest request,    HttpContext context){
      if (!request.containsHeader(HEADER_ACCEPT_ENCODING)) {
        request.addHeader(HEADER_ACCEPT_ENCODING,ENCODING_GZIP);
      }
    }
  }
);
  client.addResponseInterceptor(new HttpResponseInterceptor(){
    public void process(    HttpResponse response,    HttpContext context){
      final HttpEntity entity=response.getEntity();
      final Header encoding=entity.getContentEncoding();
      if (encoding != null) {
        for (        HeaderElement element : encoding.getElements()) {
          if (element.getName().equalsIgnoreCase(ENCODING_GZIP)) {
            response.setEntity(new InflatingEntity(response.getEntity()));
            break;
          }
        }
      }
    }
  }
);
  return client;
}
 

Example 23

From project couchdb-lucene, under directory /src/main/java/com/github/rnewson/couchdb/lucene/.

Source file: HttpClientFactory.java

  15 
vote

public void process(final HttpRequest request,final HttpContext context) throws HttpException, IOException {
  final AuthState authState=(AuthState)context.getAttribute(ClientContext.TARGET_AUTH_STATE);
  final CredentialsProvider credsProvider=(CredentialsProvider)context.getAttribute(ClientContext.CREDS_PROVIDER);
  final HttpHost targetHost=(HttpHost)context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
  if (authState.getAuthScheme() == null) {
    AuthScope authScope=new AuthScope(targetHost.getHostName(),targetHost.getPort());
    Credentials creds=credsProvider.getCredentials(authScope);
    if (creds != null) {
      authState.setAuthScheme(new BasicScheme());
      authState.setCredentials(creds);
    }
  }
}
 

Example 24

From project dccsched, under directory /src/com/underhilllabs/dccsched/service/.

Source file: SyncService.java

  15 
vote

/** 
 * Generate and return a  {@link HttpClient} configured for general use,including setting an application-specific user-agent string.
 */
public static HttpClient getHttpClient(Context context){
  final HttpParams params=new BasicHttpParams();
  HttpConnectionParams.setConnectionTimeout(params,20 * SECOND_IN_MILLIS);
  HttpConnectionParams.setSoTimeout(params,20 * SECOND_IN_MILLIS);
  HttpConnectionParams.setSocketBufferSize(params,8192);
  HttpProtocolParams.setUserAgent(params,buildUserAgent(context));
  final DefaultHttpClient client=new DefaultHttpClient(params);
  client.addRequestInterceptor(new HttpRequestInterceptor(){
    public void process(    HttpRequest request,    HttpContext context){
      if (!request.containsHeader(HEADER_ACCEPT_ENCODING)) {
        request.addHeader(HEADER_ACCEPT_ENCODING,ENCODING_GZIP);
      }
    }
  }
);
  client.addResponseInterceptor(new HttpResponseInterceptor(){
    public void process(    HttpResponse response,    HttpContext context){
      final HttpEntity entity=response.getEntity();
      final Header encoding=entity.getContentEncoding();
      if (encoding != null) {
        for (        HeaderElement element : encoding.getElements()) {
          if (element.getName().equalsIgnoreCase(ENCODING_GZIP)) {
            response.setEntity(new InflatingEntity(response.getEntity()));
            break;
          }
        }
      }
    }
  }
);
  return client;
}
 

Example 25

From project dcnyc10-android, under directory /android/src/com/lullabot/android/apps/iosched/service/.

Source file: SyncService.java

  15 
vote

/** 
 * Generate and return a  {@link HttpClient} configured for general use,including setting an application-specific user-agent string.
 */
public static HttpClient getHttpClient(Context context){
  final HttpParams params=new BasicHttpParams();
  HttpConnectionParams.setConnectionTimeout(params,20 * SECOND_IN_MILLIS);
  HttpConnectionParams.setSoTimeout(params,20 * SECOND_IN_MILLIS);
  HttpConnectionParams.setSocketBufferSize(params,8192);
  HttpProtocolParams.setUserAgent(params,buildUserAgent(context));
  final DefaultHttpClient client=new DefaultHttpClient(params);
  client.addRequestInterceptor(new HttpRequestInterceptor(){
    public void process(    HttpRequest request,    HttpContext context){
      if (!request.containsHeader(HEADER_ACCEPT_ENCODING)) {
        request.addHeader(HEADER_ACCEPT_ENCODING,ENCODING_GZIP);
      }
    }
  }
);
  client.addResponseInterceptor(new HttpResponseInterceptor(){
    public void process(    HttpResponse response,    HttpContext context){
      final HttpEntity entity=response.getEntity();
      final Header encoding=entity.getContentEncoding();
      if (encoding != null) {
        for (        HeaderElement element : encoding.getElements()) {
          if (element.getName().equalsIgnoreCase(ENCODING_GZIP)) {
            response.setEntity(new InflatingEntity(response.getEntity()));
            break;
          }
        }
      }
    }
  }
);
  return client;
}
 

Example 26

From project DeliciousDroid, under directory /src/com/deliciousdroid/client/.

Source file: PreemptiveAuthInterceptor.java

  15 
vote

public void process(final HttpRequest request,final HttpContext context) throws HttpException, IOException {
  AuthState authState=(AuthState)context.getAttribute(ClientContext.TARGET_AUTH_STATE);
  CredentialsProvider credsProvider=(CredentialsProvider)context.getAttribute(ClientContext.CREDS_PROVIDER);
  HttpHost targetHost=(HttpHost)context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
  if (authState.getAuthScheme() == null) {
    AuthScope authScope=new AuthScope(targetHost.getHostName(),targetHost.getPort());
    Credentials creds=credsProvider.getCredentials(authScope);
    if (creds != null) {
      authState.setAuthScheme(new BasicScheme());
      authState.setCredentials(creds);
    }
  }
}
 

Example 27

From project devoxx-france-android-in-fine, under directory /src/com/infine/android/devoxx/service/.

Source file: RestService.java

  15 
vote

/** 
 * Generate and return a  {@link HttpClient} configured for general use,including setting an application-specific user-agent string.
 */
public static HttpClient getHttpClient(Context context){
  final HttpParams params=new BasicHttpParams();
  HttpConnectionParams.setConnectionTimeout(params,20 * 1000);
  HttpConnectionParams.setSoTimeout(params,20 * 1000);
  HttpConnectionParams.setSocketBufferSize(params,8192);
  HttpProtocolParams.setUserAgent(params,buildUserAgent(context));
  final DefaultHttpClient client=new DefaultHttpClient(params);
  client.addRequestInterceptor(new HttpRequestInterceptor(){
    public void process(    HttpRequest request,    HttpContext context){
      if (!request.containsHeader(HEADER_ACCEPT_ENCODING)) {
        request.addHeader(HEADER_ACCEPT_ENCODING,ENCODING_GZIP);
      }
    }
  }
);
  client.addResponseInterceptor(new HttpResponseInterceptor(){
    public void process(    HttpResponse response,    HttpContext context){
      final HttpEntity entity=response.getEntity();
      final Header encoding=entity.getContentEncoding();
      if (encoding != null) {
        for (        HeaderElement element : encoding.getElements()) {
          if (element.getName().equalsIgnoreCase(ENCODING_GZIP)) {
            response.setEntity(new InflatingEntity(response.getEntity()));
            break;
          }
        }
      }
    }
  }
);
  return client;
}
 

Example 28

From project DiscogsForAndroid, under directory /src/com/discogs/services/.

Source file: NetworkHelper.java

  15 
vote

private void initHTTPClient(){
  SchemeRegistry schemeRegistry=new SchemeRegistry();
  schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
  schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443));
  HttpParams params=new BasicHttpParams();
  HttpProtocolParams.setContentCharset(params,"utf-8");
  params.setBooleanParameter("http.protocol.expect-continue",false);
  HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1);
  HttpProtocolParams.setContentCharset(params,HTTP.DEFAULT_CONTENT_CHARSET);
  HttpProtocolParams.setUseExpectContinue(params,true);
  ThreadSafeClientConnManager connectionManager=new ThreadSafeClientConnManager(params,schemeRegistry);
  httpClient=new DefaultHttpClient(connectionManager,params);
  httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(3,false));
  httpClient.addRequestInterceptor(new HttpRequestInterceptor(){
    public void process(    final HttpRequest request,    final HttpContext context) throws HttpException, IOException {
      if (!request.containsHeader("Accept-Encoding")) {
        request.addHeader("Accept-Encoding","gzip");
      }
    }
  }
);
  httpClient.addResponseInterceptor(new HttpResponseInterceptor(){
    public void process(    final HttpResponse response,    final HttpContext context) throws HttpException, IOException {
      HttpEntity entity=response.getEntity();
      if (entity != null) {
        Header ceheader=entity.getContentEncoding();
        if (ceheader != null) {
          HeaderElement[] codecs=ceheader.getElements();
          for (int i=0; i < codecs.length; i++) {
            if (codecs[i].getName().equalsIgnoreCase("gzip")) {
              response.setEntity(new GzipDecompressingEntity(response.getEntity()));
              return;
            }
          }
        }
      }
    }
  }
);
}
 

Example 29

From project EasySOA, under directory /easysoa-proxy/easysoa-proxy-core/easysoa-proxy-core-httpdiscoveryproxy/src/main/java/org/easysoa/proxy/.

Source file: HttpRetryHandler.java

  15 
vote

public boolean retryRequest(IOException exception,int executionCount,HttpContext context){
  if (executionCount >= maxRetryNumber) {
    return false;
  }
  if (exception instanceof NoHttpResponseException) {
    return true;
  }
  if (exception instanceof SSLHandshakeException) {
    return false;
  }
  HttpRequest request=(HttpRequest)context.getAttribute(ExecutionContext.HTTP_REQUEST);
  boolean idempotent=!(request instanceof HttpEntityEnclosingRequest);
  if (idempotent) {
    return true;
  }
  return false;
}
 

Example 30

From project eucalyptus, under directory /clc/modules/axis2-transport/src/org/apache/axis2/transport/http/server/.

Source file: AxisHttpResponseImpl.java

  15 
vote

public AxisHttpResponseImpl(final AxisHttpConnection conn,final HttpResponse response,final HttpProcessor httpproc,final HttpContext context){
  super();
  if (response == null) {
    throw new IllegalArgumentException("HTTP response may not be null");
  }
  if (conn == null) {
    throw new IllegalArgumentException("HTTP connection may not be null");
  }
  if (httpproc == null) {
    throw new IllegalArgumentException("HTTP processor may not be null");
  }
  if (context == null) {
    throw new IllegalArgumentException("HTTP context may not be null");
  }
  this.response=response;
  this.conn=conn;
  this.httpproc=httpproc;
  this.context=context;
}
 

Example 31

From project fanfoudroid, under directory /src/com/ch_linghu/fanfoudroid/http/.

Source file: HttpClient.java

  15 
vote

@Override public void process(final HttpRequest request,final HttpContext context){
  AuthState authState=(AuthState)context.getAttribute(ClientContext.TARGET_AUTH_STATE);
  CredentialsProvider credsProvider=(CredentialsProvider)context.getAttribute(ClientContext.CREDS_PROVIDER);
  HttpHost targetHost=(HttpHost)context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
  if (authState.getAuthScheme() == null) {
    AuthScope authScope=new AuthScope(targetHost.getHostName(),targetHost.getPort());
    Credentials creds=credsProvider.getCredentials(authScope);
    if (creds != null) {
      authState.setAuthScheme(new BasicScheme());
      authState.setCredentials(creds);
    }
  }
}
 

Example 32

From project gddsched2, under directory /trunk/android/src/com/google/android/apps/iosched2/service/.

Source file: SyncService.java

  15 
vote

/** 
 * Generate and return a  {@link HttpClient} configured for general use,including setting an application-specific user-agent string.
 */
public static HttpClient getHttpClient(Context context){
  final HttpParams params=new BasicHttpParams();
  HttpConnectionParams.setConnectionTimeout(params,20 * SECOND_IN_MILLIS);
  HttpConnectionParams.setSoTimeout(params,20 * SECOND_IN_MILLIS);
  HttpConnectionParams.setSocketBufferSize(params,8192);
  HttpProtocolParams.setUserAgent(params,buildUserAgent(context));
  final DefaultHttpClient client=new DefaultHttpClient(params);
  client.addRequestInterceptor(new HttpRequestInterceptor(){
    public void process(    HttpRequest request,    HttpContext context){
      if (!request.containsHeader(HEADER_ACCEPT_ENCODING)) {
        request.addHeader(HEADER_ACCEPT_ENCODING,ENCODING_GZIP);
      }
    }
  }
);
  client.addResponseInterceptor(new HttpResponseInterceptor(){
    public void process(    HttpResponse response,    HttpContext context){
      final HttpEntity entity=response.getEntity();
      final Header encoding=entity.getContentEncoding();
      if (encoding != null) {
        for (        HeaderElement element : encoding.getElements()) {
          if (element.getName().equalsIgnoreCase(ENCODING_GZIP)) {
            response.setEntity(new InflatingEntity(response.getEntity()));
            break;
          }
        }
      }
    }
  }
);
  return client;
}
 

Example 33

From project gnip4j, under directory /http/src/main/java/com/zaubersoftware/gnip4j/http/.

Source file: GZipInterceptor.java

  15 
vote

/** 
 * @see HttpResponseInterceptor#process(HttpResponse,HttpContext) 
 */
public final void process(final HttpResponse response,final HttpContext context) throws HttpException, IOException {
  final HttpEntity entity=response.getEntity();
  final Header ceheader=entity.getContentEncoding();
  if (ceheader != null) {
    final HeaderElement[] codecs=ceheader.getElements();
    for (int i=0; i < codecs.length; i++) {
      if (codecs[i].getName().equalsIgnoreCase("gzip")) {
        response.setEntity(new GzipDecompressingEntity(response.getEntity()));
        return;
      }
    }
  }
}
 

Example 34

From project httpbuilder, under directory /src/main/java/groovyx/net/http/.

Source file: AuthConfig.java

  15 
vote

public void process(HttpRequest request,HttpContext ctx) throws HttpException, IOException {
  try {
    HttpHost host=(HttpHost)ctx.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
    final URI requestURI=new URI(host.toURI()).resolve(request.getRequestLine().getUri());
    oauth.signpost.http.HttpRequest oAuthRequest=new OAuthRequestAdapter(request,requestURI);
    this.oauth.sign(oAuthRequest);
  }
 catch (  URISyntaxException ex) {
    throw new HttpException("Error rebuilding request URI",ex);
  }
catch (  OAuthException e) {
    throw new HttpException("OAuth signing error",e);
  }
}