Commit 3f6a3a28 authored by Grégory Mantelet's avatar Grégory Mantelet
Browse files

[UWS] Replace the public static variable for the tmp directory by a class

attribute.

In this way, it is possible to run two different instances of a UWS/TAP service
with a different temporary directory in the same JVM.
parent 3d22e42a
Loading
Loading
Loading
Loading
+34 −10
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ package uws.service.file;
 * You should have received a copy of the GNU Lesser General Public License
 * along with UWSLibrary.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Copyright 2012-2017 - UDS/Centre de Données astronomiques de Strasbourg (CDS),
 * Copyright 2012-2018 - UDS/Centre de Données astronomiques de Strasbourg (CDS),
 *                       Astronomisches Rechen Institut (ARI)
 */

@@ -53,26 +53,31 @@ import uws.service.log.UWSLog.LogLevel;
import uws.service.request.UploadFile;

/**
 * <p>All UWS files are stored in the local machine into the specified directory.</p>
 * All UWS files are stored in the local machine into the specified directory.
 *
 * <p>
 * 	The name of the log file, the result files and the backup files may be customized by overriding the following functions:
 * 	{@link #getLogFileName(uws.service.log.UWSLog.LogLevel, String)}, {@link #getResultFileName(Result, UWSJob)}, {@link #getBackupFileName(JobOwner)} and {@link #getBackupFileName()}.
 * 	The name of the log file, the result files and the backup files may be
 * 	customised by overriding the following functions:
 * 	{@link #getLogFileName(uws.service.log.UWSLog.LogLevel, String)},
 * 	{@link #getResultFileName(Result, UWSJob)},
 * 	{@link #getBackupFileName(JobOwner)} and {@link #getBackupFileName()}.
 * </p>
 *
 * <p>
 * 	By default, results and backups are grouped by owner/user and owners/users are grouped thanks to {@link DefaultOwnerGroupIdentifier}.
 * 	By using the appropriate constructor, you can change these default behaviors.
 * 	By default, results and backups are grouped by owner/user and owners/users
 * 	are grouped thanks to {@link DefaultOwnerGroupIdentifier}. By using the
 * 	appropriate constructor, you can change these default behaviours.
 * </p>
 *
 * <p>
 * 	A log file rotation is set by default so that avoiding a too big log file after several months/years of use.
 * 	By default the rotation is done every month on the 1st at 6am. This frequency can be changed easily thanks to the function
 * 	{@link #setLogRotationFreq(String)}.
 * 	A log file rotation is set by default so that avoiding a too big log file
 * 	after several months/years of use. By default the rotation is done every
 * 	month on the 1st at 6am. This frequency can be changed easily thanks to the
 * 	function {@link #setLogRotationFreq(String)}.
 * </p>
 *
 * @author Gr&eacute;gory Mantelet (CDS;ARI)
 * @version 4.4 (07/2018)
 * @version 4.4 (08/2018)
 */
public class LocalUWSFileManager implements UWSFileManager {

@@ -87,6 +92,10 @@ public class LocalUWSFileManager implements UWSFileManager {
	/** Directory in which all files managed by this class will be written and read. */
	protected final File rootDirectory;

	/** Directory in which temporary files (e.g. uploads) should be stored.
	 * @since 4.4 */
	protected File tmpDirectory = new File(System.getProperty("java.io.tmpdir"));

	/** Output toward the service log file. */
	protected PrintWriter logOutput = null;
	/** Frequency at which the log file must be "rotated" (the file is renamed with the date of its first write and a new log file is created).
@@ -439,6 +448,21 @@ public class LocalUWSFileManager implements UWSFileManager {
			return new File(upload.getLocation());
	}

	@Override
	public File getTmpDirectory(){
		return tmpDirectory;
	}

	@Override
	public boolean setTmpDirectory(final File newTmpDir){
		if (newTmpDir == null || !newTmpDir.exists() || !newTmpDir.isDirectory() || !newTmpDir.canRead() || !newTmpDir.canWrite())
			return false;
		else{
			tmpDirectory = newTmpDir;
			return true;
		}
	}

	@Override
	public InputStream getUploadInput(final UploadFile upload) throws IOException{
		// Check the source file:
+280 −123

File changed.

Preview size limit exceeded, changes collapsed.

+50 −42

File changed.

Preview size limit exceeded, changes collapsed.

+29 −24

File changed.

Preview size limit exceeded, changes collapsed.

+9 −6
Original line number Diff line number Diff line
@@ -169,7 +169,7 @@ public class XMLRequestParser implements RequestParser {
		Object reqID = request.getAttribute(UWS.REQ_ATTRIBUTE_ID);
		if (reqID == null || !(reqID instanceof String))
			reqID = (new Date()).getTime();
		File xmlFile = new File(UWSFileManager.TMP_UPLOAD_DIR, "JOB_DESCRIPTION_" + reqID);
		File xmlFile = new File(fileManager.getTmpDirectory(), "JOB_DESCRIPTION_" + reqID);

		OutputStream output = null;
		InputStream input = null;
@@ -254,12 +254,14 @@ public class XMLRequestParser implements RequestParser {
			if (output != null){
				try{
					output.close();
				}catch(IOException ioe2){}
				}catch(IOException ioe2){
				}
			}
			if (input != null){
				try{
					input.close();
				}catch(IOException ioe2){}
				}catch(IOException ioe2){
				}
			}
		}

@@ -312,7 +314,8 @@ public class XMLRequestParser implements RequestParser {
			if (input != null){
				try{
					input.close();
				}catch(IOException ioe){}
				}catch(IOException ioe){
				}
			}
		}
	}