本文整理匯總了Java中io.netty.handler.codec.http.DefaultHttpRequest類的典型用法代碼示例。如果您正苦於以下問題:Java DefaultHttpRequest類的具體用法?Java DefaultHttpRequest怎麽用?Java DefaultHttpRequest使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
DefaultHttpRequest類屬於io.netty.handler.codec.http包,在下文中一共展示了DefaultHttpRequest類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: adapter
import io.netty.handler.codec.http.DefaultHttpRequest; //導入依賴的package包/類
public static HttpRequest adapter(HttpRequest httpRequest) {
if (httpRequest instanceof DefaultHttpRequest) {
HttpVer version;
if (httpRequest.protocolVersion().minorVersion() == 0) {
version = HttpVer.HTTP_1_0;
} else {
version = HttpVer.HTTP_1_1;
}
HttpHeadsInfo httpHeadsInfo = new HttpHeadsInfo();
for (Entry<String, String> entry : httpRequest.headers()) {
httpHeadsInfo.set(entry.getKey(), entry.getValue());
}
return new HttpRequestInfo(version, httpRequest.method().toString(), httpRequest.uri(),
httpHeadsInfo, null);
}
return httpRequest;
}
示例2: streamDownstreamCall_setsHostHeaderCorrectly
import io.netty.handler.codec.http.DefaultHttpRequest; //導入依賴的package包/類
@DataProvider(value = {
"80 | false | localhost | localhost",
"80 | true | localhost | localhost:80",
"8080 | false | localhost | localhost:8080",
"443 | true | localhost | localhost",
"443 | false | localhost | localhost:443",
"8080 | true | localhost | localhost:8080",
}, splitBy = "\\|")
@Test
public void streamDownstreamCall_setsHostHeaderCorrectly(int downstreamPort, boolean isSecure, String downstreamHost, String expectedHostHeader) {
// given
DefaultHttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "");
ChannelHandlerContext ctx = mockChannelHandlerContext();
StreamingCallback streamingCallback = mock(StreamingCallback.class);
// when
new StreamingAsyncHttpClient(200, 200, true)
.streamDownstreamCall(downstreamHost, downstreamPort, request, isSecure, false, streamingCallback, 200, ctx);
// then
assertThat(request.headers().get(HOST)).isEqualTo(expectedHostHeader);
}
示例3: HttpClientOperations
import io.netty.handler.codec.http.DefaultHttpRequest; //導入依賴的package包/類
HttpClientOperations(Channel channel,
BiFunction<? super HttpClientResponse, ? super HttpClientRequest, ? extends Publisher<Void>> handler,
ContextHandler<?> context) {
super(channel, handler, context);
this.isSecure = channel.pipeline()
.get(NettyPipeline.SslHandler) != null;
String[] redirects = channel.attr(REDIRECT_ATTR_KEY)
.get();
this.redirectedFrom = redirects == null ? EMPTY_REDIRECTIONS : redirects;
this.nettyRequest =
new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/");
this.requestHeaders = nettyRequest.headers();
this.requestHeaders.set(HttpHeaderNames.USER_AGENT, HttpClient.USER_AGENT);
this.inboundPrefetch = 16;
chunkedTransfer(true);
}
示例4: channelRead0
import io.netty.handler.codec.http.DefaultHttpRequest; //導入依賴的package包/類
@Override
public void channelRead0(ChannelHandlerContext ctx, DefaultHttpRequest request)
throws Exception {
// TODO Auto-generated method stub
if(request.getMethod().equals(RtspMethods.TEARDOWN))
handleRtspTEARDOWNMethod(ctx,request);
else if(request.getMethod().equals(RtspMethods.OPTIONS))
handleRtspOPTIONSMethod(ctx,request);
else if(request.getMethod().equals(RtspMethods.DESCRIBE))
handleRtspDESCRIBEMethod(ctx,request);
else if(request.getMethod().equals(RtspMethods.SETUP))
handleRtspSETUPMethod(ctx,request);
else if(request.getMethod().equals(RtspMethods.PLAY))
handleRtspPLAYMethod(ctx,request);
else if(request.getMethod().equals(RtspMethods.PAUSE))
handleRtspPAUSEMethod(ctx,request);
else
System.err.println("Exception in ServerHandler");
}
示例5: setUp
import io.netty.handler.codec.http.DefaultHttpRequest; //導入依賴的package包/類
@BeforeMethod
public void setUp() throws Exception {
HTTPCarbonMessage httpCarbonMessage = new HTTPCarbonMessage(
new DefaultHttpRequest(HttpVersion.HTTP_1_1, io.netty.handler.codec.http.HttpMethod.GET, "msf4j"));
httpCarbonMessage.getHeaders().add("testA", "test1");
httpCarbonMessage.getHeaders().add("testA", "test2");
httpCarbonMessage.setHeader("Accept", "application/json");
httpCarbonMessage.setHeader("Content-Type", "text/html");
httpCarbonMessage.setHeader("Content-Language", "en");
httpCarbonMessage.setHeader("Content-Length", "1024");
httpCarbonMessage.setHeader("Date", "Sun, 06 Nov 1994 08:49:37 GMT");
httpCarbonMessage.getHeaders().add("Accept-Language", "da");
httpCarbonMessage.getHeaders().add("Accept-Language", "en-gb;q=0.8");
httpCarbonMessage.getHeaders().add("Accept-Language", "en;q=0.7");
httpCarbonMessage.getHeaders().add("Cookie", "JSESSIONID=3508015E4EF0ECA8C4B761FCC4BC1718");
httpHeaders1 = new HttpHeadersImpl(httpCarbonMessage.getHeaders());
HTTPCarbonMessage httpCarbonMessage2 = new HTTPCarbonMessage(
new DefaultHttpRequest(HttpVersion.HTTP_1_1, io.netty.handler.codec.http.HttpMethod.GET, "msf4j"));
httpHeaders2 = new HttpHeadersImpl(httpCarbonMessage2.getHeaders());
}
示例6: createHttpRequest
import io.netty.handler.codec.http.DefaultHttpRequest; //導入依賴的package包/類
@SuppressWarnings("unchecked")
public static HttpRequest createHttpRequest(HTTPCarbonMessage msg) {
HttpMethod httpMethod;
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;
}
示例7: createHttpRequest
import io.netty.handler.codec.http.DefaultHttpRequest; //導入依賴的package包/類
private HTTPCarbonMessage createHttpRequest(String method, String location) {
URL locationUrl = null;
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;
}
示例8: testAuthenticationHeaderMissing
import io.netty.handler.codec.http.DefaultHttpRequest; //導入依賴的package包/類
@Test(expected = AuthenticationHeaderMissingException.class)
public void testAuthenticationHeaderMissing() throws Exception {
AuthenticationProvider authenticationProvider = EasyMock
.createMock(AuthenticationProvider.class);
HttpRequest httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1,
HttpMethod.GET, "testUri");
Module module = new DiscardingModule();
Session session = module.startSession(null);
session.setCustomer(new Customer("testUserName", "testPassword"));
session.setServiceName("testServiceName");
module.close();
EasyMock.replay(authenticationProvider);
@SuppressWarnings("resource")
// close() method invokes only authenticationProvider.close(), which has been invoked explicitly above.
AuthenticationPreProcessor authenticationPreProcessor = new AuthenticationPreProcessor(
authenticationProvider);
authenticationPreProcessor.process(httpRequest, session);
EasyMock.verify(authenticationProvider);
}
示例9: testSuccessfulAdding
import io.netty.handler.codec.http.DefaultHttpRequest; //導入依賴的package包/類
@Test
public void testSuccessfulAdding() {
Accountancy accountancy = EasyMock.createMock(Accountancy.class);
Module module = new DiscardingModule();
Session session = module.startSession(null);
session.setCustomer(new Customer("testUserName", "testPassword"));
session.setServiceName("testServiceName");
module.close();
Capture<AccountancyItem> capture = new Capture<AccountancyItem>();
accountancy.addItem(EasyMock.capture(capture));
EasyMock.replay(accountancy);
accountancyPostProcessor = new AccountancyPostProcessor(accountancy);
accountancyPostProcessor.process(new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/testRequestPath"), session);
EasyMock.verify(accountancy);
}
示例10: testCustomerIsNull
import io.netty.handler.codec.http.DefaultHttpRequest; //導入依賴的package包/類
@Test(expected = IllegalStateException.class)
public void testCustomerIsNull() {
Accountancy accountancy = EasyMock.createMock(Accountancy.class);
Module module = new DiscardingModule();
Session session = module.startSession(null);
// The lack of setter invocation for customer
session.setServiceName("testServiceName");
module.close();
EasyMock.replay(accountancy);
accountancyPostProcessor = new AccountancyPostProcessor(accountancy);
accountancyPostProcessor.process(new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/testRequestPath"), session);
EasyMock.verify(accountancy);
}
示例11: testServiceNameIsNull
import io.netty.handler.codec.http.DefaultHttpRequest; //導入依賴的package包/類
@Test(expected = IllegalStateException.class)
public void testServiceNameIsNull() {
Accountancy accountancy = EasyMock.createMock(Accountancy.class);
Module module = new DiscardingModule();
Session session = module.startSession(null);
session.setCustomer(new Customer("testUserName", "testPassword"));
// The lack of setter invocation for service name
module.close();
EasyMock.replay(accountancy);
accountancyPostProcessor = new AccountancyPostProcessor(accountancy);
accountancyPostProcessor.process(new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/testRequestPath"), session);
EasyMock.verify(accountancy);
}
示例12: testCustomerAndServiceNameAreNull
import io.netty.handler.codec.http.DefaultHttpRequest; //導入依賴的package包/類
@Test(expected = IllegalStateException.class)
public void testCustomerAndServiceNameAreNull() {
Accountancy accountancy = EasyMock.createMock(Accountancy.class);
Module module = new DiscardingModule();
Session session = module.startSession(null);
// The lack of setter invocation for customer
// The lack of setter invocation for service name
module.close();
EasyMock.replay(accountancy);
accountancyPostProcessor = new AccountancyPostProcessor(accountancy);
accountancyPostProcessor.process(new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/testRequestPath"), session);
EasyMock.verify(accountancy);
}
示例13: testThreadBoundaries
import io.netty.handler.codec.http.DefaultHttpRequest; //導入依賴的package包/類
@Test
public void testThreadBoundaries() throws Exception {
Thread thread =
new Thread(
new Runnable() {
public void run() {
EmbeddedChannel channel =
new EmbeddedChannel(
new HttpServerTracingHandler(httpTracingState), new ApplicationHandler());
DefaultHttpRequest request = new DefaultHttpRequest(HTTP_1_1, GET, "/foo");
channel.writeInbound(request);
channel.runPendingTasks();
synchronized (httpTracing) {
httpTracing.notify();
}
}
});
thread.start();
synchronized (httpTracing) {
httpTracing.wait();
}
Assert.assertEquals(2, spans.size());
}
示例14: testDeniedRule
import io.netty.handler.codec.http.DefaultHttpRequest; //導入依賴的package包/類
@Test
public void testDeniedRule() throws UnknownHostException {
List<Http1DeterministicRuleEngineConfig.Rule> blacklist = new ArrayList<>();
HashMultimap<String, String> headers = HashMultimap.create();
headers.put("User-Agent", "Bad-actor: 1.0");
Http1DeterministicRuleEngineConfig.Rule bad =
new Http1DeterministicRuleEngineConfig.Rule(
HttpMethod.GET, "/path/to/failure", HttpVersion.HTTP_1_0, headers);
blacklist.add(bad);
Http1Filter http1Filter =
new Http1Filter(new Http1FilterConfig(ImmutableList.copyOf(blacklist)));
EmbeddedChannel chDeny = new EmbeddedChannel(http1Filter);
DefaultHttpRequest request =
new DefaultHttpRequest(HttpVersion.HTTP_1_0, HttpMethod.GET, "/path/to/failure");
request.headers().set("User-Agent", "Bad-actor: 1.0");
chDeny.writeInbound(request);
chDeny.runPendingTasks();
assertFalse(chDeny.isActive());
assertFalse(chDeny.isOpen());
}
示例15: testAllowedRule
import io.netty.handler.codec.http.DefaultHttpRequest; //導入依賴的package包/類
@Test
public void testAllowedRule() throws UnknownHostException {
List<Http1DeterministicRuleEngineConfig.Rule> blacklist = new ArrayList<>();
HashMultimap<String, String> headers = HashMultimap.create();
headers.put("User-Agent", "Bad-actor: 1.0");
Http1DeterministicRuleEngineConfig.Rule bad =
new Http1DeterministicRuleEngineConfig.Rule(
HttpMethod.POST, "/path/to/failure", HttpVersion.HTTP_1_1, headers);
blacklist.add(bad);
Http1Filter http1Filter =
new Http1Filter(new Http1FilterConfig(ImmutableList.copyOf(blacklist)));
EmbeddedChannel chAllow = new EmbeddedChannel(http1Filter);
DefaultHttpRequest request =
new DefaultHttpRequest(HttpVersion.HTTP_1_0, HttpMethod.GET, "/path/to/failure");
request.headers().set("User-Agent", "Bad-actor: 1.0");
chAllow.writeInbound(request);
assertTrue(chAllow.isActive());
assertTrue(chAllow.isOpen());
}