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


Java HttpRequest.getUri方法代碼示例

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


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

示例1: decode

import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
@Override
protected Object decode(
        Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {

    HttpRequest request = (HttpRequest) msg;
    QueryStringDecoder decoder = new QueryStringDecoder(request.getUri());

    DeviceSession deviceSession = getDeviceSession(
            channel, remoteAddress, decoder.getParameters().get("UserName").get(0));
    if (deviceSession == null) {
        return null;
    }

    Parser parser = new Parser(PATTERN, decoder.getParameters().get("LOC").get(0));
    if (!parser.matches()) {
        return null;
    }

    Position position = new Position();
    position.setProtocol(getProtocolName());
    position.setDeviceId(deviceSession.getDeviceId());

    position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));

    position.setValid(true);
    position.setLatitude(parser.nextDouble(0));
    position.setLongitude(parser.nextDouble(0));
    position.setAltitude(parser.nextDouble(0));
    position.setSpeed(parser.nextDouble(0));
    position.setCourse(parser.nextDouble(0));

    if (channel != null) {
        HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
        channel.write(response).addListener(ChannelFutureListener.CLOSE);
    }

    return position;
}
 
開發者ID:bamartinezd,項目名稱:traccar-service,代碼行數:39,代碼來源:PathAwayProtocolDecoder.java

示例2: doPost

import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
private void doPost(ChannelHandlerContext ctx, MessageEvent e, HttpRequest req)
        throws IOException {

  final QueryStringDecoder decoded = new QueryStringDecoder(req.getUri());
  if (!decoded.getPath().equalsIgnoreCase("/write")) {
    writeResponseAndClose(e,
            new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.NOT_FOUND));
    return;
  }

  try {
    metricParser.parse(req);
  } catch (IllegalArgumentException iae) {
    logger.warn("Metric parser failed: " + iae.getMessage());
  }

  HttpResponse response = new DefaultHttpResponse(
          HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
  response.setContent(ChannelBuffers.copiedBuffer(
          ("Seen events").getBytes()
  ));
  writeResponseAndClose(e, response);
}
 
開發者ID:yandex,項目名稱:opentsdb-flume,代碼行數:24,代碼來源:LegacyHttpSource.java

示例3: getRequestBody

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

示例4: messageReceived

import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
    if (!readingChunks) {
        request = (HttpRequest) e.getMessage();
        String uri = request.getUri();
        if (uri.equals("/exception")) {
            throw new Exception("Test");
        }
        if (request.isChunked()) {
            readingChunks = true;
        } else {
            writeResponse(e);
        }
    } else {
        HttpChunk chunk = (HttpChunk) e.getMessage();
        if (chunk.isLast()) {
            readingChunks = false;
            writeResponse(e);
        }
    }
}
 
開發者ID:glowroot,項目名稱:glowroot,代碼行數:22,代碼來源:HttpServerHandler.java

示例5: decode

import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
@Override
protected Object decode(ChannelHandlerContext ctx, Channel channel, Object msg)
        throws Exception
{
  HttpRequest nettyRequest = (HttpRequest) msg;
  URI uri = new URI(nettyRequest.getUri());
  RestRequestBuilder builder = new RestRequestBuilder(uri);
  builder.setMethod(nettyRequest.getMethod().getName());
  for (Map.Entry<String, String> e : nettyRequest.getHeaders())
  {
    builder.unsafeAddHeaderValue(e.getKey(), e.getValue());
  }
  ChannelBuffer buf = nettyRequest.getContent();
  if (buf != null)
  {
    if (buf.hasArray())
    {
      // TODO make a copy?
      builder.setEntity(buf.array());
    }
  }

  return builder.build();
}
 
開發者ID:ppdai,項目名稱:rest4j,代碼行數:25,代碼來源:RAPServerCodec.java

示例6: messageReceived

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

import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
public static Response create(HttpRequest httpRequest) {
	Response response = new Response();
	response.requestPath = httpRequest.getUri();
	response.contentType = StringUtils.defaultIfEmpty(httpRequest.headers().get(HttpHeaders.Names.CONTENT_TYPE), ContentType.TEXT_PLAIN.getMimeType());
	response.shouldKeepAlive = HttpHeaders.isKeepAlive(httpRequest);
	return response;
}
 
開發者ID:iceize,項目名稱:netty-http-3.x,代碼行數:8,代碼來源:Response.java

示例8: process

import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
public boolean process(HttpRequest request, HttpResponse response)
    throws Exception {
    String uri = request.getUri();
    if (uri.equalsIgnoreCase(FAVICON)) {
        response.setStatus(HttpResponseStatus.NOT_FOUND);
        log.warn("favicon.ico isn't found!");
        response.setContent(ChannelBuffers.copiedBuffer(HttpResponseStatus.NOT_FOUND.toString(), CharsetUtil.UTF_8));
        return false;
    }

    return true;
}
 
開發者ID:sunguangran,項目名稱:navi,代碼行數:13,代碼來源:FaviousRequestLister.java

示例9: packageNaviHttpRequest

import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
@Override
public NaviHttpRequest packageNaviHttpRequest(HttpRequest request) throws Exception {
    String uri = request.getUri();

    // 過濾 "//"
    uri = uri.replaceAll("/(/)+", "/");

    // 重定向
    uri = redirect(uri);
    if (uri == null || uri.length() == 0) {
        throw new NaviSystemException("malformed URL!", NaviError.SYSERROR);
    }

    if (uri.indexOf('?') > 0) {
        uri = uri.substring(0, uri.indexOf('?'));
    }

    String[] uriSplits = uri.split("/");
    if (uriSplits.length < 2) {
        throw new NaviSystemException("malformed URL!", NaviError.SYSERROR);
    }

    NaviHttpRequest naviReq = new NaviHttpRequest(request);
    naviReq.setServer(ServerConfigure.get(NaviDefine.SERVER));
    naviReq.setModuleNm(uriSplits[1]);
    naviReq.setUri(uri);
    return naviReq;
}
 
開發者ID:sunguangran,項目名稱:navi,代碼行數:29,代碼來源:DefaultNaviRequestDispatcher.java

示例10: populateCamelHeaders

import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
@Override
public void populateCamelHeaders(HttpRequest request, Map<String, Object> headers, Exchange exchange, NettyHttpConfiguration configuration) throws Exception {
    super.populateCamelHeaders(request, headers, exchange, configuration);

    String path = request.getUri();
    if (path == null) {
        return;
    }

    // skip the scheme/host/port etc, as we only want the context-path
    URI uri = new URI(path);
    path = uri.getPath();

    // in the endpoint the user may have defined rest {} placeholders
    // so we need to map those placeholders with data from the incoming request context path

    String consumerPath = configuration.getPath();

    if (useRestMatching(consumerPath)) {

        // split using single char / is optimized in the jdk
        String[] paths = path.split("/");
        String[] consumerPaths = consumerPath.split("/");

        for (int i = 0; i < consumerPaths.length; i++) {
            if (paths.length < i) {
                break;
            }
            String p1 = consumerPaths[i];
            if (p1.startsWith("{") && p1.endsWith("}")) {
                String key = p1.substring(1, p1.length() - 1);
                String value = paths[i];
                if (value != null) {
                    NettyHttpHelper.appendHeader(headers, key, value);
                }
            }
        }
    }
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:40,代碼來源:RestNettyHttpBinding.java

示例11: 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

示例12: handle

import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
public ComposableFuture<Map<String, String>> handle(final HttpRequest request) {
  final QueryStringDecoder queryStringDecoder = new QueryStringDecoder(request.getUri());
  final Map<String,List<String>> params = queryStringDecoder.getParameters();
  final Map<String, String> res = new HashMap<>();
  for (final String key: params.keySet()) {
    res.put(key, params.get(key).get(0));
  }

  return ComposableFutures.fromValue(res);
}
 
開發者ID:outbrain,項目名稱:ob1k,代碼行數:11,代碼來源:ParamsService.java

示例13: parseGet

import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
private void parseGet(ChannelHandlerContext ctx, MessageEvent e, HttpRequest request)  {
	QueryStringDecoder decoder = new QueryStringDecoder(request.getUri());
	String path = decoder.getPath();
	HttpResponse response = null;;
	LogHelper.info("got get request "+path);
	if(path.equals("/ewifi/ping/")){
		response = parsePing(ctx, decoder);
	}else if(path.equals("/ewifi/auth/")){
		response = parseAuth(ctx, decoder);
	}else if(path.equals("/ewifi/login/")){
		response = parseLogin(ctx, decoder);
	}else if(path.equals("/ewifi/portal/")){
		response = parsePortal(ctx, decoder);
	}else if(path.equals("/ewifi/regedit/")){
		response = parseRegedit(ctx, decoder);
	}else if(path.equals("/ewifi/querymac/")){
		response = parseQuery(ctx, decoder);
	}else{
		response = parseStatic(ctx, decoder);
	}

	Channel ch = e.getChannel();
	if (ch.isConnected()) {
		ch.write(response).addListener(ChannelFutureListener.CLOSE);
	}

}
 
開發者ID:violetgo,項目名稱:wifidogAuthServer,代碼行數:28,代碼來源:HttpHandler.java

示例14: writeAccessLog

import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
/**
 * override this method for your log content
 * @param channel
 * @param nhr
 * @param resp
 * @throws UnsupportedEncodingException
 */
protected void writeAccessLog( final Channel channel, HttpRequest req, 
		DefaultHttpResponse resp) throws UnsupportedEncodingException{
	String ip = channel.getRemoteAddress().toString();
	if( ip.startsWith("/") ) ip = ip.substring(1);
	
	String url = req.getUri();
	String responeContent = resp.getContent().toString( CharsetUtil.UTF_8 );
	
	log.info( "{}\t{}", ip + " " + url, responeContent );
	
}
 
開發者ID:lgnlgn,項目名稱:feluca,代碼行數:19,代碼來源:BaseChannelHandler.java

示例15: service

import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
@Override
protected void service(ResourceProvider provider, Channel channel, HttpRequest request) throws IOException {
	String path = request.getUri();
	ByteBuffer buf = provider.get(path);

	ChannelBuffer wrapped;
	HttpResponseStatus status = HttpResponseStatus.OK;

	String mime = getMimeType(request.getUri());

	if (buf == null) {
		status = HttpResponseStatus.NOT_FOUND;
		wrapped = createErrorPage(status, "The page you requested could not be found.");
		mime = "text/html";
	} else {
		wrapped = ChannelBuffers.wrappedBuffer(buf);
	}

	HttpResponse response = new DefaultHttpResponse(request.getProtocolVersion(), status);

	response.setHeader("Date", new Date());
	response.setHeader("Server", SERVER_IDENTIFIER);
	response.setHeader("Content-type", mime + ", charset=" + CHARACTER_SET.name());
	response.setHeader("Cache-control", "no-cache");
	response.setHeader("Pragma", "no-cache");
	response.setHeader("Expires", new Date(0));
	response.setHeader("Connection", "close");
	response.setHeader("Content-length", wrapped.readableBytes());
	response.setChunked(false);
	response.setContent(wrapped);

	channel.write(response).addListener(ChannelFutureListener.CLOSE);
}
 
開發者ID:DealerNextDoor,項目名稱:ApolloDev,代碼行數:34,代碼來源:HttpRequestWorker.java


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