servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ff...@apache.org
Subject svn commit: r671768 - in /servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc: ./ src/main/java/org/apache/servicemix/cxfbc/ src/test/java/org/apache/servicemix/cxfbc/
Date Thu, 26 Jun 2008 05:33:48 GMT
Author: ffang
Date: Wed Jun 25 22:33:48 2008
New Revision: 671768

URL: http://svn.apache.org/viewvc?rev=671768&view=rev
Log:
[SM-1414]Want to be able to see all the web services exposed by cxf-bc, in a browser.

Added:
    servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/ListServiceHandler.java
  (with props)
Modified:
    servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/pom.xml
    servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/CxfBcConsumer.java
    servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/test/java/org/apache/servicemix/cxfbc/CxfBcComponentTest.java

Modified: servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/pom.xml?rev=671768&r1=671767&r2=671768&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/pom.xml
(original)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/pom.xml
Wed Jun 25 22:33:48 2008
@@ -278,6 +278,29 @@
                <artifactId>wstx-asl</artifactId>
            </exclusion>
        </exclusions>
+ 
+    </dependency>
+    <dependency>
+        <groupId>commons-httpclient</groupId>
+        <artifactId>commons-httpclient</artifactId>
+        <scope>test</scope>
+        <exclusions>         
+            <exclusion>
+                <groupId>commons-codec</groupId>
+                <artifactId>commons-codec</artifactId>
+            </exclusion>
+        </exclusions>
+    </dependency>
+    <dependency>
+        <groupId>commons-codec</groupId>
+        <artifactId>commons-codec</artifactId>
+        <scope>test</scope>
+        <exclusions>
+            <exclusion>
+                <groupId>junit</groupId>
+                <artifactId>junit</artifactId>
+            </exclusion>
+        </exclusions>
     </dependency>
   </dependencies>
 

Modified: servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/CxfBcConsumer.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/CxfBcConsumer.java?rev=671768&r1=671767&r2=671768&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/CxfBcConsumer.java
(original)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/CxfBcConsumer.java
Wed Jun 25 22:33:48 2008
@@ -61,6 +61,7 @@
 import org.apache.cxf.endpoint.EndpointImpl;
 import org.apache.cxf.endpoint.Server;
 import org.apache.cxf.endpoint.ServerImpl;
+import org.apache.cxf.endpoint.ServerRegistry;
 import org.apache.cxf.helpers.DOMUtils;
 import org.apache.cxf.interceptor.AttachmentInInterceptor;
 import org.apache.cxf.interceptor.AttachmentOutInterceptor;
@@ -83,6 +84,8 @@
 import org.apache.cxf.service.model.MessagePartInfo;
 import org.apache.cxf.service.model.ServiceInfo;
 import org.apache.cxf.transport.ChainInitiationObserver;
+import org.apache.cxf.transport.http_jetty.JettyHTTPDestination;
+import org.apache.cxf.transport.http_jetty.JettyHTTPServerEngine;
 import org.apache.cxf.ws.addressing.AddressingProperties;
 import org.apache.cxf.ws.rm.Servant;
 import org.apache.cxf.wsdl.WSDLManager;
@@ -96,6 +99,7 @@
 import org.apache.servicemix.cxfbc.interceptors.MtomCheckInterceptor;
 import org.apache.servicemix.jbi.jaxp.SourceTransformer;
 import org.apache.servicemix.soap.util.DomUtil;
+import org.mortbay.jetty.Handler;
 import org.springframework.core.io.Resource;
 
 
@@ -203,9 +207,24 @@
     @Override
     public void start() throws Exception {
         super.start();
+        registerListServiceHandler();
         server.start();
     }
 
+    private void registerListServiceHandler() {
+        if (server.getDestination() instanceof JettyHTTPDestination) {
+            JettyHTTPDestination jettyDest = (JettyHTTPDestination) server.getDestination();
+            JettyHTTPServerEngine jettyEng = (JettyHTTPServerEngine) jettyDest.getEngine();
+            List<Handler> handlers = jettyEng.getHandlers();
+            if (handlers == null) {
+                handlers = new ArrayList<Handler>();
+                jettyEng.setHandlers(handlers);
+            }
+            handlers.add(new ListServiceHandler(getBus().getExtension(ServerRegistry.class)));
+                
+        }
+    }
+
     @Override
     public void stop() throws Exception {
         server.stop();

Added: servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/ListServiceHandler.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/ListServiceHandler.java?rev=671768&view=auto
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/ListServiceHandler.java
(added)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/ListServiceHandler.java
Wed Jun 25 22:33:48 2008
@@ -0,0 +1,101 @@
+/*
+ * 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.servicemix.cxfbc;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.cxf.endpoint.Server;
+import org.apache.cxf.endpoint.ServerRegistry;
+import org.apache.cxf.transport.http_jetty.JettyHTTPDestination;
+import org.mortbay.jetty.HttpConnection;
+import org.mortbay.jetty.HttpMethods;
+import org.mortbay.jetty.MimeTypes;
+import org.mortbay.jetty.handler.AbstractHandler;
+import org.mortbay.util.ByteArrayISO8859Writer;
+import org.mortbay.util.StringUtil;
+
+public class ListServiceHandler extends AbstractHandler {
+
+
+    private ServerRegistry serverRegistry;
+    
+    public ListServiceHandler(ServerRegistry serRegistry) {
+        this.serverRegistry = serRegistry;
+    }
+    
+    public void handle(String target, HttpServletRequest request,
+            HttpServletResponse response, int dispatch) throws IOException,
+            ServletException {
+        if (response.isCommitted()
+                || HttpConnection.getCurrentConnection().getRequest()
+                        .isHandled()) {
+            return;
+        }
+
+        String method = request.getMethod();
+
+        if (!method.equals(HttpMethods.GET)
+                || !request.getRequestURI().equals("/")) {
+            return;
+        }
+
+        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 on cxf bc component are: <ul>");
+
+        List<Server> servers = serverRegistry.getServers();
+        for (Iterator iter = servers.iterator(); iter.hasNext();) {
+            Server server = (Server) iter.next();
+            JettyHTTPDestination jhd = (JettyHTTPDestination)server.getDestination();
+            String address = jhd.getAddress().getAddress().getValue();
+            writer.write("<li><a href=\"");
+            writer.write(address);
+            writer.write("?wsdl\">");
+            writer.write(address);
+            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();
+    }
+
+}

Propchange: servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/ListServiceHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/ListServiceHandler.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/test/java/org/apache/servicemix/cxfbc/CxfBcComponentTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/test/java/org/apache/servicemix/cxfbc/CxfBcComponentTest.java?rev=671768&r1=671767&r2=671768&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/test/java/org/apache/servicemix/cxfbc/CxfBcComponentTest.java
(original)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/test/java/org/apache/servicemix/cxfbc/CxfBcComponentTest.java
Wed Jun 25 22:33:48 2008
@@ -27,6 +27,8 @@
 
 import junit.framework.TestCase;
 
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.GetMethod;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.endpoint.Client;
 import org.apache.cxf.frontend.ClientProxy;
@@ -99,6 +101,30 @@
 
         Thread.sleep(100);
     }
+    
+    public void testListService() throws Exception {
+        CxfBcComponent comp = new CxfBcComponent();
+        CxfBcConsumer ep = new CxfBcConsumer();
+        ep.setWsdl(new ClassPathResource("HelloWorld-DOC.wsdl"));
+        ep.setTargetService(new QName("urn:test", "target"));
+        comp.setEndpoints(new CxfBcEndpointType[] {ep});
+        jbi.activateComponent(comp, "servicemix-cxfbc");
+
+        MockServiceComponent echo = new MockServiceComponent();
+        echo.setService(new QName("urn:test", "target"));
+        echo.setEndpoint("endpoint");
+        echo.setResponseXml("<jbi:message xmlns:jbi='http://java.sun.com/xml/ns/jbi/wsdl-11-wrapper'><jbi:part>"

+                + "<ns2:HelloResponse xmlns:ns2='uri:HelloWorld'><text>helloffang</text></ns2:HelloResponse></jbi:part></jbi:message>");
+        jbi.activateComponent(echo, "echo");
+        URL wsdl = getClass().getResource("/HelloWorld-DOC.wsdl");
+        assertNotNull(wsdl);
+        GetMethod getMethod = new GetMethod("http://localhost:8080");
+        HttpClient httpClient = new HttpClient();
+        httpClient.executeMethod(getMethod);
+        String response = getMethod.getResponseBodyAsString();
+        assertTrue(response.indexOf("Known services on cxf bc component are:") >= 0);
+        assertTrue(response.indexOf("http://localhost:8080/hello") >= 0);
+    }
 
     public void testEndpointDOCWithExternalConsumer() throws Exception {
         CxfBcComponent comp = new CxfBcComponent();



Mime
View raw message