本文整理匯總了Java中io.netty.handler.codec.http.HttpMethod類的典型用法代碼示例。如果您正苦於以下問題:Java HttpMethod類的具體用法?Java HttpMethod怎麽用?Java HttpMethod使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
HttpMethod類屬於io.netty.handler.codec.http包,在下文中一共展示了HttpMethod類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import io.netty.handler.codec.http.HttpMethod; //導入依賴的package包/類
public static void main(String[] args) {
int loopTimes = 200;
class Runner implements Runnable{
private Logger logger = LoggerFactory.getLogger(Runner.class);
@Override
public void run() {
RouteResult<RenderType> result = RouterContext.getRouteResult(HttpMethod.GET,"/user/info");
logger.info("routeResult={},currentThread={}",result,Thread.currentThread().getName());
}
}
for(int i=0;i<loopTimes;i++){
new Thread(new Runner()).start();
}
}
示例2: allowedMethods
import io.netty.handler.codec.http.HttpMethod; //導入依賴的package包/類
/**
* Returns allowed methods for a specific URI.
* <p>
* For {@code OPTIONS *}, use {@link #allAllowedMethods()} instead of this method.
*/
public Set<HttpMethod> allowedMethods(String uri) {
QueryStringDecoder decoder = new QueryStringDecoder(uri);
String[] tokens = PathPattern.removeSlashesAtBothEnds(decoder.path()).split("/");
if (anyMethodRouter.anyMatched(tokens)) {
return allAllowedMethods();
}
Set<HttpMethod> ret = new HashSet<HttpMethod>(routers.size());
for (Entry<HttpMethod, MethodlessRouter<T>> entry : routers.entrySet()) {
MethodlessRouter<T> router = entry.getValue();
if (router.anyMatched(tokens)) {
HttpMethod method = entry.getKey();
ret.add(method);
}
}
return ret;
}
示例3: uri
import io.netty.handler.codec.http.HttpMethod; //導入依賴的package包/類
/**
* Given a target and params, this method tries to do the reverse routing
* and returns the URI.
*
* <p>Placeholders in the path pattern will be filled with the params.
* The params can be a map of {@code placeholder name -> value}
* or ordered values.
*
* <p>If a param doesn't have a corresponding placeholder, it will be put
* to the query part of the result URI.
*
* @return {@code null} if there's no match
*/
public String uri(HttpMethod method, T target, Object... params) {
MethodlessRouter<T> router = (method == null) ? anyMethodRouter : routers.get(method);
// Fallback to anyMethodRouter if no router is found for the method
if (router == null) {
router = anyMethodRouter;
}
String ret = router.uri(target, params);
if (ret != null) {
return ret;
}
// Fallback to anyMethodRouter if the router was not anyMethodRouter and no path is found
return (router != anyMethodRouter) ? anyMethodRouter.uri(target, params) : null;
}
示例4: doQuery
import io.netty.handler.codec.http.HttpMethod; //導入依賴的package包/類
public Observable<DocumentServiceResponse> doQuery(RxDocumentServiceRequest request) {
request.getHeaders().put(HttpConstants.HttpHeaders.IS_QUERY, "true");
switch (this.queryCompatibilityMode) {
case SqlQuery:
request.getHeaders().put(HttpConstants.HttpHeaders.CONTENT_TYPE,
RuntimeConstants.MediaTypes.SQL);
break;
case Default:
case Query:
default:
request.getHeaders().put(HttpConstants.HttpHeaders.CONTENT_TYPE,
RuntimeConstants.MediaTypes.QUERY_JSON);
break;
}
return this.performRequest(request, HttpMethod.POST);
}
示例5: makeHandler
import io.netty.handler.codec.http.HttpMethod; //導入依賴的package包/類
@Override
public RequestHandler makeHandler(HttpServerRequest<ByteBuf> request) {
HttpMethod method = request.getHttpMethod();
TusRequest tusRequest = new RxNettyTusRequestAdapter(request);
if (method.equals(HttpMethod.OPTIONS)) {
return new OptionHandler(options, tusRequest);
}
if (method.equals(HttpMethod.POST)) {
return new PostHandler(options, tusRequest, pool);
}
if (method.equals(HttpMethod.HEAD)) {
return new HeadHandler(options, tusRequest, pool);
}
if (method.equals(HttpMethod.PATCH)) {
return new PatchHandler(options, tusRequest, pool);
}
return new NotImplementedHandler();
}
示例6: shouldHandlerRequestAndResponse
import io.netty.handler.codec.http.HttpMethod; //導入依賴的package包/類
@Test
public void shouldHandlerRequestAndResponse() {
inboundChannel.pipeline().addLast(handler);
DefaultFullHttpRequest req = new DefaultFullHttpRequest(
HttpVersion.HTTP_1_1, HttpMethod.GET, "/");
inboundChannel.write(req);
assertEquals(1, inboundChannel.outboundMessages().size());
Object outboundReq = inboundChannel.outboundMessages().poll();
assertTrue(outboundReq instanceof ByteBuf);
assertEquals("GET / HTTP/1.1\r\n\r\n", new String(readBytes((ByteBuf) outboundReq)));
DefaultFullHttpResponse resp = new DefaultFullHttpResponse(
HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
assertFalse(inboundChannel.writeInbound(resp));
assertEquals(1, outboundChannel.outboundMessages().size());
assertEquals(resp, outboundChannel.outboundMessages().poll());
resp.release();
}
示例7: shouldPendingRequests
import io.netty.handler.codec.http.HttpMethod; //導入依賴的package包/類
@Test
public void shouldPendingRequests() {
inboundChannel.pipeline().addLast(handler);
DefaultFullHttpRequest req = new DefaultFullHttpRequest(
HttpVersion.HTTP_1_1, HttpMethod.GET, "/");
// First request
inboundChannel.write(req.retain());
assertEquals(1, inboundChannel.outboundMessages().size());
assertTrue(inboundChannel.outboundMessages().poll() instanceof ByteBuf);
// Second request
inboundChannel.write(req);
// Should pending second request
assertTrue(inboundChannel.outboundMessages().isEmpty());
}
示例8: handle
import io.netty.handler.codec.http.HttpMethod; //導入依賴的package包/類
public void handle(ChannelHandlerContext ctx, HttpRequest req)
throws IOException, URISyntaxException {
String op = params.op();
HttpMethod method = req.getMethod();
if (PutOpParam.Op.CREATE.name().equalsIgnoreCase(op)
&& method == PUT) {
onCreate(ctx);
} else if (PostOpParam.Op.APPEND.name().equalsIgnoreCase(op)
&& method == POST) {
onAppend(ctx);
} else if (GetOpParam.Op.OPEN.name().equalsIgnoreCase(op)
&& method == GET) {
onOpen(ctx);
} else if(GetOpParam.Op.GETFILECHECKSUM.name().equalsIgnoreCase(op)
&& method == GET) {
onGetFileChecksum(ctx);
} else {
throw new IllegalArgumentException("Invalid operation " + op);
}
}
示例9: computeAccessSignature
import io.netty.handler.codec.http.HttpMethod; //導入依賴的package包/類
private String computeAccessSignature(String timestamp, HttpMethod method, String urlTxt, ByteBuffer body)
throws GeneralSecurityException {
if (conn == null) {
throw new IllegalStateException("cannot generate exchange request post-disconnect()");
}
String prehash = timestamp + method.name() + urlTxt;
Mac mac = Mac.getInstance("HmacSHA256");
mac.init(signingKey);
mac.update(prehash.getBytes());
if (body != null) {
mac.update(body);
}
return new String(Base64.encodeBase64(mac.doFinal()));
}
示例10: testCorsConfig
import io.netty.handler.codec.http.HttpMethod; //導入依賴的package包/類
public void testCorsConfig() {
final Set<String> methods = new HashSet<>(Arrays.asList("get", "options", "post"));
final Set<String> headers = new HashSet<>(Arrays.asList("Content-Type", "Content-Length"));
final String prefix = randomBoolean() ? " " : ""; // sometimes have a leading whitespace between comma delimited elements
final Settings settings = Settings.builder()
.put(SETTING_CORS_ENABLED.getKey(), true)
.put(SETTING_CORS_ALLOW_ORIGIN.getKey(), "*")
.put(SETTING_CORS_ALLOW_METHODS.getKey(), collectionToDelimitedString(methods, ",", prefix, ""))
.put(SETTING_CORS_ALLOW_HEADERS.getKey(), collectionToDelimitedString(headers, ",", prefix, ""))
.put(SETTING_CORS_ALLOW_CREDENTIALS.getKey(), true)
.build();
final Netty4CorsConfig corsConfig = Netty4HttpServerTransport.buildCorsConfig(settings);
assertTrue(corsConfig.isAnyOriginSupported());
assertEquals(headers, corsConfig.allowedRequestHeaders());
assertEquals(methods, corsConfig.allowedRequestMethods().stream().map(HttpMethod::name).collect(Collectors.toSet()));
}
示例11: testReleaseOnSendToClosedChannel
import io.netty.handler.codec.http.HttpMethod; //導入依賴的package包/類
public void testReleaseOnSendToClosedChannel() {
final Settings settings = Settings.builder().build();
final NamedXContentRegistry registry = xContentRegistry();
try (Netty4HttpServerTransport httpServerTransport =
new Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, registry, new NullDispatcher())) {
final FullHttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/");
final EmbeddedChannel embeddedChannel = new EmbeddedChannel();
final Netty4HttpRequest request = new Netty4HttpRequest(registry, httpRequest, embeddedChannel);
final HttpPipelinedRequest pipelinedRequest = randomBoolean() ? new HttpPipelinedRequest(request.request(), 1) : null;
final Netty4HttpChannel channel =
new Netty4HttpChannel(httpServerTransport, request, pipelinedRequest, randomBoolean(), threadPool.getThreadContext());
final TestResponse response = new TestResponse(bigArrays);
assertThat(response.content(), instanceOf(Releasable.class));
embeddedChannel.close();
channel.sendResponse(response);
// ESTestCase#after will invoke ensureAllArraysAreReleased which will fail if the response content was not released
}
}
示例12: executeRequest
import io.netty.handler.codec.http.HttpMethod; //導入依賴的package包/類
private FullHttpResponse executeRequest(final Settings settings, final String originValue, final String host) {
// construct request and send it over the transport layer
try (Netty4HttpServerTransport httpServerTransport =
new Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, xContentRegistry(),
new NullDispatcher())) {
httpServerTransport.start();
final FullHttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/");
if (originValue != null) {
httpRequest.headers().add(HttpHeaderNames.ORIGIN, originValue);
}
httpRequest.headers().add(HttpHeaderNames.HOST, host);
final WriteCapturingChannel writeCapturingChannel = new WriteCapturingChannel();
final Netty4HttpRequest request = new Netty4HttpRequest(xContentRegistry(), httpRequest, writeCapturingChannel);
Netty4HttpChannel channel =
new Netty4HttpChannel(httpServerTransport, request, null, randomBoolean(), threadPool.getThreadContext());
channel.sendResponse(new TestResponse());
// get the response
List<Object> writtenObjects = writeCapturingChannel.getWrittenObjects();
assertThat(writtenObjects.size(), is(1));
return (FullHttpResponse) writtenObjects.get(0);
}
}
示例13: sendRequest
import io.netty.handler.codec.http.HttpMethod; //導入依賴的package包/類
private void sendRequest(HttpUrl url) {
start = System.nanoTime();
total = 0;
HttpRequest request = new DefaultFullHttpRequest(
HttpVersion.HTTP_1_1, HttpMethod.GET, url.encodedPath());
request.headers().set(HttpHeaders.Names.HOST, url.host());
request.headers().set(HttpHeaders.Names.ACCEPT_ENCODING, HttpHeaders.Values.GZIP);
channel.writeAndFlush(request);
}
示例14: ifConnectSuccess
import io.netty.handler.codec.http.HttpMethod; //導入依賴的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;
}
示例15: getMethodlessRouter
import io.netty.handler.codec.http.HttpMethod; //導入依賴的package包/類
private MethodlessRouter<T> getMethodlessRouter(HttpMethod method) {
if (method == null) {
return anyMethodRouter;
}
MethodlessRouter<T> r = routers.get(method);
if (r == null) {
r = new MethodlessRouter<T>();
routers.put(method, r);
}
return r;
}