Skip to content

Commit 85b57db

Browse files
jshum2479ddsharpe
authored andcommitted
Enhance error message for HttpUtil.downloadFile (#60)
* Enhance error message for HttpUtil.downloadFile
1 parent 3cec205 commit 85b57db

File tree

1 file changed

+16
-5
lines changed
  • imagetool/src/main/java/com/oracle/weblogic/imagetool/util

1 file changed

+16
-5
lines changed

imagetool/src/main/java/com/oracle/weblogic/imagetool/util/HttpUtil.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class HttpUtil {
5353
*/
5454
public static Document getXMLContent(String url, String username, String password) throws IOException {
5555

56-
logger.finest("HTTPUtil.getXMLContent " + url);
56+
logger.entering(url);
5757
String xmlString = Executor.newInstance(getOraClient(username, password))
5858
.execute(Request.Get(url).connectTimeout(30000).socketTimeout(30000))
5959
.returnContent().asString();
@@ -62,7 +62,7 @@ public static Document getXMLContent(String url, String username, String passwor
6262
DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
6363
InputSource is = new InputSource(new StringReader(xmlString));
6464
Document doc = docBuilder.parse(is);
65-
logger.finest("HTTPUtil.getXMLContent result " + XPathUtil.prettyPrint(doc));
65+
logger.exiting(XPathUtil.prettyPrint(doc));
6666
return doc;
6767
} catch (ParserConfigurationException ex) {
6868
throw new IllegalStateException(ex);
@@ -74,6 +74,7 @@ public static Document getXMLContent(String url, String username, String passwor
7474
}
7575

7676
private static HttpClient getOraClient(String userId, String password) {
77+
logger.entering(userId);
7778
RequestConfig.Builder config = RequestConfig.custom();
7879
config.setCircularRedirectsAllowed(true);
7980
config.setCookieSpec(CookieSpecs.STANDARD);
@@ -88,6 +89,7 @@ private static HttpClient getOraClient(String userId, String password) {
8889
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(
8990
userId, password));
9091
}
92+
logger.exiting();
9193
return HttpClientBuilder.create().setDefaultRequestConfig(config.build())
9294
.setDefaultCookieStore(cookieStore).useSystemProperties()
9395
.setDefaultCredentialsProvider(credentialsProvider).build();
@@ -105,9 +107,18 @@ private static HttpClient getOraClient(String userId, String password) {
105107

106108
public static void downloadFile(String url, String fileName, String username, String password)
107109
throws IOException {
108-
Executor.newInstance(getOraClient(username, password))
109-
.execute(Request.Get(url).connectTimeout(30000).socketTimeout(30000))
110-
.saveContent(new File(fileName));
110+
logger.entering(url);
111+
try {
112+
Executor.newInstance(getOraClient(username, password))
113+
.execute(Request.Get(url).connectTimeout(30000).socketTimeout(30000))
114+
.saveContent(new File(fileName));
115+
} catch (Exception ex) {
116+
String message = String.format("Failed to download and save file %s from %s: %s", fileName, url,
117+
ex.getLocalizedMessage());
118+
logger.info(message);
119+
throw new IOException(message, ex);
120+
}
121+
logger.exiting(fileName);
111122
}
112123

113124
/**

0 commit comments

Comments
 (0)