|
|
|
@ -28,67 +28,70 @@ import org.slf4j.LoggerFactory;
|
|
|
|
|
public class HttpResolver extends HttpServlet {
|
|
|
|
|
|
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** The logger. */
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(HttpResolver.class);
|
|
|
|
|
|
|
|
|
|
public void init(ServletConfig conf) throws ServletException {
|
|
|
|
|
|
|
|
|
|
Handler.activateProtocol();
|
|
|
|
|
super.init(conf);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void doGet(HttpServletRequest request,
|
|
|
|
|
HttpServletResponse response) throws IOException {
|
|
|
|
|
|
|
|
|
|
logger.info("The http session id is: " + request.getSession().getId());
|
|
|
|
|
String uri = request.getParameter("smp-uri");
|
|
|
|
|
|
|
|
|
|
uri = uri.replace(" ","+");
|
|
|
|
|
|
|
|
|
|
String uri = request.getParameter("smp-uri");
|
|
|
|
|
|
|
|
|
|
uri = uri.replace(" ","+");//the char + is removed when the servlet is doing unescaping of the query paramenters, we just put it back
|
|
|
|
|
|
|
|
|
|
logger.debug("URI = "+ uri);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
if (uri == null || uri.equals("")) {
|
|
|
|
|
// the document has not id - not found
|
|
|
|
|
response.sendError(404);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OutputStream out = response.getOutputStream();
|
|
|
|
|
|
|
|
|
|
String name = "";//we don't need to put a name in the HEADER
|
|
|
|
|
response.addHeader("content_name", name);
|
|
|
|
|
response.addHeader("Content-Name", name);
|
|
|
|
|
|
|
|
|
|
response.addHeader("content-disposition", "attachment; filename=" +name);
|
|
|
|
|
response.setContentType("unknown/unknown");
|
|
|
|
|
|
|
|
|
|
URL url = new URL(uri);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
if (uri == null || uri.equals("")) {
|
|
|
|
|
// the document has not id - not found
|
|
|
|
|
response.sendError(404);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OutputStream out = response.getOutputStream();
|
|
|
|
|
Handler.activateProtocol();
|
|
|
|
|
String name = "";
|
|
|
|
|
response.addHeader("content_name", name);
|
|
|
|
|
response.addHeader("Content-Name", name);
|
|
|
|
|
|
|
|
|
|
response.addHeader("content-disposition", "attachment; filename=" +name);
|
|
|
|
|
response.setContentType("unknown/unknown");
|
|
|
|
|
|
|
|
|
|
logger.info("About to get object");
|
|
|
|
|
URL url = new URL(uri);
|
|
|
|
|
URLConnection uc = null;
|
|
|
|
|
InputStream in = null;
|
|
|
|
|
try {
|
|
|
|
|
uc = ( URLConnection ) url.openConnection ( );
|
|
|
|
|
in = uc.getInputStream();
|
|
|
|
|
}
|
|
|
|
|
catch(Exception e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
URLConnection uc = null;
|
|
|
|
|
|
|
|
|
|
InputStream in = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IOUtils.copy(in, out);
|
|
|
|
|
logger.info("Printing outToString: " + out.toString());
|
|
|
|
|
out.flush();
|
|
|
|
|
out.close();
|
|
|
|
|
in.close();
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
try {
|
|
|
|
|
uc = ( URLConnection ) url.openConnection ( );
|
|
|
|
|
in = uc.getInputStream();
|
|
|
|
|
}
|
|
|
|
|
catch(Exception e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
logger.error("Exception:", e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IOUtils.copy(in, out);
|
|
|
|
|
|
|
|
|
|
out.flush();
|
|
|
|
|
out.close();
|
|
|
|
|
in.close();
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
logger.error("Exception:", e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|