01: /*
02: * Copyright 2007 Outerthought bvba and Schaubroeck nv
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: package org.outerj.daisy.doctaskrunner.serverimpl.httphandlers;
17:
18: import org.outerj.daisy.httpconnector.spi.HttpUtil;
19: import org.outerj.daisy.httpconnector.spi.RequestHandlerSupport;
20: import org.outerj.daisy.repository.Repository;
21: import org.outerj.daisy.doctaskrunner.Task;
22: import org.outerj.daisy.doctaskrunner.TaskException;
23: import org.outerj.daisy.doctaskrunner.DocumentTaskManager;
24: import org.outerj.daisy.util.HttpConstants;
25:
26: import javax.servlet.http.HttpServletRequest;
27: import javax.servlet.http.HttpServletResponse;
28: import java.util.Map;
29:
30: public class TaskHandler extends AbstractDocTaskRequestHandler {
31: public void handleRequest(Map matchMap, HttpServletRequest request,
32: HttpServletResponse response, Repository repository,
33: RequestHandlerSupport support) throws Exception {
34: DocumentTaskManager taskManager = (DocumentTaskManager) repository
35: .getExtension("DocumentTaskManager");
36: long taskId = HttpUtil.parseId("task", (String) matchMap
37: .get("1"));
38: if (request.getMethod().equals(HttpConstants.GET)) {
39: Task task = taskManager.getTask(taskId);
40: task.getXml().save(response.getOutputStream());
41: } else if (request.getMethod().equals(HttpConstants.POST)) {
42: String action = HttpUtil.getStringParam(request, "action");
43: if (action.equals("interrupt")) {
44: taskManager.interruptTask(taskId);
45: } else {
46: throw new TaskException(
47: "Unsupported action parameter: " + action);
48: }
49: } else if (request.getMethod().equals(HttpConstants.DELETE)) {
50: taskManager.deleteTask(taskId);
51: } else {
52: response.sendError(HttpConstants._405_Method_Not_Allowed);
53: }
54: }
55:
56: public String getPathPattern() {
57: return "/task/*";
58: }
59: }
|