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