ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1143485 - in /webservices/commons/trunk/modules/neethi/src: main/java/org/apache/neethi/ main/java/org/apache/neethi/builders/converters/ test/java/org/apache/neethi/ test/test-resources/samples/
Date Wed, 06 Jul 2011 16:16:29 GMT
Author: dkulp
Date: Wed Jul  6 16:16:28 2011
New Revision: 1143485

URL: http://svn.apache.org/viewvc?rev=1143485&view=rev
Log:
[NEETHI-12] Fixes to make sure the passed in element really is a Policy
element.

Added:
    webservices/commons/trunk/modules/neethi/src/test/test-resources/samples/test28.xml  
(with props)
Modified:
    webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/AbstractPolicyOperator.java
    webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/PolicyBuilder.java
    webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/converters/AbstractOMConverter.java
    webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/converters/AbstractStaxConverter.java
    webservices/commons/trunk/modules/neethi/src/test/java/org/apache/neethi/BasicTestCases.java
    webservices/commons/trunk/modules/neethi/src/test/java/org/apache/neethi/PolicyTestCase.java

Modified: webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/AbstractPolicyOperator.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/AbstractPolicyOperator.java?rev=1143485&r1=1143484&r2=1143485&view=diff
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/AbstractPolicyOperator.java
(original)
+++ webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/AbstractPolicyOperator.java
Wed Jul  6 16:16:28 2011
@@ -84,12 +84,14 @@ public abstract class AbstractPolicyOper
         }
         
         
-        result.addPolicyComponent(normalizeOperator(policy, reg, deep));
+        result.addPolicyComponent(normalizeOperator(policy, policy, reg, deep));
         return result;
     }
     
-    private static PolicyComponent normalizeOperator(PolicyOperator operator, 
-                                                     PolicyRegistry reg, boolean deep) {
+    private static PolicyComponent normalizeOperator(Policy policy, 
+                                                     PolicyOperator operator, 
+                                                     PolicyRegistry reg,
+                                                     boolean deep) {
                         
         short type = operator.getType();
                 
@@ -125,23 +127,35 @@ public abstract class AbstractPolicyOper
             } else if (policyComponent.getType() == Constants.TYPE_POLICY_REF) {
                 String uri = ((PolicyReference) policyComponent).getURI();
                 policyComponent = reg == null ? null : reg.lookup(uri);
-                
+                if (policyComponent == null && uri.charAt(0) == '#') {
+                    String id = uri.substring(1);
+
+                    policyComponent = reg == null ? null : reg.lookup(id);
+                    if (policyComponent == null) {
+                        for (PolicyComponent p : policy.getPolicyComponents()) {
+                            if (p instanceof Policy && id.equals(((Policy)p).getId()))
{
+                                policyComponent = p;
+                            }
+                        }
+                    }
+                }
                 if (policyComponent == null) {
                     throw new RuntimeException(uri + " can't be resolved");
                 }
                 
                 All all = new All();
                 all.addPolicyComponents(((Policy) policyComponent).getPolicyComponents());
-                childComponentsList.add(AbstractPolicyOperator.normalizeOperator(all, reg,
deep));
+                childComponentsList.add(AbstractPolicyOperator.normalizeOperator(policy,
all, reg, deep));
          
             } else if (policyComponent.getType() == Constants.TYPE_POLICY) {
                 All all = new All();
                 all.addPolicyComponents(((Policy) policyComponent).getPolicyComponents());
-                childComponentsList.add(AbstractPolicyOperator.normalizeOperator(all, reg,
deep));
+                childComponentsList.add(AbstractPolicyOperator.normalizeOperator(policy,
all, reg, deep));
                 
             } else {
                 childComponentsList.add(AbstractPolicyOperator
-                                            .normalizeOperator((PolicyOperator)policyComponent,
reg, deep));
+                                            .normalizeOperator(policy,
+                                                               (PolicyOperator)policyComponent,
reg, deep));
             }            
         }
         

Modified: webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/PolicyBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/PolicyBuilder.java?rev=1143485&r1=1143484&r2=1143485&view=diff
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/PolicyBuilder.java
(original)
+++ webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/PolicyBuilder.java
Wed Jul  6 16:16:28 2011
@@ -168,8 +168,13 @@ public class PolicyBuilder {
     }
 
     private Policy getPolicyOperator(Object element) {
-        String ns = factory.getConverterRegistry().findQName(element).getNamespaceURI();
-        return (Policy) processOperationElement(element, new Policy(defaultPolicyRegistry,
ns));
+        QName qn = factory.getConverterRegistry().findQName(element);
+        String ns = qn.getNamespaceURI();
+        
+        if (Constants.isPolicyNS(ns)) {
+            return (Policy) processOperationElement(element, new Policy(defaultPolicyRegistry,
ns));
+        }
+        throw new IllegalArgumentException(qn + " is not a <wsp:Policy> element.");

     }
 
     private ExactlyOne getExactlyOneOperator(Object element) {

Modified: webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/converters/AbstractOMConverter.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/converters/AbstractOMConverter.java?rev=1143485&r1=1143484&r2=1143485&view=diff
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/converters/AbstractOMConverter.java
(original)
+++ webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/converters/AbstractOMConverter.java
Wed Jul  6 16:16:28 2011
@@ -34,6 +34,9 @@ import org.apache.axiom.om.OMElement;
 public abstract class AbstractOMConverter {
 
     public QName getQName(OMElement s) {
+        if (s.getNamespace() == null) {
+            return new QName(s.getLocalName());
+        }
         return new QName(s.getNamespace().getNamespaceURI(), s.getLocalName());
     }
     public Map<QName, String> getAttributes(OMElement s) {

Modified: webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/converters/AbstractStaxConverter.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/converters/AbstractStaxConverter.java?rev=1143485&r1=1143484&r2=1143485&view=diff
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/converters/AbstractStaxConverter.java
(original)
+++ webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/converters/AbstractStaxConverter.java
Wed Jul  6 16:16:28 2011
@@ -52,6 +52,7 @@ public abstract class AbstractStaxConver
         return mp;
     }
     public Iterator<XMLStreamReader> getChildren(final XMLStreamReader s) {
+        final QName base = s.getName();
         try {
             int evt = s.getEventType();
             if (s.hasNext()) {
@@ -79,6 +80,15 @@ public abstract class AbstractStaxConver
                         && evt != XMLStreamReader.START_ELEMENT) {
                         evt = s.next();
                     }
+                    if (evt == XMLStreamReader.END_ELEMENT
+                        && !s.getName().equals(base)) {
+                        evt = s.next();
+                        while (s.hasNext() 
+                            && evt != XMLStreamReader.END_ELEMENT 
+                            && evt != XMLStreamReader.START_ELEMENT) {
+                            evt = s.next();
+                        }
+                    }
                     return evt == XMLStreamReader.START_ELEMENT;
                 } catch (Exception ex) {
                     return false;

Modified: webservices/commons/trunk/modules/neethi/src/test/java/org/apache/neethi/BasicTestCases.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/test/java/org/apache/neethi/BasicTestCases.java?rev=1143485&r1=1143484&r2=1143485&view=diff
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/test/java/org/apache/neethi/BasicTestCases.java
(original)
+++ webservices/commons/trunk/modules/neethi/src/test/java/org/apache/neethi/BasicTestCases.java
Wed Jul  6 16:16:28 2011
@@ -22,6 +22,8 @@ package org.apache.neethi;
 import java.io.IOException;
 import java.io.StringReader;
 import java.io.StringWriter;
+import java.util.Iterator;
+import java.util.List;
 
 import javax.xml.namespace.QName;
 import javax.xml.parsers.DocumentBuilder;
@@ -31,6 +33,7 @@ import javax.xml.stream.XMLOutputFactory
 import javax.xml.stream.XMLStreamWriter;
 
 import org.w3c.dom.Element;
+import org.w3c.dom.Node;
 
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
@@ -44,9 +47,8 @@ import org.junit.Test;
 /**
  * 
  */
-public class BasicTestCases extends Assert {
-    PolicyBuilder pb = new PolicyBuilder();
-    
+public class BasicTestCases extends PolicyTestCase {
+
     @Test
     public void testPrimitiveBuilder() throws Exception {
         String text = "<ns1:MaximumRetransmissionCount FooAtt=\"blah\" xmlns:ns1=\"http://foo\">10"
@@ -54,7 +56,7 @@ public class BasicTestCases extends Asse
         
         
         Assertion as = new XMLPrimitiveAssertionBuilder().build(getElementFromString(text),
-                                                                pb.getAssertionBuilderFactory());
+                                                                policyEngine.getAssertionBuilderFactory());
         assertNotNull(as);
         PrimitiveAssertion pas = (PrimitiveAssertion)as;
         assertEquals("10", pas.getTextValue());
@@ -81,7 +83,7 @@ public class BasicTestCases extends Asse
                                                                                         
 
         Assertion as = new XMLPrimitiveAssertionBuilder().build(getElementFromString(text),
-                                                                pb.getAssertionBuilderFactory());
+                                                                policyEngine.getAssertionBuilderFactory());
         assertNotNull(as);
         
         
@@ -109,7 +111,7 @@ public class BasicTestCases extends Asse
             + "</sp:SignedParts>";
 
         Assertion as = new XMLPrimitiveAssertionBuilder().build(getElementFromString(text),
-                                                                pb.getAssertionBuilderFactory());
+                                                                policyEngine.getAssertionBuilderFactory());
         assertNotNull(as);
         
         
@@ -144,4 +146,34 @@ public class BasicTestCases extends Asse
         
         return db.parse(new InputSource(new StringReader(s))).getDocumentElement();
     }
+    
+    @Test
+    public void testInvalidPolicyElementName() throws Exception {
+        for (int x = 0; x < 4; x++) {
+            try {
+                getPolicy("samples/test28.xml", x);
+            } catch (IllegalArgumentException ex) {
+                //expected
+                assertTrue(ex.getMessage().contains("Policies"));
+            }
+        }
+        Element d = getResourceAsDOM("samples/test28.xml");
+        assertNotNull(d);
+        Node nd = d.getFirstChild();
+        Policy first = null;
+        while (nd != null) {
+            if (nd instanceof Element) {
+                Policy p = policyEngine.getPolicy(nd);
+                if (p.getId() != null) {
+                    policyEngine.getPolicyRegistry().register(p.getId(), p);
+                }
+                if (first == null) {
+                    first = p;
+                }
+            }
+            nd = nd.getNextSibling();
+        }
+        first.normalize(true);
+        
+    }
 }

Modified: webservices/commons/trunk/modules/neethi/src/test/java/org/apache/neethi/PolicyTestCase.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/test/java/org/apache/neethi/PolicyTestCase.java?rev=1143485&r1=1143484&r2=1143485&view=diff
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/test/java/org/apache/neethi/PolicyTestCase.java
(original)
+++ webservices/commons/trunk/modules/neethi/src/test/java/org/apache/neethi/PolicyTestCase.java
Wed Jul  6 16:16:28 2011
@@ -58,7 +58,7 @@ public abstract class PolicyTestCase ext
     }
 
     public Policy getPolicy(String name) throws Exception {
-        return getPolicy(name, 3);
+        return getPolicy(name, 0);
     }
     public Policy getPolicy(String name, int type) throws Exception {
         switch (type) {

Added: webservices/commons/trunk/modules/neethi/src/test/test-resources/samples/test28.xml
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/test/test-resources/samples/test28.xml?rev=1143485&view=auto
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/test/test-resources/samples/test28.xml (added)
+++ webservices/commons/trunk/modules/neethi/src/test/test-resources/samples/test28.xml Wed
Jul  6 16:16:28 2011
@@ -0,0 +1,30 @@
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements. See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership. The ASF licenses this file
+  ~ to you 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.
+  -->
+<Policies xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
xmlns:wsaws="http://www.w3.org/2005/08/addressing">
+    <wsp:Policy Name="OuterPolicy" >
+        <wsp:All>
+            <wsp:PolicyReference URI="#PolicyID"/>
+        </wsp:All>
+    </wsp:Policy> 
+    <wsp:Policy Name="TestPolicy" wsu:Id="PolicyID" >
+         <wsp:All>
+            <wsaws:UsingAddressing xmlns:wsaws="http://www.w3.org/2006/05/addressing/wsdl"/>
+          </wsp:All>
+    </wsp:Policy>
+</Policies>
\ No newline at end of file

Propchange: webservices/commons/trunk/modules/neethi/src/test/test-resources/samples/test28.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: webservices/commons/trunk/modules/neethi/src/test/test-resources/samples/test28.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: webservices/commons/trunk/modules/neethi/src/test/test-resources/samples/test28.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Mime
View raw message