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:io.selendroid.server.util.HttpClientUtil.java
License:Apache License
public static HttpResponse executeRequest(String url, HttpMethod method) throws Exception { HttpRequestBase request = null;/*from w w w . ja v a2s . c o m*/ if (HttpMethod.GET.equals(method)) { request = new HttpGet(url); } else if (HttpMethod.POST.equals(method)) { request = new HttpPost(url); } else if (HttpMethod.DELETE.equals(method)) { request = new HttpDelete(url); } else { throw new RuntimeException("Provided HttpMethod not supported"); } return getHttpClient().execute(request); }
From source file:io.selendroid.standalone.server.handler.ProxyToDeviceHandler.java
License:Apache License
private JSONObject proxyRequestToDevice(HttpRequest request, ActiveSession session, String url, String method) throws Exception { HttpResponse r;/*from w w w. j a v a 2 s .c o m*/ if ("get".equalsIgnoreCase(method)) { log.fine("Proxy GET to the device: " + url); r = HttpClientUtil.executeRequest(url, HttpMethod.GET); } else if ("post".equalsIgnoreCase(method)) { JSONObject payload = getPayload(request); log.fine("Proxy POST to the device: " + url + ", payload:\n" + payload); r = HttpClientUtil.executeRequestWithPayload(url, session.getSelendroidServerPort(), HttpMethod.POST, payload.toString()); } else if ("delete".equalsIgnoreCase(method)) { log.fine("Proxy DELETE to the device: " + url); r = HttpClientUtil.executeRequest(url, HttpMethod.DELETE); } else { throw new SelendroidException("HTTP method not supported: " + method); } return HttpClientUtil.parseJsonResponse(r); }
From source file:io.selendroid.standalone.server.model.SelendroidStandaloneDriver.java
License:Apache License
public void stopSession(String sessionId) throws AndroidDeviceException { if (isValidSession(sessionId)) { ActiveSession session = sessions.get(sessionId); session.stopSessionTimer();// w w w .jav a2 s.c om try { HttpClientUtil.executeRequest( "http://localhost:" + session.getSelendroidServerPort() + "/wd/hub/session/" + sessionId, HttpMethod.DELETE); } catch (Exception e) { log.log(Level.WARNING, "Error stopping session, safe to ignore", e); } deviceStore.release(session.getDevice(), session.getAut()); sessions.remove(sessionId); } }
From source file:io.selendroid.standalone.server.util.HttpClientUtil.java
License:Apache License
public static HttpResponse executeRequest(String url, HttpMethod method) throws Exception { HttpRequestBase request;/*from w w w. ja v a 2 s. c o m*/ if (HttpMethod.GET.equals(method)) { request = new HttpGet(url); } else if (HttpMethod.POST.equals(method)) { request = new HttpPost(url); } else if (HttpMethod.DELETE.equals(method)) { request = new HttpDelete(url); } else { throw new RuntimeException("Provided HttpMethod not supported: " + method); } return getHttpClient().execute(request); }
From source file:io.urmia.api.handler.RestApiHandler.java
License:Open Source License
@Override protected void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception { if (msg instanceof HttpRequest) { if (requestState != RequestState.EXPECT_REQUEST) { sendError(ctx, ERROR_BAD_REQUEST); return; }/*from w w w. j ava 2s .co m*/ request = (HttpRequest) msg; log.info("received HttpRequest: {} {}", request.getMethod(), request.getUri()); final ObjectRequest r; try { r = new ObjectRequest(request); } catch (ExceptionInInitializerError e) { log.warn("unable to parse the request into a command: {}", request.getUri()); return; } objectRequest = r; httpRequest = request; if (HttpMethod.PUT.equals(request.getMethod())) { if (objectRequest.isNotDirectory()) // make dir request setupProxyToPUT(ctx, objectRequest); requestState = RequestState.EXPECT_CONTENT_OR_LAST; } else { requestState = RequestState.EXPECT_LAST; ctx.read(); } return; } if (objectRequest == null) { String uri = request == null ? "" : request.getUri(); log.warn("not expecting an empty objectRequest. parse error maybe: {}", uri); ByteBuf body = request == null || request.getMethod().equals(HttpMethod.HEAD) ? null : errorBody("ResourceNotFoundError", uri + " does not exist"); sendError(ctx, HttpResponseStatus.NOT_FOUND, body); return; } if (msg instanceof HttpContent) { if (requestState != RequestState.EXPECT_LAST && requestState != RequestState.EXPECT_CONTENT_OR_LAST) { log.warn("not expecting LAST or CONTENT, requestState: {}", requestState); sendError(ctx, HttpResponseStatus.NOT_EXTENDED); return; } final boolean last = msg instanceof LastHttpContent; final boolean emptyLast = last && msg == LastHttpContent.EMPTY_LAST_CONTENT; if (proxyMode && !emptyLast) // todo: the emptyLast was added for mln ctx.fireChannelRead(msg); // example of reading only if at the end if (last) { log.debug("received LastHttpContent: {}", msg); requestState = RequestState.EXPECT_REQUEST; final HttpRequest request = httpRequest; if (HttpMethod.HEAD.equals(request.getMethod())) { handleHEAD(ctx, objectRequest); return; } if (HttpMethod.GET.equals(request.getMethod())) { handleGET(ctx, objectRequest); return; } if (HttpMethod.DELETE.equals(request.getMethod())) { handleDELETE(ctx, objectRequest); return; } if (HttpMethod.PUT.equals(request.getMethod())) { if (proxyMode) log.info("finished file upload: {}", objectRequest); else handlePUTmkdir(ctx, objectRequest); return; } log.warn("unknown request: {}", request); sendError(ctx, HttpResponseStatus.BAD_REQUEST); } return; } log.warn("unexpected msg type: {}", msg); sendError(ctx, HttpResponseStatus.BAD_REQUEST); }
From source file:io.urmia.st.StorageServerHandler.java
License:Open Source License
@Override protected void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception { if (msg instanceof HttpRequest) { requestStartMS = System.currentTimeMillis(); request = (HttpRequest) msg;/*from w w w.java2 s .com*/ log.info("received HttpRequest: {} {}", request.getMethod(), request.getUri()); // todo: what's this? //if (is100ContinueExpected(request)) { // send100Continue(ctx); //} if (HttpMethod.PUT.equals(request.getMethod())) { // start doing the fs put. next msg is not a LastHttpContent handlePUT(ctx, request); //return; } ctx.read(); return; } if (msg instanceof HttpContent) { // New chunk is received HttpContent chunk = (HttpContent) msg; //log.info("chunk {} of size: {}", chunk, chunk.content().readableBytes()); if (fileChannel != null) { writeToFile(chunk.content()); } // example of reading only if at the end if (chunk instanceof LastHttpContent) { log.trace("received LastHttpContent: {}", chunk); if (HttpMethod.HEAD.equals(request.getMethod())) { handleHEAD(ctx, request); ctx.read(); return; } if (HttpMethod.GET.equals(request.getMethod())) { handleGET(ctx, request); ctx.read(); return; } if (HttpMethod.DELETE.equals(request.getMethod())) { handleDELETE(ctx, request); ctx.read(); return; } if (HttpMethod.PUT.equals(request.getMethod())) { // TODO: reset() if exception catch or timeout (i.e. no LastHttpContent) writeResponse(ctx, new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK), true); // close the connection after upload (mput) done reset(); access.success(ctx, "PUT", uri, requestStartMS); ctx.read(); return; } log.warn("unknown request: {}", request); sendError(ctx, HttpResponseStatus.BAD_REQUEST); } ctx.read(); return; } log.warn("unknown msg type: {}", msg); }
From source file:io.vertx.core.http.impl.HttpServerRequestImpl.java
License:Open Source License
@Override public HttpServerRequest setExpectMultipart(boolean expect) { synchronized (conn) { checkEnded();//w w w . j av a2s. com 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 w w . j a v a 2 s . c om 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:net.anyflow.menton.http.HttpClient.java
License:Apache License
@Override public HttpResponse delete(final MessageReceiver receiver) { httpRequest().setMethod(HttpMethod.DELETE); return request(receiver); }
From source file:net.anyflow.menton.http.HttpRequest.java
License:Apache License
public Map<String, List<String>> parameters() { if (parameters != null) { return parameters; }//from w ww.ja v a 2 s. c o m Map<String, List<String>> ret = Maps.newHashMap(); if (HttpMethod.GET.equals(method()) || HttpMethod.DELETE.equals(method())) { ret.putAll((new QueryStringDecoder(uri())).parameters()); return ret; } else if (headers().contains(HttpHeaderNames.CONTENT_TYPE) && headers().get(HttpHeaderNames.CONTENT_TYPE) .startsWith(HttpHeaderValues.APPLICATION_X_WWW_FORM_URLENCODED.toString()) && (HttpMethod.POST.equals(method()) || HttpMethod.PUT.equals(method()))) { ret.putAll((new QueryStringDecoder("/dummy?" + content().toString(CharsetUtil.UTF_8))).parameters()); } return ret; }