svn commit: r734798 - in /activemq/camel/trunk/components/camel-rest/src/main: java/org/apache/camel/rest/model/ java/org/apache/camel/rest/resources/ webapp/WEB-INF/ webapp/org/apache/camel/rest/model/ webapp/org/apache/camel/rest/resources/CamelConte...

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r734798 - in /activemq/camel/trunk/components/camel-rest/src/main: java/org/apache/camel/rest/model/ java/org/apache/camel/rest/resources/ webapp/WEB-INF/ webapp/org/apache/camel/rest/model/ webapp/org/apache/camel/rest/resources/CamelConte...

jstrachan-2
Author: jstrachan
Date: Thu Jan 15 12:22:34 2009
New Revision: 734798

URL: http://svn.apache.org/viewvc?rev=734798&view=rev
Log:
more improvements for CAMEL-888 for both XML and HTML mappings; including simple HTML routes view - still work in progress but slowly getting there

Added:
    activemq/camel/trunk/components/camel-rest/src/main/java/org/apache/camel/rest/resources/ViewableResource.java   (with props)
    activemq/camel/trunk/components/camel-rest/src/main/webapp/org/apache/camel/rest/resources/CamelContextResource/routes.jsp   (with props)
Removed:
    activemq/camel/trunk/components/camel-rest/src/main/webapp/org/apache/camel/rest/model/
Modified:
    activemq/camel/trunk/components/camel-rest/src/main/java/org/apache/camel/rest/model/EndpointLink.java
    activemq/camel/trunk/components/camel-rest/src/main/java/org/apache/camel/rest/resources/CamelContextResource.java
    activemq/camel/trunk/components/camel-rest/src/main/java/org/apache/camel/rest/resources/EndpointResource.java
    activemq/camel/trunk/components/camel-rest/src/main/webapp/WEB-INF/web.xml

Modified: activemq/camel/trunk/components/camel-rest/src/main/java/org/apache/camel/rest/model/EndpointLink.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-rest/src/main/java/org/apache/camel/rest/model/EndpointLink.java?rev=734798&r1=734797&r2=734798&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-rest/src/main/java/org/apache/camel/rest/model/EndpointLink.java (original)
+++ activemq/camel/trunk/components/camel-rest/src/main/java/org/apache/camel/rest/model/EndpointLink.java Thu Jan 15 12:22:34 2009
@@ -70,6 +70,6 @@
 
     protected String createHref(String uri) {
         // TODO how to encode as a href?
-        return "/endpoints/" + uri;
+        return "/endpoint/" + uri;
     }
 }

Modified: activemq/camel/trunk/components/camel-rest/src/main/java/org/apache/camel/rest/resources/CamelContextResource.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-rest/src/main/java/org/apache/camel/rest/resources/CamelContextResource.java?rev=734798&r1=734797&r2=734798&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-rest/src/main/java/org/apache/camel/rest/resources/CamelContextResource.java (original)
+++ activemq/camel/trunk/components/camel-rest/src/main/java/org/apache/camel/rest/resources/CamelContextResource.java Thu Jan 15 12:22:34 2009
@@ -17,9 +17,9 @@
 package org.apache.camel.rest.resources;
 
 
+import com.sun.jersey.api.view.Viewable;
 import com.sun.jersey.spi.inject.Inject;
 import com.sun.jersey.spi.resource.Singleton;
-import com.sun.jersey.api.view.Viewable;
 import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
 import org.apache.camel.model.RouteType;
@@ -34,7 +34,7 @@
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;
 import java.util.List;
-//import static org.apache.camel.rest.resources.Constants.*;
+
 
 /**
  * The resource for the CamelContext
@@ -43,7 +43,7 @@
  */
 @Path("/")
 @Singleton
-public class CamelContextResource {
+public class CamelContextResource extends ViewableResource {
 
     private final CamelContext camelContext;
 
@@ -59,16 +59,51 @@
         return camelContext.getName();
     }
 
+
+
+    // HTML representations
+    //-------------------------------------------------------------------------
+
+    // Its a shame there's not an easier way to bind the explicit views...
+    //-------------------------------------------------------------------------
+
+
+    @GET
+    @Path("endpoints")
+    @Produces({MediaType.TEXT_HTML})
+    public Viewable endpoints() {
+        return view("endpoints");
+    }
+
+    @GET
+    @Path("foo")
+    @Produces({MediaType.TEXT_HTML})
+    public Viewable foo() {
+        return view("foo");
+    }
+
+/*
     @GET
     @Path("{view}")
     @Produces({MediaType.TEXT_HTML})
-    public Viewable get(@PathParam("view") String view) {
-        if (view == null || view.length() == 0) {
-            view = "index";
-        }
-        return new Viewable(view, this);
+    public Viewable genericView(@PathParam("view") String view) {
+        return view(view);
     }
 
+*/
+
+    @GET
+    @Path("routes")
+    @Produces({MediaType.TEXT_HTML})
+    public Viewable routesView() {
+        return view("routes");
+    }
+
+
+    // XML / JSON representations
+    //-------------------------------------------------------------------------
+
+
     @GET
     @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
     public Camel getCamel() {
@@ -104,7 +139,6 @@
     /**
      * Looks up an individual endpoint
      */
-    @GET
     @Path("endpoint/{id}")
     public EndpointResource getEndpoint(@PathParam("id") String id) {
         // TODO lets assume the ID is the endpoint
@@ -123,6 +157,7 @@
      */
     @GET
     @Path("routes")
+    @Produces({"application/xml", "application/json"})
     public RoutesType getRouteDefinitions() {
         RoutesType answer = new RoutesType();
         if (camelContext != null) {
@@ -132,4 +167,12 @@
         return answer;
     }
 
+    // Properties
+    //-------------------------------------------------------------------------
+    public List<RouteType> getRoutes() {
+        return getRouteDefinitions().getRoutes();
+    }
+
+
+
 }

Modified: activemq/camel/trunk/components/camel-rest/src/main/java/org/apache/camel/rest/resources/EndpointResource.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-rest/src/main/java/org/apache/camel/rest/resources/EndpointResource.java?rev=734798&r1=734797&r2=734798&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-rest/src/main/java/org/apache/camel/rest/resources/EndpointResource.java (original)
+++ activemq/camel/trunk/components/camel-rest/src/main/java/org/apache/camel/rest/resources/EndpointResource.java Thu Jan 15 12:22:34 2009
@@ -22,7 +22,7 @@
 /**
  * @version $Revision$
  */
-public class EndpointResource {
+public class EndpointResource extends ViewableResource {
 
     private final Endpoint endpoint;
 
@@ -33,7 +33,8 @@
     public String getHref() {
         return new EndpointLink(endpoint).getHref();
     }
+
     public String getUri() {
-        return  endpoint.getEndpointUri();
+        return endpoint.getEndpointUri();
     }
 }

Added: activemq/camel/trunk/components/camel-rest/src/main/java/org/apache/camel/rest/resources/ViewableResource.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-rest/src/main/java/org/apache/camel/rest/resources/ViewableResource.java?rev=734798&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-rest/src/main/java/org/apache/camel/rest/resources/ViewableResource.java (added)
+++ activemq/camel/trunk/components/camel-rest/src/main/java/org/apache/camel/rest/resources/ViewableResource.java Thu Jan 15 12:22:34 2009
@@ -0,0 +1,46 @@
+/**
+ *
+ * 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.rest.resources;
+
+import com.sun.jersey.api.view.Viewable;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+/**
+ * A base class for any resource which is viewable in HTML
+ *
+ * @version $Revision: 1.1 $
+ */
+@Produces({MediaType.TEXT_HTML})
+public abstract class ViewableResource {
+
+    @GET
+    @Produces({MediaType.TEXT_HTML})
+    public Viewable index() {
+        return view("index");
+    }
+
+    protected Viewable view(String view) {
+        if (view == null || view.length() == 0) {
+            view = "index";
+        }
+        return new Viewable(view, this);
+    }
+}

Propchange: activemq/camel/trunk/components/camel-rest/src/main/java/org/apache/camel/rest/resources/ViewableResource.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/camel/trunk/components/camel-rest/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-rest/src/main/webapp/WEB-INF/web.xml?rev=734798&r1=734797&r2=734798&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-rest/src/main/webapp/WEB-INF/web.xml (original)
+++ activemq/camel/trunk/components/camel-rest/src/main/webapp/WEB-INF/web.xml Thu Jan 15 12:22:34 2009
@@ -78,6 +78,7 @@
       <param-name>com.sun.jersey.config.feature.ImplicitViewables</param-name>
       <param-value>true</param-value>
     </init-param>
+    <load-on-startup>1</load-on-startup>
   </servlet>
   <servlet-mapping>
     <servlet-name>Jersey Spring</servlet-name>

Added: activemq/camel/trunk/components/camel-rest/src/main/webapp/org/apache/camel/rest/resources/CamelContextResource/routes.jsp
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-rest/src/main/webapp/org/apache/camel/rest/resources/CamelContextResource/routes.jsp?rev=734798&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-rest/src/main/webapp/org/apache/camel/rest/resources/CamelContextResource/routes.jsp (added)
+++ activemq/camel/trunk/components/camel-rest/src/main/webapp/org/apache/camel/rest/resources/CamelContextResource/routes.jsp Thu Jan 15 12:22:34 2009
@@ -0,0 +1,18 @@
+<html>
+<head>
+  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+  <title>Routes</title>
+</head>
+<body>
+
+<h2>Routes</h2>
+
+
+<ul>
+  <c:forEach var="i" items="${it.routes}">
+    <li><a href="${i.id}">${i.shortName}</a> ${i.description}
+  </c:forEach>
+</ul>
+
+</body>
+</html>

Propchange: activemq/camel/trunk/components/camel-rest/src/main/webapp/org/apache/camel/rest/resources/CamelContextResource/routes.jsp
------------------------------------------------------------------------------
    svn:eol-style = native