List of usage examples for io.netty.handler.codec.http HttpMethod HttpMethod
public HttpMethod(String name)
From source file:com.ning.http.client.providers.netty_4.NettyAsyncHttpProvider.java
License:Apache License
protected final static HttpRequest buildRequest(AsyncHttpClientConfig config, Request request, URI uri, boolean allowConnect, ByteBuf buffer, ProxyServer proxyServer) throws IOException { String method = request.getMethod(); if (allowConnect && proxyServer != null && isSecure(uri)) { method = HttpMethod.CONNECT.toString(); }// w w w . j ava 2s.co m return construct(config, request, new HttpMethod(method), uri, buffer, proxyServer); }
From source file:org.wso2.carbon.gateway.internal.transport.common.Util.java
License:Open Source License
@SuppressWarnings("unchecked") public static HttpRequest createHttpRequest(CarbonMessage msg) { HttpMethod httpMethod;/*from ww w . java2 s.c om*/ if (null != msg.getProperty(Constants.HTTP_METHOD)) { httpMethod = new HttpMethod((String) msg.getProperty(Constants.HTTP_METHOD)); } else { httpMethod = new HttpMethod(DEFAULT_HTTP_METHOD_POST); } HttpVersion httpVersion; if (null != msg.getProperty(Constants.HTTP_VERSION)) { httpVersion = new HttpVersion((String) msg.getProperty(Constants.HTTP_VERSION), true); } else { httpVersion = new HttpVersion(DEFAULT_VERSION_HTTP_1_1, true); } HttpRequest outgoingRequest = new DefaultHttpRequest(httpVersion, httpMethod, msg.getURI(), true); Map headers = (Map) msg.getProperty(Constants.TRANSPORT_HEADERS); Util.setHeaders(outgoingRequest, headers); return outgoingRequest; }
From source file:org.wso2.carbon.transport.http.netty.common.Util.java
License:Open Source License
@SuppressWarnings("unchecked") public static HttpRequest createHttpRequest(HTTPCarbonMessage msg) { HttpMethod httpMethod;/*from w w w .j av a2s . co m*/ if (null != msg.getProperty(Constants.HTTP_METHOD)) { httpMethod = new HttpMethod((String) msg.getProperty(Constants.HTTP_METHOD)); } else { httpMethod = new HttpMethod(DEFAULT_HTTP_METHOD_POST); } HttpVersion httpVersion; if (null != msg.getProperty(Constants.HTTP_VERSION)) { httpVersion = new HttpVersion((String) msg.getProperty(Constants.HTTP_VERSION), true); } else { httpVersion = new HttpVersion(DEFAULT_VERSION_HTTP_1_1, true); } if ((String) msg.getProperty(Constants.TO) == null) { msg.setProperty(Constants.TO, "/"); } HttpRequest outgoingRequest = new DefaultHttpRequest(httpVersion, httpMethod, (String) msg.getProperty(Constants.TO), false); HttpHeaders headers = msg.getHeaders(); outgoingRequest.headers().setAll(headers); return outgoingRequest; }
From source file:org.wso2.carbon.transport.http.netty.redirect.HTTPClientRedirectTestCase.java
License:Open Source License
private HTTPCarbonMessage createHttpRequest(String method, String location) { URL locationUrl = null;/*from w w w .j a va2 s. co m*/ try { locationUrl = new URL(location); } catch (MalformedURLException e) { TestUtil.handleException("MalformedURLException occurred while running unitTestForRedirectHandler ", e); } HttpMethod httpMethod = new HttpMethod(method); HTTPCarbonMessage httpCarbonRequest = new HTTPCarbonMessage( new DefaultHttpRequest(HttpVersion.HTTP_1_1, httpMethod, "")); httpCarbonRequest.setProperty(Constants.PORT, locationUrl.getPort()); httpCarbonRequest.setProperty(Constants.PROTOCOL, locationUrl.getProtocol()); httpCarbonRequest.setProperty(Constants.HOST, locationUrl.getHost()); httpCarbonRequest.setProperty(Constants.HTTP_METHOD, method); httpCarbonRequest.setProperty(Constants.REQUEST_URL, locationUrl.getPath()); httpCarbonRequest.setProperty(Constants.TO, locationUrl.getPath()); httpCarbonRequest.setHeader(Constants.HOST, locationUrl.getHost()); httpCarbonRequest.setHeader(Constants.PORT, Integer.toString(locationUrl.getPort())); httpCarbonRequest.setEndOfMsgAdded(true); return httpCarbonRequest; }
From source file:org.wso2.carbon.transport.http.netty.sender.RedirectHandler.java
License:Open Source License
/** * Create redirect request./*w w w . j a v a2 s.c o m*/ * * @return HTTPCarbonMessage with request properties * @throws MalformedURLException */ private HTTPCarbonMessage createHttpCarbonRequest() throws MalformedURLException { if (LOG.isDebugEnabled()) { LOG.debug("Create redirect request with http method : " + redirectState.get(Constants.HTTP_METHOD)); } URL locationUrl = new URL(redirectState.get(Constants.LOCATION)); HttpMethod httpMethod = new HttpMethod(redirectState.get(Constants.HTTP_METHOD)); HTTPCarbonMessage httpCarbonRequest = new HTTPCarbonMessage( new DefaultHttpRequest(HttpVersion.HTTP_1_1, httpMethod, "")); httpCarbonRequest.setProperty(Constants.PORT, locationUrl.getPort() != -1 ? locationUrl.getPort() : getDefaultPort(locationUrl.getProtocol())); httpCarbonRequest.setProperty(Constants.PROTOCOL, locationUrl.getProtocol()); httpCarbonRequest.setProperty(Constants.HOST, locationUrl.getHost()); httpCarbonRequest.setProperty(Constants.HTTP_METHOD, redirectState.get(Constants.HTTP_METHOD)); httpCarbonRequest.setProperty(Constants.REQUEST_URL, locationUrl.getPath()); httpCarbonRequest.setProperty(Constants.TO, locationUrl.getPath()); StringBuffer host = new StringBuffer(locationUrl.getHost()); if (locationUrl.getPort() != -1 && locationUrl.getPort() != Constants.DEFAULT_HTTP_PORT && locationUrl.getPort() != Constants.DEFAULT_HTTPS_PORT) { host.append(Constants.COLON).append(locationUrl.getPort()); } httpCarbonRequest.setHeader(Constants.HOST, host.toString()); httpCarbonRequest.setEndOfMsgAdded(true); return httpCarbonRequest; }
From source file:reactor.io.net.impl.netty.http.NettyHttpClient.java
License:Open Source License
@Override public Promise<? extends HttpChannel<IN, OUT>> request(final Method method, final String url, final ReactorChannelHandler<IN, OUT, HttpChannel<IN, OUT>> handler) { final URI currentURI; try {/*from w w w . j av a2 s. co m*/ Assert.isTrue(method != null && url != null); currentURI = parseURL(method, url); lastURI = currentURI; } catch (Exception e) { return Promises.error(e); } start(new ReactorChannelHandler<IN, OUT, HttpChannel<IN, OUT>>() { @Override public Publisher<Void> apply(HttpChannel<IN, OUT> inoutHttpChannel) { try { final NettyHttpChannel<IN, OUT> ch = ((NettyHttpChannel<IN, OUT>) inoutHttpChannel); ch.getNettyRequest() .setUri(currentURI.getPath() + (currentURI.getQuery() == null ? "" : "?" + currentURI.getQuery())) .setMethod(new HttpMethod(method.getName())).headers() .add(HttpHeaders.Names.HOST, currentURI.getHost()).add(HttpHeaders.Names.ACCEPT, "*/*"); if (handler != null) { Publisher<Void> p = handler.apply(ch); reply.onNext(ch); return p; } else { reply.onNext(ch); return Streams.empty(); } } catch (Throwable t) { reply.onError(t); return Promises.error(t); } } }); return reply; }