Author: asankha
Date: Mon Jun  5 03:25:52 2006
New Revision: 411729

URL: http://svn.apache.org/viewvc?rev=411729&view=rev
Log:
Support service level policies from Synapse (note: Axis2 policy support 
requires enhancements to fully support RM/Sec termination with this model)

Modified:
    
incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/ProxyServiceFactory.java
    
incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/ProxyService.java

Modified: 
incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/ProxyServiceFactory.java
URL: 
http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/ProxyServiceFactory.java?rev=411729&r1=411728&r2=411729&view=diff
==============================================================================
--- 
incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/ProxyServiceFactory.java
 (original)
+++ 
incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/ProxyServiceFactory.java
 Mon Jun  5 03:25:52 2006
@@ -25,6 +25,7 @@
 import javax.xml.namespace.QName;
 import java.net.URL;
 import java.net.MalformedURLException;
+import java.util.Iterator;
 
 /**
  * Creates a ProxyService instance using the XML fragment specification
@@ -131,7 +132,26 @@
         }
 
         //OMElement schema = elem.getFirstChildWithName(new 
QName(Constants.SYNAPSE_NAMESPACE, "schema"));
-        //OMElement policy = elem.getFirstChildWithName(new 
QName(Constants.SYNAPSE_NAMESPACE, "policy"));
+        Iterator policies = elem.getChildrenWithName(new 
QName(Constants.SYNAPSE_NAMESPACE, "policy"));
+        while (policies.hasNext()) {
+            Object o = policies.next();
+            if (o instanceof OMElement) {
+                OMElement policy = (OMElement) o;
+                OMAttribute url = policy.getAttribute(new 
QName(Constants.NULL_NAMESPACE, "url"));
+                if (url != null) {
+                    try {
+                        proxy.addServiceLevelPoliciy(new 
URL(url.getAttributeValue()));
+                    } catch (MalformedURLException e) {
+                        handleException("Invalid policy URL : " + 
url.getAttributeValue());
+                    }
+                } else {
+                    handleException("Policy element does not specify the 
policy URL");
+                }
+            } else {
+                handleException("Invalid 'policy' element found under element 
'policies'");
+            }
+        }
+
 
         return proxy;
     }

Modified: 
incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/ProxyService.java
URL: 
http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/ProxyService.java?rev=411729&r1=411728&r2=411729&view=diff
==============================================================================
--- 
incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/ProxyService.java
 (original)
+++ 
incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/ProxyService.java
 Mon Jun  5 03:25:52 2006
@@ -18,14 +18,20 @@
 import org.apache.axis2.description.WSDL11ToAxisServiceBuilder;
 import org.apache.axis2.description.AxisService;
 import org.apache.axis2.description.AxisOperation;
+import org.apache.axis2.description.PolicyInclude;
 import org.apache.synapse.SynapseException;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.ws.policy.util.PolicyReader;
+import org.apache.ws.policy.util.PolicyFactory;
+import org.apache.ws.policy.Policy;
 
 import java.net.URL;
 import java.io.IOException;
 import java.util.Iterator;
 import java.util.StringTokenizer;
+import java.util.List;
+import java.util.ArrayList;
 
 /**
  * <proxy name="string" type="wsdl|jms|rest" [description="string"]>
@@ -68,8 +74,8 @@
     private URL wsdl;
     /** The URLs for any supplied schemas */
     private URL[] schemas;
-    /** The URLs for any supplied policies */
-    private URL[] policies;
+    /** The URLs for any supplied policies that would apply at the service 
level */
+    private List serviceLevelPolicies = new ArrayList();
 
     public ProxyService() {}
 
@@ -107,6 +113,26 @@
                         proxyService.setExposeTransports(transposrts);
                     }
 
+                    // if service level policies are specified, apply them
+                    if (!serviceLevelPolicies.isEmpty()) {
+                        PolicyReader reader = 
PolicyFactory.getPolicyReader(PolicyFactory.OM_POLICY_READER);
+                        Policy svcEffectivePolicy = null;
+
+                        Iterator iter = serviceLevelPolicies.iterator();
+                        while (iter.hasNext()) {
+                            URL policyUrl = (URL) iter.next();
+                            if (svcEffectivePolicy == null) {
+                                svcEffectivePolicy = 
reader.readPolicy(policyUrl.openStream());
+                            } else {
+                                
svcEffectivePolicy.merge(reader.readPolicy(policyUrl.openStream()));
+                            }
+                        }
+
+                        PolicyInclude policyInclude = new PolicyInclude();
+                        
policyInclude.addPolicyElement(PolicyInclude.SERVICE_POLICY, 
svcEffectivePolicy);
+                        proxyService.setPolicyInclude(policyInclude);
+                    }
+
                     // create a custom message receiver for this proxy service 
to use a given named
                     // endpoint or sequence for forwarding/message mediation
                     ProxyServiceMessageReceiver msgRcvr = new 
ProxyServiceMessageReceiver();
@@ -208,12 +234,12 @@
         this.schemas = schemas;
     }
 
-    public URL[] getPolicies() {
-        return policies;
+    public List getServiceLevelPolicies() {
+        return serviceLevelPolicies;
     }
 
-    public void setPolicies(URL[] policies) {
-        this.policies = policies;
+    public void addServiceLevelPoliciy(URL serviceLevelPolicy) {
+        this.serviceLevelPolicies.add(serviceLevelPolicy);
     }
 
     private static void handleException(String msg) {



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

Reply via email to