marquee.xmlrpc.testing
Class ServletExample
java.lang.Object
javax.servlet.GenericServlet
javax.servlet.http.HttpServlet
marquee.xmlrpc.testing.ServletExample
- All Implemented Interfaces:
- java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig
- public class ServletExample
- extends javax.servlet.http.HttpServlet
A simple servlet example with two invocation handlers; en Echo handler and an XmlRpcClient
hooked up to the spellchecking service. This shows a nice feature introduced by Hannes
Waln?ffer in the Helma XML-RPC Library -- XmlRpcClients may also serve as InvocationHandlers.
How is this? XmlRpcClients have an invoke() method that you call when you want the client
object to invoke a method on the server the client is connected to. Invocation handlers also
has an invoke() method that the XmlRpcServer (a dispatcher actually) calls when an inbound
call to that handler is received.
By chance (oh, really?) the two invoke() methods have the same signature. By registering
an XmlRpcClient as an invocation handler, when the server receives a call to that handler,
it calls its invoke() method as it does with all handlers. The invoke() method of the client,
as I explained, in turn calls the server for which it was created. We have created a kind of
relay that is very useful when an applet is performing XML-RPC invocations on the server it
was loaded from. Applets may only communicate with the server it originated from, but if that
server has registered an XmlRpcClient as an invocation handler, that client will act as a
relay to another XML-RPC service.
The sample servlet registers an XmlRpcClient under the name "Speller", which is hooked up
to the spelling service at stuffeddog.com. Invoking the "Speller.invoke" method on this
servlet, will make the client autmatically relay the call to the stuffeddog server and
back to the caller. Fancy stuff. The first argument to the "Speller.invoke" method must
be the method name to call at stuffed dog. This is true when calling all clients acting as
relays. The second argument is the text to check the spelling for (a string), and the final
argument should be a Hashtable containing settings for the spell checker. An empty Hashtable
should be used (it does not support settings yet).
This is an extension to a sample servlet posted by David Watson at SourceForge. Thanks!
- Version:
- $Revision: 1.7 $
- Author:
- David Watson (davidthewatson@users.sourceforge.net), Greger Ohlson (greger.ohlson@marquee.se)
- See Also:
- Serialized Form
Method Summary |
void |
doPost(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res)
This is your standard handy dandy doPost() as it could appear in any servlet using
an XmlRpcServer. |
void |
init(javax.servlet.ServletConfig config)
|
Methods inherited from class javax.servlet.http.HttpServlet |
service |
Methods inherited from class javax.servlet.GenericServlet |
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ServletExample
public ServletExample()
init
public void init(javax.servlet.ServletConfig config)
-
doPost
public void doPost(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res)
- This is your standard handy dandy doPost() as it could appear in any servlet using
an XmlRpcServer. It's not specific to this example. The exception handling leaves
a lot to imagination, though.