Example usage for io.netty.handler.codec.http HttpMethod TRACE

List of usage examples for io.netty.handler.codec.http HttpMethod TRACE

Introduction

In this page you can find the example usage for io.netty.handler.codec.http HttpMethod TRACE.

Prototype

HttpMethod TRACE

To view the source code for io.netty.handler.codec.http HttpMethod TRACE.

Click Source Link

Document

The TRACE method is used to invoke a remote, application-layer loop- back of the request message.

Usage

From source file:com.github.ambry.rest.NettyRequestTest.java

License:Open Source License

/**
 * Tests conversion of {@link HttpRequest} to {@link NettyRequest} given bad input (i.e. checks for the correct
 * exception and {@link RestServiceErrorCode} if any).
 * @throws RestServiceException//from   ww  w  . j  a  v a 2s  .  co  m
 */
@Test
public void conversionWithBadInputTest() throws RestServiceException {
    // HttpRequest null.
    try {
        new NettyRequest(null, new NettyMetrics(new MetricRegistry()));
        fail("Provided null HttpRequest to NettyRequest, yet it did not fail");
    } catch (IllegalArgumentException e) {
        // expected. nothing to do.
    }

    // unknown http method
    try {
        createNettyRequest(HttpMethod.TRACE, "/", null);
        fail("Unknown http method was supplied to NettyRequest. It should have failed to construct");
    } catch (RestServiceException e) {
        assertEquals("Unexpected RestServiceErrorCode", RestServiceErrorCode.UnsupportedHttpMethod,
                e.getErrorCode());
    }
}

From source file:com.github.jonbonazza.puni.core.mux.DefaultMuxer.java

License:Apache License

public DefaultMuxer() {
    methodMap.put(HttpMethod.CONNECT, new HashMap<>());
    methodMap.put(HttpMethod.DELETE, new HashMap<>());
    methodMap.put(HttpMethod.GET, new HashMap<>());
    methodMap.put(HttpMethod.HEAD, new HashMap<>());
    methodMap.put(HttpMethod.OPTIONS, new HashMap<>());
    methodMap.put(HttpMethod.PATCH, new HashMap<>());
    methodMap.put(HttpMethod.POST, new HashMap<>());
    methodMap.put(HttpMethod.PUT, new HashMap<>());
    methodMap.put(HttpMethod.TRACE, new HashMap<>());
}

From source file:com.rackspacecloud.blueflood.http.RouteMatcher.java

License:Apache License

public void route(ChannelHandlerContext context, FullHttpRequest request) {
    final String method = request.getMethod().name();
    final String URI = request.getUri();

    // Method not implemented for any resource. So return 501.
    if (method == null || !implementedVerbs.contains(method)) {
        route(context, request, unsupportedVerbsHandler);
        return;//w w w.  j a  v a2s .  c o m
    }

    final Pattern pattern = getMatchingPatternForURL(URI);

    // No methods registered for this pattern i.e. URL isn't registered. Return 404.
    if (pattern == null) {
        route(context, request, noRouteHandler);
        return;
    }

    final Set<String> supportedMethods = getSupportedMethods(pattern);
    if (supportedMethods == null) {
        log.warn("No supported methods registered for a known pattern " + pattern);
        route(context, request, noRouteHandler);
        return;
    }

    // The method requested is not available for the resource. Return 405.
    if (!supportedMethods.contains(method)) {
        route(context, request, unsupportedMethodHandler);
        return;
    }
    PatternRouteBinding binding = null;
    if (method.equals(HttpMethod.GET.name())) {
        binding = getBindings.get(pattern);
    } else if (method.equals(HttpMethod.PUT.name())) {
        binding = putBindings.get(pattern);
    } else if (method.equals(HttpMethod.POST.name())) {
        binding = postBindings.get(pattern);
    } else if (method.equals(HttpMethod.DELETE.name())) {
        binding = deleteBindings.get(pattern);
    } else if (method.equals(HttpMethod.PATCH.name())) {
        binding = deleteBindings.get(pattern);
    } else if (method.equals(HttpMethod.OPTIONS.name())) {
        binding = optionsBindings.get(pattern);
    } else if (method.equals(HttpMethod.HEAD.name())) {
        binding = headBindings.get(pattern);
    } else if (method.equals(HttpMethod.TRACE.name())) {
        binding = traceBindings.get(pattern);
    } else if (method.equals(HttpMethod.CONNECT.name())) {
        binding = connectBindings.get(pattern);
    }

    if (binding != null) {
        request = updateRequestHeaders(request, binding);
        route(context, request, binding.handler);
    } else {
        throw new RuntimeException("Cannot find a valid binding for URL " + URI);
    }
}

From source file:io.advantageous.conekt.http.impl.HttpClientRequestImpl.java

License:Open Source License

private HttpMethod toNettyHttpMethod(io.advantageous.conekt.http.HttpMethod method) {
    switch (method) {
    case CONNECT: {
        return HttpMethod.CONNECT;
    }/*from   www. ja v  a 2s. c o  m*/
    case GET: {
        return HttpMethod.GET;
    }
    case PUT: {
        return HttpMethod.PUT;
    }
    case POST: {
        return HttpMethod.POST;
    }
    case DELETE: {
        return HttpMethod.DELETE;
    }
    case HEAD: {
        return HttpMethod.HEAD;
    }
    case OPTIONS: {
        return HttpMethod.OPTIONS;
    }
    case TRACE: {
        return HttpMethod.TRACE;
    }
    case PATCH: {
        return HttpMethod.PATCH;
    }
    default:
        throw new IllegalArgumentException();
    }
}

From source file:io.vertx.core.http.impl.HttpUtils.java

License:Open Source License

static HttpMethod toNettyHttpMethod(io.vertx.core.http.HttpMethod method, String rawMethod) {
    switch (method) {
    case CONNECT: {
        return HttpMethod.CONNECT;
    }//  w  ww  . j  a  va 2 s. c o m
    case GET: {
        return HttpMethod.GET;
    }
    case PUT: {
        return HttpMethod.PUT;
    }
    case POST: {
        return HttpMethod.POST;
    }
    case DELETE: {
        return HttpMethod.DELETE;
    }
    case HEAD: {
        return HttpMethod.HEAD;
    }
    case OPTIONS: {
        return HttpMethod.OPTIONS;
    }
    case TRACE: {
        return HttpMethod.TRACE;
    }
    case PATCH: {
        return HttpMethod.PATCH;
    }
    default: {
        return HttpMethod.valueOf(rawMethod);
    }
    }
}

From source file:org.asynchttpclient.Dsl.java

License:Open Source License

public static RequestBuilder trace(String url) {
    return request(HttpMethod.TRACE.name(), url);
}

From source file:org.elasticsearch.http.nio.NioHttpRequest.java

License:Apache License

@Override
public RestRequest.Method method() {
    HttpMethod httpMethod = request.method();
    if (httpMethod == HttpMethod.GET)
        return RestRequest.Method.GET;

    if (httpMethod == HttpMethod.POST)
        return RestRequest.Method.POST;

    if (httpMethod == HttpMethod.PUT)
        return RestRequest.Method.PUT;

    if (httpMethod == HttpMethod.DELETE)
        return RestRequest.Method.DELETE;

    if (httpMethod == HttpMethod.HEAD) {
        return RestRequest.Method.HEAD;
    }/*w  w w.  j  a v a 2 s.co  m*/

    if (httpMethod == HttpMethod.OPTIONS) {
        return RestRequest.Method.OPTIONS;
    }

    if (httpMethod == HttpMethod.PATCH) {
        return RestRequest.Method.PATCH;
    }

    if (httpMethod == HttpMethod.TRACE) {
        return RestRequest.Method.TRACE;
    }

    if (httpMethod == HttpMethod.CONNECT) {
        return RestRequest.Method.CONNECT;
    }

    throw new IllegalArgumentException("Unexpected http method: " + httpMethod);
}

From source file:org.thingsplode.synapse.endpoint.handlers.HttpRequestHandler.java

License:Apache License

@Override
protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest httpRequest) throws Exception {
    //todo: support for API keys
    ///endpoints/json?api_key=565656
    try {//  w w w.  j  av  a 2s  . c  o  m
        // Handle a bad request.
        if (!httpRequest.decoderResult().isSuccess()) {
            HttpResponseHandler.sendError(ctx, HttpResponseStatus.BAD_REQUEST, "Could not decode request.",
                    httpRequest);
            return;
        }

        if (httpRequest.method().equals(HttpMethod.HEAD) || httpRequest.method().equals(HttpMethod.PATCH)
                || httpRequest.method().equals(HttpMethod.TRACE)
                || httpRequest.method().equals(HttpMethod.CONNECT)
                || httpRequest.method().equals(HttpMethod.OPTIONS)) {
            HttpResponseHandler.sendError(ctx, HttpResponseStatus.FORBIDDEN,
                    "Method forbidden (The following are not supported: HEAD, PATCH, TRACE, CONNECT, OPTIONS).",
                    httpRequest);
            return;
        }

        //check websocket upgrade request
        String upgradeHeader = httpRequest.headers().get(HttpHeaderNames.UPGRADE);
        if (!Util.isEmpty(upgradeHeader) && UPGRADE_TO_WEBSOCKET.equalsIgnoreCase(upgradeHeader)) {
            //case websocket upgrade request is detected -> Prepare websocket handshake
            upgradeToWebsocket(ctx, httpRequest);
            return;
        } else {
            //case simple http request
            Request request = new Request(prepareHeader(ctx, httpRequest));

            //no information about the object type / it will be processed in a later stage
            //todo: with requestbodytype header value early deserialization would be possible, however not beneficial in routing cases
            request.setBody(httpRequest.content());
            ctx.fireChannelRead(request);
        }
    } catch (Exception ex) {
        logger.error("Channel read error: " + ex.getMessage(), ex);
        HttpResponseHandler.sendError(ctx, HttpResponseStatus.INTERNAL_SERVER_ERROR,
                ex.getClass().getSimpleName() + ": " + ex.getMessage(), httpRequest);
    }
}