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 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.junit.jupiter.api.Test;
31
32
33
34
35 public class HttpGetContentInfoFunctionalTest {
36
37 FileSystemOptions getOptionsWithProxy() throws MalformedURLException {
38
39 String proxyHost = null;
40 int proxyPort = -1;
41 final String proxyUrl = System.getenv("https_proxy");
42 if (proxyUrl != null) {
43 final URL url = new URL(proxyUrl);
44 proxyHost = url.getHost();
45 proxyPort = url.getPort();
46 }
47
48
49 if (proxyHost == null || proxyPort == -1) {
50 return null;
51 }
52
53
54 final HttpFileSystemConfigBuilder builder = HttpFileSystemConfigBuilder.getInstance();
55 final FileSystemOptions opts = new FileSystemOptions();
56 builder.setProxyHost(opts, proxyHost);
57 builder.setProxyPort(opts, proxyPort);
58 return opts;
59 }
60
61
62
63
64
65
66 @Test
67 public void testGetContentInfo() throws FileSystemException, MalformedURLException {
68 final FileSystemManager fsManager = VFS.getManager();
69 final String uri = "http://www.apache.org/licenses/LICENSE-2.0.txt";
70 try (FileObject fo = fsManager.resolveFile(uri, getOptionsWithProxy());
71 final FileContent content = fo.getContent()) {
72 assertNotNull(content);
73
74 content.getContentInfo();
75 }
76 }
77
78 }