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


Java ProtocolException类代码示例

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


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

示例1: getRedirect

import org.apache.http.ProtocolException; //导入依赖的package包/类
public HttpUriRequest getRedirect(HttpRequest request, HttpResponse response, HttpContext context) throws ProtocolException {
    URI uri = this.getLocationURI(request, response, context);
    String method = request.getRequestLine().getMethod();
    if (method.equalsIgnoreCase(HttpHead.METHOD_NAME)) {
        return new HttpHead(uri);
    } else if (method.equalsIgnoreCase(HttpPost.METHOD_NAME)) {
        return this.copyEntity(new HttpPost(uri), request);
    } else if (method.equalsIgnoreCase(HttpPut.METHOD_NAME)) {
        return this.copyEntity(new HttpPut(uri), request);
    } else if (method.equalsIgnoreCase(HttpDelete.METHOD_NAME)) {
        return new HttpDelete(uri);
    } else if (method.equalsIgnoreCase(HttpTrace.METHOD_NAME)) {
        return new HttpTrace(uri);
    } else if (method.equalsIgnoreCase(HttpOptions.METHOD_NAME)) {
        return new HttpOptions(uri);
    } else if (method.equalsIgnoreCase(HttpPatch.METHOD_NAME)) {
        return this.copyEntity(new HttpPatch(uri), request);
    } else {
        return new HttpGet(uri);
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:22,代码来源:AlwaysRedirectRedirectStrategy.java

示例2: isRedirected

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

    int statusCode = response.getStatusLine().getStatusCode();
    String method = request.getRequestLine().getMethod();
    Header locationHeader = response.getFirstHeader("location");
    switch (statusCode) {
    case HttpStatus.SC_MOVED_TEMPORARILY:
        return isRedirectable(method) && locationHeader != null;
    case HttpStatus.SC_MOVED_PERMANENTLY:
    case HttpStatus.SC_TEMPORARY_REDIRECT:
        return isRedirectable(method);
    case HttpStatus.SC_SEE_OTHER:
        return true;
    default:
        return false;
    } //end of switch
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:27,代码来源:DefaultRedirectStrategy.java

示例3: RequestWrapper

import org.apache.http.ProtocolException; //导入依赖的package包/类
public RequestWrapper(final HttpRequest request) throws ProtocolException {
    super();
    if (request == null) {
        throw new IllegalArgumentException("HTTP request may not be null");
    }
    this.original = request;
    setParams(request.getParams());
    setHeaders(request.getAllHeaders());
    // Make a copy of the original URI
    if (request instanceof HttpUriRequest) {
        this.uri = ((HttpUriRequest) request).getURI();
        this.method = ((HttpUriRequest) request).getMethod();
        this.version = null;
    } else {
        RequestLine requestLine = request.getRequestLine();
        try {
            this.uri = new URI(requestLine.getUri());
        } catch (URISyntaxException ex) {
            throw new ProtocolException("Invalid request URI: "
                    + requestLine.getUri(), ex);
        }
        this.method = requestLine.getMethod();
        this.version = request.getProtocolVersion();
    }
    this.execCount = 0;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:27,代码来源:RequestWrapper.java

示例4: handleException

import org.apache.http.ProtocolException; //导入依赖的package包/类
/**
 * Handles the given exception and generates an HTTP response to be sent
 * back to the client to inform about the exceptional condition encountered
 * in the course of the request processing.
 *
 * @param ex the exception.
 * @param response the HTTP response.
 */
protected void handleException(final HttpException ex, final HttpResponse response) {
    if (ex instanceof MethodNotSupportedException) {
        response.setStatusCode(HttpStatus.SC_NOT_IMPLEMENTED);
    } else if (ex instanceof UnsupportedHttpVersionException) {
        response.setStatusCode(HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED);
    } else if (ex instanceof ProtocolException) {
        response.setStatusCode(HttpStatus.SC_BAD_REQUEST);
    } else {
        response.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
    }
    String message = ex.getMessage();
    if (message == null) {
        message = ex.toString();
    }
    byte[] msg = EncodingUtils.getAsciiBytes(message);
    ByteArrayEntity entity = new ByteArrayEntity(msg);
    entity.setContentType("text/plain; charset=US-ASCII");
    response.setEntity(entity);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:28,代码来源:HttpService.java

示例5: RequestEntityRestStorageService

import org.apache.http.ProtocolException; //导入依赖的package包/类
public RequestEntityRestStorageService(final S3Session session,
                                       final Jets3tProperties properties,
                                       final HttpClientBuilder configuration) {
    super(session.getHost().getCredentials().isAnonymousLogin() ? null :
                    new AWSCredentials(null, null) {
                        @Override
                        public String getAccessKey() {
                            return session.getHost().getCredentials().getUsername();
                        }

                        @Override
                        public String getSecretKey() {
                            return session.getHost().getCredentials().getPassword();
                        }
                    },
            new PreferencesUseragentProvider().get(), null, properties);
    this.session = session;
    configuration.disableContentCompression();
    configuration.setRetryHandler(new S3HttpRequestRetryHandler(this, preferences.getInteger("http.connections.retry")));
    configuration.setRedirectStrategy(new DefaultRedirectStrategy() {
        @Override
        public HttpUriRequest getRedirect(final HttpRequest request, final HttpResponse response, final HttpContext context) throws ProtocolException {
            if(response.containsHeader("x-amz-bucket-region")) {
                final String host = ((HttpUriRequest) request).getURI().getHost();
                if(!StringUtils.equals(session.getHost().getHostname(), host)) {
                    regionEndpointCache.putRegionForBucketName(
                            StringUtils.split(StringUtils.removeEnd(((HttpUriRequest) request).getURI().getHost(), session.getHost().getHostname()), ".")[0],
                            response.getFirstHeader("x-amz-bucket-region").getValue());
                }
            }
            return super.getRedirect(request, response, context);
        }
    });
    this.setHttpClient(configuration.build());
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:36,代码来源:RequestEntityRestStorageService.java

示例6: createLocationURI

import org.apache.http.ProtocolException; //导入依赖的package包/类
@Override
protected URI createLocationURI(String location) throws ProtocolException
{
    try
    {
        final URIBuilder b = new URIBuilder(new URI(encode(location)).normalize());
        final String host = b.getHost();
        if (host != null)
        {
            b.setHost(host.toLowerCase(Locale.ROOT));
        }
        final String path = b.getPath();
        if (TextUtils.isEmpty(path))
        {
            b.setPath("/");
        }
        return b.build();
    }
    catch (final URISyntaxException ex)
    {
        throw new ProtocolException("Invalid redirect URI: " + location, ex);
    }
}
 
开发者ID:PaleoCrafter,项目名称:CurseSync,代码行数:24,代码来源:SafeRedirectStrategy.java

示例7: getRedirect

import org.apache.http.ProtocolException; //导入依赖的package包/类
@Override
public HttpUriRequest getRedirect(HttpRequest request, HttpResponse response, HttpContext context) throws ProtocolException {
    URI uri = getLocationURI(request, response, context);
    String method = request.getRequestLine().getMethod();
    if ("post".equalsIgnoreCase(method)) {
        try {
            HttpRequestWrapper httpRequestWrapper = (HttpRequestWrapper) request;
            httpRequestWrapper.setURI(uri);
            httpRequestWrapper.removeHeaders("Content-Length");
            return httpRequestWrapper;
        } catch (Exception e) {
            logger.error("强转为HttpRequestWrapper出错");
        }
        return new HttpPost(uri);
    } else {
        return new HttpGet(uri);
    }
}
 
开发者ID:xbynet,项目名称:crawler,代码行数:19,代码来源:CustomRedirectStrategy.java

示例8: rewriteRequestURI

import org.apache.http.ProtocolException; //导入依赖的package包/类
static void rewriteRequestURI(
        final HttpRequestWrapper request,
        final HttpRoute route) throws ProtocolException {
    try {
        URI uri = request.getURI();
        if (uri != null) {
            // Make sure the request URI is relative
            if (uri.isAbsolute()) {
                uri = URIUtilsHC4.rewriteURI(uri, null, true);
            } else {
                uri = URIUtilsHC4.rewriteURI(uri);
            }
            request.setURI(uri);
        }
    } catch (final URISyntaxException ex) {
        throw new ProtocolException("Invalid URI: " + request.getRequestLine().getUri(), ex);
    }
}
 
开发者ID:xxonehjh,项目名称:remote-files-sync,代码行数:19,代码来源:MinimalClientExec.java

示例9: isRedirected

import org.apache.http.ProtocolException; //导入依赖的package包/类
public boolean isRedirected(
        final HttpRequest request,
        final HttpResponse response,
        final HttpContext context) throws ProtocolException {
    Args.notNull(request, "HTTP request");
    Args.notNull(response, "HTTP response");

    final int statusCode = response.getStatusLine().getStatusCode();
    final String method = request.getRequestLine().getMethod();
    final Header locationHeader = response.getFirstHeader("location");
    switch (statusCode) {
    case HttpStatus.SC_MOVED_TEMPORARILY:
        return isRedirectable(method) && locationHeader != null;
    case HttpStatus.SC_MOVED_PERMANENTLY:
    case HttpStatus.SC_TEMPORARY_REDIRECT:
        return isRedirectable(method);
    case HttpStatus.SC_SEE_OTHER:
        return true;
    default:
        return false;
    } //end of switch
}
 
开发者ID:xxonehjh,项目名称:remote-files-sync,代码行数:23,代码来源:DefaultRedirectStrategy.java

示例10: createLocationURI

import org.apache.http.ProtocolException; //导入依赖的package包/类
/**
 * @since 4.1
 */
protected URI createLocationURI(final String location) throws ProtocolException {
    try {
        final URIBuilder b = new URIBuilder(new URI(location).normalize());
        final String host = b.getHost();
        if (host != null) {
            b.setHost(host.toLowerCase(Locale.ENGLISH));
        }
        final String path = b.getPath();
        if (TextUtils.isEmpty(path)) {
            b.setPath("/");
        }
        return b.build();
    } catch (final URISyntaxException ex) {
        throw new ProtocolException("Invalid redirect URI: " + location, ex);
    }
}
 
开发者ID:xxonehjh,项目名称:remote-files-sync,代码行数:20,代码来源:DefaultRedirectStrategy.java

示例11: getRedirect

import org.apache.http.ProtocolException; //导入依赖的package包/类
public HttpUriRequest getRedirect(
        final HttpRequest request,
        final HttpResponse response,
        final HttpContext context) throws ProtocolException {
    final URI uri = getLocationURI(request, response, context);
    final String method = request.getRequestLine().getMethod();
    if (method.equalsIgnoreCase(HttpHeadHC4.METHOD_NAME)) {
        return new HttpHeadHC4(uri);
    } else if (method.equalsIgnoreCase(HttpGetHC4.METHOD_NAME)) {
        return new HttpGetHC4(uri);
    } else {
        final int status = response.getStatusLine().getStatusCode();
        if (status == HttpStatus.SC_TEMPORARY_REDIRECT) {
            return RequestBuilder.copy(request).setUri(uri).build();
        } else {
            return new HttpGetHC4(uri);
        }
    }
}
 
开发者ID:xxonehjh,项目名称:remote-files-sync,代码行数:20,代码来源:DefaultRedirectStrategy.java

示例12: determineRoute

import org.apache.http.ProtocolException; //导入依赖的package包/类
public HttpRoute determineRoute(
        final HttpHost host,
        final HttpRequest request,
        final HttpContext context) throws HttpException {
    Args.notNull(request, "Request");
    if (host == null) {
        throw new ProtocolException("Target host is not specified");
    }
    final HttpClientContext clientContext = HttpClientContext.adapt(context);
    final RequestConfig config = clientContext.getRequestConfig();
    final InetAddress local = config.getLocalAddress();
    HttpHost proxy = config.getProxy();
    if (proxy == null) {
        proxy = determineProxy(host, request, context);
    }

    final HttpHost target;
    if (host.getPort() <= 0) {
        try {
            target = new HttpHost(
                    host.getHostName(),
                    this.schemePortResolver.resolve(host),
                    host.getSchemeName());
        } catch (final UnsupportedSchemeException ex) {
            throw new HttpException(ex.getMessage());
        }
    } else {
        target = host;
    }
    final boolean secure = target.getSchemeName().equalsIgnoreCase("https");
    if (proxy == null) {
        return new HttpRoute(target, local, secure);
    } else {
        return new HttpRoute(target, local, proxy, secure);
    }
}
 
开发者ID:xxonehjh,项目名称:remote-files-sync,代码行数:37,代码来源:DefaultRoutePlanner.java

示例13: revalidateCacheEntry

import org.apache.http.ProtocolException; //导入依赖的package包/类
private HttpResponse revalidateCacheEntry(final HttpHost target,
        final HttpRequestWrapper request, final HttpContext context, final HttpCacheEntry entry,
        final Date now) throws ClientProtocolException {

    try {
        if (asynchRevalidator != null
            && !staleResponseNotAllowed(request, entry, now)
            && validityPolicy.mayReturnStaleWhileRevalidating(entry, now)) {
            log.trace("Serving stale with asynchronous revalidation");
            final HttpResponse resp = generateCachedResponse(request, context, entry, now);

            asynchRevalidator.revalidateCacheEntry(target, request, context, entry);

            return resp;
        }
        return revalidateCacheEntry(target, request, context, entry);
    } catch (final IOException ioex) {
        return handleRevalidationFailure(request, context, entry, now);
    } catch (final ProtocolException e) {
        throw new ClientProtocolException(e);
    }
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:23,代码来源:CachingHttpClient.java

示例14: testRunGracefullyHandlesProtocolException

import org.apache.http.ProtocolException; //导入依赖的package包/类
@Test
public void testRunGracefullyHandlesProtocolException() throws Exception {
    final String identifier = "foo";

    final AsynchronousValidationRequest impl = new AsynchronousValidationRequest(
            mockParent, mockClient, route, request, context, mockExecAware, mockCacheEntry,
            identifier, 0);

    when(
            mockClient.revalidateCacheEntry(
                    route, request, context, mockExecAware, mockCacheEntry)).thenThrow(
            new ProtocolException());

    impl.run();

    verify(mockClient).revalidateCacheEntry(
            route, request, context, mockExecAware, mockCacheEntry);
    verify(mockParent).markComplete(identifier);
    verify(mockParent).jobFailed(identifier);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:21,代码来源:TestAsynchronousValidationRequest.java

示例15: rewriteRequestURI

import org.apache.http.ProtocolException; //导入依赖的package包/类
static void rewriteRequestURI(
        final HttpRequestWrapper request,
        final HttpRoute route) throws ProtocolException {
    try {
        URI uri = request.getURI();
        if (uri != null) {
            // Make sure the request URI is relative
            if (uri.isAbsolute()) {
                uri = URIUtils.rewriteURI(uri, null, true);
            } else {
                uri = URIUtils.rewriteURI(uri);
            }
            request.setURI(uri);
        }
    } catch (final URISyntaxException ex) {
        throw new ProtocolException("Invalid URI: " + request.getRequestLine().getUri(), ex);
    }
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:19,代码来源:MinimalClientExec.java


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