当前位置: 首页>>代码示例>>Java>>正文


Java FullHttpRequest.method方法代码示例

本文整理汇总了Java中io.netty.handler.codec.http.FullHttpRequest.method方法的典型用法代码示例。如果您正苦于以下问题:Java FullHttpRequest.method方法的具体用法?Java FullHttpRequest.method怎么用?Java FullHttpRequest.method使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.netty.handler.codec.http.FullHttpRequest的用法示例。


在下文中一共展示了FullHttpRequest.method方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleRequest

import io.netty.handler.codec.http.FullHttpRequest; //导入方法依赖的package包/类
/**
 * Processes an HTTP request
 * @param ctx The channel handler context
 * @param req The HTTP request
 */
public void handleRequest(final ChannelHandlerContext ctx, final FullHttpRequest req) {
	log.warn("HTTP Request: {}", req);
       if (req.method() != GET) {
           sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HTTP_1_1, FORBIDDEN));
           return;
       }
       String uri = req.uri();
       if(!"/ws".equals(uri)) {
       	//channelRead(ctx, req);
       	final WebSocketServerProtocolHandler wsProto = ctx.pipeline().get(WebSocketServerProtocolHandler.class);
       	if(wsProto != null) {
       		try {
				wsProto.acceptInboundMessage(req);
				return;
			} catch (Exception ex) {
				log.error("Failed to dispatch http request to WebSocketServerProtocolHandler on channel [{}]", ctx.channel(), ex);
			}
       	}
       }
       log.error("Failed to handle HTTP Request [{}] on channel [{}]", req, ctx.channel());
       sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HTTP_1_1, HttpResponseStatus.MISDIRECTED_REQUEST));
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:28,代码来源:WebSocketServiceHandler.java

示例2: handleHttpRequest

import io.netty.handler.codec.http.FullHttpRequest; //导入方法依赖的package包/类
private void handleHttpRequest(ChannelHandlerContext ctx, FullHttpRequest req) throws Exception {

        // Handle a bad request.
        if (!req.decoderResult().isSuccess()) {
            sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HTTP_1_1, BAD_REQUEST));
            return;
        }

        // Allow only GET methods.
        if (req.method() != GET) {
            sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HTTP_1_1, FORBIDDEN));
            return;
        }

        // Handshake
        WebSocketServerHandshakerFactory wsFactory = new WebSocketServerHandshakerFactory(
                getWebSocketLocation(req), null, false);
        handshaker = wsFactory.newHandshaker(req);

        if (handshaker == null) {
            WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(ctx.channel());
        } else {
            handshaker.handshake(ctx.channel(), req);
        }
    }
 
开发者ID:ZhangFly,项目名称:WTFSocket_Server_JAVA,代码行数:26,代码来源:WTFSocketWebSocketHandler.java

示例3: Request

import io.netty.handler.codec.http.FullHttpRequest; //导入方法依赖的package包/类
public Request(Channel channel, FullHttpRequest fullHttpRequest) {
    this.fullHttpRequest = fullHttpRequest;
    this.channel = channel;
    this.method = fullHttpRequest.method();
    //get cookie
    parseCookie();
}
 
开发者ID:zhyzhyzhy,项目名称:Ink,代码行数:8,代码来源:Request.java

示例4: routeSetter

import io.netty.handler.codec.http.FullHttpRequest; //导入方法依赖的package包/类
public static void routeSetter(Route route, FullHttpRequest fullHttpRequest) throws Exception {
    String path = fullHttpRequest.uri();
    HttpMethod method = fullHttpRequest.method();


    if (route.security()) {
        CheckResult checkResult = SecurityManager.check(route);
        if (!checkResult.isOk()) {
            throw checkResult.exception();
        }
    }

    //设置@PathVariable
    routePathVariableSetter(path, route);

    if (route.httpMethod().equals(HttpMethod.GET)) {
        //设置GET @RequestParam
        GETParamsSetter(path, route);
    } else if (route.httpMethod().equals(HttpMethod.POST)) {
        //设置POST @RequestParam
        POSTParamsSetter(fullHttpRequest, route);
    }

    //设置@RequestJson
    if ("application/json".equals(fullHttpRequest.headers().get("content-Type"))) {
        routeRequestJsonSetter(fullHttpRequest.content().copy().toString(CharsetUtil.UTF_8), route);
    }

    //设置@FILE
    if (fullHttpRequest.headers().get("content-Type") != null && fullHttpRequest.headers().get("content-Type").startsWith("multipart/form-data")) {
        fileSetter(fullHttpRequest, route);
    }

    //设置model
    modelSetter(fullHttpRequest, route);

}
 
开发者ID:zhyzhyzhy,项目名称:Ink,代码行数:38,代码来源:RouteSetter.java

示例5: channelRead0

import io.netty.handler.codec.http.FullHttpRequest; //导入方法依赖的package包/类
@Override
protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest req) throws Exception {
    // Handle a bad request.
    if (!req.decoderResult().isSuccess()) {
        sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HTTP_1_1, BAD_REQUEST));
        return;
    }

    // Allow only GET methods.
    if (req.method() != GET) {
        sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HTTP_1_1, FORBIDDEN));
        return;
    }

    // Send the index page
    if ("/".equals(req.uri()) || "/index.html".equals(req.uri()) || "/craft.html".equals(req.uri())) {
        sendTextResource(null,"/craft.html", "text/html; charset=UTF-8", req, ctx);
    } else if ("/craft.js".equals(req.uri()) || "/craftw.js".equals(req.uri())) {
        String prepend = "window.DEFAULT_ARGV = ['-'];"; // connect back to self
        sendTextResource(prepend, req.uri(), "application/javascript; charset=UTF-8", req, ctx);
    } else if ("/craft.html.mem".equals(req.uri())) {
        sendBinaryResource(req.uri(), "application/octet-stream", req, ctx);
    } else if ("/craftw.wasm".equals(req.uri())) {
        // craftw = webassembly build
        sendBinaryResource(req.uri(), "application/octet-stream", req, ctx);
    } else if ("/craft.data".equals(req.uri()) || "/craftw.data".equals(req.uri())) {
        // same data file for both asmjs and webassembly
        sendBinaryResource("/craft.data", "application/octet-stream", req, ctx);
    } else if ("/textures.zip".equals(req.uri())) {
        File file = new File(this.pluginDataFolder, "textures.zip");
        if (file.exists()) {
            sendBinaryResource(req.uri(), "application/octet-stream", req, ctx);
        } else {
            System.out.println("request for /textures.zip but does not exist in plugin data folder");
            sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HTTP_1_1, PRECONDITION_FAILED));
        }
    } else {
        sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HTTP_1_1, NOT_FOUND));
    }
}
 
开发者ID:satoshinm,项目名称:WebSandboxMC,代码行数:41,代码来源:WebSocketIndexPageHandler.java

示例6: ifConnectSuccess

import io.netty.handler.codec.http.FullHttpRequest; //导入方法依赖的package包/类
private boolean ifConnectSuccess(ChannelHandlerContext ctx, FullHttpRequest request) {
    if (!request.decoderResult().isSuccess()) {
        sendError(ctx, HttpResponseStatus.BAD_REQUEST);
        return false;
    }
    if (request.method() != HttpMethod.GET) {
        sendError(ctx, HttpResponseStatus.METHOD_NOT_ALLOWED);
        return false;
    }
    return true;
}
 
开发者ID:noti0na1,项目名称:HFSN,代码行数:12,代码来源:HttpFileServerHandler.java

示例7: HttpRequest

import io.netty.handler.codec.http.FullHttpRequest; //导入方法依赖的package包/类
protected HttpRequest(FullHttpRequest fullHttpRequest) throws URISyntaxException {
	super(fullHttpRequest.protocolVersion(), fullHttpRequest.method(), fullHttpRequest.uri(),
			fullHttpRequest.content().copy());

	this.headers().set(fullHttpRequest.headers());
	this.trailingHeaders().set(fullHttpRequest.trailingHeaders());
	this.setDecoderResult(fullHttpRequest.decoderResult());
	this.uri = createUriWithNormalizing(fullHttpRequest.uri());

	this.parameters = parameters();
	this.cookies = cookies();
	this.pathParameters = Maps.newHashMap();
}
 
开发者ID:anyflow,项目名称:lannister,代码行数:14,代码来源:HttpRequest.java

示例8: channelRead0

import io.netty.handler.codec.http.FullHttpRequest; //导入方法依赖的package包/类
@Override
protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest req) throws Exception {
    // Handle a bad request.
    if (!req.decoderResult().isSuccess()) {
        sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HTTP_1_1, BAD_REQUEST));
        return;
    }

    // Allow only GET methods.
    if (req.method() != GET) {
        sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HTTP_1_1, FORBIDDEN));
        return;
    }

    // Send the index page
    if ("/".equals(req.uri()) || "/index.html".equals(req.uri())) {
        String webSocketLocation = getWebSocketLocation(ctx.pipeline(), req, websocketPath);
        ByteBuf content = WebSocketServerIndexPage.getContent(webSocketLocation);
        FullHttpResponse res = new DefaultFullHttpResponse(HTTP_1_1, OK, content);

        res.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/html; charset=UTF-8");
        HttpUtil.setContentLength(res, content.readableBytes());

        sendHttpResponse(ctx, req, res);
    } else {
        sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HTTP_1_1, NOT_FOUND));
    }
}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:29,代码来源:WebSocketIndexPageHandler.java

示例9: channelRead0

import io.netty.handler.codec.http.FullHttpRequest; //导入方法依赖的package包/类
@Override
protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest req) throws Exception {
	// Handle a bad request.
	if (!req.decoderResult().isSuccess()) {
		sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HTTP_1_1, BAD_REQUEST));
		return;
	}

	// Allow only GET methods.
	if (req.method() != GET) {
		sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HTTP_1_1, FORBIDDEN));
		return;
	}

	// Send the index page
	if ("/".equals(req.uri()) || "/index.html".equals(req.uri())) {
		String webSocketLocation = getWebSocketLocation(ctx.pipeline(), req, websocketPath);
		ByteBuf content = WatcherServerIndexPage.getContent(webSocketLocation);
		FullHttpResponse res = new DefaultFullHttpResponse(HTTP_1_1, OK, content);

		res.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/html; charset=UTF-8");
		HttpUtil.setContentLength(res, content.readableBytes());

		sendHttpResponse(ctx, req, res);
	} else {
		sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HTTP_1_1, NOT_FOUND));
	}
}
 
开发者ID:herowzz,项目名称:SimLogMonitor,代码行数:29,代码来源:WatcherServerIndexPageHandler.java

示例10: process

import io.netty.handler.codec.http.FullHttpRequest; //导入方法依赖的package包/类
@Override
protected boolean process(@NotNull ChannelHandlerContext context, @NotNull FullHttpRequest request, @NotNull QueryStringDecoder urlDecoder) throws IOException {
  if (handlers.isEmpty()) {
    // not yet initialized, for example, P2PTransport could add handlers after we bound.
    return false;
  }

  return request.method() == HttpMethod.POST && XmlRpcServer.SERVICE.getInstance().process(urlDecoder.path(), request, context, handlers);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:SubServer.java

示例11: decode

import io.netty.handler.codec.http.FullHttpRequest; //导入方法依赖的package包/类
@Override
protected void decode(ChannelHandlerContext ctx, FullHttpRequest request, List<Object> out) throws Exception {
	// Handle a bad request.
	if (!request.decoderResult().isSuccess()) {
		sendHttpResponse(ctx, request, new DefaultFullHttpResponse(HTTP_1_1, BAD_REQUEST));
		return;
	}
	if ("websocket".equalsIgnoreCase((String) request.headers().get("Upgrade"))) {
		handleWebSocket(ctx, request);
		return;
	}

	String queryStr = request.uri();
	if ("/favicon.ico".equals(queryStr)) {
		FullHttpResponse res = new DefaultFullHttpResponse(HTTP_1_1, NOT_FOUND);
		sendHttpResponse(ctx, request, res);
		return;
	}
	if (queryStr != null) {
		queryStr = queryStr.trim();
		if (queryStr.length() > 0 && queryStr.charAt(0) == '/') {
			if (queryStr.length() == 1) {
				queryStr = "";
			} else {
				int wh = queryStr.indexOf('?');
				if (wh > 0) {
					queryStr = queryStr.substring(wh + 1);
				} else {
					queryStr = queryStr.substring(1);
				}
			}
		}
	} else {
		queryStr = "";
	}
	HttpMethod method = request.method();
	logger.debug("decode queryStr ={}, method={}, msg={}", queryStr, method, request);
	if (directHandleMethod(ctx, request, method)) {
		return;
	}
	ByteBuf content;
	if (queryStr.length() == 0) {
		if (HttpMethod.GET.equals(method)) {
			handleHttpHomePage(ctx, request);
			return;
		}
		content = request.content().retain();
	} else {
		queryStr = URLDecoder.decode(queryStr, "UTF-8");
		int strLen = queryStr.length();
		if (queryStr.charAt(0) != '[' && strLen > 5) {
			boolean wordOrLetter = Character.isLetterOrDigit(queryStr.charAt(strLen - 1));
			for (int i = 2, MAX = Math.min(strLen, 7); i < MAX; i++) {
				char c = queryStr.charAt(strLen - i);
				if (c == '.') {
					if (wordOrLetter) {
						serverDef.httpResourceHandler.process(ctx, request, queryStr, strLen - i);
						return;
					}
					break;
				} else if (wordOrLetter && !Character.isLetterOrDigit(c)) {
					wordOrLetter = false;
				}
			}
		}
		byte[] bytes = queryStr.getBytes();
		// System.err.println("URI: bytes[0] = "+bytes[0]+", len =
		// "+bytes.length);
		content = ctx.alloc().buffer(bytes.length);
		content.writeBytes(bytes);
	}
	logger.debug("content.size = " + content.readableBytes());
	out.add(content);
	boolean alive = HttpHeaderUtil.isKeepAlive(request);
	Object event = alive ? thriftMessageWrapperKeepAlive : thriftMessageWrapperNormal;
	ctx.fireUserEventTriggered(event);
}
 
开发者ID:houkx,项目名称:nettythrift,代码行数:78,代码来源:HttpThriftBufDecoder.java

示例12: isValidRequest

import io.netty.handler.codec.http.FullHttpRequest; //导入方法依赖的package包/类
/**
 * Checks if is valid request.
 *
 * @param ctx the ctx
 * @param req the req
 * @return true, if is valid request
 */
public boolean isValidRequest(ChannelHandlerContext ctx, FullHttpRequest req) {
	// Handle a bad request.
	if (!req.decoderResult().isSuccess()) {
		sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HTTP_1_1, BAD_REQUEST));
		return false;
	}

	// Allow only GET methods.
	if (req.method() != GET) {
		sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HTTP_1_1, FORBIDDEN));
		return false;
	}

	if ("/favicon.ico".equals(req.uri())) {
		FullHttpResponse res = new DefaultFullHttpResponse(HTTP_1_1, NOT_FOUND);
		sendHttpResponse(ctx, req, res);
		return false;
	}	

	if(!req.uri().contains(Const.WEBSOCKET_URI)){
		sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HTTP_1_1, FORBIDDEN));
		return false;
	}
	
	if(server.getWebSocketCount() >= cfg.getMaxConnections()){
		LOG.log(Level.SEVERE,"Maximum number of websockets " + cfg.getMaxConnections() + " created.");
		sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HTTP_1_1, FORBIDDEN));
		return false;
	}


	String origin = req.headers().get(HttpHeaderNames.ORIGIN);
	if(origin!=null && !Config.getInstance().isAllowedOrigin(origin)){
		LOG.log(Level.SEVERE,"Invalid origin " + origin + " attempting to make websocket connection");
		sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HTTP_1_1, FORBIDDEN));
		return false;
	}

	return true;
}
 
开发者ID:mwambler,项目名称:xockets.io,代码行数:48,代码来源:WebSocketValidationHandler.java

示例13: isSupported

import io.netty.handler.codec.http.FullHttpRequest; //导入方法依赖的package包/类
public boolean isSupported(@NotNull FullHttpRequest request) {
  return request.method() == HttpMethod.GET || request.method() == HttpMethod.HEAD;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:4,代码来源:HttpRequestHandler.java

示例14: isSupported

import io.netty.handler.codec.http.FullHttpRequest; //导入方法依赖的package包/类
@Override
public boolean isSupported(@NotNull FullHttpRequest request) {
  return request.method() == HttpMethod.POST || request.method() == HttpMethod.OPTIONS;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:5,代码来源:XmlRpcServerImpl.java

示例15: isSupported

import io.netty.handler.codec.http.FullHttpRequest; //导入方法依赖的package包/类
@Override
public boolean isSupported(@NotNull FullHttpRequest request) {
  return request.method() == HttpMethod.GET &&
         "WebSocket".equalsIgnoreCase(request.headers().getAsString(HttpHeaderNames.UPGRADE)) &&
         request.uri().length() > 2;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:7,代码来源:WebSocketHandshakeHandler.java


注:本文中的io.netty.handler.codec.http.FullHttpRequest.method方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。