[jbossws-commits] JBossWS SVN: r3384 - in trunk: jbossws-core/src/main/java/org/jboss/ws/extensions/policy/metadata and 1 other directories.

jbossws-commits at lists.jboss.org jbossws-commits at lists.jboss.org
Fri Jun 1 17:29:33 EDT 2007


Author: thomas.diesler at jboss.com
Date: 2007-06-01 17:29:33 -0400 (Fri, 01 Jun 2007)
New Revision: 3384

Modified:
   trunk/build/ant-import/build-testsuite.xml
   trunk/jbossws-core/src/main/java/org/jboss/ws/extensions/policy/metadata/PolicyMetaDataBuilder.java
   trunk/jbossws-core/src/test/java/org/jboss/test/ws/jaxws/wspolicy/PolicyMetaDataBuilderTestCase.java
Log:
Use UnifiedVirtualFile to load policy resources

Modified: trunk/build/ant-import/build-testsuite.xml
===================================================================
--- trunk/build/ant-import/build-testsuite.xml	2007-06-01 21:05:29 UTC (rev 3383)
+++ trunk/build/ant-import/build-testsuite.xml	2007-06-01 21:29:33 UTC (rev 3384)
@@ -149,7 +149,6 @@
       <pathelement location="${jboss.server.deploy}/juddi-service.sar/juddi.jar"/>
       <pathelement location="${jboss.server.deploy}/juddi-service.sar/juddi-saaj.jar"/>
       <pathelement location="${jboss.server.deploy}/juddi-service.sar/scout.jar"/>
-      <pathelement location="${tests.output.dir}/resources/jaxws/wspolicy"/>
       <path refid="tests.javac.classpath"/>
     </path>
   </target>

Modified: trunk/jbossws-core/src/main/java/org/jboss/ws/extensions/policy/metadata/PolicyMetaDataBuilder.java
===================================================================
--- trunk/jbossws-core/src/main/java/org/jboss/ws/extensions/policy/metadata/PolicyMetaDataBuilder.java	2007-06-01 21:05:29 UTC (rev 3383)
+++ trunk/jbossws-core/src/main/java/org/jboss/ws/extensions/policy/metadata/PolicyMetaDataBuilder.java	2007-06-01 21:29:33 UTC (rev 3384)
@@ -33,11 +33,11 @@
 import org.jboss.logging.Logger;
 import org.jboss.ws.Constants;
 import org.jboss.ws.WSException;
-import org.jboss.wsf.spi.deployment.UnifiedDeploymentInfo;
 import org.jboss.ws.extensions.policy.PolicyScopeLevel;
 import org.jboss.ws.extensions.policy.annotation.PolicyAttachment;
 import org.jboss.ws.extensions.policy.deployer.PolicyDeployer;
 import org.jboss.ws.extensions.policy.deployer.exceptions.UnsupportedPolicy;
+import org.jboss.ws.integration.UnifiedVirtualFile;
 import org.jboss.ws.metadata.umdm.EndpointMetaData;
 import org.jboss.ws.metadata.umdm.ExtensibleMetaData;
 import org.jboss.ws.metadata.wsdl.WSDLBinding;
@@ -47,6 +47,7 @@
 import org.jboss.ws.metadata.wsdl.WSDLInterface;
 import org.jboss.ws.metadata.wsdl.WSDLProperty;
 import org.jboss.ws.metadata.wsdl.WSDLService;
+import org.jboss.wsf.spi.deployment.UnifiedDeploymentInfo;
 
 /**
  * A meta data builder for policies; handles checks for policy support
@@ -62,12 +63,12 @@
    private boolean serverSide = true;
    private boolean toolMode = false;
    private PolicyDeployer customDeployer;
-   
+
    public PolicyMetaDataBuilder()
    {
-      
+
    }
-   
+
    /**
     * To be used for tests or whenever a custom deployer is required
     * 
@@ -77,77 +78,85 @@
    {
       this.customDeployer = customDeployer;
    }
-   
+
    /**
     * Creates a new PolicyMetaDataBuilder for server side policy processing.
     * 
     * @param toolMode   True if running WSProvideTask (no policy deployments)
     * @return
     */
-   public static PolicyMetaDataBuilder getServerSidePolicyMetaDataBuilder(boolean toolMode) {
+   public static PolicyMetaDataBuilder getServerSidePolicyMetaDataBuilder(boolean toolMode)
+   {
       PolicyMetaDataBuilder builder = new PolicyMetaDataBuilder();
       builder.setServerSide(true);
       builder.setToolMode(toolMode);
       return builder;
    }
-   
+
    /**
     * Creates a new PolicyMetaDataBuilder for client side policy processing.
     * 
     * @return
     */
-   public static PolicyMetaDataBuilder getClientSidePolicyMetaDataBuilder() {
+   public static PolicyMetaDataBuilder getClientSidePolicyMetaDataBuilder()
+   {
       PolicyMetaDataBuilder builder = new PolicyMetaDataBuilder();
       builder.setServerSide(false);
       return builder;
    }
-   
+
    public void processPolicyAnnotations(EndpointMetaData epMetaData, Class<?> sepClass, UnifiedDeploymentInfo udi)
    {
-      for (org.jboss.ws.extensions.policy.annotation.Policy policy : sepClass.getAnnotation(PolicyAttachment.class).value())
+      UnifiedVirtualFile vfRoot = epMetaData.getServiceMetaData().getUnifiedMetaData().getRootFile();
+      for (org.jboss.ws.extensions.policy.annotation.Policy anPolicy : sepClass.getAnnotation(PolicyAttachment.class).value())
       {
          InputStream is = null;
          try
          {
-            DOMPolicyReader reader = (DOMPolicyReader) PolicyFactory.getPolicyReader(PolicyFactory.DOM_POLICY_READER);
-            if (toolMode)
-            {
-               is = Thread.currentThread().getContextClassLoader().getResourceAsStream(policy.policyFileLocation());
-            } else
-            {
-               is = udi.getMetaDataFileURL(policy.policyFileLocation()).openStream();
-            }
+            String policyFileLocation = anPolicy.policyFileLocation();
+            if (policyFileLocation.length() == 0)
+               throw new IllegalStateException("Cannot obtain @Policy.policyFileLocation");
+            
+            // The root virtual file is the uniform way to obtain resources
+            // It should work in all containers, server/client side
+            UnifiedVirtualFile vfPolicyFile = vfRoot.findChild(policyFileLocation);
+            is = vfPolicyFile.toURL().openStream();
+            
+            DOMPolicyReader reader = (DOMPolicyReader)PolicyFactory.getPolicyReader(PolicyFactory.DOM_POLICY_READER);
             Policy unnormalizedPolicy = reader.readPolicy(is);
             Policy normPolicy = (Policy)unnormalizedPolicy.normalize();
-            log.info("Deploying Annotated Policy = "+policy.policyFileLocation());
-            PolicyScopeLevel scope = policy.scope();
-            if (PolicyScopeLevel.WSDL_PORT.equals(scope) || PolicyScopeLevel.WSDL_PORT_TYPE.equals(scope) ||
-                  PolicyScopeLevel.WSDL_BINDING.equals(scope))
+            log.info("Deploying Annotated Policy = " + policyFileLocation);
+            PolicyScopeLevel scope = anPolicy.scope();
+            if (PolicyScopeLevel.WSDL_PORT.equals(scope) || PolicyScopeLevel.WSDL_PORT_TYPE.equals(scope) || PolicyScopeLevel.WSDL_BINDING.equals(scope))
             {
                deployPolicy(normPolicy, scope, epMetaData);
             }
             else
             {
-               throw new WSException("Policy scope "+scope+" not supported yet!");
+               throw new WSException("Policy scope " + scope + " not supported yet!");
             }
          }
          catch (Exception e)
          {
-            e.printStackTrace();
-         } finally
+            log.error(e);
+         }
+         finally
          {
-            try 
+            try
             {
                is.close();
-            } catch (Exception e) {}
+            }
+            catch (Exception e)
+            {
+            }
          }
       }
    }
-   
+
    public void processPolicyExtensions(EndpointMetaData epMetaData, WSDLDefinitions wsdlDefinitions)
    {
       //Collect all policies defined in our wsdl definitions
-      DOMPolicyReader reader = (DOMPolicyReader) PolicyFactory.getPolicyReader(PolicyFactory.DOM_POLICY_READER);
+      DOMPolicyReader reader = (DOMPolicyReader)PolicyFactory.getPolicyReader(PolicyFactory.DOM_POLICY_READER);
       PolicyRegistry localPolicyRegistry = new PolicyRegistry();
       for (WSDLExtensibilityElement policyElement : wsdlDefinitions.getExtensibilityElements(Constants.WSDL_ELEMENT_POLICY))
       {
@@ -166,14 +175,17 @@
          }
          else
          {
-            log.warn("Cannot get port '"+epMetaData.getPortName()+"' from the given wsdl definitions! Eventual policies attached to this port won't be considered.");
+            log
+                  .warn("Cannot get port '" + epMetaData.getPortName()
+                        + "' from the given wsdl definitions! Eventual policies attached to this port won't be considered.");
          }
       }
       else
       {
-         log.warn("Cannot get service '"+epMetaData.getServiceMetaData().getServiceName()+"' from the given wsdl definitions!  Eventual policies attached to this service won't be considered.");
+         log.warn("Cannot get service '" + epMetaData.getServiceMetaData().getServiceName()
+               + "' from the given wsdl definitions!  Eventual policies attached to this service won't be considered.");
       }
-      
+
       //Binding scope
       WSDLBinding wsdlBinding = wsdlDefinitions.getBindingByInterfaceName(epMetaData.getPortTypeName());
       if (wsdlBinding != null)
@@ -183,9 +195,10 @@
       }
       else
       {
-         log.warn("Cannot get binding for portType '"+epMetaData.getPortTypeName()+"' from the given wsdl definitions!  Eventual policies attached to this binding won't be considered.");
+         log.warn("Cannot get binding for portType '" + epMetaData.getPortTypeName()
+               + "' from the given wsdl definitions!  Eventual policies attached to this binding won't be considered.");
       }
-      
+
       //PortType scope
       WSDLInterface wsdlInterface = wsdlDefinitions.getInterface(epMetaData.getPortTypeName());
       if (wsdlInterface != null)
@@ -195,13 +208,14 @@
       }
       else
       {
-         log.warn("Cannot get portType '"+epMetaData.getPortTypeName()+"' from the given wsdl definitions! Eventual policies attached to this portType won't be considered.");
+         log.warn("Cannot get portType '" + epMetaData.getPortTypeName()
+               + "' from the given wsdl definitions! Eventual policies attached to this portType won't be considered.");
       }
    }
-   
+
    private void processPolicies(WSDLProperty policyProp, PolicyScopeLevel scope, PolicyRegistry localPolicies, ExtensibleMetaData extMetaData)
    {
-      if (policyProp!=null && policyProp.getValue()!=null)
+      if (policyProp != null && policyProp.getValue() != null)
       {
          StringTokenizer st = new StringTokenizer(policyProp.getValue(), ", ", false);
          while (st.hasMoreTokens())
@@ -211,12 +225,12 @@
          }
       }
    }
-   
+
    private void processPolicies(List<WSDLExtensibilityElement> policyReferences, PolicyScopeLevel scope, PolicyRegistry localPolicies, ExtensibleMetaData extMetaData)
    {
       if (policyReferences != null && policyReferences.size() != 0)
       {
-         DOMPolicyReader reader = (DOMPolicyReader) PolicyFactory.getPolicyReader(PolicyFactory.DOM_POLICY_READER); 
+         DOMPolicyReader reader = (DOMPolicyReader)PolicyFactory.getPolicyReader(PolicyFactory.DOM_POLICY_READER);
          for (WSDLExtensibilityElement element : policyReferences)
          {
             PolicyReference policyRef = reader.readPolicyReference(element.getElement());
@@ -224,7 +238,7 @@
          }
       }
    }
-   
+
    private Policy resolvePolicyReference(PolicyReference policyRef, PolicyRegistry localPolicies)
    {
       Policy normPolicy;
@@ -239,7 +253,7 @@
       }
       return normPolicy;
    }
-   
+
    private void deployPolicy(Policy policy, PolicyScopeLevel scope, ExtensibleMetaData extMetaData)
    {
       PolicyDeployer deployer;
@@ -264,8 +278,7 @@
          deployPolicyClientSide(policy, scope, extMetaData, deployer);
       }
    }
-   
-   
+
    private void deployPolicyServerSide(Policy policy, PolicyScopeLevel scope, ExtensibleMetaData extMetaData, PolicyDeployer deployer)
    {
       PolicyMetaExtension ext = (PolicyMetaExtension)extMetaData.getExtension(Constants.URI_WS_POLICY);
@@ -277,15 +290,14 @@
       try
       {
          Policy deployedPolicy = deployer.deployServerside(policy, extMetaData);
-         ext.addPolicy(scope,deployedPolicy);
+         ext.addPolicy(scope, deployedPolicy);
       }
       catch (UnsupportedPolicy e)
       {
          log.warn("Policy Not supported:" + policy.getPolicyURI());
       }
    }
-   
-   
+
    private void deployPolicyClientSide(Policy policy, PolicyScopeLevel scope, ExtensibleMetaData extMetaData, PolicyDeployer deployer)
    {
       PolicyMetaExtension ext = (PolicyMetaExtension)extMetaData.getExtension(Constants.URI_WS_POLICY);
@@ -301,7 +313,7 @@
       }
       catch (UnsupportedPolicy e)
       {
-         if (log.isDebugEnabled()) 
+         if (log.isDebugEnabled())
          {
             log.debug("Policy Not supported:" + policy.getPolicyURI());
          }

Modified: trunk/jbossws-core/src/test/java/org/jboss/test/ws/jaxws/wspolicy/PolicyMetaDataBuilderTestCase.java
===================================================================
--- trunk/jbossws-core/src/test/java/org/jboss/test/ws/jaxws/wspolicy/PolicyMetaDataBuilderTestCase.java	2007-06-01 21:05:29 UTC (rev 3383)
+++ trunk/jbossws-core/src/test/java/org/jboss/test/ws/jaxws/wspolicy/PolicyMetaDataBuilderTestCase.java	2007-06-01 21:29:33 UTC (rev 3384)
@@ -36,9 +36,12 @@
 import org.jboss.ws.extensions.policy.deployer.domainAssertion.NopAssertionDeployer;
 import org.jboss.ws.extensions.policy.metadata.PolicyMetaDataBuilder;
 import org.jboss.ws.extensions.policy.metadata.PolicyMetaExtension;
+import org.jboss.ws.integration.URLLoaderAdapter;
+import org.jboss.ws.integration.UnifiedVirtualFile;
 import org.jboss.ws.metadata.umdm.EndpointMetaData;
 import org.jboss.ws.metadata.umdm.ServerEndpointMetaData;
 import org.jboss.ws.metadata.umdm.ServiceMetaData;
+import org.jboss.ws.metadata.umdm.UnifiedMetaData;
 import org.jboss.ws.metadata.umdm.EndpointMetaData.Type;
 import org.jboss.ws.metadata.wsdl.WSDLDefinitions;
 import org.jboss.ws.tools.wsdl.WSDLDefinitionsFactory;
@@ -51,7 +54,7 @@
  */
 public class PolicyMetaDataBuilderTestCase extends JBossWSTest
 {
-   
+
    private WSDLDefinitions readWsdl(String filename) throws Exception
    {
       File wsdlFile = new File(filename);
@@ -61,7 +64,7 @@
       assertNotNull(wsdlDefinitions);
       return wsdlDefinitions;
    }
-   
+
    public void testEndpointScopePolicies() throws Exception
    {
       WSDLDefinitions wsdlDefinitions = readWsdl("resources/jaxws/wspolicy/TestService.wsdl");
@@ -69,17 +72,17 @@
       ServiceMetaData serviceMetaData = new ServiceMetaData(null, serviceName);
       QName portName = new QName("http://org.jboss.ws/jaxws/endpoint", "EndpointInterfacePort");
       QName portTypeName = new QName("http://org.jboss.ws/jaxws/endpoint", "EndpointInterface");
-      EndpointMetaData epMetaData = new ServerEndpointMetaData(serviceMetaData,portName,portTypeName,Type.JAXWS);
-      
-      Map<String,Class> map = new HashMap<String,Class>();
+      EndpointMetaData epMetaData = new ServerEndpointMetaData(serviceMetaData, portName, portTypeName, Type.JAXWS);
+
+      Map<String, Class> map = new HashMap<String, Class>();
       map.put("http://schemas.xmlsoap.org/ws/2005/02/rm/policy", NopAssertionDeployer.class);
       map.put("http://www.fabrikam123.example.com/stock", NopAssertionDeployer.class);
       map.put("http://schemas.xmlsoap.org/ws/2005/07/securitypolicy", NopAssertionDeployer.class);
       PolicyDeployer deployer = PolicyDeployer.newInstance(map);
       PolicyMetaDataBuilder builder = new PolicyMetaDataBuilder(deployer);
-      
+
       builder.processPolicyExtensions(epMetaData, wsdlDefinitions);
-      
+
       PolicyMetaExtension policyExt = (PolicyMetaExtension)epMetaData.getExtension(Constants.URI_WS_POLICY);
       Collection<Policy> bindingPolicies = policyExt.getPolicies(PolicyScopeLevel.WSDL_BINDING);
       assertNotNull(bindingPolicies);
@@ -87,65 +90,69 @@
       Iterator<Policy> bindingPoliciesIterator = bindingPolicies.iterator();
       String id1 = bindingPoliciesIterator.next().getId();
       String id2 = bindingPoliciesIterator.next().getId();
-      assertTrue(("RmPolicy".equalsIgnoreCase(id1) && "X509EndpointPolicy".equalsIgnoreCase(id2)) ||
-            ("RmPolicy".equalsIgnoreCase(id2) && "X509EndpointPolicy".equalsIgnoreCase(id1)));
-      
+      assertTrue(("RmPolicy".equalsIgnoreCase(id1) && "X509EndpointPolicy".equalsIgnoreCase(id2))
+            || ("RmPolicy".equalsIgnoreCase(id2) && "X509EndpointPolicy".equalsIgnoreCase(id1)));
+
       Collection<Policy> portPolicies = policyExt.getPolicies(PolicyScopeLevel.WSDL_PORT);
       assertNotNull(portPolicies);
       assertEquals(1, portPolicies.size());
       assertEquals("uselessPortPolicy", portPolicies.iterator().next().getId());
-      
+
       Collection<Policy> portTypePolicies = policyExt.getPolicies(PolicyScopeLevel.WSDL_PORT_TYPE);
       assertNotNull(portTypePolicies);
       assertEquals(2, portTypePolicies.size());
       Iterator<Policy> portTypePoliciesIterator = portTypePolicies.iterator();
       String id3 = portTypePoliciesIterator.next().getId();
       String id4 = portTypePoliciesIterator.next().getId();
-      assertTrue(("uselessPortTypePolicy".equalsIgnoreCase(id3) && "uselessPortTypePolicy2".equalsIgnoreCase(id4)) ||
-            ("uselessPortTypePolicy".equalsIgnoreCase(id4) && "uselessPortTypePolicy2".equalsIgnoreCase(id3)));
+      assertTrue(("uselessPortTypePolicy".equalsIgnoreCase(id3) && "uselessPortTypePolicy2".equalsIgnoreCase(id4))
+            || ("uselessPortTypePolicy".equalsIgnoreCase(id4) && "uselessPortTypePolicy2".equalsIgnoreCase(id3)));
    }
-   
-   
+
    public void testAnnotationEndpointScopePolicies() throws Exception
    {
-      Map<String,Class> map = new HashMap<String,Class>();
+      Map<String, Class> map = new HashMap<String, Class>();
       map.put("http://www.fabrikam123.example.com/stock", NopAssertionDeployer.class);
       PolicyDeployer deployer = PolicyDeployer.newInstance(map);
       PolicyMetaDataBuilder builder = new PolicyMetaDataBuilder(deployer);
       builder.setToolMode(true);
+
+      UnifiedVirtualFile vfRoot = new URLLoaderAdapter(new File("resources/jaxws/wspolicy").toURL());
+      UnifiedMetaData umd = new UnifiedMetaData(vfRoot);
+      ServiceMetaData serviceMetaData = new ServiceMetaData(umd, new QName("dummyServiceName"));
+      umd.addService(serviceMetaData);
+      EndpointMetaData epMetaData = new ServerEndpointMetaData(serviceMetaData, new QName("dummyPortName"), new QName("dummyPortTypeName"), Type.JAXWS);
+      serviceMetaData.addEndpoint(epMetaData);
       
-      EndpointMetaData epMetaData = new ServerEndpointMetaData(null, new QName("dummyPortName"),
-            new QName("dummyPortTypeName"), Type.JAXWS);
       builder.processPolicyAnnotations(epMetaData, TestMultipleEndpointPolicy.class, null);
-      
+
       PolicyMetaExtension policyExt = (PolicyMetaExtension)epMetaData.getExtension(Constants.URI_WS_POLICY);
-      
+
       Collection<Policy> portPolicies = policyExt.getPolicies(PolicyScopeLevel.WSDL_PORT);
       assertNotNull(portPolicies);
       assertEquals(2, portPolicies.size());
       Iterator<Policy> portPoliciesIterator = portPolicies.iterator();
       String id1 = portPoliciesIterator.next().getId();
       String id2 = portPoliciesIterator.next().getId();
-      assertTrue(("uselessPortPolicy".equalsIgnoreCase(id1) && "uselessPortPolicy2".equalsIgnoreCase(id2)) ||
-            ("uselessPortPolicy".equalsIgnoreCase(id2) && "uselessPortPolicy2".equalsIgnoreCase(id1)));
-      
+      assertTrue(("uselessPortPolicy".equalsIgnoreCase(id1) && "uselessPortPolicy2".equalsIgnoreCase(id2))
+            || ("uselessPortPolicy".equalsIgnoreCase(id2) && "uselessPortPolicy2".equalsIgnoreCase(id1)));
+
       Collection<Policy> portTypePolicies = policyExt.getPolicies(PolicyScopeLevel.WSDL_PORT_TYPE);
       assertNotNull(portTypePolicies);
       assertEquals(2, portTypePolicies.size());
       Iterator<Policy> portTypePoliciesIterator = portTypePolicies.iterator();
       String id3 = portTypePoliciesIterator.next().getId();
       String id4 = portTypePoliciesIterator.next().getId();
-      assertTrue(("uselessPortTypePolicy".equalsIgnoreCase(id3) && "uselessPortTypePolicy2".equalsIgnoreCase(id4)) ||
-            ("uselessPortTypePolicy".equalsIgnoreCase(id4) && "uselessPortTypePolicy2".equalsIgnoreCase(id3)));
-      
+      assertTrue(("uselessPortTypePolicy".equalsIgnoreCase(id3) && "uselessPortTypePolicy2".equalsIgnoreCase(id4))
+            || ("uselessPortTypePolicy".equalsIgnoreCase(id4) && "uselessPortTypePolicy2".equalsIgnoreCase(id3)));
+
       Collection<Policy> bindingPolicies = policyExt.getPolicies(PolicyScopeLevel.WSDL_BINDING);
       assertNotNull(bindingPolicies);
       assertEquals(2, bindingPolicies.size());
       Iterator<Policy> bindingPoliciesIterator = bindingPolicies.iterator();
       String id5 = bindingPoliciesIterator.next().getId();
       String id6 = bindingPoliciesIterator.next().getId();
-      assertTrue(("uselessBindingPolicy".equalsIgnoreCase(id5) && "uselessBindingPolicy2".equalsIgnoreCase(id6)) ||
-            ("uselessBindingPolicy".equalsIgnoreCase(id6) && "uselessBindingPolicy2".equalsIgnoreCase(id5)));
+      assertTrue(("uselessBindingPolicy".equalsIgnoreCase(id5) && "uselessBindingPolicy2".equalsIgnoreCase(id6))
+            || ("uselessBindingPolicy".equalsIgnoreCase(id6) && "uselessBindingPolicy2".equalsIgnoreCase(id5)));
    }
-   
+
 }




More information about the jbossws-commits mailing list