List of usage examples for io.netty.handler.codec.http HttpMethod PATCH
HttpMethod PATCH
To view the source code for io.netty.handler.codec.http HttpMethod PATCH.
Click Source Link
From source file:org.restexpress.RestExpressTest.java
License:Apache License
@Test public void shouldCallAltMethods() throws ClientProtocolException, IOException { int port = nextPort(); String testUrl = createUrl(TEST_URL_PATTERN, port); RestExpress re = new RestExpress(); NoopController controller = new NoopController(); re.uri(TEST_PATH, controller).method(HttpMethod.HEAD, HttpMethod.OPTIONS, HttpMethod.PATCH); re.bind(port);/*from www . jav a2 s. c o m*/ waitForStartup(); HttpGet get = new HttpGet(testUrl); try { HttpResponse response = (HttpResponse) CLIENT.execute(get); assertEquals(405, response.getStatusLine().getStatusCode()); } finally { get.releaseConnection(); } HttpOptions options = new HttpOptions(testUrl); try { HttpResponse response = (HttpResponse) CLIENT.execute(options); assertEquals(200, response.getStatusLine().getStatusCode()); assertEquals(0, controller.delete); assertEquals(0, controller.read); assertEquals(0, controller.create); assertEquals(0, controller.update); assertEquals(1, controller.options); assertEquals(0, controller.head); assertEquals(0, controller.patch); } finally { options.releaseConnection(); } HttpHead head = new HttpHead(testUrl); try { HttpResponse response = (HttpResponse) CLIENT.execute(head); assertEquals(200, response.getStatusLine().getStatusCode()); assertEquals(0, controller.delete); assertEquals(0, controller.read); assertEquals(0, controller.create); assertEquals(0, controller.update); assertEquals(1, controller.options); assertEquals(1, controller.head); assertEquals(0, controller.patch); } finally { head.releaseConnection(); } HttpPatch patch = new HttpPatch(testUrl); try { HttpResponse response = (HttpResponse) CLIENT.execute(patch); assertEquals(200, response.getStatusLine().getStatusCode()); assertEquals(0, controller.delete); assertEquals(0, controller.read); assertEquals(0, controller.create); assertEquals(0, controller.update); assertEquals(1, controller.options); assertEquals(1, controller.head); assertEquals(1, controller.patch); } finally { patch.releaseConnection(); } re.shutdown(true); }
From source file:org.restexpress.RestExpressTest.java
License:Apache License
@Test public void shouldCallAltNamedMethods() throws ClientProtocolException, IOException { int port = nextPort(); String testUrl = createUrl(TEST_URL_PATTERN, port); RestExpress re = new RestExpress(); AltController controller = new AltController(); re.uri(TEST_PATH, controller).action("altHead", HttpMethod.HEAD).action("altOptions", HttpMethod.OPTIONS) .action("altPatch", HttpMethod.PATCH); re.bind(port);/*from w w w . j av a2s . co m*/ waitForStartup(); HttpGet get = new HttpGet(testUrl); try { HttpResponse response = (HttpResponse) CLIENT.execute(get); assertEquals(405, response.getStatusLine().getStatusCode()); } finally { get.releaseConnection(); } HttpOptions options = new HttpOptions(testUrl); try { HttpResponse response = (HttpResponse) CLIENT.execute(options); assertEquals(200, response.getStatusLine().getStatusCode()); assertEquals(1, controller.options); assertEquals(0, controller.head); assertEquals(0, controller.patch); } finally { options.releaseConnection(); } HttpHead head = new HttpHead(testUrl); try { HttpResponse response = (HttpResponse) CLIENT.execute(head); assertEquals(200, response.getStatusLine().getStatusCode()); assertEquals(1, controller.options); assertEquals(1, controller.head); assertEquals(0, controller.patch); } finally { head.releaseConnection(); } HttpPatch patch = new HttpPatch(testUrl); try { HttpResponse response = (HttpResponse) CLIENT.execute(patch); assertEquals(200, response.getStatusLine().getStatusCode()); assertEquals(1, controller.options); assertEquals(1, controller.head); assertEquals(1, controller.patch); } finally { patch.releaseConnection(); } re.shutdown(true); }
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 {/*from w ww . jav a2s. com*/ // 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); } }
From source file:org.vertx.java.core.http.impl.DefaultHttpServerRequest.java
License:Open Source License
@Override public HttpServerRequest expectMultiPart(boolean expect) { if (expect) { String contentType = request.headers().get(HttpHeaders.Names.CONTENT_TYPE); if (contentType != null) { HttpMethod method = request.getMethod(); String lowerCaseContentType = contentType.toLowerCase(); 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))) { decoder = new HttpPostRequestDecoder(new DataFactory(), request); }/* w ww . j ava 2s . c o m*/ } } else { decoder = null; } return this; }
From source file:org.wisdom.engine.wrapper.RequestFromNettyTest.java
License:Apache License
@Test public void testMethod() throws Exception { HttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/"); RequestFromNetty request = new RequestFromNetty(null, null, req); assertThat(request.method()).isEqualTo("GET"); req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PATCH, "/"); request = new RequestFromNetty(null, null, req); assertThat(request.method()).isEqualTo("PATCH"); }
From source file:org.wisdom.framework.vertx.RequestFromVertXTest.java
License:Apache License
@Test public void testMethod() throws Exception { HttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/"); RequestFromVertx request = new RequestFromVertx(context, create(req), null); assertThat(request.method()).isEqualTo("GET"); req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PATCH, "/"); request = new RequestFromVertx(context, create(req), null); assertThat(request.method()).isEqualTo("PATCH"); }
From source file:reactor.ipc.netty.http.client.HttpClient.java
License:Open Source License
/** * HTTP PATCH the passed URL. When connection has been made, the passed handler is * invoked and can be used to build precisely the request and write data to it. * * @param url the target remote URL/*from www .ja va 2 s. c o m*/ * @param handler the {@link Function} to invoke on open channel * * @return a {@link Mono} of the {@link HttpServerResponse} ready to consume for * response */ public final Mono<HttpClientResponse> patch(String url, Function<? super HttpClientRequest, ? extends Publisher<Void>> handler) { return request(HttpMethod.PATCH, url, handler); }
From source file:reactor.ipc.netty.http.client.HttpClient.java
License:Open Source License
/** * HTTP PATCH the passed URL.//from w w w . j a v a 2s . c o m * * @param url the target remote URL * * @return a {@link Mono} of the {@link HttpServerResponse} ready to consume for * response */ public final Mono<HttpClientResponse> patch(String url) { return request(HttpMethod.PATCH, url, null); }
From source file:reactor.ipc.netty.http.client.HttpClientFormEncoder.java
License:Open Source License
/** * @param factory the factory used to create InterfaceHttpData * @param request the request to encode/*from w ww. ja v a 2 s. com*/ * @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 */ HttpClientFormEncoder(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.method(); 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.newCharset = charset; this.factory = factory; this.progressFlux = DirectProcessor.create(); this.cleanOnTerminate = true; this.newMode = encoderMode; this.newMultipart = multipart; // Fill default values bodyListDatas = new ArrayList<>(); // default mode isLastChunk = false; isLastChunkSent = false; isMultipart = multipart; multipartHttpDatas = new ArrayList<>(); this.encoderMode = encoderMode; if (isMultipart) { initDataMultipart(); } }
From source file:uapi.web.http.netty.internal.NettyHttpRequest.java
License:Open Source License
NettyHttpRequest(final ILogger logger, final HttpRequest httpRequest) { this._logger = logger; this._request = httpRequest; HttpHeaders headers = this._request.headers(); Looper.from(headers.iteratorAsString()) .foreach(entry -> this._headers.put(entry.getKey().toLowerCase(), entry.getValue())); this._uri = this._request.uri(); QueryStringDecoder queryStringDecoder = new QueryStringDecoder(this._uri); Map<String, List<String>> params = queryStringDecoder.parameters(); Looper.from(params.entrySet()).foreach(entry -> this._params.put(entry.getKey(), entry.getValue())); HttpVersion version = this._request.protocolVersion(); if (HttpVersion.HTTP_1_0.equals(version)) { this._version = uapi.web.http.HttpVersion.V_1_0; } else if (HttpVersion.HTTP_1_1.equals(version)) { this._version = uapi.web.http.HttpVersion.V_1_1; } else {//from www . ja v a 2 s. co m throw new KernelException("Unsupported Http version - {}", version); } HttpMethod method = this._request.method(); if (HttpMethod.GET.equals(method)) { this._method = uapi.web.http.HttpMethod.GET; } else if (HttpMethod.PUT.equals(method)) { this._method = uapi.web.http.HttpMethod.PUT; } else if (HttpMethod.POST.equals(method)) { this._method = uapi.web.http.HttpMethod.POST; } else if (HttpMethod.PATCH.equals(method)) { this._method = uapi.web.http.HttpMethod.PATCH; } else if (HttpMethod.DELETE.equals(method)) { this._method = uapi.web.http.HttpMethod.DELETE; } else { throw new KernelException("Unsupported http method {}", method.toString()); } // Decode content type String contentTypeString = this._headers.get(HttpHeaderNames.CONTENT_TYPE.toString()); if (contentTypeString == null) { this._conentType = ContentType.TEXT; this._charset = Charset.forName("UTF-8"); } else { String[] contentTypeInfo = contentTypeString.split(";"); if (contentTypeInfo.length < 0) { this._conentType = ContentType.TEXT; this._charset = CharsetUtil.UTF_8; } else if (contentTypeInfo.length == 1) { this._conentType = ContentType.parse(contentTypeInfo[0].trim()); this._charset = CharsetUtil.UTF_8; } else { this._conentType = ContentType.parse(contentTypeInfo[0].trim()); this._charset = Looper.from(contentTypeInfo).map(info -> info.split("=")) .filter(kv -> kv.length == 2).filter(kv -> kv[0].trim().equalsIgnoreCase("charset")) .map(kv -> kv[1].trim()).map(Charset::forName).first(CharsetUtil.UTF_8); } } }