当前位置: 首页>>代码示例>>Java>>正文


Java HttpObject类代码示例

本文整理汇总了Java中io.netty.handler.codec.http.HttpObject的典型用法代码示例。如果您正苦于以下问题:Java HttpObject类的具体用法?Java HttpObject怎么用?Java HttpObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


HttpObject类属于io.netty.handler.codec.http包,在下文中一共展示了HttpObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeResponse

import io.netty.handler.codec.http.HttpObject; //导入依赖的package包/类
private boolean writeResponse(HttpObject currentObj, ChannelHandlerContext ctx) {
    // Decide whether to close the connection or not.
    boolean keepAlive = HttpHeaders.isKeepAlive(request);

    // Build the response object.
    FullHttpResponse response = new DefaultFullHttpResponse(
        HTTP_1_1, currentObj.getDecoderResult().isSuccess() ? OK : BAD_REQUEST,
        Unpooled.copiedBuffer(buf.toString(), CharsetUtil.UTF_8));

    response.headers().set(CONTENT_TYPE, "application/json");

    if (keepAlive) {
        // Add 'Content-Length' header only for a keep-alive connection.
        response.headers().set(CONTENT_LENGTH, response.content().readableBytes());
        // Add keep alive header as per:
        // - http://www.w3.org/Protocols/HTTP/1.1/draft-ietf-http-v11-spec-01.html#Connection
        response.headers().set(CONNECTION, HttpHeaders.Values.KEEP_ALIVE);
    }

    // Write the response.
    ctx.write(response);

    return keepAlive;
}
 
开发者ID:aerogear,项目名称:push-network-proxies,代码行数:25,代码来源:MockingFCMServerHandler.java

示例2: channelRead

import io.netty.handler.codec.http.HttpObject; //导入依赖的package包/类
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    LOGGER.info("[Client ({})] => [Server ({})] : {}",
                connectionInfo.getClientAddr(), connectionInfo.getServerAddr(),
                msg);

    if (msg instanceof FullHttpRequest) {
        String streamId = ((HttpRequest) msg).headers().get(
                HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text());
        if (streamId == null) {
            throw new IllegalStateException("No streamId");
        }
        streams.offer(streamId);
    } else if (msg instanceof HttpObject) {
        throw new IllegalStateException("Cannot handle message: " + msg.getClass());
    }

    outboundChannel.writeAndFlush(msg);
}
 
开发者ID:chhsiao90,项目名称:nitmproxy,代码行数:20,代码来源:Http2FrontendHandler.java

示例3: debugRequestInfo

import io.netty.handler.codec.http.HttpObject; //导入依赖的package包/类
private void debugRequestInfo(HttpObject httpObject, String key) {
	if (m_debugInfo && httpObject instanceof HttpRequest) {
		if (key != null) {
			LOGGER.debug("Cache Key: " + key);
		}
		if (httpObject instanceof FullHttpRequest) {
			FullHttpRequest req = (FullHttpRequest) httpObject;
			HttpHeaders headers = req.headers();
			LOGGER.debug("Headers:");
			for (Iterator<Entry<String, String>> it = headers.iterator(); it
					.hasNext();) {
				Entry<String, String> entry = it.next();
				LOGGER.debug("\t" + entry.getKey() + ":\t"
						+ entry.getValue());
			}
			ByteBuf content = req.content();
			int length = content.readableBytes();
			LOGGER.debug("Content Length: " + length);
			if (length != 0) {
				LOGGER.debug("Content: "
						+ content.toString(Charset.forName("UTF-8")));
			}
		}
	}
}
 
开发者ID:eBay,项目名称:ServiceCOLDCache,代码行数:26,代码来源:NettyRequestProxyFilter.java

示例4: channelRead0

import io.netty.handler.codec.http.HttpObject; //导入依赖的package包/类
@Override
public void channelRead0(ChannelHandlerContext ctx, HttpObject msg)
		throws Exception {
	if (msg instanceof HttpResponse) {
		HttpResponse response = (HttpResponse) msg;

		LOGGER.info("Response status: " + response.getStatus());
		if (response.getStatus().equals(OK)) {
			LOGGER.info("Operation is successful");
		} else {
			LOGGER.error("Operation is failed");
		}
	}

	if (msg instanceof HttpContent) {
		HttpContent content = (HttpContent) msg;

		System.out.print(content.content().toString(CharsetUtil.UTF_8));
		System.out.flush();

	}

}
 
开发者ID:eBay,项目名称:ServiceCOLDCache,代码行数:24,代码来源:HttpSnoopClientHandler.java

示例5: mock

import io.netty.handler.codec.http.HttpObject; //导入依赖的package包/类
@Test
public void doChannelRead_checks_for_fully_send_responses_but_does_nothing_else_if_msg_is_not_HttpRequest_or_HttpContent() {
    // given
    HttpObject msgMock = mock(HttpObject.class);

    // when
    PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, msgMock);

    // then
    verify(ctxMock).channel();
    verifyNoMoreInteractions(ctxMock);
    verify(stateMock).isResponseSendingLastChunkSent();
    verifyNoMoreInteractions(stateMock);
    verifyNoMoreInteractions(msgMock);
    assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:17,代码来源:RequestInfoSetterHandlerTest.java

示例6: doChannelRead_does_nothing_if_msg_is_not_HttpRequest

import io.netty.handler.codec.http.HttpObject; //导入依赖的package包/类
@Test
public void doChannelRead_does_nothing_if_msg_is_not_HttpRequest() {
    // given
    String pathTemplate = "/some/path/with/{id}";
    Collection<String> pathTemplates = new ArrayList<String>() {{ add(pathTemplate); }};
    doReturn(pathTemplates).when(matcherMock).matchingPathTemplates();
    HttpObject msg = mock(HttpObject.class);

    // when
    PipelineContinuationBehavior result = handlerSpy.doChannelRead(ctxMock, msg);

    // then
    verify(handlerSpy).doChannelRead(ctxMock, msg);
    verifyNoMoreInteractions(handlerSpy);
    verifyNoMoreInteractions(requestInfoMock);
    verifyNoMoreInteractions(stateMock);
    assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:19,代码来源:RoutingHandlerTest.java

示例7: createNettyHttpClientBootstrap

import io.netty.handler.codec.http.HttpObject; //导入依赖的package包/类
public static Bootstrap createNettyHttpClientBootstrap() {
    Bootstrap bootstrap = new Bootstrap();
    bootstrap.group(new NioEventLoopGroup())
             .channel(NioSocketChannel.class)
             .handler(new ChannelInitializer<SocketChannel>() {
                 @Override
                 protected void initChannel(SocketChannel ch) throws Exception {
                     ChannelPipeline p = ch.pipeline();
                     p.addLast(new HttpClientCodec());
                     p.addLast(new HttpObjectAggregator(Integer.MAX_VALUE));
                     p.addLast("clientResponseHandler", new SimpleChannelInboundHandler<HttpObject>() {
                         @Override
                         protected void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception {
                             throw new RuntimeException("Client response handler was not setup before the call");
                         }
                     });
                 }
             });

    return bootstrap;
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:22,代码来源:ComponentTestUtils.java

示例8: setupNettyHttpClientResponseHandler

import io.netty.handler.codec.http.HttpObject; //导入依赖的package包/类
public static CompletableFuture<NettyHttpClientResponse> setupNettyHttpClientResponseHandler(
    Channel ch, Consumer<ChannelPipeline> pipelineAdjuster
) {
    CompletableFuture<NettyHttpClientResponse> responseFromServerFuture = new CompletableFuture<>();
    ch.pipeline().replace("clientResponseHandler", "clientResponseHandler", new SimpleChannelInboundHandler<HttpObject>() {
        @Override
        protected void channelRead0(ChannelHandlerContext ctx, HttpObject msg)
            throws Exception {
            if (msg instanceof FullHttpResponse) {
                // Store the proxyServer response for asserting on later.
                responseFromServerFuture.complete(new NettyHttpClientResponse((FullHttpResponse) msg));
            } else {
                // Should never happen.
                throw new RuntimeException("Received unexpected message type: " + msg.getClass());
            }
        }
    });

    if (pipelineAdjuster != null)
        pipelineAdjuster.accept(ch.pipeline());
    
    return responseFromServerFuture;
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:24,代码来源:ComponentTestUtils.java

示例9: clientToProxyRequest

import io.netty.handler.codec.http.HttpObject; //导入依赖的package包/类
@Override
public HttpResponse clientToProxyRequest(HttpObject httpObject) {
    if (httpObject instanceof HttpRequest) {
        this.httpRequest = (HttpRequest) httpObject;
    }

    if (httpObject instanceof HttpContent) {
        HttpContent httpContent = (HttpContent) httpObject;

        storeRequestContent(httpContent);

        if (httpContent instanceof LastHttpContent) {
            LastHttpContent lastHttpContent = (LastHttpContent) httpContent;
            trailingHeaders = lastHttpContent .trailingHeaders();
        }
    }

    return null;
}
 
开发者ID:misakuo,项目名称:Dream-Catcher,代码行数:20,代码来源:ClientRequestCaptureFilter.java

示例10: clientToProxyRequest

import io.netty.handler.codec.http.HttpObject; //导入依赖的package包/类
@Override
public HttpResponse clientToProxyRequest(HttpObject httpObject) {
    if (httpObject instanceof HttpRequest) {
        HttpRequest httpRequest = (HttpRequest) httpObject;

        if (ProxyUtils.isCONNECT(httpRequest)) {
            Attribute<String> hostname = ctx.attr(AttributeKey.<String>valueOf(HttpsAwareFiltersAdapter.HOST_ATTRIBUTE_NAME));
            String hostAndPort = httpRequest.getUri();

            // CONNECT requests contain the port, even when using the default port. a sensible default is to remove the
            // default port, since in most cases it is not explicitly specified and its presence (in a HAR file, for example)
            // would be unexpected.
            String hostNoDefaultPort = BrowserMobHttpUtil.removeMatchingPort(hostAndPort, 443);
            hostname.set(hostNoDefaultPort);
        }
    }

    return null;
}
 
开发者ID:misakuo,项目名称:Dream-Catcher,代码行数:20,代码来源:HttpsHostCaptureFilter.java

示例11: serverToProxyResponse

import io.netty.handler.codec.http.HttpObject; //导入依赖的package包/类
@Override
public HttpObject serverToProxyResponse(HttpObject httpObject) {
    HttpObject processedHttpObject = httpObject;

    for (HttpFilters filter : filters) {
        try {
            processedHttpObject = filter.serverToProxyResponse(processedHttpObject);
            if (processedHttpObject == null) {
                return null;
            }
        } catch (RuntimeException e) {
            log.warn("Filter in filter chain threw exception. Filter method may have been aborted.", e);
        }
    }

    return processedHttpObject;
}
 
开发者ID:misakuo,项目名称:Dream-Catcher,代码行数:18,代码来源:BrowserMobHttpFilterChain.java

示例12: proxyToClientResponse

import io.netty.handler.codec.http.HttpObject; //导入依赖的package包/类
@Override
public HttpObject proxyToClientResponse(HttpObject httpObject) {
    HttpObject processedHttpObject = httpObject;
    for (HttpFilters filter : filters) {
        try {
            processedHttpObject = filter.proxyToClientResponse(processedHttpObject);
            if (processedHttpObject == null) {
                return null;
            }
        } catch (RuntimeException e) {
            log.warn("Filter in filter chain threw exception. Filter method may have been aborted.", e);
        }
    }

    return processedHttpObject;
}
 
开发者ID:misakuo,项目名称:Dream-Catcher,代码行数:17,代码来源:BrowserMobHttpFilterChain.java

示例13: clientToProxyRequest

import io.netty.handler.codec.http.HttpObject; //导入依赖的package包/类
@Override
public HttpResponse clientToProxyRequest(HttpObject httpObject) {
    if (httpObject instanceof HttpRequest) {
        HttpRequest httpRequest = (HttpRequest) httpObject;

        String url = getFullUrl(httpRequest);

        for (BlacklistEntry entry : blacklistedUrls) {
            if (HttpMethod.CONNECT.equals(httpRequest.getMethod()) && entry.getHttpMethodPattern() == null) {
                // do not allow CONNECTs to be blacklisted unless a method pattern is explicitly specified
                continue;
            }

            if (entry.matches(url, httpRequest.getMethod().name())) {
                HttpResponseStatus status = HttpResponseStatus.valueOf(entry.getStatusCode());
                HttpResponse resp = new DefaultFullHttpResponse(httpRequest.getProtocolVersion(), status);
                HttpHeaders.setContentLength(resp, 0L);

                return resp;
            }
        }
    }

    return null;
}
 
开发者ID:misakuo,项目名称:Dream-Catcher,代码行数:26,代码来源:BlacklistFilter.java

示例14: clientToProxyRequest

import io.netty.handler.codec.http.HttpObject; //导入依赖的package包/类
@Override
public HttpResponse clientToProxyRequest(HttpObject httpObject) {
    if (credentialsByHostname.isEmpty()) {
        return null;
    }

    if (httpObject instanceof HttpRequest) {
        HttpRequest httpRequest = (HttpRequest) httpObject;

        // providing authorization during a CONNECT is generally not useful
        if (ProxyUtils.isCONNECT(httpRequest)) {
            return null;
        }

        String hostname = getHost(httpRequest);

        // if there is an entry in the credentials map matching this hostname, add the credentials to the request
        String base64CredentialsForHostname = credentialsByHostname.get(hostname);
        if (base64CredentialsForHostname != null) {
            httpRequest.headers().add(HttpHeaders.Names.AUTHORIZATION, "Basic " + base64CredentialsForHostname);
        }
    }

    return null;
}
 
开发者ID:misakuo,项目名称:Dream-Catcher,代码行数:26,代码来源:AutoBasicAuthFilter.java

示例15: channelRead0

import io.netty.handler.codec.http.HttpObject; //导入依赖的package包/类
@Override
protected void channelRead0(ChannelHandlerContext channelHandlerContext, HttpObject httpObject)
    throws Exception {
  // initial request
  if (LOG.isDebugEnabled()) {
    LOG.debug(String.format("%s: Reading from client %s", System.currentTimeMillis(), httpObject));
  }
  if (httpObject instanceof HttpRequest) {
    HttpRequest initialRequest = (HttpRequest) httpObject;
    if (_channelHandlerDelegate == null) {
      _channelHandlerDelegate =
          HandlerDelegateFactory.create(initialRequest, _channelMediator, _connectionFlowRegistry);
      _channelHandlerDelegate.onCreate();
    }
  }
  _channelHandlerDelegate.onRead(httpObject);
}
 
开发者ID:linkedin,项目名称:flashback,代码行数:18,代码来源:ClientChannelHandler.java


注:本文中的io.netty.handler.codec.http.HttpObject类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。