changed url redirect and error messages

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@77321 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2013-06-26 12:22:04 +00:00
parent fce6d410d8
commit 2d5ac77f77
2 changed files with 40 additions and 9 deletions

View File

@ -70,7 +70,7 @@ public class RequestBuilderWorkspaceValidateItem {
// System.out.println("status code is "+status);
if(!(status==200) && !(status==202)){ //NOT IS STATUS SC_ACCEPTED
handleError("Sorry, an error occurred on retriving item, "+response.getText()); //ERROR STATUS
handleError("Sorry, an error occurred on retriving the file. "+response.getText()); //ERROR STATUS
}else{ //OK STATUS
@ -88,7 +88,7 @@ public class RequestBuilderWorkspaceValidateItem {
});
} catch (RequestException e) {
throw new Exception("An error occured on send request");
throw new Exception("Sorry, an error occurred while contacting server, try again");
}
}

View File

@ -124,7 +124,7 @@ public class DownloadServlet extends HttpServlet{
} catch (ItemNotFoundException e) {
logger.error("Requested item "+itemId+" not found",e);
// sendError(resp, HttpServletResponse.SC_INTERNAL_SERVER_ERROR +": Error, no items found");
handleError(urlRedirectOnError, req, resp, itemId, HttpServletResponse.SC_INTERNAL_SERVER_ERROR +": "+ConstantsExplorer.ERROR_ITEM_DOES_NOT_EXIST);
handleError(urlRedirectOnError, req, resp, itemId, "The file has been deleted by another user.");
// sendError(resp, HttpServletResponse.SC_INTERNAL_SERVER_ERROR +": "+ConstantsExplorer.ERROR_ITEM_DOES_NOT_EXIST);
return;
@ -557,12 +557,11 @@ public class DownloadServlet extends HttpServlet{
protected void handleError(boolean urlRedirectOnError, HttpServletRequest req, HttpServletResponse resp, String itemId, String message) throws IOException{
logger.warn("Handle rrror occurred: "+message);
if(urlRedirectOnError){
String path = req.getRequestURI().substring(req.getContextPath().length());
urlRedirect(resp, path, itemId);
urlRedirect(req, resp, itemId);
}else
sendError(resp,HttpServletResponse.SC_INTERNAL_SERVER_ERROR +": Error during data retrieving");
sendError(resp,message);
}
@ -598,12 +597,44 @@ public class DownloadServlet extends HttpServlet{
response.flushBuffer();
}
protected void urlRedirect(HttpServletResponse response, String contextPath, String url) throws IOException {
protected void urlRedirect(HttpServletRequest req, HttpServletResponse response, String fakePath) throws IOException {
response.sendRedirect(response.encodeRedirectURL(contextPath + "/" +url));
String requestUrl = getRequestURL(req) + "/"+fakePath;
logger.trace("Url redirect on: "+requestUrl);
// System.out.println("Url redirect on: "+requestUrl);
response.sendRedirect(response.encodeRedirectURL(requestUrl));
return;
}
public static String getRequestURL(HttpServletRequest req) {
String scheme = req.getScheme(); // http
String serverName = req.getServerName(); // hostname.com
int serverPort = req.getServerPort(); // 80
String contextPath = req.getContextPath(); // /mywebapp
String servletPath = req.getServletPath(); // /servlet/MyServlet
// String pathInfo = req.getPathInfo(); // /a/b;c=123
// String queryString = req.getQueryString(); // d=789
// Reconstruct original requesting URL
StringBuffer url = new StringBuffer();
url.append(scheme).append("://").append(serverName);
if ((serverPort != 80) && (serverPort != 443)) {
url.append(":").append(serverPort);
}
url.append(contextPath).append(servletPath);
// if (pathInfo != null) {
// url.append(pathInfo);
// }
// if (queryString != null) {
// url.append("?").append(queryString);
// }
return url.toString();
}
public static void main(String[] args) {
InputStream is = null;