implemented the initial XML-RPC APIs in Venice - for creating and destroying

"sessions," logging in, posting messages to topics, attaching files to
messages, and a couple of minor things that aren't as important right now
This commit is contained in:
Eric J. Bowersox 2002-02-01 22:40:55 +00:00
parent f463834ef0
commit 25c5817a67
24 changed files with 1013 additions and 23 deletions

View File

@ -276,19 +276,58 @@
<!-- Configuration for the RPC interfaces. -->
<rpc>
<!-- Timeout for RPC sessions -->
<session-timeout>60</session-timeout>
<xmlrpc-methods>
<!-- XML-RPC validation suite -->
<method name="validator1\.[a-zA-Z]*"><script name="test/validation.js"/></method>
<method name="validator1\.[:alpha:]+"><script name="test/validation.js"/></method>
<!-- Multicall "boxcar" marshaller (see http://www.xmlrpc.com/discuss/msgReader$1208) -->
<method name="system.multicall"><object class="com.silverwrist.venice.ui.rpc.XmlRpcMulticall"/></method>
<!-- The session creation API -->
<method name="venice:session\.create">
<object class="com.silverwrist.venice.ui.rpc.XmlRpcCreateSession"/>
</method>
<!-- The other session APIs -->
<method name="venice:session\.([:alnum:]+)">
<script name="session.js"/>
<session param="0"/>
<env name="call" value="${match.1}"/>
</method>
<!-- The conferencing APIs for conferences -->
<method name="venice:conferencing\.conference\.([:alnum:]+)">
<script name="conf/conference.js"/>
<session param="0"/>
<env name="call" value="${match.1}"/>
</method>
<!-- The conferencing APIs for topics -->
<method name="venice:conferencing\.topic\.([:alnum:]+)">
<script name="conf/topic.js"/>
<session param="0"/>
<env name="call" value="${match.1}"/>
</method>
<!-- The conferencing APIs for messages -->
<method name="venice:conferencing\.message\.([:alnum:]+)">
<script name="conf/message.js"/>
<session param="0"/>
<env name="call" value="${match.1}"/>
</method>
<!-- A test method -->
<method name="venice:test\.sumDifference">
<!-- <object class="com.silverwrist.venice.ui.rpc.XmlRpcTestHandler"/> -->
<!-- <session param="0"/> -->
<script name="test/test1.js"/>
<env name="e1" value="foo"/>
<env name="p1" value="${param.0}"/>
</method>
</xmlrpc-methods>
</rpc>

View File

@ -0,0 +1,59 @@
// The contents of this file are subject to the Mozilla Public License Version 1.1
// (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
//
// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
// WARRANTY OF ANY KIND, either express or implied. See the License for the specific
// language governing rights and limitations under the License.
//
// The Original Code is the Venice Web Communities System.
//
// The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
// for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
// Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
//
// Contributor(s):
// Implements the conferencing topic API
importPackage(java.util);
importPackage(Packages.com.silverwrist.venice.core);
importPackage(Packages.com.silverwrist.venice.ui.rpc);
rinput = bsf.lookupBean("request");
xreq = bsf.lookupBean("xmlrpc");
env = bsf.lookupBean("environment");
call_name = env.get("call");
// All methods have at least three parameters: session, community, conference.
if (xreq.paramCount<3)
{ // not enough parameters
vlib.output(new XmlRpcFault(XmlRpcFault.INVALID_PARAMS,"parameter count mismatch"));
vlib.done();
} // end if
comm = xreq.getParamCommunity(1);
conf = xreq.getParamConference(2,comm);
if ("name"==call_name)
{ // venice:conferencing.conference.name <session-id> <community> <conference> [<new-name>]
// Retrieves or sets the conference name.
if (xreq.paramCount==3)
vlib.output(conf.name);
else if (xreq.paramCount==4)
{ // set the name
name = xreq.getParamString(3);
conf.name = name;
vlib.output(name); // output the new name on success
} // end else if
else // wrong parameter count
vlib.output(new XmlRpcFault(XmlRpcFault.INVALID_PARAMS,"parameter count mismatch"));
vlib.done();
} // end if
// just in case there's a method name that wasn't listed
vlib.output(new XmlRpcFault(XmlRpcFault.METHOD_NOT_FOUND,"invalid method name: " + xreq.method));

View File

@ -0,0 +1,60 @@
// The contents of this file are subject to the Mozilla Public License Version 1.1
// (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
//
// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
// WARRANTY OF ANY KIND, either express or implied. See the License for the specific
// language governing rights and limitations under the License.
//
// The Original Code is the Venice Web Communities System.
//
// The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
// for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
// Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
//
// Contributor(s):
// Implements the conferencing message API
importPackage(java.util);
importPackage(Packages.com.silverwrist.venice.core);
importPackage(Packages.com.silverwrist.venice.ui.rpc);
rinput = bsf.lookupBean("request");
xreq = bsf.lookupBean("xmlrpc");
env = bsf.lookupBean("environment");
call_name = env.get("call");
// All methods have at least five parameters: session, community, conference, topic, message.
if (xreq.paramCount<5)
{ // not enough parameters
vlib.output(new XmlRpcFault(XmlRpcFault.INVALID_PARAMS,"parameter count mismatch"));
vlib.done();
} // end if
comm = xreq.getParamCommunity(1);
conf = xreq.getParamConference(2,comm);
topic = xreq.getParamTopic(3,conf);
msg = xreq.getParamPost(4,topic);
if ("attach"==call_name)
{ // venice:conferencing.message.attach <session-id> <community> <conference> <topic> <message> <mime-type>
// <filename> <data>
if (xreq.paramCount!=8)
vlib.output(new XmlRpcFault(XmlRpcFault.INVALID_PARAMS,"parameter count mismatch"));
else if ("base64"!=xreq.getParamType(7))
vlib.output(new XmlRpcFault(XmlRpcFault.INVALID_PARAMS,"data parameter type mismatch"));
else
{ // attach the data and return
msg.attachData(xreq.getParamString(5),xreq.getParamString(6),vlib.castByteArray(xreq.getParam(7)));
vlib.output(vlib.booleanObject(true));
} // end else
vlib.done();
} // end if
// just in case there's a method name that wasn't listed
vlib.output(new XmlRpcFault(XmlRpcFault.METHOD_NOT_FOUND,"invalid method name: " + xreq.method));

57
rpcscripts/conf/topic.js Normal file
View File

@ -0,0 +1,57 @@
// The contents of this file are subject to the Mozilla Public License Version 1.1
// (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
//
// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
// WARRANTY OF ANY KIND, either express or implied. See the License for the specific
// language governing rights and limitations under the License.
//
// The Original Code is the Venice Web Communities System.
//
// The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
// for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
// Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
//
// Contributor(s):
// Implements the conferencing topic API
importPackage(java.util);
importPackage(Packages.com.silverwrist.venice.core);
importPackage(Packages.com.silverwrist.venice.ui.rpc);
rinput = bsf.lookupBean("request");
xreq = bsf.lookupBean("xmlrpc");
env = bsf.lookupBean("environment");
call_name = env.get("call");
// All methods have at least four parameters: session, community, conference, topic.
if (xreq.paramCount<4)
{ // not enough parameters
vlib.output(new XmlRpcFault(XmlRpcFault.INVALID_PARAMS,"parameter count mismatch"));
vlib.done();
} // end if
comm = xreq.getParamCommunity(1);
conf = xreq.getParamConference(2,comm);
topic = xreq.getParamTopic(3,conf);
if ("postMessage"==call_name)
{ // venice:conferencing.topic.postMessage <session-id> <community> <conference> <topic> <pseud> <text>
// Posts a message, returns the message number within the topic
if (xreq.paramCount!=6)
vlib.output(new XmlRpcFault(XmlRpcFault.INVALID_PARAMS,"parameter count mismatch"));
else
{ // post the message
msg = topic.postNewMessage(0,xreq.getParamString(4),xreq.getParamString(5));
vlib.output(vlib.createInteger(msg.postNumber));
} // end else
vlib.done();
} // end if
// just in case there's a method name that wasn't listed
vlib.output(new XmlRpcFault(XmlRpcFault.METHOD_NOT_FOUND,"invalid method name: " + xreq.method));

66
rpcscripts/session.js Normal file
View File

@ -0,0 +1,66 @@
// The contents of this file are subject to the Mozilla Public License Version 1.1
// (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
//
// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
// WARRANTY OF ANY KIND, either express or implied. See the License for the specific
// language governing rights and limitations under the License.
//
// The Original Code is the Venice Web Communities System.
//
// The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
// for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
// Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
//
// Contributor(s):
// Implements the session API
importPackage(java.util);
importPackage(Packages.com.silverwrist.venice.core);
importPackage(Packages.com.silverwrist.venice.ui.rpc);
rinput = bsf.lookupBean("request");
xreq = bsf.lookupBean("xmlrpc");
env = bsf.lookupBean("environment");
call_name = env.get("call");
//logger.debug("call selector = " + call_name);
if ("destroy"==call_name)
{ // venice:session.destroy <session-id> - destroys a session
if (xreq.paramCount!=1)
vlib.output(new XmlRpcFault(XmlRpcFault.INVALID_PARAMS,"parameter count mismatch"));
else
{ // end the session
rinput.endSession();
vlib.output(vlib.booleanObject(true));
} // end else
vlib.done();
} // end if
if ("login"==call_name)
{ // venice:session.login <session-id> <username> <password> - logs in the session
if (xreq.paramCount!=3)
vlib.output(new XmlRpcFault(XmlRpcFault.INVALID_PARAMS,"parameter count mismatch"));
else
{ // get the user name and password and log in
username = xreq.getParamString(1);
password = xreq.getParamString(2);
if (rinput.user.isLoggedIn())
vlib.output(new XmlRpcFault(XmlRpcFault.DEFAULT_ERROR,"user already logged in"));
else
rinput.user.authenticate(username,password);
vlib.output(vlib.booleanObject(true));
} // end else
vlib.done();
} // end if
// just in case there's a method name that wasn't listed
vlib.output(new XmlRpcFault(XmlRpcFault.METHOD_NOT_FOUND,"invalid method name: " + xreq.method));

View File

@ -75,6 +75,8 @@ public interface TopicMessageContext
public abstract void attachData(String m_type, String file, int length, InputStream data)
throws AccessError, DataException;
public abstract void attachData(String m_type, String file, byte[] data) throws AccessError, DataException;
public abstract boolean canPublish();
public abstract void publish() throws DataException, AccessError;

View File

@ -923,6 +923,12 @@ class TopicMessageUserContextImpl implements TopicMessageContext
} // end attachData
public void attachData(String m_type, String file, byte[] data) throws AccessError, DataException
{
attachData(m_type,file,data.length,new ByteArrayInputStream(data));
} // end attachData
public boolean canPublish()
{
if (!(env.testPermission(EnvUser.PERM_PUBLISH_FP)))

View File

@ -11,7 +11,7 @@
*
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
* Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
* Copyright (C) 2001-02 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
@ -19,6 +19,18 @@ package com.silverwrist.venice.except;
public class AccessError extends VeniceException
{
/*--------------------------------------------------------------------------------
* Static data members
*--------------------------------------------------------------------------------
*/
private static final int FAULTCODE_BASE = 20000;
/*--------------------------------------------------------------------------------
* Constructors
*--------------------------------------------------------------------------------
*/
public AccessError()
{
super();
@ -43,4 +55,15 @@ public class AccessError extends VeniceException
} // end constructor
/*--------------------------------------------------------------------------------
* Overrides from class VeniceException
*--------------------------------------------------------------------------------
*/
public int getFaultCode()
{
return FAULTCODE_BASE;
} // end getFaultCode
} // end class AccessError

View File

@ -11,7 +11,7 @@
*
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
* Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
* Copyright (C) 2001-02 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
@ -19,6 +19,18 @@ package com.silverwrist.venice.except;
public class DataException extends VeniceException
{
/*--------------------------------------------------------------------------------
* Static data members
*--------------------------------------------------------------------------------
*/
private static final int FAULTCODE_BASE = 10000;
/*--------------------------------------------------------------------------------
* Constructors
*--------------------------------------------------------------------------------
*/
public DataException()
{
super();
@ -43,4 +55,15 @@ public class DataException extends VeniceException
} // end constructor
/*--------------------------------------------------------------------------------
* Overrides from class VeniceException
*--------------------------------------------------------------------------------
*/
public int getFaultCode()
{
return FAULTCODE_BASE;
} // end getFaultCode
} // end class DataException

View File

@ -0,0 +1,24 @@
/*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
*
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* The Original Code is the Venice Web Communities System.
*
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
* Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.except;
public interface SupplyFaultCode
{
public abstract int getFaultCode();
} // end interface SupplyFaultCode

View File

@ -11,7 +11,7 @@
*
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
* Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
* Copyright (C) 2001-02 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
@ -27,7 +27,7 @@ import java.io.PrintWriter;
* @author Eric J. Bowersox &lt;erbo@silcom.com&gt;
* @version X
*/
public class VeniceException extends Exception
public class VeniceException extends Exception implements SupplyFaultCode
{
/*--------------------------------------------------------------------------------
* Attributes
@ -139,6 +139,17 @@ public class VeniceException extends Exception
} // end printStackTrace
/*--------------------------------------------------------------------------------
* Implementations from interface SupplyFaultCode
*--------------------------------------------------------------------------------
*/
public int getFaultCode()
{
return 0;
} // end getFaultCode
/*--------------------------------------------------------------------------------
* External operations
*--------------------------------------------------------------------------------

View File

@ -188,4 +188,8 @@ public interface RequestInput extends LinkTypes
public abstract void registerCleanup(AutoCleanup ac);
public abstract void pushSession(VeniceUISession sess);
public abstract void popSession();
} // end interface RequestInput

View File

@ -81,6 +81,7 @@ public class RootConfig implements LinkTypes, ColorSelectors
private ButtonHolder buttons; // the button definitions
private String[] content_hdr; // the content header parts
private Remapper remapper; // the URL remapper
private int rpc_timeout = 60; // RPC session timeout
private List xmlrpc_methods; // the list of XML-RPC methods
private StockMessages stock_messages; // the stock messages
private Map menus; // the menus
@ -391,6 +392,18 @@ public class RootConfig implements LinkTypes, ColorSelectors
sect = loader.configGetSubSection(root_h,"rpc");
sect_h = new DOMElementHelper(sect);
// Get the <session-timeout/> figure.
if (sect_h.hasChildElement("session-timeout"))
{ // get the timeout value
Integer xtmp = sect_h.getSubElementInt("session-timeout");
if (xtmp==null)
throw new ConfigException("<session-timeout/> value is not an integer",sect);
rpc_timeout = xtmp.intValue();
if (rpc_timeout<=0)
throw new ConfigException("<session-timeout/> value is invalid",sect);
} // end if
// Get the <xmlrpc-methods/> section.
sect1 = loader.configGetSubSection(sect_h,"xmlrpc-methods");
nl = sect1.getChildNodes();
@ -773,6 +786,12 @@ public class RootConfig implements LinkTypes, ColorSelectors
} // end getDefaultServletAddress
public final int getRpcSessionTimeout()
{
return rpc_timeout;
} // end getRpcSessionTimeout
public final List getXmlRpcMethods()
{
return xmlrpc_methods;

View File

@ -0,0 +1,203 @@
/*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
*
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* The Original Code is the Venice Web Communities System.
*
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
* Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.ui.rpc;
import java.util.*;
import javax.servlet.*;
import org.apache.log4j.*;
import com.silverwrist.venice.core.*;
import com.silverwrist.venice.except.*;
import com.silverwrist.venice.ui.*;
import com.silverwrist.venice.ui.config.RootConfig;
import com.silverwrist.venice.ui.servlet.RequestImpl;
class RpcSessionBroker
{
/*--------------------------------------------------------------------------------
* Internal class for sweeping the sessions
*--------------------------------------------------------------------------------
*/
class SessionSweeper extends TimerTask
{
private LinkedList workspace = new LinkedList();
SessionSweeper()
{
super();
} // end constructor
public void run()
{
synchronized (RpcSessionBroker.this)
{ // seek and destroy all expired sessions
Iterator it = sessions.values().iterator();
while (it.hasNext())
{ // find all the tasks that are due to be invalidated
RpcVeniceUISession s = (RpcVeniceUISession)(it.next());
if (s.canUnloadNow())
workspace.addLast(s);
} // end while
while (workspace.size()>0)
{ // invalidate all sessions that have not been accessed recently
RpcVeniceUISession s = (RpcVeniceUISession)(workspace.removeFirst());
if (logger.isDebugEnabled())
logger.debug("session sweeper removing session with ID " + s.getID());
s.invalidate();
} // end while
} // end synchronized block
} // end run
} // end class SessionSweeper
/*--------------------------------------------------------------------------------
* Static data members
*--------------------------------------------------------------------------------
*/
private static Category logger = Category.getInstance(RpcSessionBroker.class);
private static final String ATTRIBUTE = "ui.rpc.SessionBroker";
private static final long INTERVAL = 1000;
private static final String PREFIX = "rpcsess:";
private static final String ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
private static final int ID_LENGTH = 40;
private static Random rng = new Random(); // random number generator
/*--------------------------------------------------------------------------------
* Attributes
*--------------------------------------------------------------------------------
*/
private HashMap sessions = new HashMap(); // the actual sessions
private VeniceEngine engine; // the Venice engine
private int timeout_value; // the timeout value
private Timer timer = new Timer(true); // the interval timer used to schedule sweeps
/*--------------------------------------------------------------------------------
* Constructor
*--------------------------------------------------------------------------------
*/
private RpcSessionBroker(VeniceEngine engine, RootConfig root)
{
this.engine = engine;
this.timeout_value = root.getRpcSessionTimeout();
timer.scheduleAtFixedRate(new SessionSweeper(),INTERVAL,INTERVAL);
} // end constructor
/*--------------------------------------------------------------------------------
* Internal operations
*--------------------------------------------------------------------------------
*/
private static final String generateID()
{
StringBuffer buf = new StringBuffer(PREFIX);
for (int i=0; i<ID_LENGTH; i++)
buf.append(ALPHABET.charAt(rng.nextInt(ALPHABET.length())));
return buf.toString();
} // end generateID
/*--------------------------------------------------------------------------------
* External operations
*--------------------------------------------------------------------------------
*/
final int getTimeout()
{
return timeout_value;
} // end getTimeout
final VeniceEngine getEngine()
{
return engine;
} // end getEngine
final synchronized VeniceUISession getSession(String id)
{
if (logger.isDebugEnabled())
logger.debug("looking up session with ID " + id + " - current session count is " + sessions.size());
RpcVeniceUISession rc = (RpcVeniceUISession)(sessions.get(id));
if (rc!=null)
rc.touch();
return rc;
} // end getSession
final synchronized VeniceUISession createSession(String remote_address) throws DataException
{
String new_id = generateID();
while (sessions.containsKey(new_id))
new_id = generateID();
RpcVeniceUISession rc = new RpcVeniceUISession(new_id,remote_address,this);
sessions.put(new_id,rc);
if (logger.isDebugEnabled())
logger.debug("created new session with ID " + new_id + " - session count now " + sessions.size());
return rc;
} // end createSession
final synchronized void detachSession(String id)
{
if (logger.isDebugEnabled())
logger.debug("removing session with ID " + id + " - current session count is " + sessions.size());
sessions.remove(id);
if (logger.isDebugEnabled())
logger.debug("session count now " + sessions.size());
} // end detachSession
/*--------------------------------------------------------------------------------
* External static operations
*--------------------------------------------------------------------------------
*/
public static RpcSessionBroker get(ServletContext ctxt)
{
return (RpcSessionBroker)(RequestImpl.getAppAttribute(ctxt,ATTRIBUTE));
} // end get
public static RpcSessionBroker get(RequestInput ri)
{
return (RpcSessionBroker)(ri.getAppAttribute(ATTRIBUTE));
} // end get
public static synchronized void init(ServletContext ctxt, VeniceEngine engine, RootConfig root)
{
if (RequestImpl.getAppAttribute(ctxt,ATTRIBUTE)==null)
RequestImpl.setAppAttribute(ctxt,ATTRIBUTE,new RpcSessionBroker(engine,root));
} // end init
} // end class RpcSessionBroker

View File

@ -0,0 +1,161 @@
/*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
*
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* The Original Code is the Venice Web Communities System.
*
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
* Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.ui.rpc;
import java.util.*;
import com.silverwrist.venice.core.*;
import com.silverwrist.venice.except.*;
import com.silverwrist.venice.ui.*;
class RpcVeniceUISession implements VeniceUISession
{
/*--------------------------------------------------------------------------------
* Attributes
*--------------------------------------------------------------------------------
*/
private RpcSessionBroker broker; // session broker
private long create_time; // session creation time
private long access_time; // session last access time
private String id; // the session ID
private String remote_addr; // the remote address
private int max_inactive; // the maximum inactive interval
private HashMap attrs = new HashMap(); // storage for attributes
private UserContext user; // user context in this session
/*--------------------------------------------------------------------------------
* Constructor
*--------------------------------------------------------------------------------
*/
RpcVeniceUISession(String id, String remote_addr, RpcSessionBroker broker) throws DataException
{
this.broker = broker;
this.id = id;
this.remote_addr = remote_addr;
this.max_inactive = broker.getTimeout() * 60;
this.user = broker.getEngine().createUserContext(remote_addr);
this.create_time = this.access_time = System.currentTimeMillis();
} // end constructor
/*--------------------------------------------------------------------------------
* Implementations from interface VeniceUISession
*--------------------------------------------------------------------------------
*/
public long getCreationTime()
{
return create_time;
} // end getCreationTime
public String getID()
{
return id;
} // end getID
public long getLastAccessedTime()
{
return access_time;
} // end getLastAccessedTime
public synchronized void setMaxInactiveInterval(int interval)
{
max_inactive = interval;
touch();
} // end setMaxInactiveInterval
public int getMaxInactiveInterval()
{
return max_inactive;
} // end getMaxInactiveInterval
public Object getAttribute(String name)
{
return attrs.get(name);
} // end getAttribute
public Enumeration getAttributeNames()
{
return Collections.enumeration(attrs.keySet());
} // end getAttributeNames
public synchronized void setAttribute(String name, Object o)
{
attrs.put(name,o);
touch();
} // end setAttribute
public synchronized void removeAttribute(String name)
{
attrs.remove(name);
touch();
} // end removeAttribute
public synchronized void invalidate()
{
broker.detachSession(id);
broker = null;
attrs.clear();
} // end invalidate
public UserContext getUser()
{
return user;
} // end getUser
public synchronized void setUser(UserContext user)
{
this.user = user;
touch();
} // end setUser
public void preprocess(RequestInput ri)
{ // do nothing
} // end preprocess
/*--------------------------------------------------------------------------------
* External operations
*--------------------------------------------------------------------------------
*/
final synchronized boolean canUnloadNow()
{
return ((System.currentTimeMillis() - access_time) > ((long)1000 * max_inactive));
} // end canUnloadNow
final synchronized void touch()
{
access_time = System.currentTimeMillis();
} // end touch
} // end class RpcVeniceUISession

View File

@ -0,0 +1,50 @@
/*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
*
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* The Original Code is the Venice Web Communities System.
*
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
* Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.ui.rpc;
import java.util.*;
import org.apache.log4j.*;
import com.silverwrist.venice.ui.*;
public class XmlRpcCreateSession implements XmlRpcDispatch
{
/*--------------------------------------------------------------------------------
* Static data members
*--------------------------------------------------------------------------------
*/
private static Category logger = Category.getInstance(XmlRpcCreateSession.class);
/*--------------------------------------------------------------------------------
* Implementations from interface XmlRpcDispatch
*--------------------------------------------------------------------------------
*/
public Object dispatch(RequestInput req, XmlRpcRequest xreq, Map environment) throws Exception, XmlRpcFault
{
if (logger.isDebugEnabled())
logger.debug("Dispatching a Create Session call");
VeniceUISession session = RpcSessionBroker.get(req).createSession(req.getSourceAddress());
if (logger.isDebugEnabled())
logger.debug("Created new session with ID " + session.getID());
return session.getID();
} // end dispatch
} // end class XmlRpcSession

View File

@ -19,6 +19,7 @@ package com.silverwrist.venice.ui.rpc;
import java.io.IOException;
import com.silverwrist.util.StringUtil;
import com.silverwrist.venice.except.SupplyFaultCode;
import com.silverwrist.venice.ui.*;
import com.silverwrist.venice.ui.helpers.ThrowableContent;
@ -67,6 +68,12 @@ public class XmlRpcFault extends ThrowableContent implements ContentExecute
public XmlRpcFault(Throwable t)
{
super(t);
if (t instanceof SupplyFaultCode)
{ // retrieve the fault code
SupplyFaultCode sfc = (SupplyFaultCode)t;
fault_code = sfc.getFaultCode();
} // end if
} // end constructor
@ -80,6 +87,12 @@ public class XmlRpcFault extends ThrowableContent implements ContentExecute
public XmlRpcFault(String msg, Throwable t)
{
super(msg,t);
if (t instanceof SupplyFaultCode)
{ // retrieve the fault code
SupplyFaultCode sfc = (SupplyFaultCode)t;
fault_code = sfc.getFaultCode();
} // end if
} // end constructor

View File

@ -49,6 +49,7 @@ public class XmlRpcMethod
private Class obj_class = null; // "class" handler for object
private String script_name = null; // script name to use as a handler
private Map raw_env; // "raw" environment
private int session_param = -1; // session parameter
/*--------------------------------------------------------------------------------
* Constructor
@ -119,7 +120,15 @@ public class XmlRpcMethod
else // no handler - this is an error
throw new ConfigException("method \"" + method_name + "\" does not have a valid handler",cfg);
NodeList nl = sub.getChildNodes();
if ((sub = cfg_h.getSubElement("session"))!=null)
{ // find the session parameter index
session_param = loader.configGetAttributeInt(sub,"param");
if (session_param<0)
throw new ConfigException("invalid session parameter index",sub);
} // end if
NodeList nl = cfg.getChildNodes();
HashMap tmp_env = new HashMap();
for (int i=0; i<nl.getLength(); i++)
{ // look for specific nodes
@ -141,6 +150,38 @@ public class XmlRpcMethod
} // end constructor
/*--------------------------------------------------------------------------------
* Internal operations
*--------------------------------------------------------------------------------
*/
private final void bindSession(RequestInput req, XmlRpcRequest xreq) throws XmlRpcFault
{
if (logger.isDebugEnabled())
logger.debug("trying to bind parameter at index " + session_param + " to session");
if (session_param>=xreq.getParamCount())
{ // too few parameters - bail out!
logger.error("session parameter is at index " + session_param + " but only " + xreq.getParamCount()
+ " parameter(s) present");
throw new XmlRpcFault(XmlRpcFault.SERVER_ERROR,"invalid parameter index for session binding");
} // end if
String session_id = xreq.getParamString(session_param).trim();
if (logger.isDebugEnabled())
logger.debug("Passed session ID = " + session_id);
VeniceUISession vuis = RpcSessionBroker.get(req).getSession(session_id);
if (vuis==null)
{ // the session cannot be acquired
logger.debug("Cannot get session for session ID " + session_id);
throw new XmlRpcFault(XmlRpcFault.INVALID_PARAMS,"session not found");
} // end if
req.pushSession(vuis); // push the session into the request
} // end bindSession
/*--------------------------------------------------------------------------------
* External operations
*--------------------------------------------------------------------------------
@ -181,7 +222,20 @@ public class XmlRpcMethod
} // end if
return disp.dispatch(req,xreq,env); // dispatch the call
if (session_param>=0)
bindSession(req,xreq);
try
{ // dispatch the call
return disp.dispatch(req,xreq,env);
} // end try
finally
{ // pop the session we pushed
if (session_param>=0)
req.popSession();
} // end finally
} // end if
@ -193,19 +247,36 @@ public class XmlRpcMethod
logger.debug("EXECUTING " + full_name);
try
{ // execute the script!
if (session_param>=0)
bindSession(req,xreq);
ScriptManager smgr = req.getScriptManager();
smgr.pushContext();
smgr.register("xmlrpc",xreq);
smgr.register("environment",env);
ScriptReturn sro = new ScriptReturn();
smgr.exec(new File(full_name),logger_name,sro);
smgr.popContext();
return sro.get();
try
{ // execute the script
ScriptReturn sro = new ScriptReturn();
smgr.exec(new File(full_name),logger_name,sro);
return sro.get();
} // end try
finally
{ // make sure and pop the context before we return
smgr.popContext();
if (session_param>=0)
req.popSession();
} // end finally
} // end try
catch (ScriptingException se)
{ // script error! we are not amused...
return new XmlRpcFault(XmlRpcFault.APPLICATION_ERROR,"scripting error: " + se.toString());
Throwable t = se.getException();
if (t instanceof SupplyFaultCode)
return new XmlRpcFault(t);
else
return new XmlRpcFault(XmlRpcFault.APPLICATION_ERROR,"scripting error: " + se.toString());
} // end catch
catch (ThrowableContent tc)

View File

@ -99,7 +99,7 @@ public class XmlRpcMulticall implements XmlRpcDispatch
while (it.hasNext())
{ // parse out a request and dispatch it
try
{ // parse the request
{ // parse the request, execute it, and add its result to the return array
XmlRpcRequest sub_xreq = parseRequest(req,it.next());
Object sub_rc = XmlRpcServlet.dispatchMethodCall(req,sub_xreq);
if (sub_rc instanceof XmlRpcFault)

View File

@ -24,6 +24,7 @@ import javax.mail.internet.*;
import org.apache.log4j.*;
import org.w3c.dom.*;
import com.silverwrist.util.*;
import com.silverwrist.venice.core.*;
import com.silverwrist.venice.except.*;
import com.silverwrist.venice.ui.*;
import com.silverwrist.venice.util.XMLLoader;
@ -59,8 +60,7 @@ public class XmlRpcRequest
throw new XmlRpcFault(XmlRpcFault.INVALID_REQUEST,"no XML call structure found");
try
{
// load the initial structure and method name
{ // load the initial structure and method name
XMLLoader loader = XMLLoader.get();
Element root = loader.postGetRootElement(req_doc,"methodCall");
DOMElementHelper root_h = new DOMElementHelper(root);
@ -475,4 +475,49 @@ public class XmlRpcRequest
} // end getParamString
public final CommunityContext getParamCommunity(int ndx) throws XmlRpcFault, DataException
{
Object foo = method_params.get(ndx);
if ((foo instanceof byte[]) || (foo instanceof List) || (foo instanceof Map) || (foo instanceof Boolean))
throw new XmlRpcFault(XmlRpcFault.INVALID_PARAMS,"parameter type mismatch");
if (foo instanceof Integer)
return req.getUser().getCommunityContext(((Integer)foo).intValue());
else
return req.getUser().getCommunityContext(foo.toString().trim());
} // end getParamCommunity
public final ConferenceContext getParamConference(int ndx, CommunityContext comm)
throws XmlRpcFault, DataException, AccessError
{
Object foo = method_params.get(ndx);
if ((foo instanceof byte[]) || (foo instanceof List) || (foo instanceof Map) || (foo instanceof Boolean))
throw new XmlRpcFault(XmlRpcFault.INVALID_PARAMS,"parameter type mismatch");
if (foo instanceof Integer)
return comm.getConferenceContext(((Integer)foo).intValue());
else
return comm.getConferenceContext(foo.toString().trim());
} // end getParamConference
public final TopicContext getParamTopic(int ndx, ConferenceContext conf)
throws XmlRpcFault, DataException, AccessError
{
Object foo = method_params.get(ndx);
if (!(foo instanceof Integer))
throw new XmlRpcFault(XmlRpcFault.INVALID_PARAMS,"parameter type mismatch");
return conf.getTopic(((Integer)foo).shortValue());
} // end getParamTopic
public final TopicMessageContext getParamPost(int ndx, TopicContext topic)
throws XmlRpcFault, DataException, AccessError
{
Object foo = method_params.get(ndx);
if (!(foo instanceof Integer))
throw new XmlRpcFault(XmlRpcFault.INVALID_PARAMS,"parameter type mismatch");
return topic.getMessage(((Integer)foo).intValue());
} // end getParamPost
} // end class XmlRpcRequest

View File

@ -21,6 +21,7 @@ import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.log4j.*;
import org.apache.regexp.*;
import com.silverwrist.util.*;
import com.silverwrist.venice.core.*;
@ -76,6 +77,8 @@ public class XmlRpcServlet extends BaseServlet
*--------------------------------------------------------------------------------
*/
private static Category logger = Category.getInstance(XmlRpcServlet.class);
private static final String METHOD_LIST_ATTR = "ui.xmlrpc.MethodList";
public static final String OBJECT_CLASS_CACHE_ATTR = "ui.xmlrpc.class.ObjectCache";
@ -91,6 +94,7 @@ public class XmlRpcServlet extends BaseServlet
List methods = root.getXmlRpcMethods();
RequestImpl.setAppAttribute(ctxt,METHOD_LIST_ATTR,methods);
RequestImpl.setAppAttribute(ctxt,OBJECT_CLASS_CACHE_ATTR,Collections.synchronizedMap(new HashMap()));
RpcSessionBroker.init(ctxt,engine,root);
} // end init
@ -135,7 +139,10 @@ public class XmlRpcServlet extends BaseServlet
static Object dispatchMethodCall(RequestInput req, XmlRpcRequest xreq)
{
// Prepare the parameters map
if (logger.isDebugEnabled())
logger.debug("XML-RPC Method Call: " + xreq.getMethod());
// Prepare the parameters map.
int i;
HashMap param_repl_map = new HashMap();
for (i=0; i<xreq.getParamCount(); i++)
@ -166,19 +173,26 @@ public class XmlRpcServlet extends BaseServlet
} // end while
if (!found) // method not found
if (!found)
{ // method not found
logger.error("Method not found: " + the_name);
return new XmlRpcFault(XmlRpcFault.METHOD_NOT_FOUND,"Method not found: " + the_name);
} // end if
// prepare the substitution map
sub_map = (HashMap)(param_repl_map.clone());
int ct = matcher.getParenCount();
for (i=0; i<=ct; i++)
sub_map.put("match." + i,matcher.getParen(i));
// test for method remapping
String remap = meth.getRemap();
if (remap!=null)
{ // substitute in variables and rescan
the_name = StringUtil.replaceAllVariables(remap,sub_map);
if (logger.isDebugEnabled())
logger.debug("-- call remapped to method: " + the_name);
rescan = true;
} // end if

View File

@ -11,7 +11,7 @@
*
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
* Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
* Copyright (C) 2001-02 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
@ -31,6 +31,20 @@ public class ScriptLibrary
*--------------------------------------------------------------------------------
*/
public final Boolean booleanObject(boolean b)
{
return (b ? Boolean.TRUE : Boolean.FALSE);
} // end booleanObject
public final byte[] castByteArray(Object o)
{
if (o instanceof byte[])
return (byte[])o;
throw new ClassCastException("ScriptLibrary.castByteArray: invalid cast");
} // end castByteArray
public final ConferenceContext castConferenceContext(Object o)
{
if (o instanceof ConferenceContext)

View File

@ -11,7 +11,7 @@
*
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
* Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
* Copyright (C) 2001-02 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
@ -264,8 +264,12 @@ public class ScriptManager
{ // throw a ScriptingException
logger.error("Execution exception while running script",t);
if (t!=null)
{ // throw THIS exception
logger.error("Exception type: " + t.getClass().getName());
throw new ScriptingException(source,lang,e.getMessage(),t);
else
} // end if
else // throw the regular old name
throw new ScriptingException(source,lang,e.getMessage(),e);
} // end if
@ -273,15 +277,20 @@ public class ScriptManager
{ // usually indicates a compiler error in the scripting engine
logger.error("Script compilation error",e);
if (t!=null)
logger.error("Root cause:",t);
throw new ScriptingException(source,lang,e.getMessage());
{ // throw THIS exception
logger.error("Exception type: " + t.getClass().getName());
throw new ScriptingException(source,lang,e.getMessage(),t);
} // end if
else // throw the regular old name
throw new ScriptingException(source,lang,e.getMessage(),e);
} // end else if
else
{ // unknown exception type here!
logger.error("Unknown BSFException in script execution (reason " + e.getReason() + ")",e);
if (t!=null)
logger.error("Root cause:",t);
logger.error("Root cause (type " + t.getClass().getName() + "):",t);
throw new ScriptingException("unexpected exception while executing " + source + " [" + lang + "]",e);
} // end else

View File

@ -583,6 +583,7 @@ public class RequestImpl implements RequestInput
private CommunityContext community = null; // the current community
private LinkedList auto_cleanup = null; // auto-cleanup callbacks
private Document request_doc = null; // request parsed as an XML document
private LinkedList session_stack = null; // session stack
/*--------------------------------------------------------------------------------
* Constructor
@ -1555,6 +1556,22 @@ public class RequestImpl implements RequestInput
} // end registerCleanup
public void pushSession(VeniceUISession sess)
{
if (session_stack==null)
session_stack = new LinkedList();
session_stack.addFirst(session);
session = sess;
} // end pushSession
public void popSession()
{
if ((session_stack!=null) && (session_stack.size()>0))
session = (VeniceUISession)(session_stack.removeFirst());
} // end popSession
/*--------------------------------------------------------------------------------
* External static operations
*--------------------------------------------------------------------------------