Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve uploading/downloading files in deegree console #955

Merged
merged 3 commits into from
Mar 1, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.IOUtils;
import org.apache.commons.io.FileUtils;
import org.deegree.commons.config.DeegreeWorkspace;
import org.deegree.commons.utils.Pair;

Expand Down Expand Up @@ -84,15 +85,24 @@ public static void upload( String path, HttpServletRequest req, HttpServletRespo
// unzip a workspace
String wsName = p.second.substring( 0, p.second.length() - 4 );
String dirName = p.second.endsWith( ".zip" ) ? wsName : p.second;
File dir = new File( getWorkspaceRoot(), dirName );
if ( isWorkspace( dirName ) ) {
File workspaceRoot = new File ( getWorkspaceRoot() );
File dir = new File( workspaceRoot, dirName );
if ( !FileUtils.directoryContains( workspaceRoot, dir ) ) {
IOUtils.write( "Workspace " + wsName + " invalid.\n", resp.getOutputStream() );
return;
} else if ( isWorkspace( dirName ) ) {
IOUtils.write( "Workspace " + wsName + " exists.\n", resp.getOutputStream() );
return;
}
unzip( in, dir );
IOUtils.write( "Workspace " + wsName + " uploaded.\n", resp.getOutputStream() );
} else {
File dest = new File( p.first.getLocation(), p.second );
File workspaceDir = p.first.getLocation();
File dest = new File( workspaceDir, p.second );
if ( !FileUtils.directoryContains( workspaceDir, dest ) ) {
IOUtils.write( "Unable to upload file: " + p.second + ".\n", resp.getOutputStream() );
return;
}
if ( !dest.getParentFile().exists() && !dest.getParentFile().mkdirs() ) {
IOUtils.write( "Unable to create parent directory for upload.\n", resp.getOutputStream() );
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%@ page language="java" pageEncoding="UTF-8" import="java.io.*,javax.faces.context.FacesContext, org.apache.commons.io.IOUtils"%><%
<%@ page language="java" pageEncoding="UTF-8" import="java.io.*,javax.faces.context.FacesContext, org.apache.commons.io.*"%><%
// PLEASE NOTE:
//
// Do *not* add anything (header, whitespace, etc.) in front or after the JSP
Expand All @@ -8,15 +8,22 @@
InputStream is = null;
OutputStream os = null;
try {
String mimeType = request.getParameter("mt");
File file = new File ( new File (System.getProperty("java.io.tmpdir")),request.getParameter("file") );
response.setContentType( mimeType );
is = new FileInputStream( file );
os = response.getOutputStream();
IOUtils.copy(is, os);
String mimeType = request.getParameter( "mt" );
String fileName = request.getParameter( "file" );

File tmpDir = new File( System.getProperty( "java.io.tmpdir" ) );
File file = new File( tmpDir, fileName );
if ( FileUtils.directoryContains( tmpDir, file ) && file.exists() ) {
response.setContentType( mimeType );
is = new FileInputStream( file );
os = response.getOutputStream();
IOUtils.copy( is, os );
} else {
throw new Exception( "Unable to download requested file: " + fileName );
}
} catch ( Exception e ) {
e.printStackTrace();
throw new Exception( "Unable to perform download: " + e.getMessage() );
throw new Exception( "Exception while downloading file", e );
} finally {
IOUtils.closeQuietly(is);
IOUtils.closeQuietly(os);
Expand Down