Skip to content
This repository was archived by the owner on Jun 2, 2022. It is now read-only.

Commit 670785c

Browse files
committed
Merge branch 'standalone-cs'
Conflicts: .gitignore
2 parents 72c2096 + 571f05f commit 670785c

21 files changed

+255
-480
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
.settings
44
target
55
*~
6+

pom.xml

+40-21
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>taskworker</groupId>
55
<artifactId>examples</artifactId>
6-
<version>0.0.1-SNAPSHOT</version>
6+
<version>0.2.0-SNAPSHOT</version>
77

88
<properties>
9-
<appengine.app.version>1</appengine.app.version>
10-
<appengine.target.version>1.7.5</appengine.target.version>
119
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1210
</properties>
1311

@@ -37,13 +35,17 @@
3735
<dependency>
3836
<groupId>taskworker</groupId>
3937
<artifactId>core</artifactId>
40-
<version>0.0.1-SNAPSHOT</version>
41-
</dependency>
42-
<dependency>
43-
<groupId>com.google.appengine</groupId>
44-
<artifactId>appengine-api-1.0-sdk</artifactId>
45-
<version>${appengine.target.version}</version>
46-
<scope>provided</scope>
38+
<version>0.2.0-SNAPSHOT</version>
39+
<exclusions>
40+
<exclusion>
41+
<artifactId>servlet-api</artifactId>
42+
<groupId>javax.servlet</groupId>
43+
</exclusion>
44+
<exclusion>
45+
<artifactId>jetty</artifactId>
46+
<groupId>org.mortbay.jetty</groupId>
47+
</exclusion>
48+
</exclusions>
4749
</dependency>
4850

4951
<!-- deps used by the workers -->
@@ -69,12 +71,12 @@
6971
<version>1.7.2</version>
7072
</dependency>
7173

72-
<dependency>
73-
<!-- need this newer version, instead of the one used by astyanax -->
74-
<groupId>org.jboss.spec.javax.servlet</groupId>
75-
<artifactId>jboss-servlet-api_3.0_spec</artifactId>
76-
<version>1.0.2.Final</version>
77-
</dependency>
74+
<dependency>
75+
<groupId>org.apache.tomcat</groupId>
76+
<artifactId>tomcat-servlet-api</artifactId>
77+
<version>7.0.21</version>
78+
<scope>provided</scope>
79+
</dependency>
7880
</dependencies>
7981

8082
<build>
@@ -114,12 +116,29 @@
114116
</configuration>
115117

116118
</plugin>
117-
119+
118120
<plugin>
119-
<groupId>com.google.appengine</groupId>
120-
<artifactId>appengine-maven-plugin</artifactId>
121-
<version>${appengine.target.version}</version>
122-
</plugin>
121+
<artifactId>maven-assembly-plugin</artifactId>
122+
<configuration>
123+
<archive>
124+
<manifest>
125+
<mainClass>drm.taskworker.App</mainClass>
126+
</manifest>
127+
</archive>
128+
<descriptorRefs>
129+
<descriptorRef>jar-with-dependencies</descriptorRef>
130+
</descriptorRefs>
131+
</configuration>
132+
<executions>
133+
<execution>
134+
<id>make-assembly</id> <!-- this is used for inheritance merges -->
135+
<phase>package</phase> <!-- bind to the packaging phase -->
136+
<goals>
137+
<goal>single</goal>
138+
</goals>
139+
</execution>
140+
</executions>
141+
</plugin>
123142

124143
<plugin>
125144
<groupId>com.mycila.maven-license-plugin</groupId>

src/main/java/drm/demo/DownloadServlet.java

-72
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
Copyright 2013 KU Leuven Research and Development - iMinds - Distrinet
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
16+
Administrative Contact: [email protected]
17+
Technical Contact: [email protected]
18+
*/
19+
20+
package drm.taskworker.web;
21+
22+
import java.io.BufferedInputStream;
23+
import java.io.BufferedOutputStream;
24+
import java.io.BufferedReader;
25+
import java.io.File;
26+
import java.io.FileInputStream;
27+
import java.io.FileNotFoundException;
28+
import java.io.FileOutputStream;
29+
import java.io.IOException;
30+
import java.io.InputStream;
31+
import java.io.InputStreamReader;
32+
import java.io.OutputStream;
33+
34+
import javax.servlet.ServletException;
35+
import javax.servlet.ServletOutputStream;
36+
import javax.servlet.http.HttpServlet;
37+
import javax.servlet.http.HttpServletRequest;
38+
import javax.servlet.http.HttpServletResponse;
39+
40+
import org.apache.commons.io.IOUtils;
41+
42+
/**
43+
* Servlet implementation class DownloadServlet
44+
*/
45+
public class DownloadServlet extends HttpServlet {
46+
/**
47+
* @see HttpServlet#HttpServlet()
48+
*/
49+
public DownloadServlet() {
50+
super();
51+
}
52+
53+
/**
54+
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
55+
* response)
56+
*/
57+
protected void doGet(HttpServletRequest request,
58+
HttpServletResponse response) throws ServletException, IOException {
59+
String id = request.getParameter("id");
60+
61+
// totally insecure storage!
62+
File file = new File("/tmp/" + id);
63+
64+
if (file.canRead()) {
65+
byte[] result = new byte[(int)file.length()];
66+
try {
67+
InputStream input = null;
68+
ServletOutputStream outStream = null;
69+
try {
70+
int totalBytesRead = 0;
71+
input = new BufferedInputStream(new FileInputStream(file));
72+
73+
while(totalBytesRead < result.length){
74+
int bytesRemaining = result.length - totalBytesRead;
75+
//input.read() returns -1, 0, or more :
76+
int bytesRead = input.read(result, totalBytesRead, bytesRemaining);
77+
if (bytesRead > 0){
78+
totalBytesRead = totalBytesRead + bytesRead;
79+
}
80+
}
81+
response.setContentType("application/zip");
82+
response.setContentLength(result.length);
83+
// sets HTTP header
84+
response.setHeader("Content-Disposition", "attachment; filename=\"result.zip\"");
85+
86+
outStream = response.getOutputStream();
87+
outStream.write(result, 0, result.length);
88+
89+
} finally {
90+
input.close();
91+
outStream.close();
92+
}
93+
} catch (IOException e) {
94+
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
95+
}
96+
} else {
97+
response.sendError(HttpServletResponse.SC_NOT_FOUND);
98+
}
99+
}
100+
101+
protected void doPut(HttpServletRequest req, HttpServletResponse resp)
102+
throws ServletException, IOException {
103+
String id = req.getParameter("id");
104+
105+
File file = new File("/tmp/" + id);
106+
107+
InputStream is = req.getInputStream();
108+
OutputStream os = new FileOutputStream(file);
109+
IOUtils.copy(is, os);
110+
is.close();
111+
os.close();
112+
}
113+
}

src/main/java/drm/demo/MonitorServlet.java renamed to src/main/java/drm/taskworker/web/MonitorServlet.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,16 @@
1717
* Administrative Contact: [email protected]
1818
* Technical Contact: [email protected]
1919
*/
20-
package drm.demo;
20+
package drm.taskworker.web;
2121

2222
import java.io.IOException;
23-
import java.util.ArrayList;
24-
import java.util.List;
2523

2624
import javax.servlet.ServletException;
2725
import javax.servlet.annotation.WebServlet;
2826
import javax.servlet.http.HttpServlet;
2927
import javax.servlet.http.HttpServletRequest;
3028
import javax.servlet.http.HttpServletResponse;
3129

32-
import drm.taskworker.tasks.WorkflowInstance;
33-
3430
/**
3531
* Servlet implementation class Workflow
3632
*/

src/main/java/drm/demo/StartWorkflowServlet.java renamed to src/main/java/drm/taskworker/web/StartWorkflowServlet.java

+21-20
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@
1717
Technical Contact: [email protected]
1818
*/
1919

20-
package drm.demo;
20+
package drm.taskworker.web;
2121

2222
import java.io.IOException;
23+
import java.io.InputStream;
24+
import java.io.StringWriter;
2325
import java.util.Date;
24-
import java.util.List;
25-
import java.util.Map;
2626

2727
import javax.servlet.ServletException;
28+
import javax.servlet.annotation.MultipartConfig;
2829
import javax.servlet.annotation.WebServlet;
2930
import javax.servlet.http.HttpServlet;
3031
import javax.servlet.http.HttpServletRequest;
3132
import javax.servlet.http.HttpServletResponse;
33+
import javax.servlet.http.Part;
3234

33-
import com.google.appengine.api.blobstore.BlobKey;
34-
import com.google.appengine.api.blobstore.BlobstoreService;
35-
import com.google.appengine.api.blobstore.BlobstoreServiceFactory;
35+
import org.apache.commons.io.IOUtils;
3636

3737
import drm.taskworker.Job;
3838
import drm.taskworker.Service;
@@ -47,10 +47,8 @@
4747
* @author Bart Vanbrabant <[email protected]>
4848
*/
4949
@WebServlet("/start")
50+
@MultipartConfig
5051
public class StartWorkflowServlet extends HttpServlet {
51-
private BlobstoreService blobstoreService = BlobstoreServiceFactory
52-
.getBlobstoreService();
53-
5452
/**
5553
* @see HttpServlet#HttpServlet()
5654
*/
@@ -66,8 +64,6 @@ private String[] getWorkflows() {
6664
return workflowNames;
6765
}
6866

69-
70-
7167
/**
7268
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
7369
* response)
@@ -80,28 +76,33 @@ protected void doGet(HttpServletRequest request,
8076
request.getRequestDispatcher("/start.jsp").forward(request, response);
8177
}
8278

83-
84-
8579
/**
8680
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
8781
* response)
8882
*/
8983
@Override
9084
protected void doPost(HttpServletRequest request,
9185
HttpServletResponse response) throws ServletException, IOException {
92-
Map<String, List<BlobKey>> blobKeys =
93-
blobstoreService.getUploads(request);
9486

9587
Object data = null;
9688
String textField = request.getParameter("text");
97-
if (blobKeys.size() == 1 && blobKeys.containsKey("file")) {
98-
List<BlobKey> keys = blobKeys.get("file");
99-
data = keys.get(0);
100-
} else if (textField != null && textField.length() > 0) {
89+
90+
Part filePart = request.getPart("file"); // Retrieves <input type="file" name="file">
91+
92+
if (filePart != null) {
93+
InputStream filecontent = filePart.getInputStream();
94+
95+
StringWriter writer = new StringWriter();
96+
IOUtils.copy(filecontent, writer, "utf-8");
97+
data = writer.toString();
98+
}
99+
else if (textField != null && textField.length() > 0) {
101100
data = request.getParameter("text");
102-
} else {
101+
}
102+
else {
103103
request.setAttribute("error", "Either file or text should be provided.");
104104
}
105+
105106
if (data != null) {
106107
// get the delay
107108
int delay = Integer.valueOf(request.getParameter("date"));

0 commit comments

Comments
 (0)