本文整理汇总了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));
}