Example usage for org.apache.http.protocol SyncBasicHttpContext SyncBasicHttpContext

List of usage examples for org.apache.http.protocol SyncBasicHttpContext SyncBasicHttpContext

Introduction

In this page you can find the example usage for org.apache.http.protocol SyncBasicHttpContext SyncBasicHttpContext.

Prototype

public SyncBasicHttpContext(HttpContext httpContext) 

Source Link

Usage

From source file:org.eclipse.lyo.testsuite.oslcv2.trs.TRSTest.java

@BeforeClass
public static void setupOnce() {
    try {/*w  w  w.j a  va2s  .c  om*/
        prop = getConfigPropertiesInstance();

        String trsEndpoint = prop.getProperty("configTrsEndpoint");
        String acceptType = prop.getProperty("acceptType");

        httpClient = new EasySSLClient().getClient();

        httpContext = new DefaultedHttpContext(new BasicHttpContext(), new SyncBasicHttpContext(null));

        trsResource = getResource(trsEndpoint, httpClient, httpContext, acceptType);
    } catch (FileNotFoundException e) {
        terminateTest(Messages.getServerString("tests.general.config.properties.missing"), e);
    } catch (InterruptedException e) {
        terminateTest(null, e);
    } catch (IOException e) {
        terminateTest(Messages.getServerString("tests.general.config.properties.unreadable"), e);
    } catch (FetchException e) {
        terminateTest(Messages.getServerString("tests.general.trs.fetch.error"), e);
    } catch (Exception e) {
        terminateTest(null, e);
    }
}

From source file:org.eclipse.lyo.testsuite.oslcv2.trs.BaseTest.java

@BeforeClass
public static void setupOnce() {
    try {//from  ww  w .j  a  v a  2  s.  c  om
        prop = getConfigPropertiesInstance();

        //Read the base end point from the TRS Resource
        String trsEndpoint = prop.getProperty("configTrsEndpoint");
        String acceptType = prop.getProperty("acceptType");

        httpClient = new EasySSLClient().getClient();

        httpContext = new DefaultedHttpContext(new BasicHttpContext(), new SyncBasicHttpContext(null));
        trsResource = getResource(trsEndpoint, httpClient, httpContext, acceptType);
        String trsEndpointBase = trsResource.getProperty(ITRSVocabulary.BASE_PROPERTY).getObject().toString();
        trsBaseResource = getResource(trsEndpointBase, httpClient, httpContext, acceptType);
    } catch (FileNotFoundException e) {
        terminateTest(Messages.getServerString("tests.general.config.properties.missing"), e);
    } catch (IOException e) {
        terminateTest(Messages.getServerString("tests.general.config.properties.unreadable"), e);
    } catch (FetchException e) {
        terminateTest(Messages.getServerString("tests.general.trs.fetch.error"), e);
    } catch (Exception e) {
        terminateTest(null, e);
    }
}

From source file:org.eclipse.lyo.testsuite.oslcv2.trs.ChangeLogTest.java

@BeforeClass
public static void setupOnce() {
    try {//www . ja  v  a 2  s  . c om
        prop = getConfigPropertiesInstance();

        String trsEndpoint = prop.getProperty("configTrsEndpoint");
        String acceptType = prop.getProperty("acceptType");

        httpClient = new EasySSLClient().getClient();

        httpContext = new DefaultedHttpContext(new BasicHttpContext(), new SyncBasicHttpContext(null));

        trsResource = getResource(trsEndpoint, httpClient, httpContext, acceptType);
    } catch (FileNotFoundException e) {
        terminateTest(Messages.getServerString("tests.general.config.properties.missing"), e);
    } catch (IOException e) {
        terminateTest(Messages.getServerString("tests.general.config.properties.unreadable"), e);
    } catch (FetchException e) {
        terminateTest(Messages.getServerString("tests.general.trs.fetch.error"), e);
    } catch (Exception e) {
        terminateTest(null, e);
    }
}

From source file:org.eclipse.lyo.rio.trs.tests.ChangeLogCreationTest.java

@BeforeClass
public static void setupOnce() {
    try {/*  ww  w. j ava2s  .c  o  m*/
        prop = getConfigPropertiesInstance();
        String resCreationFactoryUri = prop.getProperty("configResourceCreationFactoryUri");
        String resCreationContent = (prop.getProperty("configResContentFile").equals("")
                ? prop.getProperty("configResContent")
                : readFileAsString(new File(RESOURCES + FileSep + prop.getProperty("configResContentFile"))));
        String resContentType = prop.getProperty("configContentType");
        String trsEndpoint = prop.getProperty("configTrsEndpoint");
        String acceptType = prop.getProperty("acceptType");

        httpClient = new EasySSLClient().getClient();
        httpContext = new DefaultedHttpContext(new BasicHttpContext(), new SyncBasicHttpContext(null));

        //Create a resource using the resource creation factory.. oslc:CreationFactory
        createdResourceUrl = SendUtil.createResource(resCreationFactoryUri, httpClient, httpContext,
                resContentType, resCreationContent);

        trsResource = getResource(trsEndpoint, httpClient, httpContext, acceptType);
    } catch (FileNotFoundException e) {
        terminateTest(Messages.getServerString("tests.general.config.properties.missing"), e);
    } catch (IOException e) {
        terminateTest(Messages.getServerString("tests.general.config.properties.unreadable"), e);
    } catch (FetchException e) {
        terminateTest(Messages.getServerString("tests.general.trs.fetch.error"), e);
    } catch (SendException e) {
        terminateTest(Messages.getServerString("tests.general.trs.send.error"), e);
    } catch (Exception e) {
        terminateTest(null, e);
    }
}

From source file:org.eclipse.lyo.rio.trs.tests.ChangeLogUpdationTest.java

@BeforeClass
public static void setupOnce() {
    try {//w w  w  . j  a  v a  2  s . co m
        prop = getConfigPropertiesInstance();
        String resCreationFactoryUri = prop.getProperty("configResourceCreationFactoryUri");
        String resCreationContent = (prop.getProperty("configResContentFile").equals("")
                ? prop.getProperty("configResContent")
                : readFileAsString(new File(RESOURCES + FileSep + prop.getProperty("configResContentFile"))));
        String resContentType = prop.getProperty("configContentType");
        String resUpdateContentType = prop.getProperty("configUpdateContentType");
        String trsEndpoint = prop.getProperty("configTrsEndpoint");
        String acceptType = prop.getProperty("acceptType");

        httpClient = new EasySSLClient().getClient();
        httpContext = new DefaultedHttpContext(new BasicHttpContext(), new SyncBasicHttpContext(null));

        //Create a resource using the resource creation factory.. oslc:CreationFactory
        createdResourceUrl = SendUtil.createResource(resCreationFactoryUri, httpClient, httpContext,
                resContentType, resCreationContent);

        //Now Update the resource using a HTTP PUT call
        String updateContent = readFileAsString(
                new File(RESOURCES + FileSep + prop.getProperty("configResUpdateFile")));

        //Replace the Update content with the correct resource identifier of the resource created above
        updateContent = formatUpdateContent(updateContent, resUpdateContentType);

        SendUtil.updateResource(createdResourceUrl, httpClient, httpContext, resUpdateContentType,
                updateContent);

        trsResource = getResource(trsEndpoint, httpClient, httpContext, acceptType);

    } catch (FileNotFoundException e) {
        terminateTest(Messages.getServerString("tests.general.config.properties.missing"), e);
    } catch (IOException e) {
        terminateTest(Messages.getServerString("tests.general.config.properties.unreadable"), e);
    } catch (FetchException e) {
        terminateTest(Messages.getServerString("tests.general.trs.fetch.error"), e);
    } catch (SendException e) {
        terminateTest(Messages.getServerString("tests.general.trs.send.error"), e);
    } catch (Exception e) {
        terminateTest(null, e);
    }
}

From source file:me.xiaopan.android.gohttp.HttpClientManager.java

public HttpClientManager(SchemeRegistry schemeRegistry) {
    BasicHttpParams httpParams = new BasicHttpParams();
    HttpConnectionParams.setTcpNoDelay(httpParams, true); //?TCP
    HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1); //Http??
    HttpProtocolParams.setUserAgent(httpParams, DEFAULT_USER_AGENT); //?
    httpContext = new SyncBasicHttpContext(new BasicHttpContext()); //?Http
    httpClient = new DefaultHttpClient(new ThreadSafeClientConnManager(httpParams, schemeRegistry), httpParams);
    httpClient.addRequestInterceptor(new GzipProcessRequestInterceptor());
    httpClient.addRequestInterceptor(new AddRequestHeaderRequestInterceptor(getHeaderMap()));
    httpClient.addResponseInterceptor(new GzipProcessResponseInterceptor());
    httpClient//from  w  ww. j a v  a2 s.  co  m
            .setHttpRequestRetryHandler(new RetryHandler(DEFAULT_MAX_RETRIES, DEFAULT_RETRY_SLEEP_TIME_MILLIS));
    clientHeaderMap = new HashMap<String, String>();
    setTimeout(DEFAULT_TIMEOUT);
    setMaxConnections(DEFAULT_MAX_CONNECTIONS);
    setSocketBufferSize(DEFAULT_SOCKET_BUFFER_SIZE);
}

From source file:com.louding.frame.http.download.SimpleDownloader.java

/**
 * ?httpClient/*from   w w  w.java2s .c  o m*/
 */
private void initHttpClient() {
    BasicHttpParams httpParams = new BasicHttpParams();

    ConnManagerParams.setTimeout(httpParams, config.timeOut);
    ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(config.maxConnections));
    ConnManagerParams.setMaxTotalConnections(httpParams, config.maxConnections);

    HttpConnectionParams.setSoTimeout(httpParams, config.timeOut);
    HttpConnectionParams.setConnectionTimeout(httpParams, config.timeOut);
    HttpConnectionParams.setTcpNoDelay(httpParams, true);
    HttpConnectionParams.setSocketBufferSize(httpParams, config.socketBuffer);

    HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setUserAgent(httpParams, "KJLibrary");

    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
    ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(httpParams, schemeRegistry);

    context = new SyncBasicHttpContext(new BasicHttpContext());
    client = new DefaultHttpClient(cm, httpParams);
    client.addRequestInterceptor(new HttpRequestInterceptor() {
        @Override
        public void process(HttpRequest request, HttpContext context) {
            if (!request.containsHeader("Accept-Encoding")) {
                request.addHeader("Accept-Encoding", "gzip");
            }

            for (Entry<String, String> entry : config.httpHeader.entrySet()) {
                request.addHeader(entry.getKey(), entry.getValue());
            }
        }
    });

    client.addResponseInterceptor(new HttpResponseInterceptor() {
        @Override
        public void process(HttpResponse response, HttpContext context) {
            final HttpEntity entity = response.getEntity();
            if (entity == null) {
                return;
            }
            final Header encoding = entity.getContentEncoding();
            if (encoding != null) {
                for (HeaderElement element : encoding.getElements()) {
                    if (element.getName().equalsIgnoreCase("gzip")) {
                        response.setEntity(new InflatingEntity(response.getEntity()));
                        break;
                    }
                }
            }
        }
    });
    client.setHttpRequestRetryHandler(new RetryHandler(config.timeOut));
}

From source file:cn.com.zzwfang.http.HttpClient.java

/**
 * Cookie//  w w w .j  a v  a2s . c om
 */
//   private PersistentCookieStore cookieStore;

public HttpClient(Context context) {
    if (httpClient != null) {
        return;
    }
    //      Log.i("--->", "HttpClient ?httpClient-------------");
    BasicHttpParams httpParams = new BasicHttpParams();
    ConnManagerParams.setTimeout(httpParams, socketTimeout);
    ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(maxConnections));
    ConnManagerParams.setMaxTotalConnections(httpParams, totalConnections);

    HttpConnectionParams.setConnectionTimeout(httpParams, socketTimeout);
    HttpConnectionParams.setSoTimeout(httpParams, socketTimeout);
    HttpConnectionParams.setTcpNoDelay(httpParams, true);
    HttpConnectionParams.setSocketBufferSize(httpParams, DEFAULT_SOCKET_BUFFER_SIZE);

    HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setUserAgent(httpParams, userAgent);

    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
    ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(httpParams, schemeRegistry);

    httpParams.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BROWSER_COMPATIBILITY);

    httpContext = new SyncBasicHttpContext(new BasicHttpContext());
    httpClient = new DefaultHttpClient(cm, httpParams);
    httpClient.setHttpRequestRetryHandler(new InnerRetryHandler(DEFAULT_MAX_RETRIES));
    //      cookieStore = new PersistentCookieStore(context);
    //      httpContext.setAttribute("http.cookie-store", cookieStore);
    //      httpClient.setCookieStore(cookieStore);

}

From source file:com.loopj.android.http.RdHttpClient.java

/**
 * Creates a new AsyncHttpClient./*w ww.  j  a va  2 s  .co m*/
 */
public RdHttpClient() {
    BasicHttpParams httpParams = new BasicHttpParams();

    ConnManagerParams.setTimeout(httpParams, socketTimeout);
    ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(maxConnections));
    ConnManagerParams.setMaxTotalConnections(httpParams, DEFAULT_MAX_CONNECTIONS);

    HttpConnectionParams.setSoTimeout(httpParams, socketTimeout);
    HttpConnectionParams.setConnectionTimeout(httpParams, socketTimeout);
    HttpConnectionParams.setTcpNoDelay(httpParams, true);
    HttpConnectionParams.setSocketBufferSize(httpParams, DEFAULT_SOCKET_BUFFER_SIZE);

    HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setUserAgent(httpParams,
            String.format("android-async-http/%s (http://loopj.com/android-async-http)", VERSION));

    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
    ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(httpParams, schemeRegistry);

    httpContext = new SyncBasicHttpContext(new BasicHttpContext());
    httpClient = new DefaultHttpClient(cm, httpParams);
    httpClient.addRequestInterceptor(new HttpRequestInterceptor() {
        @Override
        public void process(HttpRequest request, HttpContext context) {
            if (!request.containsHeader(HEADER_ACCEPT_ENCODING)) {
                request.addHeader(HEADER_ACCEPT_ENCODING, ENCODING_GZIP);
            }
            for (String header : clientHeaderMap.keySet()) {
                request.addHeader(header, clientHeaderMap.get(header));
            }
        }
    });
    httpClient.clearResponseInterceptors();
    httpClient.addResponseInterceptor(new HttpResponseInterceptor() {
        @Override
        public void process(HttpResponse response, HttpContext context) {
            final HttpEntity entity = response.getEntity();
            if (entity == null) {
                return;
            }
            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;
                    }
                }
            }
        }
    });

    httpClient.setHttpRequestRetryHandler(new RetryHandler(DEFAULT_MAX_RETRIES));

    clientHeaderMap = new HashMap<String, String>();
}

From source file:com.jana.android.net.AbstractHttpConnection.java

private void setupHttp() {

    httpContext = new SyncBasicHttpContext(new BasicHttpContext());

    sHttpClient/*from www .  jav  a  2  s . c  om*/
            .setHttpRequestRetryHandler(new RetryHandler(DEFAULT_MAX_RETRIES, DEFAULT_RETRY_SLEEP_TIME_MILLIS));
}