org.apache.http.client.methods.HttpTrace Java Examples

The following examples show how to use org.apache.http.client.methods.HttpTrace. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpComponentsClientHttpRequestFactory.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Create a Commons HttpMethodBase object for the given HTTP method and URI specification.
 * @param httpMethod the HTTP method
 * @param uri the URI
 * @return the Commons HttpMethodBase object
 */
protected HttpUriRequest createHttpUriRequest(HttpMethod httpMethod, URI uri) {
	switch (httpMethod) {
		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 PATCH:
			return new HttpPatch(uri);
		case DELETE:
			return new HttpDelete(uri);
		case OPTIONS:
			return new HttpOptions(uri);
		case TRACE:
			return new HttpTrace(uri);
		default:
			throw new IllegalArgumentException("Invalid HTTP method: " + httpMethod);
	}
}
 
Example #2
Source File: RequestUtils.java    From RoboZombie with Apache License 2.0 6 votes vote down vote up
/**
 * <p>Retrieves the proper extension of {@link HttpRequestBase} for the given {@link InvocationContext}. 
 * This implementation is solely dependent upon the {@link RequestMethod} property in the annotated 
 * metdata of the endpoint method definition.</p>
 *
 * @param context
 * 			the {@link InvocationContext} for which a {@link HttpRequestBase} is to be generated 
 * <br><br>
 * @return the {@link HttpRequestBase} translated from the {@link InvocationContext}'s {@link RequestMethod}
 * <br><br>
 * @throws NullPointerException
 * 			if the supplied {@link InvocationContext} was {@code null} 
 * <br><br>
 * @since 1.3.0
 */
static HttpRequestBase translateRequestMethod(InvocationContext context) {
	
	RequestMethod requestMethod = Metadata.findMethod(assertNotNull(context).getRequest());
	
	switch (requestMethod) {
	
		case POST: return new HttpPost();
		case PUT: return new HttpPut();
		case PATCH: return new HttpPatch();
		case DELETE: return new HttpDelete();
		case HEAD: return new HttpHead();
		case TRACE: return new HttpTrace();
		case OPTIONS: return new HttpOptions();
		
		case GET: default: return new HttpGet();
	}
}
 
Example #3
Source File: cfHttpConnection.java    From openbd-core with GNU General Public License v3.0 6 votes vote down vote up
private HttpUriRequest resolveMethod( String _method, boolean _multipart ) throws cfmRunTimeException {
	String method = _method.toUpperCase();
	if ( method.equals( "GET" ) ) {
		return new HttpGet();
	} else if ( method.equals( "POST" ) ) {
		return new HttpPost();
	} else if ( method.equals( "HEAD" ) ) {
		return new HttpHead();
	} else if ( method.equals( "TRACE" ) ) {
		return new HttpTrace();
	} else if ( method.equals( "DELETE" ) ) {
		return new HttpDelete();
	} else if ( method.equals( "OPTIONS" ) ) {
		return new HttpOptions();
	} else if ( method.equals( "PUT" ) ) {
		return new HttpPut();
	} else if ( method.equals( "PATCH" ) ) {
		return new HttpPatch();
	}
	throw newRunTimeException( "Unsupported METHOD value [" + method + "]. Valid METHOD values are GET, POST, HEAD, TRACE, DELETE, OPTIONS, PATCH and PUT." );
}
 
Example #4
Source File: ClientImpl.java    From datamill with ISC License 6 votes vote down vote up
protected HttpUriRequest buildHttpRequest(Method method, URI uri) {
    switch (method) {
        case OPTIONS:
            return new HttpOptions(uri);
        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 PATCH:
            return new HttpPatch(uri);
        default:
            throw new IllegalArgumentException("Method " + method + " is not implemented!");
    }
}
 
Example #5
Source File: HttpComponentsRequestFactory.java    From fahrschein with Apache License 2.0 6 votes vote down vote up
/**
 * Create a Commons HttpMethodBase object for the given HTTP method and URI specification.
 * @param method the HTTP method
 * @param uri the URI
 * @return the Commons HttpMethodBase object
 */
private static HttpUriRequest createHttpUriRequest(String method, URI uri) {
    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 "PATCH":
            return new HttpPatch(uri);
        case "DELETE":
            return new HttpDelete(uri);
        case "OPTIONS":
            return new HttpOptions(uri);
        case "TRACE":
            return new HttpTrace(uri);
        default:
            throw new IllegalArgumentException("Invalid HTTP method: " + method);
    }
}
 
Example #6
Source File: JDiscHttpServletTest.java    From vespa with Apache License 2.0 6 votes vote down vote up
@Test
public void requireThatServerRespondsToAllMethods() throws Exception {
    final TestDriver driver = TestDrivers.newInstance(newEchoHandler());
    final URI uri = driver.client().newUri("/status.html");
    driver.client().execute(new HttpGet(uri))
          .expectStatusCode(is(OK));
    driver.client().execute(new HttpPost(uri))
          .expectStatusCode(is(OK));
    driver.client().execute(new HttpHead(uri))
          .expectStatusCode(is(OK));
    driver.client().execute(new HttpPut(uri))
          .expectStatusCode(is(OK));
    driver.client().execute(new HttpDelete(uri))
          .expectStatusCode(is(OK));
    driver.client().execute(new HttpOptions(uri))
          .expectStatusCode(is(OK));
    driver.client().execute(new HttpTrace(uri))
          .expectStatusCode(is(OK));
    driver.client().execute(new HttpPatch(uri))
            .expectStatusCode(is(OK));
    assertThat(driver.close(), is(true));
}
 
Example #7
Source File: HttpComponentsClientHttpRequestFactory.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Create a Commons HttpMethodBase object for the given HTTP method and URI specification.
 * @param httpMethod the HTTP method
 * @param uri the URI
 * @return the Commons HttpMethodBase object
 */
protected HttpUriRequest createHttpUriRequest(HttpMethod httpMethod, URI uri) {
	switch (httpMethod) {
		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 PATCH:
			return new HttpPatch(uri);
		case DELETE:
			return new HttpDelete(uri);
		case OPTIONS:
			return new HttpOptions(uri);
		case TRACE:
			return new HttpTrace(uri);
		default:
			throw new IllegalArgumentException("Invalid HTTP method: " + httpMethod);
	}
}
 
Example #8
Source File: HttpComponentsClientHttpRequestFactory.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create a Commons HttpMethodBase object for the given HTTP method and URI specification.
 * @param httpMethod the HTTP method
 * @param uri the URI
 * @return the Commons HttpMethodBase object
 */
protected HttpUriRequest createHttpUriRequest(HttpMethod httpMethod, URI uri) {
	switch (httpMethod) {
		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 PATCH:
			return new HttpPatch(uri);
		case DELETE:
			return new HttpDelete(uri);
		case OPTIONS:
			return new HttpOptions(uri);
		case TRACE:
			return new HttpTrace(uri);
		default:
			throw new IllegalArgumentException("Invalid HTTP method: " + httpMethod);
	}
}
 
Example #9
Source File: HttpComponentsClientHttpRequestFactory.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Create a Commons HttpMethodBase object for the given HTTP method and URI specification.
 * @param httpMethod the HTTP method
 * @param uri the URI
 * @return the Commons HttpMethodBase object
 */
protected HttpUriRequest createHttpUriRequest(HttpMethod httpMethod, URI uri) {
	switch (httpMethod) {
		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 PATCH:
			return new HttpPatch(uri);
		case DELETE:
			return new HttpDelete(uri);
		case OPTIONS:
			return new HttpOptions(uri);
		case TRACE:
			return new HttpTrace(uri);
		default:
			throw new IllegalArgumentException("Invalid HTTP method: " + httpMethod);
	}
}
 
Example #10
Source File: HttpMethodTests.java    From vividus with Apache License 2.0 5 votes vote down vote up
static Stream<Arguments> successfulEmptyRequestCreation()
{
    return Stream.of(
            Arguments.of(HttpMethod.GET, HttpGet.class),
            Arguments.of(HttpMethod.HEAD, HttpHead.class),
            Arguments.of(HttpMethod.DELETE, HttpDelete.class),
            Arguments.of(HttpMethod.OPTIONS, HttpOptions.class),
            Arguments.of(HttpMethod.TRACE, HttpTrace.class),
            Arguments.of(HttpMethod.POST, HttpPost.class),
            Arguments.of(HttpMethod.PUT, HttpPutWithoutBody.class),
            Arguments.of(HttpMethod.DEBUG, HttpDebug.class)
    );
}
 
Example #11
Source File: HttpClientStackTest.java    From device-database with Apache License 2.0 5 votes vote down vote up
@Test public void createTraceRequest() throws Exception {
    TestRequest.Trace request = new TestRequest.Trace();
    assertEquals(request.getMethod(), Method.TRACE);

    HttpUriRequest httpRequest = HttpClientStack.createHttpRequest(request, null);
    assertTrue(httpRequest instanceof HttpTrace);
}
 
Example #12
Source File: HttpClientStackTest.java    From CrossBow with Apache License 2.0 5 votes vote down vote up
@Test public void createTraceRequest() throws Exception {
    TestRequest.Trace request = new TestRequest.Trace();
    assertEquals(request.getMethod(), Method.TRACE);

    HttpUriRequest httpRequest = HttpClientStack.createHttpRequest(request, null);
    assertTrue(httpRequest instanceof HttpTrace);
}
 
Example #13
Source File: WebConsoleSecurityTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testTrace() throws Exception {
    final HttpURLConnection connection = getConnection();
    connection.setRequestMethod(HttpTrace.METHOD_NAME);
    connection.connect();
    assertEquals(HttpURLConnection.HTTP_UNAUTHORIZED, connection.getResponseCode());
}
 
Example #14
Source File: ApacheHttpStack.java    From jus with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the appropriate subclass of HttpUriRequest for passed in request.
 */
static HttpRequestBase createHttpRequest(
        Request<?> request, Map<String, String> additionalHeaders) {
    switch (request.getMethod()) {
        case Request.Method.GET:
            return new HttpGet(request.getUrlString());
        case Request.Method.DELETE:
            return new HttpDelete(request.getUrlString());
        case Request.Method.POST: {
            HttpPost postRequest = new HttpPost(request.getUrlString());
            postRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType());
            setEntityIfNonEmptyBody(postRequest, request);
            return postRequest;
        }
        case Request.Method.PUT: {
            HttpPut putRequest = new HttpPut(request.getUrlString());
            putRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType());
            setEntityIfNonEmptyBody(putRequest, request);
            return putRequest;
        }
        case Request.Method.HEAD:
            return new HttpHead(request.getUrlString());
        case Request.Method.OPTIONS:
            return new HttpOptions(request.getUrlString());
        case Request.Method.TRACE:
            return new HttpTrace(request.getUrlString());
        case Request.Method.PATCH: {
            HttpPatch patchRequest = new HttpPatch(request.getUrlString());
            patchRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType());
            setEntityIfNonEmptyBody(patchRequest, request);
            return patchRequest;
        }
        default:
            throw new IllegalStateException("Unknown request method.");
    }
}
 
Example #15
Source File: HttpServiceImpl.java    From container with Apache License 2.0 5 votes vote down vote up
@Override
public HttpResponse Trace(final String uri) throws IOException {
    DefaultHttpClient client = new DefaultHttpClient();
    client.setRedirectStrategy(new LaxRedirectStrategy());
    final HttpTrace trace = new HttpTrace(uri);
    final HttpResponse response = client.execute(trace);
    return response;
}
 
Example #16
Source File: CustomRedirectStrategy.java    From neembuu-uploader with GNU General Public License v3.0 5 votes vote down vote up
@Override
public HttpUriRequest getRedirect(
        final HttpRequest request,
        final HttpResponse response,
        final HttpContext context) throws ProtocolException {
    URI uri = null;
    try {
        uri = getLocationURI(request, response, context);
    } catch (URISyntaxException ex) {
        Logger.getLogger(CustomRedirectStrategy.class.getName()).log(Level.SEVERE, null, ex);
    }
    String method = request.getRequestLine().getMethod();
    if (method.equalsIgnoreCase(HttpHead.METHOD_NAME)) {
        return new HttpHead(uri);
    } else if (method.equalsIgnoreCase(HttpGet.METHOD_NAME)) {
        return new HttpGet(uri);
    } else {
        int status = response.getStatusLine().getStatusCode();
        if (status == HttpStatus.SC_TEMPORARY_REDIRECT) {
            if (method.equalsIgnoreCase(HttpPost.METHOD_NAME)) {
                return copyEntity(new HttpPost(uri), request);
            } else if (method.equalsIgnoreCase(HttpPut.METHOD_NAME)) {
                return 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 copyEntity(new HttpPatch(uri), request);
            }
        }
        return new HttpGet(uri);
    }
}
 
Example #17
Source File: HttpClientStackTest.java    From product-emm with Apache License 2.0 5 votes vote down vote up
@Test public void createTraceRequest() throws Exception {
    TestRequest.Trace request = new TestRequest.Trace();
    assertEquals(request.getMethod(), Method.TRACE);

    HttpUriRequest httpRequest = HttpClientStack.createHttpRequest(request, null);
    assertTrue(httpRequest instanceof HttpTrace);
}
 
Example #18
Source File: HttpClientStackTest.java    From product-emm with Apache License 2.0 5 votes vote down vote up
@Test public void createTraceRequest() throws Exception {
    TestRequest.Trace request = new TestRequest.Trace();
    assertEquals(request.getMethod(), Method.TRACE);

    HttpUriRequest httpRequest = HttpClientStack.createHttpRequest(request, null);
    assertTrue(httpRequest instanceof HttpTrace);
}
 
Example #19
Source File: HttpClientStackTest.java    From volley with Apache License 2.0 5 votes vote down vote up
@Test
public void createTraceRequest() throws Exception {
    TestRequest.Trace request = new TestRequest.Trace();
    assertEquals(request.getMethod(), Method.TRACE);

    HttpUriRequest httpRequest = HttpClientStack.createHttpRequest(request, null);
    assertTrue(httpRequest instanceof HttpTrace);
}
 
Example #20
Source File: HttpClientStackTest.java    From android-project-wo2b with Apache License 2.0 5 votes vote down vote up
public void testCreateTraceRequest() throws Exception {
    TestRequest.Trace request = new TestRequest.Trace();
    assertEquals(request.getMethod(), Method.TRACE);

    HttpUriRequest httpRequest = HttpClientStack.createHttpRequest(request, null);
    assertTrue(httpRequest instanceof HttpTrace);
}
 
Example #21
Source File: HttpClientStackTest.java    From SaveVolley with Apache License 2.0 5 votes vote down vote up
@Test public void createTraceRequest() throws Exception {
    TestRequest.Trace request = new TestRequest.Trace();
    assertEquals(request.getMethod(), Method.TRACE);

    HttpUriRequest httpRequest = HttpClientStack.createHttpRequest(request, null);
    assertTrue(httpRequest instanceof HttpTrace);
}
 
Example #22
Source File: HttpClientImpl.java    From nano-framework with Apache License 2.0 4 votes vote down vote up
@Override
public HttpResponse trace(final String url) throws HttpClientException {
    return process(new HttpTrace(url));
}
 
Example #23
Source File: HttpClientImpl.java    From nano-framework with Apache License 2.0 4 votes vote down vote up
@Override
public HttpResponse trace(final String url, final Map<String, String> params) throws HttpClientException {
    return process(createBase(HttpTrace.class, url, params));
}
 
Example #24
Source File: HttpClientImpl.java    From nano-framework with Apache License 2.0 4 votes vote down vote up
@Override
public HttpResponse trace(final String url, final Map<String, String> headers, final Map<String, String> params) throws HttpClientException {
    return process(createBase(HttpTrace.class, url, headers, params));
}
 
Example #25
Source File: HttpToolIntegrationTest.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
@Test(expectedExceptions = PropagatedRuntimeException.class)
public void testHttpRequestBuilderThrowsExIfBodySetForTrace() throws Exception {
    new HttpTool.HttpRequestBuilder<>(HttpTrace.class).body("test").build();
}