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