Search in sources :

Example 36 with ChannelBuffer

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);
}
Also used : VerifierNone(org.apache.hadoop.oncrpc.security.VerifierNone) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Example 37 with ChannelBuffer

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);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) XDR(org.apache.hadoop.oncrpc.XDR) RpcResponse(org.apache.hadoop.oncrpc.RpcResponse) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) RpcCall(org.apache.hadoop.oncrpc.RpcCall) VerifierNone(org.apache.hadoop.oncrpc.security.VerifierNone) NfsExports(org.apache.hadoop.nfs.NfsExports) ArrayList(java.util.ArrayList) List(java.util.List) InetAddress(java.net.InetAddress)

Example 38 with ChannelBuffer

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();
    }
}
Also used : ByteBuffer(java.nio.ByteBuffer) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Example 39 with ChannelBuffer

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);
    }
}
Also used : Frame(com.cgbystrom.sockjs.Frame) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Example 40 with ChannelBuffer

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);
    }
}
Also used : Frame(com.cgbystrom.sockjs.Frame) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Aggregations

ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)494 DefaultHttpResponse (org.jboss.netty.handler.codec.http.DefaultHttpResponse)70 Test (org.junit.Test)67 DeviceSession (org.traccar.DeviceSession)64 Position (org.traccar.model.Position)62 HttpResponse (org.jboss.netty.handler.codec.http.HttpResponse)61 Test (org.testng.annotations.Test)49 HttpChunk (org.jboss.netty.handler.codec.http.HttpChunk)48 DefaultHttpChunk (org.jboss.netty.handler.codec.http.DefaultHttpChunk)44 HttpChunkTrailer (org.jboss.netty.handler.codec.http.HttpChunkTrailer)37 DefaultHttpChunkTrailer (org.jboss.netty.handler.codec.http.DefaultHttpChunkTrailer)34 ChannelFuture (org.jboss.netty.channel.ChannelFuture)28 Checkpoint (com.linkedin.databus.core.Checkpoint)27 ByteBuffer (java.nio.ByteBuffer)27 RecoverablePduException (com.cloudhopper.smpp.type.RecoverablePduException)26 UnrecoverablePduException (com.cloudhopper.smpp.type.UnrecoverablePduException)26 DateBuilder (org.traccar.helper.DateBuilder)26 BootstrapDatabaseTooOldException (com.linkedin.databus2.core.container.request.BootstrapDatabaseTooOldException)25 IOException (java.io.IOException)23 ArrayList (java.util.ArrayList)23