cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r529419 - in /incubator/cxf/trunk: api/src/main/java/org/apache/cxf/transports/http/ common/common/ common/common/src/main/java/org/apache/cxf/helpers/ common/common/src/test/java/org/apache/cxf/staxutils/ rt/core/src/main/java/org/apache/c...
Date Mon, 16 Apr 2007 22:13:09 GMT
Author: dkulp
Date: Mon Apr 16 15:13:05 2007
New Revision: 529419

URL: http://svn.apache.org/viewvc?view=rev&rev=529419
Log:
Update the ?wsdl stuff to re-write all the import/includes with new ?wsdl and ?xsd versions.
  (this is a start.  It probably breaks with existing absolute includes/imports)



Modified:
    incubator/cxf/trunk/api/src/main/java/org/apache/cxf/transports/http/QueryHandler.java
    incubator/cxf/trunk/common/common/pom.xml
    incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/XMLUtils.java
    incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/W3CDOMStreamReaderTest.java
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/http/QueryHandlerRegistryImpl.java
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/http/WSDLQueryHandler.java
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/ResourceManagerWSDLLocator.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/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFServlet.java
    incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/CXFServletTest.java

Modified: 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=diff&rev=529419&r1=529418&r2=529419
==============================================================================
--- incubator/cxf/trunk/api/src/main/java/org/apache/cxf/transports/http/QueryHandler.java
(original)
+++ incubator/cxf/trunk/api/src/main/java/org/apache/cxf/transports/http/QueryHandler.java
Mon Apr 16 15:13:05 2007
@@ -26,22 +26,29 @@
 public interface QueryHandler {
     
     /**
-     * @param uri the target URI
+     * @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.
      * @return true iff the URI is a recognized WSDL query
      */
-    boolean isRecognizedQuery(String uri, EndpointInfo endpoint);
+    boolean isRecognizedQuery(String fullQueryString, String ctx, EndpointInfo endpoint);
 
     /**
+     * @param fullQueryString the target full query string (with params) of the request
+     * @param ctx the context that was set for this invokation
      * @return the content-type for the response
      */
-    String getResponseContentType(String uri);
+    String getResponseContentType(String fullQueryString, String ctx);
  
     /**
      * Write query response to output stream
+     * @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.
      */ 
-    void writeResponse(String queryURI, EndpointInfo endpoint, OutputStream os);
+    void writeResponse(String fullQueryString, String ctx, EndpointInfo endpoint, OutputStream
os);
     
 
 

Modified: incubator/cxf/trunk/common/common/pom.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/pom.xml?view=diff&rev=529419&r1=529418&r2=529419
==============================================================================
--- incubator/cxf/trunk/common/common/pom.xml (original)
+++ incubator/cxf/trunk/common/common/pom.xml Mon Apr 16 15:13:05 2007
@@ -116,12 +116,17 @@
             <artifactId>wstx-asl</artifactId>
             <scope>test</scope>
         </dependency>
+
+        <dependency>
+            <groupId>javax.xml.soap</groupId>
+            <artifactId>saaj-api</artifactId>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>com.sun.xml.messaging.saaj</groupId>
             <artifactId>saaj-impl</artifactId>
             <scope>test</scope>
         </dependency>
-
         <dependency>
             <groupId>org.apache.geronimo.specs</groupId>
             <artifactId>geronimo-activation_1.1_spec</artifactId>

Modified: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/XMLUtils.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/XMLUtils.java?view=diff&rev=529419&r1=529418&r2=529419
==============================================================================
--- incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/XMLUtils.java (original)
+++ incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/XMLUtils.java Mon
Apr 16 15:13:05 2007
@@ -116,9 +116,12 @@
     }
 
     public static void writeTo(Node node, OutputStream os) {
+        writeTo(new DOMSource(node), os);
+    }
+    public static void writeTo(Source src, OutputStream os) {
+        Transformer it;
         try {
-            Transformer it = newTransformer();
-
+            it = newTransformer();
             it.setOutputProperty(OutputKeys.METHOD, "xml");
             if (indent()) {
                 it.setOutputProperty(OutputKeys.INDENT, "yes");
@@ -126,12 +129,13 @@
             }
             it.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, omitXmlDecl);
             it.setOutputProperty(OutputKeys.ENCODING, charset);
-            it.transform(new DOMSource(node), new StreamResult(os));
-        } catch (Exception e) {
+            it.transform(src, new StreamResult(os));
+        } catch (TransformerException e) {
+            // TODO Auto-generated catch block
             e.printStackTrace();
         }
-    }
 
+    }
     public static String toString(Source source) throws TransformerException, IOException
{
         return toString(source, null);
     }

Modified: incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/W3CDOMStreamReaderTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/W3CDOMStreamReaderTest.java?view=diff&rev=529419&r1=529418&r2=529419
==============================================================================
--- incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/W3CDOMStreamReaderTest.java
(original)
+++ incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/W3CDOMStreamReaderTest.java
Mon Apr 16 15:13:05 2007
@@ -24,15 +24,14 @@
 
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.SOAPMessage;
+import javax.xml.soap.SOAPPart;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.transform.dom.DOMSource;
 
 import org.w3c.dom.Document;
 
-import com.sun.xml.messaging.saaj.soap.ver1_1.Message1_1Impl;
-import com.sun.xml.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl;
-import com.sun.xml.messaging.saaj.soap.ver1_1.SOAPPart1_1Impl;
-
 import org.apache.cxf.helpers.XMLUtils;
 
 import org.junit.Assert;
@@ -57,15 +56,14 @@
         docBuilderFactory.setNamespaceAware(true);
         DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
 
-        SOAPMessageFactory1_1Impl factory = new SOAPMessageFactory1_1Impl();
-        Message1_1Impl msg = (Message1_1Impl)factory.createMessage();
-        SOAPPart1_1Impl part = new SOAPPart1_1Impl(msg);
+        MessageFactory factory = MessageFactory.newInstance();
+        SOAPMessage msg = factory.createMessage();
+        SOAPPart part = msg.getSOAPPart();
 
         Document doc = docBuilder.parse(is);
 
         W3CDOMStreamWriter writer = new W3CDOMStreamWriter(part.getEnvelope());
         XMLStreamReader reader = StaxUtils.createXMLStreamReader(new DOMSource(doc));
-
 
         StaxUtils.copy(reader, writer);
         assertEquals(RESULT, XMLUtils.toString(writer.getDocument()));

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/http/QueryHandlerRegistryImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/http/QueryHandlerRegistryImpl.java?view=diff&rev=529419&r1=529418&r2=529419
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/http/QueryHandlerRegistryImpl.java
(original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/http/QueryHandlerRegistryImpl.java
Mon Apr 16 15:13:05 2007
@@ -44,7 +44,7 @@
     @PostConstruct
     public void init() {
         queryHandlers = new ArrayList<QueryHandler>();
-        registerHandler(new WSDLQueryHandler());
+        registerHandler(new WSDLQueryHandler(bus));
     }
 
 

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=529419&r1=529418&r2=529419
==============================================================================
--- 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 Apr 16 15:13:05 2007
@@ -19,42 +19,242 @@
 
 package org.apache.cxf.transport.http;
 
+import java.io.IOException;
 import java.io.OutputStream;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 
 import javax.wsdl.Definition;
+import javax.wsdl.Import;
+import javax.wsdl.Types;
 import javax.wsdl.WSDLException;
+import javax.wsdl.extensions.ExtensibilityElement;
+import javax.wsdl.extensions.schema.Schema;
+import javax.wsdl.extensions.schema.SchemaImport;
+import javax.wsdl.extensions.schema.SchemaReference;
 import javax.wsdl.factory.WSDLFactory;
 import javax.wsdl.xml.WSDLWriter;
+import javax.xml.parsers.ParserConfigurationException;
 
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+
+import org.apache.cxf.Bus;
+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.wsdl11.ResourceManagerWSDLLocator;
 import org.apache.cxf.wsdl11.ServiceWSDLBuilder;
 
+
 public class WSDLQueryHandler implements QueryHandler {
 
-    public String getResponseContentType(String uri) {
-        if (uri.toLowerCase().endsWith("?wsdl")) {
+    Bus bus;
+    public WSDLQueryHandler(Bus b) {
+        bus = b;
+    }
+
+    public String getResponseContentType(String baseUri, String ctx) {
+        if (baseUri.toLowerCase().contains("?wsdl")
+            || baseUri.toLowerCase().contains("?xsd=")) {
             return "text/xml";
         }
         return null;
     }
 
-    public boolean isRecognizedQuery(String uri, EndpointInfo endpointInfo) {
-        if (uri != null && uri.toLowerCase().endsWith("?wsdl")) {
-            String addressContext = uri.substring(0, uri.length() - 5);            
-            return endpointInfo.getAddress().contains(addressContext);
+    public boolean isRecognizedQuery(String baseUri, String ctx, EndpointInfo endpointInfo)
{
+        if (baseUri != null 
+            && (baseUri.toLowerCase().contains("?wsdl")
+                || baseUri.toLowerCase().contains("?xsd="))) {
+            return endpointInfo.getAddress().contains(ctx);
         }
         return false;
     }
 
-    public void writeResponse(String queryURI, EndpointInfo endpointInfo, OutputStream os)
{
+    public void writeResponse(String baseUri, String ctxUri,
+                              EndpointInfo endpointInfo, OutputStream os) {
         try {
-            WSDLWriter wsdlWriter = WSDLFactory.newInstance().newWSDLWriter();
-            Definition def = new ServiceWSDLBuilder(endpointInfo.getService()).build();
-            wsdlWriter.writeWSDL(def, os);
+            int idx = baseUri.toLowerCase().indexOf("?wsdl");
+            String base = null;
+            String wsdl = "";
+            String xsd =  null;
+            if (idx != -1) {
+                base = baseUri.substring(0, baseUri.toLowerCase().indexOf("?wsdl"));
+                wsdl = baseUri.substring(baseUri.toLowerCase().indexOf("?wsdl") + 5);
+                if (wsdl.length() > 0) {
+                    wsdl = wsdl.substring(1);
+                }
+            } else {
+                base = baseUri.substring(0, baseUri.toLowerCase().indexOf("?xsd="));
+                xsd = baseUri.substring(baseUri.toLowerCase().indexOf("?xsd=") + 5);
+            }
+            
+            Map<String, Definition> mp = CastUtils.cast((Map)endpointInfo.getService()
+                                                        .getProperty(WSDLQueryHandler.class.getName()));
+            Map<String, SchemaReference> smp = CastUtils.cast((Map)endpointInfo.getService()
+                                                        .getProperty(WSDLQueryHandler.class.getName()

+                                                                     + ".Schemas"));
+
+            if (mp == null) {
+                endpointInfo.getService().setProperty(WSDLQueryHandler.class.getName(),
+                                                      new ConcurrentHashMap());
+                mp = CastUtils.cast((Map)endpointInfo.getService()
+                                    .getProperty(WSDLQueryHandler.class.getName()));
+            }
+            if (smp == null) {
+                endpointInfo.getService().setProperty(WSDLQueryHandler.class.getName()
+                                                      + ".Schemas",
+                                                      new ConcurrentHashMap());
+                smp = CastUtils.cast((Map)endpointInfo.getService()
+                                    .getProperty(WSDLQueryHandler.class.getName()
+                                                 + ".Schemas"));
+            }
+            
+            if (!mp.containsKey(wsdl)) {
+                Definition def = new ServiceWSDLBuilder(endpointInfo.getService()).build();
+                mp.put("", def);
+                updateDefinition(def, mp, smp, base, endpointInfo);
+            }
+            
+            
+            Document doc;
+            if (xsd == null) {
+                Definition def = mp.get(wsdl);
+    
+                WSDLWriter wsdlWriter = WSDLFactory.newInstance().newWSDLWriter();
+                doc = wsdlWriter.getDocument(def);
+            } else {
+                SchemaReference si = smp.get(xsd);
+                ResourceManagerWSDLLocator rml = new ResourceManagerWSDLLocator(si.getReferencedSchema()
+                                                                                .getDocumentBaseURI(),
+                                                                                bus);
+                
+                InputSource src = rml.getBaseInputSource();
+                doc = XMLUtils.getParser().parse(src);
+            }
+            
+            NodeList nl = doc.getDocumentElement()
+                .getElementsByTagNameNS("http://www.w3.org/2001/XMLSchema",
+                                        "import");
+            for (int x = 0; x < nl.getLength(); x++) {
+                Element el = (Element)nl.item(x);
+                String sl = el.getAttribute("schemaLocation");
+                if (smp.containsKey(sl)) {
+                    el.setAttribute("schemaLocation", smp.get(sl).getSchemaLocationURI());
+                }
+            }
+            nl = doc.getDocumentElement()
+                .getElementsByTagNameNS("http://www.w3.org/2001/XMLSchema",
+                                        "include");
+            for (int x = 0; x < nl.getLength(); x++) {
+                Element el = (Element)nl.item(x);
+                String sl = el.getAttribute("schemaLocation");
+                if (smp.containsKey(sl)) {
+                    el.setAttribute("schemaLocation", smp.get(sl).getSchemaLocationURI());
+                }
+            }
+            
+            XMLUtils.writeTo(doc, os);
         } catch (WSDLException wex) {
             wex.printStackTrace();
+        } catch (SAXException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (IOException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (ParserConfigurationException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+    }
+    
+    private void updateDefinition(Definition def, Map<String, Definition> done,
+                                  Map<String, SchemaReference> doneSchemas,
+                                  String base, EndpointInfo ei) {
+        Collection<List> imports = CastUtils.cast((Collection<?>)def.getImports().values());
+        for (List lst : imports) {
+            List<Import> impLst = CastUtils.cast(lst);
+            for (Import imp : impLst) {
+                String start = imp.getLocationURI();
+                String uri = start;
+                if (!uri.startsWith(base)) {
+                    uri = base + "?wsdl=" + uri;
+                }
+                imp.setLocationURI(uri);
+                done.put(start, imp.getDefinition());
+                updateDefinition(imp.getDefinition(), done, doneSchemas, base, ei);
+            }
+        }      
+        
+        
+        /* This doesn't actually work.   Setting setSchemaLocationURI on the import
+        * for some reason doesn't actually result in the new URI being written
+        * */
+        Types types = def.getTypes();
+        if (types != null) {
+            for (ExtensibilityElement el 
+                : CastUtils.cast((List)types.getExtensibilityElements(), ExtensibilityElement.class))
{
+                if (el instanceof Schema) {
+                    Schema see = (Schema)el;
+                    updateSchemaImports(see, doneSchemas, base);
+                }
+            }
+        }
+    }
+    
+    private void updateSchemaImports(Schema schema,
+                                     Map<String, SchemaReference> doneSchemas,
+                                     String base) {
+        Collection<List>  imports = CastUtils.cast((Collection<?>)schema.getImports().values());
+        for (List lst : imports) {
+            List<SchemaImport> impLst = CastUtils.cast(lst);
+            for (SchemaImport imp : impLst) {
+                String start = imp.getSchemaLocationURI();
+                if (start != null) {
+                    String uri = start;
+                    if (!uri.startsWith(base)) {
+                        uri = base + "?xsd=" + uri;
+                    }
+                    imp.setSchemaLocationURI(uri);
+                    doneSchemas.put(start, imp);
+                    updateSchemaImports(imp.getReferencedSchema(), doneSchemas, base);
+
+                    System.out.println(schema.getDocumentBaseURI());
+                    System.out.println(start);
+                    System.out.println(uri);
+                    System.out.println();
+                } else {
+                    System.out.println(schema.getDocumentBaseURI());
+                    System.out.println(imp.getId());
+                    System.out.println(imp.getSchemaLocationURI());
+                    System.out.println(imp.getReferencedSchema());
+                    System.out.println();
+                }
+            }
+        }
+        List<SchemaReference> includes = CastUtils.cast(schema.getIncludes());
+        for (SchemaReference included : includes) {
+            String start = included.getSchemaLocationURI();
+            if (start != null) {
+                String uri = start;
+                if (!uri.startsWith(base)) {
+                    uri = base + "?xsd=" + uri;
+                }
+                included.setSchemaLocationURI(uri);
+                doneSchemas.put(start, included);
+                updateSchemaImports(included.getReferencedSchema(), doneSchemas, base);
+            }
         }
+        
     }
 
 }

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/ResourceManagerWSDLLocator.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/ResourceManagerWSDLLocator.java?view=diff&rev=529419&r1=529418&r2=529419
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/ResourceManagerWSDLLocator.java
(original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/ResourceManagerWSDLLocator.java
Mon Apr 16 15:13:05 2007
@@ -25,6 +25,8 @@
 import org.xml.sax.InputSource;
 
 import org.apache.cxf.Bus;
+import org.apache.cxf.catalog.CatalogWSDLLocator;
+import org.apache.cxf.catalog.OASISCatalogManager;
 import org.apache.cxf.resource.ResourceManager;
 
 
@@ -40,6 +42,13 @@
         this.wsdlUrl = wsdlUrl;
         this.bus = bus;
         this.parent = parent;
+    }
+
+    public ResourceManagerWSDLLocator(String wsdlUrl,
+                                      Bus bus) {
+        this.wsdlUrl = wsdlUrl;
+        this.bus = bus;
+        this.parent = new CatalogWSDLLocator(wsdlUrl, OASISCatalogManager.getCatalog(bus));
     }
 
 

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=529419&r1=529418&r2=529419
==============================================================================
--- 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 Apr 16 15:13:05 2007
@@ -141,11 +141,12 @@
         }
         QueryHandlerRegistry queryHandlerRegistry = bus.getExtension(QueryHandlerRegistry.class);
         if (queryHandlerRegistry != null) { 
+            String requestURL = req.getRequestURI() + "?" + req.getQueryString();
+            String pathInfo = req.getPathInfo();
             for (QueryHandler qh : queryHandlerRegistry.getHandlers()) {
-                String requestURL = req.getPathInfo() + "?" + req.getQueryString();     
          
-                if (qh.isRecognizedQuery(requestURL, endpointInfo)) {
-                    resp.setContentType(qh.getResponseContentType(requestURL));
-                    qh.writeResponse(requestURL, endpointInfo, resp.getOutputStream());
+                if (qh.isRecognizedQuery(requestURL, pathInfo, endpointInfo)) {
+                    resp.setContentType(qh.getResponseContentType(requestURL, pathInfo));
+                    qh.writeResponse(requestURL, pathInfo, endpointInfo, resp.getOutputStream());
                     resp.getOutputStream().flush();                     
                     baseRequest.setHandled(true);
                     return;

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=529419&r1=529418&r2=529419
==============================================================================
--- 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 Apr 16 15:13:05 2007
@@ -530,9 +530,11 @@
         bus.getExtension(QueryHandlerRegistry.class);
         EasyMock.expectLastCall().andReturn(queryHandlerRegistry);
         queryHandlerRegistry.getHandlers();
-        EasyMock.expectLastCall().andReturn(queryHandlerList);
-        request.getPathInfo();
+        EasyMock.expectLastCall().andReturn(queryHandlerList);       
+        request.getRequestURI();
         EasyMock.expectLastCall().andReturn("http://localhost/bar/foo");
+        request.getPathInfo();
+        EasyMock.expectLastCall().andReturn("/bar/foo");
         request.getQueryString();
         EasyMock.expectLastCall().andReturn("wsdl");       
         response.setContentType("text/xml");
@@ -541,11 +543,11 @@
         EasyMock.expectLastCall().andReturn(os).anyTimes();
         request.setHandled(true);
         EasyMock.expectLastCall();
-        wsdlQueryHandler.isRecognizedQuery("http://localhost/bar/foo?wsdl", endpointInfo);
+        wsdlQueryHandler.isRecognizedQuery("http://localhost/bar/foo?wsdl", "/bar/foo", endpointInfo);
         EasyMock.expectLastCall().andReturn(true);   
-        wsdlQueryHandler.getResponseContentType("http://localhost/bar/foo?wsdl");
+        wsdlQueryHandler.getResponseContentType("http://localhost/bar/foo?wsdl", "/bar/foo");
         EasyMock.expectLastCall().andReturn("text/xml");
-        wsdlQueryHandler.writeResponse("http://localhost/bar/foo?wsdl", endpointInfo, os);
+        wsdlQueryHandler.writeResponse("http://localhost/bar/foo?wsdl", "/bar/foo", endpointInfo,
os);
         EasyMock.expectLastCall().once();
         EasyMock.replay(bus);
         EasyMock.replay(queryHandlerRegistry);

Modified: incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFServlet.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFServlet.java?view=diff&rev=529419&r1=529418&r2=529419
==============================================================================
--- incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFServlet.java
(original)
+++ incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFServlet.java
Mon Apr 16 15:13:05 2007
@@ -55,7 +55,6 @@
  *
  */
 public class CXFServlet extends HttpServlet {
-    static final String ADDRESS_PERFIX = "http://localhost/services";
     static final Map<String, WeakReference<Bus>> BUS_MAP = new Hashtable<String,
WeakReference<Bus>>();
     static final Logger LOG = Logger.getLogger(CXFServlet.class.getName());
     
@@ -65,7 +64,7 @@
     private GenericApplicationContext childCtx;
 
     public ServletController createServletController() {
-        return new ServletController(servletTransportFactory, this.getServletContext(), this);
+        return new ServletController(servletTransportFactory, this);
     }
 
     public ServletController getController() {

Modified: incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java?view=diff&rev=529419&r1=529418&r2=529419
==============================================================================
--- incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java
(original)
+++ incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java
Mon Apr 16 15:13:05 2007
@@ -22,84 +22,41 @@
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.Collection;
-import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
-import javax.servlet.ServletContext;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import javax.wsdl.Definition;
-import javax.wsdl.Port;
-import javax.wsdl.WSDLException;
-import javax.wsdl.extensions.ExtensibilityElement;
-import javax.xml.transform.Result;
-import javax.xml.transform.Source;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.sax.SAXSource;
-import javax.xml.transform.stream.StreamResult;
-import javax.xml.transform.stream.StreamSource;
-
-import org.xml.sax.InputSource;
 
 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.resource.ExtendedURIResolver;
 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.transport.http.AbstractHTTPDestination;
 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.wsdl11.ServiceWSDLBuilder;
-import org.xmlsoap.schemas.wsdl.http.AddressType;
 
 public class ServletController {
     
     private static final Logger LOG = Logger.getLogger(ServletController.class.getName());
 
     private ServletTransportFactory transport;
-    private ServletContext servletContext;
     private CXFServlet cxfServlet;
  
-    public ServletController(ServletTransportFactory df, ServletContext servCont, CXFServlet
servlet) {
+    public ServletController(ServletTransportFactory df, CXFServlet servlet) {
         this.transport = df;
-        this.servletContext = servCont;
         this.cxfServlet = servlet;
     }
 
     public void invoke(HttpServletRequest request, HttpServletResponse res) throws ServletException
{
-        boolean wsdl = false;
-        boolean xsd = false;
-        if (request.getQueryString() != null && request.getQueryString().trim().equalsIgnoreCase("wsdl"))
{
-            wsdl = true;
-        }       
-        String xsdName = request.getRequestURI().substring(
-            request.getRequestURI().lastIndexOf("/") + 1); 
-        if (xsdName != null 
-                && xsdName.substring(xsdName.lastIndexOf(".") + 1).equalsIgnoreCase("xsd"))
{
-            xsd = true;
-        }
         try {
             EndpointInfo ei = new EndpointInfo();
-            String address = "";
+            String address = "http://localhost" + request.getServletPath() 
+                + (request.getPathInfo() == null ? "" : request.getPathInfo());
             
-            if (xsd) {
-                address = "http://localhost"
-                          + request.getServletPath()
-                          + (request.getPathInfo() == null ? "" 
-                              : request.getPathInfo()
-                                  .substring(0, request.getPathInfo().lastIndexOf(xsdName)
- 1));
-            } else {
-                address = "http://localhost" + request.getServletPath() 
-                    + (request.getPathInfo() == null ? "" : request.getPathInfo());
-            }
             ei.setAddress(address);
-           
             ServletDestination d = (ServletDestination)transport.getDestination(ei);
 
             if (d.getMessageObserver() == null) {
@@ -107,15 +64,38 @@
                     || request.getRequestURI().endsWith("services/")) {
                     generateServiceList(request, res);
                 } else {
-                    LOG.warning("Can't find the the request for " + address + "'s Observer
");
+                    LOG.warning("Can't find the the request for " + request.getRequestURI()
+ "'s Observer ");
+                    LOG.warning(transport.getDestinationsPaths().toString());
+                    LOG.warning(transport.getDestinations().toString());
                     generateNotFound(request, res);
                 }
-
-            } else if (xsd) {
-                generateXSD(request, res, d, xsdName);
-            } else if (wsdl) {
-                generateWSDL(request, res, d);
             } else {
+                ei = d.getEndpointInfo();
+                Bus bus = cxfServlet.getBus();
+                if (bus.getExtension(QueryHandlerRegistry.class) != null) { 
+                    for (QueryHandler qh : bus.getExtension(QueryHandlerRegistry.class).getHandlers())
{
+                        if (null != request.getQueryString() && request.getQueryString().length()
> 0) {
+                            String ctxUri = request.getPathInfo();
+                            String baseUri = request.getRequestURL().toString() 
+                                + "?" + request.getQueryString();
+                            
+                            if (qh.isRecognizedQuery(baseUri, ctxUri, ei)) {
+                                
+                                res.setContentType(qh.getResponseContentType(baseUri, ctxUri));
+                                OutputStream out = res.getOutputStream();
+                                try {
+                                    qh.writeResponse(baseUri, ctxUri, ei, out);
+                                    out.flush();
+                                    return;
+                                } catch (Exception e) {
+                                    throw new ServletException(e);
+                                }
+                                
+                            }
+                        }   
+                    }
+                }
+                
                 invokeDestination(request, res, d);
             }
         } catch (IOException e) {
@@ -128,17 +108,18 @@
         Collection<ServletDestination> destinations = transport.getDestinations();
         response.setContentType("text/html");        
         response.getWriter().write("<html><body>");
+        
+        String reqPerfix = request.getRequestURL().toString();
+        reqPerfix = reqPerfix.substring(0, reqPerfix.lastIndexOf("services"));
+        
         if (destinations.size() > 0) {  
             for (ServletDestination sd : destinations) {
                 if (null != sd.getEndpointInfo().getName()) {
                     String address = sd.getAddress().getAddress().getValue();
-                    int bi = address.indexOf(CXFServlet.ADDRESS_PERFIX);
-                    String reqPerfix = request.getRequestURL().toString();
-                    if (reqPerfix.endsWith("/")) {
-                        reqPerfix = reqPerfix.substring(0, reqPerfix.length() - 1);
-                    }
-                    address = reqPerfix 
-                        + address.substring(bi + CXFServlet.ADDRESS_PERFIX.length());
+                    
+                    address = reqPerfix
+                        + address.substring("http://localhost/".length());
+                    
                     response.getWriter().write("<p> <a href=\"" + address + "?wsdl\">");
                     response.getWriter().write(sd.getEndpointInfo().getName() + "</a>
</p>");
                 }    
@@ -149,31 +130,6 @@
         response.getWriter().write("</body></html>");
     }
 
-    private void generateXSD(HttpServletRequest request, HttpServletResponse response, ServletDestination
d,
-                             String xsdName) throws ServletException {
-        response.setHeader(HttpHeaderHelper.CONTENT_TYPE, "text/xml");
-        try {
-            OutputStream os = response.getOutputStream();
-            ExtendedURIResolver resolver = new ExtendedURIResolver();
-            Source source = null;
-
-            EndpointInfo ei = d.getEndpointInfo();
-            String wsdlBaseURI = ei.getService().getDescription().getBaseURI();
-            if (wsdlBaseURI != null) {
-                InputSource inputSource = resolver.resolve(xsdName, wsdlBaseURI);
-                source = new SAXSource(inputSource);
-
-            } else {
-                source = new StreamSource(servletContext.getResourceAsStream("/WEB-INF/wsdl/"
+ xsdName));
-            }
-            Result result = new StreamResult(os);
-            TransformerFactory.newInstance().newTransformer().transform(source, result);
-            response.getOutputStream().flush();
-        } catch (Exception e) {
-            throw new ServletException(e);
-        }
-    }
-
     protected void generateNotFound(HttpServletRequest request, HttpServletResponse res)
throws IOException {
         res.setStatus(404);
         res.setContentType("text/html");
@@ -202,55 +158,5 @@
             throw new ServletException(e);
         }
 
-    }
-
-    protected void generateWSDL(HttpServletRequest request, 
-                                HttpServletResponse response, 
-                                ServletDestination d)
-        throws ServletException {
-        
-        try {
-            OutputStream os = response.getOutputStream();
-
-            EndpointInfo ei = d.getEndpointInfo();
-            Definition def = new ServiceWSDLBuilder(ei.getService()).build();
-            Port port = def.getService(ei.getService().getName()).getPort(ei.getName().getLocalPart());
-            List<?> exts = port.getExtensibilityElements();
-            if (exts.size() > 0) {
-                ExtensibilityElement el = (ExtensibilityElement)exts.get(0);
-                if (SOAPBindingUtil.isSOAPAddress(el)) {
-                    SoapAddress add = SOAPBindingUtil.getSoapAddress(el);
-                    add.setLocationURI(request.getRequestURL().toString());
-                }
-                if (el instanceof AddressType) {
-                    AddressType add = (AddressType)el;
-                    add.setLocation(request.getRequestURL().toString());
-                }
-            }
-            
-            Bus bus = cxfServlet.getBus();
-            if (bus.getExtension(QueryHandlerRegistry.class) != null) { 
-                for (QueryHandler qh : bus.getExtension(QueryHandlerRegistry.class).getHandlers())
{
-                    if (null != request.getQueryString() && request.getQueryString().length()
> 0) {
-                        String requestURL = request.getPathInfo() + "?" + request.getQueryString();
-                        if (qh.isRecognizedQuery(requestURL, ei)) {
-                            response.setContentType(qh.getResponseContentType(requestURL));
-                            try {
-                                qh.writeResponse(requestURL, ei, os);
-                            } catch (Exception e) {
-                                throw new ServletException(e);
-                            }
-                        }
-                    }   
-                }
-            }
-
-            response.getOutputStream().flush();
-            
-        } catch (WSDLException e) {
-            throw new ServletException(e);
-        } catch (IOException e) {
-            throw new ServletException(e);
-        }
     }
 }

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/CXFServletTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/CXFServletTest.java?view=diff&rev=529419&r1=529418&r2=529419
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/CXFServletTest.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/CXFServletTest.java
Mon Apr 16 15:13:05 2007
@@ -141,12 +141,21 @@
         ServletUnitClient client = newClient();
         client.setExceptionsThrownOnErrorStatus(true);
 
-        WebRequest req = new GetMethodQueryWebRequest("http://localhost/services/greeter/test_import.xsd");
-        
+        WebRequest req 
+            = new GetMethodQueryWebRequest("http://localhost/services/greeter?wsdl");
         WebResponse res = client.getResponse(req); 
         assertEquals(200, res.getResponseCode());
-        //assertEquals("text/xml", res.getContentType());
+        String text = res.getText();
+        assertEquals("text/xml", res.getContentType());
+        assertTrue(text.contains("http://localhost/services/greeter?wsdl=test_import.xsd"));
+
+        req = new GetMethodQueryWebRequest("http://localhost/services/greeter?wsdl=test_import.xsd");
+        res = client.getResponse(req); 
+        assertEquals(200, res.getResponseCode());
+        text = res.getText();
+        
+        assertEquals("text/xml", res.getContentType());
         assertTrue("the xsd should contain the completType SimpleStruct",
-                   res.getText().contains("<complexType name=\"SimpleStruct\">"));
+                   text.contains("<complexType name=\"SimpleStruct\">"));
     }
 }



Mime
View raw message