Skip to content

Commit

Permalink
fix: publish the files as internal files
Browse files Browse the repository at this point in the history
  • Loading branch information
mosoriob committed Jun 12, 2023
1 parent 2a713d2 commit 99f06c6
Show file tree
Hide file tree
Showing 7 changed files with 247 additions and 162 deletions.
2 changes: 1 addition & 1 deletion planner/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<properties>
<jsch.version>0.1.53</jsch.version>
<ontapi.version>1.3.0</ontapi.version>
<ontapi.version>1.3.1</ontapi.version>
<nanocloud.version>0.8.11</nanocloud.version>
<gson.version>2.2.4</gson.version>
<junit.version>4.5</junit.version>
Expand Down
2 changes: 1 addition & 1 deletion portal/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<properties>
<!-- rewrite.version>2.0.12.Final</rewrite.version -->
<wings-opmm.version>1.2.6</wings-opmm.version>
<wings-opmm.version>1.2.7</wings-opmm.version>
<servlet-api.version>2.5</servlet-api.version>
<httpclient.version>4.5.2</httpclient.version>
<jersey.version>2.27</jersey.version>
Expand Down
287 changes: 151 additions & 136 deletions portal/src/main/java/edu/isi/wings/portal/classes/config/Config.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import edu.isi.kcap.wings.opmm.WorkflowExecutionExport;
import edu.isi.kcap.wings.opmm.WorkflowTemplateExport;
import edu.isi.kcap.wings.opmm.DataTypes.Links;
import edu.isi.kcap.wings.opmm.DataTypes.ProvenanceResponseSchema;
import edu.isi.kcap.ontapi.KBTriple;
import edu.isi.wings.catalog.component.ComponentFactory;
import edu.isi.wings.catalog.data.DataFactory;
Expand Down Expand Up @@ -537,11 +538,11 @@ private String urlToString(URL url) {
* @return
* @throws Exception
*/
public HashMap<String, Links> publishRun(String runid) throws Exception {
public ProvenanceResponseSchema publishRun(String runid) throws Exception {
HashMap<String, String> retmap = new HashMap<String, String>();
ExecutionMonitorAPI monitor = config.getDomainExecutionMonitor();
RuntimePlan plan = monitor.getRunDetails(runid);
HashMap<String, Links> response = null;
ProvenanceResponseSchema response = null;
if (plan.getRuntimeInfo().getStatus() != Status.SUCCESS) {
throw new Exception("Can only publish successfully completed runs");
} else
Expand Down Expand Up @@ -662,12 +663,6 @@ public HashMap<String, Links> publishRun(String runid) throws Exception {
componentLibraryFilePath.getAbsolutePath(), planFilePath.getAbsolutePath(),
endpointQueryURI, endpointPostURI, executionFilePath, expandedTemplateFilePath, abstractFilePath,
filePublisher, serialization);
System.out.println(executionFilePath);
System.out.println(expandedTemplateFilePath);
System.out.println(abstractFilePath);

System.out.println("Response: " + response);
System.out.println("Published ended");
} catch (Exception e) {
throw new Exception("Error publishing run: " + e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.google.gson.Gson;

import edu.isi.kcap.wings.opmm.DataTypes.Links;
import edu.isi.kcap.wings.opmm.DataTypes.ProvenanceResponseSchema;
import edu.isi.wings.portal.classes.util.TemplateBindings;
import edu.isi.wings.portal.controllers.RunController;

Expand Down Expand Up @@ -181,11 +182,9 @@ public String publishRun(
@FormParam("run_id") String run_id) {
if (this.rc != null) {
try {
HashMap<String, Links> responseQuery = this.rc.publishRun(run_id);
ProvenanceResponseSchema responseQuery = this.rc.publishRun(run_id);
Gson gson = new Gson();
String json = gson.toJson(responseQuery);
Links catalog = responseQuery.get("catalog");
System.out.println(json);
return json;
} catch (Exception e) {
// TODO Auto-generated catch block
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package edu.isi.wings.portal.servlets;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import edu.isi.wings.portal.classes.config.Config;

public class ProvenanceFileServlet extends HttpServlet {

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Config config = new Config(request, null, null);
String provenanceDirectoryPath = config.getProvenanceDirectory();
File provenanceDirectory = new File(provenanceDirectoryPath);

String requestFile = request.getPathInfo();
String filePath = provenanceDirectoryPath + File.separator + requestFile;
System.out.println("FileServlet: " + filePath);

File file = new File(filePath);
if (!file.exists()) {
response.sendError(HttpServletResponse.SC_NOT_FOUND); // 404.
return;
}
// check if filepath is in allowed directory
if (!isInsideDirectory(file, provenanceDirectory)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
// Set content type and headers for the response
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment; filename=\"" + file.getName() + "\"");

// Read the file and write its contents to the response output stream
try (FileInputStream fis = new FileInputStream(filePath);
OutputStream out = response.getOutputStream()) {
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = fis.read(buffer)) != -1) {
out.write(buffer, 0, bytesRead);
}
} catch (IOException e) {
// Handle exception
e.printStackTrace();
}
}

private static boolean isInsideDirectory(File file, File directory) {
File parent = file.getParentFile();
if (parent == null) {
return false;
} else if (parent.equals(directory)) {
return true;
} else {
return isInsideDirectory(parent, directory);
}
}
}
37 changes: 24 additions & 13 deletions portal/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:web="http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee">
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:web="http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee">
<display-name>Wings Portal</display-name>
<servlet>
<description>Login page</description>
Expand All @@ -14,7 +14,7 @@
<servlet-name>Login</servlet-name>
<url-pattern>/login/*</url-pattern>
</servlet-mapping>

<servlet>
<description>Servlet to Export Graph</description>
<display-name>Graph Exporter</display-name>
Expand All @@ -26,6 +26,17 @@
<url-pattern>/export/*</url-pattern>
</servlet-mapping>

<servlet>
<description>Servlet to obtain the Provenance Files</description>
<display-name>Provenance Files</display-name>
<servlet-name>ProvenanceFile</servlet-name>
<servlet-class>edu.isi.wings.portal.servlets.ProvenanceFileServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ProvenanceFile</servlet-name>
<url-pattern>/provenance/*</url-pattern>
</servlet-mapping>

<servlet>
<description></description>
<display-name>SparqlEndpoint</display-name>
Expand All @@ -36,7 +47,7 @@
<servlet-name>SparqlEndpoint</servlet-name>
<url-pattern>/sparql</url-pattern>
</servlet-mapping>

<servlet>
<description>Wings Config</description>
<display-name>Wings config</display-name>
Expand All @@ -46,9 +57,9 @@
<servlet-mapping>
<servlet-name>ViewConfig</servlet-name>
<url-pattern>/config</url-pattern>
</servlet-mapping>
<!--
</servlet-mapping>

<!--
CORS & Compression filters for Non-REST-API servlets
The Jersey REST-APIs have their own filters and interceptors
-->
Expand Down Expand Up @@ -78,11 +89,11 @@
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>

<session-config>
<session-timeout>43200</session-timeout>
</session-config>

<security-role>
<role-name>WingsUser</role-name>
</security-role>
Expand Down Expand Up @@ -111,13 +122,13 @@
<role-name>WingsAdmin</role-name>
</auth-constraint>
</security-constraint>

<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/jsp/login/login.jsp</form-login-page>
<form-error-page>/jsp/login/login_failed.jsp</form-error-page>
</form-login-config>
</login-config>
</web-app>

</web-app>

0 comments on commit 99f06c6

Please sign in to comment.