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


Java HttpResponse.setHeader方法代碼示例

本文整理匯總了Java中org.jboss.netty.handler.codec.http.HttpResponse.setHeader方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpResponse.setHeader方法的具體用法?Java HttpResponse.setHeader怎麽用?Java HttpResponse.setHeader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.jboss.netty.handler.codec.http.HttpResponse的用法示例。


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

示例1: handle

import org.jboss.netty.handler.codec.http.HttpResponse; //導入方法依賴的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: setResponseHeaders

import org.jboss.netty.handler.codec.http.HttpResponse; //導入方法依賴的package包/類
protected void setResponseHeaders(HttpResponse response,
    boolean keepAliveParam, long contentLength) {
  if (!connectionKeepAliveEnabled && !keepAliveParam) {
    if (LOG.isDebugEnabled()) {
      LOG.debug("Setting connection close header...");
    }
    response.setHeader(HttpHeaders.CONNECTION, CONNECTION_CLOSE);
  } else {
    response.setHeader(HttpHeaders.CONTENT_LENGTH,
      String.valueOf(contentLength));
    response.setHeader(HttpHeaders.CONNECTION, HttpHeaders.KEEP_ALIVE);
    response.setHeader(HttpHeaders.KEEP_ALIVE, "timeout="
        + connectionKeepAliveTimeOut);
    LOG.info("Content Length in shuffle : " + contentLength);
  }
}
 
開發者ID:aliyun-beta,項目名稱:aliyun-oss-hadoop-fs,代碼行數:17,代碼來源:ShuffleHandler.java

示例3: writeRequested

import org.jboss.netty.handler.codec.http.HttpResponse; //導入方法依賴的package包/類
@Override
public void writeRequested(final ChannelHandlerContext ctx, final MessageEvent evt)
	throws Exception
{
	final HttpResponse resp = (HttpResponse)evt.getMessage();

	synchronized(this) {
		if (m_challenge != null) {
			try {
				/* Get appropriate response to challenge and
				 * add to the response base-64 encoded. XXX
				 */
				final String sig = Base64.encodePadded(getSignature());

				resp.setHeader(HeaderSignature, sig);
			}
			finally {
				/* Forget last challenge */
				m_challenge = null;
				m_localAddress = null;
			}
		}
	}

	super.writeRequested(ctx, evt);
}
 
開發者ID:SergioChan,項目名稱:Android-Airplay-Server,代碼行數:27,代碼來源:RaopRtspChallengeResponseHandler.java

示例4: encode

import org.jboss.netty.handler.codec.http.HttpResponse; //導入方法依賴的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

示例5: writeResponse

import org.jboss.netty.handler.codec.http.HttpResponse; //導入方法依賴的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

示例6: messageReceived

import org.jboss.netty.handler.codec.http.HttpResponse; //導入方法依賴的package包/類
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
        throws Exception {
    HttpRequest request = (HttpRequest) e.getMessage();
    String uri = request.getUri();
    
    System.out.println("uri:" + uri);
    HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    ChannelBuffer buffer = new DynamicChannelBuffer(2048);
    buffer.writeBytes("hello!! 你好".getBytes("UTF-8"));
    response.setContent(buffer);
    response.setHeader("Content-Type", "text/html; charset=UTF-8");
    response.setHeader("Content-Length", response.getContent().writerIndex());
    Channel ch = e.getChannel();
    // Write the initial line and the header.
    ch.write(response);
    ch.disconnect();
    ch.close();

}
 
開發者ID:laizhihuan,項目名稱:java-test-demo,代碼行數:21,代碼來源:HttpServerHandler.java

示例7: setResponseHeaders

import org.jboss.netty.handler.codec.http.HttpResponse; //導入方法依賴的package包/類
protected void setResponseHeaders(HttpResponse response,
    boolean keepAliveParam, long contentLength) {
  if (!connectionKeepAliveEnabled && !keepAliveParam) {
    LOG.info("Setting connection close header...");
    response.setHeader(HttpHeaders.CONNECTION, CONNECTION_CLOSE);
  } else {
    response.setHeader(HttpHeaders.CONTENT_LENGTH,
      String.valueOf(contentLength));
    response.setHeader(HttpHeaders.CONNECTION, HttpHeaders.KEEP_ALIVE);
    response.setHeader(HttpHeaders.KEEP_ALIVE, "timeout="
        + connectionKeepAliveTimeOut);
    LOG.info("Content Length in shuffle : " + contentLength);
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:15,代碼來源:ShuffleHandler.java

示例8: sendError

import org.jboss.netty.handler.codec.http.HttpResponse; //導入方法依賴的package包/類
protected void sendError(ChannelHandlerContext ctx, String message,
    HttpResponseStatus status) {
  HttpResponse response = new DefaultHttpResponse(HTTP_1_1, status);
  response.setHeader(CONTENT_TYPE, "text/plain; charset=UTF-8");
  // Put shuffle version into http header
  response.setHeader(ShuffleHeader.HTTP_HEADER_NAME,
      ShuffleHeader.DEFAULT_HTTP_HEADER_NAME);
  response.setHeader(ShuffleHeader.HTTP_HEADER_VERSION,
      ShuffleHeader.DEFAULT_HTTP_HEADER_VERSION);
  response.setContent(
    ChannelBuffers.copiedBuffer(message, CharsetUtil.UTF_8));

  // Close the connection as soon as the error message is sent.
  ctx.getChannel().write(response).addListener(ChannelFutureListener.CLOSE);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:16,代碼來源:ShuffleHandler.java

示例9: writeResponse

import org.jboss.netty.handler.codec.http.HttpResponse; //導入方法依賴的package包/類
private void writeResponse(MessageEvent e) 
{
    // Build the response object.
    HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
    
    response.setContent(ChannelBuffers.copiedBuffer(buf.toString(), CharsetUtil.UTF_8));
    response.setHeader(CONTENT_TYPE, "text/plain; charset=UTF-8");

    // Write the response.
    ChannelFuture future = e.getChannel().write(response);

    // Close the non-keep-alive connection after the write operation is done.
    future.addListener(ChannelFutureListener.CLOSE);
}
 
開發者ID:ZalemSoftware,項目名稱:OpenMobster,代碼行數:15,代碼來源:HttpServerHandler.java

示例10: sendError

import org.jboss.netty.handler.codec.http.HttpResponse; //導入方法依賴的package包/類
private void sendError(ChannelHandlerContext ctx, String message,
    HttpResponseStatus status) {
  HttpResponse response = new DefaultHttpResponse(HTTP_1_1, status);
  response.setHeader(CONTENT_TYPE, "text/plain; charset=UTF-8");
  response.setContent(
      ChannelBuffers.copiedBuffer(message, CharsetUtil.UTF_8));

  // Close the connection as soon as the error message is sent.
  ctx.getChannel().write(response).addListener(ChannelFutureListener.CLOSE);
}
 
開發者ID:rhli,項目名稱:hadoop-EAR,代碼行數:11,代碼來源:ShuffleHandler.java

示例11: createJsonResponse

import org.jboss.netty.handler.codec.http.HttpResponse; //導入方法依賴的package包/類
private HttpResponse createJsonResponse(String content) {
    HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    ChannelBuffer buffer = ChannelBuffers.copiedBuffer(content, UTF_8);
    response.setContent(buffer);
    response.setHeader(HttpHeaders.Names.CONTENT_TYPE, "application/json; charset=UTF-8");
    response.setHeader(HttpHeaders.Names.CONTENT_LENGTH, buffer.readableBytes());
    return response;
}
 
開發者ID:eternalthinker,項目名稱:finagle-java-example-master-slave,代碼行數:9,代碼來源:GeneratorMaster.java

示例12: main

import org.jboss.netty.handler.codec.http.HttpResponse; //導入方法依賴的package包/類
public static void main(String[] args) {
    Service<HttpRequest, HttpResponse> service = new Service<HttpRequest, HttpResponse>() {
        @Override
        public Future<HttpResponse> apply(HttpRequest request) {
            String reqContent = request.getContent().toString(CharsetUtil.UTF_8);
            System.out.println("[Helper] Request received: " + reqContent);
            
            // Parsing JSON request
            JSONObject jreq;
            try {
                jreq = (JSONObject) jsonParser.parse(reqContent);
                System.out.println("[Main] Param received - pname:" + jreq.get("pname"));
            } catch (ParseException e) {
                e.printStackTrace();
            }
            
            HttpResponse res = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
            res.setContent(ChannelBuffers.copiedBuffer("{\"v_id\":100, \"price\":0.2}", CharsetUtil.UTF_8));
            res.setHeader(HttpHeaders.Names.CONTENT_TYPE, "text/plain; charset=UTF-8");
            return Future.<HttpResponse> value(res);
        }
    };
    
    ServerBuilder.safeBuild(service,
            ServerBuilder.get().codec(Http.get()).name("HttpServer")
            .bindTo(new InetSocketAddress("localhost", 9004)));
}
 
開發者ID:eternalthinker,項目名稱:finagle-6.x-java-example,代碼行數:28,代碼來源:HelperServer.java

示例13: apply

import org.jboss.netty.handler.codec.http.HttpResponse; //導入方法依賴的package包/類
public Future<HttpResponse> apply(HttpResponse res) {
    String resContent = res.getContent().toString(CharsetUtil.UTF_8);
    System.out.println("[Main] Received helper response: " + resContent);
    
    System.out.println("[Main] Sending response to main client");
    HttpResponse finalRes = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    finalRes.setContent(ChannelBuffers.copiedBuffer("{\"bid\":" + resContent + "}", CharsetUtil.UTF_8));
    finalRes.setHeader(HttpHeaders.Names.CONTENT_TYPE, "application/json; charset=UTF-8");
    return Future.<HttpResponse> value(finalRes);
}
 
開發者ID:eternalthinker,項目名稱:finagle-6.x-java-example,代碼行數:11,代碼來源:MainServer.java

示例14: sendError

import org.jboss.netty.handler.codec.http.HttpResponse; //導入方法依賴的package包/類
private void sendError(ChannelHandlerContext ctx, HttpResponseStatus status) {
  HttpResponse response = new DefaultHttpResponse(HTTP_1_1, status);
  response.setHeader(CONTENT_TYPE, "text/plain; charset=UTF-8");
  response.setContent(ChannelBuffers.copiedBuffer(
      "Failure: " + status.toString() + "\r\n", CharsetUtil.UTF_8));

  // Close the connection as soon as the error message is sent.
  ctx.getChannel().write(response).addListener(ChannelFutureListener.CLOSE);
}
 
開發者ID:apache,項目名稱:incubator-tajo,代碼行數:10,代碼來源:HttpDataServerHandler.java

示例15: sendError

import org.jboss.netty.handler.codec.http.HttpResponse; //導入方法依賴的package包/類
private void sendError( ChannelHandlerContext ctx, HttpResponseStatus status )
{
    HttpResponse response = new DefaultHttpResponse( HTTP_1_1, status ) ;
    response.setHeader( CONTENT_TYPE, "tex/plain; charset=UTF-8" ) ;
    response.setContent( ChannelBuffers.copiedBuffer( "Failure: " + status.toString( ) + "\r\n", CharsetUtil.UTF_8 ) ) ;
    
    // Fecha a conex�o assim que a mensagem � enviada
    ctx.getChannel( ).write( response ).addListener( ChannelFutureListener.CLOSE ) ;
}
 
開發者ID:wsyssantos,項目名稱:BettaServer,代碼行數:10,代碼來源:BettaUdpFileServerHandler.java


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