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:io.jsync.http.impl.DefaultHttpServerRequest.java

License:Open Source License

@Override
public HttpServerRequest expectMultiPart(boolean expect) {
    if (expect) {
        String contentType = request.headers().get(HttpHeaderNames.CONTENT_TYPE);
        if (contentType != null) {
            HttpMethod method = request.method();
            AsciiString lowerCaseContentType = new AsciiString(contentType.toLowerCase());
            boolean isURLEncoded = lowerCaseContentType
                    .startsWith(HttpHeaderValues.APPLICATION_X_WWW_FORM_URLENCODED);
            if ((lowerCaseContentType.startsWith(HttpHeaderValues.MULTIPART_FORM_DATA) || isURLEncoded)
                    && (method.equals(HttpMethod.POST) || method.equals(HttpMethod.PUT)
                            || method.equals(HttpMethod.PATCH))) {
                decoder = new HttpPostRequestDecoder(new DataFactory(), request);
            }/*from  ww  w  .jav a  2 s.  c om*/
        }
    } else {
        decoder = null;
    }
    return this;
}

From source file:io.vertx.core.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.c o  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 NettyFileUploadDataFactory(conn.vertx(), this, () -> uploadHandler),
                                request);
                    }
                }
            }
        } else {
            decoder = null;
        }
        return this;
    }
}

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;
    }//from w  ww.  j ava 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 path(String url) {
    return request(HttpMethod.PATCH.name(), url);
}

From source file:org.bridje.http.impl.HttpBridletRequestImpl.java

License:Apache License

@Override
public boolean isPatch() {
    return getMethod().equals(HttpMethod.PATCH.name());
}

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;
    }//from w ww. j a  va2s  .  c o  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.jooby.internal.netty.NettyRequest.java

License:Apache License

private Multimap<String, String> decodeParams() throws IOException {
    if (params == null) {
        params = ArrayListMultimap.create();
        files = ArrayListMultimap.create();

        query.parameters().forEach((name, values) -> values.forEach(value -> params.put(name, value)));

        HttpMethod method = req.method();
        boolean hasBody = method.equals(HttpMethod.POST) || method.equals(HttpMethod.PUT)
                || method.equals(HttpMethod.PATCH);
        boolean formLike = false;
        if (req.headers().contains("Content-Type")) {
            String contentType = req.headers().get("Content-Type").toLowerCase();
            formLike = (contentType.startsWith(MediaType.multipart.name())
                    || contentType.startsWith(MediaType.form.name()));
        }//from  w ww . j  a  va2  s  .c o m
        if (hasBody && formLike) {
            HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(new DefaultHttpDataFactory(), req);
            try {
                Function<HttpPostRequestDecoder, Boolean> hasNext = it -> {
                    try {
                        return it.hasNext();
                    } catch (HttpPostRequestDecoder.EndOfDataDecoderException ex) {
                        return false;
                    }
                };
                while (hasNext.apply(decoder)) {
                    HttpData field = (HttpData) decoder.next();
                    try {
                        String name = field.getName();
                        if (field.getHttpDataType() == HttpDataType.FileUpload) {
                            files.put(name, new NettyUpload((FileUpload) field, tmpdir));
                        } else {
                            params.put(name, field.getString());
                        }
                    } finally {
                        field.release();
                    }
                }
            } finally {
                decoder.destroy();
            }
        }
    }
    return params;
}

From source file:org.nosceon.titanite.ControllersTest.java

License:Apache License

@Test
public void test() {
    given().expect().statusCode(200).body(equalTo(HttpMethod.GET.name())).when().get(uri("/a"));
    given().expect().statusCode(200).body(equalTo(HttpMethod.POST.name())).when().post(uri("/a"));
    given().expect().statusCode(200).body(equalTo(HttpMethod.PUT.name())).when().put(uri("/a"));
    given().expect().statusCode(200).body(equalTo(HttpMethod.DELETE.name())).when().delete(uri("/a"));
    given().expect().statusCode(200).body(equalTo(HttpMethod.PATCH.name())).when().patch(uri("/a"));

    given().expect().statusCode(200).body(equalTo(HttpMethod.GET.name())).when().get(uri("/b"));
    given().expect().statusCode(200).body(equalTo(HttpMethod.POST.name())).when().post(uri("/b"));
    given().expect().statusCode(200).body(equalTo(HttpMethod.PUT.name())).when().put(uri("/b"));
    given().expect().statusCode(200).body(equalTo(HttpMethod.DELETE.name())).when().delete(uri("/b"));
    given().expect().statusCode(200).body(equalTo(HttpMethod.PATCH.name())).when().patch(uri("/b"));
}

From source file:org.nosceon.titanite.HttpServerHandler.java

License:Apache License

private BodyParser newBodyParser(RoutingResult routing, HttpRequest request) {
    HttpMethod method = request.getMethod();
    if (method.equals(HttpMethod.POST) || method.equals(HttpMethod.PUT) || method.equals(HttpMethod.PATCH)) {

        if (routing.bodyParser() != null) {
            BodyParser bp = routing.bodyParser().get();
            if (bp != null) {
                return bp;
            }//  www  .j  ava  2  s. c  o m
        }

        String contentType = request.headers().get(HttpHeaders.Names.CONTENT_TYPE);

        if (contentType != null) {
            String lowerCaseContentType = contentType.toLowerCase();
            boolean isURLEncoded = lowerCaseContentType
                    .startsWith(HttpHeaders.Values.APPLICATION_X_WWW_FORM_URLENCODED);
            boolean isMultiPart = lowerCaseContentType.startsWith(HttpHeaders.Values.MULTIPART_FORM_DATA);

            if (isMultiPart) {
                return new FormParamsBodyParser(maxMultipartRequestSize);
            }

            if (isURLEncoded) {
                return new FormParamsBodyParser(maxRequestSize);
            }
        }

        return new RawBodyParser(maxRequestSize);
    } else {
        return new EmptyBodyParser();
    }
}

From source file:org.nosceon.titanite.MethodsTest.java

License:Apache License

@Test
public void test() {
    given().expect().statusCode(200).body(equalTo(HttpMethod.GET.name())).when().get(uri("/resource"));
    given().expect().statusCode(200).body(equalTo(HttpMethod.POST.name())).when().post(uri("/resource"));
    given().expect().statusCode(200).body(equalTo(HttpMethod.PUT.name())).when().put(uri("/resource"));
    given().expect().statusCode(200).body(equalTo(HttpMethod.DELETE.name())).when().delete(uri("/resource"));
    given().expect().statusCode(200).body(equalTo(HttpMethod.PATCH.name())).when().patch(uri("/resource"));

    given().expect().statusCode(200).body(equalTo(HttpMethod.GET.name())).when().get(uri("/controller"));
    given().expect().statusCode(200).body(equalTo(HttpMethod.POST.name())).when().post(uri("/controller"));
    given().expect().statusCode(200).body(equalTo(HttpMethod.PUT.name())).when().put(uri("/controller"));
    given().expect().statusCode(200).body(equalTo(HttpMethod.DELETE.name())).when().delete(uri("/controller"));
    given().expect().statusCode(200).body(equalTo(HttpMethod.PATCH.name())).when().patch(uri("/controller"));
}