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 24, 2024
1 parent 3efea2a commit 1cd10d3
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 11 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ Find changes for the upcoming release in the project's [changelog.d](https://git

<!-- scriv-insert-here -->

<a id='changelog-1.18.0'></a>
## 1.18.0 (2024-06-24)

### Changed

- Change result handling, to use a redirect servlet. Addresses issue with async failing due to auth header propagation with clients like pyvo, topcat


<a id='changelog-1.17.3'></a>
## 1.17.3 (2024-06-18)

Expand Down
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;
}

}
50 changes: 50 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,50 @@
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 {
try {
String path = request.getPathInfo();
String redirectUrl = generateRedirectUrl(bucketURL, path);
response.sendRedirect(redirectUrl);
} catch (Exception e) {
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "An error occurred while processing the request.");
}
}

/**
* Generates the redirect URL based on a path.
*
* @param path the request path
* @return the redirect URL constructed using the bucket URL and results file
*/
private String generateRedirectUrl(String bucketUrlString, String path) {
String resultsFile = path.substring(1);
return bucketUrlString + "/" + resultsFile;
}
}
11 changes: 11 additions & 0 deletions tap/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,17 @@
<servlet-name>SyncServlet</servlet-name>
<url-pattern>/sync/*</url-pattern>
</servlet-mapping>

<servlet>
<servlet-name>ResultsServlet</servlet-name>
<servlet-class>ca.nrc.cadc.sample.ResultsServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>ResultsServlet</servlet-name>
<url-pattern>/results/*</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>AsyncServlet</servlet-name>
<url-pattern>/async/*</url-pattern>
Expand Down

0 comments on commit 1cd10d3

Please sign in to comment.