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


Java HttpRequest.setHeader方法代碼示例

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


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

示例1: writeRequested

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

示例2: createJsonRequest

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

示例3: createJsonRequest

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

示例4: createJsonRequest

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

示例5: encode

import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg)
        throws Exception
{
  RestRequest request = (RestRequest) msg;

  HttpMethod nettyMethod = HttpMethod.valueOf(request.getMethod());
  URL url = new URL(request.getURI().toString());
  String path = url.getFile();
  // RFC 2616, section 5.1.2:
  //   Note that the absolute path cannot be empty; if none is present in the original URI,
  //   it MUST be given as "/" (the server root).
  if (path.isEmpty())
  {
    path = "/";
  }

  HttpRequest nettyRequest =
      new DefaultHttpRequest(HttpVersion.HTTP_1_1, nettyMethod, path);

  nettyRequest.setHeader(HttpHeaders.Names.HOST, url.getAuthority());
  for (Map.Entry<String, String> e : request.getHeaders().entrySet())
  {
    nettyRequest.setHeader(e.getKey(), e.getValue());
  }

  final ByteString entity = request.getEntity();
  ChannelBuffer buf = ChannelBuffers.wrappedBuffer(entity.asByteBuffer());
  nettyRequest.setContent(buf);
  nettyRequest.setHeader(HttpHeaders.Names.CONTENT_LENGTH, entity.length());

  return nettyRequest;
}
 
開發者ID:ppdai,項目名稱:rest4j,代碼行數:34,代碼來源:RAPClientCodec.java

示例6: messageReceived

import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
    //only set this on request - proceeding chunks will be routed on same outbound connection
    if (e.getMessage() instanceof HttpRequest) {
        HttpRequest request = (HttpRequest) e.getMessage();

        request.setHeader(ROUTE_HEADER, STATIC_ROUTE);
        LOG.debug("setting header {} to {}", ROUTE_HEADER, STATIC_ROUTE);

        request.setHeader("host", new URL(STATIC_ROUTE).getHost());
    }

    super.messageReceived(ctx, e);
}
 
開發者ID:neilbeveridge,項目名稱:zuul-netty,代碼行數:15,代碼來源:HttpAppResolvingHandler.java

示例7: createSendDataRequest

import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
public static HttpRequest createSendDataRequest(String host, String cookie, ChannelBuffer data, String userAgent) {
	final HttpRequest request = createRequestTemplate(host, cookie, CLIENT_SEND_REQUEST_URI, userAgent);

	request.setHeader(HttpHeaders.Names.CONTENT_LENGTH, Long.toString(data.readableBytes()));
	request.setContent(data);

	return request;
}
 
開發者ID:reines,項目名稱:httptunnel,代碼行數:9,代碼來源:HttpTunnelMessageUtils.java

示例8: createRequestTemplate

import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
private static HttpRequest createRequestTemplate(String host, String tunnelId, String uri, String userAgent) {
	final HttpRequest request = new DefaultHttpRequest(HTTP_VERSION, HttpMethod.POST, createCompleteUri(host, uri));

	request.setHeader(HttpHeaders.Names.HOST, host);
	request.setHeader(HttpHeaders.Names.USER_AGENT, userAgent);

	if (tunnelId != null)
		request.setHeader(HttpHeaders.Names.COOKIE, tunnelId);

	return request;
}
 
開發者ID:reines,項目名稱:httptunnel,代碼行數:12,代碼來源:HttpTunnelMessageUtils.java

示例9: apply

import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public Future<HttpResponse> apply(HttpRequest req) {
    // Parse URL parameters
    String bannerSize = null;
    String opt = null;
    QueryStringDecoder decoder = new QueryStringDecoder(req.getUri());
    Map <String, List<String>> params = decoder.getParameters();
    if (params.containsKey("bsize")) {
        bannerSize = params.get("bsize").get(0);
        opt = params.get("opt").get(0);
    }

    // Parse cookie
    Cookie cookie = null;
    String value = req.getHeader("Cookie");
    if (value != null) {
        Set<Cookie> cookies = new CookieDecoder().decode(value);
        for (Cookie c : cookies) {
            if (c.getName().equals(COOKIE_NAME)) {
                cookie = c;
            }
        }
    }
    String vizid = null;
    if (cookie != null) {
        vizid = cookie.getValue();
    } else {
        vizid = UUID.randomUUID().toString();
        // TODO Avoid cache access
    }

    // Get data from redis cache, through RedisServer
    Service<HttpRequest, HttpResponse> client = Http.newService(":8002");
    HttpRequest helperRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/");
    JSONObject jsonReq = new JSONObject();
    jsonReq.put("key", vizid);
    jsonReq.put("command", "SMEMBERS");
    ChannelBuffer buffer = ChannelBuffers.copiedBuffer(jsonReq.toJSONString(), UTF_8);
    helperRequest.setContent(buffer);
    helperRequest.setHeader(HttpHeaders.Names.CONTENT_TYPE, "application/json; charset=UTF-8");
    helperRequest.setHeader(HttpHeaders.Names.CONTENT_LENGTH, buffer.readableBytes());
    Future<HttpResponse> helperResponse = client.apply(helperRequest);
    client.close();

    Future<HttpResponse> response = helperResponse.flatMap(new ProcessResponse2(req, vizid, 
            bannerSize, opt, jsonParser));
    System.out.println("[CookieServer] Returning response Future");
    return response;
}
 
開發者ID:eternalthinker,項目名稱:finagle-6.x-java-example,代碼行數:50,代碼來源:CookieServer.java

示例10: main

import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的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("[Main] Request received: " + reqContent);
            
            // Parsing JSON request
            JSONObject mainReq;
            try {
                mainReq = (JSONObject) jsonParser.parse(reqContent);
                System.out.println("[Main] Param received - pname:" + mainReq.get("pname"));
            } catch (ParseException e) {
                e.printStackTrace();
            }
            
            // Initiate request to Helper
            Service<HttpRequest, HttpResponse> client = ClientBuilder
                    .safeBuild(ClientBuilder.get().codec(Http.get())
                            .hosts("localhost:9004").hostConnectionLimit(1));
            
            HttpRequest helperRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/");
            ChannelBuffer buffer;
            buffer = request.getContent();
            //buffer = ChannelBuffers.copiedBuffer("{\"dummy\":1}", CharsetUtil.UTF_8);
            helperRequest.setContent(buffer);
            helperRequest.setHeader(HttpHeaders.Names.CONTENT_TYPE, "application/json; charset=UTF-8");
            helperRequest.setHeader(HttpHeaders.Names.CONTENT_LENGTH, buffer.readableBytes());
            
            Future<HttpResponse> helperResponse = client.apply(helperRequest);
            client.close();
            
            // TODO Understand how Future exceptions are handled. Eg: Connection Error
            /* helperResponse.addEventListener( 
                    new FutureEventListener<HttpResponse>() {
                        public void onSuccess(HttpResponse helperResponse) {
                            System.out.print("[Main] Received helper response: ");
                            System.out.println(helperResponse.getContent().toString(CharsetUtil.UTF_8));
                        }
                        public void onFailure(Throwable cause) {
                            System.out.println("[Main] Helper failed with cause: " + cause);
                        }
                    }); */
            
            Future <HttpResponse> mainResponse = helperResponse.flatMap(new GetBid());
            return mainResponse;
        }
    };
    
    ServerBuilder.safeBuild(service,
            ServerBuilder.get().codec(Http.get()).name("HttpServer")
            .bindTo(new InetSocketAddress("localhost", 9001)));
}
 
開發者ID:eternalthinker,項目名稱:finagle-6.x-java-example,代碼行數:55,代碼來源:MainServer.java

示例11: setNoData

import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
private static void setNoData(HttpRequest request) {
	request.setHeader(HttpHeaders.Names.CONTENT_LENGTH, "0");
	request.setContent(null);
}
 
開發者ID:reines,項目名稱:httptunnel,代碼行數:5,代碼來源:HttpTunnelMessageUtils.java


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