本文整理汇总了Java中org.jboss.netty.handler.codec.http.HttpMethod类的典型用法代码示例。如果您正苦于以下问题:Java HttpMethod类的具体用法?Java HttpMethod怎么用?Java HttpMethod使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HttpMethod类属于org.jboss.netty.handler.codec.http包,在下文中一共展示了HttpMethod类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: method
import org.jboss.netty.handler.codec.http.HttpMethod; //导入依赖的package包/类
@Override
public Method method() {
HttpMethod httpMethod = request.getMethod();
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: messageReceived
import org.jboss.netty.handler.codec.http.HttpMethod; //导入依赖的package包/类
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
try {
final HttpRequest req = (HttpRequest) e.getMessage();
if (req.getMethod().equals(HttpMethod.POST)) {
doPost(ctx, e, req);
} else if (req.getMethod().equals(HttpMethod.GET)) {
doGet(ctx, e, req);
} else {
writeResponseAndClose(e, new DefaultHttpResponse(
HttpVersion.HTTP_1_1,
HttpResponseStatus.BAD_REQUEST));
}
} catch (Exception ex) {
if (logger.isDebugEnabled())
logger.debug("Failed to process message", ex);
HttpResponse response = new DefaultHttpResponse(
HttpVersion.HTTP_1_1,
HttpResponseStatus.INTERNAL_SERVER_ERROR);
response.setContent(
ChannelBuffers.copiedBuffer(ex.getMessage().getBytes()));
writeResponseAndClose(e, response);
}
}
示例3: createMethod
import org.jboss.netty.handler.codec.http.HttpMethod; //导入依赖的package包/类
/**
* Creates the {@link HttpMethod} to use to call the remote server, often either its GET or POST.
*
* @param message the Camel message
* @return the created method
*/
public static HttpMethod createMethod(Message message, boolean hasPayload) {
// use header first
HttpMethod m = message.getHeader(Exchange.HTTP_METHOD, HttpMethod.class);
if (m != null) {
return m;
}
String name = message.getHeader(Exchange.HTTP_METHOD, String.class);
if (name != null) {
return HttpMethod.valueOf(name);
}
if (hasPayload) {
// use POST if we have payload
return HttpMethod.POST;
} else {
// fallback to GET
return HttpMethod.GET;
}
}
示例4: channelConnected
import org.jboss.netty.handler.codec.http.HttpMethod; //导入依赖的package包/类
@Override public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e)
throws Exception {
HttpRequest request =
new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, uri.toString());
request.addHeader(Names.ACCEPT, "text/event-stream");
if (headers != null) {
for (Map.Entry<String, String> entry : headers.entrySet()) {
request.addHeader(entry.getKey(), entry.getValue());
}
}
request.addHeader(Names.HOST, uri.getHost());
request.addHeader(Names.ORIGIN, uri.getScheme() + "://" + uri.getHost());
request.addHeader(Names.CACHE_CONTROL, "no-cache");
if (lastEventId != null) {
request.addHeader("Last-Event-ID", lastEventId);
}
e.getChannel().write(request);
channel = e.getChannel();
}
示例5: DefaultRtspRequest
import org.jboss.netty.handler.codec.http.HttpMethod; //导入依赖的package包/类
public DefaultRtspRequest(HttpMethod method, String uri) throws URISyntaxException {
super(RtspVersions.RTSP_1_0);
if (method == null) {
throw new NullPointerException("method");
}
if (uri == null) {
throw new NullPointerException("uri");
}
URI objUri = new URI(uri);
String scheme = objUri.getScheme() == null ? "rtsp" : objUri
.getScheme();
host = objUri.getHost() == null ? "localhost" : objUri.getHost();
port = objUri.getPort() == -1 ? 5454 : objUri.getPort();
if (!scheme.equalsIgnoreCase("rtsp")) {
throw new UnsupportedOperationException("Only rtsp is supported");
}
this.method = method;
this.uri = uri;
}
示例6: execute
import org.jboss.netty.handler.codec.http.HttpMethod; //导入依赖的package包/类
@Override
public void execute(final TSDB tsdb, final HttpRpcPluginQuery query) throws IOException {
// only accept GET/POST for now
if (query.request().getMethod() != HttpMethod.GET &&
query.request().getMethod() != HttpMethod.POST) {
throw new BadRequestException(HttpResponseStatus.METHOD_NOT_ALLOWED,
"Method not allowed", "The HTTP method [" + query.method().getName() +
"] is not permitted for this endpoint");
}
final String[] uri = query.explodePath();
final String endpoint = uri.length > 1 ? uri[2].toLowerCase() : "";
if ("version".equals(endpoint)) {
handleVersion(query);
} else if ("rate".equals(endpoint)) {
handleRate(query);
} else if ("namespace".equals(endpoint)) {
handlePerNamespaceStats(query);
} else if ("perthread".equals(endpoint)) {
handlePerThreadStats(query);
} else {
throw new BadRequestException(HttpResponseStatus.NOT_IMPLEMENTED,
"Hello. You have reached an API that has been disconnected. "
+ "Please call again.");
}
}
示例7: testDecode
import org.jboss.netty.handler.codec.http.HttpMethod; //导入依赖的package包/类
@Test
public void testDecode() throws Exception {
OwnTracksProtocolDecoder decoder = new OwnTracksProtocolDecoder(new OwnTracksProtocol());
verifyPosition(decoder, request(HttpMethod.POST, "/",
buffer("{\"lon\":2.29513,\"lat\":48.85833,\"tst\":1497349316,\"_type\":\"location\",\"tid\":\"JJ\"}")));
verifyPosition(decoder, request(HttpMethod.POST, "/",
buffer("{\"cog\":271,\"lon\":2.29513,\"acc\":5,\"vel\":61,\"vac\":21,\"lat\":48.85833,\"tst\":1497349316,\"alt\":167,\"_type\":\"location\",\"tid\":\"JJ\",\"t\":\"u\",\"batt\":67}")));
verifyPosition(decoder, request(HttpMethod.POST, "/",
buffer("{\"lat\":48.85,\"lon\":2.295,\"_type\":\"location\",\"tid\":\"JJ\",\"tst\":1497476456}")));
}
示例8: buildCorsConfig
import org.jboss.netty.handler.codec.http.HttpMethod; //导入依赖的package包/类
private CorsConfig buildCorsConfig(Settings settings) {
if (settings.getAsBoolean(SETTING_CORS_ENABLED, false) == false) {
return CorsConfigBuilder.forOrigins().disable().build();
}
String origin = settings.get(SETTING_CORS_ALLOW_ORIGIN);
final CorsConfigBuilder builder;
if (Strings.isNullOrEmpty(origin)) {
builder = CorsConfigBuilder.forOrigins();
} else if (origin.equals(ANY_ORIGIN)) {
builder = CorsConfigBuilder.forAnyOrigin();
} else {
Pattern p = RestUtils.checkCorsSettingForRegex(origin);
if (p == null) {
builder = CorsConfigBuilder.forOrigins(RestUtils.corsSettingAsArray(origin));
} else {
builder = CorsConfigBuilder.forPattern(p);
}
}
if (settings.getAsBoolean(SETTING_CORS_ALLOW_CREDENTIALS, false)) {
builder.allowCredentials();
}
String[] strMethods = settings.getAsArray(SETTING_CORS_ALLOW_METHODS, DEFAULT_CORS_METHODS);
HttpMethod[] methods = new HttpMethod[strMethods.length];
for (int i = 0; i < methods.length; i++) {
methods[i] = HttpMethod.valueOf(strMethods[i]);
}
return builder.allowedRequestMethods(methods)
.maxAge(settings.getAsInt(SETTING_CORS_MAX_AGE, DEFAULT_CORS_MAX_AGE))
.allowedRequestHeaders(settings.getAsArray(SETTING_CORS_ALLOW_HEADERS, DEFAULT_CORS_HEADERS))
.shortCircuit()
.build();
}
示例9: setAllowMethods
import org.jboss.netty.handler.codec.http.HttpMethod; //导入依赖的package包/类
private void setAllowMethods(final HttpResponse response) {
Set<String> strMethods = new HashSet<>();
for (HttpMethod method : config.allowedRequestMethods()) {
strMethods.add(method.getName().trim());
}
response.headers().set(ACCESS_CONTROL_ALLOW_METHODS, strMethods);
}
示例10: createMockHttpRequest
import org.jboss.netty.handler.codec.http.HttpMethod; //导入依赖的package包/类
public HttpRequest createMockHttpRequest() {
HttpRequest mockHttpRequest = Mockito.mock(HttpRequest.class);
Mockito.doReturn(HttpMethod.GET).when(mockHttpRequest).getMethod();
Mockito.doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
String uri = "/mapOutput?job=job_12345_1&reduce=1";
for (int i = 0; i < 100; i++)
uri = uri.concat("&map=attempt_12345_1_m_" + i + "_0");
return uri;
}
}).when(mockHttpRequest).getUri();
return mockHttpRequest;
}
示例11: testClone
import org.jboss.netty.handler.codec.http.HttpMethod; //导入依赖的package包/类
@Test
public void testClone() throws CloneNotSupportedException {
long st = System.nanoTime();
TestAction action = new TestAction();
ActionRequest req = new ActionRequest("", new DefaultHttpRequest(HttpVersion.HTTP_1_0, HttpMethod.POST, "aaa"));
ActionResponse res = new ActionResponse(null);
action.init(Type.xml, req, res, null);
for (int i = 0; i < count; i++) {
TestAction a2= (TestAction) action.clone();
}
printTime("Test Clone", st);
}
示例12: channelConnected
import org.jboss.netty.handler.codec.http.HttpMethod; //导入依赖的package包/类
@Override
public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
final String query = "/q?" + this.query.tsdbQueryParams();
logger.debug("Sending query " + query);
final DefaultHttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET,
query);
e.getChannel().write(req);
}
示例13: stats
import org.jboss.netty.handler.codec.http.HttpMethod; //导入依赖的package包/类
/**
* WebSocket invoker for OpenTSDB HTTP <a href="http://opentsdb.net/docs/build/html/api_http/stats.html">api/stats</a> API call
* @param request The JSONRequest
*/
@JSONRequestHandler(name="stats", description="Collects TSDB wide stats and returns them in JSON format to the caller")
public void stats(JSONRequest request) {
try {
HttpRequest httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/api/stats?json=true");
invoke(false, httpRequest, request.response(ResponseType.RESP));
} catch (Exception ex) {
log.error("Failed to invoke stats", ex);
request.error("Failed to invoke stats", ex).send();
}
}
示例14: file
import org.jboss.netty.handler.codec.http.HttpMethod; //导入依赖的package包/类
/**
* WebSocket invoker for OpenTSDB HTTP <a href="http://opentsdb.net/docs/build/html/api_http/s.html">/s</a> static file retrieval API call
* @param request The JSONRequest
*/
@JSONRequestHandler(name="s", description="Retrieves a static file")
public void file(JSONRequest request) {
try {
String fileName = request.getArgument("s").replace("\"", "");
HttpRequest httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, ("/s/" + fileName));
invokeForFile(httpRequest, request.response(ResponseType.RESP));
} catch (Exception ex) {
log.error("Failed to invoke s/file", ex);
request.error("Failed to invoke s/file", ex).send();
}
}
示例15: dropcaches
import org.jboss.netty.handler.codec.http.HttpMethod; //导入依赖的package包/类
/**
* WebSocket invoker for OpenTSDB HTTP <a href="http://opentsdb.net/docs/build/html/api_http/version.html">/s</a> OpenTSDB version info API call
* @param request The JSONRequest
*/
@JSONRequestHandler(name="dropcaches", description="Drops all OpenTSDB server caches")
public void dropcaches(JSONRequest request) {
try {
HttpRequest httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/api/dropcaches?json=true");
invoke(true, httpRequest, request.response(ResponseType.RESP));
} catch (Exception ex) {
log.error("Failed to invoke dropcaches", ex);
request.error("Failed to invoke dropcaches", ex).send();
}
}