List of usage examples for io.netty.handler.codec.http HttpMethod DELETE
HttpMethod DELETE
To view the source code for io.netty.handler.codec.http HttpMethod DELETE.
Click Source Link
From source file:reactor.ipc.netty.http.client.HttpClient.java
License:Open Source License
/** * HTTP DELETE 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// w ww .j a va 2 s. c o m * * @return a {@link Mono} of the {@link HttpServerResponse} ready to consume for * response */ public final Mono<HttpClientResponse> delete(String url) { return request(HttpMethod.DELETE, url, null); }
From source file:reactor.ipc.netty.http.server.HttpPredicate.java
License:Open Source License
/** * An alias for {@link HttpPredicate#http}. * <p>//from w w w. ja va2s . co m * Creates a {@link Predicate} based on a URI template filtering . * <p> * This will listen for DELETE Method. * * @param uri The string to compile into a URI template and use for matching * * @return The new {@link Predicate}. * * @see Predicate */ public static Predicate<HttpServerRequest> delete(String uri) { return http(uri, null, HttpMethod.DELETE); }
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 ww w . j ava 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); } } }
From source file:weatherAlarm.endpoints.WeatherAlarmEndpoint.java
License:Apache License
@Override public Observable<Void> handle(HttpServerRequest<ByteBuf> request, HttpServerResponse<ByteBuf> response) { if (alarmService == null) { response.setStatus(HttpResponseStatus.SERVICE_UNAVAILABLE); return response.close(); }/* ww w.ja v a 2 s. c o m*/ if (HttpMethod.GET.equals(request.getHttpMethod())) { handleGet(response, request.getUri()); } else if (HttpMethod.PUT.equals(request.getHttpMethod())) { handlePut(response, request.getContent()); } else if (HttpMethod.DELETE.equals(request.getHttpMethod())) { handleDelete(response, request.getUri()); } else { response.setStatus(HttpResponseStatus.NOT_IMPLEMENTED); } return response.close(); }
From source file:weatherAlarm.endpoints.WeatherAlarmEndpointTest.java
License:Apache License
@Test public void testHandleRequestForDeleteAlarm() throws Exception { IWeatherAlarmService alarmService = getMockAlarmService(); WeatherAlarmEndpoint alarmEndpoint = new WeatherAlarmEndpoint(); alarmEndpoint.setAlarmService(alarmService); WeatherAlarm alarm = alarmService.getAlarms().get(0); Capture<byte[]> written = EasyMock.newCapture(); Capture<HttpResponseStatus> status = EasyMock.newCapture(); String encodedAlarmName = URLEncoder.encode(alarm.getName(), "UTF-8"); String uri = URI + "/" + encodedAlarmName; HttpServerRequest<ByteBuf> request = createMockHttpServerRequest(HttpMethod.DELETE, uri, Observable.empty());// ww w.j a v a2 s.c om HttpServerResponse<ByteBuf> response = createMockHttpResponse(status, written); alarmEndpoint.handle(request, response); Assert.assertTrue("Alarm not deleted from list " + alarm, !alarmService.getAlarms().contains(alarm)); }
From source file:weatherAlarm.endpoints.WeatherAlarmEndpointTest.java
License:Apache License
@Test public void testHandleRequestForDeleteAlarms() throws Exception { IWeatherAlarmService alarmService = getMockAlarmService(); WeatherAlarmEndpoint alarmEndpoint = new WeatherAlarmEndpoint(); alarmEndpoint.setAlarmService(alarmService); WeatherAlarm alarm = alarmService.getAlarms().get(0); Capture<byte[]> written = EasyMock.newCapture(); Capture<HttpResponseStatus> status = EasyMock.newCapture(); HttpServerRequest<ByteBuf> request = createMockHttpServerRequest(HttpMethod.DELETE, URI, Observable.empty());/*from w w w .java 2 s . c o m*/ HttpServerResponse<ByteBuf> response = createMockHttpResponse(status, written); alarmEndpoint.handle(request, response); Assert.assertTrue("Alarm deleted from list " + alarm, alarmService.getAlarms().contains(alarm)); Assert.assertEquals("Unexpected status", HttpResponseStatus.UNAUTHORIZED, status.getValue()); }