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:org.soyatec.windowsazure.internal.util.HttpUtilities.java

/**
 * Create a httpRequest with the uri and method.
 * /*  w  w w  .  j av a 2s .  co m*/
 * @param uri
 * @param method
 * @return HttpUriRequest
 */
public static HttpUriRequest createHttpRequest(URI uri, String method) {
    HttpUriRequest request;
    if (method.equals(HttpMethod.Get)) {
        request = new HttpGet(uri);
    } else if (method.equals(HttpMethod.Post)) {
        request = new HttpPost(uri);
    } else if (method.equals(HttpMethod.Delete)) {
        request = new HttpDelete(uri);
    } else if (method.equals(HttpMethod.Head)) {
        request = new HttpHead(uri);
    } else if (method.equals(HttpMethod.Options)) {
        request = new HttpOptions(uri);
    } else if (method.equals(HttpMethod.Put)) {
        request = new HttpPut(uri);
    } else if (method.equals(HttpMethod.Trace)) {
        request = new HttpTrace(uri);
    } else if (method.equals(HttpMerge.METHOD_NAME)) {
        request = new HttpMerge(uri);
    } else {
        throw new IllegalArgumentException(MessageFormat.format("{0} is not a valid HTTP method.", method));
    }
    return request;
}

From source file:com.machinepublishers.jbrowserdriver.StreamConnection.java

/**
 * {@inheritDoc}//from www.  j a  va 2s .co m
 */
@Override
public void connect() throws IOException {
    try {
        if (connected.compareAndSet(false, true)) {
            if (StatusMonitor.instance().isDiscarded(urlString)) {
                skip.set(true);
                LogsServer.instance().trace("Media skipped: " + urlString);
            } else if (isBlocked(url.getHost())) {
                skip.set(true);
            } else if (SettingsManager.settings() != null) {
                config.get().setCookieSpec("custom")
                        .setSocketTimeout(SettingsManager.settings().socketTimeout())
                        .setConnectTimeout(SettingsManager.settings().connectTimeout())
                        .setConnectionRequestTimeout(SettingsManager.settings().connectionReqTimeout());
                URI uri = null;
                try {
                    uri = url.toURI();
                } catch (URISyntaxException e) {
                    //decode components of the url first, because often the problem is partially encoded urls
                    uri = new URI(url.getProtocol(), url.getAuthority(),
                            url.getPath() == null ? null : URLDecoder.decode(url.getPath(), "utf-8"),
                            url.getQuery() == null ? null : URLDecoder.decode(url.getQuery(), "utf-8"),
                            url.getRef() == null ? null : URLDecoder.decode(url.getRef(), "utf-8"));
                }
                if ("OPTIONS".equals(method.get())) {
                    req.set(new HttpOptions(uri));
                } else if ("GET".equals(method.get())) {
                    req.set(new HttpGet(uri));
                } else if ("HEAD".equals(method.get())) {
                    req.set(new HttpHead(uri));
                } else if ("POST".equals(method.get())) {
                    req.set(new HttpPost(uri));
                } else if ("PUT".equals(method.get())) {
                    req.set(new HttpPut(uri));
                } else if ("DELETE".equals(method.get())) {
                    req.set(new HttpDelete(uri));
                } else if ("TRACE".equals(method.get())) {
                    req.set(new HttpTrace(uri));
                }
                processHeaders(SettingsManager.settings(), req.get());
                ProxyConfig proxy = SettingsManager.settings().proxy();
                if (proxy != null && !proxy.directConnection()
                        && !proxy.nonProxyHosts().contains(uri.getHost())) {
                    config.get().setExpectContinueEnabled(proxy.expectContinue());
                    InetSocketAddress proxyAddress = new InetSocketAddress(proxy.host(), proxy.port());
                    if (proxy.type() == ProxyConfig.Type.SOCKS) {
                        context.get().setAttribute("proxy.socks.address", proxyAddress);
                    } else {
                        config.get().setProxy(new HttpHost(proxy.host(), proxy.port()));
                    }
                }
                context.get().setCookieStore(cookieStore);
                context.get().setRequestConfig(config.get().build());
                StatusMonitor.instance().monitor(url, this);
            }
        }
    } catch (Throwable t) {
        throw new IOException(t.getMessage() + ": " + urlString, t);
    }
}

From source file:anhttpclient.impl.DefaultWebBrowser.java

/**
 * {@inheritDoc}//from   www .  ja  v  a 2  s .  c om
 */
public WebResponse getResponse(WebRequest webRequest, String charset) throws IOException {
    initHttpClient();

    switch (webRequest.getRequestMethod()) {
    case GET:
        httpRequest.set(populateHttpRequestBaseMethod(webRequest, new HttpGet(webRequest.getUrl())));
        break;
    case HEAD:
        httpRequest.set(populateHttpRequestBaseMethod(webRequest, new HttpHead(webRequest.getUrl())));
        break;
    case OPTIONS:
        httpRequest.set(populateHttpRequestBaseMethod(webRequest, new HttpOptions(webRequest.getUrl())));
        break;
    case TRACE:
        httpRequest.set(populateHttpRequestBaseMethod(webRequest, new HttpTrace(webRequest.getUrl())));
        break;
    case DELETE:
        httpRequest.set(populateHttpRequestBaseMethod(webRequest, new HttpDelete(webRequest.getUrl())));
        break;
    case POST:
        httpRequest.set(
                populateHttpEntityEnclosingRequestBaseMethod(webRequest, new HttpPost(webRequest.getUrl())));
        break;
    case PUT:
        httpRequest.set(
                populateHttpEntityEnclosingRequestBaseMethod(webRequest, new HttpPut(webRequest.getUrl())));
        break;
    default:
        throw new RuntimeException("Method not yet supported: " + webRequest.getRequestMethod());
    }

    WebResponse resp;

    HttpResponse response = executeMethod(httpRequest.get());
    if (response == null) {
        throw new IOException(
                "ANHTTPCLIENT. An empty response received from server. Possible reason: host is offline");
    }

    resp = processResponse(response, httpRequest.get(), charset);
    httpRequest.set(null);
    return resp;
}

From source file:com.gargoylesoftware.htmlunit.HttpWebConnection.java

/**
 * Creates and returns a new HttpClient HTTP method based on the specified parameters.
 * @param submitMethod the submit method being used
 * @param uri the uri being used//w  w w  . ja  v  a2 s . c om
 * @return a new HttpClient HTTP method based on the specified parameters
 */
private static HttpRequestBase buildHttpMethod(final HttpMethod submitMethod, final URI uri) {
    final HttpRequestBase method;
    switch (submitMethod) {
    case GET:
        method = new HttpGet(uri);
        break;

    case POST:
        method = new HttpPost(uri);
        break;

    case PUT:
        method = new HttpPut(uri);
        break;

    case DELETE:
        method = new HttpDelete(uri);
        break;

    case OPTIONS:
        method = new HttpOptions(uri);
        break;

    case HEAD:
        method = new HttpHead(uri);
        break;

    case TRACE:
        method = new HttpTrace(uri);
        break;

    case PATCH:
        method = new HttpPatch(uri);
        break;

    default:
        throw new IllegalStateException("Submit method not yet supported: " + submitMethod);
    }
    return method;
}

From source file:com.github.restdriver.clientdriver.integration.ClientDriverSuccessTest.java

@Test
public void testHttpTRACE() throws ClientProtocolException, IOException {

    String baseUrl = driver.getBaseUrl();
    driver.addExpectation(onRequestTo("/blah2").withMethod(Method.TRACE),
            giveResponse(null, null).withStatus(200));

    HttpClient client = new DefaultHttpClient();
    HttpTrace trace = new HttpTrace(baseUrl + "/blah2");
    HttpResponse response = client.execute(trace);

    assertThat(response.getStatusLine().getStatusCode(), is(200));
}

From source file:org.elasticsearch.client.RestClientSingleHostTests.java

private HttpUriRequest performRandomRequest(String method) throws Exception {
    String uriAsString = "/" + randomStatusCode(getRandom());
    URIBuilder uriBuilder = new URIBuilder(uriAsString);
    final Map<String, String> params = new HashMap<>();
    boolean hasParams = randomBoolean();
    if (hasParams) {
        int numParams = randomIntBetween(1, 3);
        for (int i = 0; i < numParams; i++) {
            String paramKey = "param-" + i;
            String paramValue = randomAsciiOfLengthBetween(3, 10);
            params.put(paramKey, paramValue);
            uriBuilder.addParameter(paramKey, paramValue);
        }/*from  w  w  w  .ja  va 2s. c o  m*/
    }
    if (randomBoolean()) {
        //randomly add some ignore parameter, which doesn't get sent as part of the request
        String ignore = Integer.toString(randomFrom(RestClientTestUtil.getAllErrorStatusCodes()));
        if (randomBoolean()) {
            ignore += "," + Integer.toString(randomFrom(RestClientTestUtil.getAllErrorStatusCodes()));
        }
        params.put("ignore", ignore);
    }
    URI uri = uriBuilder.build();

    HttpUriRequest request;
    switch (method) {
    case "DELETE":
        request = new HttpDeleteWithEntity(uri);
        break;
    case "GET":
        request = new HttpGetWithEntity(uri);
        break;
    case "HEAD":
        request = new HttpHead(uri);
        break;
    case "OPTIONS":
        request = new HttpOptions(uri);
        break;
    case "PATCH":
        request = new HttpPatch(uri);
        break;
    case "POST":
        request = new HttpPost(uri);
        break;
    case "PUT":
        request = new HttpPut(uri);
        break;
    case "TRACE":
        request = new HttpTrace(uri);
        break;
    default:
        throw new UnsupportedOperationException("method not supported: " + method);
    }

    HttpEntity entity = null;
    boolean hasBody = request instanceof HttpEntityEnclosingRequest && getRandom().nextBoolean();
    if (hasBody) {
        entity = new StringEntity(randomAsciiOfLengthBetween(10, 100), ContentType.APPLICATION_JSON);
        ((HttpEntityEnclosingRequest) request).setEntity(entity);
    }

    Header[] headers = new Header[0];
    final Set<String> uniqueNames = new HashSet<>();
    if (randomBoolean()) {
        headers = RestClientTestUtil.randomHeaders(getRandom(), "Header");
        for (Header header : headers) {
            request.addHeader(header);
            uniqueNames.add(header.getName());
        }
    }
    for (Header defaultHeader : defaultHeaders) {
        // request level headers override default headers
        if (uniqueNames.contains(defaultHeader.getName()) == false) {
            request.addHeader(defaultHeader);
        }
    }

    try {
        if (hasParams == false && hasBody == false && randomBoolean()) {
            restClient.performRequest(method, uriAsString, headers);
        } else if (hasBody == false && randomBoolean()) {
            restClient.performRequest(method, uriAsString, params, headers);
        } else {
            restClient.performRequest(method, uriAsString, params, entity, headers);
        }
    } catch (ResponseException e) {
        //all good
    }
    return request;
}

From source file:com.sat.vcse.automation.utils.http.HttpClient.java

/**
 * TRACE request to a server/*from  www . jav  a 2 s . c o  m*/
 * @return CoreResponse
 */
public CoreResponse trace() {
    final String METHOD_NAME = "trace(): ";

    try {
        // Build the request
        CloseableHttpClient client = getClient();
        // Instantiate a TRACE Request and define the Target URL
        HttpRequestBase httpRequestBase = new HttpTrace(this.targetURL);
        // Build the HTTP request header from the HeadersMap
        addHeader(httpRequestBase);

        // Execute the request and parse the Response
        return executeRequest(client, httpRequestBase);

    } catch (IOException exp) {
        LogHandler.error(CLASS_NAME + METHOD_NAME + "Exception: " + exp.getMessage());
        throw new CoreRuntimeException(exp, CLASS_NAME + METHOD_NAME + exp.getMessage());
    }
}

From source file:org.dasein.cloud.azure.AzureMethod.java

protected HttpRequestBase getMethod(String httpMethod, String url) {
    HttpRequestBase method = null;/*from ww w  .ja v a  2 s . c o m*/
    if (httpMethod.equals("GET")) {
        method = new HttpGet(url);
    } else if (httpMethod.equals("POST")) {
        method = new HttpPost(url);
    } else if (httpMethod.equals("PUT")) {
        method = new HttpPut(url);
    } else if (httpMethod.equals("DELETE")) {
        method = new HttpDelete(url);
    } else if (httpMethod.equals("HEAD")) {
        method = new HttpHead(url);
    } else if (httpMethod.equals("OPTIONS")) {
        method = new HttpOptions(url);
    } else if (httpMethod.equals("HEAD")) {
        method = new HttpTrace(url);
    } else {
        method = new HttpGet(url);
    }
    return method;
}