List of usage examples for io.netty.handler.codec.http HttpMethod GET
HttpMethod GET
To view the source code for io.netty.handler.codec.http HttpMethod GET.
Click Source Link
From source file:cn.zyf.context.Acl.java
License:Open Source License
public RequestInfo() { this.verb = HttpMethod.GET; this.path = ""; this.bucketName = ""; this.objectName = ""; this.params = null; this.acl = Acl.PRIVATE; this.contentLength = 0; this.contentMD5 = ""; this.contentType = ""; this.dateStr = ""; setId("req_" + UUID.randomUUID()); }
From source file:cn.zyf.handler.ObjectStorageHandler.java
License:Open Source License
private boolean isListBuckets(RequestInfo requestInfo) { return requestInfo.getVerb() == HttpMethod.GET && requestInfo.getPath().equals("/") && requestInfo.getBucketName().equals("") && requestInfo.getObjectName().equals(""); }
From source file:com.alibaba.dubbo.qos.command.decoder.HttpCommandDecoder.java
License:Apache License
public static CommandContext decode(HttpRequest request) { CommandContext commandContext = null; if (request != null) { QueryStringDecoder queryStringDecoder = new QueryStringDecoder(request.getUri()); String path = queryStringDecoder.path(); String[] array = path.split("/"); if (array.length == 2) { String name = array[1]; // process GET request and POST request separately. Check url for GET, and check body for POST if (request.getMethod() == HttpMethod.GET) { if (queryStringDecoder.parameters().isEmpty()) { commandContext = CommandContextFactory.newInstance(name); commandContext.setHttp(true); } else { List<String> valueList = new ArrayList<String>(); for (List<String> values : queryStringDecoder.parameters().values()) { valueList.addAll(values); }/*from w w w.ja va 2s.c om*/ commandContext = CommandContextFactory.newInstance(name, valueList.toArray(new String[] {}), true); } } else if (request.getMethod() == HttpMethod.POST) { HttpPostRequestDecoder httpPostRequestDecoder = new HttpPostRequestDecoder(request); List<String> valueList = new ArrayList<String>(); for (InterfaceHttpData interfaceHttpData : httpPostRequestDecoder.getBodyHttpDatas()) { if (interfaceHttpData.getHttpDataType() == InterfaceHttpData.HttpDataType.Attribute) { Attribute attribute = (Attribute) interfaceHttpData; try { valueList.add(attribute.getValue()); } catch (IOException ex) { throw new RuntimeException(ex); } } } if (valueList.isEmpty()) { commandContext = CommandContextFactory.newInstance(name); commandContext.setHttp(true); } else { commandContext = CommandContextFactory.newInstance(name, valueList.toArray(new String[] {}), true); } } } } return commandContext; }
From source file:com.barchart.netty.rest.server.RestHandlerBase.java
License:BSD License
@Override public void handle(final HttpServerRequest request) throws IOException { final HttpMethod method = request.getMethod(); try {//from w w w. j av a2 s . c om if (method == HttpMethod.GET) { get(request); } else if (method == HttpMethod.POST) { post(request); } else if (method == HttpMethod.PUT) { put(request); } else if (method == HttpMethod.DELETE) { delete(request); } else { complete(request.response(), HttpResponseStatus.METHOD_NOT_ALLOWED, method.name() + " not implemented"); } } catch (final Throwable t) { complete(request.response(), HttpResponseStatus.INTERNAL_SERVER_ERROR, t.getMessage()); } }
From source file:com.buildria.mocking.builder.action.BodyActionTest.java
License:Open Source License
@Test public void testApplyResponseUTF8() throws Exception { Object content = person;/*from w ww . jav a2s.c o m*/ List<Action> actions = new ArrayList<>(); actions.add(new HeaderAction("Content-Type", "application/json; charset=UTF-8")); Action action = new BodyAction(content, actions); HttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/api/p"); HttpResponse res = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK); HttpResponse out = action.apply(req, res); assertThat(out, notNullValue()); assertThat(out, instanceOf(DefaultFullHttpResponse.class)); DefaultFullHttpResponse response = (DefaultFullHttpResponse) out; ByteBuf buf = response.content(); byte[] json = buf.toString(StandardCharsets.UTF_8).getBytes(); assertThat(Integer.valueOf(out.headers().get("Content-Length")), is(json.length)); ObjectSerializerContext ctx = new ObjectSerializerContext(SubType.JSON, StandardCharsets.UTF_8); ObjectSerializer serializer = ObjectSerializerFactory.create(ctx); byte[] expected = serializer.serialize(person); assertThat(json, is(expected)); }
From source file:com.buildria.mocking.builder.action.BodyActionTest.java
License:Open Source License
@Test public void testApplyResponseUTF16BE() throws Exception { Object content = person;/*from w w w. j a v a2 s . c om*/ List<Action> actions = new ArrayList<>(); actions.add(new HeaderAction("Content-Type", "application/json; charset=UTF-16BE")); Action action = new BodyAction(content, actions); HttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/api/p"); HttpResponse res = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK); HttpResponse out = action.apply(req, res); assertThat(out, notNullValue()); assertThat(out, instanceOf(DefaultFullHttpResponse.class)); DefaultFullHttpResponse response = (DefaultFullHttpResponse) out; ByteBuf buf = response.content(); byte[] json = buf.toString(StandardCharsets.UTF_8).getBytes(); assertThat(Integer.valueOf(out.headers().get("Content-Length")), is(json.length)); ObjectSerializerContext ctx = new ObjectSerializerContext(SubType.JSON, StandardCharsets.UTF_16BE); ObjectSerializer serializer = ObjectSerializerFactory.create(ctx); byte[] expected = serializer.serialize(person); assertThat(json, is(expected)); }
From source file:com.buildria.mocking.builder.action.BodyActionTest.java
License:Open Source License
@Test(expected = MockingException.class) public void testApplyResponseNoContentType() throws Exception { Object content = person;//from w w w .ja va2s . co m Action action = new BodyAction(content, Collections.<Action>emptyList()); HttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/api/p"); HttpResponse res = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK); HttpResponse out = action.apply(req, res); }
From source file:com.buildria.mocking.builder.action.DelayActionTest.java
License:Open Source License
@Test public void testApply() throws Exception { long wait = 500; target = new DelayAction(wait); HttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/api/p"); HttpResponse res = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK); long start = System.currentTimeMillis(); target.apply(req, res);/*w ww.j av a2s. com*/ long end = System.currentTimeMillis(); long actual = end - start; assertThat(actual, greaterThanOrEqualTo((long) (wait * 0.9))); assertThat(actual, lessThanOrEqualTo((long) (wait * 1.1))); }
From source file:com.buildria.mocking.builder.action.HeaderActionTest.java
License:Open Source License
@Test public void testApplyResponse() throws Exception { String header = "Content-Type"; String value = "application/xml"; Action action = new HeaderAction(header, value); HttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/api/p"); HttpResponse res = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK); HttpResponse out = action.apply(req, res); assertThat(out, notNullValue());// w w w. j av a 2s . c o m assertThat(out.headers().get("Content-Type"), is("application/xml")); }
From source file:com.buildria.mocking.builder.action.RawBodyActionTest.java
License:Open Source License
@Test public void testApplyResponse() throws Exception { byte[] content = "content".getBytes(); Action action = new RawBodyAction(content); HttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/api/p"); HttpResponse res = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK); res.headers().add(ACCEPT, "application/xml"); HttpResponse out = action.apply(req, res); assertThat(out, notNullValue());// w w w .j a v a 2 s.c om assertThat(out.headers().get(CONTENT_LENGTH), is("7")); assertThat(out.headers().get(ACCEPT), is("application/xml")); assertThat(out, instanceOf(DefaultFullHttpResponse.class)); DefaultFullHttpResponse response = (DefaultFullHttpResponse) out; ByteBuf buf = response.content(); byte[] actual = new byte[buf.readableBytes()]; buf.readBytes(actual); assertThat(actual, is(content)); }