本文整理匯總了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);
}
示例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);
}
}
示例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;
}
示例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;
}
示例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();
}
}
示例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();
}
示例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);
}
示例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();
}
示例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);
}
示例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());
}
示例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);
}
示例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);
}
示例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));
}