List of usage examples for io.netty.handler.codec.http HttpMethod name
AsciiString name
To view the source code for io.netty.handler.codec.http HttpMethod name.
Click Source Link
From source file:io.selendroid.server.util.HttpClientUtil.java
License:Apache License
public static HttpResponse executeRequestWithPayload(String uri, int port, HttpMethod method, String payload) throws Exception { BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest(method.name(), uri); request.setEntity(new StringEntity(payload, "UTF-8")); return getHttpClient().execute(new HttpHost("localhost", port), request); }
From source file:net.mms_projects.copy_it.api.http.pages.exceptions.UnsupportedMethodException.java
License:Open Source License
public UnsupportedMethodException(HttpMethod method) { super(MESSAGE + method.name()); }
From source file:net.nikore.gozer.router.RibbonRouter.java
License:Apache License
@Override public RequestContext apply(RequestContext ctx) { HttpMethod verb = utils.getVerb(ctx.getRequest()); String requestURL;// w w w. j av a 2 s . c o m if (ctx.hasOriginRequest()) { requestURL = ctx.getOriginHost() + ctx.getOringRequest(); } else { requestURL = ctx.getOriginHost() + ctx.getRequest().getRequestURI(); } HttpClientRequest<ByteBuf> request = HttpClientRequest.create(verb, requestURL); HTTPRequestUtils.buildRequestHeaders(ctx.getRequest()).forEach(request::withHeader); SimpleRibbonResponse response = utils.simpleRequest(request); ctx.setResponseStatusCode(response.getStatusCode()); ctx.setResponseBody(new String(response.getContent())); ctx.setResponseDataStream(new ByteArrayInputStream(response.getContent())); ctx.setResponseGZipped(response.isGzipped()); if (ctx.debugRequest()) { Debug.addRequestDebug("GOZER:: host=" + ctx.getOriginHost(), ctx); HTTPRequestUtils.buildRequestHeaders(ctx.getRequest()) .forEach((s, s2) -> Debug.addRequestDebug("GOZER Headers::> " + s + " " + s2, ctx)); Debug.addRequestDebug("GOZER:: Request Info >" + verb.name() + " " + requestURL, ctx); Debug.addRequestDebug("GOZER:: response entity >" + new String(response.getContent()), ctx); } return ctx; }
From source file:org.apache.olingo.netty.server.core.NettyServiceDispatcherTest.java
License:Apache License
@Test public void testMetadata() throws Exception { DefaultFullHttpRequest nettyRequest = Mockito.mock(DefaultFullHttpRequest.class); io.netty.handler.codec.http.HttpMethod httpMethod = mock(io.netty.handler.codec.http.HttpMethod.class); when(httpMethod.name()).thenReturn("GET"); when(nettyRequest.method()).thenReturn(httpMethod); HttpVersion httpVersion = mock(HttpVersion.class); when(httpVersion.text()).thenReturn("HTTP/1.0"); when(nettyRequest.protocolVersion()).thenReturn(httpVersion); when(nettyRequest.uri()).thenReturn("/trippin/$metadata"); HttpHeaders headers = mock(HttpHeaders.class); when(nettyRequest.headers()).thenReturn(headers); when(nettyRequest.content()).thenReturn(Unpooled.buffer()); DefaultFullHttpResponse nettyResponse = mock(DefaultFullHttpResponse.class); when(nettyResponse.status()).thenReturn(HttpResponseStatus.OK); when(nettyResponse.headers()).thenReturn(headers); when(nettyResponse.content()).thenReturn(Unpooled.buffer()); Map<String, String> requestParams = new HashMap<String, String>(); requestParams.put("contextPath", "/trippin"); ODataNettyHandler handler = odata.createNettyHandler(metadata); handler.processNettyRequest(nettyRequest, nettyResponse, requestParams); assertNotNull(new String(nettyResponse.content().array())); assertEquals(200, nettyResponse.status().code()); assertEquals("OK", nettyResponse.status().reasonPhrase()); }
From source file:org.apache.olingo.netty.server.core.ODataNettyHandlerImplTest.java
License:Apache License
@Test public void testNettyReqResp_GetMethod() { MetadataProcessor processor = mock(MetadataProcessor.class); final ODataNetty odata = ODataNetty.newInstance(); final ServiceMetadata metadata = odata.createServiceMetadata(new EdmTechProvider(), Collections.<EdmxReference>emptyList()); ODataNettyHandler handler = odata.createNettyHandler(metadata); handler.register(processor);//from w w w . ja v a2s .c o m DefaultFullHttpRequest nettyRequest = mock(DefaultFullHttpRequest.class); io.netty.handler.codec.http.HttpMethod httpMethod = mock(io.netty.handler.codec.http.HttpMethod.class); when(httpMethod.name()).thenReturn("GET"); when(nettyRequest.method()).thenReturn(httpMethod); HttpVersion httpVersion = mock(HttpVersion.class); when(httpVersion.text()).thenReturn("HTTP/1.0"); when(nettyRequest.protocolVersion()).thenReturn(httpVersion); when(nettyRequest.uri()).thenReturn("/odata.svc/$metadata"); HttpHeaders headers = mock(HttpHeaders.class); headers.add("Accept", "application/atom+xml"); Set<String> set = new HashSet<String>(); set.add("Accept"); when(headers.names()).thenReturn(set); when(nettyRequest.headers()).thenReturn(headers); when(nettyRequest.content()).thenReturn(Unpooled.buffer()); DefaultFullHttpResponse nettyResponse = mock(DefaultFullHttpResponse.class); when(nettyResponse.status()).thenReturn(HttpResponseStatus.OK); when(nettyResponse.headers()).thenReturn(headers); when(nettyResponse.content()).thenReturn(Unpooled.buffer()); Map<String, String> requestParams = new HashMap<String, String>(); requestParams.put("contextPath", "/odata.svc"); handler.processNettyRequest(nettyRequest, nettyResponse, requestParams); nettyResponse.status(); assertEquals(HttpStatusCode.OK.getStatusCode(), HttpResponseStatus.OK.code()); }
From source file:org.apache.olingo.netty.server.core.ODataNettyHandlerImplTest.java
License:Apache License
@Test public void testNettyReqResp_POSTMethod() { EntityProcessor processor = mock(EntityProcessor.class); final ODataNetty odata = ODataNetty.newInstance(); final ServiceMetadata metadata = odata.createServiceMetadata(new EdmTechProvider(), Collections.<EdmxReference>emptyList()); ODataNettyHandler handler = odata.createNettyHandler(metadata); handler.register(processor);//from w w w . j a va 2s . co m HttpRequest nettyRequest = mock(DefaultFullHttpRequest.class); io.netty.handler.codec.http.HttpMethod httpMethod = mock(io.netty.handler.codec.http.HttpMethod.class); when(httpMethod.name()).thenReturn("POST"); when(nettyRequest.method()).thenReturn(httpMethod); HttpVersion httpVersion = mock(HttpVersion.class); when(httpVersion.text()).thenReturn("HTTP/1.0"); when(nettyRequest.protocolVersion()).thenReturn(httpVersion); when(nettyRequest.uri()).thenReturn("/odata.svc/ESAllPrim"); HttpHeaders headers = mock(HttpHeaders.class); headers.set("Content-Type", "application/json"); Set<String> set = new HashSet<String>(); set.add("Content-Type"); when(headers.names()).thenReturn(set); List<String> headerValues = new ArrayList<String>(); headerValues.add("application/json"); when(headers.getAll("Content-Type")).thenReturn(headerValues); when(nettyRequest.headers()).thenReturn(headers); String content = "{\"@odata.context\": \"$metadata#ESAllPrim/$entity\"," + "\"PropertyInt16\": 32767," + "\"PropertyString\": \"First Resource &&&- positive values\"," + "\"PropertyBoolean\": true," + "\"PropertyByte\": 255," + "\"PropertySByte\": 127," + "\"PropertyInt32\": 2147483647," + "\"PropertyInt64\": 9223372036854775807," + "\"PropertySingle\": 17900000," + "\"PropertyDouble\": -179000," + "\"PropertyDecimal\": 34," + "\"PropertyBinary\": \"ASNFZ4mrze8=\"," + "\"PropertyDate\": \"2012-12-03\"," + "\"PropertyDateTimeOffset\": \"2012-12-03T07:16:23Z\"," + "\"PropertyDuration\": \"PT6S\"," + "\"PropertyGuid\": \"01234567-89ab-cdef-0123-456789abcdef\"," + "\"PropertyTimeOfDay\": \"03:26:05\"}"; byte[] arr = new byte[content.length()]; arr = content.getBytes(); when(((DefaultFullHttpRequest) nettyRequest).content()).thenReturn(Unpooled.copiedBuffer(arr)); HttpResponse nettyResponse = mock(DefaultFullHttpResponse.class); when(nettyResponse.status()).thenReturn(HttpResponseStatus.CREATED); when(nettyResponse.headers()).thenReturn(headers); when(((DefaultFullHttpResponse) nettyResponse).content()).thenReturn(Unpooled.buffer()); Map<String, String> requestParams = new HashMap<String, String>(); requestParams.put("contextPath", "/odata.svc"); handler.processNettyRequest(nettyRequest, nettyResponse, requestParams); nettyResponse.status(); assertEquals(HttpStatusCode.CREATED.getStatusCode(), HttpResponseStatus.CREATED.code()); }
From source file:org.ebayopensource.scc.cache.RequestKeyGenerator.java
License:Apache License
private String getRequestHash(FullHttpRequest request) { HttpHeaders headers = request.headers(); String requestURI = getRequestURI(request); HttpMethod requestMethod = request.getMethod(); Set<String> skipHeaders = m_skipHeaders; boolean skipRequestContent = m_uriMatchEnabled && WildcardMatcher.isPatternCanBeMatchedIn(m_uriMatchOnly, new CacheDecisionObject(requestURI, requestMethod.name())); if (skipRequestContent) { skipHeaders = new HashSet<>(m_skipHeaders); skipHeaders.add(HttpHeaders.Names.CONTENT_LENGTH.toUpperCase()); }/*from ww w. j a va2 s. c o m*/ int uriHashcode = requestURI.hashCode(); int methodHashCode = requestMethod.hashCode(); List<Entry<String, String>> entries = headers.entries(); List<String> hashList = new ArrayList<>(); for (Iterator<Entry<String, String>> it = entries.iterator(); it.hasNext();) { Entry<String, String> entry = it.next(); if (skipHeaders.contains(entry.getKey().toUpperCase())) { continue; } hashList.add(entry.getKey()); hashList.add(entry.getValue()); } int headersHashcode = hashList.hashCode(); StringBuilder sb = new StringBuilder(4); sb.append(uriHashcode).append(methodHashCode).append(headersHashcode); if (!skipRequestContent) { ByteBuf content = request.content(); sb.append(content.hashCode()); } return Checksum.checksum(sb.toString()); }
From source file:org.elasticsearch.http.nio.HttpReadWriteHandlerTests.java
License:Apache License
private NioHttpRequest prepareHandlerForResponse(HttpReadWriteHandler handler) throws IOException { HttpMethod method = randomBoolean() ? HttpMethod.GET : HttpMethod.HEAD; HttpVersion version = randomBoolean() ? HttpVersion.HTTP_1_0 : HttpVersion.HTTP_1_1; String uri = "http://localhost:9090/" + randomAlphaOfLength(8); io.netty.handler.codec.http.HttpRequest request = new DefaultFullHttpRequest(version, method, uri); ByteBuf buf = requestEncoder.encode(request); try {/*from ww w .j a v a 2 s. c om*/ handler.consumeReads(toChannelBuffer(buf)); } finally { buf.release(); } ArgumentCaptor<NioHttpRequest> requestCaptor = ArgumentCaptor.forClass(NioHttpRequest.class); verify(transport, atLeastOnce()).incomingRequest(requestCaptor.capture(), any(HttpChannel.class)); NioHttpRequest nioHttpRequest = requestCaptor.getValue(); assertNotNull(nioHttpRequest); assertEquals(method.name(), nioHttpRequest.method().name()); if (version == HttpVersion.HTTP_1_1) { assertEquals(HttpRequest.HttpVersion.HTTP_1_1, nioHttpRequest.protocolVersion()); } else { assertEquals(HttpRequest.HttpVersion.HTTP_1_0, nioHttpRequest.protocolVersion()); } assertEquals(nioHttpRequest.uri(), uri); return nioHttpRequest; }
From source file:org.jboss.aerogear.webpush.WebPushClient.java
License:Apache License
private Http2Headers http2Headers(final HttpMethod method, final String url) { final URI hostUri = URI.create("https://" + host + ":" + port + "/" + url); final Http2Headers headers = new DefaultHttp2Headers().method(AsciiString.of(method.name())); headers.path(asciiString(url));//from w ww . ja v a 2s . c om headers.authority(asciiString(hostUri.getAuthority())); headers.scheme(asciiString(hostUri.getScheme())); return headers; }
From source file:org.nosceon.titanite.Router.java
License:Apache License
private Method map(HttpMethod method) { try {//ww w . j a va 2 s .co m return Method.valueOf(method.name()); } catch (IllegalArgumentException e) { return null; } }