Example usage for org.apache.http.client.methods HttpOptions HttpOptions

List of usage examples for org.apache.http.client.methods HttpOptions HttpOptions

Introduction

In this page you can find the example usage for org.apache.http.client.methods HttpOptions HttpOptions.

Prototype

public HttpOptions(final String uri) 

Source Link

Usage

From source file:com.navercorp.volleyextensions.volleyer.multipart.stack.MultipartHttpClientStack.java

/**
 * Creates the appropriate subclass of HttpUriRequest for passed in request.
 *//* w w w.java 2  s  . com*/
@SuppressWarnings("deprecation")
/* protected */ static HttpUriRequest createHttpRequest(Request<?> request,
        Map<String, String> additionalHeaders) throws AuthFailureError {
    switch (request.getMethod()) {
    case Method.DEPRECATED_GET_OR_POST: {
        // This is the deprecated way that needs to be handled for backwards compatibility.
        // If the request's post body is null, then the assumption is that the request is
        // GET.  Otherwise, it is assumed that the request is a POST.
        byte[] postBody = request.getPostBody();
        if (postBody != null) {
            HttpPost postRequest = new HttpPost(request.getUrl());
            postRequest.addHeader(HEADER_CONTENT_TYPE, request.getPostBodyContentType());
            HttpEntity entity;
            entity = new ByteArrayEntity(postBody);
            postRequest.setEntity(entity);
            return postRequest;
        } else {
            return new HttpGet(request.getUrl());
        }
    }
    case Method.GET:
        return new HttpGet(request.getUrl());
    case Method.DELETE:
        return new HttpDelete(request.getUrl());
    case Method.POST: {
        HttpPost postRequest = new HttpPost(request.getUrl());
        setEntityIfNonEmptyMultipart(postRequest, request);
        return postRequest;
    }
    case Method.PUT: {
        HttpPut putRequest = new HttpPut(request.getUrl());
        setEntityIfNonEmptyMultipart(putRequest, request);
        return putRequest;
    }
    case Method.HEAD:
        return new HttpHead(request.getUrl());
    case Method.OPTIONS:
        return new HttpOptions(request.getUrl());
    case Method.TRACE:
        return new HttpTrace(request.getUrl());
    case Method.PATCH: {
        HttpPatch patchRequest = new HttpPatch(request.getUrl());
        patchRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType());
        setEntityIfNonEmptyMultipart(patchRequest, request);
        return patchRequest;
    }
    default:
        throw new IllegalStateException("Unknown request method.");
    }
}

From source file:com.nxt.zyl.data.volley.toolbox.HttpClientStack.java

/**
 * Creates the appropriate subclass of HttpUriRequest for passed in request.
 *///w w w . j a  va 2  s.c  o  m
@SuppressWarnings("deprecation")
/* protected */ static HttpUriRequest createHttpRequest(Request<?> request,
        Map<String, String> additionalHeaders) throws IOException, AuthFailureError {
    switch (request.getMethod()) {
    case Request.Method.DEPRECATED_GET_OR_POST: {
        // This is the deprecated way that needs to be handled for backwards compatibility.
        // If the request's post body is null, then the assumption is that the request is
        // GET.  Otherwise, it is assumed that the request is a POST.
        byte[] postBody = request.getPostBody();
        if (postBody != null) {
            HttpPost postRequest = new HttpPost(request.getUrl());
            postRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType());
            HttpEntity entity;
            entity = new ByteArrayEntity(postBody);
            postRequest.setEntity(entity);
            return postRequest;
        } else {
            return new HttpGet(request.getUrl());
        }
    }
    case Request.Method.GET:
        return new HttpGet(request.getUrl());
    case Method.DELETE:
        return new HttpDelete(request.getUrl());
    case Method.POST: {
        HttpPost postRequest = new HttpPost(request.getUrl());
        postRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType());
        setEntityIfNonEmptyBody(postRequest, request);
        return postRequest;
    }
    case Method.PUT: {
        HttpPut putRequest = new HttpPut(request.getUrl());
        putRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType());
        setEntityIfNonEmptyBody(putRequest, request);
        return putRequest;
    }
    case Method.HEAD:
        return new HttpHead(request.getUrl());
    case Method.OPTIONS:
        return new HttpOptions(request.getUrl());
    case Method.TRACE:
        return new HttpTrace(request.getUrl());
    case Method.PATCH: {
        HttpPatch patchRequest = new HttpPatch(request.getUrl());
        patchRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType());
        setEntityIfNonEmptyBody(patchRequest, request);
        return patchRequest;
    }
    default:
        throw new IllegalStateException("Unknown request method.");
    }
}

From source file:com.jaeksoft.searchlib.crawler.web.spider.HttpDownloader.java

public final DownloadItem request(final URI uri, final Method method, final CredentialItem credentialItem,
        final List<Header> additionalHeaders, final List<CookieItem> cookies, final HttpEntity entity)
        throws ClientProtocolException, IllegalStateException, IOException, URISyntaxException,
        SearchLibException {// w  w  w .  j av  a 2s  .c o  m
    HttpRequestBase httpRequestBase;
    switch (method) {
    case GET:
        httpRequestBase = new HttpGet(uri);
        break;
    case POST:
        httpRequestBase = new HttpPost(uri);
        break;
    case PUT:
        httpRequestBase = new HttpPut(uri);
        break;
    case DELETE:
        httpRequestBase = new HttpDelete(uri);
        break;
    case OPTIONS:
        httpRequestBase = new HttpOptions(uri);
        break;
    case PATCH:
        httpRequestBase = new HttpPatch(uri);
        break;
    case HEAD:
        httpRequestBase = new HttpHead(uri);
        break;
    default:
        throw new SearchLibException("Unkown method: " + method);
    }
    return request(httpRequestBase, credentialItem, additionalHeaders, cookies, entity);
}

From source file:co.uk.alt236.restclient4android.net.Connection.java

private HttpRequestBase setupHttpRequest(NetworkRequest request, URI uri) {
    String method = request.getAction().toUpperCase();
    String body = request.getRequestBody();

    HttpRequestBase httpReq = null;/*from w  w w .  j  a  va2  s.co  m*/
    HttpEntity entity = null;

    if (body != null) {
        body = body.trim();
        if (body.length() > 0) {
            entity = new ByteArrayEntity(body.getBytes());
        }
    }

    if ("GET".equals(method)) {
        httpReq = new HttpGet(uri);

    } else if ("POST".equals(method)) {
        httpReq = new HttpPost(uri);

        if (entity != null) {
            ((HttpPost) httpReq).setEntity(entity);
        }

    } else if ("PUT".equals(method)) {
        httpReq = new HttpPut(uri);
        if (entity != null) {
            ((HttpPut) httpReq).setEntity(entity);
        }

    } else if ("DELETE".equals(method)) {
        httpReq = new HttpDelete(uri);
    } else if ("HEAD".equals(method)) {
        httpReq = new HttpHead(uri);
    } else if ("TRACE".equals(method)) {
        httpReq = new HttpTrace(uri);
    } else if ("OPTIONS".equals(method)) {
        httpReq = new HttpOptions(uri);
    }

    setAuthentication(httpReq, request);
    setHeaders(httpReq, request);

    return httpReq;
}

From source file:se.inera.certificate.proxy.mappings.remote.RemoteDispatcher.java

private HttpResponse makeRequest(HttpServletRequest request, URI newUrl) throws IOException {
    log.debug("CALLING: {}", newUrl);

    String method = request.getMethod();
    if (method.equalsIgnoreCase("GET")) {
        return makeGetRequest(request, new HttpGet(newUrl));
    } else if (method.contentEquals("POST")) {
        return makePostRequest(request, new HttpPost(newUrl));
    } else if (method.contentEquals("PUT")) {
        return makePutRequest(request, new HttpPut(newUrl));
    } else if (method.contentEquals("OPTIONS")) {
        return makeOptionsRequest(request, new HttpOptions(newUrl));
    }//  ww  w.  j a v a2  s. c  om

    return new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_FORBIDDEN, "Unknown method:" + method);
}

From source file:code.google.restclient.core.Hitter.java

/**
 * Method to make POST or PUT request by sending http entity (as body)
 *//*from  w  ww. j  av  a2s.co m*/
public void hit(String url, String methodName, HttpHandler handler, Map<String, String> requestHeaders)
        throws Exception {

    if (DEBUG_ENABLED)
        LOG.debug("hit() - method => " + methodName + ", url => " + url);

    if (HttpGet.METHOD_NAME.equals(methodName)) {
        if (DEBUG_ENABLED)
            LOG.debug("hit() - ===> GET " + url);
        hit(url, new HttpGet(url), handler, requestHeaders);
    } else if (HttpHead.METHOD_NAME.equals(methodName)) {
        if (DEBUG_ENABLED)
            LOG.debug("hit() - ===> HEAD " + url);
        hit(url, new HttpHead(url), handler, requestHeaders);
    } else if (HttpDelete.METHOD_NAME.equals(methodName)) {
        if (DEBUG_ENABLED)
            LOG.debug("hit() - ===> DELETE " + url);
        hit(url, new HttpDelete(url), handler, requestHeaders);
    } else if (HttpOptions.METHOD_NAME.equals(methodName)) {
        if (DEBUG_ENABLED)
            LOG.debug("hit() - ===> OPTIONS " + url);
        hit(url, new HttpOptions(url), handler, requestHeaders);
    } else if (HttpTrace.METHOD_NAME.equals(methodName)) {
        if (DEBUG_ENABLED)
            LOG.debug("hit() - ===> TRACE " + url);
        hit(url, new HttpTrace(url), handler, requestHeaders);
    } else if (HttpPost.METHOD_NAME.equals(methodName)) { // POST
        if (DEBUG_ENABLED)
            LOG.debug("hit() - ===> POST " + url);
        HttpPost httpPost = new HttpPost(url);
        httpPost.setEntity(handler.getReqBodyEntity());
        hit(url, httpPost, handler, requestHeaders);
    } else if (HttpPut.METHOD_NAME.equals(methodName)) { // PUT
        if (DEBUG_ENABLED)
            LOG.debug("hit() - ===> PUT " + url);
        HttpPut httpPut = new HttpPut(url);
        httpPut.setEntity(handler.getReqBodyEntity());
        hit(url, httpPut, handler, requestHeaders);
    } else {
        throw new IllegalArgumentException("hit(): Unsupported method => " + methodName);
    }
}

From source file:com.comcast.csv.drivethru.api.HTTPRequestManager.java

/**
 * Create the HTTP Method./*from   w  w  w.  j ava2s  .c  om*/
 * @return the method
 */
private HttpUriRequest createMethod() {
    HttpUriRequest request = null;

    switch (mMethod) {
    case GET:
        request = new HttpGet(mUrl);
        break;

    case POST:
        request = new HttpPost(mUrl);
        break;

    case PATCH:
        request = new HttpPatch(mUrl);
        break;

    case OPTIONS:
        request = new HttpOptions(mUrl);
        break;

    case DELETE:
        request = new HttpDelete(mUrl);
        break;

    case PUT:
        request = new HttpPut(mUrl);
        break;

    case HEAD:
        request = new HttpHead(mUrl);
        break;

    case TRACE:
        request = new HttpTrace(mUrl);
        break;

    default:
        throw new UnsupportedOperationException("Unknown method: " + mMethod.toString());
    }

    return request;
}

From source file:org.apache.hadoop.gateway.dispatch.AppCookieManager.java

protected HttpRequest createKerberosAuthenticationRequest(HttpUriRequest userRequest) {
    HttpRequest authRequest = new HttpOptions(userRequest.getURI().getPath());
    return authRequest;
}

From source file:com.github.technosf.posterer.modules.commons.transport.CommonsResponseModelTaskImpl.java

/**
 * Generates the specific request type//from   w ww.j  a va 2s.  c  om
 * 
 * @param uri
 *            the uri
 * @param method
 *            the request method
 * @return the request
 */
@Nullable
private static HttpUriRequest createRequest(final @Nullable URI uri, final @Nullable String method) {
    if (method != null && uri != null) {
        switch (method) {
        case "GET":
            return new HttpGet(uri);
        case "HEAD":
            return new HttpHead(uri);
        case "POST":
            return new HttpPost(uri);
        case "PUT":
            return new HttpPut(uri);
        case "DELETE":
            return new HttpDelete(uri);
        case "TRACE":
            return new HttpTrace(uri);
        case "OPTIONS":
            return new HttpOptions(uri);
        case "PATCH":
            return new HttpPatch(uri);
        }
    }

    LOG.error(CONST_ERR_UNKNOWN_METHOD, method);
    return null;
}