📄 restworksession.java
字号:
/* * Copyright (c) 2005, John Mettraux, OpenWFE.org * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * . Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * . Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * . Neither the name of the "OpenWFE" nor the names of its contributors may be * used to endorse or promote products derived from this software without * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * $Id: RestWorkSession.java,v 1.8 2005/05/17 16:41:04 jmettraux Exp $ *///// RestWorkSession.java//// john.mettraux@openwfe.org//// generated with // jtmpl 1.0.04 31.10.2002 John Mettraux (jmettraux@openwfe.org)//package openwfe.org.worklist.impl;import java.nio.channels.SelectionKey;import openwfe.org.ServiceException;import openwfe.org.ApplicationContext;import openwfe.org.rmi.session.WorkSessionServer;import openwfe.org.rmi.session.WorkSessionServerImpl;import openwfe.org.rest.RestUtils;import openwfe.org.rest.RestService;import openwfe.org.rest.RmiBridgedRestSession;import openwfe.org.engine.workitem.LaunchItem;import openwfe.org.engine.workitem.InFlowWorkItem;import openwfe.org.engine.workitem.WorkItemCoderLoader;import openwfe.org.engine.expressions.FlowExpressionId;import openwfe.org.worklist.Launchable;import openwfe.org.worklist.WorkSession;import openwfe.org.worklist.WorkListException;import openwfe.org.worklist.impl.XmlWorkItemAndHeaderCoder;/** * An association with a rmi worksession * * <p><font size=2>CVS Info : * <br>$Author: jmettraux $ * <br>$Date: 2005/05/17 16:41:04 $ * <br>$Id: RestWorkSession.java,v 1.8 2005/05/17 16:41:04 jmettraux Exp $ </font> * * @author john.mettraux@openwfe.org */public class RestWorkSession extends RmiBridgedRestSession{ private final static org.apache.log4j.Logger log = org.apache.log4j.Logger .getLogger(RestWorkSession.class.getName()); // // CONSTANTS and DEFINITIONS private final static String E_LAUNCHABLES = "launchables"; private final static String E_LAUNCHABLE = "launchable"; private final static String A_ENGINE_ID = "engine-id"; private final static String A_URL = "url"; // // FIELDS private WorkSession session = null; private XmlWorkItemAndHeaderCoder coder = null; // // CONSTRUCTORS public void init (final RestService service, final Long sessionId, final String username, final String password) throws ServiceException { super.init(service, sessionId, username, password); // // locating the coder that will be used final WorkItemCoderLoader loader = openwfe.org.engine.Definitions .getWorkItemCoderLoader(this.service.getContext()); log.debug("init() loader is "+loader); this.coder = (XmlWorkItemAndHeaderCoder)loader.getXmlCoder(); log.info ("HeaderCoder successfully located"); } // // METHODS from RestSession protected boolean authentify (final String username, final String password) throws ServiceException { try { this.session = (WorkSession)getWorkSessionServer() .login(username, password); } catch (final Exception e) { throw new ServiceException("login failed", e); } return true; } // // METHODS // // session methods public void do_getstorenames (final SelectionKey key, final String firstLine, final byte[] request) throws Exception { do_liststores(key, firstLine, request); } public void do_liststores (final SelectionKey key, final String firstLine, final byte[] request) throws Exception { java.util.List storeNames = this.session.getStoreNames(); org.jdom.Element eStores = new org.jdom.Element("stores"); java.util.Iterator it = storeNames.iterator(); while (it.hasNext()) { eStores.addContent(buildStoreElement((String)it.next())); } reply(key, eStores); } protected org.jdom.Element buildStoreElement (String storeName) throws Exception { int count = 0; try { count = this.session.countWorkItems(storeName); } catch (java.security.AccessControlException ace) { // ignore } String permissionString = ""; try { if (this.session.checkPermission(storeName, "read")) permissionString += "r"; } catch (java.security.AccessControlException ace) { // ignore } try { if (this.session.checkPermission(storeName, "write")) permissionString += "w"; } catch (java.security.AccessControlException ace) { // ignore } try { if (this.session.checkPermission(storeName, "delegate")) permissionString += "d"; } catch (java.security.AccessControlException ace) { // ignore } try { if (this.session.checkPermission(storeName, "browse")) permissionString += "b"; } catch (java.security.AccessControlException ace) { // ignore } org.jdom.Element elt = new org.jdom.Element("store"); elt.setAttribute("name", storeName); elt.setAttribute("workitem-count", ""+count); elt.setAttribute("permissions", permissionString); return elt; } public void do_getheaders (final SelectionKey key, final String firstLine, final byte[] request) throws Exception { final String storeName = extractStoreName(firstLine); int limit = -1; try { limit = Integer.parseInt (RestUtils.extractFromLine(firstLine, "limit")); } catch (Exception e) { // ignore } final java.util.List headers = this.session.getHeaders(storeName, limit); reply(key, getCoder().encodeHeadersAsXml(headers)); } public void do_findflowinstance (final SelectionKey key, final String firstLine, final byte[] request) throws Exception { String storeName = extractStoreName(firstLine); String wfid = null; try { wfid = RestUtils.extractFromLine(firstLine, "id"); } catch (Exception e) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -