17
17
import com .oracle .weblogic .imagetool .logging .LoggingFactory ;
18
18
import org .apache .http .HttpEntity ;
19
19
import org .apache .http .HttpEntityEnclosingRequest ;
20
+ import org .apache .http .HttpHost ;
20
21
import org .apache .http .HttpRequest ;
21
- import org .apache .http .auth .AuthScope ;
22
- import org .apache .http .auth .UsernamePasswordCredentials ;
23
22
import org .apache .http .client .ClientProtocolException ;
24
23
import org .apache .http .client .CookieStore ;
25
- import org .apache .http .client .CredentialsProvider ;
26
24
import org .apache .http .client .HttpClient ;
27
25
import org .apache .http .client .HttpRequestRetryHandler ;
28
26
import org .apache .http .client .config .CookieSpecs ;
33
31
import org .apache .http .entity .mime .HttpMultipartMode ;
34
32
import org .apache .http .entity .mime .MultipartEntityBuilder ;
35
33
import org .apache .http .impl .client .BasicCookieStore ;
36
- import org .apache .http .impl .client .BasicCredentialsProvider ;
37
34
import org .apache .http .impl .client .CloseableHttpClient ;
38
35
import org .apache .http .impl .client .HttpClientBuilder ;
39
- import org .apache .http .impl .cookie .BasicClientCookie ;
40
36
import org .w3c .dom .Document ;
41
37
import org .xml .sax .InputSource ;
42
38
import org .xml .sax .SAXException ;
@@ -100,8 +96,8 @@ public static Document parseXmlString(String xmlString) throws ClientProtocolExc
100
96
*/
101
97
public static Document getXMLContent (String url , String username , String password ) throws IOException {
102
98
logger .entering (url );
103
- String xmlString = Executor . newInstance ( getOraClient ( username , password ))
104
- .execute ( Request . Get ( url ). connectTimeout ( 30000 ). socketTimeout (30000 ))
99
+ String xmlString = getHttpExecutor ( username ,password ). execute ( Request . Get ( url ). connectTimeout ( 30000 )
100
+ .socketTimeout (30000 ))
105
101
.returnContent ().asString ();
106
102
logger .exiting (xmlString );
107
103
return parseXmlString (xmlString );
@@ -120,25 +116,51 @@ public static HttpClient getOraClient(String userId, String password) {
120
116
config .setCookieSpec (CookieSpecs .STANDARD );
121
117
122
118
CookieStore cookieStore = new BasicCookieStore ();
123
- CredentialsProvider credentialsProvider = new BasicCredentialsProvider ();
124
-
125
- if (userId != null && password != null ) {
126
- BasicClientCookie cc = new BasicClientCookie ("oraclelicense" , "a" );
127
- cc .setDomain ("edelivery.oracle.com" );
128
- cookieStore .addCookie (cc );
129
- credentialsProvider .setCredentials (AuthScope .ANY , new UsernamePasswordCredentials (
130
- userId , password ));
131
- }
132
- HttpClient result = HttpClientBuilder .create ()
119
+
120
+ String proxyHost = System .getProperty ("https.proxyHost" );
121
+ String proxyPort = System .getProperty ("https.proxyPort" );
122
+ HttpClient result ;
123
+ result = HttpClientBuilder .create ()
133
124
.setDefaultRequestConfig (config .build ())
134
125
.setRetryHandler (retryHandler ())
126
+ .setProxy (proxyHost != null ? new HttpHost (proxyHost , Integer .parseInt (proxyPort )) : null )
135
127
.setUserAgent ("Wget/1.10" )
136
128
.setDefaultCookieStore (cookieStore ).useSystemProperties ()
137
- .setDefaultCredentialsProvider (credentialsProvider ).build ();
129
+ .build ();
130
+
138
131
logger .exiting ();
139
132
return result ;
140
133
}
141
134
135
+ /**
136
+ * Return a Executor for http access.
137
+ * @param supportUserName oracle support username
138
+ * @param supportPassword oracle support password
139
+ * @return Executor
140
+ */
141
+
142
+ public static Executor getHttpExecutor (String supportUserName , String supportPassword ) {
143
+
144
+ String proxyUser = System .getProperty ("https.proxyUser" );
145
+ String proxyPassword = System .getProperty ("https.proxyPassword" );
146
+ String proxyHost = System .getProperty ("https.proxyHost" );
147
+ String proxyPort = System .getProperty ("https.proxyPort" );
148
+ Executor executor = Executor .newInstance (getOraClient (supportUserName , supportPassword ));
149
+
150
+
151
+ if (proxyHost != null ) {
152
+ if (proxyPassword != null ) {
153
+ executor .auth (new HttpHost (proxyHost , Integer .parseInt (proxyPort )), proxyUser , proxyPassword );
154
+ }
155
+
156
+ executor
157
+ .auth (new HttpHost ("login.oracle.com" , 443 ), supportUserName , supportPassword )
158
+ .auth (new HttpHost ("updates.oracle.com" , 443 ), supportUserName , supportPassword )
159
+ .authPreemptiveProxy (new HttpHost (proxyHost , Integer .parseInt (proxyPort )));
160
+ }
161
+ return executor ;
162
+ }
163
+
142
164
private static HttpRequestRetryHandler retryHandler () {
143
165
return (exception , executionCount , context ) -> {
144
166
@@ -202,16 +224,18 @@ public static Document postCheckConflictRequest(String url, String payload, Stri
202
224
.setUserAgent ("Wget/1.10" )
203
225
.useSystemProperties ().build ();
204
226
205
- Executor httpExecutor = Executor . newInstance ( client ). auth (username , password );
227
+ Executor httpExecutor = HttpUtil . getHttpExecutor (username , password );
206
228
httpExecutor .use (cookieStore );
207
229
230
+
208
231
// Has to do search first, otherwise results in 302
209
232
// MUST use the same httpExecutor to maintain session
210
233
211
234
212
235
boolean complete = false ;
213
236
int count = 0 ;
214
237
String xmlString = null ;
238
+
215
239
while (!complete ) {
216
240
try {
217
241
httpExecutor
@@ -223,7 +247,9 @@ public static Document postCheckConflictRequest(String url, String payload, Stri
223
247
.build ();
224
248
225
249
xmlString =
226
- httpExecutor .execute (Request .Post (url ).connectTimeout (30000 ).socketTimeout (30000 ).body (entity ))
250
+ httpExecutor .execute (Request .Post (url ).connectTimeout (30000 )
251
+ .socketTimeout (30000 )
252
+ .body (entity ))
227
253
.returnContent ().asString ();
228
254
complete = true ;
229
255
} catch (IOException ioe ) {
0 commit comments