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


Java HttpRequest類代碼示例

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


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

示例1: ifNoPageLoadingActions_OptionalEmptyIsReturned

import io.netty.handler.codec.http.HttpRequest; //導入依賴的package包/類
@Test
public void ifNoPageLoadingActions_OptionalEmptyIsReturned() throws MalformedURLException, UnsupportedEncodingException {
    ActionsFilter actionsFilter = createMocks(false);
    when(actionsFilter.filter(PAGE_LOADING)).thenReturn(new ArrayList<>());

    HttpRequest httpRequest = mock(HttpRequest.class);
    when(httpRequest.getUri()).thenReturn(EXPECTED_URL);
    
    RequestToPageLoadingEventConverter requestToPageLoadingEventConverter =
            new RequestToPageLoadingEventConverter(BASE_URL, actionsFilter);

    Optional<Map<String, String>> expected = Optional.empty();
    Optional<Map<String, String>> actual = requestToPageLoadingEventConverter.convert(httpRequest);

    assertEquals(expected, actual);
}
 
開發者ID:hristo-vrigazov,項目名稱:bromium,代碼行數:17,代碼來源:RequestToPageLoadingEventConverterTest.java

示例2: onRequestReceived

import io.netty.handler.codec.http.HttpRequest; //導入依賴的package包/類
@Override
public void onRequestReceived(ChannelHandlerContext ctx, HttpRequest request) {

    HttpSessionThreadLocal.unset();

    Collection<Cookie> cookies = Utils.getCookies(HttpSessionImpl.SESSION_ID_KEY, request);
    if (cookies != null) {
        for (Cookie cookie : cookies) {
            String jsessionId = cookie.value();
            HttpSession s = HttpSessionThreadLocal.getSessionStore().findSession(jsessionId);
            if (s != null) {
                HttpSessionThreadLocal.set(s);
                this.sessionRequestedByCookie = true;
                break;
            }
        }
    }
}
 
開發者ID:geeker-lait,項目名稱:tasfe-framework,代碼行數:19,代碼來源:HttpSessionInterceptor.java

示例3: channelRead

import io.netty.handler.codec.http.HttpRequest; //導入依賴的package包/類
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    if(msg instanceof HttpRequest){
        HttpRequest request = (HttpRequest) msg;
        if(!request.uri().equals(CommonConstants.FAVICON_ICO)){
            // 將request和context存儲到ThreadLocal中去,便於後期在其他地方獲取並使用
            DataHolder.store(DataHolder.HolderType.REQUEST,request);
            DataHolder.store(DataHolder.HolderType.CONTEXT,ctx);
        }
    }
    /**
     * 提交給下一個ChannelHandler去處理
     * 並且不需要調用ReferenceCountUtil.release(msg);來釋放引用計數
     */
    ctx.fireChannelRead(msg);
}
 
開發者ID:all4you,項目名稱:redant,代碼行數:17,代碼來源:DataStorer.java

示例4: get

import io.netty.handler.codec.http.HttpRequest; //導入依賴的package包/類
@Override
public FullHttpResponse get(ChannelHandlerContext channelHandlerContext, QueryDecoder queryDecoder, PathProvider path, HttpRequest httpRequest) throws Exception
{
    CloudNet.getLogger().debug("HTTP Request from " + channelHandlerContext.channel().remoteAddress());

    StringBuilder stringBuilder = new StringBuilder();

    try (InputStream inputStream = WebsiteDocumentation.class.getClassLoader().getResourceAsStream("files/api-doc.txt");
         BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8)))
    {
        String input;
        while ((input = bufferedReader.readLine()) != null)
        {
            stringBuilder.append(input).append(System.lineSeparator());
        }
    }

    String output = stringBuilder.substring(0);
    ByteBuf byteBuf = Unpooled.wrappedBuffer(output.getBytes(StandardCharsets.UTF_8));
    FullHttpResponse fullHttpResponse = new DefaultFullHttpResponse(httpRequest.getProtocolVersion(), HttpResponseStatus.OK, byteBuf);
    fullHttpResponse.headers().set("Content-Type", "text/plain");
    return fullHttpResponse;
}
 
開發者ID:Dytanic,項目名稱:CloudNet,代碼行數:24,代碼來源:WebsiteDocumentation.java

示例5: ifEventWithSuppliedValueMatchesTheUriThenEventIsReturned

import io.netty.handler.codec.http.HttpRequest; //導入依賴的package包/類
@Test
public void ifEventWithSuppliedValueMatchesTheUriThenEventIsReturned() throws MalformedURLException, UnsupportedEncodingException {
    ActionsFilter actionsFilter = createMocks(false);

    HttpRequest httpRequest = mock(HttpRequest.class);
    when(httpRequest.getUri()).thenReturn(EXPECTED_URL);

    RequestToPageLoadingEventConverter requestToPageLoadingEventConverter =
            new RequestToPageLoadingEventConverter(BASE_URL, actionsFilter);

    Map<String, String> expected = ImmutableMap.of(EVENT, EXAMPLE_EVENT_NAME);
    Optional<Map<String, String>> actual = requestToPageLoadingEventConverter.convert(httpRequest);

    assertTrue(actual.isPresent());
    assertEquals(expected, actual.get());
}
 
開發者ID:hristo-vrigazov,項目名稱:bromium,代碼行數:17,代碼來源:RequestToPageLoadingEventConverterTest.java

示例6: handle

import io.netty.handler.codec.http.HttpRequest; //導入依賴的package包/類
public void handle(ChannelHandlerContext ctx, HttpRequest req)
  throws IOException, URISyntaxException {
  String op = params.op();
  HttpMethod method = req.getMethod();
  if (PutOpParam.Op.CREATE.name().equalsIgnoreCase(op)
    && method == PUT) {
    onCreate(ctx);
  } else if (PostOpParam.Op.APPEND.name().equalsIgnoreCase(op)
    && method == POST) {
    onAppend(ctx);
  } else if (GetOpParam.Op.OPEN.name().equalsIgnoreCase(op)
    && method == GET) {
    onOpen(ctx);
  } else if(GetOpParam.Op.GETFILECHECKSUM.name().equalsIgnoreCase(op)
    && method == GET) {
    onGetFileChecksum(ctx);
  } else {
    throw new IllegalArgumentException("Invalid operation " + op);
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:21,代碼來源:WebHdfsHandler.java

示例7: filterRequest

import io.netty.handler.codec.http.HttpRequest; //導入依賴的package包/類
@Override
public HttpResponse filterRequest(HttpRequest httpRequest, HttpMessageContents httpMessageContents, HttpMessageInfo httpMessageInfo) {
    for (EventDetector eventDetector: eventDetectors) {
        if (eventDetector.canDetectPredicate().test(httpRequest)) {
            try {
                Optional<Map<String, String>> optionalEvent = eventDetector.getConverter().convert(httpRequest);

                if (optionalEvent.isPresent()) {
                    Map<String, String> event = optionalEvent.get();
                    recordingState.storeTestCaseStep(event);
                    logger.info("Recorded event {}", event);
                }

            } catch (UnsupportedEncodingException | MalformedURLException e) {
                logger.error("Error while trying to convert test case step", e);
            }
        }
    }

    return null;
}
 
開發者ID:hristo-vrigazov,項目名稱:bromium,代碼行數:22,代碼來源:RecordRequestFilter.java

示例8: channelRead0

import io.netty.handler.codec.http.HttpRequest; //導入依賴的package包/類
@Override
public void channelRead0(final ChannelHandlerContext ctx,
                         final HttpRequest req) throws Exception {
  Preconditions.checkArgument(req.getUri().startsWith(WEBHDFS_PREFIX));
  QueryStringDecoder queryString = new QueryStringDecoder(req.getUri());
  params = new ParameterParser(queryString, conf);
  DataNodeUGIProvider ugiProvider = new DataNodeUGIProvider(params);
  ugi = ugiProvider.ugi();
  path = params.path();

  injectToken();
  ugi.doAs(new PrivilegedExceptionAction<Void>() {
    @Override
    public Void run() throws Exception {
      handle(ctx, req);
      return null;
    }
  });
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:20,代碼來源:WebHdfsHandler.java

示例9: getResponseFilter

import io.netty.handler.codec.http.HttpRequest; //導入依賴的package包/類
@CheckedProvides(IOProvider.class)
public ResponseFilter getResponseFilter(@Named(COMMAND) String command,
                                        ReplayingState replayingState,
                                        @Named(SHOULD_INJECT_JS_PREDICATE) Predicate<HttpRequest> httpRequestPredicate,
                                        @Named(RECORDING_JAVASCRIPT_CODE) IOProvider<String>
                                                    recordingJavascriptCodeProvider,
                                        @Named(REPLAYING_JAVASCRIPT_CODE) IOProvider<String>
                                                    replayingJavascriptCodeProvider) throws IOException {
    switch (command) {
        case RECORD:
            return new RecordResponseFilter(recordingJavascriptCodeProvider.get(), httpRequestPredicate);
        case REPLAY:
            return new ReplayResponseFilter(replayingJavascriptCodeProvider.get(), replayingState, httpRequestPredicate);
        default:
            throw new NoSuchCommandException();
    }
}
 
開發者ID:hristo-vrigazov,項目名稱:bromium,代碼行數:18,代碼來源:DefaultModule.java

示例10: doesNotAddToStateIfConverterReturnsEmpty

import io.netty.handler.codec.http.HttpRequest; //導入依賴的package包/類
@Test
public void doesNotAddToStateIfConverterReturnsEmpty() throws MalformedURLException, UnsupportedEncodingException {
    HttpRequest httpRequest = mock(HttpRequest.class);
    Map<String, String> event = getEvent();
    when(httpRequest.getUri()).thenReturn(SUBMIT_EVENT_URL + "?event=mockEvent&text=mockText");
    Predicate<HttpRequest> httpRequestPredicate = mock(Predicate.class);
    when(httpRequestPredicate.test(httpRequest)).thenReturn(true);
    RecordingState recordingState = mock(RecordingState.class);
    HttpRequestToTestCaseStepConverter httpRequestToTestCaseStepConverter = mock(HttpRequestToTestCaseStepConverter.class);
    when(httpRequestToTestCaseStepConverter.convert(httpRequest)).thenReturn(Optional.empty());
    EventDetector eventDetector = mock(EventDetector.class);
    when(eventDetector.canDetectPredicate()).thenReturn(httpRequestPredicate);
    when(eventDetector.getConverter()).thenReturn(httpRequestToTestCaseStepConverter);
    List<EventDetector> eventDetectors = Arrays.asList(eventDetector);
    RecordRequestFilter requestFilter = new RecordRequestFilter(recordingState, eventDetectors);
    requestFilter.filterRequest(httpRequest, mock(HttpMessageContents.class), mock(HttpMessageInfo.class));

    verify(recordingState, never()).storeTestCaseStep(event);
}
 
開發者ID:hristo-vrigazov,項目名稱:bromium,代碼行數:20,代碼來源:RecordRequestFilterTest.java

示例11: doesNotAddToQueueIfEncodingIsUnsupporte

import io.netty.handler.codec.http.HttpRequest; //導入依賴的package包/類
@Test
public void doesNotAddToQueueIfEncodingIsUnsupporte() throws MalformedURLException, UnsupportedEncodingException {
    HttpRequest httpRequest = mock(HttpRequest.class);
    when(httpRequest.getUri()).thenReturn("blabla" + SUBMIT_EVENT_URL);
    RecordingState recordingState = mock(RecordingState.class);
    Predicate<HttpRequest> httpRequestPredicate = mock(Predicate.class);
    when(httpRequestPredicate.test(httpRequest)).thenReturn(true);
    HttpRequestToTestCaseStepConverter httpRequestToTestCaseStepConverter = mock(HttpRequestToTestCaseStepConverter.class);
    when(httpRequestToTestCaseStepConverter.convert(httpRequest)).thenThrow(new UnsupportedEncodingException());
    EventDetector eventDetector = mock(EventDetector.class);
    when(eventDetector.canDetectPredicate()).thenReturn(httpRequestPredicate);
    when(eventDetector.getConverter()).thenReturn(httpRequestToTestCaseStepConverter);
    List<EventDetector> eventDetectors = Arrays.asList(eventDetector);
    RecordRequestFilter requestFilter = new RecordRequestFilter(recordingState, eventDetectors);
    requestFilter.filterRequest(httpRequest, mock(HttpMessageContents.class), mock(HttpMessageInfo.class));
    verify(recordingState, never()).storeTestCaseStep(anyMap());
}
 
開發者ID:hristo-vrigazov,項目名稱:bromium,代碼行數:18,代碼來源:RecordRequestFilterTest.java

示例12: setCorsResponseHeaders

import io.netty.handler.codec.http.HttpRequest; //導入依賴的package包/類
public static void setCorsResponseHeaders(HttpRequest request, HttpResponse resp, Netty4CorsConfig config) {
    if (!config.isCorsSupportEnabled()) {
        return;
    }
    String originHeader = request.headers().get(HttpHeaderNames.ORIGIN);
    if (!Strings.isNullOrEmpty(originHeader)) {
        final String originHeaderVal;
        if (config.isAnyOriginSupported()) {
            originHeaderVal = ANY_ORIGIN;
        } else if (config.isOriginAllowed(originHeader) || isSameOrigin(originHeader, request.headers().get(HttpHeaderNames.HOST))) {
            originHeaderVal = originHeader;
        } else {
            originHeaderVal = null;
        }
        if (originHeaderVal != null) {
            resp.headers().add(HttpHeaderNames.ACCESS_CONTROL_ALLOW_ORIGIN, originHeaderVal);
        }
    }
    if (config.isCredentialsAllowed()) {
        resp.headers().add(HttpHeaderNames.ACCESS_CONTROL_ALLOW_CREDENTIALS, "true");
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:23,代碼來源:Netty4CorsHandler.java

示例13: channelRead

import io.netty.handler.codec.http.HttpRequest; //導入依賴的package包/類
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
    if (msg instanceof HttpRequest) {
        HttpRequest req = (HttpRequest) msg;

        boolean keepAlive = HttpUtil.isKeepAlive(req);
        FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK, Unpooled.wrappedBuffer(CONTENT));
        response.headers().set(CONTENT_TYPE, "text/plain");
        response.headers().setInt(CONTENT_LENGTH, response.content().readableBytes());

        if (!keepAlive) {
            ctx.write(response).addListener(ChannelFutureListener.CLOSE);
        } else {
            response.headers().set(CONNECTION, KEEP_ALIVE);
            ctx.write(response);
        }
    }
}
 
開發者ID:avirtuos,項目名稱:teslog,代碼行數:19,代碼來源:HttpHelloWorldServerHandler.java

示例14: sendHttpResponse

import io.netty.handler.codec.http.HttpRequest; //導入依賴的package包/類
private static void sendHttpResponse(ChannelHandlerContext ctx,
		HttpRequest req, FullHttpResponse res) {
	// Generate an error page if response getStatus code is not OK (200).
	if (res.getStatus().code() != 200) {
		ByteBuf buf = Unpooled.copiedBuffer(res.getStatus().toString(),
				CharsetUtil.UTF_8);
		res.content().writeBytes(buf);
		buf.release();
		setContentLength(res, res.content().readableBytes());
	}

	// Send the response and close the connection if necessary.
	ChannelFuture f = ctx.writeAndFlush(res);
	if (!isKeepAlive(req) || res.getStatus().code() != 200) {
		f.addListener(ChannelFutureListener.CLOSE);
	}
}
 
開發者ID:osswangxining,項目名稱:mqttserver,代碼行數:18,代碼來源:HttpRequestHandler.java

示例15: doesNotAddRequestIfNotRequired

import io.netty.handler.codec.http.HttpRequest; //導入依賴的package包/類
@Test
public void doesNotAddRequestIfNotRequired() {
    HttpRequest httpRequest = mock(HttpRequest.class);
    when(httpRequest.getUri()).thenReturn("http://something/" + "?event=mockEvent&text=mockText");
    RecordingState recordingState = mock(RecordingState.class);
    Predicate<HttpRequest> httpRequestPredicate = mock(Predicate.class);
    when(httpRequestPredicate.test(httpRequest)).thenReturn(false);
    HttpRequestToTestCaseStepConverter httpRequestToTestCaseStepConverter = mock(HttpRequestToTestCaseStepConverter.class);
    EventDetector eventDetector = mock(EventDetector.class);
    when(eventDetector.canDetectPredicate()).thenReturn(httpRequestPredicate);
    when(eventDetector.getConverter()).thenReturn(httpRequestToTestCaseStepConverter);
    List<EventDetector> eventDetectors = Arrays.asList(eventDetector);
    RecordRequestFilter requestFilter = new RecordRequestFilter(recordingState, eventDetectors);
    requestFilter.filterRequest(httpRequest, mock(HttpMessageContents.class), mock(HttpMessageInfo.class));
    verify(recordingState, never()).storeTestCaseStep(anyMap());
}
 
開發者ID:hristo-vrigazov,項目名稱:bromium,代碼行數:17,代碼來源:RecordRequestFilterTest.java


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