cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From egl...@apache.org
Subject svn commit: r565327 - in /incubator/cxf/trunk: api/src/main/java/org/apache/cxf/transports/http/ rt/core/src/main/java/org/apache/cxf/transport/http/ rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/ rt/transports/http-jetty/s...
Date Mon, 13 Aug 2007 12:40:12 GMT
Author: eglynn
Date: Mon Aug 13 05:40:10 2007
New Revision: 565327

URL: http://svn.apache.org/viewvc?view=rev&rev=565327
Log:
Binary compatible re-work of Sean's fix for the WSDL QueryHandler to support steem context
matching on "?wsdl" queries.


Added:
    incubator/cxf/trunk/api/src/main/java/org/apache/cxf/transports/http/StemMatchingQueryHandler.java
  (with props)
Modified:
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/http/WSDLQueryHandler.java
    incubator/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java
    incubator/cxf/trunk/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestinationTest.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/factory_pattern/MultiplexHttpAddressClientServerTest.java

Added: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/transports/http/StemMatchingQueryHandler.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/transports/http/StemMatchingQueryHandler.java?view=auto&rev=565327
==============================================================================
--- incubator/cxf/trunk/api/src/main/java/org/apache/cxf/transports/http/StemMatchingQueryHandler.java
(added)
+++ incubator/cxf/trunk/api/src/main/java/org/apache/cxf/transports/http/StemMatchingQueryHandler.java
Mon Aug 13 05:40:10 2007
@@ -0,0 +1,39 @@
+/**
+ * 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.
+ */
+
+package org.apache.cxf.transports.http;
+
+import org.apache.cxf.service.model.EndpointInfo;
+
+public interface StemMatchingQueryHandler extends QueryHandler {
+    
+    /**
+     * @param fullQueryString the target full query string (with params) of the request
+     * @param ctx the context that was set for this invokation
+     * @param endpoint the current endpoint for this context (e.g. the endpoint this
+     * Destination was activated for). Null if no current endpoint.
+     * @param contextMatchExact true if contextMatchStrategy is "exact"
+false otherwise
+     * @return true iff the URI is a recognized WSDL query
+     */
+    boolean isRecognizedQuery(String fullQueryString,
+                              String ctx,
+                              EndpointInfo endpoint,
+                              boolean contextMatchExact);
+}

Propchange: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/transports/http/StemMatchingQueryHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/transports/http/StemMatchingQueryHandler.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/http/WSDLQueryHandler.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/http/WSDLQueryHandler.java?view=diff&rev=565327&r1=565326&r2=565327
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/http/WSDLQueryHandler.java
(original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/http/WSDLQueryHandler.java
Mon Aug 13 05:40:10 2007
@@ -28,6 +28,8 @@
 import java.util.Map;
 import java.util.ResourceBundle;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 import javax.wsdl.Definition;
 import javax.wsdl.Import;
@@ -51,19 +53,21 @@
 import org.apache.cxf.Bus;
 import org.apache.cxf.common.i18n.BundleUtils;
 import org.apache.cxf.common.i18n.Message;
+import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.helpers.XMLUtils;
 import org.apache.cxf.service.model.EndpointInfo;
-import org.apache.cxf.transports.http.QueryHandler;
+import org.apache.cxf.transports.http.StemMatchingQueryHandler;
 import org.apache.cxf.wsdl.WSDLManager;
 import org.apache.cxf.wsdl11.ResourceManagerWSDLLocator;
 import org.apache.cxf.wsdl11.ServiceWSDLBuilder;
 
 
-public class WSDLQueryHandler implements QueryHandler {
+public class WSDLQueryHandler implements StemMatchingQueryHandler {
     private static final ResourceBundle BUNDLE = BundleUtils.getBundle(WSDLQueryHandler.class);
+    private static final Logger LOG = LogUtils.getL7dLogger(WSDLQueryHandler.class);
+    private Bus bus;
 
-    Bus bus;
     public WSDLQueryHandler(Bus b) {
         bus = b;
     }
@@ -76,11 +80,17 @@
         return null;
     }
 
-    public boolean isRecognizedQuery(String baseUri, String ctx, EndpointInfo endpointInfo)
{
+    public boolean isRecognizedQuery(String baseUri, String ctx, 
+                                     EndpointInfo endpointInfo, boolean contextMatchExact)
{
         if (baseUri != null 
             && (baseUri.toLowerCase().contains("?wsdl")
                 || baseUri.toLowerCase().contains("?xsd="))) {
-            return endpointInfo.getAddress().contains(ctx);
+            if (contextMatchExact) {
+                return endpointInfo.getAddress().contains(ctx);
+            } else {
+                // contextMatchStrategy will be "stem"
+                return endpointInfo.getAddress().contains(getStem(baseUri));
+            }
         }
         return false;
     }
@@ -268,4 +278,24 @@
             }
         }
     }
+    
+    public boolean isRecognizedQuery(String baseUri, String ctx, EndpointInfo endpointInfo)
{
+        return isRecognizedQuery(baseUri, ctx, endpointInfo, false);
+    }
+    
+      
+    private String getStem(String baseURI) {
+        
+        URL url = null;
+        try {
+            url = new URL(baseURI);
+        } catch (MalformedURLException e) {
+            LOG.log(Level.WARNING, "URL creation failed: ", e);
+        }
+        String port = String.valueOf(url.getPort());
+        baseURI = baseURI.substring(baseURI.indexOf(port) + port.length(), baseURI.lastIndexOf("/"));
+        
+        return baseURI;
+    }
+     
 }

Modified: incubator/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java?view=diff&rev=565327&r1=565326&r2=565327
==============================================================================
--- incubator/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java
(original)
+++ incubator/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java
Mon Aug 13 05:40:10 2007
@@ -44,6 +44,7 @@
 import org.apache.cxf.transport.https.SSLUtils;
 import org.apache.cxf.transports.http.QueryHandler;
 import org.apache.cxf.transports.http.QueryHandlerRegistry;
+import org.apache.cxf.transports.http.StemMatchingQueryHandler;
 import org.mortbay.jetty.HttpConnection;
 import org.mortbay.jetty.Request;
 
@@ -175,7 +176,7 @@
         // only update the EndpointAddress if the base path is equal
         // make sure we don't broke the get operation?parament query 
         String address = endpointInfo.getAddress();
-        if (getBasePath(address).equals(getBasePath(addr))) {
+        if (getBasePath(address).equals(getStem(getBasePath(addr)))) {
             endpointInfo.setAddress(addr);
         }
     }
@@ -196,11 +197,22 @@
             String requestURL = req.getRequestURL() + "?" + req.getQueryString();
             String pathInfo = req.getPathInfo();                     
             for (QueryHandler qh : queryHandlerRegistry.getHandlers()) {
-                if (qh.isRecognizedQuery(requestURL, pathInfo, endpointInfo)) {
+                boolean recognized =
+                    qh instanceof StemMatchingQueryHandler
+                    ? ((StemMatchingQueryHandler)qh).isRecognizedQuery(requestURL,
+                                                                       pathInfo,
+                                                                       endpointInfo,
+                                                                       contextMatchOnExact())
+                    : qh.isRecognizedQuery(requestURL, pathInfo, endpointInfo);
+                if (recognized) {
                     //replace the endpointInfo address with request url only for get wsdl
          
                     updateEndpointAddress(req.getRequestURL().toString());   
                     resp.setContentType(qh.getResponseContentType(requestURL, pathInfo));
-                    qh.writeResponse(requestURL, pathInfo, endpointInfo, resp.getOutputStream());
+                    try {
+                        qh.writeResponse(requestURL, pathInfo, endpointInfo, resp.getOutputStream());
+                    } catch (Exception ex) {
+                        LOG.log(Level.WARNING, "writeResponse failed: ", ex);
+                    }
                     resp.getOutputStream().flush();                     
                     baseRequest.setHandled(true);
                     return;
@@ -275,4 +287,7 @@
         return engine;
     }
    
+    private String getStem(String baseURI) {    
+        return baseURI.substring(0, baseURI.lastIndexOf("/"));
+    }
 }

Modified: incubator/cxf/trunk/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestinationTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestinationTest.java?view=diff&rev=565327&r1=565326&r2=565327
==============================================================================
--- incubator/cxf/trunk/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestinationTest.java
(original)
+++ incubator/cxf/trunk/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestinationTest.java
Mon Aug 13 05:40:10 2007
@@ -49,9 +49,9 @@
 import org.apache.cxf.transport.Conduit;
 import org.apache.cxf.transport.Destination;
 import org.apache.cxf.transport.MessageObserver;
-import org.apache.cxf.transport.http.WSDLQueryHandler;
 import org.apache.cxf.transports.http.QueryHandler;
 import org.apache.cxf.transports.http.QueryHandlerRegistry;
+import org.apache.cxf.transports.http.StemMatchingQueryHandler;
 import org.apache.cxf.transports.http.configuration.HTTPServerPolicy;
 import org.apache.cxf.ws.addressing.AddressingProperties;
 import org.apache.cxf.ws.addressing.EndpointReferenceType;
@@ -95,7 +95,7 @@
     private MessageObserver observer;
     private ServletInputStream is;
     private ServletOutputStream os;
-    private WSDLQueryHandler wsdlQueryHandler;
+    private QueryHandler wsdlQueryHandler;
     private QueryHandlerRegistry  queryHandlerRegistry;
     private List<QueryHandler> queryHandlerList;
     private JettyHTTPTransportFactory transportFactory; 
@@ -225,8 +225,26 @@
     }
     
     @Test
-    public void testDoServiceWithHttpGETandQueryWSDL() throws Exception {
+    public void testDoServiceWithHttpGETandStemMatchingQueryWSDL() throws Exception {
         destination = setUpDestination(false, true);
+        setUpQueryHandler(true);
+        setUpDoService(false,
+                       false,
+                       false,
+                       "GET",
+                       "?wsdl",
+                       200);
+        
+        destination.doService(request, response);
+        assertNotNull("unexpected null response", response);
+        
+        
+    }
+    
+    @Test
+    public void testDoServiceWithHttpGETandNonStemMatchingQueryWSDL() throws Exception {
+        destination = setUpDestination(false, true);
+        setUpQueryHandler(false);
         setUpDoService(false,
                        false,
                        false,
@@ -479,6 +497,13 @@
         return dest;
     }
     
+    private void setUpQueryHandler(boolean stemMatching) {
+        wsdlQueryHandler = stemMatching
+                           ? EasyMock.createMock(StemMatchingQueryHandler.class)
+                           : EasyMock.createMock(QueryHandler.class);
+
+    }
+    
     private void setUpRemoveServant() throws Exception {
         EasyMock.reset(engine);
         engine.removeServant(EasyMock.eq(new URL(NOWHERE + "bar/foo")));
@@ -634,7 +659,6 @@
     }
     
     private void verifyGetWSDLQuery() throws Exception {
-        wsdlQueryHandler = EasyMock.createMock(WSDLQueryHandler.class);
         queryHandlerRegistry = EasyMock.createMock(QueryHandlerRegistry.class);
         queryHandlerList = new ArrayList<QueryHandler>();
         queryHandlerList.add(wsdlQueryHandler);
@@ -655,7 +679,17 @@
         EasyMock.expectLastCall().andReturn(os).anyTimes();
         request.setHandled(true);
         EasyMock.expectLastCall();
-        wsdlQueryHandler.isRecognizedQuery("http://localhost/bar/foo?wsdl", "/bar/foo", endpointInfo);
+        if (wsdlQueryHandler instanceof StemMatchingQueryHandler) {
+            ((StemMatchingQueryHandler)wsdlQueryHandler).isRecognizedQuery(
+                "http://localhost/bar/foo?wsdl", 
+                "/bar/foo",
+                endpointInfo,
+                false);
+        } else {
+            wsdlQueryHandler.isRecognizedQuery("http://localhost/bar/foo?wsdl",
+                                               "/bar/foo",
+                                               endpointInfo);
+        }
         EasyMock.expectLastCall().andReturn(true);   
         wsdlQueryHandler.getResponseContentType("http://localhost/bar/foo?wsdl", "/bar/foo");
         EasyMock.expectLastCall().andReturn("text/xml");

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/factory_pattern/MultiplexHttpAddressClientServerTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/factory_pattern/MultiplexHttpAddressClientServerTest.java?view=diff&rev=565327&r1=565326&r2=565327
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/factory_pattern/MultiplexHttpAddressClientServerTest.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/factory_pattern/MultiplexHttpAddressClientServerTest.java
Mon Aug 13 05:40:10 2007
@@ -22,6 +22,7 @@
 
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Proxy;
+import java.net.URL;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -111,5 +112,17 @@
             
         IsEvenResponse numResp = num.isEven();
         assertTrue("103 is not even", Boolean.FALSE.equals(numResp.isEven()));
+    }
+    
+    @Test
+    public void testWithGetWsdlOnServant() throws Exception {
+        
+        int firstChar = new URL(NumberFactoryImpl.NUMBER_SERVANT_ADDRESS_ROOT 
+                + "?wsdl").openStream().read();        
+        assertTrue("firstChar :" + String.valueOf(firstChar), firstChar == '<');
+        
+        firstChar = new URL(NumberFactoryImpl.NUMBER_SERVANT_ADDRESS_ROOT 
+                                + "103?wsdl").openStream().read();
+        assertTrue("firstChar :" + String.valueOf(firstChar), firstChar == '<');
     }
 }



Mime
View raw message