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.servoy.extensions.plugins.http.TraceRequest.java

public TraceRequest(String url, DefaultHttpClient hc, IClientPluginAccess plugin) {
    super(url, hc, new HttpTrace(url), plugin);
}

From source file:com.woonoz.proxy.servlet.HttpTraceRequestHandler.java

@Override
protected HttpRequestBase createHttpRequestBase(URI targetUri) {
    return new HttpTrace(targetUri);
}

From source file:org.megam.deccanplato.provider.crm.test.common.FileUploadTest.java

@Test
public void execute() throws ClientProtocolException, IOException {
    httpPost.setHeader("Authorization",
            "BoxAuth api_key=bvn29jldy2nnr7l3q03v5k8aalb4utt4&auth_token=34kssk9sxjrv6pliusyf83m58h9ul3sb");
    HttpTrace trace = new HttpTrace(Uri);
    System.out.println(httpClient);
    //httpClient.execute(httpPost);
    HttpResponse resp;// w  ww.ja  v a2s .c o  m
    System.out.println(httpPost.toString());
    resp = httpClient.execute(httpPost);

    System.out.println(
            resp.getStatusLine().getStatusCode() + ":::::" + resp.getEntity() + "::::::" + resp.getLocale());
    System.out.println("Location" + resp.getLastHeader("Location").getValue().toLowerCase());
    System.out.println("Location" + resp.getFirstHeader("Location").getValue().toLowerCase());
    if (resp.getStatusLine().getStatusCode() == 302) {
        String redirectURL = resp.getFirstHeader("Location").getValue();
        System.out.println(resp.getFirstHeader("Location").getValue());
    }

    InputStream in = resp.getEntity().getContent();

    FileOutputStream fos = new FileOutputStream(new File("/home/pandiyaraja/Documents/5979334871.txt"));

    byte[] buffer = new byte[4096];
    int length;
    while ((length = in.read(buffer)) > 0) {
        fos.write(buffer, 0, length);
    }
}

From source file:org.dojotoolkit.zazl.internal.XMLHttpRequestUtils.java

@SuppressWarnings({ "unchecked", "rawtypes" })
public static String xhrRequest(String shrDataString) {
    InputStream is = null;/*www . j a  v a2  s  .  c o  m*/
    String json = null;

    try {
        logger.logp(Level.FINER, XMLHttpRequestUtils.class.getName(), "xhrRequest",
                "shrDataString [" + shrDataString + "]");

        Map<String, Object> xhrData = (Map<String, Object>) JSONParser.parse(new StringReader(shrDataString));
        String url = (String) xhrData.get("url");
        String method = (String) xhrData.get("method");
        List headers = (List) xhrData.get("headers");
        URL requestURL = createURL(url);
        URI uri = new URI(requestURL.toString());

        HashMap httpMethods = new HashMap(7);
        httpMethods.put("DELETE", new HttpDelete(uri));
        httpMethods.put("GET", new HttpGet(uri));
        httpMethods.put("HEAD", new HttpHead(uri));
        httpMethods.put("OPTIONS", new HttpOptions(uri));
        httpMethods.put("POST", new HttpPost(uri));
        httpMethods.put("PUT", new HttpPut(uri));
        httpMethods.put("TRACE", new HttpTrace(uri));
        HttpUriRequest request = (HttpUriRequest) httpMethods.get(method.toUpperCase());

        if (request.equals(null)) {
            throw new Error("SYNTAX_ERR");
        }

        for (Object header : headers) {
            StringTokenizer st = new StringTokenizer((String) header, ":");
            String name = st.nextToken();
            String value = st.nextToken();
            request.addHeader(name, value);
        }

        HttpClient client = new DefaultHttpClient();

        HttpResponse response = client.execute(request);
        Map headerMap = new HashMap();

        HeaderIterator headerIter = response.headerIterator();

        while (headerIter.hasNext()) {
            Header header = headerIter.nextHeader();
            headerMap.put(header.getName(), header.getValue());
        }

        int status = response.getStatusLine().getStatusCode();
        String statusText = response.getStatusLine().toString();

        is = response.getEntity().getContent();
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        String line = null;
        StringBuffer sb = new StringBuffer();

        while ((line = br.readLine()) != null) {
            sb.append(line);
            sb.append('\n');
        }
        Map m = new HashMap();
        m.put("status", new Integer(status));
        m.put("statusText", statusText);
        m.put("responseText", sb.toString());
        m.put("headers", headerMap.toString());
        StringWriter w = new StringWriter();
        JSONSerializer.serialize(w, m);
        json = w.toString();
        logger.logp(Level.FINER, XMLHttpRequestUtils.class.getName(), "xhrRequest", "json [" + json + "]");
    } catch (Throwable e) {
        logger.logp(Level.SEVERE, XMLHttpRequestUtils.class.getName(), "xhrRequest",
                "Failed request for [" + shrDataString + "]", e);
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException e) {
            }
        }
    }
    return json;
}

From source file:com.helger.httpclient.HttpClientHelper.java

@Nonnull
public static HttpRequestBase createRequest(@Nonnull final EHttpMethod eHTTPMethod,
        @Nonnull final ISimpleURL aSimpleURL) {
    final String sURL = aSimpleURL.getAsStringWithEncodedParameters();
    switch (eHTTPMethod) {
    case DELETE://  w w  w.j  a  v a 2s . c  o m
        return new HttpDelete(sURL);
    case GET:
        return new HttpGet(sURL);
    case HEAD:
        return new HttpHead(sURL);
    case OPTIONS:
        return new HttpOptions(sURL);
    case TRACE:
        return new HttpTrace(sURL);
    case POST:
        return new HttpPost(sURL);
    case PUT:
        return new HttpPut(sURL);
    default:
        throw new IllegalStateException("Unsupported HTTP method: " + eHTTPMethod);
    }
}

From source file:org.apache.abdera2.common.protocol.RequestHelper.java

public static HttpUriRequest createRequest(String method, String uri, HttpEntity entity,
        RequestOptions options) {//from  w  w w.  j a v  a2 s . c o m
    if (method == null)
        return null;
    if (options == null)
        options = createAtomDefaultRequestOptions().get();
    Method m = Method.get(method);
    Method actual = null;
    HttpUriRequest httpMethod = null;
    if (options.isUsePostOverride() && !nopostoveride.contains(m)) {
        actual = m;
        m = Method.POST;
    }
    if (m == GET)
        httpMethod = new HttpGet(uri);
    else if (m == POST) {
        httpMethod = new HttpPost(uri);
        if (entity != null)
            ((HttpPost) httpMethod).setEntity(entity);
    } else if (m == PUT) {
        httpMethod = new HttpPut(uri);
        if (entity != null)
            ((HttpPut) httpMethod).setEntity(entity);
    } else if (m == DELETE)
        httpMethod = new HttpDelete(uri);
    else if (m == HEAD)
        httpMethod = new HttpHead(uri);
    else if (m == OPTIONS)
        httpMethod = new HttpOptions(uri);
    else if (m == TRACE)
        httpMethod = new HttpTrace(uri);
    //        else if (m == PATCH)
    //          httpMethod = new ExtensionRequest(m.name(),uri,entity);
    else
        httpMethod = new ExtensionRequest(m.name(), uri, entity);
    if (actual != null) {
        httpMethod.addHeader("X-HTTP-Method-Override", actual.name());
    }
    initHeaders(options, httpMethod);
    HttpParams params = httpMethod.getParams();
    if (!options.isUseExpectContinue()) {
        params.setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false);
    } else {
        if (options.getWaitForContinue() > -1)
            params.setIntParameter(CoreProtocolPNames.WAIT_FOR_CONTINUE, options.getWaitForContinue());
    }
    if (!(httpMethod instanceof HttpEntityEnclosingRequest))
        params.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, options.isFollowRedirects());
    return httpMethod;
}

From source file:org.gradle.internal.resource.transport.http.AlwaysRedirectRedirectStrategy.java

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 {/*  ww w  .  j  a  v  a  2 s  .c om*/
        return new HttpGet(uri);
    }
}

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

/**
 * @param uri/*  w  w w.  jav a 2  s .  c  om*/
 * @param method
 * @return
 */
private static HttpUriRequest createRequest(URI uri, String method) {
    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);
    }

    return null;
}

From source file:org.jboss.as.test.integration.web.security.servlet.methods.DenyUncoveredHttpMethodsTestCase.java

@Test
public void testTraceMethod() throws Exception {
    HttpTrace httpTrace = new HttpTrace(getURL());
    HttpResponse response = getHttpResponse(httpTrace);

    assertThat(statusCodeOf(response), is(HttpServletResponse.SC_METHOD_NOT_ALLOWED));
}