Skip to content

Commit 3e80aa2

Browse files
committed
Added results servlet / deprecated Authenticator
1 parent 3efea2a commit 3e80aa2

File tree

3 files changed

+45
-11
lines changed

3 files changed

+45
-11
lines changed

tap/src/main/java/ca/nrc/cadc/sample/AuthenticatorImpl.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,10 @@
2929
import org.apache.log4j.Logger;
3030

3131
/**
32-
* Implementes the Authenticator for processing Gafaelfawr auth,
33-
* and using it to authenticate against the TAP service.
34-
*
35-
* The token in the authorization header is used to make a call
36-
* to Gafaelfawr to retrieve details such as the uid and uidNumber.
37-
*
38-
* @author cbanek
32+
* @deprecated This class is deprecated and will be removed in future releases.
33+
* The TAP Service now uses IdentityManager for authentication, available in the opencadc library
3934
*/
35+
@Deprecated
4036
public class AuthenticatorImpl implements Authenticator
4137
{
4238
private static final Logger log = Logger.getLogger(AuthenticatorImpl.class);

tap/src/main/java/ca/nrc/cadc/sample/ResultStoreImpl.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/*
32
************************************************************************
43
******************* CANADIAN ASTRONOMY DATA CENTRE *******************
@@ -94,7 +93,8 @@ public class ResultStoreImpl implements ResultStore {
9493
private String filename;
9594
private static final String bucket = System.getProperty("gcs_bucket");
9695
private static final String bucketURL = System.getProperty("gcs_bucket_url");
97-
96+
private static final String baseURL = System.getProperty("base_url");
97+
private static final String pathPrefix = System.getProperty("path_prefix");
9898

9999
@Override
100100
public URL put(final ResultSet resultSet,
@@ -135,14 +135,14 @@ public URL put(final ResultSet resultSet,
135135
private OutputStream getOutputStream() {
136136
Storage storage = StorageOptions.getDefaultInstance().getService();
137137
BlobId blobId = BlobId.of(bucket, filename);
138+
138139
BlobInfo blobInfo = BlobInfo.newBuilder(blobId).setContentType("application/x-votable+xml").build();
139140
Blob blob = storage.create(blobInfo);
140141
return Channels.newOutputStream(blob.writer());
141142
}
142143

143144
private URL getURL() throws MalformedURLException {
144-
URL bucket = new URL(bucketURL);
145-
return new URL(bucket, filename);
145+
return new URL(baseURL + pathPrefix + "/results/" + filename);
146146
}
147147

148148
@Override
@@ -157,4 +157,5 @@ public void setJob(Job _job) {
157157
public void setFilename(String filename) {
158158
this.filename = filename;
159159
}
160+
160161
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package ca.nrc.cadc.sample;
2+
3+
import org.apache.log4j.Logger;
4+
import javax.servlet.ServletException;
5+
import javax.servlet.http.HttpServlet;
6+
import javax.servlet.http.HttpServletRequest;
7+
import javax.servlet.http.HttpServletResponse;
8+
import java.io.IOException;
9+
10+
/**
11+
* A servlet that handles redirecting to specific job results.
12+
* This servlet extracts the VOTable file name from the request path and constructs a URL to redirect the client.
13+
*
14+
* @author stvoutsin
15+
*/
16+
public class ResultsServlet extends HttpServlet {
17+
private static final Logger log = Logger.getLogger(ResultsServlet.class);
18+
private static final String bucketURL = System.getProperty("gcs_bucket_url");
19+
20+
/**
21+
* Processes GET requests by extracting the result filename from the request path and redirecting to the corresponding results URL.
22+
* The filename is assumed to be the path info of the request URL, following the first '/' character.
23+
*
24+
* @param request the HttpServletRequest object that contains the request
25+
* @param response the HttpServletResponse object that contains the response
26+
* @throws ServletException if an input or output error is detected when the servlet handles the GET request
27+
* @throws IOException if the request for the GET could not be handled
28+
*/
29+
@Override
30+
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
31+
String path = request.getPathInfo();
32+
String resultsFile = path.substring(1);
33+
String redirectUrl = bucketURL + "/" + resultsFile;
34+
log.debug("Redirect URL: " + redirectUrl);
35+
response.sendRedirect(redirectUrl);
36+
}
37+
}

0 commit comments

Comments
 (0)