camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r748093 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/ camel-core/src/main/java/org/apache/camel/model/ components/camel-web/src/main/java/org/apache/camel/web/resources/ components/camel-web/src/main/webapp/org/apache/camel/...
Date Thu, 26 Feb 2009 11:27:40 GMT
Author: jstrachan
Date: Thu Feb 26 11:27:40 2009
New Revision: 748093

URL: http://svn.apache.org/viewvc?rev=748093&view=rev
Log:
CAMEL-1355 - added the ability to start/stop routes from camel-web as well as display an individual
route's status or post it restfully

Added:
    camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/resources/RouteStatusResource.java
  (with props)
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/ServiceStatus.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteType.java
    camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/resources/EndpointsResource.java
    camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/resources/RouteResource.java
    camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/resources/RoutesResource.java
    camel/trunk/components/camel-web/src/main/webapp/org/apache/camel/web/resources/RoutesResource/index.jsp

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/ServiceStatus.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/ServiceStatus.java?rev=748093&r1=748092&r2=748093&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/ServiceStatus.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/ServiceStatus.java Thu Feb 26 11:27:40
2009
@@ -24,4 +24,12 @@
  */
 public enum ServiceStatus {
     Created, Starting, Started, Stopping, Stopped;
+
+    public boolean isStartable() {
+        return this != Starting && this != Started;
+    }
+
+    public boolean isStoppable() {
+        return this != Stopping && this != Stopped;
+    }
 }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteType.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteType.java?rev=748093&r1=748092&r2=748093&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteType.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteType.java Thu Feb 26
11:27:40 2009
@@ -81,11 +81,35 @@
      */
     public ServiceStatus getStatus() {
         if (camelContext != null) {
-            return camelContext.getRouteStatus(this);
+            ServiceStatus answer = camelContext.getRouteStatus(this);
+            if (answer == null) {
+                answer = ServiceStatus.Stopped;
+            }
+            return answer;
         }
         return null;
     }
 
+    public boolean isStartable() {
+        ServiceStatus status = getStatus();
+        if (status == null) {
+            return true;
+        }
+        else {
+            return status.isStartable();
+        }
+    }
+
+    public boolean isStoppable() {
+        ServiceStatus status = getStatus();
+        if (status == null) {
+            return false;
+        }
+        else {
+            return status.isStoppable();
+        }
+    }
+    
     public List<RouteContext> addRoutes(CamelContext context, Collection<Route>
routes) throws Exception {
         List<RouteContext> answer = new ArrayList<RouteContext>();
         setCamelContext(context);

Modified: camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/resources/EndpointsResource.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/resources/EndpointsResource.java?rev=748093&r1=748092&r2=748093&view=diff
==============================================================================
--- camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/resources/EndpointsResource.java
(original)
+++ camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/resources/EndpointsResource.java
Thu Feb 26 11:27:40 2009
@@ -113,6 +113,7 @@
     @POST
     @Consumes("application/x-www-form-urlencoded")
     public Response postUriForm(@Context UriInfo uriInfo, Form formData) throws URISyntaxException
{
+        // TODO replace the Form class with an injected bean?
         System.out.println("Received form! " + formData);
         newUri = formData.getFirst("uri", String.class);
         EndpointResource endpoint = getEndpoint(newUri);

Modified: camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/resources/RouteResource.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/resources/RouteResource.java?rev=748093&r1=748092&r2=748093&view=diff
==============================================================================
--- camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/resources/RouteResource.java
(original)
+++ camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/resources/RouteResource.java
Thu Feb 26 11:27:40 2009
@@ -18,8 +18,11 @@
 
 import java.io.IOException;
 import java.io.StringWriter;
+import java.util.List;
 import javax.ws.rs.GET;
 import javax.ws.rs.Produces;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
 import javax.ws.rs.core.MediaType;
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
@@ -78,4 +81,14 @@
         return generator.getRoutesText(getCamelContext());
     }
 
+
+    /**
+     * Looks up an individual route
+     */
+    @Path("status")
+    public RouteStatusResource getRouteStatus() {
+        return new RouteStatusResource(this);
+    }
+
+
 }

Added: camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/resources/RouteStatusResource.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/resources/RouteStatusResource.java?rev=748093&view=auto
==============================================================================
--- camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/resources/RouteStatusResource.java
(added)
+++ camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/resources/RouteStatusResource.java
Thu Feb 26 11:27:40 2009
@@ -0,0 +1,100 @@
+/**
+ *
+ * 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.camel.web.resources;
+
+import com.sun.jersey.api.representation.Form;
+import org.apache.camel.CamelContext;
+import org.apache.camel.ServiceStatus;
+import org.apache.camel.model.RouteType;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.net.URI;
+
+/**
+ * Represents the status of a single single Camel Route which is used to implement one or
more
+ * <a href="http://camel.apache.org/enterprise-integration-patterns.html">Enterprise
Integration Paterns</a>
+ *
+ * @version $Revision: 1.1 $
+ */
+public class RouteStatusResource {
+    private RouteResource routeResource;
+
+    public RouteStatusResource(RouteResource routeResource) {
+        this.routeResource = routeResource;
+    }
+
+    public RouteType getRoute() {
+        return routeResource.getRoute();
+    }
+
+    public CamelContext getCamelContext() {
+        return routeResource.getCamelContext();
+    }
+
+    @GET
+    @Produces(MediaType.TEXT_PLAIN)
+    public String getStatusText() {
+        ServiceStatus status = getStatus();
+        if (status != null) {
+            return status.toString();
+        }
+        return null;
+    }
+
+    public ServiceStatus getStatus() {
+        return getRoute().getStatus();
+    }
+
+    @POST
+    @Consumes(MediaType.TEXT_PLAIN)
+    public Response setStatus(String status) throws Exception {
+        if (status != null) {
+            if (status.equalsIgnoreCase("start")) {
+                getCamelContext().startRoute(getRoute());
+                return Response.ok().build();
+            } else if (status.equalsIgnoreCase("stop")) {
+                getCamelContext().stopRoute(getRoute());
+                return Response.ok().build();
+            }
+        }
+        return Response.noContent().build();
+    }
+
+
+    /**
+     * Sets the status of this route to either "start" or "stop"
+     *
+     * @param formData is the form data POSTed typically from a HTML form with the <code>status</code>
field
+     *                 set to either "start" or "stop"
+     */
+    @POST
+    @Consumes("application/x-www-form-urlencoded")
+    public Response setStatus(Form formData) throws Exception {
+        // TODO replace the Form class with an injected bean?
+        System.out.println("Received form! " + formData);
+        String status = formData.getFirst("status", String.class);
+        setStatus(status);
+        return Response.seeOther(new URI("/routes")).build();
+    }
+
+}

Propchange: camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/resources/RouteStatusResource.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/resources/RoutesResource.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/resources/RoutesResource.java?rev=748093&r1=748092&r2=748093&view=diff
==============================================================================
--- camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/resources/RoutesResource.java
(original)
+++ camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/resources/RoutesResource.java
Thu Feb 26 11:27:40 2009
@@ -71,7 +71,7 @@
      * Looks up an individual route
      */
     @Path("{id}")
-    public RouteResource getEndpoint(@PathParam("id") String id) {
+    public RouteResource getRoute(@PathParam("id") String id) {
         List<RouteType> list = getRoutes();
         for (RouteType routeType : list) {
             if (routeType.getId().equals(id)) {

Modified: camel/trunk/components/camel-web/src/main/webapp/org/apache/camel/web/resources/RoutesResource/index.jsp
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-web/src/main/webapp/org/apache/camel/web/resources/RoutesResource/index.jsp?rev=748093&r1=748092&r2=748093&view=diff
==============================================================================
--- camel/trunk/components/camel-web/src/main/webapp/org/apache/camel/web/resources/RoutesResource/index.jsp
(original)
+++ camel/trunk/components/camel-web/src/main/webapp/org/apache/camel/web/resources/RoutesResource/index.jsp
Thu Feb 26 11:27:40 2009
@@ -10,7 +10,7 @@
 <table>
   <tr>
     <th>Route</th>
-    <th>Status</th>
+    <th colspan="2">Status</th>
   </tr>
 <ul>
   <c:forEach var="i" items="${it.routes}">
@@ -21,6 +21,18 @@
     <td class="${i.status}">
       ${i.status}
     </td>
+    <td>
+      <form action='<c:url value="/routes/${i.id}/status"/>' method="POST" name="setStatus">
+      <c:if test="${i.startable}">
+        <input type="hidden" name="status" value="start">
+        <input type="submit" value="Start">
+      </c:if>
+      <c:if test="${i.stoppable}">
+        <input type="hidden" name="status" value="stop">
+        <input type="submit" value="Stop">
+      </c:if>
+      </form>
+    </td>
   </c:forEach>
 </ul>
 </table>



Mime
View raw message