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


Java HttpMethod.POST屬性代碼示例

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


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

示例1: method

@Override
public Method method() {
    HttpMethod httpMethod = request.method();
    if (httpMethod == HttpMethod.GET)
        return Method.GET;

    if (httpMethod == HttpMethod.POST)
        return Method.POST;

    if (httpMethod == HttpMethod.PUT)
        return Method.PUT;

    if (httpMethod == HttpMethod.DELETE)
        return Method.DELETE;

    if (httpMethod == HttpMethod.HEAD) {
        return Method.HEAD;
    }

    if (httpMethod == HttpMethod.OPTIONS) {
        return Method.OPTIONS;
    }

    return Method.GET;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:25,代碼來源:Netty4HttpRequest.java

示例2: testBasicAuthenticationFailure

@Test
public void testBasicAuthenticationFailure() throws Exception {
    Configuration config = TestConfiguration.createMinimalConfigurationForTest();

    BasicAuthLogin auth = new BasicAuthLogin();
    auth.setUsername("test");
    auth.setPassword("test2");
    DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/login");
    request.content().writeBytes(JsonSerializer.getObjectMapper().writeValueAsBytes(auth));

    TestHttpQueryDecoder decoder = new TestHttpQueryDecoder(config);
    decoder.decode(null, request, results);
    Assert.assertEquals(1, results.size());
    Object result = results.iterator().next();
    Assert.assertEquals(BasicAuthLoginRequest.class, result.getClass());

    BasicAuthLoginRequestHandler handler = new BasicAuthLoginRequestHandler(config);
    CaptureChannelHandlerContext ctx = new CaptureChannelHandlerContext();
    handler.channelRead(ctx, result);
    Assert.assertNotNull(ctx.msg);
    Assert.assertTrue(ctx.msg instanceof DefaultFullHttpResponse);
    DefaultFullHttpResponse response = (DefaultFullHttpResponse) ctx.msg;
    Assert.assertEquals(HttpResponseStatus.UNAUTHORIZED, response.getStatus());
    Assert.assertTrue(response.headers().contains(Names.CONTENT_TYPE));
    Assert.assertEquals(Constants.JSON_TYPE, response.headers().get(Names.CONTENT_TYPE));
}
 
開發者ID:NationalSecurityAgency,項目名稱:qonduit,代碼行數:26,代碼來源:BasicAuthLoginRequestHandlerTest.java

示例3: createHttpCarbonMessage

public HTTPCarbonMessage createHttpCarbonMessage(String method) {
    HTTPCarbonMessage httpCarbonMessage = null;
    switch (method) {
        case "GET": {
            httpCarbonMessage = new HTTPCarbonMessage(
                    new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, ""));
            break;
        }
        case "PUT": {
            httpCarbonMessage = new HTTPCarbonMessage(
                    new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PUT, ""));
            break;
        }
        case "PATCH": {
            httpCarbonMessage = new HTTPCarbonMessage(
                    new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PATCH, ""));
            break;
        }
        case "DELETE": {
            httpCarbonMessage = new HTTPCarbonMessage(
                    new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.DELETE, ""));
            break;
        }
        case "POST": {
            httpCarbonMessage = new HTTPCarbonMessage(
                    new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, ""));
            break;
        }
        default: {
            log.error("Invalid request type.");

            break;
        }
    }
    return httpCarbonMessage;
}
 
開發者ID:wso2-extensions,項目名稱:siddhi-io-http,代碼行數:36,代碼來源:HttpSink.java

示例4: testBasicAuthentication

@Test
public void testBasicAuthentication() throws Exception {
    Configuration config = TestConfiguration.createMinimalConfigurationForTest();

    BasicAuthLogin auth = new BasicAuthLogin();
    auth.setUsername("test");
    auth.setPassword("test1");
    DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/login");
    request.content().writeBytes(JsonSerializer.getObjectMapper().writeValueAsBytes(auth));

    TestHttpQueryDecoder decoder = new TestHttpQueryDecoder(config);
    decoder.decode(null, request, results);
    Assert.assertEquals(1, results.size());
    Object result = results.iterator().next();
    Assert.assertEquals(BasicAuthLoginRequest.class, result.getClass());

    BasicAuthLoginRequestHandler handler = new BasicAuthLoginRequestHandler(config);
    CaptureChannelHandlerContext ctx = new CaptureChannelHandlerContext();
    handler.channelRead(ctx, result);
    Assert.assertNotNull(ctx.msg);
    Assert.assertTrue(ctx.msg instanceof DefaultFullHttpResponse);
    DefaultFullHttpResponse response = (DefaultFullHttpResponse) ctx.msg;
    Assert.assertEquals(HttpResponseStatus.OK, response.getStatus());
    Assert.assertTrue(response.headers().contains(Names.CONTENT_TYPE));
    Assert.assertEquals(Constants.JSON_TYPE, response.headers().get(Names.CONTENT_TYPE));
    Assert.assertTrue(response.headers().contains(Names.SET_COOKIE));
    Cookie c = ClientCookieDecoder.STRICT.decode(response.headers().get(Names.SET_COOKIE));
    Assert.assertEquals(TestConfiguration.HTTP_ADDRESS_DEFAULT, c.domain());
    Assert.assertEquals(86400, c.maxAge());
    Assert.assertTrue(c.isHttpOnly());
    Assert.assertTrue(c.isSecure());
    Assert.assertEquals(Constants.COOKIE_NAME, c.name());
    UUID.fromString(c.value());
}
 
開發者ID:NationalSecurityAgency,項目名稱:qonduit,代碼行數:34,代碼來源:BasicAuthLoginRequestHandlerTest.java

示例5: testVersionPost

/**
 * Only /login requests are handled
 */
@Test(expected = QonduitException.class)
public void testVersionPost() throws Exception {
    decoder = new TestHttpQueryDecoder(config);
    DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/version");
    addCookie(request);
    decoder.decode(null, request, results);
    Assert.assertEquals(1, results.size());
    Assert.assertEquals("VersionRequest", results.iterator().next().getClass().getSimpleName());
}
 
開發者ID:NationalSecurityAgency,項目名稱:qonduit,代碼行數:12,代碼來源:HttpRequestDecoderTest.java

示例6: handleHttpRequest

protected void handleHttpRequest(ChannelHandlerContext ctx, FullHttpRequest req) throws Exception {
    // Handle a bad request.
    if (!req.getDecoderResult().isSuccess()) {
        httpFileHandler.sendError(ctx, HttpResponseStatus.BAD_REQUEST);
        return;
    }

    // If you're going to do normal HTTP POST authentication before upgrading the
    // WebSocket, the recommendation is to handle it right here
    if (req.getMethod() == HttpMethod.POST) {
        httpFileHandler.sendError(ctx, HttpResponseStatus.FORBIDDEN);
        return;
    }

    // Allow only GET methods.
    if (req.getMethod() != HttpMethod.GET) {
        httpFileHandler.sendError(ctx, HttpResponseStatus.FORBIDDEN);
        return;
    }

    // Send the demo page and favicon.ico
    if ("/".equals(req.getUri())) {
        httpFileHandler.sendRedirect(ctx, "/index.html");
        return;
    }

    // check for websocket upgrade request
    String upgradeHeader = req.headers().get("Upgrade");
    if (upgradeHeader != null && "websocket".equalsIgnoreCase(upgradeHeader)) {
        // Handshake. Ideally you'd want to configure your websocket uri
        String url = "ws://" + req.headers().get("Host") + "/marketdata";
        WebSocketServerHandshakerFactory wsFactory = new WebSocketServerHandshakerFactory(url, null, false);
        handshaker = wsFactory.newHandshaker(req);
        if (handshaker == null) {
            WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(ctx.channel());
        }
        else {
            handshaker.handshake(ctx.channel(), req);
        }
    }
    else {
        boolean handled = handleREST(ctx, req);
        if (!handled) {
            httpFileHandler.sendFile(ctx, req);
        }
    }
}
 
開發者ID:SpreadServe,項目名稱:TFWebSock,代碼行數:47,代碼來源:WebSocketHandler.java


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