Skip to content

Commit

Permalink
vo: trim line responses from UWS services
Browse files Browse the repository at this point in the history
For single-line responses like the output from the {jobs}/(job-id)/phase
UWS endpoint, add a switch to trim trailing whitespace from the result.
The GACS TAP service was returning phases like "COMPLETED\r\n" which
didn't match "COMPLETED" that I was looking for.  I don't know whether
this trailing whitespace is strictly legal, but I posted a message
on the GWS mailing list to find out, with no response, so give GACS
the benefit of the doubt for now.
  • Loading branch information
mbtaylor authored and mmpcn committed Nov 27, 2014
1 parent 4fbfe5f commit d4e7e27
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
7 changes: 6 additions & 1 deletion ttools/src/main/uk/ac/starlink/ttools/taplint/JobStage.java
Expand Up @@ -812,14 +812,19 @@ private void checkDateTime( URL url, String txt ) {
*/
private String readTextContent( URL url, boolean mustExist ) {
byte[] buf = readContent( url, "text/plain", mustExist );
if ( buf == null ) {
return null;
}
final String txt;
try {
return buf == null ? null : new String( buf, "UTF-8" );
txt = new String( buf, "UTF-8" );
}
catch ( UnsupportedEncodingException e ) {
reporter_.report( FixedCode.F_UTF8,
"Unknown encoding UTF-8??", e );
return null;
}
return UwsJob.TRIM_TEXT ? txt.trim() : txt;
}

/**
Expand Down
13 changes: 13 additions & 0 deletions vo/src/main/uk/ac/starlink/vo/UwsJob.java
Expand Up @@ -46,6 +46,16 @@ public class UwsJob {
/** Chunk size for HTTP transfer encoding; if <=0, don't chunk. */
public static int HTTP_CHUNK_SIZE = 1024 * 1024;

/**
* Whether to trim whitespace from line text responses (like job/phase).
* I'm not sure whether (trailing) whitespace is permitted in service
* responses in this context, but the ESAC GACS service appends "\r\n"
* to its phase endpoint result.
* I asked (17-Sep-2014) on the grid@ivoa.net mailing list what's the
* right answer, but no response, so accept trailing whitespace for now.
*/
public static boolean TRIM_TEXT = true;

/**
* Constructor.
*
Expand Down Expand Up @@ -171,6 +181,9 @@ public void readPhase() throws IOException {
}
in.close();
String phase = sbuf.toString();
if ( TRIM_TEXT ) {
phase = phase.trim();
}
logger_.info( phaseUrl + " phase: " + phase );
phase_ = phase;
phaseTime_ = System.currentTimeMillis();
Expand Down

0 comments on commit d4e7e27

Please sign in to comment.