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.workflow.serverimpl.httpconnector.handlers;
17:
18: import org.outerj.daisy.repository.Repository;
19: import org.outerj.daisy.workflow.*;
20: import org.outerj.daisy.workflow.commonimpl.WfXmlHelper;
21: import org.outerj.daisy.xmlutil.LocalSAXParserFactory;
22: import org.outerj.daisy.util.HttpConstants;
23: import org.outerj.daisy.httpconnector.spi.RequestHandlerSupport;
24: import org.outerx.daisy.x10Workflow.StartProcessDocument;
25: import org.apache.xmlbeans.XmlOptions;
26:
27: import javax.servlet.http.HttpServletRequest;
28: import javax.servlet.http.HttpServletResponse;
29: import java.util.Map;
30: import java.util.Locale;
31:
32: public class ProcessInstancesHandler extends
33: AbstractWorkflowRequestHandler {
34: public void handleRequest(Map matchMap, HttpServletRequest request,
35: HttpServletResponse response, Repository repository,
36: RequestHandlerSupport support) throws Exception {
37: WorkflowManager workflowManager = (WorkflowManager) repository
38: .getExtension("WorkflowManager");
39:
40: if (request.getMethod().equals(HttpConstants.POST)) {
41: Locale locale = WfHttpUtil.getLocale(request);
42: XmlOptions xmlOptions = new XmlOptions()
43: .setLoadUseXMLReader(LocalSAXParserFactory
44: .newXmlReader());
45: StartProcessDocument document = StartProcessDocument.Factory
46: .parse(request.getInputStream(), xmlOptions);
47: StartProcessDocument.StartProcess xml = document
48: .getStartProcess();
49:
50: TaskUpdateData taskUpdateData = null;
51: if (xml.isSetTaskUpdateData()) {
52: taskUpdateData = WfXmlHelper
53: .instantiateTaskUpdateData(xml
54: .getTaskUpdateData());
55: }
56:
57: WfProcessInstance process = workflowManager.startProcess(
58: xml.getProcessDefinitionId(), taskUpdateData, xml
59: .getInitialTransition(), locale);
60: process.getXml().save(response.getOutputStream());
61: } else {
62: response.sendError(HttpConstants._405_Method_Not_Allowed);
63: }
64: }
65:
66: public String getPathPattern() {
67: return "/process";
68: }
69: }
|