org.jboss.netty.handler.codec.http.HttpRequest.getMethod()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(10.6k)|赞(0)|评价(0)|浏览(114)

本文整理了Java中org.jboss.netty.handler.codec.http.HttpRequest.getMethod()方法的一些代码示例,展示了HttpRequest.getMethod()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpRequest.getMethod()方法的具体详情如下:
包路径:org.jboss.netty.handler.codec.http.HttpRequest
类名称:HttpRequest
方法名:getMethod

HttpRequest.getMethod介绍

[英]Returns the method of this request.
[中]返回此请求的方法。

代码示例

代码示例来源:origin: io.netty/netty

@Override
  protected Object encode(ChannelHandlerContext ctx, Channel channel,
      Object msg) throws Exception {
    if (msg instanceof HttpRequest && !done) {
      queue.offer(((HttpRequest) msg).getMethod());
    }
    Object obj =  super.encode(ctx, channel, msg);
    if (failOnMissingResponse) {
      // check if the request is chunked if so do not increment
      if (msg instanceof HttpRequest && !((HttpRequest) msg).isChunked()) {
        requestResponseCounter.incrementAndGet();
      } else if (msg instanceof HttpChunk && ((HttpChunk) msg).isLast()) {
        // increment as its the last chunk
        requestResponseCounter.incrementAndGet();
      }
    }
    return obj;
  }
}

代码示例来源:origin: io.netty/netty

throw new NullPointerException("charset");
HttpMethod method = request.getMethod();
if (!(method.equals(HttpMethod.POST) || method.equals(HttpMethod.PUT) || method.equals(HttpMethod.PATCH))) {
  throw new ErrorDataEncoderException("Cannot create a Encoder if not a POST");

代码示例来源:origin: voldemort/voldemort

} else {
  HttpMethod httpMethod = request.getMethod();
  if(httpMethod.equals(HttpMethod.GET)) {
    if(logger.isDebugEnabled()) {

代码示例来源:origin: io.netty/netty

@Override
protected void encodeInitialLine(ChannelBuffer buf, HttpMessage message) throws Exception {
  HttpRequest request = (HttpRequest) message;
  buf.writeBytes(request.getMethod().toString().getBytes("ASCII"));
  buf.writeByte(SP);

代码示例来源:origin: io.netty/netty

@Override
  protected void encodeInitialLine(ChannelBuffer buf, HttpMessage message)
      throws Exception {
    HttpRequest request = (HttpRequest) message;
    buf.writeBytes(request.getMethod().toString().getBytes("ASCII"));
    buf.writeByte((byte) ' ');
    buf.writeBytes(request.getUri().getBytes("UTF-8"));
    buf.writeByte((byte) ' ');
    buf.writeBytes(request.getProtocolVersion().toString().getBytes("ASCII"));
    buf.writeByte((byte) '\r');
    buf.writeByte((byte) '\n');
  }
}

代码示例来源:origin: voldemort/voldemort

storeList = Lists.newArrayList(storeArray);
HttpMethod httpMethod = request.getMethod();
if(httpMethod.equals(HttpMethod.GET)) {
  response = handleGet(storeList);

代码示例来源:origin: apache/hive

throws Exception {
HttpRequest request = (HttpRequest) evt.getMessage();
if (request.getMethod() != GET) {
  sendError(ctx, METHOD_NOT_ALLOWED);
  return;

代码示例来源:origin: io.netty/netty

/**
 * Returns the content length of the specified web socket message.  If the
 * specified message is not a web socket message, {@code -1} is returned.
 */
private static int getWebSocketContentLength(HttpMessage message) {
  // WebSockset messages have constant content-lengths.
  HttpHeaders h = message.headers();
  if (message instanceof HttpRequest) {
    HttpRequest req = (HttpRequest) message;
    if (HttpMethod.GET.equals(req.getMethod()) &&
      h.contains(Names.SEC_WEBSOCKET_KEY1) &&
      h.contains(Names.SEC_WEBSOCKET_KEY2)) {
      return 8;
    }
  } else if (message instanceof HttpResponse) {
    HttpResponse res = (HttpResponse) message;
    if (res.getStatus().getCode() == 101 &&
      h.contains(Names.SEC_WEBSOCKET_ORIGIN) &&
      h.contains(Names.SEC_WEBSOCKET_LOCATION)) {
      return 16;
    }
  }
  // Not a web socket message
  return -1;
}

代码示例来源:origin: io.netty/netty

@Override
public void messageReceived(final ChannelHandlerContext ctx, MessageEvent e) throws Exception {
  if (e.getMessage() instanceof HttpRequest) {
    HttpRequest req = (HttpRequest) e.getMessage();
    if (req.getMethod() != GET) {
      sendHttpResponse(ctx, req, new DefaultHttpResponse(HTTP_1_1, FORBIDDEN));
      return;
    }
    final WebSocketServerHandshakerFactory wsFactory = new WebSocketServerHandshakerFactory(
        getWebSocketLocation(ctx.getPipeline(), req, websocketPath), subprotocols, allowExtensions);
    final WebSocketServerHandshaker handshaker = wsFactory.newHandshaker(req);
    if (handshaker == null) {
      wsFactory.sendUnsupportedWebSocketVersionResponse(ctx.getChannel());
    } else {
      final ChannelFuture handshakeFuture = handshaker.handshake(ctx.getChannel(), req);
      handshakeFuture.addListener(new ChannelFutureListener() {
        public void operationComplete(ChannelFuture future) throws Exception {
          if (!future.isSuccess()) {
            Channels.fireExceptionCaught(ctx, future.getCause());
          }
        }
      });
      WebSocketServerProtocolHandler.setHandshaker(ctx, handshaker);
      ctx.getPipeline().replace(this, "WS403Responder",
      WebSocketServerProtocolHandler.forbiddenHttpRequestResponder());
    }
  }
}

代码示例来源:origin: webbit/webbit

@Override
public String method() {
  return httpRequest.getMethod().getName();
}

代码示例来源:origin: webbit/webbit

@Override
  public String toString() {
    return messageEvent.getRemoteAddress() + " " + httpRequest.getMethod() + " " + httpRequest.getUri();
  }
}

代码示例来源:origin: io.netty/netty

SpdyHeaders.setMethod(spdyVersion, spdySynStreamFrame, httpRequest.getMethod());
SpdyHeaders.setUrl(spdyVersion, spdySynStreamFrame, httpRequest.getUri());
SpdyHeaders.setVersion(spdyVersion, spdySynStreamFrame, httpMessage.getProtocolVersion());

代码示例来源:origin: com.ning/async-http-client

future.getNettyRequest().getHttpRequest().getMethod(),
future.getNettyRequest().getHttpRequest().getUri());

代码示例来源:origin: com.ning/async-http-client

public <T> ListenableFuture<T> sendRequest(final Request request,//
    final AsyncHandler<T> asyncHandler,//
    NettyResponseFuture<T> future,//
    boolean reclaimCache) throws IOException {
  if (closed.get())
    throw new IOException("Closed");
  Uri uri = request.getUri();
  validateWebSocketRequest(request, uri, asyncHandler);
  ProxyServer proxyServer = getProxyServer(config, request);
  boolean resultOfAConnect = future != null && future.getNettyRequest() != null
      && future.getNettyRequest().getHttpRequest().getMethod() == HttpMethod.CONNECT;
  boolean useProxy = proxyServer != null && !resultOfAConnect;
  if (useProxy && useProxyConnect(uri))
    // SSL proxy, have to handle CONNECT
    if (future != null && future.isConnectAllowed())
      // CONNECT forced
      return sendRequestWithCertainForceConnect(request, asyncHandler, future, reclaimCache, uri, proxyServer, true, true);
    else
      return sendRequestThroughSslProxy(request, asyncHandler, future, reclaimCache, uri, proxyServer);
  else
    return sendRequestWithCertainForceConnect(request, asyncHandler, future, reclaimCache, uri, proxyServer, useProxy, false);
}

代码示例来源:origin: com.ning/async-http-client

private void writeRequest(Channel channel) {
  LOGGER.debug("Using non-cached Channel {} for {} '{}'",
      channel,
      future.getNettyRequest().getHttpRequest().getMethod(),
      future.getNettyRequest().getHttpRequest().getUri());
  Channels.setAttribute(channel, future);
  if (future.isDone()) {
    abortChannelPreemption();
    return;
  }
  if (future.getAsyncHandler() instanceof AsyncHandlerExtensions)
    AsyncHandlerExtensions.class.cast(future.getAsyncHandler()).onConnectionOpen();
  channelManager.registerOpenChannel(channel, partitionKey);
  future.attachChannel(channel, false);
  requestSender.writeRequest(future, channel);
}

代码示例来源:origin: resteasy/Resteasy

@Override
protected Object decode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception
{
 if (!(msg instanceof org.jboss.netty.handler.codec.http.HttpRequest))
 {
   return msg;
 }
 org.jboss.netty.handler.codec.http.HttpRequest request = (org.jboss.netty.handler.codec.http.HttpRequest) msg;
 boolean keepAlive = org.jboss.netty.handler.codec.http.HttpHeaders.isKeepAlive(request) & isKeepAlive;
 NettyHttpResponse response = new NettyHttpResponse(channel, keepAlive, request.getMethod());
 ResteasyHttpHeaders headers = null;
 ResteasyUriInfo uriInfo = null;
 try
 {
   headers = NettyUtil.extractHttpHeaders(request);
   uriInfo = NettyUtil.extractUriInfo(request, servletMappingPrefix, proto);
   HttpRequest nettyRequest = new NettyHttpRequest(headers, uriInfo, request.getMethod().getName(), dispatcher, response, org.jboss.netty.handler.codec.http.HttpHeaders.is100ContinueExpected(request) );
   ChannelBufferInputStream is = new ChannelBufferInputStream(request.getContent());
   nettyRequest.setInputStream(is);
   return nettyRequest;
 }
 catch (Exception e)
 {
   response.sendError(400);
   // made it warn so that people can filter this.
   LogMessages.LOGGER.warn(Messages.MESSAGES.failedToParseRequest(), e);
   return null;
 }
}

代码示例来源:origin: com.ning/async-http-client

public <T> void writeRequest(NettyResponseFuture<T> future, Channel channel) {
  NettyRequest nettyRequest = future.getNettyRequest();
  HttpRequest httpRequest = nettyRequest.getHttpRequest();
  AsyncHandler<T> handler = future.getAsyncHandler();
  // if the channel is dead because it was pooled and the remote
  // server decided to close it,
  // we just let it go and the channelInactive do its work
  if (!Channels.isChannelValid(channel))
    return;
  try {
    if (handler instanceof TransferCompletionHandler)
      configureTransferAdapter(handler, httpRequest);
    if (!future.isHeadersAlreadyWrittenOnContinue()) {
      if (future.getAsyncHandler() instanceof AsyncHandlerExtensions)
        AsyncHandlerExtensions.class.cast(future.getAsyncHandler()).onSendRequest(nettyRequest);
      channel.write(httpRequest).addListener(new ProgressListener(config, future.getAsyncHandler(), future, true));
    }
    if (nettyRequest.getBody() != null && !future.isDontWriteBodyBecauseExpectContinue() && httpRequest.getMethod() != HttpMethod.CONNECT)
      nettyRequest.getBody().write(channel, future, config);
    // don't bother scheduling timeouts if channel became invalid
    if (Channels.isChannelValid(channel))
      scheduleTimeouts(future);
  } catch (Throwable t) {
    LOGGER.error("Can't write request", t);
    Channels.silentlyCloseChannel(channel);
  }
}

代码示例来源:origin: com.ning/async-http-client

private boolean exitAfterHandlingConnect(//
    final Channel channel,//
    final NettyResponseFuture<?> future,//
    final Request request,//
    ProxyServer proxyServer,//
    int statusCode,//
    HttpRequest httpRequest) throws IOException {
  if (statusCode == OK.getCode() && httpRequest.getMethod() == HttpMethod.CONNECT) {
    if (future.isKeepAlive())
      future.attachChannel(channel, true);
    try {
      Uri requestUri = request.getUri();
      String scheme = requestUri.getScheme();
      String host = requestUri.getHost();
      int port = getDefaultPort(requestUri);
      logger.debug("Connecting to proxy {} for scheme {}", proxyServer, scheme);
      channelManager.upgradeProtocol(channel.getPipeline(), scheme, host, port);
    } catch (Throwable ex) {
      requestSender.abort(channel, future, ex);
    }
    future.setReuseChannel(true);
    future.setConnectAllowed(false);
    requestSender.sendNextRequest(new RequestBuilder(future.getRequest()).build(), future);
    return true;
  }
  return false;
}

代码示例来源:origin: com.ning/async-http-client

boolean connect = future.getNettyRequest().getHttpRequest().getMethod() == HttpMethod.CONNECT;
requestFactory.addAuthorizationHeader(headers, perConnectionAuthorizationHeader(request, uri, proxy, realm));
requestFactory.setProxyAuthorizationHeader(headers, perConnectionProxyAuthorizationHeader(request, proxy, connect));

代码示例来源:origin: org.webbitserver/webbit

@Override
  public String toString() {
    return messageEvent.getRemoteAddress() + " " + httpRequest.getMethod() + " " + httpRequest.getUri();
  }
}

相关文章