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