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


Java HttpRequest.getHeader方法代碼示例

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


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

示例1: getcSeq

import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
/**
 * Metodo que extrae la cabecera de una peticion el CSeq
 */
private int getcSeq(HttpRequest request) throws RtspRequestException {

	int cSeq;
	String str_cSeq;


	str_cSeq = request.getHeader("CSeq");

	if(str_cSeq==null){
		throw new RtspRequestException("Request not contains CSeq header", RtspResponseStatuses.BAD_REQUEST);
	}

	try {
		cSeq = Integer.parseInt(str_cSeq);
	}
	catch(Exception e) {
		throw new RtspRequestException("CSeq header must be a number", RtspResponseStatuses.BAD_REQUEST);
	}

	return cSeq;	
}
 
開發者ID:laggc,項目名稱:rtsp_multicast_pfc,代碼行數:25,代碼來源:RtspServerListener.java

示例2: apply

import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
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 Skip cache access
    }

    // Get data from redis cache
    Future<scala.collection.immutable.Set<ChannelBuffer>> udResponse = redisCache.sMembers(vizid);

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

示例3: HttpRequestServletWrapper

import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
public HttpRequestServletWrapper(HttpRequest request,
		InetSocketAddress localAddress, 
		InetSocketAddress remoteAddress, 
		boolean secure,
		ServletContext context,
		HttpSession session) {
	this.request = request;
	this.localAddress = localAddress;
	this.remoteAddress = remoteAddress;
	
	this.secure = secure;
	this.context = context;
	this.session = session;
	
	parseUri(request.getUri());

	String contentType = request.getHeader(HttpHeaders.CONTENT_TYPE);
	
	String contentTypeCharset = "UTF-8";
	int idx;
	if(contentType!=null) {
		
		if((idx = contentType.indexOf(';')) > -1) {
			String tmp = contentType.substring(idx+1);
			contentType = contentType.substring(0, idx);
			if((idx = tmp.indexOf("charset=")) > -1) {
				contentTypeCharset = tmp.substring(idx+8);
			}
		}
		
		if(contentType!=null && contentType.equalsIgnoreCase("application/x-www-form-urlencoded")) {
			processParameters(request.getContent().toString(Charset.forName(contentTypeCharset)));
		}
	}
}
 
開發者ID:ludup,項目名稱:hypersocket-framework,代碼行數:36,代碼來源:HttpRequestServletWrapper.java

示例4: getSession

import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
/**
 * De una petición extraemos el ID de sesión si tiene, o si no, 
 * generamos uno.
 * @param request
 * @param method
 * @return
 * @throws RtspRequestException
 */
private String getSession(HttpRequest request, HttpMethod method) throws RtspRequestException {

	String session = request.getHeader("Session");

	if((session==null) && method.equals(RtspMethods.PLAY)) {
		throw new RtspRequestException("Session not found in play request",RtspResponseStatuses.SESSION_NOT_FOUND);
	}

	if(session==null)
	{
		session=generateSession();
	}
	return session;
}
 
開發者ID:laggc,項目名稱:rtsp_multicast_pfc,代碼行數:23,代碼來源:RtspServerListener.java

示例5: getRoute

import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
private URL getRoute(HttpRequest request)
        throws IllegalRouteException {
    URL route;
    String sRoute = request.getHeader(ROUTE_HEADER);
    try {
        route = new URL(sRoute);
    } catch (MalformedURLException e) {
        throw new IllegalRouteException(sRoute);
    }

    LOG.debug("found route: {}", route);

    return route;
}
 
開發者ID:neilbeveridge,項目名稱:zuul-netty,代碼行數:15,代碼來源:HttpProxyHandler.java

示例6: getWebSocketLocation

import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
private String getWebSocketLocation( HttpRequest req ) {
    String path = req.getUri();
    if ( path.equals( "/" ) ) {
        path = null;
    }
    if ( path != null ) {
        path = removeEnd( path, "/" );
    }
    String location =
            ( ssl ? "wss://" : "ws://" ) + req.getHeader( HttpHeaders.Names.HOST ) + ( path != null ? path : "" );
    logger.info( location );
    return location;
}
 
開發者ID:apache,項目名稱:usergrid,代碼行數:14,代碼來源:WebSocketChannelHandler.java

示例7: handleCookie

import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
public HttpSession handleCookie(HttpRequest request, ActionResponse actionResponse) {
		String cookieString = request.getHeader(HttpHeaders.Names.COOKIE);
//		logger.debug("cookie >> {}", cookieString);
		HttpSession sessionObj = null;
		String responseCookie = "";
		boolean hasSessionCookie = false;
		
		if(cookieString != null){
			String[] cookieArray = cookieString.split(";");
			for (int i = 0; i < cookieArray.length; i++) {
				String cookie = cookieArray[i].trim();
				String[] kv = cookie.split("=");
				String key = null;
				String value = null;
				
				if(kv.length > 0){
					key = kv[0];
				}
				if(kv.length > 1){
					value = kv[1];
				}
				
				if (DefaultSessionCookie.equalsIgnoreCase(key) && value != null && value.length() > 0) {
					// 세션쿠키 발견.
					hasSessionCookie = true;
					sessionObj = sessionObjMap.get(value);
					if (sessionObj == null) {
						sessionObj = new HttpSession(value);
						sessionObjMap.put(value, sessionObj);
					}else{
//						logger.debug("세션객체 찾음. {} >> {}", kv[i], sessionObj.map());
					}
				} else {
					if (responseCookie.length() > 0) {
						responseCookie += ";";
					}
					responseCookie += cookie;
				}
	
			}
		}
		
		if (responseCookie.length() > 0) {
			actionResponse.setResponseCookie(responseCookie);
		}
		
		if (!hasSessionCookie) {
			// cookie가 없거나, 쿠키내에 JSESSIONID가 없다면 생성해서 Set-Cookie로 돌려준다.JSESSIONID=1bqe4dww377gy1c3pwqjzxbedj;Path=/admin
			//TODO expireTimeInHour를 날짜로 바꿔서 추가. ; Expires=Wed, 09 Jun 2021 10:18:14 GMT
			String newSessionId = newSessionId();
			sessionObj = new HttpSession(newSessionId);
			sessionObjMap.put(newSessionId, sessionObj);
			logger.debug("New Session Created! {} >> {}", newSessionId, sessionObj);
			actionResponse.setResponseSetCookie(DefaultSessionCookie + "=" + newSessionId +";Path=/"); //경로구분없이 모두 동일한 session을 타도록 함.
		}
		
		if(sessionObj != null){
			sessionObj.update();
		}
		return sessionObj;
	}
 
開發者ID:gncloud,項目名稱:fastcatsearch3,代碼行數:62,代碼來源:HttpSessionManager.java

示例8: ActionRequest

import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
public ActionRequest(String uri, HttpRequest request) {
		this.uri = uri;
		this.request = request;
        String contentType = request.getHeader("Content-Type");
		if (request != null) {
            parameterMap = new HashMap<String, String>();
			if (request.getMethod() == HttpMethod.GET) {
				// logger.debug("URI:{} , {}, {}", request.getUri(), request.getUri().length(), uri.length());
				if (request.getUri().length() > uri.length()) {
					queryString = request.getUri().substring(uri.length() + 1); // 맨앞의 ?를 제거하기 위해 +1
                    if (queryString != null) {
                        parse();
                    }
				}
			} else if (request.getMethod() == HttpMethod.POST || request.getMethod() == HttpMethod.PUT || request.getMethod() == HttpMethod.DELETE ) {
                if (request.getUri().length() > uri.length()) {
                    queryString = request.getUri().substring(uri.length() + 1); // 맨앞의 ?를 제거하기 위해 +1
                    if (queryString != null) {
                        parse();
                    }
                }
				long len = HttpHeaders.getContentLength(request);
				ChannelBuffer buffer = request.getContent();
				requestBody = new String(buffer.toByteBuffer().array(), 0, (int) len);
                if(contentType == null || !contentType.startsWith("text/plain")) {
                    if (requestBody != null) {
                        parse(requestBody);
                    }
                }
			} else {

			}
			if(logger.isDebugEnabled()) {
				String debugQueryString = null;
				if(queryString != null) {
					debugQueryString = queryString.length() > 100 ? queryString.substring(0, 100) + "..." : queryString;
				}
				logger.debug("action {}, param={}", uri, debugQueryString);
			}

//            parameterMap = new HashMap<String, String>();
//			if (queryString != null) {
//				parse();
//			}
		}
	}
 
開發者ID:gncloud,項目名稱:fastcatsearch3,代碼行數:47,代碼來源:ActionRequest.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: getWebSocketLocation

import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
private static String getWebSocketLocation(HttpRequest req)
{
	return "ws://" + req.getHeader(HttpHeaders.Names.HOST) + WEBSOCKET_PATH;
}
 
開發者ID:EricssonResearch,項目名稱:trap,代碼行數:5,代碼來源:WebServerSocketHandler.java

示例11: getWebSocketLocation

import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
private static String getWebSocketLocation(HttpRequest req) {
    return "ws://" + req.getHeader(HttpHeaders.Names.HOST) + WEBSOCKET_PATH;
}
 
開發者ID:hou80houzhu,項目名稱:rocserver,代碼行數:4,代碼來源:WebSocketServerHandler.java

示例12: RequestWorker

import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
RequestWorker(ChannelHandlerContext ctx,
	HttpRequest nettyRequest) {
	this.ctx = ctx;
	this.nettyRequest = nettyRequest;
	
	interfaceResource = (HTTPInterfaceResource) ctx.getChannel().getParent().getAttachment();
	
	nettyResponse = new HttpResponseServletWrapper(
			new DefaultHttpResponse(HttpVersion.HTTP_1_1,
					HttpResponseStatus.OK),
			ctx.getChannel(), nettyRequest);
	
	session = server.setupHttpSession(
			nettyRequest.getHeaders("Cookie"), 
			interfaceResource.getProtocol()==HTTPProtocol.HTTPS,
			nettyResponse);
	
	InetSocketAddress remoteAddress = (InetSocketAddress) ctx.getChannel().getRemoteAddress();
	if(nettyRequest.containsHeader("X-Forwarded-For")) {
		String[] ips = nettyRequest.getHeader("X-Forwarded-For").split(",");
		remoteAddress = new InetSocketAddress(ips[0], remoteAddress.getPort());
	} else if(nettyRequest.containsHeader("Forwarded")) {
		StringTokenizer t = new StringTokenizer(nettyRequest.getHeader("Forwarded"), ";");
		while(t.hasMoreTokens()) {
			String[] pair = t.nextToken().split("=");
			if(pair.length == 2 && pair[0].equalsIgnoreCase("for")) {
				remoteAddress = new InetSocketAddress(pair[1], remoteAddress.getPort());
			}
		}
	}
	
	servletRequest = new HttpRequestServletWrapper(
			nettyRequest, (InetSocketAddress) ctx.getChannel()
					.getLocalAddress(), remoteAddress, 
					interfaceResource.getProtocol()==HTTPProtocol.HTTPS, 
					server.getServletConfig().getServletContext(), session);
	
	if(nettyRequest.isChunked()) {
		ctx.getChannel().setAttachment(servletRequest);
	}
}
 
開發者ID:ludup,項目名稱:hypersocket-framework,代碼行數:42,代碼來源:HttpRequestDispatcherHandler.java

示例13: getWebSocketLocation

import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
private static String getWebSocketLocation(HttpRequest req) {
	return "ws://" + req.getHeader(HttpHeaders.HOST) + req.getUri();
}
 
開發者ID:ludup,項目名稱:hypersocket-framework,代碼行數:4,代碼來源:HttpRequestDispatcherHandler.java

示例14: checkTransport

import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
/**
 * Verificamos que las peticiones SETUP expecifican en la cabecera
 * Transport multicast.
 * @param request
 * @throws RtspRequestException
 */
private void checkTransport(HttpRequest request) throws RtspRequestException {

	String transport = request.getHeader("Transport");

	if(transport==null) {
		throw new RtspRequestException("Request not contains Transport header", RtspResponseStatuses.BAD_REQUEST);
	}

	
	
	if(!transport.toUpperCase().contains("MULTICAST")) {
		throw new RtspRequestException("Only multicast transport is allowed", RtspResponseStatuses.UNSUPPORTED_TRANSPORT);
	}
	
	if(transport.toUpperCase().contains("TCP")) {
		throw new RtspRequestException("Only UDP transport is allowed", RtspResponseStatuses.UNSUPPORTED_TRANSPORT);
	}
}
 
開發者ID:laggc,項目名稱:rtsp_multicast_pfc,代碼行數:25,代碼來源:RtspServerListener.java

示例15: checkHost

import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
public static boolean checkHost(HttpRequest request, SocketAddress expectedHost) {
	final String host = request.getHeader(HttpHeaders.Names.HOST);
	return expectedHost == null ? host == null : convertToHostString(expectedHost).equals(host);
}
 
開發者ID:reines,項目名稱:httptunnel,代碼行數:5,代碼來源:HttpTunnelMessageUtils.java


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