1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.vfs2.provider.http;
18
19 import java.util.Arrays;
20 import java.util.Collection;
21 import java.util.Collections;
22
23 import org.apache.commons.httpclient.HttpClient;
24 import org.apache.commons.vfs2.Capability;
25 import org.apache.commons.vfs2.FileName;
26 import org.apache.commons.vfs2.FileSystem;
27 import org.apache.commons.vfs2.FileSystemConfigBuilder;
28 import org.apache.commons.vfs2.FileSystemException;
29 import org.apache.commons.vfs2.FileSystemOptions;
30 import org.apache.commons.vfs2.UserAuthenticationData;
31 import org.apache.commons.vfs2.provider.AbstractOriginatingFileProvider;
32 import org.apache.commons.vfs2.provider.GenericFileName;
33 import org.apache.commons.vfs2.util.UserAuthenticatorUtils;
34
35
36
37
38
39
40 @Deprecated
41 public class HttpFileProvider extends AbstractOriginatingFileProvider {
42
43
44 public static final UserAuthenticationData.Type[] AUTHENTICATOR_TYPES = {
45 UserAuthenticationData.USERNAME, UserAuthenticationData.PASSWORD };
46
47 static final Collection<Capability> CAPABILITIES = Collections
48 .unmodifiableCollection(Arrays.asList(Capability.GET_TYPE, Capability.READ_CONTENT, Capability.URI, Capability.GET_LAST_MODIFIED,
49 Capability.ATTRIBUTES, Capability.RANDOM_ACCESS_READ, Capability.DIRECTORY_READ_CONTENT));
50
51
52
53
54 public HttpFileProvider() {
55 setFileNameParser(HttpFileNameParser.getInstance());
56 }
57
58
59
60
61
62
63 @Override
64 protected FileSystem doCreateFileSystem(final FileName name, final FileSystemOptions fileSystemOptions)
65 throws FileSystemException {
66
67 final GenericFileName rootName = (GenericFileName) name;
68 UserAuthenticationData authData = null;
69 HttpClient httpClient;
70 try {
71 authData = UserAuthenticatorUtils.authenticate(fileSystemOptions, AUTHENTICATOR_TYPES);
72 final String fileScheme = rootName.getScheme();
73 final char lastChar = fileScheme.charAt(fileScheme.length() - 1);
74 final String internalScheme = lastChar == 's' || lastChar == 'S' ? "https" : "http";
75 httpClient = HttpClientFactory.createConnection(internalScheme, rootName.getHostName(),
76 rootName.getPort(),
77 UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData,
78 UserAuthenticationData.USERNAME, UserAuthenticatorUtils.toChar(rootName.getUserName()))),
79 UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData,
80 UserAuthenticationData.PASSWORD, UserAuthenticatorUtils.toChar(rootName.getPassword()))),
81 fileSystemOptions);
82 } finally {
83 UserAuthenticatorUtils.cleanup(authData);
84 }
85 return new HttpFileSystem(rootName, httpClient, fileSystemOptions);
86 }
87
88 @Override
89 public Collection<Capability> getCapabilities() {
90 return CAPABILITIES;
91 }
92
93 @Override
94 public FileSystemConfigBuilder getConfigBuilder() {
95 return HttpFileSystemConfigBuilder.getInstance();
96 }
97 }