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

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

Introduction

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

Prototype

public HttpTrace(final String uri) 

Source Link

Usage

From source file:com.feedeo.rest.client.AbstractRestClient.java

protected ClientHttpRequestFactory createClientHttpRequestFactory(HttpClient httpClient) {
    return new HttpComponentsClientHttpRequestFactory(httpClient) {
        @Override/*w  w  w . j av  a  2s .com*/
        protected HttpUriRequest createHttpUriRequest(HttpMethod httpMethod, URI uri) {
            switch (httpMethod) {
            case GET:
                return new HttpGet(uri);
            case DELETE:
                return new HttpEntityEnclosingDeleteRequest(uri);
            case HEAD:
                return new HttpHead(uri);
            case OPTIONS:
                return new HttpOptions(uri);
            case POST:
                return new HttpPost(uri);
            case PUT:
                return new HttpPut(uri);
            case TRACE:
                return new HttpTrace(uri);
            case PATCH:
                return new HttpPatch(uri);
            default:
                throw new IllegalArgumentException("Invalid HTTP method: " + httpMethod);
            }
        }
    };
}

From source file:org.sonatype.nexus.test.utils.hc4client.Hc4MethodCall.java

/**
 * Constructor./*from w ww .  j a  v  a2 s .  co  m*/
 *
 * @param helper     The parent HTTP client helper.
 * @param method     The method name.
 * @param requestUri The request URI.
 * @param hasEntity  Indicates if the call will have an entity to send to the server.
 */
public Hc4MethodCall(Hc4ClientHelper helper, final String method, String requestUri, boolean hasEntity)
        throws IOException {
    super(helper, method, requestUri);
    this.clientHelper = helper;

    if (requestUri.startsWith("http")) {
        if (method.equalsIgnoreCase(Method.GET.getName())) {
            this.httpMethod = new HttpGet(requestUri);
        } else if (method.equalsIgnoreCase(Method.POST.getName())) {
            this.httpMethod = new HttpPost(requestUri);
        } else if (method.equalsIgnoreCase(Method.PUT.getName())) {
            this.httpMethod = new HttpPut(requestUri);
        } else if (method.equalsIgnoreCase(Method.HEAD.getName())) {
            this.httpMethod = new HttpHead(requestUri);
        } else if (method.equalsIgnoreCase(Method.DELETE.getName())) {
            this.httpMethod = new HttpDelete(requestUri);
        } else if (method.equalsIgnoreCase(Method.CONNECT.getName())) {
            // CONNECT unsupported (and is unused by legacy ITs)
            throw new UnsupportedOperationException("Not implemented");
        } else if (method.equalsIgnoreCase(Method.OPTIONS.getName())) {
            this.httpMethod = new HttpOptions(requestUri);
        } else if (method.equalsIgnoreCase(Method.TRACE.getName())) {
            this.httpMethod = new HttpTrace(requestUri);
        } else {
            // custom HTTP verbs unsupported (and is unused by legacy ITs)
            throw new UnsupportedOperationException("Not implemented");
        }

        this.httpMethod.getParams().setBooleanParameter(ClientPNames.HANDLE_REDIRECTS,
                this.clientHelper.isFollowRedirects());
        // retry handler setting unsupported (legaacy ITs use default HC4 retry handler)
        this.responseHeadersAdded = false;
        setConfidential(this.httpMethod.getURI().getScheme().equalsIgnoreCase(Protocol.HTTPS.getSchemeName()));
    } else {
        throw new IllegalArgumentException("Only HTTP or HTTPS resource URIs are allowed here");
    }
}

From source file:com.lovebridge.library.volley.toolbox.HttpClientStack.java

/**
 * Creates the appropriate subclass of HttpUriRequest for passed in request.
 *///from w  w  w. j av a 2  s.  c  o  m
@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());
        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.sayar.requests.impl.HttpClientRequestHandler.java

public Response execute(final RequestArguments args) throws AuthenticationException, InvalidParameterException {
    // Parse params
    final String url = args.getUrl();
    final Map<String, String> params = args.getParams();
    final HttpAuthentication httpAuth = args.getHttpAuth();

    String formattedUrl;//from   w  ww. j  ava2s .  c o m
    try {
        formattedUrl = RequestHandlerUtils.formatUrl(url, params);
    } catch (final UnsupportedEncodingException e) {
        Log.e(RequestsConstants.LOG_TAG, "Unsupported Encoding Exception in Url Parameters.", e);
        throw new InvalidParameterException("Url Parameter Encoding is invalid.");

    }

    final RequestMethod method = args.getMethod();
    HttpUriRequest request = null;
    if (method == RequestMethod.GET) {
        request = new HttpGet(formattedUrl);
    } else if (method == RequestMethod.DELETE) {
        request = new HttpDelete(formattedUrl);
    } else if (method == RequestMethod.OPTIONS) {
        request = new HttpOptions(formattedUrl);
    } else if (method == RequestMethod.HEAD) {
        request = new HttpHead(formattedUrl);
    } else if (method == RequestMethod.TRACE) {
        request = new HttpTrace(formattedUrl);
    } else if (method == RequestMethod.POST || method == RequestMethod.PUT) {
        request = method == RequestMethod.POST ? new HttpPost(formattedUrl) : new HttpPut(formattedUrl);
        if (args.getRequestEntity() != null) {
            ((HttpEntityEnclosingRequestBase) request).setEntity(args.getRequestEntity());
        }
    } else {
        throw new InvalidParameterException("Request Method is not set.");
    }

    if (httpAuth != null) {
        try {
            HttpClientRequestHandler.addAuthentication(request, httpAuth);
        } catch (final AuthenticationException e) {
            Log.e(RequestsConstants.LOG_TAG, "Adding Authentication Failed.", e);
            throw e;
        }
    }
    if (args.getHeaders() != null) {
        HttpClientRequestHandler.addHeaderParams(request, args.getHeaders());
    }

    final Response response = new Response();

    final HttpClient client = this.getHttpClient(args);

    try {
        final HttpResponse httpResponse = client.execute(request);

        response.setResponseVersion(httpResponse.getProtocolVersion());
        response.setStatusAndCode(httpResponse.getStatusLine());

        final HttpEntity entity = httpResponse.getEntity();

        if (entity != null) {
            // Convert the stream into a string and store into the RAW
            // field.
            // InputStream instream = entity.getContent();
            // response.setRaw(RequestHandlerUtils.convertStreamToString(instream));
            // instream.close(); // Closing the input stream will trigger
            // connection release

            // TODO: Perhaps we should be dealing with the charset
            response.setRaw(EntityUtils.toString(entity));

            try {
                // Get the Content Type
                final String contenttype = entity.getContentType().getValue();

                RequestParser parser = null;

                // Check if a request-specific parser was set.
                if (args.getRequestParser() == null) {
                    // Parse the request according to the user's wishes.
                    final String extractionFormat = args.getParseAs();

                    // Determine extraction format if none are set.
                    if (extractionFormat == null) {
                        // If we can not find an appropriate parser, the
                        // default one will be returned.
                        parser = RequestParserFactory.findRequestParser(contenttype);
                    } else {
                        // Try to get the requested parser. This will throw
                        // an exception if we can't get it.
                        parser = RequestParserFactory.getRequestParser(extractionFormat);
                    }
                } else {
                    // Set a request specific parser.
                    parser = args.getRequestParser();
                }

                // Parse the content.. and if it throws an exception log it.
                final Object result = parser.parse(response.getRaw());
                // Check the result of the parser.
                if (result != null) {
                    response.setContent(result);
                    response.setParsedAs(parser.getName());
                } else {
                    // If the parser returned nothing (and most likely it
                    // wasn't the default parser).

                    // We already have the raw response, user the default
                    // parser fallback.
                    response.setContent(RequestParserFactory.DEFAULT_PARSER.parse(response.getRaw()));
                    response.setParsedAs(RequestParserFactory.DEFAULT_PARSER.getName());
                }
            } catch (final InvalidParameterException e) {
                Log.e(RequestsConstants.LOG_TAG, "Parser Requested Could Not Be Found.", e);
                throw e;
            } catch (final Exception e) {
                // Catch any parsing exception.
                Log.e(RequestsConstants.LOG_TAG, "Parser Failed Exception.", e);
                // Informed it was parsed as nothing... aka look at the raw
                // string.
                response.setParsedAs(null);
            }

        } else {
            if (args.getMethod() != RequestMethod.HEAD) {
                Log.w(RequestsConstants.LOG_TAG, "Entity is empty?");
            }
        }
    } catch (final ClientProtocolException e) {
        Log.e(RequestsConstants.LOG_TAG, "Client Protocol Exception", e);
    } catch (final IOException e) {
        Log.e(RequestsConstants.LOG_TAG, "IO Exception.", e);
    } finally {
    }

    return response;
}

From source file:org.camunda.connect.httpclient.impl.AbstractHttpConnector.java

@SuppressWarnings("unchecked")
protected <T extends HttpRequestBase> T createHttpRequestBase(Q request) {
    String url = request.getUrl();
    if (url != null && !url.trim().isEmpty()) {
        String method = request.getMethod();
        if (HttpGet.METHOD_NAME.equals(method)) {
            return (T) new HttpGet(url);
        } else if (HttpPost.METHOD_NAME.equals(method)) {
            return (T) new HttpPost(url);
        } else if (HttpPut.METHOD_NAME.equals(method)) {
            return (T) new HttpPut(url);
        } else if (HttpDelete.METHOD_NAME.equals(method)) {
            return (T) new HttpDelete(url);
        } else if (HttpPatch.METHOD_NAME.equals(method)) {
            return (T) new HttpPatch(url);
        } else if (HttpHead.METHOD_NAME.equals(method)) {
            return (T) new HttpHead(url);
        } else if (HttpOptions.METHOD_NAME.equals(method)) {
            return (T) new HttpOptions(url);
        } else if (HttpTrace.METHOD_NAME.equals(method)) {
            return (T) new HttpTrace(url);
        } else {/* w ww  .  j  ava 2 s  .com*/
            throw LOG.unknownHttpMethod(method);
        }
    } else {
        throw LOG.requestUrlRequired();
    }
}

From source file:org.craftercms.deployer.impl.processors.HttpMethodCallProcessor.java

protected HttpUriRequest createRequest() {
    if (method.equalsIgnoreCase("get")) {
        return new HttpGet(url);
    } else if (method.equalsIgnoreCase("post")) {
        return new HttpPost(url);
    } else if (method.equalsIgnoreCase("put")) {
        return new HttpPut(url);
    } else if (method.equalsIgnoreCase("delete")) {
        return new HttpDelete(url);
    } else if (method.equalsIgnoreCase("head")) {
        return new HttpHead(url);
    } else if (method.equalsIgnoreCase("options")) {
        return new HttpOptions(url);
    } else if (method.equalsIgnoreCase("trace")) {
        return new HttpTrace(url);
    } else {//from ww w.ja  v  a2 s  . c  o  m
        throw new DeploymentException("HTTP method '" + method + " not recognized");
    }
}

From source file:cn.bidaround.ytcore.util.HttpClientStack.java

/**
 * Creates the appropriate subclass of HttpUriRequest for passed in request.
 *///from w  w  w.  ja  v a 2 s. c  o  m
@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());
        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:cn.com.xxutils.volley.toolbox.HttpClientStack.java

/**
 * Creates the appropriate subclass of HttpUriRequest for passed in request.
 *///from  ww  w . j  av  a 2  s  . c  om
@SuppressWarnings("deprecation")
/* protected */ static HttpUriRequest createHttpRequest(Request<?> request,
        Map<String, String> additionalHeaders) throws 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.getPostBodyContentType());
            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 Request.Method.DELETE:
        return new HttpDelete(request.getUrl());
    case Request.Method.POST: {
        HttpPost postRequest = new HttpPost(request.getUrl());
        postRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType());
        setEntityIfNonEmptyBody(postRequest, request);
        return postRequest;
    }
    case Request.Method.PUT: {
        HttpPut putRequest = new HttpPut(request.getUrl());
        putRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType());
        setEntityIfNonEmptyBody(putRequest, request);
        return putRequest;
    }
    case Request.Method.HEAD:
        return new HttpHead(request.getUrl());
    case Request.Method.OPTIONS:
        return new HttpOptions(request.getUrl());
    case Request.Method.TRACE:
        return new HttpTrace(request.getUrl());
    case Request.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.selene.volley.stack.HttpClientStack.java

/**
 * Creates the appropriate subclass of HttpUriRequest for passed in request.
 *//* www  .j  a va  2  s  . c  om*/
@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());
        postRequest.addHeader(HTTP.CONTENT_TYPE, request.getBodyContentType());
        setEntityIfNonEmptyBody(postRequest, request);
        return postRequest;
    }
    case Method.PUT: {
        HttpPut putRequest = new HttpPut(request.getUrl());
        putRequest.addHeader(HTTP.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(HTTP.CONTENT_TYPE, request.getBodyContentType());
        setEntityIfNonEmptyBody(patchRequest, request);
        return patchRequest;
    }
    default:
        throw new IllegalStateException("Unknown request method.");
    }
}

From source file:com.iframe.source.publics.http.volley.toolbox.HttpClientStack.java

/**
 * Creates the appropriate subclass of HttpUriRequest for passed in request.
 *//* ww  w  .  j  a va 2 s  .  c  om*/
@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());
        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.");
    }
}