本文整理了Java中io.netty.handler.codec.http.HttpRequest.getMethod()
方法的一些代码示例,展示了HttpRequest.getMethod()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpRequest.getMethod()
方法的具体详情如下:
包路径:io.netty.handler.codec.http.HttpRequest
类名称:HttpRequest
方法名:getMethod
暂无
代码示例来源:origin: apache/incubator-dubbo
if (request.getMethod() == HttpMethod.GET) {
if (queryStringDecoder.parameters().isEmpty()) {
commandContext = CommandContextFactory.newInstance(name);
} else if (request.getMethod() == HttpMethod.POST) {
HttpPostRequestDecoder httpPostRequestDecoder = new HttpPostRequestDecoder(request);
List<String> valueList = new ArrayList<String>();
代码示例来源:origin: apache/incubator-dubbo
if (request.getMethod() == HttpMethod.GET) {
if (queryStringDecoder.parameters().isEmpty()) {
commandContext = CommandContextFactory.newInstance(name);
} else if (request.getMethod() == HttpMethod.POST) {
HttpPostRequestDecoder httpPostRequestDecoder = new HttpPostRequestDecoder(request);
List<String> valueList = new ArrayList<String>();
代码示例来源:origin: kaaproject/kaa
LOG.trace("Session: {} got valid HTTP request:\n{}",
sessionUuidAttr.get().toString(), httpRequest.headers().toString());
if (httpRequest.getMethod().equals(HttpMethod.POST)) {
String uri = httpRequest.getUri();
AbstractCommand cp = (AbstractCommand) commandFactory.getCommandProcessor(uri);
LOG.error("Got invalid HTTP method: expecting only POST");
throw new BadRequestException(
"Incorrect method " + httpRequest.getMethod().toString() + ", expected POST"
);
代码示例来源:origin: JZ-Darkal/AndroidHttpCapture
protected void captureRequestHeaderSize(HttpRequest httpRequest) {
String requestLine = httpRequest.getMethod().toString() + ' ' + httpRequest.getUri() + ' ' + httpRequest.getProtocolVersion().toString();
// +2 => CRLF after status line, +4 => header/data separation
long requestHeadersSize = requestLine.length() + 6;
HttpHeaders headers = httpRequest.headers();
requestHeadersSize += BrowserMobHttpUtil.getHeaderSize(headers);
harEntry.getRequest().setHeadersSize(requestHeadersSize);
}
代码示例来源:origin: JZ-Darkal/AndroidHttpCapture
/**
* Creates a new {@link HarRequest} object for this failed HTTP CONNECT. Does not populate fields within the request,
* such as the error message.
*
* @param httpConnectRequest the HTTP CONNECT request that failed
* @return a new HAR request object
*/
private HarRequest createRequestForFailedConnect(HttpRequest httpConnectRequest) {
String url = getFullUrl(httpConnectRequest);
return new HarRequest(httpConnectRequest.getMethod().toString(), url, httpConnectRequest.getProtocolVersion().text());
}
代码示例来源:origin: JZ-Darkal/AndroidHttpCapture
@Override
public HttpResponse clientToProxyRequest(HttpObject httpObject) {
if (httpObject instanceof HttpRequest) {
HttpRequest httpRequest = (HttpRequest) httpObject;
String url = getFullUrl(httpRequest);
for (BlacklistEntry entry : blacklistedUrls) {
if (HttpMethod.CONNECT.equals(httpRequest.getMethod()) && entry.getHttpMethodPattern() == null) {
// do not allow CONNECTs to be blacklisted unless a method pattern is explicitly specified
continue;
}
if (entry.matches(url, httpRequest.getMethod().name())) {
HttpResponseStatus status = HttpResponseStatus.valueOf(entry.getStatusCode());
HttpResponse resp = new DefaultFullHttpResponse(httpRequest.getProtocolVersion(), status);
HttpHeaders.setContentLength(resp, 0L);
return resp;
}
}
}
return null;
}
}
代码示例来源:origin: JZ-Darkal/AndroidHttpCapture
/**
* Creates a HarRequest object using the method, url, and HTTP version of the specified request.
*
* @param httpRequest HTTP request on which the HarRequest will be based
* @return a new HarRequest object
*/
private HarRequest createHarRequestForHttpRequest(HttpRequest httpRequest) {
// the HAR spec defines the request.url field as:
// url [string] - Absolute URL of the request (fragments are not included).
// the URI on the httpRequest may only identify the path of the resource, so find the full URL.
// the full URL consists of the scheme + host + port (if non-standard) + path + query params + fragment.
String url = getFullUrl(httpRequest);
return new HarRequest(httpRequest.getMethod().toString(), url, httpRequest.getProtocolVersion().text());
}
代码示例来源:origin: org.apache.hadoop/hadoop-hdfs
@Override
public String getMethod() {
return req.getMethod().name();
}
代码示例来源:origin: linkedin/flashback
public void interpretHttpRequest(HttpRequest nettyHttpRequest) {
_httpMethod = nettyHttpRequest.getMethod().toString();
try {
URI uri = new URI(nettyHttpRequest.getUri());
if (uri.isAbsolute()) {
_uri = uri;
} else {
String hostName = nettyHttpRequest.headers().get(HttpHeaders.Names.HOST);
if (!Strings.isNullOrEmpty(hostName)) {
_uri = new URI(String.format("https://%s%s", hostName, uri));
} else {
_path = uri.toString();
}
}
} catch (URISyntaxException e) {
throw new IllegalStateException("Invalid URI in underlying request", e);
}
}
代码示例来源:origin: org.apache.hadoop/hadoop-hdfs
@Override
public void operationComplete(ChannelFuture future) throws Exception {
if (future.isSuccess()) {
ctx.channel().pipeline().remove(HttpResponseEncoder.class);
HttpRequest newReq = new DefaultFullHttpRequest(HTTP_1_1,
req.getMethod(), req.getUri());
newReq.headers().add(req.headers());
newReq.headers().set(CONNECTION, Values.CLOSE);
future.channel().writeAndFlush(newReq);
} else {
DefaultHttpResponse resp = new DefaultHttpResponse(HTTP_1_1,
INTERNAL_SERVER_ERROR);
resp.headers().set(CONNECTION, Values.CLOSE);
LOG.info("Proxy " + uri + " failed. Cause: ", future.cause());
ctx.writeAndFlush(resp).addListener(ChannelFutureListener.CLOSE);
client.close();
}
}
});
代码示例来源:origin: org.apache.hadoop/hadoop-hdfs
@Override
public Void run() throws Exception {
try {
handle(ctx, req);
} finally {
String host = null;
try {
host = ((InetSocketAddress)ctx.channel().remoteAddress()).
getAddress().getHostAddress();
} catch (Exception e) {
LOG.warn("Error retrieving hostname: ", e);
host = "unknown";
}
REQLOG.info(host + " " + req.getMethod() + " " + req.getUri() + " " +
getResponseCode());
}
return null;
}
});
代码示例来源:origin: adyliu/jafka
args = new HashMap<String, String>(4);
if (request.getMethod() != HttpMethod.POST) {
sendStatusMessage(ctx, HttpResponseStatus.METHOD_NOT_ALLOWED, "POST METHOD REQUIRED");
return;
代码示例来源:origin: rackerlabs/blueflood
public void trackResponse(HttpRequest request, FullHttpResponse response) {
// check if tenantId is being tracked by JMX TenantTrackerMBean and log the response if it is
// HttpRequest is needed for original request uri and tenantId
if (request == null) return;
if (response == null) return;
String tenantId = findTid( request.getUri() );
if (isTracking(tenantId)) {
HttpResponseStatus status = response.getStatus();
String messageBody = response.content().toString(Constants.DEFAULT_CHARSET);
// get parameters
String queryParams = getQueryParameters(request);
// get headers
String headers = "";
for (String headerName : response.headers().names()) {
headers += "\n" + headerName + "\t" + response.headers().get(headerName);
}
// get response content
String responseContent = "";
if ((messageBody != null) && (!messageBody.isEmpty())) {
responseContent = "\nRESPONSE_CONTENT:\n" + messageBody;
}
String logMessage = "[TRACKER] " +
"Response for tenantId " + tenantId + " " + request.getMethod() + " request " + request.getUri() + queryParams +
"\nRESPONSE_STATUS: " + status.code() +
"\nRESPONSE HEADERS: " + headers +
responseContent;
log.info(logMessage);
}
}
代码示例来源:origin: rackerlabs/blueflood
request.getMethod() + " request for tenantId " + tenantId + ": " + request.getUri() + queryParams + "\n" +
"HEADERS: " + headers +
requestContent;
代码示例来源:origin: linkedin/flashback
public static ChannelHandlerDelegate create(HttpRequest httpRequest, ChannelMediator channelMediator,
Map<Protocol, List<ConnectionFlowStep>> connectionFlowRegistry) {
if (HttpMethod.CONNECT.equals(httpRequest.getMethod())) {
List<ConnectionFlowStep> connectionFlow = connectionFlowRegistry.get(Protocol.HTTPS);
ConnectionFlowProcessor httpsConnectionFlowProcessor =
new ConnectionFlowProcessor(channelMediator, httpRequest, connectionFlow);
channelMediator.initializeProxyModeController(httpRequest);
return new HttpsChannelHandlerDelegate(channelMediator, httpsConnectionFlowProcessor);
} else {
List<ConnectionFlowStep> connectionFlow = connectionFlowRegistry.get(Protocol.HTTP);
ConnectionFlowProcessor httpConnectionFlowProcessor =
new ConnectionFlowProcessor(channelMediator, httpRequest, connectionFlow);
channelMediator.initializeProxyModeController(httpRequest);
return new HttpChannelHandlerDelegate(channelMediator, httpConnectionFlowProcessor);
}
}
代码示例来源:origin: org.apache.hadoop/hadoop-hdfs
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 if(PutOpParam.Op.CREATE.name().equalsIgnoreCase(op)
&& method == OPTIONS) {
allowCORSOnCreate(ctx);
} else {
throw new IllegalArgumentException("Invalid operation " + op);
}
}
代码示例来源:origin: jwpttcg66/NettyGameServer
if (request.getMethod() != HttpMethod.POST) {
throw new IllegalStateException("请求不是GET请求.");
代码示例来源:origin: apache/cloudstack
responseContent.setLength(0);
if (request.getMethod().equals(HttpMethod.POST)) {
代码示例来源:origin: org.apache.hadoop/hadoop-hdfs
@Override
public void channelRead0(ChannelHandlerContext ctx, HttpRequest request)
throws Exception {
if (request.getMethod() != HttpMethod.GET) {
DefaultHttpResponse resp = new DefaultHttpResponse(HTTP_1_1,
METHOD_NOT_ALLOWED);
代码示例来源:origin: apache/cxf
public void requestReceivedFromClient(FlowContext flowContext,
HttpRequest httpRequest) {
if (httpRequest.getMethod() != HttpMethod.CONNECT) {
count.incrementAndGet();
}
}
内容来源于网络,如有侵权,请联系作者删除!