コード例 #1
0
 /// <exception cref="System.Exception"/>
 protected internal virtual void _testAuthenticationHttpClient(Authenticator authenticator
                                                               , bool doPost)
 {
     Start();
     try
     {
         SystemDefaultHttpClient httpClient = GetHttpClient();
         DoHttpClientRequest(httpClient, new HttpGet(GetBaseURL()));
         // Always do a GET before POST to trigger the SPNego negotiation
         if (doPost)
         {
             HttpPost             post      = new HttpPost(GetBaseURL());
             byte[]               postBytes = Runtime.GetBytesForString(Post);
             ByteArrayInputStream bis       = new ByteArrayInputStream(postBytes);
             InputStreamEntity    entity    = new InputStreamEntity(bis, postBytes.Length);
             // Important that the entity is not repeatable -- this means if
             // we have to renegotiate (e.g. b/c the cookie wasn't handled properly)
             // the test will fail.
             NUnit.Framework.Assert.IsFalse(entity.IsRepeatable());
             post.SetEntity(entity);
             DoHttpClientRequest(httpClient, post);
         }
     }
     finally
     {
         Stop();
     }
 }
コード例 #2
0
        /// <summary>
        /// Creates new instance of
        /// <see cref="Apache.Http.HttpEntity">Apache.Http.HttpEntity</see>
        /// based on the current state.
        /// </summary>
        public virtual HttpEntity Build()
        {
            AbstractHttpEntity e;

            if (this.text != null)
            {
                e = new StringEntity(this.text, GetContentOrDefault(ContentType.DefaultText));
            }
            else
            {
                if (this.binary != null)
                {
                    e = new ByteArrayEntity(this.binary, GetContentOrDefault(ContentType.DefaultBinary
                                                                             ));
                }
                else
                {
                    if (this.stream != null)
                    {
                        e = new InputStreamEntity(this.stream, 1, GetContentOrDefault(ContentType.DefaultBinary
                                                                                      ));
                    }
                    else
                    {
                        if (this.parameters != null)
                        {
                            e = new UrlEncodedFormEntity(this.parameters, this.contentType != null ? this.contentType
                                                         .GetCharset() : null);
                        }
                        else
                        {
                            if (this.serializable != null)
                            {
                                e = new SerializableEntity(this.serializable);
                                e.SetContentType(ContentType.DefaultBinary.ToString());
                            }
                            else
                            {
                                if (this.file != null)
                                {
                                    e = new FileEntity(this.file, GetContentOrDefault(ContentType.DefaultBinary));
                                }
                                else
                                {
                                    e = new BasicHttpEntity();
                                }
                            }
                        }
                    }
                }
            }
            if (e.GetContentType() != null && this.contentType != null)
            {
                e.SetContentType(this.contentType.ToString());
            }
            e.SetContentEncoding(this.contentEncoding);
            e.SetChunked(this.chunked);
            if (this.gzipCompress)
            {
                return(new GzipCompressingEntity(e));
            }
            return(e);
        }
コード例 #3
0
ファイル: HttpFSServer.cs プロジェクト: orf53975/hadoop.net
        public virtual Response Get(string path, HttpFSParametersProvider.OperationParam
                                    op, Parameters @params, HttpServletRequest request)
        {
            UserGroupInformation user = HttpUserGroupInformation.Get();
            Response             response;

            path = MakeAbsolute(path);
            MDC.Put(HttpFSFileSystem.OpParam, op.Value().ToString());
            MDC.Put("hostname", request.GetRemoteAddr());
            switch (op.Value())
            {
            case HttpFSFileSystem.Operation.Open:
            {
                //Invoking the command directly using an unmanaged FileSystem that is
                // released by the FileSystemReleaseFilter
                FSOperations.FSOpen command = new FSOperations.FSOpen(path);
                FileSystem          fs      = CreateFileSystem(user);
                InputStream         @is     = command.Execute(fs);
                long offset = @params.Get <HttpFSParametersProvider.OffsetParam>(HttpFSParametersProvider.OffsetParam
                                                                                 .Name);
                long len = @params.Get <HttpFSParametersProvider.LenParam>(HttpFSParametersProvider.LenParam
                                                                           .Name);
                AuditLog.Info("[{}] offset [{}] len [{}]", new object[] { path, offset, len });
                InputStreamEntity entity = new InputStreamEntity(@is, offset, len);
                response = Response.Ok(entity).Type(MediaType.ApplicationOctetStream).Build();
                break;
            }

            case HttpFSFileSystem.Operation.Getfilestatus:
            {
                FSOperations.FSFileStatus command = new FSOperations.FSFileStatus(path);
                IDictionary json = FsExecute(user, command);
                AuditLog.Info("[{}]", path);
                response = Response.Ok(json).Type(MediaType.ApplicationJson).Build();
                break;
            }

            case HttpFSFileSystem.Operation.Liststatus:
            {
                string filter = @params.Get <HttpFSParametersProvider.FilterParam>(HttpFSParametersProvider.FilterParam
                                                                                   .Name);
                FSOperations.FSListStatus command = new FSOperations.FSListStatus(path, filter);
                IDictionary json = FsExecute(user, command);
                AuditLog.Info("[{}] filter [{}]", path, (filter != null) ? filter : "-");
                response = Response.Ok(json).Type(MediaType.ApplicationJson).Build();
                break;
            }

            case HttpFSFileSystem.Operation.Gethomedirectory:
            {
                EnforceRootPath(op.Value(), path);
                FSOperations.FSHomeDir command = new FSOperations.FSHomeDir();
                JSONObject             json    = FsExecute(user, command);
                AuditLog.Info(string.Empty);
                response = Response.Ok(json).Type(MediaType.ApplicationJson).Build();
                break;
            }

            case HttpFSFileSystem.Operation.Instrumentation:
            {
                EnforceRootPath(op.Value(), path);
                Groups         groups     = HttpFSServerWebApp.Get().Get <Groups>();
                IList <string> userGroups = groups.GetGroups(user.GetShortUserName());
                if (!userGroups.Contains(HttpFSServerWebApp.Get().GetAdminGroup()))
                {
                    throw new AccessControlException("User not in HttpFSServer admin group");
                }
                Instrumentation instrumentation = HttpFSServerWebApp.Get().Get <Instrumentation>();
                IDictionary     snapshot        = instrumentation.GetSnapshot();
                response = Response.Ok(snapshot).Build();
                break;
            }

            case HttpFSFileSystem.Operation.Getcontentsummary:
            {
                FSOperations.FSContentSummary command = new FSOperations.FSContentSummary(path);
                IDictionary json = FsExecute(user, command);
                AuditLog.Info("[{}]", path);
                response = Response.Ok(json).Type(MediaType.ApplicationJson).Build();
                break;
            }

            case HttpFSFileSystem.Operation.Getfilechecksum:
            {
                FSOperations.FSFileChecksum command = new FSOperations.FSFileChecksum(path);
                IDictionary json = FsExecute(user, command);
                AuditLog.Info("[{}]", path);
                response = Response.Ok(json).Type(MediaType.ApplicationJson).Build();
                break;
            }

            case HttpFSFileSystem.Operation.Getfileblocklocations:
            {
                response = Response.Status(Response.Status.BadRequest).Build();
                break;
            }

            case HttpFSFileSystem.Operation.Getaclstatus:
            {
                FSOperations.FSAclStatus command = new FSOperations.FSAclStatus(path);
                IDictionary json = FsExecute(user, command);
                AuditLog.Info("ACL status for [{}]", path);
                response = Response.Ok(json).Type(MediaType.ApplicationJson).Build();
                break;
            }

            case HttpFSFileSystem.Operation.Getxattrs:
            {
                IList <string> xattrNames = @params.GetValues <HttpFSParametersProvider.XAttrNameParam
                                                               >(HttpFSParametersProvider.XAttrNameParam.Name);
                XAttrCodec encoding = @params.Get <HttpFSParametersProvider.XAttrEncodingParam>(HttpFSParametersProvider.XAttrEncodingParam
                                                                                                .Name);
                FSOperations.FSGetXAttrs command = new FSOperations.FSGetXAttrs(path, xattrNames,
                                                                                encoding);
                IDictionary json = FsExecute(user, command);
                AuditLog.Info("XAttrs for [{}]", path);
                response = Response.Ok(json).Type(MediaType.ApplicationJson).Build();
                break;
            }

            case HttpFSFileSystem.Operation.Listxattrs:
            {
                FSOperations.FSListXAttrs command = new FSOperations.FSListXAttrs(path);
                IDictionary json = FsExecute(user, command);
                AuditLog.Info("XAttr names for [{}]", path);
                response = Response.Ok(json).Type(MediaType.ApplicationJson).Build();
                break;
            }

            default:
            {
                throw new IOException(MessageFormat.Format("Invalid HTTP GET operation [{0}]", op
                                                           .Value()));
            }
            }
            return(response);
        }