Author: dkulp
Date: Tue Mar 24 18:22:48 2009
New Revision: 757935

URL: http://svn.apache.org/viewvc?rev=757935&view=rev
Log:
[CXF-1766, CXF-2117] Support proper wildcards for handler chains

Modified:
    
cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/AnnotationHandlerChainBuilder.java
    
cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/AnnotationHandlerChainBuilderTest.java
    
cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/handlers.xml

Modified: 
cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/AnnotationHandlerChainBuilder.java
URL: 
http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/AnnotationHandlerChainBuilder.java?rev=757935&r1=757934&r2=757935&view=diff
==============================================================================
--- 
cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/AnnotationHandlerChainBuilder.java
 (original)
+++ 
cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/AnnotationHandlerChainBuilder.java
 Tue Mar 24 18:22:48 2009
@@ -216,13 +216,39 @@
         }
         if (localPart.contains("*")) {
             //wildcard pattern matching
-            return Pattern.matches(localPart, comp.getLocalPart());
+            return Pattern.matches(mapPattern(localPart), comp.getLocalPart());
         } else if (!localPart.equals(comp.getLocalPart())) {
             return false;
         }
         return true;
     }
     
+    private String mapPattern(String s) {
+        StringBuilder buf = new StringBuilder(s);
+        for (int x = 0; x < buf.length(); x++) {
+            switch (buf.charAt(x)) {
+            case '*':
+                buf.insert(x, '.');
+                x++;
+                break;
+            case '.':
+            case '\\':
+            case '^':
+            case '$':
+            case '{':
+            case '}':
+            case '(':
+            case ')':
+                buf.insert(x, '\\');
+                x++;
+                break;
+            default:
+                //nothing to do
+            }
+        }
+        return buf.toString();
+    }
+    
     private void processHandlerElement(Element el, List<Handler> chain) {
         try {
             JAXBContext ctx = getContextForPortComponentHandlerType();

Modified: 
cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/AnnotationHandlerChainBuilderTest.java
URL: 
http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/AnnotationHandlerChainBuilderTest.java?rev=757935&r1=757934&r2=757935&view=diff
==============================================================================
--- 
cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/AnnotationHandlerChainBuilderTest.java
 (original)
+++ 
cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/AnnotationHandlerChainBuilderTest.java
 Tue Mar 24 18:22:48 2009
@@ -88,6 +88,19 @@
         assertEquals(3, handlers.size());
     }
     
+    @Test
+    public void testFindHandlerChainAnnotationPerPortServiceBindingWildcard() {
+        HandlerTestImpl handlerTestImpl = new HandlerTestImpl();
+        AnnotationHandlerChainBuilder chainBuilder = new 
AnnotationHandlerChainBuilder();
+        QName portQName = new QName("http://apache.org/handler_test";, 
"SoapPortWildcard");
+        QName serviceQName = new QName("http://apache.org/handler_test";, 
"SoapServiceWildcard");
+        String bindingID = "BindingUnknow";
+        List<Handler> handlers = chainBuilder
+            .buildHandlerChainFromClass(handlerTestImpl.getClass(), portQName, 
serviceQName, bindingID);
+        assertNotNull(handlers);
+        assertEquals(7, handlers.size());
+    }
+    
     public static class TestLogicalHandler implements LogicalHandler {
         Map config;
         boolean initCalled;

Modified: 
cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/handlers.xml
URL: 
http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/handlers.xml?rev=757935&r1=757934&r2=757935&view=diff
==============================================================================
--- 
cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/handlers.xml
 (original)
+++ 
cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/handlers.xml
 Tue Mar 24 18:22:48 2009
@@ -1,61 +1,62 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!--
-  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
+       <!--
+               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.
+       -->
+<handler-chains xmlns="http://java.sun.com/xml/ns/javaee";
+       xmlns:cfg="http://cxf.apache.org/configuration/cfg"; 
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb";
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee";>
+       <handler-chain>
+               <handler>
+                       <handler-name>lh3</handler-name>
+                       <handler-class>
+                               
org.apache.cxf.jaxws.handler.AnnotationHandlerChainBuilderTest$TestProtocolHandler
+                       </handler-class>
+                       <init-param>
+                               <param-name>token</param-name>
+                               <param-value>String</param-value>
+                       </init-param>
+               </handler>
+       </handler-chain>
+       <handler-chain>
+               <handler>
+                       <handler-name>lh1</handler-name>
+                       <handler-class>
+                               
org.apache.cxf.jaxws.handler.AnnotationHandlerChainBuilderTest$TestLogicalHandler
+                       </handler-class>
+                       <init-param>
+                               <param-name>token</param-name>
+                               <param-value>String</param-value>
+                       </init-param>
+               </handler>
+               <handler>
+                       <handler-name>lh2</handler-name>
+                       <handler-class>
+                               
org.apache.cxf.jaxws.handler.AnnotationHandlerChainBuilderTest$TestLogicalHandler
+                       </handler-class>
+                       <init-param>
+                               <param-name>token</param-name>
+                               <param-value>String</param-value>
+                       </init-param>
+               </handler>
+       </handler-chain>
 
-  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.
--->
-<handler-chains xmlns="http://java.sun.com/xml/ns/javaee"; 
-xmlns:cfg="http://cxf.apache.org/configuration/cfg"; 
-xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"; 
-xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
-xsi:schemaLocation="http://java.sun.com/xml/ns/javaee";>
-    <handler-chain>
-       <handler>
-               <handler-name>lh3</handler-name>
-               
<handler-class>org.apache.cxf.jaxws.handler.AnnotationHandlerChainBuilderTest$TestProtocolHandler</handler-class>
-               <init-param>
-                       <param-name>token</param-name>
-                       <param-value>String</param-value>
-               </init-param>
-       </handler>
-    </handler-chain>
-    <handler-chain>
-       <handler>
-               <handler-name>lh1</handler-name>
-               
<handler-class>org.apache.cxf.jaxws.handler.AnnotationHandlerChainBuilderTest$TestLogicalHandler</handler-class>
-               <init-param>
-                       <param-name>token</param-name>
-                       <param-value>String</param-value>
-               </init-param>
-       </handler>
-       <handler>
-               <handler-name>lh2</handler-name>
-               
<handler-class>org.apache.cxf.jaxws.handler.AnnotationHandlerChainBuilderTest$TestLogicalHandler</handler-class>
-               <init-param>
-                       <param-name>token</param-name>
-                       <param-value>String</param-value>
-               </init-param>
-       </handler>
-    </handler-chain>
-    
-    
-    <handler-chain>
-               <port-name-pattern
-                       xmlns:ns1="http://apache.org/handler_test";>
-                       ns1:SoapPort1
+       <handler-chain>
+               <port-name-pattern xmlns:ns1="http://apache.org/handler_test";>
+                       ns1:Soap*
                </port-name-pattern>
                <handler>
                        <handler-name>Handler1</handler-name>
@@ -70,11 +71,10 @@
                        </handler-class>
                </handler>
        </handler-chain>
-       
-    <handler-chain>
-               <service-name-pattern
-                       xmlns:ns1="http://apache.org/handler_test";>
-                       ns1:SoapService1
+
+       <handler-chain>
+               <service-name-pattern 
xmlns:ns1="http://apache.org/handler_test";>
+                       ns1:Soap*
                </service-name-pattern>
                <handler>
                        <handler-name>Handler1</handler-name>
@@ -88,23 +88,29 @@
                                
org.apache.cxf.jaxws.handler.AnnotationHandlerChainBuilderTest$TestLogicalHandler
                        </handler-class>
                </handler>
-       </handler-chain>        
-       
-              <!-- ====================== -->
-           <!-- protocol based handlers-->
-           <!-- ====================== -->
-           <handler-chain>
-              <!-- REVISIT: valued used by TCK, do not understand...
-              <protocol-bindings>##SOAP11_HTTP</protocol-bindings>
-               -->
-              
<protocol-bindings>http://schemas.xmlsoap.org/wsdl/soap/http</protocol-bindings>
-              <handler>
-                    <handler-name>Handler7</handler-name>
-                    
<handler-class>org.apache.cxf.jaxws.handler.AnnotationHandlerChainBuilderTest$TestLogicalHandler</handler-class>
-              </handler>
-              <handler>
-                    <handler-name>Handler8</handler-name>
-                    
<handler-class>org.apache.cxf.jaxws.handler.AnnotationHandlerChainBuilderTest$TestProtocolHandler</handler-class>
-              </handler>
-           </handler-chain>
+       </handler-chain>
+
+       <!-- ====================== -->
+       <!-- protocol based handlers-->
+       <!-- ====================== -->
+       <handler-chain>
+               <!--
+                       REVISIT: valued used by TCK, do not understand...
+                       <protocol-bindings>##SOAP11_HTTP</protocol-bindings>
+               -->
+               <protocol-bindings>http://schemas.xmlsoap.org/wsdl/soap/http
+               </protocol-bindings>
+               <handler>
+                       <handler-name>Handler7</handler-name>
+                       <handler-class>
+                               
org.apache.cxf.jaxws.handler.AnnotationHandlerChainBuilderTest$TestLogicalHandler
+                       </handler-class>
+               </handler>
+               <handler>
+                       <handler-name>Handler8</handler-name>
+                       <handler-class>
+                               
org.apache.cxf.jaxws.handler.AnnotationHandlerChainBuilderTest$TestProtocolHandler
+                       </handler-class>
+               </handler>
+       </handler-chain>
 </handler-chains>


Reply via email to