/** * Same thing a extractParams(), but it works with * HttpServletRequest.getQueryString() returns (which don't entail the * '/documentation.pl?' part). */ public static java.util.Map extractParamsFromQueryString (final String line) { return extractParams("?"+line); }
public void init (final RestService service, final Long sessionId, final String username, final String password) throws ServiceException { this.service = service; this.sessionId = sessionId; touch(); authentify(username, password); }
/** * Determines how many bytes are still to be read. */ public static int determineBytesToRead (final String[] headers) { /* final int headerLength = extractNumericHeaderValue(headers, K_HEADER_LENGTH); final int contentLength = extractNumericHeaderValue(headers, K_CONTENT_LENGTH); log.debug ("determineBytesToRead() hl : "+headerLength+ " cl : "+contentLength+ " delta = "+(contentLength - headerLength)); return contentLength - headerLength; */ return extractNumericHeaderValue(headers, K_CONTENT_LENGTH); }
touch(); action = RestUtils.extractFromLine(firstLine, "action"); 400, "Bad Request", this.service.getServerName(), null, "text/plain", this.service.removeSession(this.sessionId); 200, "OK", this.service.getServerName(), null, "text/xml", if (evalRequest(action, key, headers)) return; 400, "Bad Request", this.service.getServerName(), null, "text/plain", he.getErrorCode(), he.getMessage(), this.service.getServerName(),
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.getService().getContext()); if (log.isDebugEnabled()) log.debug("init() loader is "+loader); this.coder = (XmlWorkItemAndHeaderCoder)loader.getXmlCoder(); log.info ("HeaderCoder successfully located"); }
/** * Returns the WorkSessionServer instance serving logins to the RMI * WorkSessions. */ protected WorkSessionServer getWorkSessionServer () throws Exception { WorkSessionServer result = (WorkSessionServer)this.getService() .getContext().lookup(sessionServerKey); if (result != null) return result; // // instantiating the workSessionServer result = new WorkSessionServerImpl(); ((Service)result).init (this.sessionServerKey, this.getService().getContext(), this.getService().getParams()); this.getService().getContext() .put(this.sessionServerKey, result); return result; }
/** * Extracts the session id out of the first request line. */ protected static Long extractSessionId (final String firstLine) throws java.io.IOException { try { final String value = RestUtils.extractFromLine (firstLine, "session"); if (log.isDebugEnabled()) log.debug("extractSessionId() sessionId = \""+value+"\""); return new Long(Long.parseLong(value)); } catch (Exception e) { //log.debug("extractSessionId() Failed to extract sessionId", e); return null; } }
/** * A human readable representation of the HttpException. */ public String toString () { final StringBuffer sb = new StringBuffer(); sb.append("HTTP "); sb.append(getErrorCode()); if (getMessage() != null) { sb.append(" "); sb.append(getMessage()); } sb.append("\n"); sb.append(super.toString()); return sb.toString(); }
public void init (final RestService service, final Long sessionId, final String username, final String password) throws ServiceException { super.init(service, sessionId, username, password); this.sessionServerKey = ""+this.hashCode()+SESSION_SERVER_SUFFIX; }
/** * This method is used to turn a simple exception into an HttpError, * very useful in final implementations of this class. */ public static void rethrowAsHttpException (final int httpErrorCode, final Exception e) throws HttpException { throw new HttpException(httpErrorCode, e.getMessage()); }
/** * Extract a numeric (int) value from the HTTP headers. */ public static int extractNumericHeaderValue (final String[] headers, final String key) { final String s = extractHeaderValue(headers, key); try { return Integer.parseInt(s); } catch (final Throwable t) { // ignore } return -1; }
protected void reply (final SelectionKey key, final org.jdom.Element elt) { NetUtils.httpReply (key, 200, "OK", this.service.getServerName(), null, "text/xml", elt); //log.debug("reply() :\n"+elt); }
public org.jdom.Element getStatus () { org.jdom.Element result = new org.jdom.Element(getName()); result.addContent(XmlUtils.getClassElt(this)); result.addContent(XmlUtils.getRevisionElt("$Id: RestService.java 2713 2006-06-01 14:38:45Z jmettraux $")); return result; }
public static String printSessions (final java.util.Map sessions) { StringBuffer sb = new StringBuffer(); sb.append("\n[\n "); java.util.Iterator it = sessions.keySet().iterator(); while (it.hasNext()) { Long sessionId = (Long)it.next(); RestSession session = (RestSession)sessions.get(sessionId); sb.append(" "); sb.append(sessionId); sb.append(" : "); sb.append(new java.util.Date(session.getLastUsed())); if (it.hasNext()) { sb.append(",\n"); } } sb.append("\n]\n"); return sb.toString(); }
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 = Definitions .getWorkItemCoderLoader(this.getService().getContext()); this.coder = (XmlWorkItemCoder)loader.getXmlCoder(); log.info ("WorkItemCoder successfully located"); }
public void do_getheaders (final SelectionKey key, final String[] headers) throws Exception { final String storeName = extractStoreName(headers[0]); int limit = -1; try { limit = Integer.parseInt (RestUtils.extractFromLine(headers[0], "limit")); } catch (Exception e) { // ignore } final java.util.List owfeHeaders = this.session.getHeaders(storeName, limit); reply(key, getCoder().encodeHeadersAsXml(owfeHeaders)); }
protected RestSession newRestSession (final Long sessionId, final String username, final String password) throws Exception { final Class clazz = Class.forName(this.restSessionClassName); final RestSession session = (RestSession)clazz.newInstance(); session.init (this, sessionId, username, password); log.debug("newRestSession() ok."); return session; }
public void do_findflowinstance (final SelectionKey key, final String[] headers) throws Exception { String storeName = extractStoreName(headers[0]); String wfid = null; try { wfid = RestUtils.extractFromLine(headers[0], "id"); } catch (Exception e) { // ignore } java.util.List feis = this.session.findFlowInstance(storeName, wfid); reply(key, getCoder().encodeIdsAsXml(feis)); }
public void do_launchflow (final SelectionKey key, final String[] headers) throws Exception { final String engineId = RestUtils.extractFromLine (headers[0], "engineid"); org.jdom.Element reqElt = parseBody(key, headers); LaunchItem item = (LaunchItem)getCoder().decode(reqElt, null, null); //log.debug // ("do_launchflow() field is >"+item.getAttributes().sget("field")+ // "<"); final String flowId = this.session.launch(engineId, item); org.jdom.Element eReply = new org.jdom.Element("ok"); eReply.setAttribute("flow-id", flowId); reply(key, eReply); }
public void do_getworkitem (final SelectionKey key, final String[] headers) throws Exception { final String storeName = extractStoreName(headers[0]); InFlowWorkItem item = null; if (headers[0].startsWith("GET ")) { String sid = RestUtils.extractFromLine(headers[0], "id"); item = this.session.get(storeName, sid); } else { final org.jdom.Element reqElt = parseBody(key, headers); //log.debug // ("getWorkItem() : request body >\n"+ // openwfe.org.Utils.toString(reqElt, "ISO-8859-1")); final FlowExpressionId itemId = getCoder().decodeFlowExpressionId(reqElt); item = this.session.get(storeName, itemId); } // debug //openwfe.org.Utils.dump // ("rest_4_", // item.getAttributes().sget("field") // .getBytes(openwfe.org.Utils.getEncoding())); reply(key, getCoder().encodeAsXml(item)); }