cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sea...@apache.org
Subject svn commit: r501802 - in /incubator/cxf/trunk: ./ api/src/main/java/org/apache/cxf/endpoint/ api/src/main/java/org/apache/cxf/transports/ api/src/main/java/org/apache/cxf/transports/http/ rt/core/src/main/java/org/apache/cxf/endpoint/ rt/core/src/main/...
Date Wed, 31 Jan 2007 11:18:11 GMT
Author: seanoc
Date: Wed Jan 31 03:18:09 2007
New Revision: 501802

URL: http://svn.apache.org/viewvc?view=rev&rev=501802
Log:
Resolved issues:

https://issues.apache.org/jira/browse/CXF-237
https://issues.apache.org/jira/browse/CXF-360

Also added in a QueryHandler and associated classes which enables the handling of a HTTP GET
based on the nature of the query, for example ?wsdl dealt with by a WSDLQueryHandler

Added:
    incubator/cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/ServerLifeCycleListener.java
    incubator/cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/ServerLifeCycleManager.java
    incubator/cxf/trunk/api/src/main/java/org/apache/cxf/transports/
    incubator/cxf/trunk/api/src/main/java/org/apache/cxf/transports/http/
    incubator/cxf/trunk/api/src/main/java/org/apache/cxf/transports/http/QueryHandler.java
    incubator/cxf/trunk/api/src/main/java/org/apache/cxf/transports/http/QueryHandlerRegistry.java
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ServerLifeCycleManagerImpl.java
    incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/QueryHandlerRegistryImpl.java
    incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/WSDLQueryHandler.java
Modified:
    incubator/cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/Server.java
    incubator/cxf/trunk/checkstyle.xml
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ServerImpl.java
    incubator/cxf/trunk/rt/core/src/main/resources/META-INF/cxf/cxf.xml
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/servlet/ServletController.java
    incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPTransportFactory.java
    incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/JettyHTTPDestination.java
    incubator/cxf/trunk/rt/transports/http/src/main/resources/META-INF/bus-extensions.xml
    incubator/cxf/trunk/rt/transports/http/src/main/resources/META-INF/cxf/cxf-extension-http.xml
    incubator/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/JettyHTTPDestinationTest.java

Modified: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/Server.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/Server.java?view=diff&rev=501802&r1=501801&r2=501802
==============================================================================
--- incubator/cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/Server.java (original)
+++ incubator/cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/Server.java Wed Jan 31 03:18:09
2007
@@ -28,4 +28,7 @@
     void stop();
     
     Destination getDestination();
+    
+    Endpoint getEndpoint();
+        
 }

Added: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/ServerLifeCycleListener.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/ServerLifeCycleListener.java?view=auto&rev=501802
==============================================================================
--- incubator/cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/ServerLifeCycleListener.java
(added)
+++ incubator/cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/ServerLifeCycleListener.java
Wed Jan 31 03:18:09 2007
@@ -0,0 +1,25 @@
+/**
+ * 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.endpoint;
+
+public interface ServerLifeCycleListener {
+    void startServer(Server server);
+    void stopServer(Server server); 
+}

Added: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/ServerLifeCycleManager.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/ServerLifeCycleManager.java?view=auto&rev=501802
==============================================================================
--- incubator/cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/ServerLifeCycleManager.java
(added)
+++ incubator/cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/ServerLifeCycleManager.java
Wed Jan 31 03:18:09 2007
@@ -0,0 +1,28 @@
+/**
+ * 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.endpoint;
+
+
+public interface ServerLifeCycleManager { 
+    void startServer(Server server);
+    void stopServer(Server  server);
+    void registerListener(ServerLifeCycleListener listener);
+    void unRegisterListener(ServerLifeCycleListener listener);
+}

Added: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/transports/http/QueryHandler.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/transports/http/QueryHandler.java?view=auto&rev=501802
==============================================================================
--- incubator/cxf/trunk/api/src/main/java/org/apache/cxf/transports/http/QueryHandler.java
(added)
+++ incubator/cxf/trunk/api/src/main/java/org/apache/cxf/transports/http/QueryHandler.java
Wed Jan 31 03:18:09 2007
@@ -0,0 +1,48 @@
+/**
+ * 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 java.io.OutputStream;
+
+import org.apache.cxf.service.model.EndpointInfo;
+
+public interface QueryHandler {
+    
+    /**
+     * @param URI the target URI
+     * @param endpoint the current endpoint for this context (e.g. the endpoint this
+     * Destination was activated for). Null if no current endpoint.
+     * @return true iff the URI is a recognized WSDL query
+     */
+    boolean isRecognizedQuery(String uri, EndpointInfo endpoint);
+
+    /**
+     * @return the content-type for the response
+     */
+    String getResponseContentType(String uri);
+ 
+    /**
+     * Write query response to output stream
+     */ 
+    void writeResponse(String queryURI, EndpointInfo endpoint, OutputStream os);
+    
+
+
+}

Added: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/transports/http/QueryHandlerRegistry.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/transports/http/QueryHandlerRegistry.java?view=auto&rev=501802
==============================================================================
--- incubator/cxf/trunk/api/src/main/java/org/apache/cxf/transports/http/QueryHandlerRegistry.java
(added)
+++ incubator/cxf/trunk/api/src/main/java/org/apache/cxf/transports/http/QueryHandlerRegistry.java
Wed Jan 31 03:18:09 2007
@@ -0,0 +1,37 @@
+/**
+ * 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 java.util.List;
+
+public interface QueryHandlerRegistry {
+    
+    /**
+     * Register QueryHandler with registry
+     */ 
+    void registerHandler(QueryHandler handler);
+    
+    /**
+     * Returns list of QueryHandlers
+     */  
+    List<QueryHandler> getHandlers();
+
+
+}

Modified: incubator/cxf/trunk/checkstyle.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/checkstyle.xml?view=diff&rev=501802&r1=501801&r2=501802
==============================================================================
--- incubator/cxf/trunk/checkstyle.xml (original)
+++ incubator/cxf/trunk/checkstyle.xml Wed Jan 31 03:18:09 2007
@@ -88,7 +88,7 @@
         <module name="RedundantImport"/>
         <module name="UnusedImports"/>
         <module name="ImportOrder">
-            <property name="groups" value="java,javax,org.w3c,org.xml,w3c"/>
+            <property name="groups" value="java,javax,org.w3c,org.xml,junit,com,org"/>
             <property name="ordered" value="true"/>
         </module>
         <!--

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ServerImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ServerImpl.java?view=diff&rev=501802&r1=501801&r2=501802
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ServerImpl.java (original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ServerImpl.java Wed
Jan 31 03:18:09 2007
@@ -37,11 +37,15 @@
     private MessageObserver messageObserver;
     private Endpoint endpoint;
     private ServerRegistry serverRegistry;
+    private Bus bus;
+    private ServerLifeCycleManager mgr;
     
     public ServerImpl(Bus bus, Endpoint endpoint, MessageObserver observer) 
         throws BusException, IOException {
+        
         this.endpoint = endpoint;
-        this.messageObserver = observer;       
+        this.messageObserver = observer;  
+        this.bus = bus;
 
         EndpointInfo ei = endpoint.getEndpointInfo();
         DestinationFactory destinationFactory = bus.getExtension(DestinationFactoryManager.class)
@@ -58,18 +62,26 @@
         this.destination = destination;
     }
 
-    public void start() {        
+    public void start() {     
+        
         getDestination().setMessageObserver(messageObserver);
         //regist the active server to run
         if (null != serverRegistry) {
             LOG.fine("register the server to serverRegistry ");
             serverRegistry.register(this);
         }
+        mgr = bus.getExtension(ServerLifeCycleManager.class);
+        if (mgr != null) {
+            mgr.startServer(this);
+        }
     }
 
     public void stop() {
         LOG.fine("Server is stopping.");
-        getDestination().setMessageObserver(null);        
+        getDestination().setMessageObserver(null);  
+        if (mgr != null) {
+            mgr.stopServer(this);
+        }
     }
 
     public MessageObserver getMessageObserver() {

Added: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ServerLifeCycleManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ServerLifeCycleManagerImpl.java?view=auto&rev=501802
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ServerLifeCycleManagerImpl.java
(added)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ServerLifeCycleManagerImpl.java
Wed Jan 31 03:18:09 2007
@@ -0,0 +1,74 @@
+/**
+ * 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.endpoint;
+
+import java.util.List;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.Resource;
+
+import org.apache.cxf.Bus;
+
+public class ServerLifeCycleManagerImpl implements ServerLifeCycleManager {
+    
+    private List<ServerLifeCycleListener> listeners;
+    private Bus bus;
+
+    public void registerListener(ServerLifeCycleListener listener) {
+        listeners.add(listener);
+    }
+
+    public void startServer(Server server) {
+        if (null != listeners) {
+            for (ServerLifeCycleListener listener : listeners) {
+                listener.startServer(server);
+            }
+        }
+    }
+
+    public void stopServer(Server server) {
+        if (null != listeners) {
+            for (ServerLifeCycleListener listener : listeners) {
+                listener.stopServer(server);
+            }
+        } 
+    }
+
+    public void unRegisterListener(ServerLifeCycleListener listener) {
+        listeners.remove(listener);
+    }
+    
+    public Bus getBus() {
+        return bus;
+    }
+    
+    @Resource
+    public void setBus(Bus bus) {        
+        this.bus = bus;        
+    }
+    
+    @PostConstruct
+    public void register() {
+        if (null != bus) {
+            bus.setExtension(this, ServerLifeCycleManager.class);
+        }
+    }
+
+}

Modified: incubator/cxf/trunk/rt/core/src/main/resources/META-INF/cxf/cxf.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/resources/META-INF/cxf/cxf.xml?view=diff&rev=501802&r1=501801&r2=501802
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/resources/META-INF/cxf/cxf.xml (original)
+++ incubator/cxf/trunk/rt/core/src/main/resources/META-INF/cxf/cxf.xml Wed Jan 31 03:18:09
2007
@@ -86,5 +86,9 @@
     <bean id="org.apache.cxf.endpoint.ServerRegistry" class="org.apache.cxf.endpoint.ServerRegistryImpl">
         <property name="bus" ref="cxf"/>
     </bean>
+
+    <bean id="org.apache.cxf.endpoint.ServerLifeCycleManager" class="org.apache.cxf.endpoint.ServerLifeCycleManagerImpl">
+        <property name="bus" ref="cxf"/>
+    </bean>
     
 </beans>

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/servlet/ServletController.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/servlet/ServletController.java?view=diff&rev=501802&r1=501801&r2=501802
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/servlet/ServletController.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/servlet/ServletController.java
Wed Jan 31 03:18:09 2007
@@ -33,20 +33,21 @@
 import javax.wsdl.Port;
 import javax.wsdl.WSDLException;
 import javax.wsdl.extensions.ExtensibilityElement;
-import javax.wsdl.factory.WSDLFactory;
-import javax.wsdl.xml.WSDLWriter;
 import javax.xml.transform.Result;
 import javax.xml.transform.Source;
 import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.stream.StreamResult;
 import javax.xml.transform.stream.StreamSource;
 
+import org.apache.cxf.Bus;
 import org.apache.cxf.helpers.HttpHeaderHelper;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageImpl;
 import org.apache.cxf.service.model.EndpointInfo;
 import org.apache.cxf.tools.common.extensions.soap.SoapAddress;
 import org.apache.cxf.tools.util.SOAPBindingUtil;
+import org.apache.cxf.transports.http.QueryHandler;
+import org.apache.cxf.transports.http.QueryHandlerRegistry;
 import org.apache.cxf.wsdl11.ServiceWSDLBuilder;
 import org.xmlsoap.schemas.wsdl.http.AddressType;
 
@@ -182,7 +183,6 @@
         try {
             OutputStream os = response.getOutputStream();
 
-            WSDLWriter wsdlWriter = WSDLFactory.newInstance().newWSDLWriter();
             EndpointInfo ei = d.getEndpointInfo();
             Definition def = new ServiceWSDLBuilder(ei.getService()).build();
             Port port = def.getService(ei.getService().getName()).getPort(ei.getName().getLocalPart());
@@ -198,9 +198,23 @@
                     add.setLocation(request.getRequestURL().toString());
                 }
             }
+            
+            Bus bus = CXFServlet.BUS_MAP.get("bus.id").get();
+            if (bus.getExtension(QueryHandlerRegistry.class) != null) { 
+                for (QueryHandler qh : bus.getExtension(QueryHandlerRegistry.class).getHandlers())
{
+                    if (qh.isRecognizedQuery(request.getQueryString(), ei)) {
+                      
+                        try {
+                            qh.writeResponse(request.getRequestURL().toString(), ei, os);
+                        } catch (Exception e) {
+                            throw new ServletException(e);
+                        }
+                    }
+                }
+            }
 
-            wsdlWriter.writeWSDL(def, os);
             response.getOutputStream().flush();
+            
         } catch (WSDLException e) {
             throw new ServletException(e);
         } catch (IOException e) {

Modified: incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPTransportFactory.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPTransportFactory.java?view=diff&rev=501802&r1=501801&r2=501802
==============================================================================
--- incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPTransportFactory.java
(original)
+++ incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPTransportFactory.java
Wed Jan 31 03:18:09 2007
@@ -51,6 +51,7 @@
 import org.apache.cxf.transport.DestinationFactoryManager;
 import org.apache.cxf.transport.https.HttpsURLConnectionFactory;
 import org.apache.cxf.transport.https.JettySslListenerFactory;
+import org.apache.cxf.transports.http.QueryHandlerRegistry;
 import org.apache.cxf.ws.addressing.EndpointReferenceType;
 import org.apache.cxf.wsdl11.WSDLEndpointFactory;
 import org.mortbay.http.SocketListener;
@@ -99,6 +100,11 @@
             for (String ns : activationNamespaces) {
                 dfm.registerDestinationFactory(ns, this);
             }
+        }
+        
+        QueryHandlerRegistry qhr = bus.getExtension(QueryHandlerRegistry.class);
+        if (null != qhr) {
+            qhr.registerHandler(new WSDLQueryHandler());
         }
     }
 

Modified: incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/JettyHTTPDestination.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/JettyHTTPDestination.java?view=diff&rev=501802&r1=501801&r2=501802
==============================================================================
--- incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/JettyHTTPDestination.java
(original)
+++ incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/JettyHTTPDestination.java
Wed Jan 31 03:18:09 2007
@@ -32,10 +32,6 @@
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
-import javax.wsdl.Definition;
-import javax.wsdl.factory.WSDLFactory;
-import javax.wsdl.xml.WSDLWriter;
-
 import org.apache.cxf.Bus;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.StringUtils;
@@ -48,8 +44,9 @@
 import org.apache.cxf.transport.Conduit;
 import org.apache.cxf.transport.ConduitInitiator;
 import org.apache.cxf.transport.http.destination.HTTPDestinationConfigBean;
+import org.apache.cxf.transports.http.QueryHandler;
+import org.apache.cxf.transports.http.QueryHandlerRegistry;
 import org.apache.cxf.ws.addressing.EndpointReferenceType;
-import org.apache.cxf.wsdl11.ServiceWSDLBuilder;
 import org.mortbay.http.HttpRequest;
 import org.mortbay.http.HttpResponse;
 import org.mortbay.http.handler.AbstractHttpHandler;
@@ -237,24 +234,20 @@
             req.setHandled(true);
             return;
         }
-
-        if ("GET".equals(req.getMethod()) && req.getURI().toString().toLowerCase().endsWith("?wsdl"))
{
-            try {
-
-                resp.addField(HttpHeaderHelper.CONTENT_TYPE, "text/xml");
-
-                OutputStream os = resp.getOutputStream();
-
-                WSDLWriter wsdlWriter = WSDLFactory.newInstance().newWSDLWriter();
-                Definition def = new ServiceWSDLBuilder(endpointInfo.getService()).build();
-                wsdlWriter.writeWSDL(def, os);
-                resp.getOutputStream().flush();
-                resp.commit();
-                req.setHandled(true);
-                return;
-            } catch (Exception ex) {
-
-                ex.printStackTrace();
+        QueryHandlerRegistry queryHandlerRegistry = bus.getExtension(QueryHandlerRegistry.class);
+        if (queryHandlerRegistry != null) { 
+            for (QueryHandler qh : queryHandlerRegistry.getHandlers()) {
+                if (qh.isRecognizedQuery(req.getURI().toString(), endpointInfo)) {
+                    if (resp.getField(HttpHeaderHelper.CONTENT_TYPE) == null) {
+                        resp.addField(HttpHeaderHelper.CONTENT_TYPE, 
+                                      qh.getResponseContentType(req.getURI().toString()));
+                    }
+                    qh.writeResponse(req.getURI().toString(), endpointInfo, resp.getOutputStream());
+                    resp.getOutputStream().flush(); 
+                    resp.commit();
+                    req.setHandled(true);
+                    return;
+                }
             }
         }
 

Added: incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/QueryHandlerRegistryImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/QueryHandlerRegistryImpl.java?view=auto&rev=501802
==============================================================================
--- incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/QueryHandlerRegistryImpl.java
(added)
+++ incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/QueryHandlerRegistryImpl.java
Wed Jan 31 03:18:09 2007
@@ -0,0 +1,59 @@
+/**
+ * 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.transport.http;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.Resource;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.transports.http.QueryHandler;
+import org.apache.cxf.transports.http.QueryHandlerRegistry;
+
+public class QueryHandlerRegistryImpl implements QueryHandlerRegistry {
+    
+    List<QueryHandler> queryHandlers;
+    Bus bus;
+    
+    @PostConstruct
+    public void init() {
+        queryHandlers = new ArrayList<QueryHandler>();
+    }
+
+    public List<QueryHandler> getHandlers() {
+        return queryHandlers;
+    }
+
+    public void registerHandler(QueryHandler handler) {
+        queryHandlers.add(handler);
+    }
+    
+    @Resource
+    public void setBus(Bus b) {
+        bus = b;
+    }
+
+    public Bus getBus() {
+        return bus;
+    }
+
+}

Added: incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/WSDLQueryHandler.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/WSDLQueryHandler.java?view=auto&rev=501802
==============================================================================
--- incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/WSDLQueryHandler.java
(added)
+++ incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/WSDLQueryHandler.java
Wed Jan 31 03:18:09 2007
@@ -0,0 +1,60 @@
+/**
+ * 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.transport.http;
+
+import java.io.OutputStream;
+
+import javax.wsdl.Definition;
+import javax.wsdl.WSDLException;
+import javax.wsdl.factory.WSDLFactory;
+import javax.wsdl.xml.WSDLWriter;
+
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.transports.http.QueryHandler;
+import org.apache.cxf.wsdl11.ServiceWSDLBuilder;
+
+public class WSDLQueryHandler implements QueryHandler {
+
+    public String getResponseContentType(String uri) {
+        if (uri.toString().toLowerCase().endsWith("?wsdl")) {
+            return "text/xml";
+        }
+        return null;
+    }
+
+    public boolean isRecognizedQuery(String uri, EndpointInfo endpointInfo) {       
+        if (uri != null) {
+            return endpointInfo.getAddress().contains(uri) 
+                && uri.toString().toLowerCase().endsWith("?wsdl");   
+        }
+        return false;
+    }
+
+    public void writeResponse(String queryURI, EndpointInfo endpointInfo, OutputStream os)
{
+        try {
+            WSDLWriter wsdlWriter = WSDLFactory.newInstance().newWSDLWriter();
+            Definition def = new ServiceWSDLBuilder(endpointInfo.getService()).build();
+            wsdlWriter.writeWSDL(def, os);
+        } catch (WSDLException wex) {
+            wex.printStackTrace();
+        }
+    }
+
+}

Modified: incubator/cxf/trunk/rt/transports/http/src/main/resources/META-INF/bus-extensions.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http/src/main/resources/META-INF/bus-extensions.xml?view=diff&rev=501802&r1=501801&r2=501802
==============================================================================
--- incubator/cxf/trunk/rt/transports/http/src/main/resources/META-INF/bus-extensions.xml
(original)
+++ incubator/cxf/trunk/rt/transports/http/src/main/resources/META-INF/bus-extensions.xml
Wed Jan 31 03:18:09 2007
@@ -27,4 +27,6 @@
         <namespace>http://cxf.apache.org/transports/http/configuration</namespace>
         <namespace>http://cxf.apache.org/bindings/xformat</namespace>
     </extension>
+    <extension class="org.apache.cxf.transport.http.QueryHandlerRegistryImpl"
+       	   interface="org.apache.cxf.transports.http.QueryHandlerRegistry"/>   
 </extensions>

Modified: incubator/cxf/trunk/rt/transports/http/src/main/resources/META-INF/cxf/cxf-extension-http.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http/src/main/resources/META-INF/cxf/cxf-extension-http.xml?view=diff&rev=501802&r1=501801&r2=501802
==============================================================================
--- incubator/cxf/trunk/rt/transports/http/src/main/resources/META-INF/cxf/cxf-extension-http.xml
(original)
+++ incubator/cxf/trunk/rt/transports/http/src/main/resources/META-INF/cxf/cxf-extension-http.xml
Wed Jan 31 03:18:09 2007
@@ -36,4 +36,7 @@
             </list>
         </property>
     </bean>
+    <bean id="org.apache.cxf.transports.http.QueryHandlerRegistry" class="org.apache.cxf.transport.http.QueryHandlerRegistryImpl">
+        <property name="bus" ref="cxf"/>
+    </bean>
 </beans>

Modified: incubator/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/JettyHTTPDestinationTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/JettyHTTPDestinationTest.java?view=diff&rev=501802&r1=501801&r2=501802
==============================================================================
--- incubator/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/JettyHTTPDestinationTest.java
(original)
+++ incubator/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/JettyHTTPDestinationTest.java
Wed Jan 31 03:18:09 2007
@@ -46,6 +46,8 @@
 import org.apache.cxf.transport.Conduit;
 import org.apache.cxf.transport.ConduitInitiator;
 import org.apache.cxf.transport.MessageObserver;
+import org.apache.cxf.transports.http.QueryHandler;
+import org.apache.cxf.transports.http.QueryHandlerRegistry;
 import org.apache.cxf.transports.http.configuration.HTTPServerPolicy;
 import org.apache.cxf.ws.addressing.EndpointReferenceType;
 import org.apache.cxf.wsdl.EndpointReferenceUtils;
@@ -83,6 +85,9 @@
     private InputStream is;
     private OutputStream os;
     private IMocksControl control;
+    private WSDLQueryHandler wsdlQueryHandler;
+    private QueryHandlerRegistry  queryHandlerRegistry;
+    private List<QueryHandler> queryHandlerList; 
 
     
     public void setUp() throws Exception {
@@ -121,7 +126,7 @@
     }
 
     public void testDoServiceRedirectURL() throws Exception {
-        destination = setUpDestination(false);
+        destination = setUpDestination(false, false);
         setUpDoService(true);
         destination.doService(request, response);
 
@@ -137,14 +142,14 @@
     }
 
     public void testDoService() throws Exception {
-        destination = setUpDestination(false);
+        destination = setUpDestination(false, false);
         setUpDoService(false);
         destination.doService(request, response);
         verifyDoService();
     }
     
     public void testDoServiceWithHttpGET() throws Exception {
-        destination = setUpDestination(false);
+        destination = setUpDestination(false, false);
         setUpDoService(false,
                        false,
                        false,
@@ -164,9 +169,23 @@
                      "?customerId=abc&cutomerAdd=def");
 
     }
+    
+    public void testDoServiceWithHttpGETandQueryWSDL() throws Exception {
+        destination = setUpDestination(false, true);
+        setUpDoService(false,
+                       false,
+                       false,
+                       "GET",
+                       "?wsdl");
+        
+        destination.doService(request, response);
+        assertNotNull("unexpected null response", response);
+        assertEquals("text/xml", response.getContentType());
+        
+    }
 
     public void testGetAnonBackChannel() throws Exception {
-        destination = setUpDestination(false);
+        destination = setUpDestination(false, false);
         setUpDoService(false);
         destination.doService(request, response);
         setUpInMessage();
@@ -181,7 +200,7 @@
     }
     
     public void testGetBackChannelSend() throws Exception {
-        destination = setUpDestination(false);
+        destination = setUpDestination(false, false);
         setUpDoService(false, true);
         destination.doService(request, response);
         setUpInMessage();
@@ -193,7 +212,7 @@
     }
 
     public void testGetBackChannelSendFault() throws Exception {
-        destination = setUpDestination(false);
+        destination = setUpDestination(false, false);
         setUpDoService(false, true);
         destination.doService(request, response);
         setUpInMessage();
@@ -205,7 +224,7 @@
     }
     
     public void testGetBackChannelSendOneway() throws Exception {
-        destination = setUpDestination(false);
+        destination = setUpDestination(false, false);
         setUpDoService(false, true);
         destination.doService(request, response);
         setUpInMessage();
@@ -217,7 +236,7 @@
     }
 
     public void testGetBackChannelSendDecoupled() throws Exception {
-        destination = setUpDestination(false);
+        destination = setUpDestination(false, false);
         replyTo = getEPR(NOWHERE + "response/foo");
         setUpDoService(false, true, true);
         destination.doService(request, response);
@@ -265,13 +284,17 @@
         
     private JettyHTTPDestination setUpDestination()
         throws Exception {
-        return setUpDestination(false);
+        return setUpDestination(false, false);
     };
     
-    private JettyHTTPDestination setUpDestination(boolean contextMatchOnStem)
+    private JettyHTTPDestination setUpDestination(boolean contextMatchOnStem, boolean mockedBus)
         throws Exception {
         address = getEPR("bar/foo");
-        bus = new CXFBusImpl();
+        if (!mockedBus) {
+            bus = new CXFBusImpl();
+        } else {
+            bus = control.createMock(Bus.class);
+        }
         
         conduitInitiator = control.createMock(ConduitInitiator.class);
         engine = control.createMock(ServerEngine.class);
@@ -373,6 +396,9 @@
             //    response.commit();
             //    EasyMock.expectLastCall();                
             //}
+            if ("GET".equals(method) && "?wsdl".equals(query)) {
+                verifyGetWSDLQuery();
+            }
         }
         
         if (decoupled) {
@@ -383,6 +409,7 @@
             decoupledBackChannel.send(EasyMock.eq(outMessage));
             EasyMock.expectLastCall();
         }
+        
         control.replay();
     }
     
@@ -409,6 +436,23 @@
         challenges.add(CUSTOM_CHALLENGE);
         responseHeaders.put(CHALLENGE_HEADER, challenges);
     }
+    
+    private void verifyGetWSDLQuery() throws Exception {
+        wsdlQueryHandler = control.createMock(WSDLQueryHandler.class);
+        queryHandlerRegistry = control.createMock(QueryHandlerRegistry.class);
+        queryHandlerList = new ArrayList<QueryHandler>();
+        queryHandlerList.add(wsdlQueryHandler);
+        bus.getExtension(QueryHandlerRegistry.class);
+        EasyMock.expectLastCall().andReturn(queryHandlerRegistry);
+        queryHandlerRegistry.getHandlers();
+        EasyMock.expectLastCall().andReturn(queryHandlerList);
+        wsdlQueryHandler.isRecognizedQuery("http://localhost/bar/foo?wsdl", endpointInfo);
+        EasyMock.expectLastCall().andReturn(true);   
+        wsdlQueryHandler.getResponseContentType("http://localhost/bar/foo?wsdl");
+        EasyMock.expectLastCall().andReturn("text/xml");
+        wsdlQueryHandler.writeResponse("http://localhost/bar/foo?wsdl", endpointInfo, os);
+        EasyMock.expectLastCall().once();
+    }
 
     private void verifyDoService() throws Exception {
         assertNotNull("unexpected null message", inMessage);
@@ -431,7 +475,7 @@
         
         
         assertEquals("unexpected getMethod calls",
-                      2,
+                     1,
                      request.getMethodCallCount());
         assertEquals("unexpected getInputStream calls",
                      1,



Mime
View raw message