use of org.jboss.netty.buffer.ChannelBuffer in project hadoop by apache.
the class RpcProgram method sendRejectedReply.
protected static void sendRejectedReply(RpcCall call, SocketAddress remoteAddress, ChannelHandlerContext ctx) {
XDR out = new XDR();
RpcDeniedReply reply = new RpcDeniedReply(call.getXid(), RpcReply.ReplyState.MSG_DENIED, RpcDeniedReply.RejectState.AUTH_ERROR, new VerifierNone());
reply.write(out);
ChannelBuffer buf = ChannelBuffers.wrappedBuffer(out.asReadOnlyWrap().buffer());
RpcResponse rsp = new RpcResponse(buf, remoteAddress);
RpcUtil.sendRpcResponse(ctx, rsp);
}
use of org.jboss.netty.buffer.ChannelBuffer in project hadoop by apache.
the class RpcProgramMountd method handleInternal.
@Override
public void handleInternal(ChannelHandlerContext ctx, RpcInfo info) {
RpcCall rpcCall = (RpcCall) info.header();
final MNTPROC mntproc = MNTPROC.fromValue(rpcCall.getProcedure());
int xid = rpcCall.getXid();
byte[] data = new byte[info.data().readableBytes()];
info.data().readBytes(data);
XDR xdr = new XDR(data);
XDR out = new XDR();
InetAddress client = ((InetSocketAddress) info.remoteAddress()).getAddress();
if (mntproc == MNTPROC.NULL) {
out = nullOp(out, xid, client);
} else if (mntproc == MNTPROC.MNT) {
// Only do port monitoring for MNT
if (!doPortMonitoring(info.remoteAddress())) {
out = MountResponse.writeMNTResponse(Nfs3Status.NFS3ERR_ACCES, out, xid, null);
} else {
out = mnt(xdr, out, xid, client);
}
} else if (mntproc == MNTPROC.DUMP) {
out = dump(out, xid, client);
} else if (mntproc == MNTPROC.UMNT) {
out = umnt(xdr, out, xid, client);
} else if (mntproc == MNTPROC.UMNTALL) {
umntall(out, xid, client);
} else if (mntproc == MNTPROC.EXPORT) {
// Currently only support one NFS export
List<NfsExports> hostsMatchers = new ArrayList<NfsExports>();
if (hostsMatcher != null) {
hostsMatchers.add(hostsMatcher);
out = MountResponse.writeExportList(out, xid, exports, hostsMatchers);
} else {
// This means there are no valid exports provided.
RpcAcceptedReply.getInstance(xid, RpcAcceptedReply.AcceptState.PROC_UNAVAIL, new VerifierNone()).write(out);
}
} else {
// Invalid procedure
RpcAcceptedReply.getInstance(xid, RpcAcceptedReply.AcceptState.PROC_UNAVAIL, new VerifierNone()).write(out);
}
ChannelBuffer buf = ChannelBuffers.wrappedBuffer(out.asReadOnlyWrap().buffer());
RpcResponse rsp = new RpcResponse(buf, info.remoteAddress());
RpcUtil.sendRpcResponse(ctx, rsp);
}
use of org.jboss.netty.buffer.ChannelBuffer in project crate by crate.
the class DigestBlob method addToHead.
public void addToHead(BytesReference content) throws IOException {
if (content == null) {
return;
}
int written = 0;
ChannelBuffer channelBuffer = Netty3Utils.toChannelBuffer(content);
int readableBytes = channelBuffer.readableBytes();
assert readableBytes + headSize.get() <= headLength : "Got too many bytes in addToHead()";
ByteBuffer byteBuffer = channelBuffer.toByteBuffer();
while (written < readableBytes) {
updateDigest(byteBuffer);
written += headFileChannel.write(byteBuffer);
}
headSize.addAndGet(written);
if (headSize.get() == headLength) {
headCatchedUpLatch.countDown();
}
}
use of org.jboss.netty.buffer.ChannelBuffer in project sockjs-netty by cgbystrom.
the class HtmlFileTransport method writeRequested.
@Override
public void writeRequested(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
if (e.getMessage() instanceof Frame) {
final Frame frame = (Frame) e.getMessage();
if (headerSent.compareAndSet(false, true)) {
HttpResponse response = createResponse(CONTENT_TYPE_HTML);
response.setHeader(CACHE_CONTROL, "no-store, no-cache, must-revalidate, max-age=0");
// Safari needs at least 1024 bytes to parse the website. Relevant:
// http://code.google.com/p/browsersec/wiki/Part2#Survey_of_content_sniffing_behaviors
int spaces = 1024 - header.readableBytes();
ChannelBuffer paddedHeader = ChannelBuffers.buffer(1024 + 50);
paddedHeader.writeBytes(header);
for (int i = 0; i < spaces + 20; i++) {
paddedHeader.writeByte(' ');
}
paddedHeader.writeByte('\r');
paddedHeader.writeByte('\n');
// Opera needs one more new line at the start.
paddedHeader.writeByte('\r');
paddedHeader.writeByte('\n');
ctx.sendDownstream(new DownstreamMessageEvent(e.getChannel(), e.getFuture(), response, e.getRemoteAddress()));
ctx.sendDownstream(new DownstreamMessageEvent(e.getChannel(), e.getFuture(), new DefaultHttpChunk(paddedHeader), e.getRemoteAddress()));
}
final ChannelBuffer frameContent = Frame.encode(frame, false);
final ChannelBuffer content = ChannelBuffers.dynamicBuffer(frameContent.readableBytes() + 10);
Frame.escapeJson(frameContent, content);
ChannelBuffer wrappedContent = ChannelBuffers.wrappedBuffer(PREFIX, content, POSTFIX);
ctx.sendDownstream(new DownstreamMessageEvent(e.getChannel(), e.getFuture(), new DefaultHttpChunk(wrappedContent), e.getRemoteAddress()));
logResponseSize(e.getChannel(), content);
} else {
super.writeRequested(ctx, e);
}
}
use of org.jboss.netty.buffer.ChannelBuffer in project sockjs-netty by cgbystrom.
the class JsonpPollingTransport method writeRequested.
@Override
public void writeRequested(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
if (e.getMessage() instanceof Frame) {
final Frame frame = (Frame) e.getMessage();
HttpResponse response = createResponse(CONTENT_TYPE_JAVASCRIPT);
response.setHeader(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.CLOSE);
response.setHeader(HttpHeaders.Names.CACHE_CONTROL, "no-store, no-cache, must-revalidate, max-age=0");
ChannelBuffer escapedContent = ChannelBuffers.dynamicBuffer();
Frame.escapeJson(Frame.encode(frame, false), escapedContent);
String m = jsonpCallback + "(\"" + escapedContent.toString(CharsetUtil.UTF_8) + "\");\r\n";
e.getFuture().addListener(ChannelFutureListener.CLOSE);
final ChannelBuffer content = ChannelBuffers.copiedBuffer(m, CharsetUtil.UTF_8);
response.setContent(content);
response.setHeader(HttpHeaders.Names.CONTENT_LENGTH, content.readableBytes());
ctx.sendDownstream(new DownstreamMessageEvent(e.getChannel(), e.getFuture(), response, e.getRemoteAddress()));
transportMetrics.messagesSent.mark();
transportMetrics.messagesSentSize.update(content.readableBytes());
} else {
super.writeRequested(ctx, e);
}
}
Aggregations