當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。