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:com.linecorp.armeria.client.http.SimpleHttpRequestBuilder.java
License:Apache License
/** * Returns a {@link SimpleHttpRequestBuilder} for a PUT request to the given URI, * for setting additional HTTP parameters as needed. *///from ww w.j a v a 2 s . c o m public static SimpleHttpRequestBuilder forPut(String uri) { return createRequestBuilder(uri, HttpMethod.PUT); }
From source file:com.linecorp.armeria.client.http.SimpleHttpRequestBuilderTest.java
License:Apache License
@Test public void httpMethods() { assertEquals(HttpMethod.GET, SimpleHttpRequestBuilder.forGet("/path").build().method()); assertEquals(HttpMethod.POST, SimpleHttpRequestBuilder.forPost("/path").build().method()); assertEquals(HttpMethod.PUT, SimpleHttpRequestBuilder.forPut("/path").build().method()); assertEquals(HttpMethod.PATCH, SimpleHttpRequestBuilder.forPatch("/path").build().method()); assertEquals(HttpMethod.DELETE, SimpleHttpRequestBuilder.forDelete("/path").build().method()); assertEquals(HttpMethod.HEAD, SimpleHttpRequestBuilder.forHead("/path").build().method()); assertEquals(HttpMethod.OPTIONS, SimpleHttpRequestBuilder.forOptions("/path").build().method()); }
From source file:com.linkedin.proxy.netty.MysqlQueryDecoder.java
License:Apache License
@Override protected void decode(ChannelHandlerContext ctx, FullHttpRequest msg, List<Object> out) throws Exception { MysqlQuery result = new MysqlQuery(); try {/* w ww. j a v a2 s . c o m*/ HttpMethod met = msg.getMethod(); String uri = msg.getUri(); int s = 0; int e = uri.length(); if (uri.charAt(0) == '/') s = 1; if (uri.charAt(e - 1) == '/') e--; String parts[] = uri.substring(s, e).split("/"); result.setDbName(parts[0]); result.setTableName(parts[1]); result.setKeyColName(parts[2]); result.setValueColName(parts[3]); if (met.equals(HttpMethod.PUT)) { /* * If HttpRequest method is PUT, I interpret it as a WRITE query. * MysqlQuery instance's value is set as the value in the HttpRequest. */ result.setKey(parts[4]); byte[] tempData = new byte[msg.content().readableBytes()]; msg.content().readBytes(tempData); result.setValue(tempData); result.setType(QueryType.WRITE); } else if (met.equals(HttpMethod.GET)) { /* * If HttpRequest method is GET, I interpret it as a READ query. * Once the query is processed, the result value (if any) is written to MysqlQuery.value. */ result.setKey(parts[4]); result.setType(QueryType.READ); } else if (met.equals(HttpMethod.DELETE)) { /* * If HttpRequest method is DELETE, I interpret it as a DELETE query. */ result.setKey(parts[4]); result.setType(QueryType.DELETE); } else if (met.equals(HttpMethod.POST)) { /* * If HttpRequest method is POST, I interpret it as a CREATE TABLE query. * I store size of the value column in MysqlQuery.Value. * I store byte array of the string representation. */ result.setValue(parts[4].getBytes()); result.setType(QueryType.CREATE); } else { result.setType(QueryType.INVALID); _LOG.error("Unhandled HttpMethod: " + met); _LOG.error("Type=" + QueryType.INVALID); } } catch (Exception e) { _LOG.error("Exception occured during HttpRequest processing", e); result.setType(QueryType.INVALID); _LOG.error("Type=" + QueryType.INVALID); } out.add(result); }
From source file:com.linkedin.proxy.netty.RocksdbQueryDecoder.java
License:Apache License
@Override protected void decode(ChannelHandlerContext ctx, FullHttpRequest msg, List<Object> out) throws Exception { /*// w w w .j a va2 s . c o m * Expected inputs: * PUT /dbName/key <value in content> * GET /dbName/key * DELETE /dbName/key */ Query result = new Query(); try { HttpMethod met = msg.getMethod(); String uri = msg.getUri(); int s = 0; int e = uri.length(); if (uri.charAt(0) == '/') s = 1; if (uri.charAt(e - 1) == '/') e--; String parts[] = uri.substring(s, e).split("/"); result.setDbName(parts[0]); _LOG.debug("DbName: " + parts[0]); result.setKey(parts[1]); _LOG.debug("Key: " + parts[1]); if (met.equals(HttpMethod.PUT)) { /* * If HttpRequest method is PUT, I interpret it as a WRITE query. * Query instance's value is set as the value in the HttpRequest. */ byte[] tempData = new byte[msg.content().readableBytes()]; msg.content().readBytes(tempData); result.setValue(tempData); _LOG.debug("Value size: " + tempData.length); result.setType(QueryType.WRITE); } else if (met.equals(HttpMethod.GET)) { /* * If HttpRequest method is GET, I interpret it as a READ query. * Once the query is processed, the result value (if any) is written to MysqlQuery.value. */ result.setType(QueryType.READ); } else if (met.equals(HttpMethod.DELETE)) { /* * If HttpRequest method is DELETE, I interpret it as a DELETE query. */ result.setType(QueryType.DELETE); } else { result.setType(QueryType.INVALID); _LOG.error("Unhandled HttpMethod: " + met); _LOG.error("Type=" + QueryType.INVALID); } _LOG.debug("Type: " + result.getType()); } catch (Exception e) { _LOG.error("Exception occured during HttpRequest processing", e); result.setType(QueryType.INVALID); _LOG.error("Type=" + QueryType.INVALID); } out.add(result); }
From source file:com.litgh.RouterTest.java
License:Open Source License
public void testRouterAPI() { Router router = new Router(); final Map<String, Boolean> test = new HashMap<String, Boolean>(); router.GET("/GET", new Handler() { public void handle(HttpRequest req, FullHttpResponse resp, List<Param> params) { test.put("GET", true); }/*from ww w .j a v a2 s. c o m*/ }); router.POST("/POST", new Handler() { public void handle(HttpRequest req, FullHttpResponse resp, List<Param> params) { test.put("POST", true); } }); router.PUT("/PUT", new Handler() { public void handle(HttpRequest req, FullHttpResponse resp, List<Param> params) { test.put("PUT", true); } }); router.DELETE("/DELETE", new Handler() { public void handle(HttpRequest req, FullHttpResponse resp, List<Param> params) { test.put("DELETE", true); } }); router.HEAD("/HEAD", new Handler() { public void handle(HttpRequest req, FullHttpResponse resp, List<Param> params) { test.put("HEAD", true); } }); router.PATCH("/PATCH", new Handler() { public void handle(HttpRequest req, FullHttpResponse resp, List<Param> params) { test.put("PATCH", true); } }); HttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/GET"); FullHttpResponse resp = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK); router.serverHttp(req, resp); req.setMethod(HttpMethod.POST); req.setUri("/POST"); router.serverHttp(req, resp); req.setMethod(HttpMethod.PUT); req.setUri("/PUT"); router.serverHttp(req, resp); req.setMethod(HttpMethod.DELETE); req.setUri("/DELETE"); router.serverHttp(req, resp); req.setMethod(HttpMethod.HEAD); req.setUri("/HEAD"); router.serverHttp(req, resp); req.setMethod(HttpMethod.PATCH); req.setUri("/PATCH"); router.serverHttp(req, resp); assertEquals("routing GET failed", Boolean.TRUE, test.get("GET")); assertEquals("routing POST failed", Boolean.TRUE, test.get("POST")); assertEquals("routing PUT failed", Boolean.TRUE, test.get("PUT")); assertEquals("routing DELETE failed", Boolean.TRUE, test.get("DELETE")); assertEquals("routing HEAD failed", Boolean.TRUE, test.get("HEAD")); assertEquals("routing PATCH failed", Boolean.TRUE, test.get("PATCH")); }
From source file:com.nike.cerberus.endpoints.admin.PutSDBMetadata.java
License:Apache License
@Override public Matcher requestMatcher() { return Matcher.match("/v1/metadata", HttpMethod.PUT); }
From source file:com.nike.cerberus.endpoints.sdb.UpdateSafeDepositBox.java
License:Apache License
@Override public Matcher requestMatcher() { return Matcher.match("/v1/safe-deposit-box/{id}", HttpMethod.PUT); }
From source file:com.nike.cerberus.endpoints.sdb.UpdateSafeDepositBoxV2.java
License:Apache License
@Override public Matcher requestMatcher() { return Matcher.match("/v2/safe-deposit-box/{id}", HttpMethod.PUT); }
From source file:com.rackspacecloud.blueflood.http.RouteMatcher.java
License:Apache License
public void route(ChannelHandlerContext context, FullHttpRequest request) { final String method = request.getMethod().name(); final String URI = request.getUri(); // Method not implemented for any resource. So return 501. if (method == null || !implementedVerbs.contains(method)) { route(context, request, unsupportedVerbsHandler); return;/*from www . j a v a2s . com*/ } final Pattern pattern = getMatchingPatternForURL(URI); // No methods registered for this pattern i.e. URL isn't registered. Return 404. if (pattern == null) { route(context, request, noRouteHandler); return; } final Set<String> supportedMethods = getSupportedMethods(pattern); if (supportedMethods == null) { log.warn("No supported methods registered for a known pattern " + pattern); route(context, request, noRouteHandler); return; } // The method requested is not available for the resource. Return 405. if (!supportedMethods.contains(method)) { route(context, request, unsupportedMethodHandler); return; } PatternRouteBinding binding = null; if (method.equals(HttpMethod.GET.name())) { binding = getBindings.get(pattern); } else if (method.equals(HttpMethod.PUT.name())) { binding = putBindings.get(pattern); } else if (method.equals(HttpMethod.POST.name())) { binding = postBindings.get(pattern); } else if (method.equals(HttpMethod.DELETE.name())) { binding = deleteBindings.get(pattern); } else if (method.equals(HttpMethod.PATCH.name())) { binding = deleteBindings.get(pattern); } else if (method.equals(HttpMethod.OPTIONS.name())) { binding = optionsBindings.get(pattern); } else if (method.equals(HttpMethod.HEAD.name())) { binding = headBindings.get(pattern); } else if (method.equals(HttpMethod.TRACE.name())) { binding = traceBindings.get(pattern); } else if (method.equals(HttpMethod.CONNECT.name())) { binding = connectBindings.get(pattern); } if (binding != null) { request = updateRequestHeaders(request, binding); route(context, request, binding.handler); } else { throw new RuntimeException("Cannot find a valid binding for URL " + URI); } }
From source file:com.rackspacecloud.blueflood.http.RouteMatcher.java
License:Apache License
public void put(String pattern, HttpRequestHandler handler) { addBinding(pattern, HttpMethod.PUT.name(), handler, putBindings); }