Author: ruwan
Date: Wed Feb 28 02:32:23 2007
New Revision: 512692

URL: http://svn.apache.org/viewvc?view=rev&rev=512692
Log:
New logic for the proxy service

Modified:
    
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/Constants.java
    
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ProxyServiceSerializer.java
    
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/AsyncCallback.java
    
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2SynapseEnvironment.java
    
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/ProxyService.java
    
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/ProxyServiceMessageReceiver.java
    
webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/TestMediator.java
    
webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/TestMediator.java

Modified: 
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/Constants.java
URL: 
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/Constants.java?view=diff&rev=512692&r1=512691&r2=512692
==============================================================================
--- 
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/Constants.java
 (original)
+++ 
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/Constants.java
 Wed Feb 28 02:32:23 2007
@@ -53,7 +53,7 @@
     String SCOPE_AXIS2 = "axis2";
 
     /** An string name which holds the out sequence property in the 
MessageContext */
-    String OUT_SEQUENCE = "outSequence";
+    String PROXY_SERVICE = "proxy.name";
 
     /** A key with this name on the message context set to Boolean.TRUE, 
indicates that this is a response */
     String ISRESPONSE_PROPERTY = "synapse.isresponse";

Modified: 
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ProxyServiceSerializer.java
URL: 
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ProxyServiceSerializer.java?view=diff&rev=512692&r1=512691&r2=512692
==============================================================================
--- 
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ProxyServiceSerializer.java
 (original)
+++ 
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ProxyServiceSerializer.java
 Wed Feb 28 02:32:23 2007
@@ -32,15 +32,24 @@
 import java.net.URI;
 
 /**
- * <proxy name="string" [description="string"] 
[transports="(http|https|jms)+|all"]>
- * <target sequence="name" | endpoint="name"/>?   // default is main sequence
- * <wsdl key="string">?
- * <schema key="string">*
- * <policy key="string">*
- * <property name="string" value="string"/>*
- * <enableRM/>+
- * <enableSec/>+
- * </proxy>
+ * <proxyService name="string" [transports="(http |https |jms )+|all"]>
+ *    <description>..</description>?
+ *    <target [inSequence="name"] [outSequence="name"] [faultSequence="name"] 
[endpoint="name"]>
+ *       <endpoint>...</endpoint>
+ *       <inSequence>...</inSequence>
+ *       <outSequence>...</outSequence>
+ *       <faultSequence>...</faultSequence>
+ *    </target>?
+ *    <publishWSDL uri=".." key="string">
+ *       <wsdl:definition>...</wsdl:definition>?
+ *       <wsdl20:description>...</wsdl20:description>?
+ *    </publishWSDL>?
+ *    <policy key="string">
+ *       // optional service parameters
+ *    <parameter name="string">
+ *       text | xml
+ *    </parameter>?
+ * </proxyService>
  */
 public class ProxyServiceSerializer {
 

Modified: 
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/AsyncCallback.java
URL: 
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/AsyncCallback.java?view=diff&rev=512692&r1=512691&r2=512692
==============================================================================
--- 
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/AsyncCallback.java
 (original)
+++ 
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/AsyncCallback.java
 Wed Feb 28 02:32:23 2007
@@ -91,9 +91,9 @@
         }
 
         // sets the out sequence if present to the in MC to mediate the 
response
-        if(synapseOutMsgCtx.getProperty(Constants.OUT_SEQUENCE) != null) {
-            synapseInMessageContext.setProperty(Constants.OUT_SEQUENCE,
-                    synapseOutMsgCtx.getProperty(Constants.OUT_SEQUENCE));
+        if(synapseOutMsgCtx.getProperty(Constants.PROXY_SERVICE) != null) {
+            synapseInMessageContext.setProperty(Constants.PROXY_SERVICE,
+                    synapseOutMsgCtx.getProperty(Constants.PROXY_SERVICE));
         }
 
         // send the response message through the synapse mediation flow

Modified: 
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2SynapseEnvironment.java
URL: 
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2SynapseEnvironment.java?view=diff&rev=512692&r1=512691&r2=512692
==============================================================================
--- 
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2SynapseEnvironment.java
 (original)
+++ 
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2SynapseEnvironment.java
 Wed Feb 28 02:32:23 2007
@@ -41,10 +41,13 @@
     private static final Log log = 
LogFactory.getLog(Axis2SynapseEnvironment.class);
 
     private SynapseConfiguration synapseConfig;
-    /** The StatisticsCollector object  */
+    /**
+     * The StatisticsCollector object
+     */
     private StatisticsCollector statisticsCollector;
 
-    public Axis2SynapseEnvironment() {}
+    public Axis2SynapseEnvironment() {
+    }
 
     public Axis2SynapseEnvironment(ConfigurationContext cfgCtx,
                                    SynapseConfiguration synapseConfig) {
@@ -59,20 +62,40 @@
             StatisticsUtils.processProxyServiceStatistics(synCtx);
             StatisticsUtils.processSequenceStatistics(synCtx);
         }
-        // if the outSequence property is present use that for the message 
mediation
-        // if not use the main mediator to mediate the outgoing message
-        if (synCtx.getProperty(Constants.OUT_SEQUENCE) != null) {
-            Mediator mediator = synCtx.getConfiguration().getNamedSequence(
-                    (String)synCtx.getProperty(Constants.OUT_SEQUENCE));
-            // check weather the sequence specified with the property 
outSequence is availabel
-            if(mediator != null) {
-                log.debug("Using the outSequence " + 
synCtx.getProperty(Constants.OUT_SEQUENCE)
-                        + " for the out message mediation");
-                mediator.mediate(synCtx);
+        
+        // if this is a response to a proxy service 
+        if (synCtx.getProperty(Constants.PROXY_SERVICE) != null) {
+
+            if (synCtx.getConfiguration().getProxyService((String) 
synCtx.getProperty(Constants.PROXY_SERVICE))
+                    .getTargetOutSequence() != null) {
+
+                String sequenceName = 
synCtx.getConfiguration().getProxyService(
+                        (String) 
synCtx.getProperty(Constants.PROXY_SERVICE)).getTargetOutSequence();
+                Mediator outSequence = 
synCtx.getConfiguration().getNamedSequence(sequenceName);
+
+                if (outSequence != null) {
+                    log.debug("Using the sequence named " + sequenceName + " 
for the outgoing message mediation of " +
+                            "the proxy service " + 
synCtx.getProperty(Constants.PROXY_SERVICE));
+                    outSequence.mediate(synCtx);
+                } else {
+                    log.error("Unable to find the sequence specified by the 
name " + sequenceName
+                            + " - [Message dropped]");
+                }
+
+            } else if (synCtx.getConfiguration().getProxyService((String) 
synCtx.getProperty(
+                    Constants.PROXY_SERVICE)).getTargetInLineOutSequence() != 
null) {
+
+                log.debug("Using the anonymous out sequence specified in the 
proxy service "
+                        + synCtx.getProperty(Constants.PROXY_SERVICE) + " for 
out going message mediation");
+                synCtx.getConfiguration().getProxyService((String) 
synCtx.getProperty(
+                        
Constants.PROXY_SERVICE)).getTargetInLineOutSequence().mediate(synCtx);
             } else {
-                log.error("Sequence named " + 
synCtx.getProperty(Constants.OUT_SEQUENCE)
-                        + " doesn't exists in synapse");
+
+                log.debug("Proxy service " + 
synCtx.getProperty(Constants.PROXY_SERVICE) + " does not specifies " +
+                        "an out sequence - sending the response back");
+                Axis2Sender.sendBack(synCtx);
             }
+
         } else {
             synCtx.getConfiguration().getMainMediator().mediate(synCtx);
         }

Modified: 
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/ProxyService.java
URL: 
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/ProxyService.java?view=diff&rev=512692&r1=512691&r2=512692
==============================================================================
--- 
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/ProxyService.java
 (original)
+++ 
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/ProxyService.java
 Wed Feb 28 02:32:23 2007
@@ -132,7 +132,7 @@
     private Object inLineWSDL;
     /**
      * The keys for any supplied schemas
-     */
+     */   // todo: do we need this
     private List schemaKeys = new ArrayList();
     /**
      * The keys for any supplied policies that would apply at the service level
@@ -292,7 +292,7 @@
             try {
                 proxyService.addParameter(p);
             } catch (AxisFault af) {
-                handleException("Error setting property : " + name + "" +
+                handleException("Error setting parameter : " + name + "" +
                         "to proxy service as a Parameter", af);
             }
         }
@@ -322,23 +322,9 @@
             }
         }
 
-        // create a custom message receiver for this proxy service to use a 
given named
-        // endpoint or sequence for forwarding/message mediation
+        // create a custom message receiver for this proxy service 
         ProxyServiceMessageReceiver msgRcvr = new 
ProxyServiceMessageReceiver();
         msgRcvr.setName(name);
-        if (targetEndpoint != null) {
-            msgRcvr.setTargetEndpoint(targetEndpoint);
-        } else {
-            if (targetInSequence != null) {
-                msgRcvr.setTargetInSequence(targetInSequence);
-            }
-            if (targetOutSequence != null) {
-                msgRcvr.setTargetOutSequence(targetOutSequence);
-            }
-            if (targetFaultSequence != null) {
-                msgRcvr.setTargetFaultSequence(targetFaultSequence);
-            }
-        }
 
         iter = proxyService.getOperations();
         while (iter.hasNext()) {

Modified: 
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/ProxyServiceMessageReceiver.java
URL: 
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/ProxyServiceMessageReceiver.java?view=diff&rev=512692&r1=512691&r2=512692
==============================================================================
--- 
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/ProxyServiceMessageReceiver.java
 (original)
+++ 
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/ProxyServiceMessageReceiver.java
 Wed Feb 28 02:32:23 2007
@@ -46,130 +46,83 @@
      */
     private String name = null;
 
-    /**
-     * A target endpoint name requests Synapse to directly forward this 
message to the
-     * endpoint definition with the given name. If a target endpoint or 
sequence is not
-     * specified, the default main mediator would be used for mediation.
-     */
-    private String targetEndpoint = null;
-    /**
-     * A target inSequence name specifies to Synapse to use the given named 
sequence for
-     * message mediation for incoming messages. If a target endpoint or 
inSequence is not
-     * specified, the default main mediator would be used for incoming message 
mediation.
-     */
-    private String targetInSequence = null;
-    /**
-     * A target outSequence name specifies to Synapse to use the given named 
sequence for
-     * message mediation for outgoing messages. If a target endpoint or 
outSequence is not
-     * specified, the default main mediator would be used for outgoing message 
mediation.
-     */
-    private String targetOutSequence = null;
-
-    private String targetFaultSequence = null;
-       /** The target endpoint, if assigned   */
-    private Endpoint targetInLineEndpoint = null;
-    /** The target inSequence, if assigned */
-    private SequenceMediator targetInLineInSequence = null;
-    /** The target outSequence, if assigned  */
-    private SequenceMediator targetInLineOutSequence = null;
-    /** The target faultSequence, if assigned  */
-    private SequenceMediator targetInLineFaultSequence = null;
-
     public void receive(org.apache.axis2.context.MessageContext mc) throws 
AxisFault {
 
-        log.debug("Proxy Service " + name + " received a new message...");
-        log.debug("Message To: " + (mc.getTo() != null ? 
mc.getTo().getAddress() : "null"));
-        log.debug("SOAPAction: " + (mc.getSoapAction() != null ? 
mc.getSoapAction() : "null"));
         if (log.isDebugEnabled()) {
+            log.debug("Proxy Service " + name + " received a new message...");
+            log.debug("Message To: " + (mc.getTo() != null ? 
mc.getTo().getAddress() : "null"));
+            log.debug("SOAPAction: " + (mc.getSoapAction() != null ? 
mc.getSoapAction() : "null"));
             log.debug("Body : \n" + mc.getEnvelope());
         }
 
         MessageContext synCtx = 
MessageContextCreatorForAxis2.getSynapseMessageContext(mc);
+        synCtx.setProperty(org.apache.synapse.Constants.PROXY_SERVICE, name);
+        ProxyService proxy = synCtx.getConfiguration().getProxyService(name);
 
         // Setting Required property to collect the proxy service statistics
         boolean statisticsEnable;
-        ProxyService currentProxyService = 
synCtx.getConfiguration().getProxyService(name);
-        if (currentProxyService != null) {
-            statisticsEnable = (org.apache.synapse.Constants.STATISTICS_ON == 
currentProxyService.getStatisticsEnable());
+        if (proxy != null) {
+            statisticsEnable = (org.apache.synapse.Constants.STATISTICS_ON == 
proxy.getStatisticsEnable());
             if (statisticsEnable) {
                 ProxyServiceStatisticsStack proxyServiceStatisticsStack = new 
ProxyServiceStatisticsStack();
                 boolean isFault = synCtx.getEnvelope().getBody().hasFault();
-                proxyServiceStatisticsStack.put(name, 
System.currentTimeMillis(), !synCtx.isResponse(), statisticsEnable, isFault);
-                
synCtx.setCorrelationProperty(org.apache.synapse.Constants.PROXYSERVICE_STATISTICS_STACK,
 proxyServiceStatisticsStack);
-            }
-        }
-
-        // if a target endpoint is specified, directly forward to that
-        if (targetEndpoint != null) {
-            Endpoint endpoint = 
synCtx.getConfiguration().getNamedEndpoint(targetEndpoint);
-            if (endpoint == null) {
-                // what else can/should we do instead of just logging the 
message as an error?
-                log.error("The endpoint named '" + targetEndpoint
-                        + "' is not defined. Dropping current message");
-            } else {
-                synCtx.setTo(new EndpointReference(endpoint.getAddress()));
-                log.debug("Forwarding message directly to the endpoint named : 
" + targetEndpoint);
-
-                org.apache.axis2.context.MessageContext axisInMsgContext =
-                        ((Axis2MessageContext) 
synCtx).getAxis2MessageContext();
-                Axis2FlexibleMEPClient.send(endpoint, synCtx);
+                proxyServiceStatisticsStack.put(
+                        name, System.currentTimeMillis(), 
!synCtx.isResponse(), statisticsEnable, isFault);
+                synCtx.setCorrelationProperty(
+                        
org.apache.synapse.Constants.PROXYSERVICE_STATISTICS_STACK, 
proxyServiceStatisticsStack);
             }
 
-        } else {
+            // Using inSequence for the incoming message mediation
+            if (proxy.getTargetInSequence() != null) {
 
-            // if a named outSequence os specified set it as a property to the 
MessageContext
-            if (targetOutSequence != null) {
-                log.debug("OutSequence " + targetOutSequence
-                        + " for the proxy set to the MessageContext");
-                synCtx.setProperty(org.apache.synapse.Constants.OUT_SEQUENCE, 
targetOutSequence);
+                Mediator inSequence = 
synCtx.getConfiguration().getNamedSequence(proxy.getTargetInSequence());
+                if (inSequence != null) {
+                    log.debug("Using the sequence named " + 
proxy.getTargetInSequence() + " for message mediation");
+                    inSequence.mediate(synCtx);
+                } else {
+                    // todo: what can we do ?????? throw an AxisFault
+                    log.error("Unable to find the in sequence for the proxy 
service " +
+                            "specified by the name " + 
proxy.getTargetInSequence() + " - [Message dropped]");
+                }
+            } else if (proxy.getTargetInLineInSequence() != null) {
+                log.debug("Using the anonymous in sequence of the proxy 
service for message mediation");
+                proxy.getTargetInLineInSequence().mediate(synCtx);
             }
 
-            // if a named inSequence is specified, use it for message mediation
-            if (targetInSequence != null) {
-                Mediator mediator = 
synCtx.getConfiguration().getNamedSequence(targetInSequence);
-                if (mediator == null) {
-                    // what else can/should we do instead of just logging the 
message as an error?
-                    log.error("The mediator named '" + targetInSequence
-                            + "' is not defined. Dropping current message");
+            if (proxy.getTargetEndpoint() != null) {
+                Endpoint endpoint = 
synCtx.getConfiguration().getNamedEndpoint(proxy.getTargetEndpoint());
+                if (endpoint != null) {
+                    log.debug("Forwarding message to the endpoint named "
+                            + proxy.getTargetEndpoint() + " after message 
mediation");
+                    synCtx.setTo(new EndpointReference(endpoint.getAddress()));
+                    Axis2FlexibleMEPClient.send(endpoint, synCtx);
                 } else {
-                    log.debug("Using sequence named : " + targetInSequence
-                            + " for message mediation");
-                    mediator.mediate(synCtx);
+                    // todo: what can we do ?????? throw an AxisFault
+                    log.error("Unable to find the endpoint for the proxy 
service " +
+                            "specified by the name " + 
proxy.getTargetEndpoint() + " - [Message dropped]");
                 }
-
-                // else default to the Synapse main mediator
-            } else {
-                log.debug("Using default 'main' mediator for message 
mediation");
-                synCtx.getEnvironment().injectMessage(synCtx);
+            } else if (proxy.getTargetInLineEndpoint() != null) {
+                log.debug("Forwarding the message to the anonymous " +
+                        "endpoint of the proxy service after message 
mediation");
+                synCtx.setTo(new 
EndpointReference(proxy.getTargetInLineEndpoint().getAddress()));
+                Axis2FlexibleMEPClient.send(proxy.getTargetInLineEndpoint(), 
synCtx);
             }
-        }
-    }
 
-    /**
-     * Specify a named target endpoint for direct message forwarding
-     *
-     * @param targetEndpoint the name of the target endpoint to be used
-     */
-    public void setTargetEndpoint(String targetEndpoint) {
-        this.targetEndpoint = targetEndpoint;
-    }
+            // if neither the in sequence nor endpoint is specified send the 
message using the implicit parameters
+            if (proxy.getTargetInSequence() == null && 
proxy.getTargetInLineInSequence() == null
+                    && proxy.getTargetEndpoint() == null && 
proxy.getTargetInLineEndpoint() == null) {
+
+                org.apache.axis2.context.MessageContext messageContext
+                        = ((Axis2MessageContext) 
synCtx).getAxis2MessageContext();
+                AxisEngine ae = new 
AxisEngine(messageContext.getConfigurationContext());
+                ae.send(messageContext);
 
-    /**
-     * Specify a named target sequence to be used for message mediation for 
incoming messages
-     *
-     * @param targetInSequence the name of the target sequence to be used for 
incoming messages
-     */
-    public void setTargetInSequence(String targetInSequence) {
-        this.targetInSequence = targetInSequence;
-    }
+            }
+        } else {
+            log.error("Proxy Service with the name " + name + " does not 
exists - [Message dropped]");
+            throw new AxisFault("Proxy Service with the name " + name + " does 
not exists");
+        }
 
-    /**
-     * Specify a named target sequence to be used for message mediation for 
outgoing messages
-     *
-     * @param targetOutSequence the name of the target sequence to be used for 
outgoing messages
-     */
-    public void setTargetOutSequence(String targetOutSequence) {
-        this.targetOutSequence = targetOutSequence;
     }
 
     /**
@@ -181,23 +134,4 @@
         this.name = name;
     }
 
-    public void setTargetFaultSequence(String targetFaultSequence) {
-        this.targetFaultSequence = targetFaultSequence;
-    }
-
-    public void setTargetInLineEndpoint(Endpoint targetInLineEndpoint) {
-        this.targetInLineEndpoint = targetInLineEndpoint;
-    }
-
-    public void setTargetInLineInSequence(SequenceMediator 
targetInLineInSequence) {
-        this.targetInLineInSequence = targetInLineInSequence;
-    }
-
-    public void setTargetInLineOutSequence(SequenceMediator 
targetInLineOutSequence) {
-        this.targetInLineOutSequence = targetInLineOutSequence;
-    }
-
-    public void setTargetInLineFaultSequence(SequenceMediator 
targetInLineFaultSequence) {
-        this.targetInLineFaultSequence = targetInLineFaultSequence;
-    }
 }

Modified: 
webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/TestMediator.java
URL: 
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/TestMediator.java?view=diff&rev=512692&r1=512691&r2=512692
==============================================================================
--- 
webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/TestMediator.java
 (original)
+++ 
webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/TestMediator.java
 Wed Feb 28 02:32:23 2007
@@ -20,7 +20,6 @@
 package org.apache.synapse.mediators;
 
 import org.apache.synapse.MessageContext;
-import org.apache.synapse.Mediator;
 
 /**
  * Test mediator class.

Modified: 
webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/TestMediator.java
URL: 
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/TestMediator.java?view=diff&rev=512692&r1=512691&r2=512692
==============================================================================
--- 
webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/TestMediator.java
 (original)
+++ 
webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/TestMediator.java
 Wed Feb 28 02:32:23 2007
@@ -19,7 +19,6 @@
 
 package org.apache.synapse;
 
-import org.apache.synapse.Mediator;
 import org.apache.synapse.mediators.AbstractMediator;
 
 /**



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to