當前位置: 首頁>>代碼示例>>Java>>正文


Java DefaultHttpRequest類代碼示例

本文整理匯總了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;
}
 
開發者ID:monkeyWie,項目名稱:proxyee-down,代碼行數:18,代碼來源:HttpRequestInfo.java

示例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);
}
 
開發者ID:Nike-Inc,項目名稱:riposte,代碼行數:23,代碼來源:StreamingAsyncHttpClientTest.java

示例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);
}
 
開發者ID:reactor,項目名稱:reactor-netty,代碼行數:17,代碼來源:HttpClientOperations.java

示例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");
   }
 
開發者ID:Kyunghwa-Yoo,項目名稱:StitchRTSP,代碼行數:21,代碼來源:ServerHandler.java

示例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());
}
 
開發者ID:wso2,項目名稱:msf4j,代碼行數:22,代碼來源:HttpHeadersImplTest.java

示例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;
}
 
開發者ID:wso2,項目名稱:carbon-transports,代碼行數:24,代碼來源:Util.java

示例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;
}
 
開發者ID:wso2,項目名稱:carbon-transports,代碼行數:24,代碼來源:HTTPClientRedirectTestCase.java

示例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);
	
}
 
開發者ID:datacleaner,項目名稱:easydq_webservice_proxy,代碼行數:26,代碼來源:AuthenticationPreProcessorTest.java

示例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);
}
 
開發者ID:datacleaner,項目名稱:easydq_webservice_proxy,代碼行數:21,代碼來源:AccountancyPostProcessorTest.java

示例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);
}
 
開發者ID:datacleaner,項目名稱:easydq_webservice_proxy,代碼行數:17,代碼來源:AccountancyPostProcessorTest.java

示例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);
}
 
開發者ID:datacleaner,項目名稱:easydq_webservice_proxy,代碼行數:17,代碼來源:AccountancyPostProcessorTest.java

示例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);
}
 
開發者ID:datacleaner,項目名稱:easydq_webservice_proxy,代碼行數:17,代碼來源:AccountancyPostProcessorTest.java

示例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());
}
 
開發者ID:xjdr,項目名稱:xio,代碼行數:27,代碼來源:HttpServerTracingHandlerTest.java

示例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());
}
 
開發者ID:xjdr,項目名稱:xio,代碼行數:21,代碼來源:Http1FilterUnitTest.java

示例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());
}
 
開發者ID:xjdr,項目名稱:xio,代碼行數:21,代碼來源:Http1FilterUnitTest.java


注:本文中的io.netty.handler.codec.http.DefaultHttpRequest類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。