axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gdani...@apache.org
Subject svn commit: rev 55133 - in webservices/axis/trunk/java/dev/scratch/gdaniels: . EngineToy EngineToy/src EngineToy/src/axis2 EngineToy/src/axis2/config EngineToy/src/axis2/description EngineToy/src/axis2/handlers EngineToy/src/axis2/meps EngineToy/src/axis2/om EngineToy/src/axis2/phases EngineToy/src/axis2/transport EngineToy/src/axis2/transport/http EngineToy/src/test
Date Wed, 20 Oct 2004 06:23:57 GMT
Author: gdaniels
Date: Tue Oct 19 23:23:56 2004
New Revision: 55133

Added:
   webservices/axis/trunk/java/dev/scratch/gdaniels/
   webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/
   webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/
   webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/
   webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/AxisEngine.java
   webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/Constants.java
   webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/ExecutionChain.java
   webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/ExecutionFrame.java
   webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/Handler.java
   webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/HandlerDescriptor.java
   webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/Message.java
   webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/MessageContext.java
   webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/Phase.java
   webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/Provider.java
   webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/Responder.java
   webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/config/
   webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/config/ChainSupplier.java
   webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/config/HandlerSupplier.java
   webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/config/Registry.java
   webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/config/Supplier.java
   webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/description/
   webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/description/Service.java
   webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/handlers/
   webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/handlers/BasicHandler.java
   webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/handlers/Chain.java
   webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/handlers/NullHandler.java
   webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/meps/
   webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/om/
   webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/om/OMElement.java
   webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/phases/
   webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/phases/DispatchPhase.java
   webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/transport/
   webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/transport/Transport.java
   webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/transport/http/
   webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/transport/http/HTTPConstants.java
   webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/transport/http/HTTPListener.java
   webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/transport/http/HTTPResponder.java
   webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/test/
   webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/test/AsyncTester.java
   webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/test/SampleHandler.java
   webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/test/ServiceDispatcher.java
   webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/test/Tester.java
Log:
Add some very basic sample code demoing some engine concepts.  In particular:

* Phased handler chains
* Responders
* Basic flow
* The ability to pause/restart MessageContexts

Run test.Tester to try it out.  Cleanup and more comprehensive tests on the way.

Added: webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/AxisEngine.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/AxisEngine.java	Tue
Oct 19 23:23:56 2004
@@ -0,0 +1,71 @@
+package axis2;
+
+import axis2.config.Registry;
+import axis2.config.Supplier;
+import axis2.config.HandlerSupplier;
+import axis2.handlers.NullHandler;
+import axis2.phases.DispatchPhase;
+import axis2.transport.Transport;
+
+import java.util.List;
+
+/**
+ * Toy AxisEngine
+ */
+public class AxisEngine {
+    static final NullHandler nullHandler = new NullHandler();
+
+    Registry registry;
+
+    public void init() {
+    }
+
+    public void setRegistry(Registry registry) {
+        this.registry = registry;
+    }
+
+    public void send(MessageContext context) throws Exception {
+        
+    }
+
+    public boolean receive(MessageContext context) throws Exception {
+        // An ExecutionChain is the set of Handlers which will be invoked
+        // for THIS particular interaction/MessageContext.  This is a
+        // particular mechanism for acheiving stateful pause/restart, and
+        // not necessarily the best one.
+        ExecutionChain chain = new ExecutionChain();
+
+        String transportName = context.getTransport();
+
+        // Receiving is always a matter of running the transport handlers first
+        Transport transport = registry.getTransport(transportName);
+        if (transport != null) {
+            List receiveHandlers = transport.getReceiveHandlers();
+            if (receiveHandlers != null && !receiveHandlers.isEmpty()) {
+                chain.addPhase("transport", new Phase());
+                chain.addHandlers(receiveHandlers);
+            }
+        }
+
+        chain.addPhase(Constants.GLOBAL_RECEIVE, new Phase());
+        chain.addPhase("dispatch", new DispatchPhase());
+        chain.addPhase("service", new Phase());
+
+        Supplier supplier = registry.getSupplier(Constants.GLOBAL_RECEIVE);
+        supplier.deployToExecutionChainPhase(chain, Constants.GLOBAL_RECEIVE);
+
+        supplier = registry.getSupplier("dispatch");
+        supplier.deployToExecutionChainPhase(chain, "dispatch");
+
+        Provider provider = new Provider();
+        supplier = new HandlerSupplier(provider);
+        supplier.deployToExecutionChainPhase(chain, "service"); 
+
+        context.setChain(chain);
+
+        // Set the chain back to the beginning.
+        chain.reset();
+
+        return context.start();
+    }
+}

Added: webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/Constants.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/Constants.java	Tue
Oct 19 23:23:56 2004
@@ -0,0 +1,9 @@
+package axis2;
+
+/**
+ * Constants
+ */
+public interface Constants {
+    static final String GLOBAL_RECEIVE = "global.receive";
+    static final String GLOBAL_SEND = "global.send";
+}

Added: webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/ExecutionChain.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/ExecutionChain.java
Tue Oct 19 23:23:56 2004
@@ -0,0 +1,95 @@
+package axis2;
+
+import java.util.*;
+
+/**
+ * ExecutionChain
+ */
+public class ExecutionChain {
+    List phases;
+    Map phasesByName;
+    Phase currentPhase;
+    int phaseIndex = 0;
+    int handlerIndex = 0;
+
+    public ExecutionChain() {
+        phases = new LinkedList();
+        phasesByName = new HashMap();
+    }
+
+    public void addHandler(Handler handler) {
+        if (currentPhase == null) {
+            // Make a new anonymous Phase?
+        }
+        currentPhase.addHandler(handler);
+    }
+
+    public void addPhase(String name, Phase phase) {
+        phases.add(phase);
+        currentPhase = phase;
+        phasesByName.put(name, phase);
+    }
+
+    public void addHandlerToPhase(String phaseName, Handler handler) throws Exception {
+        Phase phase = (Phase)phasesByName.get(phaseName);
+        if (phase == null) {
+            throw new Exception("No such phase!");
+        }
+        phase.addHandler(handler);
+    }
+
+    public void reset() {
+        currentPhase = (Phase)phases.get(0);
+    }
+
+    public boolean invoke(MessageContext context) throws Exception {
+        int ret = 0;
+        while (true) {
+            ret = currentPhase.step(context, handlerIndex);
+            if (ret == -1) {
+                return false; // paused
+            }
+
+            if (ret == 0) {
+                // done with this phase.
+                handlerIndex = 0;
+                phaseIndex++;
+                if (phases.size() == phaseIndex)
+                    return true;  // finished
+                currentPhase = (Phase)phases.get(phaseIndex);
+                continue;
+            }
+
+            handlerIndex = ret;
+        }
+    }
+
+    /**
+     * Convenience method to add all Handlers in a list
+     * @param handlers
+     */
+    public void addHandlers(List handlers) {
+        for (Iterator i = handlers.iterator(); i.hasNext();) {
+            Handler handler = (Handler) i.next();
+            addHandler(handler);
+        }
+    }
+
+    /**
+     * Convenience method to add Handlers to a given Phase from a List
+     *
+     * @param phaseName
+     * @param handlers
+     * @throws Exception
+     */
+    public void addHandlersToPhase(String phaseName, List handlers) throws Exception {
+        Phase phase = (Phase)phasesByName.get(phaseName);
+        if (phase == null) {
+            throw new Exception("No such phase '" + phaseName + "'");
+        }
+        for (Iterator i = handlers.iterator(); i.hasNext();) {
+            Handler handler = (Handler) i.next();
+            phase.addHandler(handler);
+        }
+    }
+}

Added: webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/ExecutionFrame.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/ExecutionFrame.java
Tue Oct 19 23:23:56 2004
@@ -0,0 +1,37 @@
+package axis2;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: Glen
+ * Date: Oct 19, 2004
+ * Time: 1:11:51 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public class ExecutionFrame {
+    Handler hander;
+    Object context;
+
+    public ExecutionFrame(Handler hander, Object context) {
+        this.hander = hander;
+        this.context = context;
+    }
+
+    public ExecutionFrame() {
+    }
+
+    public Handler getHander() {
+        return hander;
+    }
+
+    public void setHander(Handler hander) {
+        this.hander = hander;
+    }
+
+    public Object getContext() {
+        return context;
+    }
+
+    public void setContext(Object context) {
+        this.context = context;
+    }
+}

Added: webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/Handler.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/Handler.java	Tue
Oct 19 23:23:56 2004
@@ -0,0 +1,21 @@
+package axis2;
+
+/**
+ * The Handler interface.
+ */
+public interface Handler {
+    /**
+     *
+     * @param context
+     * @return
+     * @throws Exception
+     */
+    boolean invoke(MessageContext context) throws Exception;
+
+    void setOption(String name, Object value);
+    Object getOption(String name);
+
+    String getName();
+
+    void setName(String name);
+}

Added: webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/HandlerDescriptor.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/HandlerDescriptor.java
Tue Oct 19 23:23:56 2004
@@ -0,0 +1,27 @@
+package axis2;
+
+import java.util.Map;
+
+/**
+ * HandlerDescriptor
+ */
+public class HandlerDescriptor {
+    String handlerName;
+    Map options;
+
+    public String getHandlerName() {
+        return handlerName;
+    }
+
+    public void setHandlerName(String handlerName) {
+        this.handlerName = handlerName;
+    }
+
+    public Map getOptions() {
+        return options;
+    }
+
+    public void setOptions(Map options) {
+        this.options = options;
+    }
+}

Added: webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/Message.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/Message.java	Tue
Oct 19 23:23:56 2004
@@ -0,0 +1,23 @@
+package axis2;
+
+import axis2.om.OMElement;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: Glen
+ * Date: Aug 29, 2004
+ * Time: 10:12:18 AM
+ * To change this template use File | Settings | File Templates.
+ */
+public class Message {
+    MessageContext context;
+    OMElement root;
+
+    public OMElement getContent() {
+        return root;
+    }
+
+    public void setContent(OMElement root) {
+        this.root = root;
+    }
+}

Added: webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/MessageContext.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/MessageContext.java
Tue Oct 19 23:23:56 2004
@@ -0,0 +1,102 @@
+
+package axis2 ;
+
+import axis2.description.Service;
+import axis2.handlers.Chain;
+
+import java.util.HashMap;
+import java.util.Stack;
+import java.util.EmptyStackException;
+
+public class MessageContext {
+    /** The transport name */
+    String transport;
+
+    Responder responder;
+    AxisEngine engine;
+    Message message;
+    Service service;
+
+    /** The currently executing  */
+    ExecutionChain chain;
+
+    Phase currentPhase;
+    Handler next;
+
+    HashMap properties = new HashMap();
+
+    public boolean start() throws Exception {
+        return chain.invoke(this);
+    }
+    public boolean resume() throws Exception {
+        return chain.invoke(this);
+    }
+
+    public void setChain(ExecutionChain c) {
+        chain = c;
+    }
+
+    public AxisEngine getAxisEngine() {
+        return engine;
+    }
+
+    public void setAxisEngine(AxisEngine engine) {
+        this.engine = engine;
+    }
+
+    public Responder getResponder() {
+        return responder;
+    }
+
+    public void setResponder(Responder responder) {
+        this.responder = responder;
+    }
+
+    public Message getMessage() {
+        return message;
+    }
+
+    public void setMessage(Message message) {
+        this.message = message;
+    }
+
+    public void setProperty(String name, Object value) {
+        properties.put(name, value);
+    }
+
+    public Object getProperty(String name) {
+        return properties.get(name);
+    }
+
+    public boolean isPropertyTrue(String name) {
+        Object val = properties.get(name);
+        if (val == null) return false;
+        if (val instanceof Boolean) return ((Boolean)val).booleanValue();
+        if (val instanceof String) return ((String)val).equalsIgnoreCase("true");
+        return false;
+    }
+
+    public Phase getCurrentPhase() {
+        return currentPhase;
+    }
+
+    public void setCurrentPhase(Phase currentPhase) {
+        this.currentPhase = currentPhase;
+    }
+
+    public Service getService() {
+        return service;
+    }
+
+    public void setService(Service service) {
+        this.service = service;
+    }
+
+    public String getTransport() {
+        return transport;
+    }
+
+    public void setTransport(String transport) {
+        this.transport = transport;
+    }
+}

Added: webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/Phase.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/Phase.java	Tue Oct
19 23:23:56 2004
@@ -0,0 +1,56 @@
+package axis2;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * A Phase is a special kind of Handler which contains other Handlers
+ * and has an explicit step where it checks pre- and post-conditions.
+ * Subclasses implement checkPreconditions and checkPostconditions in
+ * order to do this work, and throw an appropriate Exception if the
+ * MessageContext does not indicate a valid state for the phase.
+ */
+public class Phase {
+    protected List handlers = new ArrayList();
+
+    public void checkPreconditions(MessageContext context) throws Exception {
+    }
+
+    public void checkPostconditions(MessageContext context) throws Exception {
+    }
+
+    public int step(MessageContext context, int start) throws Exception {
+        if (start == 0) {
+            checkPreconditions(context);
+            context.setCurrentPhase(this);
+        }
+
+        if (start == handlers.size()) {
+            checkPostconditions(context);
+            return 0; // finished
+        }
+
+        Handler handler = (Handler)handlers.get(start);
+        if (handler.invoke(context)) {
+            // Success, move on
+            start++;
+            return start;
+        }
+
+        return -1; // pause
+    }
+
+    public List getHandlers() {
+        return handlers;
+    }
+
+    public void setHandlers(List handlers) {
+        if (handlers == null)
+            throw new NullPointerException();
+        this.handlers = handlers;
+    }
+
+    public void addHandler(Handler handler) {
+        handlers.add(handler);
+    }
+}

Added: webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/Provider.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/Provider.java	Tue
Oct 19 23:23:56 2004
@@ -0,0 +1,27 @@
+package axis2;
+
+import axis2.handlers.BasicHandler;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: Glen
+ * Date: Aug 22, 2004
+ * Time: 10:11:48 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public class Provider extends BasicHandler {
+    public boolean invoke(MessageContext msgContext) throws Exception {
+        // Make sure there's a responder, if we're expecting to generate a response
+        Responder resp = msgContext.getResponder();
+        if (resp == null) {
+            throw new Exception("No responder in MessageContext!");
+        }
+
+        // call java class
+
+        // make response message
+        
+        resp.invoke(msgContext);
+        return true;
+    }
+}

Added: webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/Responder.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/Responder.java	Tue
Oct 19 23:23:56 2004
@@ -0,0 +1,13 @@
+package axis2;
+
+import axis2.handlers.BasicHandler;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: Glen
+ * Date: Aug 22, 2004
+ * Time: 10:07:26 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public interface Responder extends Handler {
+}

Added: webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/config/ChainSupplier.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/config/ChainSupplier.java
Tue Oct 19 23:23:56 2004
@@ -0,0 +1,24 @@
+package axis2.config;
+
+import axis2.ExecutionChain;
+import axis2.handlers.Chain;
+
+/**
+ * ChainSupplier
+ */
+public class ChainSupplier implements Supplier {
+    Chain chain;
+
+    public ChainSupplier(Chain chain) {
+        this.chain = chain;
+    }
+
+    public void deployToExecutionChain(ExecutionChain chain) {
+        chain.addHandlers(this.chain.getHandlers());
+    }
+
+    public void deployToExecutionChainPhase(ExecutionChain chain, String phase)
+            throws Exception {
+        chain.addHandlersToPhase(phase, this.chain.getHandlers());
+    }
+}

Added: webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/config/HandlerSupplier.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/config/HandlerSupplier.java
Tue Oct 19 23:23:56 2004
@@ -0,0 +1,23 @@
+package axis2.config;
+
+import axis2.ExecutionChain;
+import axis2.Handler;
+
+/**
+ * HandlerSupplier
+ */
+public class HandlerSupplier implements Supplier {
+    Handler handler;
+
+    public HandlerSupplier(Handler handler) {
+        this.handler = handler;
+    }
+
+    public void deployToExecutionChain(ExecutionChain chain) {
+        chain.addHandler(handler);
+    }
+
+    public void deployToExecutionChainPhase(ExecutionChain chain, String phase) throws Exception
{
+        chain.addHandlerToPhase(phase, handler);
+    }
+}

Added: webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/config/Registry.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/config/Registry.java
Tue Oct 19 23:23:56 2004
@@ -0,0 +1,30 @@
+package axis2.config;
+
+import axis2.transport.Transport;
+import axis2.Handler;
+
+import java.util.HashMap;
+
+/**
+ * A completely cheesy registry
+ */
+public class Registry {
+    HashMap transports = new HashMap();
+    HashMap suppliers = new HashMap();
+
+    public Transport getTransport(String name) {
+        return (Transport)transports.get(name);
+    }
+
+    public void deployTransport(String name, Transport transport) {
+        transports.put(name, transport);
+    }
+
+    public Supplier getSupplier(String name) {
+        return (Supplier)suppliers.get(name);
+    }
+
+    public void deployHandler(String name, Supplier handler) {
+        suppliers.put(name, handler);
+    }
+}

Added: webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/config/Supplier.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/config/Supplier.java
Tue Oct 19 23:23:56 2004
@@ -0,0 +1,12 @@
+package axis2.config;
+
+import axis2.ExecutionChain;
+
+/**
+ * Supplier
+ */
+public interface Supplier {
+    void deployToExecutionChain(ExecutionChain chain);
+    void deployToExecutionChainPhase(ExecutionChain chain, String phase)
+            throws Exception;
+}

Added: webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/description/Service.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/description/Service.java
Tue Oct 19 23:23:56 2004
@@ -0,0 +1,19 @@
+package axis2.description;
+
+import axis2.Handler;
+import axis2.MessageContext;
+import axis2.handlers.BasicHandler;
+
+/**
+ * Service represents a web service
+ */
+public class Service extends BasicHandler {
+    /**
+     * @param context
+     * @return
+     * @throws Exception
+     */
+    public boolean invoke(MessageContext context) throws Exception {
+        return true;
+    }
+}

Added: webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/handlers/BasicHandler.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/handlers/BasicHandler.java
Tue Oct 19 23:23:56 2004
@@ -0,0 +1,30 @@
+package axis2.handlers;
+
+import axis2.Handler;
+import axis2.MessageContext;
+
+import java.util.HashMap;
+
+/**
+ * BasicHandler, which has boilerplate implementaion.
+ */
+public abstract class BasicHandler implements Handler {
+    protected HashMap options = new HashMap();
+    protected String name;
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public void setOption(String name, Object value) {
+        options.put(name, value);
+    }
+
+    public Object getOption(String name) {
+        return options.get(name);
+    }
+}

Added: webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/handlers/Chain.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/handlers/Chain.java
Tue Oct 19 23:23:56 2004
@@ -0,0 +1,22 @@
+package axis2.handlers;
+
+import axis2.Handler;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ *
+ */
+public class Chain {
+    protected String name;
+    protected List handlers = new ArrayList();
+
+    public void addHandler(Handler h) {
+        handlers.add(h);
+    }
+
+    public List getHandlers() {
+        return handlers;
+    }
+}

Added: webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/handlers/NullHandler.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/handlers/NullHandler.java
Tue Oct 19 23:23:56 2004
@@ -0,0 +1,16 @@
+package axis2.handlers;
+
+import axis2.MessageContext;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: Glen
+ * Date: Sep 5, 2004
+ * Time: 6:01:19 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public class NullHandler extends BasicHandler {
+    public boolean invoke(MessageContext context) throws Exception {
+        return true; // keep going, do nothing
+    }
+}

Added: webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/om/OMElement.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/om/OMElement.java
Tue Oct 19 23:23:56 2004
@@ -0,0 +1,19 @@
+package axis2.om;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: Glen
+ * Date: Aug 29, 2004
+ * Time: 10:12:40 AM
+ * To change this template use File | Settings | File Templates.
+ */
+public class OMElement {
+    Object value;
+
+    public Object getObjectValue() {
+        return value;
+    }
+    public void setObjectValue(Object value) {
+        this.value = value;
+    }
+}

Added: webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/phases/DispatchPhase.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/phases/DispatchPhase.java
Tue Oct 19 23:23:56 2004
@@ -0,0 +1,23 @@
+package axis2.phases;
+
+import axis2.Phase;
+import axis2.MessageContext;
+import axis2.Handler;
+import axis2.description.Service;
+
+/**
+ * The Dispatch Phase implementation
+ */
+public class DispatchPhase extends Phase {
+    public void checkPreconditions(MessageContext context) throws Exception {
+        System.out.println("Checking preconditions for DispatchPhase...");
+    }
+
+    public void checkPostconditions(MessageContext context) throws Exception {
+        System.out.println("Checking postconditions for DispatchPhase...");
+        Service service = context.getService();
+        if (service == null)
+            throw new Exception("No service by end of Dispatch phase!");
+        System.out.println("Service is '" + service.getName() + "'");
+    }
+}

Added: webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/transport/Transport.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/transport/Transport.java
Tue Oct 19 23:23:56 2004
@@ -0,0 +1,30 @@
+package axis2.transport;
+
+import axis2.Handler;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * A Transport contains sender side and receiver side
+ */
+public class Transport {
+    List sendHandlers = new ArrayList();
+    List receiveHandlers = new ArrayList();
+
+    public List getSendHandlers() {
+        return sendHandlers;
+    }
+
+    public void addSendHandler(Handler handler) {
+        sendHandlers.add(handler);
+    }
+
+    public List getReceiveHandlers() {
+        return receiveHandlers;
+    }
+
+    public void addReceiveHandler(Handler handler) {
+        receiveHandlers.add(handler);
+    }
+}

Added: webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/transport/http/HTTPConstants.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/transport/http/HTTPConstants.java
Tue Oct 19 23:23:56 2004
@@ -0,0 +1,12 @@
+package axis2.transport.http;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: Glen
+ * Date: Aug 29, 2004
+ * Time: 10:58:21 AM
+ * To change this template use File | Settings | File Templates.
+ */
+public interface HTTPConstants {
+    static final String RESPONSE_SENT = "http.response-sent";
+}
\ No newline at end of file

Added: webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/transport/http/HTTPListener.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/transport/http/HTTPListener.java
Tue Oct 19 23:23:56 2004
@@ -0,0 +1,57 @@
+package axis2.transport.http;
+
+import axis2.AxisEngine;
+import axis2.Message;
+import axis2.MessageContext;
+import axis2.Responder;
+import axis2.om.OMElement;
+import test.ServiceDispatcher;
+
+/**
+ * A sample HTTP listener class
+ */
+public class HTTPListener implements HTTPConstants {
+    AxisEngine engine;
+
+    public void test(String msg) {
+        MessageContext context = new MessageContext();
+        context.setTransport("http");
+        
+        Message message = new Message();
+        OMElement om = new OMElement();
+        om.setObjectValue(msg);
+        message.setContent(om);
+        context.setMessage(message);
+
+        // Tell the dispatcher what service name to use...
+        context.setProperty(ServiceDispatcher.SERVICE_NAME, "AxisTestService");
+
+        // Drop an appropriate responder in the MessageContext
+        Responder responder = new HTTPResponder();
+        context.setResponder(responder);
+
+        boolean ret = false;
+        try {
+            ret = engine.receive(context);
+        } catch (Exception e) {
+            // Handle exception
+            e.printStackTrace();
+        }
+
+        if (ret == false) {
+            System.out.println("MessageContext was paused - I can't deal with that!");
+            return;
+        }
+
+        // If there was already a response, do nothing.  If not (as would be the case
+        // for one-way messages or messages whose responses were routed elsewhere),
+        // return a 202.
+        if (!context.isPropertyTrue(RESPONSE_SENT)) {
+            System.out.println("HTTPListener Sending 202");
+        }
+    }
+
+    public void setEngine(AxisEngine engine) {
+        this.engine = engine;
+    }
+}

Added: webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/transport/http/HTTPResponder.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/axis2/transport/http/HTTPResponder.java
Tue Oct 19 23:23:56 2004
@@ -0,0 +1,21 @@
+package axis2.transport.http;
+
+import axis2.MessageContext;
+import axis2.Responder;
+import axis2.handlers.BasicHandler;
+
+/**
+ * HTTPResponder
+ */
+public class HTTPResponder extends BasicHandler implements Responder, HTTPConstants {
+    public boolean invoke(MessageContext context) throws Exception {
+        // The message context currently contains the response message,
+        // so what we need to do here is send it as the servlet response.
+        context.setProperty(RESPONSE_SENT, Boolean.TRUE);
+
+        // put the right transport stuff on the end of the chain
+
+        System.out.println("HTTPResponder : Writing response... (no 202 should appear)");
+        return true;
+    }
+}

Added: webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/test/AsyncTester.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/test/AsyncTester.java	Tue
Oct 19 23:23:56 2004
@@ -0,0 +1,16 @@
+package test;
+
+/**
+ * Demo async behavior
+ */
+public class AsyncTester {
+    public static void main(String[] args) {
+        // This will be a demo of asynchronous server processing.
+
+        // Receive a message on one thread
+
+        // Pause processing so a worker thread can do the actual callout to a service method
+
+        // Worker thread sends response
+    }
+}

Added: webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/test/SampleHandler.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/test/SampleHandler.java
Tue Oct 19 23:23:56 2004
@@ -0,0 +1,37 @@
+package test;
+
+import axis2.Handler;
+import axis2.MessageContext;
+import axis2.handlers.BasicHandler;
+
+/**
+ * SampleHandler
+ */
+public class SampleHandler extends BasicHandler {
+    public static final String PAUSE = "SampleHandler.pause";
+
+    /**
+     * @param context
+     * @return
+     * @throws Exception
+     */
+    public boolean invoke(MessageContext context) throws Exception {
+        System.out.println(name + ": invoke()");
+        // If we're in the midst of running (i.e. this is the second
+        // time we've been called), remove the marker from the MC
+        // and continue.
+        if (context.getProperty(PAUSE) != null) {
+            context.setProperty(PAUSE, null);
+            return true;
+        }
+
+        // Check our pause option.  If it's not there
+        // or false, just return success.
+        Boolean ret = (Boolean)getOption(PAUSE);
+        if (ret == null || ret.booleanValue() == false)
+            return true;
+
+        context.setProperty(PAUSE, Boolean.TRUE);
+        return false;
+    }
+}

Added: webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/test/ServiceDispatcher.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/test/ServiceDispatcher.java
Tue Oct 19 23:23:56 2004
@@ -0,0 +1,25 @@
+package test;
+
+import axis2.handlers.BasicHandler;
+import axis2.MessageContext;
+import axis2.description.Service;
+
+/**
+ * ServiceDispatcher
+ */
+public class ServiceDispatcher extends BasicHandler {
+    public static final String SERVICE_NAME = "serviceName";
+
+    /**
+     * @param context
+     * @return
+     * @throws Exception
+     */
+    public boolean invoke(MessageContext context) throws Exception {
+        System.out.println(name + ": invoke()");
+        Service service = new Service();
+        service.setName((String)context.getProperty(SERVICE_NAME));
+        context.setService(service);
+        return true;
+    }
+}

Added: webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/test/Tester.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/gdaniels/EngineToy/src/test/Tester.java	Tue Oct
19 23:23:56 2004
@@ -0,0 +1,57 @@
+package test;
+
+import axis2.transport.http.HTTPListener;
+import axis2.transport.Transport;
+import axis2.AxisEngine;
+import axis2.Handler;
+import axis2.Constants;
+import axis2.handlers.Chain;
+import axis2.config.Registry;
+import axis2.config.ChainSupplier;
+import axis2.config.HandlerSupplier;
+
+/**
+ * Simple test simulating an HTTP request
+ */
+public class Tester {
+    public static void main(String[] args) {
+        HTTPListener listener = new HTTPListener();
+
+        AxisEngine engine = new AxisEngine();
+        Registry registry = new Registry();
+        engine.setRegistry(registry);
+
+        Transport httpTransport = new Transport();
+        Handler h = new SampleHandler();
+        h.setName("HTTP Transport Handler");
+        httpTransport.addReceiveHandler(h);
+        registry.deployTransport("http", httpTransport);
+
+        // Create a few handlers for the global Phase
+        h = new SampleHandler();
+        Chain chain = new Chain();
+        h.setName("Handler 1");
+        chain.addHandler(h);
+
+        h = new SampleHandler();
+        h.setName("Handler 2");
+        // Uncomment this to play with pausing the MC
+        // h.setOption(SampleHandler.PAUSE, Boolean.TRUE);
+        chain.addHandler(h);
+
+        h = new SampleHandler();
+        h.setName("Handler 3");
+        chain.addHandler(h);
+
+        registry.deployHandler(Constants.GLOBAL_RECEIVE, new ChainSupplier(chain));
+
+        // Create a dispatcher which goes into the dispatch Phase
+        h = new ServiceDispatcher();
+        h.setName("Dispatcher");
+        registry.deployHandler("dispatch", new HandlerSupplier(h));
+
+        listener.setEngine(engine);
+
+        listener.test("hey there");
+    }
+}

Mime
View raw message