当前位置: 首页>>代码示例>>Java>>正文


Java ExecutionContext类代码示例

本文整理汇总了Java中org.apache.http.protocol.ExecutionContext的典型用法代码示例。如果您正苦于以下问题:Java ExecutionContext类的具体用法?Java ExecutionContext怎么用?Java ExecutionContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ExecutionContext类属于org.apache.http.protocol包,在下文中一共展示了ExecutionContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: execute

import org.apache.http.protocol.ExecutionContext; //导入依赖的package包/类
public HttpResponse execute(HttpRequest request) throws IOException, HttpException {
  HttpParams params = new BasicHttpParams();
  HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);

  HttpProcessor processor = new ImmutableHttpProcessor(new RequestContent());

  HttpRequestExecutor executor = new HttpRequestExecutor();

  HttpContext context = new BasicHttpContext(null);
  context.setAttribute(ExecutionContext.HTTP_CONNECTION, connection);

  if (!connection.isOpen()) {
    Socket socket = new Socket(address.getAddress(), address.getPort());
    connection.bind(socket, params);
  }

  context.setAttribute(ExecutionContext.HTTP_REQUEST, request);
  request.setParams(params);
  executor.preProcess(request, processor, context);
  HttpResponse response = executor.execute(request, connection, context);
  executor.postProcess(response, processor, context);

  return response;
}
 
开发者ID:ApptuitAI,项目名称:JInsight,代码行数:25,代码来源:RequestExecutorBasedClientInstrumentationTest.java

示例2: isRedirectRequested

import org.apache.http.protocol.ExecutionContext; //导入依赖的package包/类
public boolean isRedirectRequested(
        final HttpResponse response,
        final HttpContext context) {
    if (response == null) {
        throw new IllegalArgumentException("HTTP response may not be null");
    }

    int statusCode = response.getStatusLine().getStatusCode();
    switch (statusCode) {
    case HttpStatus.SC_MOVED_TEMPORARILY:
    case HttpStatus.SC_MOVED_PERMANENTLY:
    case HttpStatus.SC_TEMPORARY_REDIRECT:
        HttpRequest request = (HttpRequest) context.getAttribute(
                ExecutionContext.HTTP_REQUEST);
        String method = request.getRequestLine().getMethod();
        return method.equalsIgnoreCase(HttpGet.METHOD_NAME)
            || method.equalsIgnoreCase(HttpHead.METHOD_NAME);
    case HttpStatus.SC_SEE_OTHER:
        return true;
    default:
        return false;
    } //end of switch
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:DefaultRedirectHandler.java

示例3: process

import org.apache.http.protocol.ExecutionContext; //导入依赖的package包/类
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
    
    AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);
    
    // If no auth scheme avaialble yet, try to initialize it preemptively
    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);
        }
    }
    
}
 
开发者ID:nkasvosve,项目名称:beyondj,代码行数:21,代码来源:HttpSender.java

示例4: submitRequest

import org.apache.http.protocol.ExecutionContext; //导入依赖的package包/类
public HttpRequest submitRequest(final HttpContext context) {
    HttpHost targetHost = (HttpHost) context.getAttribute(
            ExecutionContext.HTTP_TARGET_HOST);
    Object flag = context.getAttribute(REQUEST_SENT);
    if (flag == null) {
        // Stick some object into the context
        context.setAttribute(REQUEST_SENT, Boolean.TRUE);

        System.out.println("--------------");
        System.out.println("Sending request to " + targetHost);
        System.out.println("--------------");
        
        return new BasicHttpRequest("GET", "/");
    } else {
        // No new request to submit
        return null;
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:19,代码来源:NHttpClient.java

示例5: submitRequest

import org.apache.http.protocol.ExecutionContext; //导入依赖的package包/类
public HttpRequest submitRequest(final HttpContext context) {
    HttpHost targetHost = (HttpHost) context.getAttribute(
            ExecutionContext.HTTP_TARGET_HOST);
    Object token = context.getAttribute(REQUEST_SENT);
    if (token == null) {
        // Stick some object into the context
        context.setAttribute(REQUEST_SENT, Boolean.TRUE);

        System.out.println("--------------");
        System.out.println("Sending request to " + targetHost);
        System.out.println("--------------");
        
        return new BasicHttpRequest("GET", "/");
    } else {
        // No new request to submit
        return null;
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:19,代码来源:NHttpSSLClient.java

示例6: process

import org.apache.http.protocol.ExecutionContext; //导入依赖的package包/类
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
    AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);
    // If no auth scheme has been initialized yet
    if (authState.getAuthScheme() == null) {
        CredentialsProvider credentialsProvider = (CredentialsProvider) context.getAttribute(ClientContext.CREDS_PROVIDER);
        HttpHost targetHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
        AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort());
        // Obtain credentials matching the target host
        Credentials credentials = credentialsProvider.getCredentials(authScope);
        // If found, generate BasicScheme preemptively
        if (credentials != null) {
            authState.setAuthScheme(new DiadocAuthScheme());
            authState.setCredentials(credentials);
        }
    }
}
 
开发者ID:diadoc,项目名称:diadocsdk-java,代码行数:17,代码来源:DiadocPreemptiveAuthRequestInterceptor.java

示例7: process

import org.apache.http.protocol.ExecutionContext; //导入依赖的package包/类
@Override
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 not auth scheme has been initialized yet
    if (authState.getAuthScheme() == null) {
        AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort());
        // Obtain credentials matching the target host
        org.apache.http.auth.Credentials creds = credsProvider.getCredentials(authScope);
        // If found, generate BasicScheme preemptively
        if (creds != null) {
            authState.setAuthScheme(new BasicScheme());
            authState.setCredentials(creds);
        }
    }
}
 
开发者ID:Kamshak,项目名称:foursquared,代码行数:22,代码来源:HttpApiWithBasicAuth.java

示例8: process

import org.apache.http.protocol.ExecutionContext; //导入依赖的package包/类
@Override
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 not auth scheme has been initialized yet
    if (authState.getAuthScheme() == null) {
        AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort());
        org.apache.http.auth.Credentials creds = credsProvider.getCredentials(authScope);
        if (creds != null) {
            authState.setAuthScheme(new BasicScheme());
            authState.setCredentials(creds);
        }
    }
}
 
开发者ID:Kamshak,项目名称:foursquared,代码行数:20,代码来源:SpecialWebViewActivity.java

示例9: setupClient

import org.apache.http.protocol.ExecutionContext; //导入依赖的package包/类
/**
 * This method is used to capture Location headers after HttpClient redirect handling.
 */
private void setupClient(final AbstractHttpClient client) {
	this.client.addResponseInterceptor(new HttpResponseInterceptor() {
		@Override
		public void process(final HttpResponse response, final HttpContext context)
				throws HttpException, IOException {
			Header header = response.getFirstHeader("Location");
			if (header!=null) {
				String location = header.getValue();

				/*
				 * Append the base name to the Location header
				 */
				if (location.startsWith("/")) {
					String baseUrl = context.getAttribute(ExecutionContext.HTTP_TARGET_HOST).toString();
					location = baseUrl + location;
				}
				context.setAttribute("Location", location);
			}
		}
	});
}
 
开发者ID:Coffeeboys,项目名称:RenewPass,代码行数:25,代码来源:MechanizeAgent.java

示例10: handleCacheHit

import org.apache.http.protocol.ExecutionContext; //导入依赖的package包/类
private HttpResponse handleCacheHit(final HttpHost target, final HttpRequestWrapper request,
        final HttpContext context, final HttpCacheEntry entry)
        throws ClientProtocolException, IOException {
    recordCacheHit(target, request);
    HttpResponse out = null;
    final Date now = getCurrentDate();
    if (suitabilityChecker.canCachedResponseBeUsed(target, request, entry, now)) {
        log.debug("Cache hit");
        out = generateCachedResponse(request, context, entry, now);
    } else if (!mayCallBackend(request)) {
        log.debug("Cache entry not suitable but only-if-cached requested");
        out = generateGatewayTimeout(context);
    } else {
        log.debug("Revalidating cache entry");
        return revalidateCacheEntry(target, request, context, entry, now);
    }
    if (context != null) {
        context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, target);
        context.setAttribute(ExecutionContext.HTTP_REQUEST, request);
        context.setAttribute(ExecutionContext.HTTP_RESPONSE, out);
        context.setAttribute(ExecutionContext.HTTP_REQ_SENT, Boolean.TRUE);
    }
    return out;
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:25,代码来源:CachingHttpClient.java

示例11: isRedirectRequested

import org.apache.http.protocol.ExecutionContext; //导入依赖的package包/类
@Override
public boolean isRedirectRequested(
        final HttpResponse response,
        final HttpContext context) {
    Args.notNull(response, "HTTP response");

    final int statusCode = response.getStatusLine().getStatusCode();
    switch (statusCode) {
    case HttpStatus.SC_MOVED_TEMPORARILY:
    case HttpStatus.SC_MOVED_PERMANENTLY:
    case HttpStatus.SC_TEMPORARY_REDIRECT:
        final HttpRequest request = (HttpRequest) context.getAttribute(
                ExecutionContext.HTTP_REQUEST);
        final String method = request.getRequestLine().getMethod();
        return method.equalsIgnoreCase(HttpGet.METHOD_NAME)
            || method.equalsIgnoreCase(HttpHead.METHOD_NAME);
    case HttpStatus.SC_SEE_OTHER:
        return true;
    default:
        return false;
    } //end of switch
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:23,代码来源:DefaultRedirectHandler.java

示例12: process

import org.apache.http.protocol.ExecutionContext; //导入依赖的package包/类
@Override
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 not auth scheme has been initialized yet
    if( authState.getAuthScheme() == null )
    {
        AuthScope authScope = new AuthScope( targetHost.getHostName(),
                                             targetHost.getPort() );
        // Obtain credentials matching the target host
        Credentials creds = credsProvider.getCredentials( authScope );
        // If found, generate BasicScheme preemptively
        if( creds != null )
        {
            authState.setAuthScheme( new BasicScheme() );
            authState.setCredentials( creds );
        }
    }
}
 
开发者ID:apache,项目名称:polygene-java,代码行数:25,代码来源:WebRealmServiceTest.java

示例13: process

import org.apache.http.protocol.ExecutionContext; //导入依赖的package包/类
@Override
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);
		}
	}
}
 
开发者ID:tommy4711,项目名称:gaeproxy,代码行数:20,代码来源:WeaveTransport.java

示例14: process

import org.apache.http.protocol.ExecutionContext; //导入依赖的package包/类
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 || authState.hasAuthOptions()) {
                return;
            }

            // If no authState has been established and this is a PUT or POST request, add preemptive authorisation
            String requestMethod = request.getRequestLine().getMethod();
            if (requestMethod.equals(HttpPut.METHOD_NAME) || requestMethod.equals(HttpPost.METHOD_NAME)) {
                CredentialsProvider credentialsProvider = (CredentialsProvider) context.getAttribute(ClientContext.CREDS_PROVIDER);
                HttpHost targetHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
                Credentials credentials = credentialsProvider.getCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()));
                if (credentials == null) {
                    throw new HttpException("No credentials for preemptive authentication");
                }
                authState.update(authScheme, credentials);
            }
        }
 
开发者ID:Pushjet,项目名称:Pushjet-Android,代码行数:21,代码来源:HttpClientConfigurer.java

示例15: process

import org.apache.http.protocol.ExecutionContext; //导入依赖的package包/类
@Override
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {

    AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);

    // If no auth scheme available yet, try to initialize it preemptively
    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) {
                authState.setAuthScheme(authScheme);
                authState.setCredentials(creds);
            }
        }
    }
}
 
开发者ID:epam,项目名称:Wilma,代码行数:20,代码来源:BrowserMobHttpClient.java


注:本文中的org.apache.http.protocol.ExecutionContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。