if (conn instanceof HttpURLConnection) {
HttpURLConnection httpConn = ((HttpURLConnection) conn);
int code = httpConn.getResponseCode();
if (code == 401) {
errorReceiver.error(new SAXParseException(WscompileMessages.WSIMPORT_AUTH_INFO_NEEDED(e.getMessage(), systemId, DefaultAuthenticator.defaultAuthfile), null, e));
throw new AbortException();
}
//FOR other code we will retry with MEX
}
throw e;
}
//handle 302 or 303, JDK does not seem to handle 302 very well.
//Need to redesign this a bit as we need to throw better error message for IOException in this case
if (conn instanceof HttpURLConnection) {
HttpURLConnection httpConn = ((HttpURLConnection) conn);
int code = httpConn.getResponseCode();
if (code == 302 || code == 303) {
//retry with the value in Location header
List<String> seeOther = httpConn.getHeaderFields().get("Location");
if (seeOther != null && seeOther.size() > 0) {
URL newurl = new URL(url, seeOther.get(0));
if (!newurl.equals(url)){
errorReceiver.info(new SAXParseException(WscompileMessages.WSIMPORT_HTTP_REDIRECT(code, seeOther.get(0)), null));
url = newurl;
httpConn.disconnect();
if(redirects >= 5){
errorReceiver.error(new SAXParseException(WscompileMessages.WSIMPORT_MAX_REDIRECT_ATTEMPT(), null));
throw new AbortException();
}
conn = url.openConnection();
redirects++;
redirect = true;
}