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

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

Introduction

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

Prototype

HttpMethod PATCH

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

Click Source Link

Document

The PATCH method requests that a set of changes described in the request entity be applied to the resource identified by the Request-URI.

Usage

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.linecorp.armeria.client.http.SimpleHttpRequestBuilder.java

License:Apache License

/**
 * Returns a {@link SimpleHttpRequestBuilder} for a PATCH request to the given URI,
 * for setting additional HTTP parameters as needed.
 *//*from  w ww .  jav  a  2s.  c o m*/
public static SimpleHttpRequestBuilder forPatch(String uri) {
    return createRequestBuilder(uri, HttpMethod.PATCH);
}

From source file:com.linecorp.armeria.client.http.SimpleHttpRequestBuilderTest.java

License:Apache License

@Test
public void httpMethods() {
    assertEquals(HttpMethod.GET, SimpleHttpRequestBuilder.forGet("/path").build().method());
    assertEquals(HttpMethod.POST, SimpleHttpRequestBuilder.forPost("/path").build().method());
    assertEquals(HttpMethod.PUT, SimpleHttpRequestBuilder.forPut("/path").build().method());
    assertEquals(HttpMethod.PATCH, SimpleHttpRequestBuilder.forPatch("/path").build().method());
    assertEquals(HttpMethod.DELETE, SimpleHttpRequestBuilder.forDelete("/path").build().method());
    assertEquals(HttpMethod.HEAD, SimpleHttpRequestBuilder.forHead("/path").build().method());
    assertEquals(HttpMethod.OPTIONS, SimpleHttpRequestBuilder.forOptions("/path").build().method());
}

From source file:com.litgh.RouterTest.java

License:Open Source License

public void testRouterAPI() {
    Router router = new Router();
    final Map<String, Boolean> test = new HashMap<String, Boolean>();

    router.GET("/GET", new Handler() {
        public void handle(HttpRequest req, FullHttpResponse resp, List<Param> params) {
            test.put("GET", true);
        }/*from   w  w w  .  j av  a2s .co m*/
    });

    router.POST("/POST", new Handler() {
        public void handle(HttpRequest req, FullHttpResponse resp, List<Param> params) {
            test.put("POST", true);
        }
    });

    router.PUT("/PUT", new Handler() {
        public void handle(HttpRequest req, FullHttpResponse resp, List<Param> params) {
            test.put("PUT", true);
        }
    });

    router.DELETE("/DELETE", new Handler() {
        public void handle(HttpRequest req, FullHttpResponse resp, List<Param> params) {
            test.put("DELETE", true);
        }
    });

    router.HEAD("/HEAD", new Handler() {
        public void handle(HttpRequest req, FullHttpResponse resp, List<Param> params) {
            test.put("HEAD", true);
        }
    });

    router.PATCH("/PATCH", new Handler() {
        public void handle(HttpRequest req, FullHttpResponse resp, List<Param> params) {
            test.put("PATCH", true);
        }
    });

    HttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/GET");
    FullHttpResponse resp = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    router.serverHttp(req, resp);

    req.setMethod(HttpMethod.POST);
    req.setUri("/POST");
    router.serverHttp(req, resp);

    req.setMethod(HttpMethod.PUT);
    req.setUri("/PUT");
    router.serverHttp(req, resp);

    req.setMethod(HttpMethod.DELETE);
    req.setUri("/DELETE");
    router.serverHttp(req, resp);

    req.setMethod(HttpMethod.HEAD);
    req.setUri("/HEAD");
    router.serverHttp(req, resp);

    req.setMethod(HttpMethod.PATCH);
    req.setUri("/PATCH");
    router.serverHttp(req, resp);

    assertEquals("routing GET failed", Boolean.TRUE, test.get("GET"));
    assertEquals("routing POST failed", Boolean.TRUE, test.get("POST"));
    assertEquals("routing PUT failed", Boolean.TRUE, test.get("PUT"));
    assertEquals("routing DELETE failed", Boolean.TRUE, test.get("DELETE"));
    assertEquals("routing HEAD failed", Boolean.TRUE, test.get("HEAD"));
    assertEquals("routing PATCH failed", Boolean.TRUE, test.get("PATCH"));
}

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;//ww  w.  java2 s.com
    }

    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:com.rackspacecloud.blueflood.http.RouteMatcher.java

License:Apache License

public void patch(String pattern, HttpRequestHandler handler) {
    addBinding(pattern, HttpMethod.PATCH.name(), handler, patchBindings);
}

From source file:discord4j.rest.route.Route.java

License:Open Source License

public static <T> Route<T> patch(String uri, Class<T> responseType) {
    return new Route<>(HttpMethod.PATCH, uri, responseType);
}

From source file:divconq.http.multipart.HttpPostRequestEncoder.java

License:Apache License

/**
 *
 * @param factory/*from   www  .  ja  v  a2 s.  co m*/
 *            the factory used to create InterfaceHttpData
 * @param request
 *            the request to encode
 * @param multipart
 *            True if the FORM is a ENCTYPE="multipart/form-data"
 * @param charset
 *            the charset to use as default
 * @param encoderMode
 *            the mode for the encoder to use. See {@link EncoderMode} for the details.
 * @throws NullPointerException
 *             for request or charset or factory
 * @throws ErrorDataEncoderException
 *             if the request is not a POST
 */
public HttpPostRequestEncoder(HttpDataFactory factory, HttpRequest request, boolean multipart, Charset charset,
        EncoderMode encoderMode) throws ErrorDataEncoderException {
    if (factory == null) {
        throw new NullPointerException("factory");
    }
    if (request == null) {
        throw new NullPointerException("request");
    }
    if (charset == null) {
        throw new NullPointerException("charset");
    }
    HttpMethod method = request.getMethod();
    if (!(method.equals(HttpMethod.POST) || method.equals(HttpMethod.PUT) || method.equals(HttpMethod.PATCH)
            || method.equals(HttpMethod.OPTIONS))) {
        throw new ErrorDataEncoderException("Cannot create a Encoder if not a POST");
    }
    this.request = request;
    this.charset = charset;
    this.factory = factory;
    // Fill default values
    bodyListDatas = new ArrayList<InterfaceHttpData>();
    // default mode
    isLastChunk = false;
    isLastChunkSent = false;
    isMultipart = multipart;
    multipartHttpDatas = new ArrayList<InterfaceHttpData>();
    this.encoderMode = encoderMode;
    if (isMultipart) {
        initDataMultipart();
    }
}

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  w w w.  j  a  v a  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:
        throw new IllegalArgumentException();
    }
}

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

License:Open Source License

@Override
public HttpServerRequest setExpectMultipart(boolean expect) {
    synchronized (conn) {
        checkEnded();/*from  w w w.j a v a  2s  .  co  m*/
        if (expect) {
            if (decoder == null) {
                String contentType = request.headers().get(HttpHeaders.Names.CONTENT_TYPE);
                if (contentType != null) {
                    HttpMethod method = request.getMethod();
                    String lowerCaseContentType = contentType.toLowerCase();
                    boolean isURLEncoded = lowerCaseContentType
                            .startsWith(HttpHeaders.Values.APPLICATION_X_WWW_FORM_URLENCODED);
                    if ((lowerCaseContentType.startsWith(HttpHeaders.Values.MULTIPART_FORM_DATA)
                            || isURLEncoded)
                            && (method.equals(HttpMethod.POST) || method.equals(HttpMethod.PUT)
                                    || method.equals(HttpMethod.PATCH) || method.equals(HttpMethod.DELETE))) {
                        decoder = new HttpPostRequestDecoder(new DataFactory(), request);
                    }
                }
            }
        } else {
            decoder = null;
        }
        return this;
    }
}