Exemplo n.º 1
0
			protected internal virtual void SendError(ChannelHandlerContext ctx, string message
				, HttpResponseStatus status)
			{
				HttpResponse response = new DefaultHttpResponse(HttpVersion.Http11, status);
				response.SetHeader(HttpHeaders.Names.ContentType, "text/plain; charset=UTF-8");
				// Put shuffle version into http header
				response.SetHeader(ShuffleHeader.HttpHeaderName, ShuffleHeader.DefaultHttpHeaderName
					);
				response.SetHeader(ShuffleHeader.HttpHeaderVersion, ShuffleHeader.DefaultHttpHeaderVersion
					);
				response.SetContent(ChannelBuffers.CopiedBuffer(message, CharsetUtil.Utf8));
				// Close the connection as soon as the error message is sent.
				ctx.GetChannel().Write(response).AddListener(ChannelFutureListener.Close);
			}
            /// <exception cref="System.IO.IOException"/>
            public virtual void Handle(Org.Jboss.Netty.Channel.Channel channel, Org.Apache.Hadoop.Security.Token.Token
                                       <DelegationTokenIdentifier> token, string serviceUrl)
            {
                NUnit.Framework.Assert.AreEqual(this._enclosing.testToken, token);
                byte[] bytes = Sharpen.Runtime.GetBytesForString(TestDelegationTokenRemoteFetcher
                                                                 .ExpDate);
                ChannelBuffer cbuffer = ChannelBuffers.Buffer(bytes.Length);

                cbuffer.WriteBytes(bytes);
                HttpResponse response = new DefaultHttpResponse(HttpVersion.Http11, HttpResponseStatus
                                                                .Ok);

                response.SetHeader(HttpHeaders.Names.ContentLength, bytes.Length.ToString());
                response.SetContent(cbuffer);
                channel.Write(response).AddListener(ChannelFutureListener.Close);
            }
            /// <exception cref="System.IO.IOException"/>
            public virtual void Handle(Org.Jboss.Netty.Channel.Channel channel, Org.Apache.Hadoop.Security.Token.Token
                                       <DelegationTokenIdentifier> token, string serviceUrl)
            {
                NUnit.Framework.Assert.AreEqual(this._enclosing.testToken, token);
                Credentials creds = new Credentials();

                creds.AddToken(new Text(serviceUrl), token);
                DataOutputBuffer @out = new DataOutputBuffer();

                creds.Write(@out);
                int           fileLength = @out.GetData().Length;
                ChannelBuffer cbuffer    = ChannelBuffers.Buffer(fileLength);

                cbuffer.WriteBytes(@out.GetData());
                HttpResponse response = new DefaultHttpResponse(HttpVersion.Http11, HttpResponseStatus
                                                                .Ok);

                response.SetHeader(HttpHeaders.Names.ContentLength, fileLength.ToString());
                response.SetContent(cbuffer);
                channel.Write(response).AddListener(ChannelFutureListener.Close);
            }