git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/uri-resolver@71351 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
21ea8feb8f
commit
79f7a79df7
4
pom.xml
4
pom.xml
|
@ -5,7 +5,7 @@
|
|||
<groupId>org.gcube.tools</groupId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<groupId>org.gcube.datat.transfer</groupId>
|
||||
<groupId>org.gcube.data.transfer</groupId>
|
||||
<artifactId>uri-resolver</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<packaging>war</packaging>
|
||||
|
@ -42,13 +42,11 @@
|
|||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.2.16</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>1.6.4</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
|
|
|
@ -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(" ","+");
|
||||
|
||||
|
||||
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();
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
IOUtils.copy(in, out);
|
||||
logger.info("Printing outToString: " + out.toString());
|
||||
out.flush();
|
||||
out.close();
|
||||
in.close();
|
||||
try {
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.error("Exception:", e);
|
||||
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);
|
||||
|
||||
URLConnection uc = null;
|
||||
|
||||
InputStream in = null;
|
||||
|
||||
try {
|
||||
uc = ( URLConnection ) url.openConnection ( );
|
||||
in = uc.getInputStream();
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
IOUtils.copy(in, out);
|
||||
|
||||
out.flush();
|
||||
out.close();
|
||||
in.close();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.error("Exception:", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue