servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r386353 - in /incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http: ServerManager.java processors/ConsumerProcessor.java
Date Thu, 16 Mar 2006 15:20:33 GMT
Author: gnodet
Date: Thu Mar 16 07:20:31 2006
New Revision: 386353

URL: http://svn.apache.org/viewcvs?rev=386353&view=rev
Log:
SM-351: servicemix-http should expose the endpoints' WSDL on a GET request

Modified:
    incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/ServerManager.java
    incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ConsumerProcessor.java

Modified: incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/ServerManager.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/ServerManager.java?rev=386353&r1=386352&r2=386353&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/ServerManager.java
(original)
+++ incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/ServerManager.java
Thu Mar 16 07:20:31 2006
@@ -15,6 +15,8 @@
  */
 package org.apache.servicemix.http;
 
+import java.io.IOException;
+import java.io.OutputStream;
 import java.lang.reflect.Array;
 import java.net.URL;
 import java.util.ArrayList;
@@ -23,18 +25,28 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.mortbay.jetty.Connector;
 import org.mortbay.jetty.Handler;
+import org.mortbay.jetty.HttpMethods;
+import org.mortbay.jetty.MimeTypes;
 import org.mortbay.jetty.Server;
+import org.mortbay.jetty.handler.AbstractHandler;
 import org.mortbay.jetty.handler.ContextHandler;
 import org.mortbay.jetty.servlet.ServletHandler;
 import org.mortbay.jetty.servlet.ServletHolder;
 import org.mortbay.jetty.servlet.ServletMapping;
 import org.mortbay.thread.BoundedThreadPool;
 import org.mortbay.thread.ThreadPool;
+import org.mortbay.util.ByteArrayISO8859Writer;
+import org.mortbay.util.StringUtil;
 
 public class ServerManager {
 
@@ -172,6 +184,7 @@
         Server server = new Server();
         server.setThreadPool(threadPool);
         server.setConnectors(new Connector[] { connector });
+        server.setNotFoundHandler(new DisplayServiceHandler());
         connector.start();
         server.start();
         String key = url.getProtocol() + "://" + url.getHost() + ":" + url.getPort();
@@ -189,6 +202,67 @@
 
     public ThreadPool getThreadPool() {
         return threadPool;
+    }
+    
+    protected class DisplayServiceHandler extends AbstractHandler {
+
+        public boolean handle(String target, HttpServletRequest request, HttpServletResponse
response, int dispatch) throws IOException, ServletException {
+            String method = request.getMethod();
+            
+            if (!method.equals(HttpMethods.GET) || !request.getRequestURI().equals("/"))
{
+                response.sendError(404);
+                return true;   
+            }
+
+            response.setStatus(404);
+            response.setContentType(MimeTypes.TEXT_HTML);
+            
+            ByteArrayISO8859Writer writer = new ByteArrayISO8859Writer(1500);
+
+            String uri = request.getRequestURI();
+            uri = StringUtil.replace(uri, "<", "&lt;");
+            uri = StringUtil.replace(uri, ">", "&gt;");
+            
+            writer.write("<HTML>\n<HEAD>\n<TITLE>Error 404 - Not Found");
+            writer.write("</TITLE>\n<BODY>\n<H2>Error 404 - Not Found.</H2>\n");
+            writer.write("No service matched or handled this request.<BR>");
+            writer.write("Known services are: <ul>");
+
+            Set servers = ServerManager.this.servers.keySet();
+            for (Iterator iter = servers.iterator(); iter.hasNext();) {
+                String serverUri = (String) iter.next();
+                Server server = (Server) ServerManager.this.servers.get(serverUri);
+                Handler[] handlers = server.getAllHandlers();
+                for (int i = 0; handlers != null && i < handlers.length; i++)
+                {
+                    if (!(handlers[i] instanceof ContextHandler)) {
+                        continue;
+                    }
+                    ContextHandler context = (ContextHandler)handlers[i];
+                        writer.write("<li><a href=\"");
+                        writer.write(serverUri);
+                        writer.write(context.getContextPath());
+                        writer.write("/?wsdl\">");
+                        writer.write(serverUri);
+                        writer.write(context.getContextPath());
+                        writer.write("</a></li>\n");
+                }
+            }
+            
+            for (int i=0; i < 10; i++) {
+                writer.write("\n<!-- Padding for IE                  -->");
+            }
+            
+            writer.write("\n</BODY>\n</HTML>\n");
+            writer.flush();
+            response.setContentLength(writer.size());
+            OutputStream out = response.getOutputStream();
+            writer.writeTo(out);
+            out.close();
+            
+            return true;
+        }
+        
     }
 
 }

Modified: incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ConsumerProcessor.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ConsumerProcessor.java?rev=386353&r1=386352&r2=386353&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ConsumerProcessor.java
(original)
+++ incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ConsumerProcessor.java
Thu Mar 16 07:20:31 2006
@@ -27,6 +27,10 @@
 import javax.jbi.messaging.NormalizedMessage;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
 
 import org.apache.servicemix.JbiConstants;
 import org.apache.servicemix.common.BaseLifeCycle;
@@ -44,6 +48,7 @@
 import org.mortbay.jetty.handler.ContextHandler;
 import org.mortbay.util.ajax.Continuation;
 import org.mortbay.util.ajax.ContinuationSupport;
+import org.w3c.dom.Document;
 
 import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap;
 
@@ -98,8 +103,16 @@
     }
 
     public void process(HttpServletRequest request, HttpServletResponse response) throws
Exception {
+        if ("GET".equals(request.getMethod())) {
+            String query = request.getQueryString();
+            if (query != null && query.trim().equalsIgnoreCase("wsdl")) {
+                generateWSDL(response);
+                return;
+            }
+        }
         if (!"POST".equals(request.getMethod())) {
-            throw new UnsupportedOperationException(request.getMethod() + " not supported");
+            response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, request.getMethod()
+ " not supported");
+            return;
         }
         // Not giving a specific mutex will synchronize on the contination itself
         Continuation cont = ContinuationSupport.getContinuation(request, null);
@@ -192,6 +205,18 @@
     protected ServerManager getServerManager() {
         HttpLifeCycle lf =  (HttpLifeCycle) endpoint.getServiceUnit().getComponent().getLifeCycle();
         return lf.getServer();
+    }
+    
+    protected void generateWSDL(HttpServletResponse response) throws Exception {
+        Document doc = endpoint.getDescription();
+        if (doc == null) {
+            response.sendError(HttpServletResponse.SC_NOT_FOUND, "No wsdl is available for
this service");
+            return;
+        }
+        response.setStatus(200);
+        response.setContentType("text/xml");
+        Transformer transformer = TransformerFactory.newInstance().newTransformer();
+        transformer.transform(new DOMSource(doc), new StreamResult(response.getOutputStream()));
     }
 
 }



Mime
View raw message