1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.vfs2.provider.http4s;
18
19 import static org.junit.jupiter.api.Assertions.assertNotNull;
20
21 import java.net.MalformedURLException;
22 import java.net.URL;
23
24 import org.apache.commons.vfs2.FileContent;
25 import org.apache.commons.vfs2.FileObject;
26 import org.apache.commons.vfs2.FileSystemException;
27 import org.apache.commons.vfs2.FileSystemManager;
28 import org.apache.commons.vfs2.FileSystemOptions;
29 import org.apache.commons.vfs2.VFS;
30 import org.apache.commons.vfs2.provider.http4.Http4FileSystemConfigBuilder;
31 import org.junit.jupiter.api.Test;
32
33
34
35
36 public class Http4sGetContentInfoTest {
37
38 FileSystemOptions getOptionsWithProxy() throws MalformedURLException {
39
40 String proxyHost = null;
41 int proxyPort = -1;
42 final String proxyUrl = System.getenv("https_proxy");
43 if (proxyUrl != null) {
44 final URL url = new URL(proxyUrl);
45 proxyHost = url.getHost();
46 proxyPort = url.getPort();
47 }
48
49
50 if (proxyHost == null || proxyPort == -1) {
51 return null;
52 }
53
54
55 final Http4FileSystemConfigBuilder builder = Http4FileSystemConfigBuilder.getInstance();
56 final FileSystemOptions opts = new FileSystemOptions();
57 builder.setProxyHost(opts, proxyHost);
58 builder.setProxyPort(opts, proxyPort);
59 return opts;
60 }
61
62
63
64
65
66
67
68 @Test
69 public void testGetContentInfo() throws FileSystemException, MalformedURLException {
70 final FileSystemManager fsManager = VFS.getManager();
71 final String uri = "http4://www.apache.org/licenses/LICENSE-2.0.txt";
72 try (FileObject fo = fsManager.resolveFile(uri, getOptionsWithProxy())) {
73 final FileContent content = fo.getContent();
74 assertNotNull(content);
75
76 content.getContentInfo();
77 }
78 }
79
80 }