synapse-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sami...@apache.org
Subject svn commit: r387860 - in /incubator/synapse/trunk/java/modules/core: src/org/apache/synapse/ src/org/apache/synapse/api/ src/org/apache/synapse/axis2/ src/org/apache/synapse/axis2/utils/ src/org/apache/synapse/resources/ src/org/apache/synapse/resource...
Date Wed, 22 Mar 2006 13:48:32 GMT
Author: saminda
Date: Wed Mar 22 05:48:29 2006
New Revision: 387860

URL: http://svn.apache.org/viewcvs?rev=387860&view=rev
Log:
Implementation of Proposed Resource handling framework by Paul. A test case is added to test
the frame work with the 
notion of REST GET invocation. 
SynapseEnvironment {
    ResourceHelper getResourceHelper();
}

public interface ResourceHelper {
    OMElement get(String uri); // get a resource
    OMElement get(String uri, ResourceUpdateAware mediator); // get a resource and be notified
of changes
    void registerResourceHandler(ResourceHandler rh, String urlRoot); 
         // register a handler for a given set of URLs (which share the same root)
    void notifyUpdate(String uriRoot);
         // a resource handler uses this to notify that all resources with that root
have changed (Resource Push 
model) 
}

public interface ResourceHandler {
    OMElement get(String uri);

    void setProperty(String name, String value);
    String getProperty(String name);
    String[] getPropertyNames();

    boolean isUpdated(String uriRoot); // used to poll if resource has changed (Pull model)
}

<synapse.xml>

<resource type="o.a.s.resources.HttpResource" uri-root=" http://fremantle.org/resources/">
   <property name="http.username">paul</property>
   <property name="http.password">pass</property>
   <property name=" http.proxy">proxy:80</property>
</resource>

ResourceHelpers notification mechanism is yet to commit. Mediator author can get ResourceHandlers
form synapse.xml or 
one can set it runtime. 

Added:
    incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/api/ResourceUpdateAware.java
    incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/resources/
    incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/resources/ResourceHandler.java
    incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/resources/ResourceHelper.java
    incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/resources/ResourceHelperFactory.java
    incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/resources/ResourceHelperImpl.java
    incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/resources/http/
    incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/resources/http/SimpleGETResourceHandler.java
    incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/resources/xml/
    incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/resources/xml/PropertyMediator.java
    incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/resources/xml/PropertyMediatorFactory.java
    incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/resources/xml/ResourceMediator.java
    incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/resources/xml/ResourceMediatorFactory.java
    incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/mediators/SimpleGETResourceAquiringMediator.java
    incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/spi/resources/
    incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/spi/resources/SimpleResourcesAquiringTest.java
Removed:
    incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/axis2/utils/
    incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/mediators/SimpleResourceAquireMediator.java
    incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/spi/injection/SimpleResourceAquireTest.java
Modified:
    incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/SynapseEnvironment.java
    incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/axis2/Axis2SynapseEnvironment.java
    incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/xml/ProcessorConfiguratorFinder.java

Modified: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/SynapseEnvironment.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/SynapseEnvironment.java?rev=387860&r1=387859&r2=387860&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/SynapseEnvironment.java
(original)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/SynapseEnvironment.java
Wed Mar 22 05:48:29 2006
@@ -16,6 +16,7 @@
 package org.apache.synapse;
 
 import org.apache.axis2.om.OMElement;
+import org.apache.synapse.resources.ResourceHelper;
 
 import java.util.Map;
 import java.util.HashMap;
@@ -130,5 +131,8 @@
     /**
      * This method is responsible for updating resources via simple GET interface.
      */
-    abstract public OMElement get(String url);
+   
+    abstract public ResourceHelper getResourceHelper();
+
+    abstract  public void addResourceProcessor(Processor p);
 }

Added: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/api/ResourceUpdateAware.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/api/ResourceUpdateAware.java?rev=387860&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/api/ResourceUpdateAware.java
(added)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/api/ResourceUpdateAware.java
Wed Mar 22 05:48:29 2006
@@ -0,0 +1,19 @@
+package org.apache.synapse.api;
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public interface ResourceUpdateAware {
+}

Modified: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/axis2/Axis2SynapseEnvironment.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/axis2/Axis2SynapseEnvironment.java?rev=387860&r1=387859&r2=387860&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/axis2/Axis2SynapseEnvironment.java
(original)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/axis2/Axis2SynapseEnvironment.java
Wed Mar 22 05:48:29 2006
@@ -26,15 +26,17 @@
 import org.apache.synapse.Processor;
 import org.apache.synapse.SynapseEnvironment;
 import org.apache.synapse.SynapseMessage;
-import org.apache.synapse.axis2.utils.ResourcesHandler;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.resources.ResourceHelperFactory;
+import org.apache.synapse.resources.ResourceHelper;
 
 import org.apache.synapse.xml.ProcessorConfiguratorFinder;
 
 /**
  *
  *
- * 
- * <p> This is the Axis2 implementation of the SynapseEnvironment 
+ *
+ * <p> This is the Axis2 implementation of the SynapseEnvironment
  *
  */
 public class Axis2SynapseEnvironment extends SynapseEnvironment {
@@ -46,7 +48,10 @@
 
     private Log log = LogFactory.getLog(getClass());
 
-	public Axis2SynapseEnvironment(OMElement synapseConfiguration,
+    //resourceProcessors keeps track of all <resources/>
+    private HashMap resourceProcessors = new HashMap();
+
+    public Axis2SynapseEnvironment(OMElement synapseConfiguration,
 			ClassLoader cl) {
 		super(null);
 		this.cl = cl;
@@ -67,13 +72,13 @@
 	}
 
 	public void send(SynapseMessage sm, SynapseEnvironment se) {
-		if (sm.isResponse()) 
+		if (sm.isResponse())
 			Axis2Sender.sendBack(sm);
-		else 
+		else
 			Axis2Sender.sendOn(sm, se);
 	}
 
-	
+
 	public Processor lookupProcessor(String name) {
 		return (Processor) processors.get(name);
 	}
@@ -88,12 +93,27 @@
 	public Processor getMasterProcessor() {
 		return mainprocessor;
 	}
-	
+
 	public void setMasterProcessor(Processor p) {
 		mainprocessor = p;
 	}
 
-    public OMElement get(String url) {
-        return ResourcesHandler.simpleGETRquest(url);        
+    // lookup methods for resources handling
+    public Processor lookupResourceProcessor(String uriRoot) {
+        return (Processor) resourceProcessors.get(uriRoot);
+    }
+
+    public void addResourceProcessor(Processor p) {
+        if (resourceProcessors.containsKey(p.getName())) {
+            throw new SynapseException(
+                    "Uri Root is already exists. Not acceptable");
+        }
+        resourceProcessors.put(p.getName(), p);
+    }
+
+    public ResourceHelper getResourceHelper() {
+        ResourceHelperFactory fac = ResourceHelperFactory.newInstance();
+        fac.setResourceProcessorsMap(this.resourceProcessors);
+        return fac.createResourceHelper();
     }
 }

Added: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/resources/ResourceHandler.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/resources/ResourceHandler.java?rev=387860&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/resources/ResourceHandler.java
(added)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/resources/ResourceHandler.java
Wed Mar 22 05:48:29 2006
@@ -0,0 +1,29 @@
+package org.apache.synapse.resources;
+
+import org.apache.axis2.om.OMElement;
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public interface ResourceHandler {
+    OMElement get(String uri);
+
+    void setProperty(String name, String value);
+    String getProperty(String name);
+    String[] getPropertyNames();
+
+    boolean isUpdated(String uriRoot); // used to poll if resource has changed (Pull model)
+
+}

Added: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/resources/ResourceHelper.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/resources/ResourceHelper.java?rev=387860&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/resources/ResourceHelper.java
(added)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/resources/ResourceHelper.java
Wed Mar 22 05:48:29 2006
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.synapse.resources;
+
+import org.apache.axis2.om.OMElement;
+import org.apache.synapse.api.ResourceUpdateAware;
+
+/**
+ *
+ */
+public interface ResourceHelper {
+
+    OMElement get(String uri); // get a resource
+    OMElement get(String uri, ResourceUpdateAware mediator); // get a resource and be notified
of changes
+    void registerResourceHandler(ResourceHandler rh, String urlRoot);
+         // register a handler for a given set of URLs (which share the same root)
+    void notifyUpdate(String uriRoot);
+         // a resource handler uses this to notify that all resources with that root have
changed (Resource Push model)
+}

Added: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/resources/ResourceHelperFactory.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/resources/ResourceHelperFactory.java?rev=387860&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/resources/ResourceHelperFactory.java
(added)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/resources/ResourceHelperFactory.java
Wed Mar 22 05:48:29 2006
@@ -0,0 +1,131 @@
+package org.apache.synapse.resources;
+
+
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.resources.xml.ResourceMediator;
+import org.apache.synapse.resources.xml.PropertyMediator;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public class ResourceHelperFactory {
+    private Log log = LogFactory.getLog(getClass());
+
+    private static ResourceHelperFactory fac;
+
+    private static boolean created = false;
+
+    private HashMap resourcesProcessorsMap;
+
+    private ResourceHelperFactory() {
+    }
+
+    public static ResourceHelperFactory newInstance() {
+        if (created) {
+            return fac;
+        } else {
+            fac = new ResourceHelperFactory();
+        }
+        return fac;
+    }
+
+    public ResourceHelper createResourceHelper() {
+        log.debug("Creating resources helper");
+        ResourceHelperImpl helper = new ResourceHelperImpl();
+
+        for (Iterator ite = resourcesProcessorsMap.keySet().iterator();
+             ite.hasNext();) {
+
+            String key = (String) ite.next();
+
+            Object obj = resourcesProcessorsMap.get(key);
+
+            if (obj instanceof ResourceMediator) {
+                ResourceMediator rp = (ResourceMediator) obj;
+                // getting the resource handler
+                ResourceHandler rh = getResourceHandler(rp.getType());
+                //filling the propertybags of ResourceHanlder
+                fillResourceHandler(rp,rh);
+                helper.registerResourceHandler(rh,rp.getURIRoot());
+            } else {
+                throw new SynapseException(
+                        "Should be found only ResourceHandler implementaions");
+            }
+
+        }
+        return helper;
+    }
+
+    private void fillResourceHandler(ResourceMediator rp, ResourceHandler rh) {
+        //filling the ResourcesHandlers properties
+        List rms = rp.getList();
+
+        for (Iterator ite = rms.iterator();ite.hasNext();) {
+            Object obj = ite.next();
+            if (obj instanceof PropertyMediator) {
+                PropertyMediator pp = (PropertyMediator)obj;
+                rh.setProperty(pp.getName(),pp.getValue());
+            } else {
+                throw new SynapseException("Support only PropertyMediator, found :" + obj.getClass().getName());
+            }
+        }
+
+
+
+    }
+
+    public void setResourceProcessorsMap(HashMap resourceProcessorsMap) {
+        this.resourcesProcessorsMap = resourceProcessorsMap;
+    }
+
+    private ResourceHandler getResourceHandler(String clazzName) {
+        ResourceHandler handler;
+        try {
+            Class clazz = Class.forName(clazzName);
+            Constructor ct = clazz.getConstructor(new Class[]{});
+            Object obj = ct.newInstance(new Object[]{});
+
+            if (obj instanceof ResourceHandler) {
+                handler = (ResourceHandler) obj;
+            } else {
+                throw new SynapseException(
+                        "Only Objects implements ResourceHandler should be available");
+            }
+            return handler;
+        } catch (ClassNotFoundException e) {
+            throw new SynapseException(e);
+        } catch (IllegalAccessException e) {
+            throw new SynapseException(e);
+        } catch (NoSuchMethodException e) {
+            throw new SynapseException(e);
+        } catch (InvocationTargetException e) {
+            throw new SynapseException(e);
+        } catch (InstantiationException e) {
+            throw new SynapseException(e);
+        }
+
+    }
+
+
+
+}

Added: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/resources/ResourceHelperImpl.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/resources/ResourceHelperImpl.java?rev=387860&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/resources/ResourceHelperImpl.java
(added)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/resources/ResourceHelperImpl.java
Wed Mar 22 05:48:29 2006
@@ -0,0 +1,76 @@
+package org.apache.synapse.resources;
+
+import org.apache.axis2.om.OMElement;
+import org.apache.synapse.api.ResourceUpdateAware;
+import org.apache.synapse.SynapseException;
+
+import java.util.HashMap;
+import java.util.Map;
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public class ResourceHelperImpl implements ResourceHelper {
+
+    protected HashMap resourceHandlers = new HashMap();
+
+
+    public OMElement get(String uri) { // get a resource
+        if (!(uri.equals("") || uri == null)) {
+            Object obj = resourceHandlers.get(uri);
+            if (obj != null) {
+                if (obj instanceof ResourceHandler) {
+                    ResourceHandler rh = (ResourceHandler) obj;
+
+                    return rh.get(uri);
+                } else {
+                    throw new SynapseException("Unsupported uri");
+                }
+            } else {
+                throw new SynapseException("Map doesnt contain the requested ResourceHandler");
+
+            }
+        } else {
+            throw new SynapseException("Unsupported ResourceHandler ");
+        }
+
+
+    }
+
+    public OMElement get(String uri,
+                         ResourceUpdateAware mediator) { // get a resource and be notified
of changes
+
+        throw new SynapseException("Not implemented");
+    }
+
+    public void registerResourceHandler(ResourceHandler rh, String urlRoot) {
+        //runtime null pointer setting if neeeded, otherwise it has already been checked.
+        if (rh != null && (urlRoot != null)) {
+            if (resourceHandlers.containsKey(urlRoot)) {
+                throw new SynapseException("Uri-root already exists");
+            } else {
+                resourceHandlers.put(urlRoot, rh);
+            }
+
+        }
+    }
+
+    // register a handler for a given set of URLs (which share the same root)
+    public void notifyUpdate(String uriRoot) {
+        throw new SynapseException("Not Implemented");
+    }
+
+
+}

Added: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/resources/http/SimpleGETResourceHandler.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/resources/http/SimpleGETResourceHandler.java?rev=387860&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/resources/http/SimpleGETResourceHandler.java
(added)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/resources/http/SimpleGETResourceHandler.java
Wed Mar 22 05:48:29 2006
@@ -0,0 +1,100 @@
+package org.apache.synapse.resources.http;
+
+import org.apache.synapse.resources.ResourceHandler;
+import org.apache.synapse.SynapseException;
+import org.apache.axis2.om.OMElement;
+import org.apache.axis2.om.OMAbstractFactory;
+import org.apache.axis2.om.impl.llom.builder.StAXOMBuilder;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.httpclient.methods.GetMethod;
+
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import java.util.HashMap;
+import java.util.Set;
+import java.io.IOException;
+import java.io.InputStream;
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public class SimpleGETResourceHandler implements ResourceHandler {
+
+    protected HashMap propertyMap = new HashMap();
+
+    public OMElement get(String uri) {
+        OMElement response = null;
+        HttpClient httpClient = new HttpClient();
+        /*
+         Following code technically gives the mediators to do a simple Http GET and aquire
+         some resources. Any mediator can use this method to quire its resources.
+        */
+        GetMethod httpGet = new GetMethod(uri);
+        try {
+
+            httpClient.executeMethod(httpGet);
+            if (httpGet.getStatusCode() == HttpStatus.SC_OK) {
+                response = processResponse(httpGet.getResponseBodyAsStream());
+            }
+        } catch (IOException e) {
+            throw new SynapseException(e);
+        } finally {
+            httpGet.releaseConnection();
+        }
+        if (response == null)
+            throw new SynapseException("There are no valid resonse resources");
+        return response;
+    }
+
+    public void setProperty(String name, String value) {
+        propertyMap.put(name, value);
+    }
+
+    public String getProperty(String name) {
+        return (String) propertyMap.get(name);
+    }
+
+    public String[] getPropertyNames() {
+
+        return ((String[]) propertyMap.keySet()
+                .toArray(new String[propertyMap.size()]));
+    }
+
+    public boolean isUpdated(String uriRoot){ // used to poll if resource has changed (Pull
model)
+
+        //todo: implement this method.
+        return false;
+    }
+
+    private static OMElement processResponse(InputStream inputStream) {
+        if (inputStream == null) {
+            throw new SynapseException(
+                    "Input Stream cannot be null for Resource request");
+        }
+        try {
+            XMLStreamReader parser = XMLInputFactory.newInstance()
+                    .createXMLStreamReader(inputStream);
+            StAXOMBuilder builder =
+                    new StAXOMBuilder(OMAbstractFactory.getOMFactory(), parser);
+            OMElement resourceElement = builder.getDocumentElement();
+            resourceElement.build(); //make sure we are in safe side
+            return resourceElement;
+        } catch (XMLStreamException e) {
+            throw new SynapseException(e);
+        }
+    }
+}

Added: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/resources/xml/PropertyMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/resources/xml/PropertyMediator.java?rev=387860&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/resources/xml/PropertyMediator.java
(added)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/resources/xml/PropertyMediator.java
Wed Mar 22 05:48:29 2006
@@ -0,0 +1,45 @@
+package org.apache.synapse.resources.xml;
+
+import org.apache.synapse.Processor;
+import org.apache.synapse.SynapseEnvironment;
+import org.apache.synapse.SynapseMessage;
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public class PropertyMediator implements Processor {
+
+    protected String name;
+    protected String value;
+    public boolean process(SynapseEnvironment se, SynapseMessage sm) {
+        // this is not a inline mediator. Its soule purpose is to provide properties from
Synapse.xml
+        return true;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public void setValue(String value) {
+        this.value = value;
+    }
+    public String getValue() {
+        return value;
+    }
+}

Added: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/resources/xml/PropertyMediatorFactory.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/resources/xml/PropertyMediatorFactory.java?rev=387860&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/resources/xml/PropertyMediatorFactory.java
(added)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/resources/xml/PropertyMediatorFactory.java
Wed Mar 22 05:48:29 2006
@@ -0,0 +1,57 @@
+package org.apache.synapse.resources.xml;
+
+import org.apache.synapse.xml.ProcessorConfigurator;
+import org.apache.synapse.xml.Constants;
+import org.apache.synapse.Processor;
+import org.apache.synapse.SynapseEnvironment;
+import org.apache.synapse.SynapseException;
+import org.apache.axis2.om.OMElement;
+import org.apache.axis2.om.OMAttribute;
+
+import javax.xml.namespace.QName;
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public class PropertyMediatorFactory implements ProcessorConfigurator {
+
+    private static final String PROPERTY = "property";
+
+    private static final QName PROPERTY_Q =
+            new QName(Constants.SYNAPSE_NAMESPACE,
+                    PROPERTY);
+
+    private static final QName PROPERTY_NAME_ATT_Q = new QName("name");
+
+    public Processor createProcessor(SynapseEnvironment se, OMElement el) {
+        PropertyMediator pp = new PropertyMediator();
+
+        OMAttribute name = el.getAttribute(PROPERTY_NAME_ATT_Q);
+        if (name == null) {
+            throw new SynapseException(PROPERTY + " must have "
+                    + PROPERTY_NAME_ATT_Q + " attribute: " + el.toString());
+        }
+
+        String value = el.getText();
+        pp.setName(name.getAttributeValue());
+        pp.setValue(value);
+
+        return pp;  
+    }
+
+    public QName getTagQName() {
+        return PROPERTY_Q;
+    }
+}

Added: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/resources/xml/ResourceMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/resources/xml/ResourceMediator.java?rev=387860&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/resources/xml/ResourceMediator.java
(added)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/resources/xml/ResourceMediator.java
Wed Mar 22 05:48:29 2006
@@ -0,0 +1,52 @@
+package org.apache.synapse.resources.xml;
+
+import org.apache.synapse.processors.ListProcessor;
+import org.apache.synapse.SynapseEnvironment;
+import org.apache.synapse.SynapseMessage;
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public class ResourceMediator extends ListProcessor {
+    protected String type;
+    protected String uriRoot;
+    public boolean process(SynapseEnvironment se, SynapseMessage smc) {
+        // this is not a inline mediator, It's soule purpose of existance is to populate
the ResourceHandler
+        return true;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public String getType(){
+        return type;
+    }
+
+    public void setURIRoot(String uriRoot) {
+        this.uriRoot = uriRoot;
+    }
+    public String getURIRoot() {
+        return uriRoot;
+    }
+
+    // From Interface
+	public String getName() {
+		return getURIRoot();
+	}
+	public void setName(String uriRoot) {
+		setURIRoot(uriRoot);
+	}
+}

Added: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/resources/xml/ResourceMediatorFactory.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/resources/xml/ResourceMediatorFactory.java?rev=387860&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/resources/xml/ResourceMediatorFactory.java
(added)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/resources/xml/ResourceMediatorFactory.java
Wed Mar 22 05:48:29 2006
@@ -0,0 +1,115 @@
+package org.apache.synapse.resources.xml;
+
+import org.apache.synapse.xml.Constants;
+import org.apache.synapse.xml.ProcessorConfigurator;
+import org.apache.synapse.xml.ProcessorConfiguratorFinder;
+import org.apache.synapse.Processor;
+import org.apache.synapse.SynapseEnvironment;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.processors.ListProcessor;
+import org.apache.axis2.om.OMElement;
+import org.apache.axis2.om.OMAttribute;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.xml.namespace.QName;
+import java.util.Iterator;
+import java.util.List;
+import java.util.LinkedList;
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public class ResourceMediatorFactory implements ProcessorConfigurator {
+
+    private Log log = LogFactory.getLog(getClass());
+
+    private static final String RESOURCE = "resource";
+
+	private static final QName RESOURCE_Q = new QName(Constants.SYNAPSE_NAMESPACE,
+			RESOURCE);
+
+	private static final QName RESOURCE_TYPE_ATT_Q = new QName("type");
+
+	private static final QName RESOURCE_URI_ROOT_ATT_Q = new QName("uri-root");
+
+    public Processor createProcessor(SynapseEnvironment se, OMElement el) {
+
+        ResourceMediator rp = new ResourceMediator();
+
+        this.addPropertiesMediatorsAndURIRoot(se,el,rp);
+
+        OMAttribute type = el.getAttribute(RESOURCE_TYPE_ATT_Q);
+		if (type == null) {
+			throw new SynapseException(RESOURCE + " must have "
+                    + RESOURCE_TYPE_ATT_Q + " attribute: " + el.toString());
+		}
+
+		OMAttribute uriRoot = el.getAttribute(RESOURCE_URI_ROOT_ATT_Q);
+		if (uriRoot == null) {
+			throw new SynapseException(RESOURCE + " must have "
+					+ RESOURCE_URI_ROOT_ATT_Q + " attribute: " + el.toString());
+		}
+        rp.setType(type.getAttributeValue());
+
+        rp.setURIRoot(uriRoot.getAttributeValue());
+
+        return rp;
+    }
+
+    public QName getTagQName() {
+        return RESOURCE_Q;
+    }
+
+    // this methods will give access to SynapseEnvironment's resouces registration
+
+
+    public void addPropertiesMediatorsAndURIRoot(SynapseEnvironment se, OMElement el,
+                                       ListProcessor p) {
+        this.setRUIRoot(se,el,p);
+
+        Iterator it = el.getChildElements();
+        List processors = new LinkedList();
+        while (it.hasNext()) {
+            OMElement child = (OMElement) it.next();
+            Processor proc =
+                    ProcessorConfiguratorFinder.getProcessor(se, child);
+
+            if (proc != null) {
+                if (proc instanceof PropertyMediator)
+                    processors.add(proc);
+                else
+                    throw new SynapseException(
+                            "List contains an invalid Processsor" +
+                                    proc.getClass().getName());
+            } else
+                log.info("Unknown child of all" + child.getLocalName());
+        }
+        p.setList(processors);
+
+    }
+
+    public void setRUIRoot(SynapseEnvironment se, OMElement el, Processor p) {
+
+		OMAttribute uriRoot = el.getAttribute(RESOURCE_URI_ROOT_ATT_Q);
+		if (uriRoot != null) {
+            // uri-root has already set
+            se.addResourceProcessor(p);
+		}
+		log.debug("compile "+el.getLocalName()+" with uri-root '"+p.getName() +"' on "+p.getClass());
+
+	}
+
+}

Modified: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/xml/ProcessorConfiguratorFinder.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/xml/ProcessorConfiguratorFinder.java?rev=387860&r1=387859&r2=387860&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/xml/ProcessorConfiguratorFinder.java
(original)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/xml/ProcessorConfiguratorFinder.java
Wed Mar 22 05:48:29 2006
@@ -31,6 +31,8 @@
 import org.apache.synapse.Processor;
 import org.apache.synapse.SynapseEnvironment;
 import org.apache.synapse.SynapseException;
+import org.apache.synapse.resources.xml.PropertyMediatorFactory;
+import org.apache.synapse.resources.xml.ResourceMediatorFactory;
 import org.apache.synapse.processors.builtin.xslt.XSLTProcessorConfigurator;
 import org.apache.synapse.processors.conditions.ExactlyOneProcessorConfigurator;
 import org.apache.synapse.processors.conditions.DefaultProcessorConfigurator;
@@ -66,7 +68,8 @@
             XSLTProcessorConfigurator.class,DefineProcessorConfigurator.class,
             SendNowProcessorConfigurator.class,DropProcessorConfigurator.class,
             RefDefineProcessorConfigurator.class, ExactlyOneProcessorConfigurator.class,
-            DefaultProcessorConfigurator.class};
+            DefaultProcessorConfigurator.class,
+            PropertyMediatorFactory.class, ResourceMediatorFactory.class};
 
 	private static void initialise() {
 

Added: incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/mediators/SimpleGETResourceAquiringMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/mediators/SimpleGETResourceAquiringMediator.java?rev=387860&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/mediators/SimpleGETResourceAquiringMediator.java
(added)
+++ incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/mediators/SimpleGETResourceAquiringMediator.java
Wed Mar 22 05:48:29 2006
@@ -0,0 +1,46 @@
+package org.apache.synapse.mediators;
+
+import org.apache.synapse.api.Mediator;
+import org.apache.synapse.api.EnvironmentAware;
+import org.apache.synapse.SynapseEnvironment;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.SynapseMessage;
+import org.apache.axis2.om.OMElement;
+import junit.framework.TestCase;
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public class SimpleGETResourceAquiringMediator
+        implements Mediator, EnvironmentAware {
+    private SynapseEnvironment se = null;
+
+    public void setSynapseEnvironment(SynapseEnvironment se) {
+        this.se = se;
+    }
+
+    public void setClassLoader(ClassLoader cl) {
+        throw new SynapseException(
+                "no class loader available for <classmediator/>");
+    }
+
+    public boolean mediate(SynapseMessage smc) {
+        OMElement resourcesElement = se.getResourceHelper()
+                .get("http://127.0.0.1:8090/axis2/services/npe/simple_resources");
+        // test for resources being not null
+        TestCase.assertNotNull(resourcesElement);
+        return true;
+    }
+}

Added: incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/spi/resources/SimpleResourcesAquiringTest.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/spi/resources/SimpleResourcesAquiringTest.java?rev=387860&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/spi/resources/SimpleResourcesAquiringTest.java
(added)
+++ incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/spi/resources/SimpleResourcesAquiringTest.java
Wed Mar 22 05:48:29 2006
@@ -0,0 +1,60 @@
+package org.apache.synapse.spi.resources;
+
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.om.OMElement;
+import org.apache.axis2.transport.http.SimpleHTTPServer;
+import org.apache.synapse.SynapseEnvironment;
+import org.apache.synapse.SynapseMessage;
+import org.apache.synapse.axis2.Axis2SynapseEnvironment;
+import org.apache.synapse.axis2.Axis2SynapseMessage;
+import org.apache.synapse.util.Axis2EnvSetup;
+import junit.framework.TestCase;
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public class SimpleResourcesAquiringTest extends TestCase {
+    private MessageContext msgCtx;
+    private SynapseEnvironment env;
+    private OMElement config;
+    private String synapsexml =
+                    "<synapse xmlns=\"http://ws.apache.org/ns/synapse\">\n" +
+                            "<resource type=\"org.apache.synapse.resources.http.SimpleGETResourceHandler\"
uri-root=\"http://127.0.0.1:8090/axis2/services/npe/simple_resources\">\n"+
+                                 "<property name=\"http.username\">paul</property>"+
+                                 "<property name=\"http.password\">pass</property>"+
+                            "</resource>\n"+
+                    "<classmediator class=\"org.apache.synapse.mediators.SimpleGETResourceAquiringMediator\"/>\n"
+
+                    "</synapse>";
+
+    private SimpleHTTPServer resources;
+
+    public void setUp() throws Exception {
+        msgCtx = Axis2EnvSetup.axis2Deployment("target/synapse-repository");
+        config = Axis2EnvSetup.getSynapseConfigElement(synapsexml);
+        env = new Axis2SynapseEnvironment(config,
+                Thread.currentThread().getContextClassLoader());
+        resources = new SimpleHTTPServer("target/synapse-repository-resources",8090);
+        resources.start();
+    }
+
+    protected void tearDown() throws Exception {
+        resources.stop();
+    }
+    public void testSimpleResourcesHandler() throws Exception {
+        SynapseMessage smc = new Axis2SynapseMessage(msgCtx);
+        env.injectMessage(smc);
+
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: synapse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: synapse-dev-help@ws.apache.org


Mime
View raw message