Skip to content

Commit

Permalink
Added results servlet / deprecated Authenticator
Browse files Browse the repository at this point in the history
  • Loading branch information
stvoutsin committed Jun 20, 2024
1 parent 3efea2a commit 3e80aa2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 11 deletions.
10 changes: 3 additions & 7 deletions tap/src/main/java/ca/nrc/cadc/sample/AuthenticatorImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,10 @@
import org.apache.log4j.Logger;

/**
* Implementes the Authenticator for processing Gafaelfawr auth,
* and using it to authenticate against the TAP service.
*
* The token in the authorization header is used to make a call
* to Gafaelfawr to retrieve details such as the uid and uidNumber.
*
* @author cbanek
* @deprecated This class is deprecated and will be removed in future releases.
* The TAP Service now uses IdentityManager for authentication, available in the opencadc library
*/
@Deprecated
public class AuthenticatorImpl implements Authenticator
{
private static final Logger log = Logger.getLogger(AuthenticatorImpl.class);
Expand Down
9 changes: 5 additions & 4 deletions tap/src/main/java/ca/nrc/cadc/sample/ResultStoreImpl.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/*
************************************************************************
******************* CANADIAN ASTRONOMY DATA CENTRE *******************
Expand Down Expand Up @@ -94,7 +93,8 @@ public class ResultStoreImpl implements ResultStore {
private String filename;
private static final String bucket = System.getProperty("gcs_bucket");
private static final String bucketURL = System.getProperty("gcs_bucket_url");

private static final String baseURL = System.getProperty("base_url");
private static final String pathPrefix = System.getProperty("path_prefix");

@Override
public URL put(final ResultSet resultSet,
Expand Down Expand Up @@ -135,14 +135,14 @@ public URL put(final ResultSet resultSet,
private OutputStream getOutputStream() {
Storage storage = StorageOptions.getDefaultInstance().getService();
BlobId blobId = BlobId.of(bucket, filename);

BlobInfo blobInfo = BlobInfo.newBuilder(blobId).setContentType("application/x-votable+xml").build();
Blob blob = storage.create(blobInfo);
return Channels.newOutputStream(blob.writer());
}

private URL getURL() throws MalformedURLException {
URL bucket = new URL(bucketURL);
return new URL(bucket, filename);
return new URL(baseURL + pathPrefix + "/results/" + filename);
}

@Override
Expand All @@ -157,4 +157,5 @@ public void setJob(Job _job) {
public void setFilename(String filename) {
this.filename = filename;
}

}
37 changes: 37 additions & 0 deletions tap/src/main/java/ca/nrc/cadc/sample/ResultsServlet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package ca.nrc.cadc.sample;

import org.apache.log4j.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
* A servlet that handles redirecting to specific job results.
* This servlet extracts the VOTable file name from the request path and constructs a URL to redirect the client.
*
* @author stvoutsin
*/
public class ResultsServlet extends HttpServlet {
private static final Logger log = Logger.getLogger(ResultsServlet.class);
private static final String bucketURL = System.getProperty("gcs_bucket_url");

/**
* Processes GET requests by extracting the result filename from the request path and redirecting to the corresponding results URL.
* The filename is assumed to be the path info of the request URL, following the first '/' character.
*
* @param request the HttpServletRequest object that contains the request
* @param response the HttpServletResponse object that contains the response
* @throws ServletException if an input or output error is detected when the servlet handles the GET request
* @throws IOException if the request for the GET could not be handled
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String path = request.getPathInfo();
String resultsFile = path.substring(1);
String redirectUrl = bucketURL + "/" + resultsFile;
log.debug("Redirect URL: " + redirectUrl);
response.sendRedirect(redirectUrl);
}
}

0 comments on commit 3e80aa2

Please sign in to comment.