本文整理汇总了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();
}
}
示例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();
}
示例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();
}
示例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);
}
示例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);
}
示例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()) ;
}
}
}
示例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;
}
示例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);
}
}
示例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());
}
}
});
}
示例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();
}
示例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);
}
示例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);
}
示例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);
}
示例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) ;
}
示例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) ;
}