本文整理汇总了Java中org.jboss.netty.handler.codec.http.HttpResponse.getHeaders方法的典型用法代码示例。如果您正苦于以下问题:Java HttpResponse.getHeaders方法的具体用法?Java HttpResponse.getHeaders怎么用?Java HttpResponse.getHeaders使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jboss.netty.handler.codec.http.HttpResponse
的用法示例。
在下文中一共展示了HttpResponse.getHeaders方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decode
import org.jboss.netty.handler.codec.http.HttpResponse; //导入方法依赖的package包/类
@Override
protected Object decode(ChannelHandlerContext ctx, Channel channel, Object msg)
throws Exception
{
HttpResponse nettyResponse = (HttpResponse) msg;
RestResponseBuilder builder = new RestResponseBuilder();
HttpResponseStatus status = nettyResponse.getStatus();
builder.setStatus(status.getCode());
for (Map.Entry<String, String> e : nettyResponse.getHeaders())
{
builder.unsafeAddHeaderValue(e.getKey(), e.getValue());
}
ChannelBuffer buf = nettyResponse.getContent();
byte[] array = new byte[buf.readableBytes()];
buf.readBytes(array);
builder.setEntity(array);
return builder.build();
}
示例2: invokeForFile
import org.jboss.netty.handler.codec.http.HttpResponse; //导入方法依赖的package包/类
/**
* Handles a prepared WebSocket API invocation to retrieve a static file
* @param request The prepared HTTP request so we can piggy-back on the existing RpcHandler services.
* @param response The JSONResponse to write back to
* @throws IOException thrown on IO errors
*/
protected void invokeForFile(HttpRequest request, JSONResponse response) throws IOException {
JsonGenerator generator = response.writeHeader(true);
InvocationChannel ichannel = new InvocationChannel();
HttpQuery query = new HttpQuery(tsdb, request, ichannel);
String baseRoute = query.getQueryBaseRoute();
// http_commands.get(baseRoute).execute(tsdb, query);
HttpResponse resp = (HttpResponse)ichannel.getWrites().get(0);
byte[] regionBytes = (byte[])ichannel.getWrites().get(1);
List<Map.Entry<String, String>> responseHeaders = resp.getHeaders();
for(Map.Entry<String, String> entry: responseHeaders) {
generator.writeStringField(entry.getKey(), entry.getValue());
//log.info("Reponse Header: [{}] : [{}]", entry.getKey(), entry.getValue());
}
String cType = resp.getHeader("Content-Type");
if(cType!=null) {
if(cType.startsWith("text")) {
generator.writeStringField("content", new String(regionBytes));
} else {
ChannelBuffer b64 = Base64.encode(ChannelBuffers.wrappedBuffer(regionBytes));
byte[] bytes = new byte[b64.readableBytes()];
b64.readBytes(bytes);
generator.writeBinaryField("content", bytes);
}
}
response.closeGenerator();
}
示例3: writeRequested
import org.jboss.netty.handler.codec.http.HttpResponse; //导入方法依赖的package包/类
@Override
public void writeRequested(final ChannelHandlerContext ctx, final MessageEvent evt)
throws Exception
{
final HttpResponse resp = (HttpResponse)evt.getMessage();
LogManager.i("====================writeRequested : "+resp.toString());
final Level level = Level.FINE;
if (Constants.DEBUG) {
final StringBuilder s = new StringBuilder();
s.append("<");
s.append(resp.getStatus().getCode());
s.append(" ");
s.append(resp.getStatus().getReasonPhrase());
s.append("\n");
for(final Map.Entry<String, String> header: resp.getHeaders()) {
s.append(" ");
s.append(header.getKey());
s.append(": ");
s.append(header.getValue());
s.append("\n");
}
LogManager.i("writeRequested: "+ s.toString());
}
super.writeRequested(ctx, evt);
}
示例4: dump
import org.jboss.netty.handler.codec.http.HttpResponse; //导入方法依赖的package包/类
private void dump(HttpResponse response) {
if (!this.logger.isDebugEnabled()) {
return;
}
this.logger.debug("%s|%s", response.getStatus().getCode(),
response.getStatus().getReasonPhrase());
for (Entry<String, String> h : response.getHeaders()) {
this.logger.debug("%s=%s", h.getKey(), h.getValue());
}
}