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


Java HttpHeaders类代码示例

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


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

示例1: handle

import org.jboss.netty.handler.codec.http.HttpHeaders; //导入依赖的package包/类
@Override
public void handle(Channel channel, Token<DelegationTokenIdentifier> token,
    String serviceUrl) throws IOException {
  Assert.assertEquals(testToken, token);

  Credentials creds = new Credentials();
  creds.addToken(new Text(serviceUrl), token);
  DataOutputBuffer out = new DataOutputBuffer();
  creds.write(out);
  int fileLength = out.getData().length;
  ChannelBuffer cbuffer = ChannelBuffers.buffer(fileLength);
  cbuffer.writeBytes(out.getData());
  HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
  response.setHeader(HttpHeaders.Names.CONTENT_LENGTH,
      String.valueOf(fileLength));
  response.setContent(cbuffer);
  channel.write(response).addListener(ChannelFutureListener.CLOSE);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:19,代码来源:TestDelegationTokenRemoteFetcher.java

示例2: executeString

import org.jboss.netty.handler.codec.http.HttpHeaders; //导入依赖的package包/类
private Promise<Response> executeString(String method, String body) {
    FluentCaseInsensitiveStringsMap headers = new FluentCaseInsensitiveStringsMap(this.headers);

    // Detect and maybe add charset
    String contentType = headers.getFirstValue(HttpHeaders.Names.CONTENT_TYPE);
    if (contentType == null) {
        contentType = "text/plain";
    }
    String charset = AsyncHttpProviderUtils.parseCharset(contentType);
    if (charset == null) {
        charset = "utf-8";
        headers.replace(HttpHeaders.Names.CONTENT_TYPE, contentType + "; charset=utf-8");
    }

    WSRequest req = new WSRequest(method).setBody(body)
            .setUrl(url)
            .setHeaders(headers)
            .setQueryParameters(new FluentStringsMap(queryParameters))
            .setBodyEncoding(charset);
    return execute(req);
}
 
开发者ID:vangav,项目名称:vos_backend,代码行数:22,代码来源:WS.java

示例3: needCache

import org.jboss.netty.handler.codec.http.HttpHeaders; //导入依赖的package包/类
private boolean needCache(Request request, StaticAction staticAction) {
	String ifModifiedSince = request.header(HttpHeaders.Names.IF_MODIFIED_SINCE);

	if (!needCache || StringUtils.isBlank(ifModifiedSince)) {
		return false;
	}

	SimpleDateFormat simpleDateFormat = new SimpleDateFormat(HTTP_DATE_FORMAT, Locale.US);

	try {
		Date ifModifiedSinceDate = simpleDateFormat.parse(ifModifiedSince);
		return ifModifiedSinceDate.getTime() / 1000 == staticAction.timestamp() / 1000;
	} catch (ParseException ignored) {
	}

	return false;
}
 
开发者ID:iceize,项目名称:netty-http-3.x,代码行数:18,代码来源:StaticActionDispatcher.java

示例4: getRequestBody

import org.jboss.netty.handler.codec.http.HttpHeaders; //导入依赖的package包/类
@Override
protected Object getRequestBody(Exchange exchange) throws Exception {
    // creating the url to use takes 2-steps
    String uri = NettyHttpHelper.createURL(exchange, getEndpoint());
    URI u = NettyHttpHelper.createURI(exchange, uri, getEndpoint());

    HttpRequest request = getEndpoint().getNettyHttpBinding().toNettyRequest(exchange.getIn(), u.toString(), getConfiguration());
    String actualUri = request.getUri();
    exchange.getIn().setHeader(Exchange.HTTP_URL, actualUri);
    // Need to check if we need to close the connection or not
    if (!HttpHeaders.isKeepAlive(request)) {
        // just want to make sure we close the channel if the keepAlive is not true
        exchange.setProperty(NettyConstants.NETTY_CLOSE_CHANNEL_WHEN_COMPLETE, true);
    }
    if (getConfiguration().isBridgeEndpoint()) {
        // Need to remove the Host key as it should be not used when bridging/proxying
        exchange.getIn().removeHeader("host");
    }

    return request;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:NettyHttpProducer.java

示例5: createRouteBuilder

import org.jboss.netty.handler.codec.http.HttpHeaders; //导入依赖的package包/类
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("netty-http:http://0.0.0.0:{{port}}/foo")
                .to("mock:input")
                .process(new Processor() {
                    @Override
                    public void process(Exchange exchange) throws Exception {
                        HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
                        response.setContent(ChannelBuffers.copiedBuffer("Bye World".getBytes()));
                        response.headers().set(HttpHeaders.Names.CONTENT_LENGTH, 9);

                        exchange.getOut().setBody(response);
                    }
                });
        }
    };
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:NettyUseRawHttpResponseTest.java

示例6: removeTransferEncodingChunked

import org.jboss.netty.handler.codec.http.HttpHeaders; //导入依赖的package包/类
static void removeTransferEncodingChunked(HttpMessage m) {
	List<String> values = m.headers().getAll(HttpHeaders.Names.TRANSFER_ENCODING);
	if (values.isEmpty()) {
		return;
	}
	Iterator<String> valuesIt = values.iterator();
	while (valuesIt.hasNext()) {
		String value = valuesIt.next();
		if (value.equalsIgnoreCase(HttpHeaders.Values.CHUNKED)) {
			valuesIt.remove();
		}
	}
	if (values.isEmpty()) {
		m.headers().remove(HttpHeaders.Names.TRANSFER_ENCODING);
	} else {
		m.headers().set(HttpHeaders.Names.TRANSFER_ENCODING, values);
	}
}
 
开发者ID:mirasworks,项目名称:works,代码行数:19,代码来源:MessageEncoder.java

示例7: removeTransferEncodingChunked

import org.jboss.netty.handler.codec.http.HttpHeaders; //导入依赖的package包/类
public static void removeTransferEncodingChunked(HttpMessage worksReponse) {
	List<String> values = worksReponse.headers().getAll(HttpHeaders.Names.TRANSFER_ENCODING);
	if (values.isEmpty()) {
		return;
	}
	Iterator<String> valuesIt = values.iterator();
	while (valuesIt.hasNext()) {
		String value = valuesIt.next();
		if (value.equalsIgnoreCase(HttpHeaders.Values.CHUNKED)) {
			valuesIt.remove();
		}
	}
	if (values.isEmpty()) {
		worksReponse.headers().remove(HttpHeaders.Names.TRANSFER_ENCODING);
	} else {
		worksReponse.headers().set(HttpHeaders.Names.TRANSFER_ENCODING, values);
	}
}
 
开发者ID:mirasworks,项目名称:works,代码行数:19,代码来源:Codec.java

示例8: encode

import org.jboss.netty.handler.codec.http.HttpHeaders; //导入依赖的package包/类
@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg)
        throws Exception
{
  RestResponse response = (RestResponse) msg;

  HttpResponse nettyResponse =
      new DefaultHttpResponse(HttpVersion.HTTP_1_1,
                              HttpResponseStatus.valueOf(response.getStatus()));

  for (Map.Entry<String, String> e : response.getHeaders().entrySet())
  {
    nettyResponse.setHeader(e.getKey(), e.getValue());
  }
  final ByteString entity = response.getEntity();
  ChannelBuffer buf = ChannelBuffers.wrappedBuffer(entity.asByteBuffer());
  nettyResponse.setContent(buf);
  nettyResponse.setHeader(HttpHeaders.Names.CONTENT_LENGTH, entity.length());

  return nettyResponse;
}
 
开发者ID:ppdai,项目名称:rest4j,代码行数:22,代码来源:RAPServerCodec.java

示例9: messageReceived

import org.jboss.netty.handler.codec.http.HttpHeaders; //导入依赖的package包/类
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent event) throws Exception {
    if (event.getMessage() instanceof HttpRequest) {
        try {
            HttpServletRequest httpServletRequest = new NettyHttpServletRequestAdaptor((HttpRequest) event.getMessage(), ctx.getChannel());
            HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
            response.setContent(new DynamicChannelBuffer(200));
            HttpServletResponse httpServletResponse = new NettyHttpServletResponseAdaptor(response, ctx.getChannel());
            dispatcher.dispatch(httpServletRequest,httpServletResponse);
            response.headers().set(HttpHeaders.Names.CONTENT_LENGTH,response.getContent().writerIndex());
            ChannelFuture future = ctx.getChannel().write(response);
            future.addListener(ChannelFutureListener.CLOSE);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
开发者ID:code4craft,项目名称:netty-servlet,代码行数:18,代码来源:HttpServerHandler.java

示例10: writeResponse

import org.jboss.netty.handler.codec.http.HttpHeaders; //导入依赖的package包/类
private void writeResponse(MessageEvent e) {
  HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
  response.setHeader(HttpHeaders.Names.CONTENT_TYPE, "application/json; charset=UTF-8");

  ChannelBuffer content = ChannelBuffers.dynamicBuffer();
  Writer writer = new OutputStreamWriter(new ChannelBufferOutputStream(content), CharsetUtil.UTF_8);
  reportAdapter.toJson(report.get(), writer);
  try {
    writer.close();
  } catch (IOException e1) {
    LOG.error("error writing resource report", e1);
  }
  response.setContent(content);
  ChannelFuture future = e.getChannel().write(response);
  future.addListener(ChannelFutureListener.CLOSE);
}
 
开发者ID:chtyim,项目名称:incubator-twill,代码行数:17,代码来源:TrackerService.java

示例11: executeString

import org.jboss.netty.handler.codec.http.HttpHeaders; //导入依赖的package包/类
private CompletableFuture<RestResponse> executeString(String body) {
    FluentCaseInsensitiveStringsMap headers = new FluentCaseInsensitiveStringsMap(this.headers);

    // Detect and maybe add charset
    String contentType = headers.getFirstValue(HttpHeaders.Names.CONTENT_TYPE);
    if (contentType == null) {
        contentType = "text/plain";
    }
    String charset = AsyncHttpProviderUtils.parseCharset(contentType);
    if (charset == null) {
        charset = "utf-8";
        headers.replace(HttpHeaders.Names.CONTENT_TYPE, contentType + "; charset=utf-8");
    }

    byte[] bodyBytes;
    try {
        bodyBytes = body.getBytes(charset);
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
    }

    NingRestRequest req = new NingRestRequest(client, method, url, queryParameters, headers, bodyBytes)
            .setBody(body)
            .setBodyEncoding(charset);
    return execute(req);
}
 
开发者ID:mcoira,项目名称:async-rest-client,代码行数:27,代码来源:NingRestRequestHolder.java

示例12: executeJson

import org.jboss.netty.handler.codec.http.HttpHeaders; //导入依赖的package包/类
private CompletableFuture<RestResponse> executeJson(JsonNode body) {
    FluentCaseInsensitiveStringsMap headers = new FluentCaseInsensitiveStringsMap(this.headers);
    headers.replace(HttpHeaders.Names.CONTENT_TYPE, "application/json; charset=utf-8");
    String bodyStr = Json.stringify(body);
    byte[] bodyBytes;
    try {
        bodyBytes = bodyStr.getBytes("utf-8");
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
    }

    NingRestRequest req = new NingRestRequest(client, method, url, queryParameters, headers, bodyBytes)
            .setBody(bodyStr)
            .setBodyEncoding("utf-8");
    return execute(req);

}
 
开发者ID:mcoira,项目名称:async-rest-client,代码行数:18,代码来源:NingRestRequestHolder.java

示例13: toHttpResponse

import org.jboss.netty.handler.codec.http.HttpHeaders; //导入依赖的package包/类
private HttpResponse toHttpResponse(HttpResponseStatus status, String content, Object jsonObject) {

        // headers
        Map<String, List<String>> headers = new HashMap<String, List<String>>();
        headers.put(HttpHeaders.Names.CONTENT_TYPE, Arrays.asList("application/json"));

        // response
        byte[] response = content.getBytes(Charset.forName("UTF-8"));
        if (jsonObject != null) {
            try {
                response = objectMapper.writeValueAsBytes(jsonObject);
            } catch (Exception e) {
                log.warn(e.getMessage(), e);
            }
        }
        return new HttpResponse(status.getCode(), headers, response);
    }
 
开发者ID:elasticsoftwarefoundation,项目名称:elasterix,代码行数:18,代码来源:ApiHttpMessage.java

示例14: invalidRequestSent

import org.jboss.netty.handler.codec.http.HttpHeaders; //导入依赖的package包/类
public void invalidRequestSent(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
    Channel channel = ctx.getChannel();
    if (channel == null || !channel.isOpen()) {
        log.debug("Not writing any response, channel is already closed.", e.getCause());
        return;
    }

    final DefaultHttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_0, HttpResponseStatus.BAD_REQUEST);
    response.headers().add(HttpHeaders.Names.CONTENT_TYPE, "text/plain");
    response.headers().add(HttpHeaders.Names.CONNECTION, "close");
    final ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
    new ChannelBufferOutputStream(buffer).writeBytes("Your client has sent a malformed or illegal request.\n");
    response.setContent(buffer);

    final ChannelFuture channelFuture = channel.write(response);

    channelFuture.addListener(ChannelFutureListener.CLOSE);
}
 
开发者ID:graylog-labs,项目名称:jersey-netty,代码行数:19,代码来源:NettyContainer.java

示例15: writeRequested

import org.jboss.netty.handler.codec.http.HttpHeaders; //导入依赖的package包/类
@Override
public void writeRequested(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
	final HttpRequest request = (HttpRequest) e.getMessage();

	// If we have a proxy auth header, add it into the request
       final ProxyAuthHandler handler = proxyAuthHandler.get();
       final PasswordAuthentication auth = proxyAuthCredentials.get();
	if (handler != null && auth != null) {
           final String proxyAuthHeader = handler.authenticate(request, auth.getUserName(), new String(auth.getPassword()));
           request.setHeader(HttpHeaders.Names.PROXY_AUTHORIZATION, proxyAuthHeader);
	}

	// request the connection be kept open for pipeling
	request.setHeader(HttpHeaders.Names.CONNECTION, "Keep-Alive");
	// request any proxy doesn't try give us a cached response
	request.setHeader(HttpHeaders.Names.PRAGMA, "No-Cache");

       lastRequest.set(request);
	ctx.sendDownstream(e);
}
 
开发者ID:reines,项目名称:httptunnel,代码行数:21,代码来源:HttpTunnelClientChannelProxyHandler.java


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