List of usage examples for io.netty.handler.codec.http HttpVersion HttpVersion
public HttpVersion(String text, boolean keepAliveDefault)
From source file:org.kaaproject.kaa.server.transports.http.transport.netty.ResponseEncoderTest.java
License:Apache License
@SuppressWarnings("unchecked") @Before/*from w w w.j a va 2 s . c o m*/ public void before() { Channel channel = mock(Channel.class); Attribute attribute = mock(Attribute.class); when(response.getProtocolVersion()).thenReturn(new HttpVersion("HTTP/1.1", true)); when(channelHandlerContext.channel()).thenReturn(channel); when(channelHandlerContext.writeAndFlush(any(Object.class))).thenReturn(future); when(channel.attr(AbstractNettyServer.UUID_KEY)).thenReturn(attribute); when(abstractCommand.getResponse()).thenReturn(response); }
From source file:org.wso2.carbon.gateway.internal.transport.common.Util.java
License:Open Source License
@SuppressWarnings("unchecked") public static HttpResponse createHttpResponse(CarbonMessage msg) { HttpVersion httpVersion = new HttpVersion(Util.getStringValue(msg, Constants.HTTP_VERSION, HTTP_1_1.text()), true);//w ww .j a v a2 s . c o m int statusCode = Util.getIntValue(msg, Constants.HTTP_STATUS_CODE, 200); HttpResponseStatus httpResponseStatus = new HttpResponseStatus(statusCode, HttpResponseStatus.valueOf(statusCode).reasonPhrase()); DefaultHttpResponse outgoingResponse = new DefaultHttpResponse(httpVersion, httpResponseStatus, false); Map<String, String> headerMap = (Map) msg.getProperty(Constants.TRANSPORT_HEADERS); Util.setHeaders(outgoingResponse, headerMap); return outgoingResponse; }
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 w w w . j a va 2s .c o 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); } 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 HttpResponse createHttpResponse(HTTPCarbonMessage msg, boolean connectionCloseAfterResponse) { HttpVersion httpVersion = new HttpVersion(Util.getStringValue(msg, Constants.HTTP_VERSION, HTTP_1_1.text()), true);//from w w w.j ava 2 s . c om int statusCode = Util.getIntValue(msg, Constants.HTTP_STATUS_CODE, 200); String reasonPhrase = Util.getStringValue(msg, Constants.HTTP_REASON_PHRASE, HttpResponseStatus.valueOf(statusCode).reasonPhrase()); HttpResponseStatus httpResponseStatus = new HttpResponseStatus(statusCode, reasonPhrase); DefaultHttpResponse outgoingResponse = new DefaultHttpResponse(httpVersion, httpResponseStatus, false); if (connectionCloseAfterResponse) { msg.setHeader(Constants.HTTP_CONNECTION, Constants.CONNECTION_CLOSE); } outgoingResponse.headers().setAll(msg.getHeaders()); return outgoingResponse; }
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 .ja v a2s.com*/ 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; }