int status = httpUrlConnect.getResponseCode();
String location = httpUrlConnect.getHeaderField("Location");
switch (status)
{
case HttpURLConnection.HTTP_NOT_FOUND:
throw new ResourceMissingException
(httpUrlConnect.getURL().toExternalForm(),
"", "HTTP Status-Code 404: Not Found");
case HttpURLConnection.HTTP_FORBIDDEN:
throw new ResourceMissingException
(httpUrlConnect.getURL().toExternalForm(),
"", "HTTP Status-Code 403: Forbidden");
case HttpURLConnection.HTTP_INTERNAL_ERROR:
throw new ResourceMissingException
(httpUrlConnect.getURL().toExternalForm(),
"", "HTTP Status-Code 500: Internal Server Error");
case HttpURLConnection.HTTP_NO_CONTENT:
throw new ResourceMissingException
(httpUrlConnect.getURL().toExternalForm(),
"", "HTTP Status-Code 204: No Content");
/*
* Note: these cases apply to http status codes 302 and 303
* this will handle automatic redirection to a new GET URL
*/
case HttpURLConnection.HTTP_MOVED_TEMP:
httpUrlConnect.disconnect();
httpUrlConnect = (HttpURLConnection) getConnection(location,state);
break;
case HttpURLConnection.HTTP_SEE_OTHER:
httpUrlConnect.disconnect();
httpUrlConnect = (HttpURLConnection) getConnection(location,state);
break;
/*
* Note: this cases apply to http status code 301
* it will handle the automatic redirection of GET requests.
* The spec calls for a POST redirect to be verified manually by the user
* Rather than bypass this security restriction, we will throw an exception
*/
case HttpURLConnection.HTTP_MOVED_PERM:
if (state.runtimeData.getHttpRequestMethod().equals("GET")){
httpUrlConnect.disconnect();
httpUrlConnect = (HttpURLConnection) getConnection(location,state);
}
else {
throw new ResourceMissingException
(httpUrlConnect.getURL().toExternalForm(),
"", "HTTP Status-Code 301: POST Redirection currently not supported");
}
break;
default: