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


Java QueryStringDecoder.path方法代碼示例

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


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

示例1: channelRead0

import io.netty.handler.codec.http.QueryStringDecoder; //導入方法依賴的package包/類
@Override
protected void channelRead0(ChannelHandlerContext ctx, Object msg)
		throws Exception {
	if (msg instanceof HttpRequest) {
		HttpRequest request = (HttpRequest) msg;

		String uri = request.getUri();
		QueryStringDecoder decoder = new QueryStringDecoder(uri);
		String path = decoder.path();
		//System.out.println("path "+path);
		
		HttpResponse response = findHandler(request, path).handle(request, decoder);			
		 
		ctx.write(response);
		ctx.flush().close();
	}
}
 
開發者ID:duchien85,項目名稱:netty-cookbook,代碼行數:18,代碼來源:HttpEventRoutingHandler.java

示例2: channelRead0

import io.netty.handler.codec.http.QueryStringDecoder; //導入方法依賴的package包/類
@Override
protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest request) throws Exception {
	if (!request.getDecoderResult().isSuccess()) {
		sendError(ctx, BAD_REQUEST);
		return;
	}
				
	String uri = request.getUri();
	QueryStringDecoder decoder = new QueryStringDecoder(uri);			
	SimpleHttpRequest req = new SimpleHttpRequest(decoder.path(), decoder.parameters());
				
	String cookieString = request.headers().get(HttpHeaders.Names.COOKIE);
	if (cookieString != null) {
		Set<Cookie> cookies = CookieDecoder.decode(cookieString);
		req.setCookies(cookies);
	} else {
		req.setCookies(Collections.emptySet());
	}
	req.setHeaders(request.headers());
	copyHttpBodyData(request, req);
	
	SimpleHttpResponse resp =  eventHandler.apply(req);
	ctx.write( HttpEventHandler.buildHttpResponse(resp.toString(), resp.getStatus(), resp.getContentType()) );
	ctx.flush().close();
	
}
 
開發者ID:duchien85,項目名稱:netty-cookbook,代碼行數:27,代碼來源:FunctionsChannelHandler.java

示例3: TSDBHttpRequest

import io.netty.handler.codec.http.QueryStringDecoder; //導入方法依賴的package包/類
/**
 * Creates a new TSDBHttpRequest
 * @param request The incoming HTTP request
 * @param channel The channel the request came in on
 * @param ctx The http request router's channel handler context
 */
protected TSDBHttpRequest(final HttpRequest request, final Channel channel, final ChannelHandlerContext ctx) {
	this.request = request;
	this.channel = channel;
	this.ctx = ctx;
	final QueryStringDecoder decoder = new QueryStringDecoder(request.uri());
	path = decoder.path();
	final StringBuilder b = new StringBuilder("/api/");
	pathElements = PATH_SPLIT.split(path);
	for(String part: pathElements) {
		if(part==null || part.trim().isEmpty() || "api".equals(part)) {
			continue;
		}
		b.append(part);
		break;
	}
	route = b.toString();		
}
 
開發者ID:nickman,項目名稱:tsdblite,代碼行數:24,代碼來源:TSDBHttpRequest.java

示例4: channelRead

import io.netty.handler.codec.http.QueryStringDecoder; //導入方法依賴的package包/類
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
  if (msg instanceof FullHttpRequest) {
    FullHttpRequest req = (FullHttpRequest) msg;
    if (req.method() == HttpMethod.GET && req.uri().startsWith(connectPath)) {
      final QueryStringDecoder queryDecoder = new QueryStringDecoder(req.uri());
      final String requestPath = queryDecoder.path();

      if (log.isDebugEnabled())
        log.debug("Received HTTP {} handshake request: {} from channel: {}", getTransportType().getName(), req, ctx.channel());

      try {
        handshake(ctx, req, requestPath);
      } catch (Exception e) {
        log.error("Error during {} handshake : {}", getTransportType().getName(), e);
      } finally {
        ReferenceCountUtil.release(msg);
      }
      return;
    }
  } else if (msg instanceof WebSocketFrame && isCurrentHandlerSession(ctx)) {
    handleWebSocketFrame(ctx, (WebSocketFrame) msg);
    return;
  }
  ctx.fireChannelRead(msg);
}
 
開發者ID:scalecube,項目名稱:socketio,代碼行數:27,代碼來源:WebSocketHandler.java

示例5: channelRead

import io.netty.handler.codec.http.QueryStringDecoder; //導入方法依賴的package包/類
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
  if (msg instanceof HttpRequest) {
    final HttpRequest req = (HttpRequest) msg;
    final HttpMethod requestMethod = req.method();
    final QueryStringDecoder queryDecoder = new QueryStringDecoder(req.uri());
    final String requestPath = queryDecoder.path();

    boolean disconnect = queryDecoder.parameters().containsKey(DISCONNECT);
    if (disconnect) {
      if (log.isDebugEnabled())
        log.debug("Received HTTP disconnect request: {} {} from channel: {}", requestMethod, requestPath, ctx.channel());

      final String sessionId = PipelineUtils.getSessionId(requestPath);
      final Packet disconnectPacket = new Packet(PacketType.DISCONNECT, sessionId);
      disconnectPacket.setOrigin(PipelineUtils.getOrigin(req));
      ctx.fireChannelRead(disconnectPacket);
      ReferenceCountUtil.release(msg);
      return;
    }
  }
  ctx.fireChannelRead(msg);
}
 
開發者ID:scalecube,項目名稱:socketio,代碼行數:24,代碼來源:DisconnectHandler.java

示例6: RequestLog

import io.netty.handler.codec.http.QueryStringDecoder; //導入方法依賴的package包/類
/**
 * Constructor
 * @param httpReq HttpRequest object to be sent to Sparkngin
 */
public RequestLog(HttpRequest httpReq, Pattern[] headerMatcher) {
  QueryStringDecoder decoder = new QueryStringDecoder(httpReq.getUri());
  String path = decoder.path() ;
  List<String> segments = StringUtil.split(path, '/') ;
  this.trackerName = segments.get(1) ;
  this.site = segments.get(2) ;
  
  this.uri = httpReq.getUri() ;
  this.method = httpReq.getMethod().name() ;
  requestHeaders = new HashMap<String, String>() ;
  Iterator<Entry<String, String>> i = httpReq.headers().iterator() ;
  while(i.hasNext()) {
    Entry<String, String> entry =i.next();
    String key = entry.getKey() ;
    if(extractHeader(key, headerMatcher)) {
      requestHeaders.put(key, entry.getValue()) ;
    }
  }
}
 
開發者ID:DemandCube,項目名稱:Sparkngin,代碼行數:24,代碼來源:RequestLog.java

示例7: route

import io.netty.handler.codec.http.QueryStringDecoder; //導入方法依賴的package包/類
/**
 * If there's no match, returns the result with {@link #notFound(Object) notFound}
 * as the target if it is set, otherwise returns {@code null}.
 */
public RouteResult<T> route(HttpMethod method, String uri) {
    MethodlessRouter<T> router = routers.get(method);
    if (router == null) {
        router = anyMethodRouter;
    }

    QueryStringDecoder decoder = new QueryStringDecoder(uri);
    String[] tokens = decodePathTokens(uri);

    RouteResult<T> ret = router.route(uri, decoder.path(), tokens);
    if (ret != null) {
        return new RouteResult<T>(uri, decoder.path(), ret.pathParams(), decoder.parameters(), ret.target());
    }

    if (router != anyMethodRouter) {
        ret = anyMethodRouter.route(uri, decoder.path(), tokens);
        if (ret != null) {
            return new RouteResult<T>(uri, decoder.path(), ret.pathParams(), decoder.parameters(), ret.target());
        }
    }

    if (notFound != null) {
        return new RouteResult<T>(uri, decoder.path(), Collections.<String, String>emptyMap(), decoder.parameters(), notFound);
    }

    return null;
}
 
開發者ID:all4you,項目名稱:redant,代碼行數:32,代碼來源:Router.java

示例8: getPath

import io.netty.handler.codec.http.QueryStringDecoder; //導入方法依賴的package包/類
private static String getPath(QueryStringDecoder decoder)
        throws FileNotFoundException {
  String path = decoder.path();
  if (path.startsWith(WEBHDFS_PREFIX)) {
    return path.substring(WEBHDFS_PREFIX_LENGTH);
  } else {
    throw new FileNotFoundException("Path: " + path + " should " +
            "start with " + WEBHDFS_PREFIX);
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:11,代碼來源:FSImageHandler.java

示例9: handleWebSocketRequest

import io.netty.handler.codec.http.QueryStringDecoder; //導入方法依賴的package包/類
private void handleWebSocketRequest(@NotNull final ChannelHandlerContext context, @NotNull FullHttpRequest request, @NotNull final QueryStringDecoder uriDecoder) {
  WebSocketServerHandshakerFactory factory = new WebSocketServerHandshakerFactory("ws://" + request.headers().getAsString(HttpHeaderNames.HOST) + uriDecoder.path(), null, false, NettyUtil.MAX_CONTENT_LENGTH);
  WebSocketServerHandshaker handshaker = factory.newHandshaker(request);
  if (handshaker == null) {
    WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(context.channel());
    return;
  }

  if (!context.channel().isOpen()) {
    return;
  }

  final Client client = new WebSocketClient(context.channel(), handshaker);
  context.attr(ClientManager.CLIENT).set(client);
  handshaker.handshake(context.channel(), request).addListener(new ChannelFutureListener() {
    @Override
    public void operationComplete(ChannelFuture future) throws Exception {
      if (future.isSuccess()) {
        ClientManager clientManager = WebSocketHandshakeHandler.this.clientManager.getValue();
        clientManager.addClient(client);
        MessageChannelHandler messageChannelHandler = new MessageChannelHandler(clientManager, getMessageServer());
        BuiltInServer.replaceDefaultHandler(context, messageChannelHandler);
        ChannelHandlerContext messageChannelHandlerContext = context.pipeline().context(messageChannelHandler);
        context.pipeline().addBefore(messageChannelHandlerContext.name(), "webSocketFrameAggregator", new WebSocketFrameAggregator(NettyUtil.MAX_CONTENT_LENGTH));
        messageChannelHandlerContext.attr(ClientManager.CLIENT).set(client);
        connected(client, uriDecoder.parameters());
      }
    }
  });
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:31,代碼來源:WebSocketHandshakeHandler.java

示例10: process

import io.netty.handler.codec.http.QueryStringDecoder; //導入方法依賴的package包/類
public void process(InfoPage page, Map<String, Object> scopes, QueryStringDecoder uriDecoder) throws Exception {
  String path = uriDecoder.path() ;
  String id = path.substring(path.lastIndexOf("/") + 1) ;
  int containerId = Integer.parseInt(id) ;
  AppContainerInfoHolder containerInfo = appMaster.getAppInfo().getAppContainerInfoHolder(containerId) ;
  scopes.put("containerInfo", containerInfo) ;
  page.setContainerView();
}
 
開發者ID:DemandCube,項目名稱:NeverwinterDP-Commons,代碼行數:9,代碼來源:InfoRouteHandler.java

示例11: wrapGetRequest

import io.netty.handler.codec.http.QueryStringDecoder; //導入方法依賴的package包/類
private RequestWrapper wrapGetRequest(FullHttpRequest request, HttpMethod method, String uri) {
  QueryStringDecoder queryStringDecoder = getQueryStringDecoder(uri);
  String path = queryStringDecoder.path();
  Map<String, List<String>> queryParameters = queryStringDecoder.parameters();
  String data = getRequestData(request);
  return new RequestWrapper(method, request.headers(), uri, path, queryParameters, data);
}
 
開發者ID:orctom,項目名稱:laputa,代碼行數:8,代碼來源:LaputaRequestProcessor.java

示例12: channelRead

import io.netty.handler.codec.http.QueryStringDecoder; //導入方法依賴的package包/類
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
  if (msg instanceof HttpRequest) {
    final HttpRequest req = (HttpRequest) msg;
    final HttpMethod requestMethod = req.method();
    final QueryStringDecoder queryDecoder = new QueryStringDecoder(req.uri());
    final String requestPath = queryDecoder.path();

    if (!requestPath.startsWith(handshakePath)) {
      log.warn("Received HTTP bad request: {} {} from channel: {}", requestMethod, requestPath, ctx.channel());

      HttpResponse res = new DefaultHttpResponse(HTTP_1_1, HttpResponseStatus.BAD_REQUEST);
      ChannelFuture f = ctx.channel().writeAndFlush(res);
      f.addListener(ChannelFutureListener.CLOSE);
      ReferenceCountUtil.release(req);
      return;
    }

    if (HttpMethod.GET.equals(requestMethod) && requestPath.equals(handshakePath)) {
      if (log.isDebugEnabled())
        log.debug("Received HTTP handshake request: {} {} from channel: {}", requestMethod, requestPath, ctx.channel());

      handshake(ctx, req, queryDecoder);
      ReferenceCountUtil.release(req);
      return;
    }
  }

  super.channelRead(ctx, msg);
}
 
開發者ID:scalecube,項目名稱:socketio,代碼行數:31,代碼來源:HandshakeHandler.java

示例13: messageReceived

import io.netty.handler.codec.http.QueryStringDecoder; //導入方法依賴的package包/類
@Override
protected void messageReceived(ChannelHandlerContext ctx, FullHttpRequest request) throws Exception {
	QueryStringDecoder queryDecoder = new QueryStringDecoder(request.getUri());
	final String uri = request.getUri();
	HttpMethod method = request.getMethod();

	// 請求參數
	Map<String, String> params = null;

	// GET
	if (method == HttpMethod.GET) {
		Map<String, List<String>> getParams = queryDecoder.parameters();
		params = parseParams(getParams);
	}
	// POST
	else if (method == HttpMethod.POST) {
		ByteBuf content = request.content();
		if (content.isReadable()) {
			String param = content.toString(Charset.forName("UTF-8"));
			QueryStringDecoder postQueryStringDecoder = new QueryStringDecoder("/?" + param);
			Map<String, List<String>> postParams = postQueryStringDecoder.parameters();
			params = parseParams(postParams);
		}
	}
	
	final String path = queryDecoder.path();

	LOG.info("req, path:" + path + ", method:" + method + ", uri:" + uri);

	LOG.info("params:" + params.toString());
	
	writeResponse(request, ctx);
}
 
開發者ID:yintaoxue,項目名稱:casely,代碼行數:34,代碼來源:LeanerServerHandler.java

示例14: get

import io.netty.handler.codec.http.QueryStringDecoder; //導入方法依賴的package包/類
protected Object get(ChannelHandlerContext ctx, FullHttpRequest request) {
  QueryStringDecoder reqDecoder = new QueryStringDecoder(request.getUri()) ;
  String path = reqDecoder.path() ;
  return new Hello("PingTopic Get, topic = " + path) ;
}
 
開發者ID:DemandCube,項目名稱:NeverwinterDP-Commons,代碼行數:6,代碼來源:HttpRestUnitTest.java

示例15: post

import io.netty.handler.codec.http.QueryStringDecoder; //導入方法依賴的package包/類
protected Object post(ChannelHandlerContext ctx, FullHttpRequest request) {
  QueryStringDecoder reqDecoder = new QueryStringDecoder(request.getUri()) ;
  String path = reqDecoder.path() ;
  String data = new String(getBodyData(request)) ;
  return new Hello("HelloHandler Post, Data = " + data + ", topic = " + path) ;
}
 
開發者ID:DemandCube,項目名稱:NeverwinterDP-Commons,代碼行數:7,代碼來源:HttpRestUnitTest.java


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