本文整理汇总了Java中org.jboss.netty.handler.codec.http.HttpMethod.valueOf方法的典型用法代码示例。如果您正苦于以下问题:Java HttpMethod.valueOf方法的具体用法?Java HttpMethod.valueOf怎么用?Java HttpMethod.valueOf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jboss.netty.handler.codec.http.HttpMethod
的用法示例。
在下文中一共展示了HttpMethod.valueOf方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
}
示例2: 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();
}
示例3: createMessage
import org.jboss.netty.handler.codec.http.HttpMethod; //导入方法依赖的package包/类
@Override
protected HttpMessage createMessage(String[] initialLine) throws Exception {
WorksRequest httpRequest = new WorksRequest(HttpVersion.valueOf(initialLine[2]),
HttpMethod.valueOf(initialLine[0]), initialLine[1]);
return httpRequest;
}
示例4: encode
import org.jboss.netty.handler.codec.http.HttpMethod; //导入方法依赖的package包/类
@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg)
throws Exception
{
RestRequest request = (RestRequest) msg;
HttpMethod nettyMethod = HttpMethod.valueOf(request.getMethod());
URL url = new URL(request.getURI().toString());
String path = url.getFile();
// RFC 2616, section 5.1.2:
// Note that the absolute path cannot be empty; if none is present in the original URI,
// it MUST be given as "/" (the server root).
if (path.isEmpty())
{
path = "/";
}
HttpRequest nettyRequest =
new DefaultHttpRequest(HttpVersion.HTTP_1_1, nettyMethod, path);
nettyRequest.setHeader(HttpHeaders.Names.HOST, url.getAuthority());
for (Map.Entry<String, String> e : request.getHeaders().entrySet())
{
nettyRequest.setHeader(e.getKey(), e.getValue());
}
final ByteString entity = request.getEntity();
ChannelBuffer buf = ChannelBuffers.wrappedBuffer(entity.asByteBuffer());
nettyRequest.setContent(buf);
nettyRequest.setHeader(HttpHeaders.Names.CONTENT_LENGTH, entity.length());
return nettyRequest;
}
示例5: getMethod
import org.jboss.netty.handler.codec.http.HttpMethod; //导入方法依赖的package包/类
/**
* Returns the {@link HttpMethod} represented by the HTTP method header.
*/
public static HttpMethod getMethod(int spdyVersion, SpdyHeaderBlock block) {
try {
if (spdyVersion < 3) {
return HttpMethod.valueOf(block.getHeader(Spdy2HttpNames.METHOD));
} else {
return HttpMethod.valueOf(block.getHeader(HttpNames.METHOD));
}
} catch (Exception e) {
return null;
}
}
示例6: getMethod
import org.jboss.netty.handler.codec.http.HttpMethod; //导入方法依赖的package包/类
@JsonIgnore
public HttpMethod getMethod() {
return HttpMethod.valueOf(httpRequest.getMethod());
}