geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r689225 - in /geronimo/server/trunk/plugins/jaxws/geronimo-jaxws/src: main/java/org/apache/geronimo/jaxws/handler/ test/java/org/apache/geronimo/jaxws/handler/ test/resources/
Date Tue, 26 Aug 2008 21:07:10 GMT
Author: gawor
Date: Tue Aug 26 14:07:09 2008
New Revision: 689225

URL: http://svn.apache.org/viewvc?rev=689225&view=rev
Log:
improve wildcard matching for handlers

Modified:
    geronimo/server/trunk/plugins/jaxws/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/handler/GeronimoHandlerChainBuilder.java
    geronimo/server/trunk/plugins/jaxws/geronimo-jaxws/src/test/java/org/apache/geronimo/jaxws/handler/GeronimoHandlerResolverTest.java
    geronimo/server/trunk/plugins/jaxws/geronimo-jaxws/src/test/resources/handlers_mixed.xml
    geronimo/server/trunk/plugins/jaxws/geronimo-jaxws/src/test/resources/handlers_port.xml
    geronimo/server/trunk/plugins/jaxws/geronimo-jaxws/src/test/resources/handlers_service.xml

Modified: geronimo/server/trunk/plugins/jaxws/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/handler/GeronimoHandlerChainBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/jaxws/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/handler/GeronimoHandlerChainBuilder.java?rev=689225&r1=689224&r2=689225&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/jaxws/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/handler/GeronimoHandlerChainBuilder.java
(original)
+++ geronimo/server/trunk/plugins/jaxws/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/handler/GeronimoHandlerChainBuilder.java
Tue Aug 26 14:07:09 2008
@@ -21,6 +21,7 @@
 import org.slf4j.LoggerFactory;
 import org.apache.geronimo.jaxws.JAXWSUtils;
 import org.apache.geronimo.xbeans.javaee.HandlerChainType;
+import org.apache.xmlbeans.XmlCursor;
 
 import javax.xml.namespace.QName;
 import javax.xml.ws.handler.Handler;
@@ -28,15 +29,17 @@
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 /**
  * @version $Rev$ $Date$
  */
 public class GeronimoHandlerChainBuilder extends AnnotationHandlerChainBuilder {
     private static final Logger log = LoggerFactory.getLogger(GeronimoHandlerChainBuilder.class);
-
+        
     private ClassLoader classLoader = null;
-    private javax.xml.ws.handler.PortInfo portInfo;
+    private PortInfo portInfo;
 
     public GeronimoHandlerChainBuilder(ClassLoader classloader,
                                        PortInfo portInfo) {
@@ -50,25 +53,37 @@
 
     protected List<Handler> buildHandlerChain(HandlerChainType hc,
                                               ClassLoader classLoader) {
-        if (matchServiceName(portInfo, hc.getServiceNamePattern())
-                && matchPortName(portInfo, hc.getPortNamePattern())
-                && matchBinding(portInfo, hc.getProtocolBindings())) {
+        if (matchServiceName(portInfo, hc)
+                && matchPortName(portInfo, hc)
+                && matchBinding(portInfo, hc)) {
             return super.buildHandlerChain(hc, classLoader);
         } else {
             return Collections.emptyList();
         }
     }
 
-    private boolean matchServiceName(PortInfo info, String namePattern) {
-        return match((info == null ? null : info.getServiceName()), namePattern);
+    private boolean matchServiceName(PortInfo info, HandlerChainType hc) {              

+        if (hc.isSetServiceNamePattern()) {
+            QName serviceName = (info == null) ? null : info.getServiceName(); 
+            return match(hc.xgetServiceNamePattern().newCursor(), serviceName, hc.getServiceNamePattern());
+        } else {
+            // handler matches since no service-name-pattern
+            return true;
+        }
     }
 
-    private boolean matchPortName(PortInfo info, String namePattern) {
-        return match((info == null ? null : info.getPortName()), namePattern);
+    private boolean matchPortName(PortInfo info, HandlerChainType hc) {
+        if (hc.isSetPortNamePattern()) {
+            QName portName = (info == null) ? null : info.getPortName();                
   
+            return match(hc.xgetPortNamePattern().newCursor(), portName, hc.getPortNamePattern());
+        } else {
+            // handler maches no port-name-pattern
+            return true;
+        }
     }
 
-    private boolean matchBinding(PortInfo info, List bindings) {
-        return match((info == null ? null : info.getBindingID()), bindings);
+    private boolean matchBinding(PortInfo info, HandlerChainType hc) {
+        return match((info == null ? null : info.getBindingID()), hc.getProtocolBindings());
     }
 
     private boolean match(String binding, List bindings) {
@@ -98,11 +113,11 @@
         }
         return sortHandlers(buildHandlerChain(hc, getHandlerClassLoader()));
     }
-
+    
     /*
      * Performs basic localName matching, namespaces are not checked!
      */
-    private boolean match(QName name, String namePattern) {
+    private boolean match(XmlCursor node, QName name, String namePattern) {
         if (name == null) {
             return (namePattern == null || namePattern.equals("*"));
         } else {
@@ -113,21 +128,32 @@
 
                 // get the local name from pattern
                 int pos = namePattern.indexOf(':');
-                localNamePattern = (pos == -1) ? namePattern : namePattern
-                        .substring(pos + 1);
+                if (pos == -1) {
+                    localNamePattern = namePattern;
+                } else {       
+                    localNamePattern = namePattern.substring(pos + 1);
+                    
+                    String prefix = namePattern.substring(0, pos);
+                    String namespace = node.namespaceForPrefix(prefix.trim());
+                    if (namespace == null) {
+                        namespace = prefix;
+                    }
+                    
+                    // check namespace
+                    if (!namespace.equals(name.getNamespaceURI())) {
+                        return false;
+                    }
+                }
+                
+                // check local name
                 localNamePattern = localNamePattern.trim();
-
-                if (localNamePattern.equals("*")) {
-                    // matches anything
-                    return true;
-                } else if (localNamePattern.endsWith("*")) {
-                    // match start
-                    localNamePattern = localNamePattern.substring(0,
-                            localNamePattern.length() - 1);
-                    return name.getLocalPart().startsWith(localNamePattern);
-                } else {
-                    // match exact
-                    return name.getLocalPart().equals(localNamePattern);
+                if (localNamePattern.contains("*")) {
+                    //wildcard pattern matching
+                    Pattern pattern = Pattern.compile(localNamePattern.replace("*", "(\\w|\\.|-|_)*"));
+                    Matcher matcher = pattern.matcher(name.getLocalPart());
+                    return matcher.matches();
+                } else { 
+                    return localNamePattern.equals(name.getLocalPart());
                 }
             }
         }

Modified: geronimo/server/trunk/plugins/jaxws/geronimo-jaxws/src/test/java/org/apache/geronimo/jaxws/handler/GeronimoHandlerResolverTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/jaxws/geronimo-jaxws/src/test/java/org/apache/geronimo/jaxws/handler/GeronimoHandlerResolverTest.java?rev=689225&r1=689224&r2=689225&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/jaxws/geronimo-jaxws/src/test/java/org/apache/geronimo/jaxws/handler/GeronimoHandlerResolverTest.java
(original)
+++ geronimo/server/trunk/plugins/jaxws/geronimo-jaxws/src/test/java/org/apache/geronimo/jaxws/handler/GeronimoHandlerResolverTest.java
Tue Aug 26 14:07:09 2008
@@ -47,7 +47,7 @@
         InputStream in = getClass().getResourceAsStream("/handlers_service.xml");
         assertTrue(in != null);
         HandlerChainsType handlerChains = toHandlerChains(in);
-        assertEquals(3, handlerChains.getHandlerChainArray().length);
+        assertEquals(4, handlerChains.getHandlerChainArray().length);
         
         GeronimoHandlerResolver resolver = 
             new GeronimoHandlerResolver(getClass().getClassLoader(), getClass(), handlerChains,
null);
@@ -72,6 +72,10 @@
         QName serviceName4 = new QName("http://foo", "BarFoo");
         handlers = resolver.getHandlerChain(new TestPortInfo(null, null, serviceName4));

         assertEquals(0, handlers.size());
+        
+        QName serviceName5 = new QName("https://foo", "Bar");
+        handlers = resolver.getHandlerChain(new TestPortInfo(null, null, serviceName5));

+        assertEquals(1, handlers.size());
     }
     
     public void testBindingMatching() throws Exception {
@@ -111,7 +115,7 @@
         InputStream in = getClass().getResourceAsStream("/handlers_port.xml");
         assertTrue(in != null);
         HandlerChainsType handlerChains = toHandlerChains(in); 
-        assertEquals(3, handlerChains.getHandlerChainArray().length);
+        assertEquals(4, handlerChains.getHandlerChainArray().length);
         
         GeronimoHandlerResolver resolver = 
             new GeronimoHandlerResolver(getClass().getClassLoader(), getClass(), handlerChains,
null);
@@ -136,6 +140,10 @@
         QName portName4 = new QName("http://foo", "BarFoo");
         handlers = resolver.getHandlerChain(new TestPortInfo(null, portName4, null)); 
         assertEquals(0, handlers.size());
+        
+        QName portName5 = new QName("https://foo", "Bar");
+        handlers = resolver.getHandlerChain(new TestPortInfo(null, portName5, null)); 
+        assertEquals(1, handlers.size());
     }
     
     public void testMixedMatching() throws Exception {
@@ -152,7 +160,7 @@
         handlers = resolver.getHandlerChain(new TestPortInfo(null, null, null)); 
         assertEquals(0, handlers.size());
         
-        QName serviceName1 = new QName("http:/foo", "Bar");
+        QName serviceName1 = new QName("http://foo", "Bar");
         QName portName1 = new QName("http://foo", "FooBar");
         String binding1 = "##XML_HTTP";
         handlers = resolver.getHandlerChain(new TestPortInfo(binding1, portName1, serviceName1));


Modified: geronimo/server/trunk/plugins/jaxws/geronimo-jaxws/src/test/resources/handlers_mixed.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/jaxws/geronimo-jaxws/src/test/resources/handlers_mixed.xml?rev=689225&r1=689224&r2=689225&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/jaxws/geronimo-jaxws/src/test/resources/handlers_mixed.xml
(original)
+++ geronimo/server/trunk/plugins/jaxws/geronimo-jaxws/src/test/resources/handlers_mixed.xml
Tue Aug 26 14:07:09 2008
@@ -27,14 +27,14 @@
         </jws:handler>
     </jws:handler-chain>
     <jws:handler-chain>
-        <jws:port-name-pattern>jws:Foo*</jws:port-name-pattern>
+        <jws:port-name-pattern xmlns:x1="http://foo">x1:Foo*</jws:port-name-pattern>
         <jws:handler>
             <jws:handler-name>GreeterHandler</jws:handler-name>
             <jws:handler-class>org.apache.geronimo.jaxws.handler.TestHandler</jws:handler-class>
         </jws:handler>
     </jws:handler-chain>
     <jws:handler-chain>
-        <jws:service-name-pattern>jws:Bar</jws:service-name-pattern>
+        <jws:service-name-pattern xmlns:x2="http://foo">x2:Bar</jws:service-name-pattern>
         <jws:handler>
             <jws:handler-name>GreeterHandler</jws:handler-name>
             <jws:handler-class>org.apache.geronimo.jaxws.handler.TestHandler</jws:handler-class>

Modified: geronimo/server/trunk/plugins/jaxws/geronimo-jaxws/src/test/resources/handlers_port.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/jaxws/geronimo-jaxws/src/test/resources/handlers_port.xml?rev=689225&r1=689224&r2=689225&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/jaxws/geronimo-jaxws/src/test/resources/handlers_port.xml
(original)
+++ geronimo/server/trunk/plugins/jaxws/geronimo-jaxws/src/test/resources/handlers_port.xml
Tue Aug 26 14:07:09 2008
@@ -18,23 +18,30 @@
 
 <!-- $Rev: 482336 $ $Date: 2006-12-04 15:12:19 -0500 (Mon, 04 Dec 2006) $ -->
 
-<jws:handler-chains xmlns:jws="http://java.sun.com/xml/ns/javaee">
+<jws:handler-chains xmlns:jws="http://java.sun.com/xml/ns/javaee" xmlns:x2="http://foo">
     <jws:handler-chain>
-        <jws:port-name-pattern>jws:Foo</jws:port-name-pattern>
+        <jws:port-name-pattern xmlns:x1="http://foo">x1:Foo</jws:port-name-pattern>
         <jws:handler>
             <jws:handler-name>GreeterHandler</jws:handler-name>
             <jws:handler-class>org.apache.geronimo.jaxws.handler.TestHandler</jws:handler-class>
         </jws:handler>
     </jws:handler-chain>
     <jws:handler-chain>
-        <jws:port-name-pattern>jws:Foo*</jws:port-name-pattern>
+        <jws:port-name-pattern>x2:Foo*</jws:port-name-pattern>
         <jws:handler>
             <jws:handler-name>GreeterHandler</jws:handler-name>
             <jws:handler-class>org.apache.geronimo.jaxws.handler.TestHandler</jws:handler-class>
         </jws:handler>
     </jws:handler-chain>
     <jws:handler-chain>
-        <jws:port-name-pattern>jws:Bar</jws:port-name-pattern>
+        <jws:port-name-pattern>x2:Bar</jws:port-name-pattern>
+        <jws:handler>
+            <jws:handler-name>GreeterHandler</jws:handler-name>
+            <jws:handler-class>org.apache.geronimo.jaxws.handler.TestHandler</jws:handler-class>
+        </jws:handler>
+    </jws:handler-chain>
+    <jws:handler-chain>
+        <jws:port-name-pattern xmlns:x3="https://foo">x3:Bar</jws:port-name-pattern>
         <jws:handler>
             <jws:handler-name>GreeterHandler</jws:handler-name>
             <jws:handler-class>org.apache.geronimo.jaxws.handler.TestHandler</jws:handler-class>

Modified: geronimo/server/trunk/plugins/jaxws/geronimo-jaxws/src/test/resources/handlers_service.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/jaxws/geronimo-jaxws/src/test/resources/handlers_service.xml?rev=689225&r1=689224&r2=689225&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/jaxws/geronimo-jaxws/src/test/resources/handlers_service.xml
(original)
+++ geronimo/server/trunk/plugins/jaxws/geronimo-jaxws/src/test/resources/handlers_service.xml
Tue Aug 26 14:07:09 2008
@@ -18,23 +18,30 @@
 
 <!-- $Rev: 482336 $ $Date: 2006-12-04 15:12:19 -0500 (Mon, 04 Dec 2006) $ -->
 
-<jws:handler-chains xmlns:jws="http://java.sun.com/xml/ns/javaee">
+<jws:handler-chains xmlns:jws="http://java.sun.com/xml/ns/javaee" xmlns:x2="http://foo">
     <jws:handler-chain>
-        <jws:service-name-pattern>jws:Foo</jws:service-name-pattern>
+        <jws:service-name-pattern xmlns:x1="http://foo">x1:Foo</jws:service-name-pattern>
         <jws:handler>
             <jws:handler-name>GreeterHandler</jws:handler-name>
             <jws:handler-class>org.apache.geronimo.jaxws.handler.TestHandler</jws:handler-class>
         </jws:handler>
     </jws:handler-chain>
     <jws:handler-chain>
-        <jws:service-name-pattern>jws:Foo*</jws:service-name-pattern>
+        <jws:service-name-pattern>x2:Foo*</jws:service-name-pattern>
         <jws:handler>
             <jws:handler-name>GreeterHandler</jws:handler-name>
             <jws:handler-class>org.apache.geronimo.jaxws.handler.TestHandler</jws:handler-class>
         </jws:handler>
     </jws:handler-chain>
     <jws:handler-chain>
-        <jws:service-name-pattern>jws:Bar</jws:service-name-pattern>
+        <jws:service-name-pattern>x2:Bar</jws:service-name-pattern>
+        <jws:handler>
+            <jws:handler-name>GreeterHandler</jws:handler-name>
+            <jws:handler-class>org.apache.geronimo.jaxws.handler.TestHandler</jws:handler-class>
+        </jws:handler>
+    </jws:handler-chain>
+    <jws:handler-chain>
+        <jws:service-name-pattern xmlns:x3="https://foo">x3:Bar</jws:service-name-pattern>
         <jws:handler>
             <jws:handler-name>GreeterHandler</jws:handler-name>
             <jws:handler-class>org.apache.geronimo.jaxws.handler.TestHandler</jws:handler-class>



Mime
View raw message