forked from RihanKh/OSAandSAST
-
Notifications
You must be signed in to change notification settings - Fork 2
/
SimpleConnectionAdvisor.java
178 lines (147 loc) · 6.74 KB
/
SimpleConnectionAdvisor.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package com.cx.automation.installation.old.tfsManagment;
import com.cx.automation.installation.old.tfsManagment.ConnectionClient;
import com.microsoft.tfs.core.config.ConnectionAdvisor;
import com.microsoft.tfs.core.config.ConnectionInstanceData;
import com.microsoft.tfs.core.config.auth.DefaultTransportRequestHandler;
import com.microsoft.tfs.core.config.client.ClientFactory;
import com.microsoft.tfs.core.config.client.DefaultClientFactory;
import com.microsoft.tfs.core.config.httpclient.ConfigurableHTTPClientFactory;
import com.microsoft.tfs.core.config.httpclient.DefaultHTTPClientFactory;
import com.microsoft.tfs.core.config.httpclient.HTTPClientFactory;
import com.microsoft.tfs.core.config.persistence.DefaultPersistenceStoreProvider;
import com.microsoft.tfs.core.config.persistence.PersistenceStoreProvider;
import com.microsoft.tfs.core.config.serveruri.DefaultServerURIProvider;
import com.microsoft.tfs.core.config.serveruri.ServerURIProvider;
import com.microsoft.tfs.core.config.tfproxy.TFProxyServerSettingsFactory;
import com.microsoft.tfs.core.config.webservice.DefaultWebServiceFactory;
import com.microsoft.tfs.core.config.webservice.WebServiceFactory;
import com.microsoft.tfs.core.httpclient.HostConfiguration;
import com.microsoft.tfs.core.httpclient.HttpClient;
import com.microsoft.tfs.core.httpclient.HttpState;
import com.microsoft.tfs.core.persistence.FilesystemPersistenceStore;
import com.microsoft.tfs.core.persistence.VersionedVendorFilesystemPersistenceStore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.URI;
import java.util.Locale;
import java.util.TimeZone;
/**
* Created by: iland.
* Date: 8/10/2015.
*/
public class SimpleConnectionAdvisor implements ConnectionAdvisor {
private static final Logger log = LoggerFactory.getLogger(ConnectionClient.class);
private final URI httpProxyURI;
public SimpleConnectionAdvisor() {
this(null);
}
public SimpleConnectionAdvisor(URI httpProxyURI) {
this.httpProxyURI = httpProxyURI;
}
public HTTPClientFactory getHTTPClientFactory(ConnectionInstanceData instanceData) {
return new SamplesHTTPClientFactory(instanceData);
}
private class SamplesHTTPClientFactory extends DefaultHTTPClientFactory {
public SamplesHTTPClientFactory(ConnectionInstanceData connectionInstanceData) {
super(connectionInstanceData);
}
/**
* Overrides configureClientProxy method to set the value of the
* http_proxy on the HTTP Connection.
*/
@Override
public void configureClientProxy(
HttpClient httpClient,
HostConfiguration hostConfiguration,
HttpState httpState,
ConnectionInstanceData connectionInstanceData) {
if (httpProxyURI == null) {
return;
}
if (httpProxyURI.getHost() == null) {
log.warn("Proxy URL does not contain hostname");
return;
}
log.info("Proxy URL set to "
+ httpProxyURI.getHost()
+ ":"
+ (httpProxyURI.getPort() == -1 ? 80 : httpProxyURI.getPort()));
hostConfiguration.setProxy(
httpProxyURI.getHost(),
httpProxyURI.getPort() == -1 ? 80 : httpProxyURI.getPort());
}
}
static class SamplePersistenceStoreProvider
extends DefaultPersistenceStoreProvider {
private final FilesystemPersistenceStore cacheStore;
private final FilesystemPersistenceStore configurationStore;
private final FilesystemPersistenceStore logStore;
public SamplePersistenceStoreProvider() {
super();
/*
* Build a {@link PersistenceStore} which maps to a subdirectory
* inside the user's home directory (more precisely, where the Java
* system property "user.home" points). See the Javadoc on {@link
* VersionedVendorFilesystemPersistenceStore} for how the vendor
* name, application name, and version are mixed into the path on
* each platform.
*/
FilesystemPersistenceStore baseStore =
new VersionedVendorFilesystemPersistenceStore(
"Microsoft-TEE-SDK-Sample-Vendor",
"Connection Advisor Sample",
"1.0");
/*
* Use custom child store names.
*/
cacheStore = (FilesystemPersistenceStore) baseStore.getChildStore("SampleCacheFiles");
configurationStore = (FilesystemPersistenceStore) baseStore.getChildStore("SampleConfigurationFiles");
logStore = (FilesystemPersistenceStore) baseStore.getChildStore("SampleLogs");
}
/**
* Returns a {@link FilesystemPersistenceStore} for storing cache data.
*/
@Override
public FilesystemPersistenceStore getCachePersistenceStore() {
return cacheStore;
}
/**
* Returns a {@link FilesystemPersistenceStore} for storing
* configuration data.
*/
@Override
public FilesystemPersistenceStore getConfigurationPersistenceStore() {
return configurationStore;
}
/**
* Returns a {@link FilesystemPersistenceStore} for storing log files.
*/
@Override
public FilesystemPersistenceStore getLogPersistenceStore() {
return logStore;
}
}
public ClientFactory getClientFactory(ConnectionInstanceData arg0) {
return new DefaultClientFactory();
}
public Locale getLocale(ConnectionInstanceData arg0) {
return Locale.US;
}
public PersistenceStoreProvider getPersistenceStoreProvider(ConnectionInstanceData arg0) {
return new SamplePersistenceStoreProvider();
}
public ServerURIProvider getServerURIProvider(ConnectionInstanceData instanceData) {
return new DefaultServerURIProvider(instanceData);
}
public TFProxyServerSettingsFactory getTFProxyServerSettingsFactory(ConnectionInstanceData arg0) {
return null;
}
public TimeZone getTimeZone(ConnectionInstanceData arg0) {
return null;
}
public WebServiceFactory getWebServiceFactory(ConnectionInstanceData instanceData) {
return new DefaultWebServiceFactory(getLocale(instanceData), new DefaultTransportRequestHandler(
instanceData,
(ConfigurableHTTPClientFactory) getHTTPClientFactory(instanceData)));
}
}