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:net.anyflow.menton.http.HttpRequest.java
License:Apache License
private void normalizeParameters() { String address = (new StringBuilder()).append(uriObject().getScheme()).append("://") .append(uriObject().getAuthority()).append(uriObject().getPath()).toString(); if (HttpMethod.GET.equals(method()) || HttpMethod.DELETE.equals(method())) { String parameters = convertParametersToString(); address += Strings.isNullOrEmpty(parameters) ? "" : "?" + parameters; } else if ((HttpMethod.POST.equals(method()) || HttpMethod.PUT.equals(method())) && (headers().contains(HttpHeaderNames.CONTENT_TYPE) == false || headers().get(HttpHeaderNames.CONTENT_TYPE) .startsWith(HttpHeaderValues.APPLICATION_X_WWW_FORM_URLENCODED.toString()))) { ByteBuf content = Unpooled.copiedBuffer(convertParametersToString(), CharsetUtil.UTF_8); headers().set(HttpHeaderNames.CONTENT_LENGTH, content.readableBytes()); content().clear();/* ww w .j a va 2 s . c o m*/ content().writeBytes(content); } setUri(address); }
From source file:org.apache.asterix.api.http.servlet.QueryCancellationServletTest.java
License:Apache License
private IServletRequest mockRequest(String clientContextId) { IServletRequest mockRequest = mock(IServletRequest.class); FullHttpRequest mockHttpRequest = mock(FullHttpRequest.class); when(mockRequest.getHttpRequest()).thenReturn(mockHttpRequest); when(mockHttpRequest.method()).thenReturn(HttpMethod.DELETE); if (clientContextId != null) { when(mockRequest.getParameter("client_context_id")).thenReturn(clientContextId); }//w ww .j av a 2 s . c o m return mockRequest; }
From source file:org.apache.flink.runtime.webmonitor.HttpRequestHandler.java
License:Apache License
@Override public void channelRead0(ChannelHandlerContext ctx, HttpObject msg) { try {/*from w ww. ja v a 2s . c o m*/ if (msg instanceof HttpRequest) { currentRequest = (HttpRequest) msg; currentRequestPath = null; if (currentDecoder != null) { currentDecoder.destroy(); currentDecoder = null; } if (currentRequest.getMethod() == HttpMethod.GET || currentRequest.getMethod() == HttpMethod.DELETE) { // directly delegate to the router ctx.fireChannelRead(currentRequest); } else if (currentRequest.getMethod() == HttpMethod.POST) { // POST comes in multiple objects. First the request, then the contents // keep the request and path for the remaining objects of the POST request currentRequestPath = new QueryStringDecoder(currentRequest.getUri()).path(); currentDecoder = new HttpPostRequestDecoder(DATA_FACTORY, currentRequest); } else { throw new IOException("Unsupported HTTP method: " + currentRequest.getMethod().name()); } } else if (currentDecoder != null && msg instanceof HttpContent) { // received new chunk, give it to the current decoder HttpContent chunk = (HttpContent) msg; currentDecoder.offer(chunk); try { while (currentDecoder.hasNext()) { InterfaceHttpData data = currentDecoder.next(); // IF SOMETHING EVER NEEDS POST PARAMETERS, THIS WILL BE THE PLACE TO HANDLE IT // all fields values will be passed with type Attribute. if (data.getHttpDataType() == HttpDataType.FileUpload) { DiskFileUpload file = (DiskFileUpload) data; if (file.isCompleted()) { String name = file.getFilename(); File target = new File(tmpDir, UUID.randomUUID() + "_" + name); file.renameTo(target); QueryStringEncoder encoder = new QueryStringEncoder(currentRequestPath); encoder.addParam("filepath", target.getAbsolutePath()); encoder.addParam("filename", name); currentRequest.setUri(encoder.toString()); } } data.release(); } } catch (EndOfDataDecoderException ignored) { } if (chunk instanceof LastHttpContent) { HttpRequest request = currentRequest; currentRequest = null; currentRequestPath = null; currentDecoder.destroy(); currentDecoder = null; // fire next channel handler ctx.fireChannelRead(request); } } } catch (Throwable t) { currentRequest = null; currentRequestPath = null; if (currentDecoder != null) { currentDecoder.destroy(); currentDecoder = null; } if (ctx.channel().isActive()) { byte[] bytes = ExceptionUtils.stringifyException(t).getBytes(ENCODING); DefaultFullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.INTERNAL_SERVER_ERROR, Unpooled.wrappedBuffer(bytes)); response.headers().set(HttpHeaders.Names.CONTENT_ENCODING, "utf-8"); response.headers().set(HttpHeaders.Names.CONTENT_TYPE, "text/plain"); response.headers().set(HttpHeaders.Names.CONTENT_LENGTH, response.content().readableBytes()); ctx.writeAndFlush(response); } } }
From source file:org.apache.flink.runtime.webmonitor.testutils.HttpTestClient.java
License:Apache License
/** * Sends a simple DELETE request to the given path. You only specify the $path part of * http://$host:$host/$path.//w ww . j av a2s . c o m * * @param path The $path to DELETE (http://$host:$host/$path) */ public void sendDeleteRequest(String path, FiniteDuration timeout) throws TimeoutException, InterruptedException { if (!path.startsWith("/")) { path = "/" + path; } HttpRequest getRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.DELETE, path); getRequest.headers().set(HttpHeaders.Names.HOST, host); getRequest.headers().set(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.CLOSE); sendRequest(getRequest, timeout); }
From source file:org.apache.hyracks.http.server.AbstractServlet.java
License:Apache License
@Override public void handle(IServletRequest request, IServletResponse response) { try {//from w ww . j a v a 2 s.co m final HttpMethod method = request.getHttpRequest().method(); if (HttpMethod.GET.equals(method)) { get(request, response); } else if (HttpMethod.HEAD.equals(method)) { head(request, response); } else if (HttpMethod.POST.equals(method)) { post(request, response); } else if (HttpMethod.PUT.equals(method)) { put(request, response); } else if (HttpMethod.DELETE.equals(method)) { delete(request, response); } else if (HttpMethod.OPTIONS.equals(method)) { options(request, response); } else { notAllowed(method, response); } } catch (Exception e) { LOGGER.log(Level.WARNING, "Unhandled exception", e); response.setStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR); } catch (Throwable th) { //NOSONAR Just logging and then throwing again try { LOGGER.log(Level.WARNING, "Unhandled throwable", th); } catch (Throwable loggingFailure) {// NOSONAR... swallow logging failure } throw th; } }
From source file:org.apache.hyracks.http.server.AbstractServlet.java
License:Apache License
@SuppressWarnings("squid:S1172") protected void delete(IServletRequest request, IServletResponse response) throws Exception { // designed to be extended but an error in standard case notAllowed(HttpMethod.DELETE, response); }
From source file:org.asynchttpclient.Dsl.java
License:Open Source License
public static RequestBuilder delete(String url) { return request(HttpMethod.DELETE.name(), url); }
From source file:org.bridje.http.impl.HttpBridletRequestImpl.java
License:Apache License
@Override public boolean isDelete() { return getMethod().equals(HttpMethod.DELETE.name()); }
From source file:org.caratarse.auth.services.Routes.java
License:Apache License
public static void define(Configuration config, RestExpress server) { //TODO: Your routes here... server.uri("/populates.{format}", config.getPopulateController()).action("readAll", HttpMethod.GET) .action("deleteAll", HttpMethod.DELETE).name(Constants.Routes.POPULATE_COLLECTION); server.uri("/users/{userUuid}.{format}", config.getUserController()) .method(HttpMethod.GET, HttpMethod.PUT, HttpMethod.DELETE).name(Constants.Routes.USER_READ_ROUTE); server.uri("/users.{format}", config.getUserController()).action("readAll", HttpMethod.GET) .method(HttpMethod.POST).name(Constants.Routes.USER_COLLECTION_READ_ROUTE); server.uri("/users/{userUuid}/authorizations.{format}", config.getUserAuthorizationController()) .action("readAll", HttpMethod.GET).name(Constants.Routes.USER_AUTHORIZATIONS_ROUTE); server.uri("/users/{userUuid}/authorizations/{authorizationName}.{format}", config.getUserAuthorizationController()).method(HttpMethod.GET, HttpMethod.PUT, HttpMethod.DELETE) .action("addAuthorizationToUser", HttpMethod.POST).name(Constants.Routes.USER_AUTHORIZATION_ROUTE); //// or...//www . j a v a2 s . c o m // server.regex("/some.regex", config.getRouteController()); }
From source file:org.elasticsearch.hadoop.http.netty4.Netty4HttpRequest.java
License:Apache License
@Override public Method method() { HttpMethod httpMethod = request.method(); if (httpMethod == HttpMethod.GET) return Method.GET; if (httpMethod == HttpMethod.POST) return Method.POST; if (httpMethod == HttpMethod.PUT) return Method.PUT; if (httpMethod == HttpMethod.DELETE) return Method.DELETE; if (httpMethod == HttpMethod.HEAD) { return Method.HEAD; }/* www.java2 s .c o m*/ if (httpMethod == HttpMethod.OPTIONS) { return Method.OPTIONS; } return Method.GET; }