1717import com .oracle .weblogic .imagetool .logging .LoggingFactory ;
1818import org .apache .http .HttpEntity ;
1919import org .apache .http .HttpEntityEnclosingRequest ;
20+ import org .apache .http .HttpHost ;
2021import org .apache .http .HttpRequest ;
21- import org .apache .http .auth .AuthScope ;
22- import org .apache .http .auth .UsernamePasswordCredentials ;
2322import org .apache .http .client .ClientProtocolException ;
2423import org .apache .http .client .CookieStore ;
25- import org .apache .http .client .CredentialsProvider ;
2624import org .apache .http .client .HttpClient ;
2725import org .apache .http .client .HttpRequestRetryHandler ;
2826import org .apache .http .client .config .CookieSpecs ;
3331import org .apache .http .entity .mime .HttpMultipartMode ;
3432import org .apache .http .entity .mime .MultipartEntityBuilder ;
3533import org .apache .http .impl .client .BasicCookieStore ;
36- import org .apache .http .impl .client .BasicCredentialsProvider ;
3734import org .apache .http .impl .client .CloseableHttpClient ;
3835import org .apache .http .impl .client .HttpClientBuilder ;
39- import org .apache .http .impl .cookie .BasicClientCookie ;
4036import org .w3c .dom .Document ;
4137import org .xml .sax .InputSource ;
4238import org .xml .sax .SAXException ;
@@ -100,8 +96,8 @@ public static Document parseXmlString(String xmlString) throws ClientProtocolExc
10096 */
10197 public static Document getXMLContent (String url , String username , String password ) throws IOException {
10298 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 ))
105101 .returnContent ().asString ();
106102 logger .exiting (xmlString );
107103 return parseXmlString (xmlString );
@@ -120,25 +116,51 @@ public static HttpClient getOraClient(String userId, String password) {
120116 config .setCookieSpec (CookieSpecs .STANDARD );
121117
122118 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 ()
133124 .setDefaultRequestConfig (config .build ())
134125 .setRetryHandler (retryHandler ())
126+ .setProxy (proxyHost != null ? new HttpHost (proxyHost , Integer .parseInt (proxyPort )) : null )
135127 .setUserAgent ("Wget/1.10" )
136128 .setDefaultCookieStore (cookieStore ).useSystemProperties ()
137- .setDefaultCredentialsProvider (credentialsProvider ).build ();
129+ .build ();
130+
138131 logger .exiting ();
139132 return result ;
140133 }
141134
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+
142164 private static HttpRequestRetryHandler retryHandler () {
143165 return (exception , executionCount , context ) -> {
144166
@@ -202,16 +224,18 @@ public static Document postCheckConflictRequest(String url, String payload, Stri
202224 .setUserAgent ("Wget/1.10" )
203225 .useSystemProperties ().build ();
204226
205- Executor httpExecutor = Executor . newInstance ( client ). auth (username , password );
227+ Executor httpExecutor = HttpUtil . getHttpExecutor (username , password );
206228 httpExecutor .use (cookieStore );
207229
230+
208231 // Has to do search first, otherwise results in 302
209232 // MUST use the same httpExecutor to maintain session
210233
211234
212235 boolean complete = false ;
213236 int count = 0 ;
214237 String xmlString = null ;
238+
215239 while (!complete ) {
216240 try {
217241 httpExecutor
@@ -223,7 +247,9 @@ public static Document postCheckConflictRequest(String url, String payload, Stri
223247 .build ();
224248
225249 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 ))
227253 .returnContent ().asString ();
228254 complete = true ;
229255 } catch (IOException ioe ) {
0 commit comments