Commit 96b3b851 authored by gmantele's avatar gmantele
Browse files

[UWS,TAP] 3 MAJOR DEPENDENT FIX: improve significantly the parameters...

[UWS,TAP] 3 MAJOR DEPENDENT FIX: improve significantly the parameters extraction from HTTP request in UWS (1) AND move the file-upload ability into the UWS library (2) AND the modification of parameters in UWS is now conform with the standard (3). (1) Only application/x-form-urlencoded content-type was supported. However a UWS must accept a request body containing only an XML document as a single byReference parameter. It is now done when the content-type is not known. (2) Besides multipart/form-data is now fully supported in UWS and so is still possible in TAP. (3) In the UWS standard, parameters can not be added after creation: they can just be modified. This rule is now respected in the UWS library.
parent fe5ff255
Loading
Loading
Loading
Loading
+18 −3
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ import uws.service.UWSUrl;
 * Useful conversion functions from UWS to JSON.
 * 
 * @author Grégory Mantelet (CDS;ARI)
 * @version 4.1 (09/2014)
 * @version 4.1 (12/2014)
 */
public final class Json4Uws {

@@ -153,8 +153,23 @@ public final class Json4Uws {
	public final static JSONObject getJobParamsJson(final UWSJob job) throws JSONException{
		JSONObject json = new JSONObject();
		if (job != null){
			for(String name : job.getAdditionalParameters())
				json.put(name, job.getAdditionalParameterValue(name));
			Object val;
			for(String name : job.getAdditionalParameters()){
				// get the raw value:
				val = job.getAdditionalParameterValue(name);
				// if an array, build a JSON array of strings:
				if (val != null && val.getClass().isArray()){
					JSONArray array = new JSONArray();
					for(Object o : (Object[])val){
						if (o != null)
							array.put(o.toString());
					}
					json.put(name, array);
				}
				// otherwise, just put the value:
				else
					json.put(name, val);
			}
		}
		return json;
	}
+5 −9
Original line number Diff line number Diff line
@@ -33,8 +33,8 @@ import tap.formatter.OutputFormat;
import tap.log.TAPLog;
import tap.metadata.TAPSchema;
import tap.metadata.TAPTable;
import tap.parameters.DALIUpload;
import tap.parameters.TAPParameters;
import tap.upload.TableLoader;
import tap.upload.Uploader;
import uws.UWSException;
import uws.job.JobThread;
@@ -104,7 +104,7 @@ import adql.query.ADQLQuery;
 * </p>
 * 
 * @author Gr&eacute;gory Mantelet (CDS;ARI)
 * @version 2.0 (09/2014)
 * @version 2.0 (12/2014)
 */
public class ADQLExecutor {

@@ -299,7 +299,7 @@ public class ADQLExecutor {
			dbConn = service.getFactory().getConnection(report.jobID);

			// 1. UPLOAD TABLES, if there is any:
			if (tapParams.getTableLoaders() != null && tapParams.getTableLoaders().length > 0){
			if (tapParams.getUploadedTables() != null && tapParams.getUploadedTables().length > 0){
				startStep(ExecutionProgression.UPLOADING);
				uploadTables();
				endStep();
@@ -444,16 +444,12 @@ public class ADQLExecutor {
	 */
	private final void uploadTables() throws TAPException{
		// Fetch the tables to upload:
		TableLoader[] tables = tapParams.getTableLoaders();
		DALIUpload[] tables = tapParams.getUploadedTables();

		// Upload them, if needed:
		if (tables.length > 0){
			logger.logTAP(LogLevel.INFO, report, "UPLOADING", "Loading uploaded tables (" + tables.length + ")", null);
			try{
			uploadSchema = service.getFactory().createUploader(dbConn).upload(tables);
			}finally{
				TAPParameters.deleteUploadedTables(tables);
			}
		}
	}

+11 −15
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ import adql.query.ADQLQuery;
 * Only the functions related with the database connection stay abstract.
 * 
 * @author Gr&eacute;gory Mantelet (CDS;ARI)
 * @version 2.0 (11/2014)
 * @version 2.0 (12/2014)
 */
public abstract class AbstractTAPFactory extends TAPFactory {

@@ -213,9 +213,13 @@ public abstract class AbstractTAPFactory extends TAPFactory {
	 */
	@Override
	public UWSService createUWS() throws TAPException{
		try{
			UWSService uws = new UWSService(this, this.service.getFileManager(), this.service.getLogger());
			uws.setErrorWriter(errorWriter);
			return uws;
		}catch(UWSException ue){
			throw new TAPException("Can not create a UWS service (asynchronous resource of TAP)!", ue, UWSException.INTERNAL_SERVER_ERROR);
		}
	}

	/**
@@ -276,11 +280,7 @@ public abstract class AbstractTAPFactory extends TAPFactory {
	 */
	@Override
	public TAPParameters createTAPParameters(final HttpServletRequest request) throws TAPException{
		try{
		return new TAPParameters(request, service);
		}catch(UWSException ue){
			throw new TAPException(ue);
		}
	}

	/**
@@ -295,11 +295,7 @@ public abstract class AbstractTAPFactory extends TAPFactory {
	 */
	@Override
	public TAPParameters createTAPParameters(final Map<String,Object> params) throws TAPException{
		try{
		return new TAPParameters(service, params);
		}catch(UWSException ue){
			throw new TAPException(ue);
		}
	}

}
+7 −7
Original line number Diff line number Diff line
@@ -23,13 +23,13 @@ package tap;
import java.util.Collection;
import java.util.Iterator;

import tap.file.LocalTAPFileManager;
import tap.file.TAPFileManager;
import tap.formatter.OutputFormat;
import tap.log.DefaultTAPLog;
import tap.log.TAPLog;
import tap.metadata.TAPMetadata;
import uws.service.UserIdentifier;
import uws.service.file.LocalUWSFileManager;
import uws.service.file.UWSFileManager;
import adql.db.FunctionDef;

/**
@@ -42,7 +42,7 @@ import adql.db.FunctionDef;
 * </p>
 * 
 * @author Gr&eacute;gory Mantelet (CDS;ARI)
 * @version 2.0 (10/2014)
 * @version 2.0 (12/2014)
 */
public interface ServiceConnection {

@@ -494,13 +494,13 @@ public interface ServiceConnection {
	 * </b></p>
	 * 
	 * <p><i>Piece of advice:
	 * 	The library provides a default implementation of the interface {@link TAPFileManager}:
	 * 	{@link LocalTAPFileManager}, which stores all files on the local file-system.
	 * 	The library provides a default implementation of the interface {@link UWSFileManager}:
	 * 	{@link LocalUWSFileManager}, which stores all files on the local file-system.
	 * </i></p>
	 * 
	 * @return	An instance of {@link TAPFileManager}.
	 * @return	An instance of {@link UWSFileManager}.
	 */
	public TAPFileManager getFileManager();
	public UWSFileManager getFileManager();

	/**
	 * <i><b>[MANDATORY]</b></i>
+7 −0
Original line number Diff line number Diff line
@@ -41,6 +41,8 @@ import uws.service.UWSFactory;
import uws.service.UWSService;
import uws.service.backup.UWSBackupManager;
import uws.service.error.ServiceErrorWriter;
import uws.service.file.UWSFileManager;
import uws.service.request.RequestParser;
import adql.parser.ADQLQueryFactory;
import adql.parser.QueryChecker;
import adql.query.ADQLQuery;
@@ -448,4 +450,9 @@ public abstract class TAPFactory implements UWSFactory {
	 */
	public abstract TAPParameters createTAPParameters(final Map<String,Object> params) throws TAPException;

	@Override
	public RequestParser createRequestParser(final UWSFileManager fileManager) throws UWSException{
		return new TAPRequestParser(fileManager);
	}

}
Loading