org.jboss.netty.handler.codec.http.HttpMethod Java Examples
The following examples show how to use
org.jboss.netty.handler.codec.http.HttpMethod.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpServerRequestHandler.java From feeyo-hlsserver with Apache License 2.0 | 6 votes |
public HttpServerRequestHandler() { super(); // handlers registerHandler(HttpMethod.GET, "/", new WelcomeHandler()); registerHandler(HttpMethod.GET, "/hls/*/*", new HlsLiveHandler()); registerHandler(HttpMethod.GET, "/hls/vod/*/*", new HlsVodHandler()); registerHandler(HttpMethod.POST, "/hls/manage", new HlsManageHandler()); registerHandler(HttpMethod.GET, "/hls/streams", new HlsStreamsHandler()); // login & logout ... registerHandler(HttpMethod.GET, "/auth", new AuthHandler()); registerHandler(HttpMethod.POST, "/api/dns/update", new HttpServerTest.TestHandler()); // filters registerFilter(new HlsTrafficFilter(), Type.HLS); registerFilter(new AuthCheckFilter(), Type.VM, Type.API); }
Example #2
Source File: NettyHttpRequest.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override public Method method() { HttpMethod httpMethod = request.getMethod(); if (httpMethod == HttpMethod.GET) return Method.GET; if (httpMethod == HttpMethod.POST) return Method.POST; if (httpMethod == HttpMethod.PUT) return Method.PUT; if (httpMethod == HttpMethod.DELETE) return Method.DELETE; if (httpMethod == HttpMethod.HEAD) { return Method.HEAD; } if (httpMethod == HttpMethod.OPTIONS) { return Method.OPTIONS; } return Method.GET; }
Example #3
Source File: HttpServerRequestHandler.java From feeyo-hlsserver with Apache License 2.0 | 5 votes |
private void registerHandler(HttpMethod method, String path, IRequestHandler handler) { if (method == HttpMethod.GET) { getHandlers.insert(path, handler); } else if (method == HttpMethod.POST) { postHandlers.insert(path, handler); } else { throw new RuntimeException("HttpMethod is not supported"); } }
Example #4
Source File: TestShuffleHandler.java From tez with Apache License 2.0 | 5 votes |
public HttpRequest createMockHttpRequest() { HttpRequest mockHttpRequest = mock(HttpRequest.class); Mockito.doReturn(HttpMethod.GET).when(mockHttpRequest).getMethod(); Mockito.doReturn(new DefaultHttpHeaders()).when(mockHttpRequest).headers(); Mockito.doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { String uri = "/mapOutput?job=job_12345_1&dag=1&reduce=1"; for (int i = 0; i < 100; i++) uri = uri.concat("&map=attempt_12345_1_m_" + i + "_0"); return uri; } }).when(mockHttpRequest).getUri(); return mockHttpRequest; }
Example #5
Source File: HttpClusterUpdateSettingsAction.java From elasticsearch-helper with Apache License 2.0 | 5 votes |
@Override protected HttpRequest createHttpRequest(URL url, ClusterUpdateSettingsRequest request) throws IOException { XContentBuilder builder = jsonBuilder(); builder.startObject().startObject("persistent"); request.persistentSettings().toXContent(builder, ToXContent.EMPTY_PARAMS); builder.endObject(); builder.startObject("transient"); request.transientSettings().toXContent(builder, ToXContent.EMPTY_PARAMS); builder.endObject().endObject(); return newRequest(HttpMethod.PUT, url, "/_cluster/settings", builder.string()); }
Example #6
Source File: HttpUpdateSettingsAction.java From elasticsearch-helper with Apache License 2.0 | 5 votes |
@Override protected HttpRequest createHttpRequest(URL url, UpdateSettingsRequest request) throws IOException { XContentBuilder builder = jsonBuilder(); builder.startObject(); request.settings().toXContent(builder, ToXContent.EMPTY_PARAMS); builder.endObject(); String index = request.indices() != null ? "/" + String.join(",", request.indices()) : "" ; return newRequest(HttpMethod.PUT, url, index + "/_settings", builder.string()); }
Example #7
Source File: HttpAction.java From elasticsearch-helper with Apache License 2.0 | 5 votes |
protected HttpRequest newRequest(HttpMethod method, URL url, String path, ChannelBuffer buffer) { HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, method, path); request.headers().add(HttpHeaders.Names.HOST, url.getHost()); request.headers().add(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.CLOSE); request.headers().add(HttpHeaders.Names.ACCEPT_ENCODING, HttpHeaders.Values.GZIP); if (buffer != null) { request.setContent(buffer); int length = request.getContent().readableBytes(); request.headers().add(HttpHeaders.Names.CONTENT_TYPE, "application/json"); request.headers().add(HttpHeaders.Names.CONTENT_LENGTH, length); } return request; }
Example #8
Source File: Echo.java From netty-cookbook with Apache License 2.0 | 5 votes |
public static void main(String[] args) { RestExpress server = new RestExpress().setName("Echo"); server.uri("/echo", new RestfulHandler()).method(HttpMethod.GET) .noSerialization(); server.bind(8000); server.awaitShutdown(); }
Example #9
Source File: RaopAudioHandler.java From Android-Airplay-Server with MIT License | 5 votes |
@Override public void messageReceived(final ChannelHandlerContext ctx, final MessageEvent evt) throws Exception { final HttpRequest req = (HttpRequest)evt.getMessage(); final HttpMethod method = req.getMethod(); LOG.info("messageReceived : HttpMethod: " + method); if (RaopRtspMethods.ANNOUNCE.equals(method)) { announceReceived(ctx, req); return; } else if (RaopRtspMethods.SETUP.equals(method)) { setupReceived(ctx, req); return; } else if (RaopRtspMethods.RECORD.equals(method)) { recordReceived(ctx, req); return; } else if (RaopRtspMethods.FLUSH.equals(method)) { flushReceived(ctx, req); return; } else if (RaopRtspMethods.TEARDOWN.equals(method)) { teardownReceived(ctx, req); return; } else if (RaopRtspMethods.SET_PARAMETER.equals(method)) { setParameterReceived(ctx, req); return; } else if (RaopRtspMethods.GET_PARAMETER.equals(method)) { getParameterReceived(ctx, req); return; } super.messageReceived(ctx, evt); }
Example #10
Source File: WrapFileClientHandler.java From netty-file-parent with Apache License 2.0 | 5 votes |
public WrapFileClientHandler(String host, URI uri, String userName, String pwd) { this.host = host; this.uri = uri; this.userName = userName; this.pwd = pwd; this.request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, uri.toASCIIString()); setHeaderDatas(); }
Example #11
Source File: KafkaHttpRpcPlugin.java From opentsdb-rpc-kafka with Apache License 2.0 | 5 votes |
@Override public void execute(final TSDB tsdb, final HttpRpcPluginQuery query) throws IOException { // only accept GET/POST for now if (query.request().getMethod() != HttpMethod.GET && query.request().getMethod() != HttpMethod.POST) { throw new BadRequestException(HttpResponseStatus.METHOD_NOT_ALLOWED, "Method not allowed", "The HTTP method [" + query.method().getName() + "] is not permitted for this endpoint"); } final String[] uri = query.explodePath(); final String endpoint = uri.length > 1 ? uri[2].toLowerCase() : ""; if ("version".equals(endpoint)) { handleVersion(query); } else if ("rate".equals(endpoint)) { handleRate(query); } else if ("namespace".equals(endpoint)) { handlePerNamespaceStats(query); } else if ("perthread".equals(endpoint)) { handlePerThreadStats(query); } else { throw new BadRequestException(HttpResponseStatus.NOT_IMPLEMENTED, "Hello. You have reached an API that has been disconnected. " + "Please call again."); } }
Example #12
Source File: NettyHttpServerTransport.java From Elasticsearch with Apache License 2.0 | 5 votes |
private CorsConfig buildCorsConfig(Settings settings) { if (settings.getAsBoolean(SETTING_CORS_ENABLED, false) == false) { return CorsConfigBuilder.forOrigins().disable().build(); } String origin = settings.get(SETTING_CORS_ALLOW_ORIGIN); final CorsConfigBuilder builder; if (Strings.isNullOrEmpty(origin)) { builder = CorsConfigBuilder.forOrigins(); } else if (origin.equals(ANY_ORIGIN)) { builder = CorsConfigBuilder.forAnyOrigin(); } else { Pattern p = RestUtils.checkCorsSettingForRegex(origin); if (p == null) { builder = CorsConfigBuilder.forOrigins(RestUtils.corsSettingAsArray(origin)); } else { builder = CorsConfigBuilder.forPattern(p); } } if (settings.getAsBoolean(SETTING_CORS_ALLOW_CREDENTIALS, false)) { builder.allowCredentials(); } String[] strMethods = settings.getAsArray(SETTING_CORS_ALLOW_METHODS, DEFAULT_CORS_METHODS); HttpMethod[] methods = new HttpMethod[strMethods.length]; for (int i = 0; i < methods.length; i++) { methods[i] = HttpMethod.valueOf(strMethods[i]); } return builder.allowedRequestMethods(methods) .maxAge(settings.getAsInt(SETTING_CORS_MAX_AGE, DEFAULT_CORS_MAX_AGE)) .allowedRequestHeaders(settings.getAsArray(SETTING_CORS_ALLOW_HEADERS, DEFAULT_CORS_HEADERS)) .shortCircuit() .build(); }
Example #13
Source File: CorsHandler.java From Elasticsearch with Apache License 2.0 | 5 votes |
private void setAllowMethods(final HttpResponse response) { Set<String> strMethods = new HashSet<>(); for (HttpMethod method : config.allowedRequestMethods()) { strMethods.add(method.getName().trim()); } response.headers().set(ACCESS_CONTROL_ALLOW_METHODS, strMethods); }
Example #14
Source File: HttpAction.java From elasticsearch-helper with Apache License 2.0 | 4 votes |
protected HttpRequest newPostRequest(URL url, String path, CharSequence content) { return newRequest(HttpMethod.POST, url, path, content); }
Example #15
Source File: HttpServerRequestHandler.java From feeyo-hlsserver with Apache License 2.0 | 4 votes |
private IRequestHandler getHandler(HttpRequest request) { IRequestHandler handler = null; //解析QueryString String uriString = request.getUri(); //获取Path String path = null; int pathEndPos = uriString.indexOf('?'); if (pathEndPos < 0) { path = uriString; } else { path = uriString.substring(0, pathEndPos); } // 获取参数 Map<String, String> parameters = new HashMap<String, String>(); if (uriString.startsWith("?")) { uriString = uriString.substring(1, uriString.length()); } String[] querys = uriString.split("&"); for (String query : querys) { String[] pair = query.split("="); if (pair.length == 2) { try { parameters.put(URLDecoder.decode(pair[0], "UTF8"), URLDecoder.decode(pair[1],"UTF8")); } catch (UnsupportedEncodingException e) { parameters.put(pair[0], pair[1]); } } } HttpMethod method = request.getMethod(); if (method == HttpMethod.GET) { handler = getHandlers.retrieve(path, parameters); } else if (method == HttpMethod.POST) { handler = postHandlers.retrieve(path, parameters); } return handler; }
Example #16
Source File: HttpRequestFrameworkAdapter.java From zuul-netty with Apache License 2.0 | 4 votes |
@Override public HttpMethod getMethod() { return request.getMethod(); }
Example #17
Source File: HttpSearchAction.java From elasticsearch-helper with Apache License 2.0 | 4 votes |
@Override protected HttpRequest createHttpRequest(URL url, SearchRequest request) throws IOException { String index = request.indices() != null ? "/" + String.join(",", request.indices()) : ""; return newRequest(HttpMethod.POST, url, index + "/_search", request.extraSource()); }
Example #18
Source File: CorsHandler.java From Elasticsearch with Apache License 2.0 | 4 votes |
private static boolean isPreflightRequest(final HttpRequest request) { final HttpHeaders headers = request.headers(); return request.getMethod().equals(HttpMethod.OPTIONS) && headers.contains(HttpHeaders.Names.ORIGIN) && headers.contains(HttpHeaders.Names.ACCESS_CONTROL_REQUEST_METHOD); }
Example #19
Source File: HttpAction.java From elasticsearch-helper with Apache License 2.0 | 4 votes |
protected HttpRequest newRequest(HttpMethod method, URL url, String path, BytesReference content) { return newRequest(method, url, path, content != null ? ChannelBuffers.copiedBuffer(content.toBytes()) : null); }
Example #20
Source File: HttpAction.java From elasticsearch-helper with Apache License 2.0 | 4 votes |
protected HttpRequest newRequest(HttpMethod method, URL url, String path, CharSequence content) { return newRequest(method, url, path, content != null ? ChannelBuffers.copiedBuffer(content, CharsetUtil.UTF_8) : null); }
Example #21
Source File: HttpAction.java From elasticsearch-helper with Apache License 2.0 | 4 votes |
protected HttpRequest newGetRequest(URL url, String path, CharSequence content) { return newRequest(HttpMethod.GET, url, path, content); }
Example #22
Source File: NettyAsyncHttpProvider.java From ck with Apache License 2.0 | 4 votes |
private final static HttpRequest buildRequest(AsyncHttpClientConfig config,Request request, URI uri) throws IOException{ return construct(config, request, new HttpMethod(request.getType().toString()), uri); }
Example #23
Source File: Pubsub.java From async-google-pubsub-client with Apache License 2.0 | 4 votes |
/** * Make an HTTP request. */ private <T> PubsubFuture<T> request(final String operation, final HttpMethod method, final String path, final ResponseReader<T> responseReader) { return request(operation, method, path, NO_PAYLOAD, responseReader); }
Example #24
Source File: Pubsub.java From async-google-pubsub-client with Apache License 2.0 | 4 votes |
/** * Make a DELETE request. */ private <T> PubsubFuture<T> delete(final String operation, final String path, final ResponseReader<T> responseReader) { return request(operation, HttpMethod.DELETE, path, responseReader); }
Example #25
Source File: Pubsub.java From async-google-pubsub-client with Apache License 2.0 | 4 votes |
/** * Make a PUT request. */ private <T> PubsubFuture<T> put(final String operation, final String path, final Object payload, final ResponseReader<T> responseReader) { return request(operation, HttpMethod.PUT, path, payload, responseReader); }
Example #26
Source File: Pubsub.java From async-google-pubsub-client with Apache License 2.0 | 4 votes |
/** * Make a POST request. */ private <T> PubsubFuture<T> post(final String operation, final String path, final Object payload, final ResponseReader<T> responseReader) { return request(operation, HttpMethod.POST, path, payload, responseReader); }
Example #27
Source File: Pubsub.java From async-google-pubsub-client with Apache License 2.0 | 4 votes |
/** * Make a GET request. */ private <T> PubsubFuture<T> get(final String operation, final String path, final ResponseReader<T> responseReader) { return request(operation, HttpMethod.GET, path, responseReader); }
Example #28
Source File: CorsConfigBuilder.java From Elasticsearch with Apache License 2.0 | 2 votes |
/** * Specifies the allowed set of HTTP Request Methods that should be returned in the * CORS 'Access-Control-Request-Method' response header. * * @param methods the {@link HttpMethod}s that should be allowed. * @return {@link CorsConfigBuilder} to support method chaining. */ public CorsConfigBuilder allowedRequestMethods(final HttpMethod... methods) { requestMethods.addAll(Arrays.asList(methods)); return this; }
Example #29
Source File: FrameworkHttpRequest.java From zuul-netty with Apache License 2.0 | 2 votes |
/** * Returns the method of this request. */ HttpMethod getMethod();
Example #30
Source File: CorsConfig.java From Elasticsearch with Apache License 2.0 | 2 votes |
/** * Returns the allowed set of Request Methods. The Http methods that should be returned in the * CORS 'Access-Control-Request-Method' response header. * * @return {@code Set} of {@link HttpMethod}s that represent the allowed Request Methods. */ public Set<HttpMethod> allowedRequestMethods() { return Collections.unmodifiableSet(allowedRequestMethods); }