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


Java HttpServerRequest類代碼示例

本文整理匯總了Java中io.vertx.core.http.HttpServerRequest的典型用法代碼示例。如果您正苦於以下問題:Java HttpServerRequest類的具體用法?Java HttpServerRequest怎麽用?Java HttpServerRequest使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


HttpServerRequest類屬於io.vertx.core.http包,在下文中一共展示了HttpServerRequest類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getFormattedElement

import io.vertx.core.http.HttpServerRequest; //導入依賴的package包/類
@Test
public void getFormattedElement() {
  RoutingContext mockContext = Mockito.mock(RoutingContext.class);
  AccessLogParam param = new AccessLogParam().setRoutingContext(mockContext);
  HttpServerRequest mockRequest = Mockito.mock(HttpServerRequest.class);
  VertxHttpHeaders headers = new VertxHttpHeaders();
  String testValue = "testValue";
  headers.add(HEADER_IDENTIFIER, testValue);

  Mockito.when(mockContext.request()).thenReturn(mockRequest);
  Mockito.when(mockRequest.headers()).thenReturn(headers);

  String result = ELEMENT.getFormattedElement(param);

  assertEquals(testValue, result);
  assertEquals(ELEMENT.getIdentifier(), HEADER_IDENTIFIER);
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:18,代碼來源:RequestHeaderElementTest.java

示例2: setBodyBuffer

import io.vertx.core.http.HttpServerRequest; //導入依賴的package包/類
@Test
public void setBodyBuffer() {
  Holder<Buffer> bodyHolder = new Holder<>();
  context = new MockUp<RoutingContext>() {
    @Mock
    HttpServerRequest request() {
      return vertxRequest;
    }

    @Mock
    void setBody(Buffer body) {
      bodyHolder.value = body;
    }
  }.getMockInstance();
  request = new VertxServerRequestToHttpServletRequest(context);

  Buffer bodyBuffer = Buffer.buffer();
  request.setBodyBuffer(bodyBuffer);

  Assert.assertSame(bodyBuffer, bodyHolder.value);
  Assert.assertSame(bodyBuffer, request.getBodyBuffer());
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:23,代碼來源:TestVertxServerRequestToHttpServletRequest.java

示例3: getDevNode

import io.vertx.core.http.HttpServerRequest; //導入依賴的package包/類
public Node getDevNode(App app,HttpServerRequest clientRequest){
	String hostport = clientRequest.getParam(app.name);
	String remoteip = clientRequest.remoteAddress().host();
	if(S.isNotBlank(hostport)){
		if("clear".equals(hostport)){
			devMode.remove(remoteip);
			log.debug("clear node of remote ip:"+remoteip);
			return null;
		}else{
			String[] ipp = hostport.split(":");
			Node n = app.createDevNode(ipp[0], Integer.parseInt(ipp[1]),1);
			devMode.put(remoteip, n);
			log.debug("remote ip visit setting:"+remoteip+" ["+app.name+"->"+hostport+"]");
			return n;
		}
	}else{
		return devMode.get(remoteip);
	}
}
 
開發者ID:troopson,項目名稱:etagate,代碼行數:20,代碼來源:DevModeSupport.java

示例4: getFormattedElement

import io.vertx.core.http.HttpServerRequest; //導入依賴的package包/類
@Override
public String getFormattedElement(AccessLogParam accessLogParam) {
  HttpServerRequest request = accessLogParam.getRoutingContext().request();
  if (null == request) {
    return EMPTY_RESULT;
  }

  SocketAddress localAddress = request.localAddress();
  if (null == localAddress) {
    return EMPTY_RESULT;
  }

  String localHost = localAddress.host();
  if (StringUtils.isEmpty(localHost)) {
    return EMPTY_RESULT;
  }
  return localHost;
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:19,代碼來源:LocalHostElement.java

示例5: getNode

import io.vertx.core.http.HttpServerRequest; //導入依賴的package包/類
@Override
public Node getNode(Optional<HttpServerRequest> clientRequest){
	if(size==1)
		return node.get(0);
	
	int times = 0;
	while(times<size){
		int idx = last.getAndIncrement();	
		Node n = null;
		if(idx>=size){
			last.set(1);
			n = node.get(0);
		}else
			n = node.get(idx);
		
		if(n.canTake())
			return n;	
		else
			times++;
	}	
	return null;
	
}
 
開發者ID:troopson,項目名稱:etagate,代碼行數:24,代碼來源:RoundNodeStrategy.java

示例6: handle

import io.vertx.core.http.HttpServerRequest; //導入依賴的package包/類
@Override
public void handle(RoutingContext context) {
  HttpServerRequest request = context.request();
  // we need to keep state since we can be called again on reroute
  Boolean handled = context.get(BODY_HANDLED);
  if (handled == null || !handled) {
    BHandler handler = new BHandler(context);
    request.handler(handler);
    request.endHandler(v -> handler.end());
    context.put(BODY_HANDLED, true);
  } else {
    // on reroute we need to re-merge the form params if that was desired
    if (mergeFormAttributes && request.isExpectMultipart()) {
      request.params().addAll(request.formAttributes());
    }

    context.next();
  }
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:20,代碼來源:RestBodyHandler.java

示例7: doEnd

import io.vertx.core.http.HttpServerRequest; //導入依賴的package包/類
void doEnd() {
  if (deleteUploadedFilesOnEnd) {
    if (failed) {
      deleteFileUploads();
    } else {
      context.addBodyEndHandler(x -> deleteFileUploads());
    }
  }

  if (failed) {
    return;
  }

  HttpServerRequest req = context.request();
  if (mergeFormAttributes && req.isExpectMultipart()) {
    req.params().addAll(req.formAttributes());
  }
  context.setBody(body);
  context.next();
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:21,代碼來源:RestBodyHandler.java

示例8: getFormattedElementIfNotFound

import io.vertx.core.http.HttpServerRequest; //導入依賴的package包/類
@Test
public void getFormattedElementIfNotFound() {
  RoutingContext mockContext = Mockito.mock(RoutingContext.class);
  AccessLogParam param = new AccessLogParam().setRoutingContext(mockContext);
  HttpServerRequest mockRequest = Mockito.mock(HttpServerRequest.class);
  VertxHttpHeaders headers = new VertxHttpHeaders();
  String testValue = "testValue";
  headers.add("anotherHeader", testValue);

  Mockito.when(mockContext.request()).thenReturn(mockRequest);
  Mockito.when(mockRequest.headers()).thenReturn(headers);

  String result = ELEMENT.getFormattedElement(param);

  assertEquals("-", result);
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:17,代碼來源:RequestHeaderElementTest.java

示例9: getDependAppAddr

import io.vertx.core.http.HttpServerRequest; //導入依賴的package包/類
public String getDependAppAddr(final HttpServerRequest request){
	if(this.depends==null || this.appcontain ==null )
		return null;
	
	StringBuilder sb = new StringBuilder();
	
	for(String d : this.depends){
		App a = this.appcontain.getAppInfo(d);
		if(a!=null){
			String v = a.retrievOneNodeHostPort(request);
			if(S.isNotBlank(v)){
				if(sb.length()>0)
					sb.append(",");
				sb.append(d).append("=").append(v);
			}
		}
	}
	
	return sb.toString();		
	
}
 
開發者ID:troopson,項目名稱:etagate,代碼行數:22,代碼來源:App.java

示例10: getFormattedElement

import io.vertx.core.http.HttpServerRequest; //導入依賴的package包/類
@Test
public void getFormattedElement() {
  AccessLogParam param = new AccessLogParam();
  RoutingContext context = Mockito.mock(RoutingContext.class);
  HttpServerRequest request = Mockito.mock(HttpServerRequest.class);
  SocketAddress localAddress = Mockito.mock(SocketAddress.class);

  param.setRoutingContext(context);
  Mockito.when(context.request()).thenReturn(request);
  Mockito.when(request.localAddress()).thenReturn(localAddress);
  Mockito.when(localAddress.port()).thenReturn(8080);

  String result = new LocalPortElement().getFormattedElement(param);

  assertEquals("8080", result);
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:17,代碼來源:LocalPortElementTest.java

示例11: getFormattedElement

import io.vertx.core.http.HttpServerRequest; //導入依賴的package包/類
@Test
public void getFormattedElement() {
  AccessLogParam param = new AccessLogParam();
  RoutingContext mockContext = Mockito.mock(RoutingContext.class);
  HttpServerRequest request = Mockito.mock(HttpServerRequest.class);
  String uri = "/test/uri";

  param.setRoutingContext(mockContext);
  Mockito.when(mockContext.request()).thenReturn(request);
  Mockito.when(request.method()).thenReturn(HttpMethod.DELETE);
  Mockito.when(request.path()).thenReturn(uri);
  Mockito.when(request.version()).thenReturn(HttpVersion.HTTP_1_1);

  String result = ELEMENT.getFormattedElement(param);

  assertEquals("\"DELETE " + uri + " HTTP/1.1\"", result);
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:18,代碼來源:FirstLineOfRequestElementTest.java

示例12: proxyUserRequest

import io.vertx.core.http.HttpServerRequest; //導入依賴的package包/類
/**
 * Proxies the specified HTTP request, enriching its headers with authentication information.
 *
 * @param userId  the ID of the user making the request.
 * @param origReq the original request (i.e., {@link RoutingContext#request()}.
 * @param origRes the original response (i.e., {@link RoutingContext#request()}.
 */
public void proxyUserRequest(final String userId,
                             final HttpServerRequest origReq,
                             final HttpServerResponse origRes) {
    final Handler<HttpClientResponse> proxiedResHandler = proxiedRes -> {
        origRes.setChunked(true);
        origRes.setStatusCode(proxiedRes.statusCode());
        origRes.headers().setAll(proxiedRes.headers());
        proxiedRes.handler(origRes::write);
        proxiedRes.endHandler(v -> origRes.end());
    };

    final HttpClientRequest proxiedReq;
    proxiedReq = httpClient.request(origReq.method(), port, host, origReq.uri(), proxiedResHandler);
    proxiedReq.setChunked(true);
    proxiedReq.headers().add(X_FORWARDED_PROTO, getHeader(origReq, X_FORWARDED_PROTO, origReq.scheme()));
    proxiedReq.headers().add(X_FORWARDED_FOR, getHeader(origReq, X_FORWARDED_FOR, origReq.remoteAddress().host()));
    proxiedReq.headers().addAll(origReq.headers());
    injectRutHeader(proxiedReq, userId);
    origReq.handler(proxiedReq::write);
    origReq.endHandler(v -> proxiedReq.end());
}
 
開發者ID:travelaudience,項目名稱:nexus-proxy,代碼行數:29,代碼來源:NexusHttpProxy.java

示例13: getFormattedElementIsEmpty

import io.vertx.core.http.HttpServerRequest; //導入依賴的package包/類
@Test
public void getFormattedElementIsEmpty() {
  AccessLogParam param = new AccessLogParam();
  RoutingContext context = Mockito.mock(RoutingContext.class);
  HttpServerRequest request = Mockito.mock(HttpServerRequest.class);
  SocketAddress localAddress = Mockito.mock(SocketAddress.class);
  String localHost = "";

  param.setRoutingContext(context);
  Mockito.when(context.request()).thenReturn(request);
  Mockito.when(request.localAddress()).thenReturn(localAddress);
  Mockito.when(localAddress.host()).thenReturn(localHost);

  String result = ELEMENT.getFormattedElement(param);

  assertEquals("-", result);
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:18,代碼來源:LocalHostElementTest.java

示例14: getFormattedElementOnHostIsEmpty

import io.vertx.core.http.HttpServerRequest; //導入依賴的package包/類
@Test
public void getFormattedElementOnHostIsEmpty() {
  AccessLogParam param = new AccessLogParam();
  RoutingContext context = Mockito.mock(RoutingContext.class);
  HttpServerRequest request = Mockito.mock(HttpServerRequest.class);
  SocketAddress address = Mockito.mock(SocketAddress.class);
  String remoteHost = "";

  param.setRoutingContext(context);
  Mockito.when(context.request()).thenReturn(request);
  Mockito.when(request.remoteAddress()).thenReturn(address);
  Mockito.when(address.host()).thenReturn(remoteHost);

  String result = ELEMENT.getFormattedElement(param);

  assertEquals("-", result);
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:18,代碼來源:RemoteHostElementTest.java

示例15: testLog

import io.vertx.core.http.HttpServerRequest; //導入依賴的package包/類
@Test
public void testLog() {
  RoutingContext context = Mockito.mock(RoutingContext.class);
  HttpServerRequest request = Mockito.mock(HttpServerRequest.class);
  long startMillisecond = 1416863450581L;
  AccessLogParam accessLogParam = new AccessLogParam().setStartMillisecond(startMillisecond)
      .setRoutingContext(context);
  SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DatetimeConfigurableElement.DEFAULT_DATETIME_PATTERN,
      DatetimeConfigurableElement.DEFAULT_LOCALE);
  simpleDateFormat.setTimeZone(TimeZone.getDefault());

  Mockito.when(context.request()).thenReturn(request);
  Mockito.when(request.method()).thenReturn(HttpMethod.DELETE);

  Deencapsulation.invoke(ACCESS_LOG_HANDLER, "log", accessLogParam);

  Mockito.verify(logger).info("DELETE" + " - " + simpleDateFormat.format(startMillisecond));
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:19,代碼來源:AccessLogHandlerTest.java


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