List of usage examples for io.netty.handler.codec.http HttpMethod PUT
HttpMethod PUT
To view the source code for io.netty.handler.codec.http HttpMethod PUT.
Click Source Link
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; }/* w ww .jav a 2 s. co 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.hawkular.apm.tests.client.http.NettyHttpITest.java
License:Apache License
@Override public void init() { server = HttpServer.newServer().enableWireLogging(LogLevel.DEBUG).start((req, resp) -> { if (req.getHeader(Constants.HAWKULAR_APM_TRACEID) == null) { return resp.setStatus(HttpResponseStatus.BAD_REQUEST); }//from w w w. j a va 2 s. c o m if (req.getHttpMethod() == HttpMethod.POST || req.getHttpMethod() == HttpMethod.PUT) { req.getContent().subscribe(bb -> System.out.println("DATA = " + bb.toString())); } return resp.writeString(Observable.just(HELLO_WORLD)); }); super.init(); }
From source file:org.hawkular.apm.tests.client.http.NettyNoResponseHttpITest.java
License:Apache License
@Override public void init() { server = HttpServer.newServer().enableWireLogging(LogLevel.DEBUG).start((req, resp) -> { if (req.getHeader(Constants.HAWKULAR_APM_TRACEID) == null) { return resp.setStatus(HttpResponseStatus.BAD_REQUEST); }/*w w w .j av a 2 s. com*/ if (req.getHttpMethod() == HttpMethod.POST || req.getHttpMethod() == HttpMethod.PUT) { req.getContent().subscribe(bb -> System.out.println("DATA = " + bb.toString())); } resp.setStatus(HttpResponseStatus.OK); return resp; }); super.init(); }
From source file:org.icgc.dcc.storage.test.s3.S3Request.java
License:Open Source License
public boolean isPut() { return ctx.getRequest().getMethod() == HttpMethod.PUT; }
From source file:org.iotivity.cloud.base.protocols.http.HCProxyProcessor.java
License:Open Source License
/** * This function returns a message created by the request, * which implements IRequest(used in the cloud) * translated from the HTTP request./*from w w w.jav a 2s . com*/ * * @return requestMessage */ public Message getRequestMessage() { Message requestMessage = null; String coapUriPath = mTargetCoapPath; String coapUriQuery = mTargetCoapQuery; ContentFormat coapContentFormat = null; if (mContentFormat != null) { if (mContentFormat.equalsIgnoreCase(APPLICATION_CBOR)) { coapContentFormat = ContentFormat.APPLICATION_CBOR; } } byte[] coapPayload = mCborContent; if (mHttpMethod == HttpMethod.POST) { CoapRequest coapRequest = new CoapRequest(RequestMethod.POST); coapRequest.setToken(createToken()); coapRequest.setUriPath(coapUriPath); if (coapUriQuery != null) { coapRequest.setUriQuery(coapUriQuery); } if (coapPayload != null) { coapRequest.setContentFormat(coapContentFormat); coapRequest.setPayload(coapPayload); } requestMessage = coapRequest; } else if (mHttpMethod == HttpMethod.PUT) { CoapRequest coapRequest = new CoapRequest(RequestMethod.PUT); coapRequest.setToken(createToken()); coapRequest.setUriPath(coapUriPath); if (coapUriQuery != null) { coapRequest.setUriQuery(coapUriQuery); } if (coapPayload != null) { coapRequest.setContentFormat(coapContentFormat); coapRequest.setPayload(coapPayload); } requestMessage = coapRequest; } else if (mHttpMethod == HttpMethod.GET) { CoapRequest coapRequest = new CoapRequest(RequestMethod.GET); coapRequest.setToken(createToken()); coapRequest.setUriPath(coapUriPath); if (coapUriQuery != null) { coapRequest.setUriQuery(coapUriQuery); } requestMessage = coapRequest; } else if (mHttpMethod == HttpMethod.DELETE) { CoapRequest coapRequest = new CoapRequest(RequestMethod.DELETE); coapRequest.setToken(createToken()); coapRequest.setUriPath(coapUriPath); if (coapUriQuery != null) { coapRequest.setUriQuery(coapUriQuery); } requestMessage = coapRequest; } return requestMessage; }
From source file:org.iotivity.cloud.base.protocols.proxy.CoapHttpProxyHandler.java
License:Open Source License
CoapRequest httpRequestToCoAPRequest(String uri, HttpRequest httpRequest) { CoapRequest coapRequest;//from ww w . j a v a 2 s.c om // TODO: coapRequest converter required // coapRequest.getOptions().setUriQuery(); if (httpRequest.getMethod() == HttpMethod.GET) { coapRequest = new CoapRequest(CoapMethod.GET); } else if (httpRequest.getMethod() == HttpMethod.PUT) { coapRequest = new CoapRequest(CoapMethod.PUT); } else if (httpRequest.getMethod() == HttpMethod.POST) { coapRequest = new CoapRequest(CoapMethod.POST); } else if (httpRequest.getMethod() == HttpMethod.DELETE) { coapRequest = new CoapRequest(CoapMethod.DELETE); } else { throw new IllegalArgumentException(); } coapRequest.setUriPath(uri); return coapRequest; }
From source file:org.ireland.jnetty.http.HttpServletRequestImpl.java
License:Open Source License
/** * Extract Parameters from query string and form HttpServletRequestImpl Body(application/x-www-form-urlencoded [POST * | PUT])//from www . j a v a 2s . co m */ public void extractParameters() { if (_paramsExtracted) return; _paramsExtracted = true; if (_parameters == null) _parameters = new HashMap<String, List<String>>(); // Handle query string if (_queryEncoding == null) { QueryStringDecoder queryStringDecoder = new QueryStringDecoder(request.getUri()); _parameters.putAll(queryStringDecoder.parameters()); } else { try { QueryStringDecoder queryStringDecoder = new QueryStringDecoder(request.getUri(), Charset.forName(_queryEncoding)); _parameters.putAll(queryStringDecoder.parameters()); } catch (UnsupportedCharsetException e) { if (LOG.isDebugEnabled()) LOG.warn(e); else LOG.warn(e.toString()); } } // handle form _content (application/x-www-form-urlencoded) String encoding = getCharacterEncoding(); String content_type = getContentType(); if (content_type != null && content_type.length() > 0) { content_type = ContentTypeUtil.getContentTypeWithoutCharset(content_type); // application/x-www-form-urlencoded( POST or PUT ) if (HttpHeaders.Values.APPLICATION_X_WWW_FORM_URLENCODED.equals(content_type) && (HttpMethod.POST.name().equals(getMethod()) || HttpMethod.PUT.name().equals(getMethod()))) { int content_length = getContentLength(); if (content_length > 0) { try { Charset bodyCharset = Charset.forName(encoding); String bodyContent = new String(getRowBodyContent(), bodyCharset); // Add form params to query params QueryStringDecoder queryStringDecoder = new QueryStringDecoder(bodyContent, bodyCharset, false); if (_parameters == null) _parameters = queryStringDecoder.parameters(); else//merge { Map<String, List<String>> map = queryStringDecoder.parameters(); for (Entry<String, List<String>> e : map.entrySet()) { if (!_parameters.containsKey(e.getKey())) { _parameters.put(e.getKey(), e.getValue()); } else// parameter with the same name exist,merge { List<String> value = _parameters.get(e.getKey()); if (value == null) _parameters.put(e.getKey(), e.getValue()); else { value.addAll(e.getValue()); // merge _parameters.put(e.getKey(), value); } } } } } catch (Exception e) { if (LOG.isDebugEnabled()) e.printStackTrace(); else LOG.warn(e.toString()); } } } } }
From source file:org.jboss.aerogear.simplepush.server.netty.NotificationHandlerTest.java
License:Apache License
private FullHttpRequest notificationRequest(final String endpointToken, final Long version) { final FullHttpRequest req = new DefaultFullHttpRequest(HTTP_1_1, HttpMethod.PUT, "/update/" + endpointToken); if (version != null) { req.content().writeBytes(Unpooled.copiedBuffer("version=" + version.toString(), CharsetUtil.UTF_8)); }/*from w w w .j a va2 s . c o m*/ return req; }
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())); }// w w w. j a v a2 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")); }