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

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

Introduction

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

Prototype

public DefaultedHttpContext(HttpContext httpContext, HttpContext httpContext2) 

Source Link

Usage

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

@BeforeClass
public static void setupOnce() {
    try {//from   w w w  .  j  a va  2  s.c o m
        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   w ww .j  av  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 {//from   w  ww. j a 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 {/*from ww w .  j a v a  2s  .  c  om*/
        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 {/*from   w w w  .  jav a 2 s.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 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:org.vietspider.net.client.impl.AbstractHttpClient.java

public final HttpResponse execute(HttpHost target, HttpRequest request, HttpContext context)
        throws IOException, ClientProtocolException {

    if (request == null) {
        throw new IllegalArgumentException("Request must not be null.");
    }//from   w w  w . ja v a 2 s  .  c o m
    // a null target may be acceptable, this depends on the route planner
    // a null context is acceptable, default context created below

    HttpContext execContext = null;
    RequestDirector director = null;

    // Initialize the request execution context making copies of 
    // all shared objects that are potentially threading unsafe.
    synchronized (this) {

        HttpContext defaultContext = createHttpContext();
        if (context == null) {
            execContext = defaultContext;
        } else {
            execContext = new DefaultedHttpContext(context, defaultContext);
        }
        // Create a director for this request
        director = createClientRequestDirector(getRequestExecutor(), getConnectionManager(),
                getConnectionReuseStrategy(), getConnectionKeepAliveStrategy(), getRoutePlanner(),
                getHttpProcessor().copy(), getHttpRequestRetryHandler(), getRedirectHandler(),
                getTargetAuthenticationHandler(), getProxyAuthenticationHandler(), getUserTokenHandler(),
                determineParams(request));
    }

    try {
        return director.execute(target, request, execContext);
    } catch (HttpException httpException) {
        throw new ClientProtocolException(httpException);
    }
}

From source file:org.apache.http.impl.client.AbstractHttpClient.java

@Override
protected final CloseableHttpResponse doExecute(final HttpHost target, final HttpRequest request,
        final HttpContext context) throws IOException, ClientProtocolException {

    Args.notNull(request, "HTTP request");
    // a null target may be acceptable, this depends on the route planner
    // a null context is acceptable, default context created below

    HttpContext execContext = null;
    RequestDirector director = null;//from w w  w .ja  v  a  2  s  .com
    HttpRoutePlanner routePlanner = null;
    ConnectionBackoffStrategy connectionBackoffStrategy = null;
    BackoffManager backoffManager = null;

    // Initialize the request execution context making copies of
    // all shared objects that are potentially threading unsafe.
    synchronized (this) {

        final HttpContext defaultContext = createHttpContext();
        if (context == null) {
            execContext = defaultContext;
        } else {
            execContext = new DefaultedHttpContext(context, defaultContext);
        }
        final HttpParams params = determineParams(request);
        final RequestConfig config = HttpClientParamConfig.getRequestConfig(params);
        execContext.setAttribute(ClientContext.REQUEST_CONFIG, config);

        // Create a director for this request
        director = createClientRequestDirector(getRequestExecutor(), getConnectionManager(),
                getConnectionReuseStrategy(), getConnectionKeepAliveStrategy(), getRoutePlanner(),
                getProtocolProcessor(), getHttpRequestRetryHandler(), getRedirectStrategy(),
                getTargetAuthenticationStrategy(), getProxyAuthenticationStrategy(), getUserTokenHandler(),
                params);
        routePlanner = getRoutePlanner();
        connectionBackoffStrategy = getConnectionBackoffStrategy();
        backoffManager = getBackoffManager();
    }

    try {
        if (connectionBackoffStrategy != null && backoffManager != null) {
            final HttpHost targetForRoute = (target != null) ? target
                    : (HttpHost) determineParams(request).getParameter(ClientPNames.DEFAULT_HOST);
            final HttpRoute route = routePlanner.determineRoute(targetForRoute, request, execContext);

            final CloseableHttpResponse out;
            try {
                out = CloseableHttpResponseProxy.newProxy(director.execute(target, request, execContext));
            } catch (final RuntimeException re) {
                if (connectionBackoffStrategy.shouldBackoff(re)) {
                    backoffManager.backOff(route);
                }
                throw re;
            } catch (final Exception e) {
                if (connectionBackoffStrategy.shouldBackoff(e)) {
                    backoffManager.backOff(route);
                }
                if (e instanceof HttpException) {
                    throw (HttpException) e;
                }
                if (e instanceof IOException) {
                    throw (IOException) e;
                }
                throw new UndeclaredThrowableException(e);
            }
            if (connectionBackoffStrategy.shouldBackoff(out)) {
                backoffManager.backOff(route);
            } else {
                backoffManager.probe(route);
            }
            return out;
        } else {
            return CloseableHttpResponseProxy.newProxy(director.execute(target, request, execContext));
        }
    } catch (final HttpException httpException) {
        throw new ClientProtocolException(httpException);
    }
}

From source file:org.apache.http.impl.client.AbstractStatisticsGatheringHttpClient.java

public final HttpResponse execute(HttpHost target, HttpRequest request, HttpContext context)
        throws IOException, ClientProtocolException {

    if (request == null) {
        throw new IllegalArgumentException("Request must not be null.");
    }//from   w ww  .  ja  va 2s .co  m
    // a null target may be acceptable, this depends on the route planner
    // a null context is acceptable, default context created below

    HttpContext execContext = null;
    RequestDirector director = null;

    // Initialize the request execution context making copies of
    // all shared objects that are potentially threading unsafe.
    synchronized (this) {

        HttpContext defaultContext = createHttpContext();
        if (context == null) {
            execContext = defaultContext;
        } else {
            execContext = new DefaultedHttpContext(context, defaultContext);
        }

        // Create a director for this request
        director = createClientRequestDirector(getRequestExecutor(), getConnectionManager(),
                getConnectionReuseStrategy(), getConnectionKeepAliveStrategy(), getRoutePlanner(),
                getProtocolProcessor(), getHttpRequestRetryHandler(), getRedirectStrategy(),
                getTargetAuthenticationHandler(), getProxyAuthenticationHandler(), getUserTokenHandler(),
                determineParams(request));
    }

    try {
        return director.execute(target, request, execContext);
    } catch (HttpException httpException) {
        throw new ClientProtocolException(httpException);
    }
}

From source file:org.apache.http.impl.nio.client.AbstractHttpAsyncClient.java

@Override
public <T> Future<T> execute(final HttpAsyncRequestProducer requestProducer,
        final HttpAsyncResponseConsumer<T> responseConsumer, final HttpContext context,
        final FutureCallback<T> callback) {
    if (this.terminated) {
        throw new IllegalStateException("Client has been shut down");
    }/*from ww w  .ja  v  a  2  s.  c om*/
    final BasicFuture<T> future = new BasicFuture<T>(callback);
    final ResultCallback<T> resultCallback = new DefaultResultCallback<T>(future, this.queue);
    DefaultAsyncRequestDirector<T> httpexchange;
    synchronized (this) {
        final HttpContext defaultContext = createHttpContext();
        HttpContext execContext;
        if (context == null) {
            execContext = defaultContext;
        } else {
            execContext = new DefaultedHttpContext(context, defaultContext);
        }
        httpexchange = new DefaultAsyncRequestDirector<T>(this.log, requestProducer, responseConsumer,
                execContext, resultCallback, this.connmgr, getProtocolProcessor(), getRoutePlanner(),
                getConnectionReuseStrategy(), getConnectionKeepAliveStrategy(), getRedirectStrategy(),
                getTargetAuthenticationStrategy(), getProxyAuthenticationStrategy(), getUserTokenHandler(),
                getParams());
    }
    this.queue.add(httpexchange);
    httpexchange.start();
    return future;
}