Skip to content
Snippets Groups Projects
Commit cc493eeb authored by gmantele's avatar gmantele
Browse files

[TAP,UWS] Make valid VOTable results and errors. Some error messages about...

[TAP,UWS] Make valid VOTable results and errors. Some error messages about expected TAP request parameters have been changed.
parent 59ab920d
No related branches found
No related tags found
No related merge requests found
......@@ -212,7 +212,9 @@ public class VOTableFormat implements OutputFormat {
BufferedWriter out = new BufferedWriter(writer);
// Set the root VOTABLE node:
out.write("<VOTABLE" + VOSerializer.formatAttribute("version", votVersion.getVersionNumber()) + VOSerializer.formatAttribute("xmlns", votVersion.getXmlNamespace()) + ">");
out.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
out.newLine();
out.write("<VOTABLE" + VOSerializer.formatAttribute("version", votVersion.getVersionNumber()) + VOSerializer.formatAttribute("xmlns", votVersion.getXmlNamespace()) + VOSerializer.formatAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance") + VOSerializer.formatAttribute("xsi:schemaLocation", votVersion.getXmlNamespace() + " " + votVersion.getSchemaLocation()) + ">");
out.newLine();
// The RESOURCE note MUST have a type "results": [REQUIRED]
......@@ -234,7 +236,7 @@ public class VOTableFormat implements OutputFormat {
Iterator<Map.Entry<String,String>> it = otherInfo.entrySet().iterator();
while(it.hasNext()){
Map.Entry<String,String> entry = it.next();
out.write("<INFO " + VOSerializer.formatAttribute("name", entry.getKey()) + ">" + VOSerializer.formatText(entry.getValue()) + "</INFO>");
out.write("<INFO " + VOSerializer.formatAttribute("name", entry.getKey()) + VOSerializer.formatAttribute("value", entry.getValue()) + "/>");
out.newLine();
}
}
......@@ -304,7 +306,9 @@ public class VOTableFormat implements OutputFormat {
*/
protected void writeHeader(final VOTableVersion votVersion, final TAPExecutionReport execReport, final BufferedWriter out) throws IOException, TAPException{
// Set the root VOTABLE node:
out.write("<VOTABLE" + VOSerializer.formatAttribute("version", votVersion.getVersionNumber()) + VOSerializer.formatAttribute("xmlns", votVersion.getXmlNamespace()) + ">");
out.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
out.newLine();
out.write("<VOTABLE" + VOSerializer.formatAttribute("version", votVersion.getVersionNumber()) + VOSerializer.formatAttribute("xmlns", votVersion.getXmlNamespace()) + VOSerializer.formatAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance") + VOSerializer.formatAttribute("xsi:schemaLocation", votVersion.getXmlNamespace() + " " + votVersion.getSchemaLocation()) + ">");
out.newLine();
// The RESOURCE note MUST have a type "results": [REQUIRED]
......@@ -324,7 +328,7 @@ public class VOTableFormat implements OutputFormat {
// Append the ADQL query at the origin of this result: [OPTIONAL]
String adqlQuery = execReport.parameters.getQuery();
if (adqlQuery != null){
out.write("<INFO name=\"QUERY\">" + VOSerializer.formatText(adqlQuery) + "</INFO>");
out.write("<INFO name=\"QUERY\"" + VOSerializer.formatAttribute("value", adqlQuery) + "/>");
out.newLine();
}
......
......@@ -86,11 +86,11 @@ public class FormatController implements InputParamController {
return getDefault();
if (service.getOutputFormat(strFormat) == null)
throw new UWSException(UWSException.BAD_REQUEST, "Unknown value for the job parameter format: \"" + strFormat + "\". It should be " + getAllowedFormats());
throw new UWSException(UWSException.BAD_REQUEST, "Unknown value for the parameter \"format\": \"" + strFormat + "\". It should be " + getAllowedFormats());
else
return strFormat;
}else
throw new UWSException(UWSException.INTERNAL_SERVER_ERROR, "Wrong type for the format parameter: class \"" + format.getClass().getName() + "\"! It should be a String.");
throw new UWSException(UWSException.INTERNAL_SERVER_ERROR, "Wrong type for the parameter \"format\": class \"" + format.getClass().getName() + "\"! It should be a String.");
}
/**
......
......@@ -103,10 +103,10 @@ public class MaxRecController implements InputParamController {
try{
maxRec = Integer.parseInt(strValue);
}catch(NumberFormatException nfe){
throw new UWSException(UWSException.BAD_REQUEST, "Wrong format for the MaxRec parameter: \"" + strValue + "\"! It should be a integer value between " + TAPJob.UNLIMITED_MAX_REC + " and " + maxOutputLimit + " (Default value: " + defaultOutputLimit + ").");
throw new UWSException(UWSException.BAD_REQUEST, "Wrong format for the parameter \"maxrec\": \"" + strValue + "\"! It should be a integer value between " + TAPJob.UNLIMITED_MAX_REC + " and " + maxOutputLimit + " (Default value: " + defaultOutputLimit + ").");
}
}else
throw new UWSException(UWSException.INTERNAL_SERVER_ERROR, "Wrong type for the MaxRec parameter: class \"" + value.getClass().getName() + "\"! It should be an integer or a string containing only an integer value.");
throw new UWSException(UWSException.INTERNAL_SERVER_ERROR, "Wrong type for the parameter \"maxrec\": class \"" + value.getClass().getName() + "\"! It should be an integer or a string containing only an integer value.");
// A negative output limit is considered as an unlimited output limit:
if (maxRec < TAPJob.UNLIMITED_MAX_REC)
......
......@@ -148,14 +148,14 @@ public class TAPDestructionTimeController implements InputParamController {
try{
date = UWSJob.dateFormat.parse(strValue);
}catch(ParseException pe){
throw new UWSException(UWSException.BAD_REQUEST, pe, "Wrong date format for the destruction time parameter: \"" + strValue + "\"! The format to respect is: " + UWSJob.DEFAULT_DATE_FORMAT);
throw new UWSException(UWSException.BAD_REQUEST, pe, "Wrong date format for the parameter \"destruction\": \"" + strValue + "\"! The format to respect is: " + UWSJob.DEFAULT_DATE_FORMAT);
}
}else
throw new UWSException(UWSException.INTERNAL_SERVER_ERROR, "Wrong type for the destruction time parameter: class \"" + value.getClass().getName() + "\"! It should be a Date or a string containing a date with the format \"" + UWSJob.DEFAULT_DATE_FORMAT + "\".");
throw new UWSException(UWSException.INTERNAL_SERVER_ERROR, "Wrong type for the parameter \"destruction\": class \"" + value.getClass().getName() + "\"! It should be a Date or a string containing a date with the format \"" + UWSJob.DEFAULT_DATE_FORMAT + "\".");
Date maxDate = getMaxDestructionTime();
if (maxDate != null && date.after(maxDate))
throw new UWSException(UWSException.BAD_REQUEST, "The TAP service limits the DESTRUCTION INTERVAL (since now) to " + getMaxRetentionPeriod() + " s !");
throw new UWSException(UWSException.BAD_REQUEST, "The TAP service limits the destruction interval (since now) to " + getMaxRetentionPeriod() + " s !");
return date;
}
......
......@@ -104,10 +104,10 @@ public class TAPExecutionDurationController implements InputParamController {
try{
duration = Long.parseLong((String)value);
}catch(NumberFormatException nfe){
throw new UWSException(UWSException.BAD_REQUEST, "Wrong format for the maximum duration parameter: \"" + value.toString() + "\"! It should be a long numeric value between " + TAPJob.UNLIMITED_DURATION + " and " + maxDuration + " (Default value: " + defaultDuration + ").");
throw new UWSException(UWSException.BAD_REQUEST, "Wrong format for the parameter \"executionduration\": \"" + value.toString() + "\"! It should be a long numeric value between " + TAPJob.UNLIMITED_DURATION + " and " + maxDuration + " (Default value: " + defaultDuration + ").");
}
}else
throw new UWSException(UWSException.INTERNAL_SERVER_ERROR, "Wrong type for the maximum duration parameter: class \"" + value.getClass().getName() + "\"! It should be long or a string containing only a long value.");
throw new UWSException(UWSException.INTERNAL_SERVER_ERROR, "Wrong type for the parameter \"executionduration\": class \"" + value.getClass().getName() + "\"! It should be long or a string containing only a long value.");
if (duration < TAPJob.UNLIMITED_DURATION)
duration = TAPJob.UNLIMITED_DURATION;
......
......@@ -81,7 +81,7 @@ public class TAPParameters extends UWSParameters {
// Multipart HTTP parameters:
if (isMultipartContent(request)){
if (!service.uploadEnabled())
throw new TAPException("Request error ! This TAP service has no Upload capability !");
throw new TAPException("Request error ! This TAP service has no Upload capability !", UWSException.BAD_REQUEST);
File uploadDir = service.getFileManager().getUploadDirectory();
try{
......@@ -287,7 +287,7 @@ public class TAPParameters extends UWSParameters {
for(int i = 0; i < pairs.length; i++){
String[] table = pairs[i].split(",");
if (table.length != 2)
throw new TAPException("UPLOAD parameter incorrect: bad syntax! An UPLOAD parameter must contain a list of pairs separated by a ';'. Each pair is composed of 2 parts, a table name and a URI separated by a ','.");
throw new TAPException("UPLOAD parameter incorrect: bad syntax! An UPLOAD parameter must contain a list of pairs separated by a ';'. Each pair is composed of 2 parts, a table name and a URI separated by a ','.", UWSException.BAD_REQUEST);
loaders[i] = new TableLoader(table[0], table[1], multipart);
}
......@@ -298,13 +298,13 @@ public class TAPParameters extends UWSParameters {
// Check that required parameters are not NON-NULL:
String requestParam = getRequest();
if (requestParam == null)
throw new TAPException("The parameter \"" + TAPJob.PARAM_REQUEST + "\" must be provided and its value must be equal to \"" + TAPJob.REQUEST_DO_QUERY + "\" or \"" + TAPJob.REQUEST_GET_CAPABILITIES + "\" !");
throw new TAPException("The parameter \"" + TAPJob.PARAM_REQUEST + "\" must be provided and its value must be equal to \"" + TAPJob.REQUEST_DO_QUERY + "\" or \"" + TAPJob.REQUEST_GET_CAPABILITIES + "\" !", UWSException.BAD_REQUEST);
if (requestParam.equals(TAPJob.REQUEST_DO_QUERY)){
if (get(TAPJob.PARAM_LANGUAGE) == null)
throw new TAPException("The parameter \"" + TAPJob.PARAM_LANGUAGE + "\" must be provided if " + TAPJob.PARAM_REQUEST + "=" + TAPJob.REQUEST_DO_QUERY + " !");
throw new TAPException("The parameter \"" + TAPJob.PARAM_LANGUAGE + "\" must be provided if " + TAPJob.PARAM_REQUEST + "=" + TAPJob.REQUEST_DO_QUERY + " !", UWSException.BAD_REQUEST);
else if (get(TAPJob.PARAM_QUERY) == null)
throw new TAPException("The parameter \"" + TAPJob.PARAM_QUERY + "\" must be provided if " + TAPJob.PARAM_REQUEST + "=" + TAPJob.REQUEST_DO_QUERY + " !");
throw new TAPException("The parameter \"" + TAPJob.PARAM_QUERY + "\" must be provided if " + TAPJob.PARAM_REQUEST + "=" + TAPJob.REQUEST_DO_QUERY + " !", UWSException.BAD_REQUEST);
}
// Check the version if needed:
......
......@@ -133,11 +133,11 @@ public class StringParamController implements InputParamController {
if (strValue.equalsIgnoreCase(v))
return v;
}
throw new UWSException(UWSException.BAD_REQUEST, "Unknown value for the job parameter " + paramName + ": \"" + strValue + "\". It should be " + getExpectedFormat());
throw new UWSException(UWSException.BAD_REQUEST, "Unknown value for the parameter \"" + paramName + "\": \"" + strValue + "\". It should be " + getExpectedFormat());
}else
return strValue;
}else
throw new UWSException(UWSException.INTERNAL_SERVER_ERROR, "Wrong type for the parameter " + paramName + ": \"" + value.getClass().getName() + "\"! It should be a String.");
throw new UWSException(UWSException.INTERNAL_SERVER_ERROR, "Wrong type for the parameter \"" + paramName + "\": \"" + value.getClass().getName() + "\"! It should be a String.");
}
/**
......@@ -146,7 +146,7 @@ public class StringParamController implements InputParamController {
* @return A string which describes the format expected by this controller.
*/
protected final String getExpectedFormat(){
if (possibleValues == null || possibleValues.length == 0){
if (possibleValues != null && possibleValues.length > 0){
StringBuffer buffer = new StringBuffer("a String value among: ");
for(int i = 0; i < possibleValues.length; i++)
buffer.append((i == 0) ? "" : ", ").append(possibleValues[i]);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment