You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2012/03/27 22:12:52 UTC
svn commit: r1306002 - in
/activemq/activemq-apollo/trunk/apollo-web/src/main:
scala/org/apache/activemq/apollo/web/
scala/org/apache/activemq/apollo/web/resources/ webapp/WEB-INF/
Author: chirino
Date: Tue Mar 27 20:12:52 2012
New Revision: 1306002
URL: http://svn.apache.org/viewvc?rev=1306002&view=rev
Log:
Improve how your extends the webadmin interface with JAXRS. We now use a servlet filter to reliably serve up static resources. And then simplify the web.xml configuration.
Added:
activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/JerseyServlet.scala
activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/StaticContentFilter.scala
Modified:
activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/WebModule.scala
activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/BrokerResource.scala
activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/ConfigurationResource.scala
activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/RootResource.scala
activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/Support.scala
activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/WEB-INF/web.xml
Added: activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/JerseyServlet.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/JerseyServlet.scala?rev=1306002&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/JerseyServlet.scala (added)
+++ activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/JerseyServlet.scala Tue Mar 27 20:12:52 2012
@@ -0,0 +1,77 @@
+/**
+ * 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.activemq.apollo.web
+
+import com.sun.jersey.spi.container.servlet.ServletContainer
+import javax.servlet.ServletConfig
+import javax.servlet.ServletContext
+import java.util.Enumeration
+import collection.mutable.HashMap
+// import com.wordnik.swagger.jaxrs.JaxrsApiReader
+
+/**
+ * <p>
+ * </p>
+ *
+ * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
+ */
+class JerseyServlet extends ServletContainer {
+
+ var original_config: ServletConfig = _
+ var custom_config_map = HashMap[String, String]()
+ val custom_config: ServletConfig = new ServletConfig {
+
+ def getServletName: String = {
+ return original_config.getServletName
+ }
+
+ def getServletContext: ServletContext = {
+ return original_config.getServletContext
+ }
+
+ def getInitParameterNames: Enumeration[_] = {
+ import collection.JavaConversions._
+ return new java.util.Vector(custom_config_map.keys).elements();
+ }
+
+ def getInitParameter(s: String): String = {
+ return custom_config_map.get(s).getOrElse(null)
+ }
+
+ }
+
+ override def init(config: ServletConfig): Unit = {
+ // JaxrsApiReader.setFormatString("")
+
+ original_config = config
+ custom_config_map.put("com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.ClassNamesResourceConfig")
+ custom_config_map.put("com.sun.jersey.config.property.classnames", WebModule.web_resources.map(_.getName).mkString(" "))
+ // custom_config_map.put("com.sun.jersey.config.feature.Trace", System.getProperty("com.sun.jersey.config.feature.Trace", "true"))
+ custom_config_map.put("com.sun.jersey.spi.container.ContainerRequestFilters", "com.sun.jersey.api.container.filter.PostReplaceFilter")
+ custom_config_map.put("com.sun.jersey.config.feature.Redirect", "true")
+ custom_config_map.put("com.sun.jersey.config.feature.FilterForwardOn404", "true")
+ custom_config_map.put("com.sun.jersey.config.feature.ImplicitViewables", "true")
+ custom_config_map.put("com.sun.jersey.config.property.MediaTypeMappings", """
+ html : text/html,
+ xml : application/xml,
+ json : application/json
+ """)
+
+ super.init(custom_config)
+ }
+
+}
\ No newline at end of file
Added: activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/StaticContentFilter.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/StaticContentFilter.scala?rev=1306002&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/StaticContentFilter.scala (added)
+++ activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/StaticContentFilter.scala Tue Mar 27 20:12:52 2012
@@ -0,0 +1,70 @@
+package org.apache.activemq.apollo.web
+
+import javax.servlet._
+import http.{HttpServletResponse, HttpServletRequest}
+import org.eclipse.jetty.servlet.DefaultServlet
+import org.eclipse.jetty.server.Dispatcher
+import org.eclipse.jetty.util.URIUtil
+
+
+/**
+ * <p>
+ * </p>
+ *
+ * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
+ */
+class StaticContentFilter extends Filter {
+
+ val static_content_servlet = new DefaultServlet
+
+ def init(config: FilterConfig) {
+ static_content_servlet.init(new ServletConfig {
+ def getServletName = "default"
+ def getServletContext = config.getServletContext
+ def getInitParameterNames = new java.util.Vector().elements()
+ def getInitParameter(p1: String) = null
+ })
+ }
+
+ def destroy() {
+ static_content_servlet.destroy()
+ }
+
+ def doFilter(req: ServletRequest, res: ServletResponse, chain: FilterChain) = {
+ req match {
+ case req: HttpServletRequest =>
+ res match {
+ case res: HttpServletResponse =>
+ if (static_content_exists(req)) {
+ static_content_servlet.service(req, res)
+ } else {
+ chain.doFilter(req, res)
+ }
+ case _ => chain.doFilter(req, res)
+ }
+ case _ => chain.doFilter(req, res)
+ }
+ }
+
+ def static_content_exists(request: HttpServletRequest) = {
+
+ var servletPath: String = null;
+ var pathInfo: String = null;
+
+ if (request.getAttribute(Dispatcher.INCLUDE_REQUEST_URI) != null) {
+ servletPath = request.getAttribute(Dispatcher.INCLUDE_SERVLET_PATH).asInstanceOf[String]
+ pathInfo = request.getAttribute(Dispatcher.INCLUDE_PATH_INFO).asInstanceOf[String]
+ if (servletPath == null) {
+ servletPath = request.getServletPath();
+ pathInfo = request.getPathInfo();
+ }
+ } else {
+ servletPath = request.getServletPath() // or we could do "/"
+ pathInfo = request.getPathInfo();
+ }
+
+ val resourcePath = URIUtil.addPaths(servletPath, pathInfo);
+ val resource = static_content_servlet.getResource(resourcePath)
+ resource!=null && resource.exists() && !resource.isDirectory
+ }
+}
Modified: activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/WebModule.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/WebModule.scala?rev=1306002&r1=1306001&r2=1306002&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/WebModule.scala (original)
+++ activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/WebModule.scala Tue Mar 27 20:12:52 2012
@@ -17,12 +17,15 @@
package org.apache.activemq.apollo.web
import org.apache.activemq.apollo.util.ClassFinder
-import resources.BrokerResource
import collection.immutable.TreeMap
+import collection.mutable.LinkedHashMap
+import resources._
+import org.fusesource.scalate.jersey._
+//import com.wordnik.swagger.jaxrs.ApiHelpMessageBodyWriter
trait WebModule {
def priority:Int
- def web_resources: Map[String, ()=>AnyRef]
+ def web_resources: Set[Class[_]]
def root_redirect:String
}
@@ -37,24 +40,47 @@ object WebModule {
val finder = new ClassFinder[WebModule]("META-INF/services/org.apache.activemq.apollo/web-module.index",classOf[WebModule])
val (root_redirect, web_resources) = {
-
// sort by priority. Highest priority wins.
val sorted = TreeMap(finder.singletons.map(x=> x.priority -> x): _*).values
- val web_resources = sorted.foldLeft(Map[String, ()=>AnyRef]()) { case (map, provider) =>
- map ++ provider.web_resources
+ val web_resources = LinkedHashMap[Class[_], Class[_]]()
+ for( provider <- sorted; resource <- provider.web_resources ) {
+ web_resources.put(resource,resource)
}
- (sorted.last.root_redirect, web_resources)
+ (sorted.last.root_redirect, web_resources.keySet)
}
-
}
object DefaultWebModule extends WebModule {
def priority: Int = 100
- def create_broker_resource() = new BrokerResource
- override def web_resources = Map("broker" -> create_broker_resource _ )
+ override def web_resources = Set(
+ classOf[RootResource],
+
+// classOf[ApolloApiListing],
+// classOf[ApiHelpMessageBodyWriter],
+
+ classOf[BrokerResource],
+// classOf[BrokerResourceHTML],
+// classOf[BrokerResourceJSON],
+// classOf[BrokerResourceHelp],
+
+// classOf[SessionResourceHTML],
+// classOf[SessionResourceJSON],
+// classOf[SessionResourceHelp],
+
+ classOf[ConfigurationResource],
+// classOf[ConfigurationResourceHTML],
+// classOf[ConfigurationResourceJSON],
+// classOf[ConfigurationResourceHelp],
+
+ classOf[JacksonJsonProvider],
+ classOf[JaxrsExceptionMapper],
+ classOf[ScalateTemplateProvider],
+ classOf[ScalateTemplateProcessor]
+
+ )
def root_redirect: String = "broker"
Modified: activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/BrokerResource.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/BrokerResource.scala?rev=1306002&r1=1306001&r2=1306002&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/BrokerResource.scala (original)
+++ activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/BrokerResource.scala Tue Mar 27 20:12:52 2012
@@ -46,8 +46,9 @@ import security.SecurityContext
*
* @author <a href="http://hiramchirino.com">Hiram Chirino</a>
*/
+@Path("/broker")
@Produces(Array(APPLICATION_JSON, APPLICATION_XML, TEXT_XML, "text/html;qs=5"))
-case class BrokerResource() extends Resource {
+class BrokerResource() extends Resource {
import Resource._
@GET
@@ -134,16 +135,6 @@ case class BrokerResource() extends Reso
""
}
- @Path("config")
- def config_resource:ConfigurationResource = {
- with_broker { broker =>
- configing(broker) {
- ConfigurationResource(this, broker.config)
- }
- }
- }
-
-
@GET
def get_broker():BrokerStatusDTO = {
with_broker { broker =>
@@ -237,7 +228,7 @@ case class BrokerResource() extends Reso
}
@GET
- @Path("queue-metrics")
+ @Path("/queue-metrics")
def get_queue_metrics(): AggregateDestMetricsDTO = {
val rc:AggregateDestMetricsDTO = with_broker { broker =>
monitoring(broker) {
@@ -249,7 +240,7 @@ case class BrokerResource() extends Reso
}
@GET
- @Path("topic-metrics")
+ @Path("/topic-metrics")
def get_topic_metrics(): AggregateDestMetricsDTO = {
val rc:AggregateDestMetricsDTO = with_broker { broker =>
monitoring(broker) {
@@ -261,7 +252,7 @@ case class BrokerResource() extends Reso
}
@GET
- @Path("dsub-metrics")
+ @Path("/dsub-metrics")
def get_dsub_metrics(): AggregateDestMetricsDTO = {
val rc:AggregateDestMetricsDTO = with_broker { broker =>
monitoring(broker) {
@@ -286,7 +277,7 @@ case class BrokerResource() extends Reso
}
@GET
- @Path("dest-metrics")
+ @Path("/dest-metrics")
def get_dest_metrics(): AggregateDestMetricsDTO = {
aggregate(get_queue_metrics(), get_topic_metrics(), get_dsub_metrics())
}
@@ -331,7 +322,7 @@ case class BrokerResource() extends Reso
def get_dsub_metrics(host:VirtualHost):FutureResult[AggregateDestMetricsDTO] = host.get_dsub_metrics
- @GET @Path("virtual-hosts")
+ @GET @Path("/virtual-hosts")
@Produces(Array(APPLICATION_JSON))
def virtual_host(@QueryParam("f") f:java.util.List[String], @QueryParam("q") q:String,
@QueryParam("p") p:java.lang.Integer, @QueryParam("ps") ps:java.lang.Integer, @QueryParam("o") o:java.util.List[String] ):DataPageDTO = {
@@ -346,7 +337,7 @@ case class BrokerResource() extends Reso
}
}
- @GET @Path("virtual-hosts/{id}")
+ @GET @Path("/virtual-hosts/{id}")
def virtual_host(@PathParam("id") id : String):VirtualHostStatusDTO = {
with_virtual_host(id) { host =>
monitoring(host) {
@@ -378,7 +369,7 @@ case class BrokerResource() extends Reso
result
}
- @GET @Path("virtual-hosts/{id}/queue-metrics")
+ @GET @Path("/virtual-hosts/{id}/queue-metrics")
def virtual_host_queue_metrics(@PathParam("id") id : String): AggregateDestMetricsDTO = {
val rc:AggregateDestMetricsDTO = with_virtual_host(id) { host =>
monitoring(host) {
@@ -389,7 +380,7 @@ case class BrokerResource() extends Reso
rc
}
- @GET @Path("virtual-hosts/{id}/topic-metrics")
+ @GET @Path("/virtual-hosts/{id}/topic-metrics")
def virtual_host_topic_metrics(@PathParam("id") id : String): AggregateDestMetricsDTO = {
val rc:AggregateDestMetricsDTO = with_virtual_host(id) { host =>
monitoring(host) {
@@ -400,7 +391,7 @@ case class BrokerResource() extends Reso
rc
}
- @GET @Path("virtual-hosts/{id}/dsub-metrics")
+ @GET @Path("/virtual-hosts/{id}/dsub-metrics")
def virtual_host_dsub_metrics(@PathParam("id") id : String): AggregateDestMetricsDTO = {
val rc:AggregateDestMetricsDTO = with_virtual_host(id) { host =>
monitoring(host) {
@@ -411,13 +402,13 @@ case class BrokerResource() extends Reso
rc
}
- @GET @Path("virtual-hosts/{id}/dest-metrics")
+ @GET @Path("/virtual-hosts/{id}/dest-metrics")
def virtual_host_dest_metrics(@PathParam("id") id : String): AggregateDestMetricsDTO = {
aggregate(virtual_host_queue_metrics(id), virtual_host_topic_metrics(id), virtual_host_dsub_metrics(id))
}
- @GET @Path("virtual-hosts/{id}/store")
+ @GET @Path("/virtual-hosts/{id}/store")
def store(@PathParam("id") id : String):StoreStatusDTO = {
with_virtual_host(id) { host =>
monitoring(host) {
@@ -509,7 +500,8 @@ case class BrokerResource() extends Reso
}
}
- @GET @Path("virtual-hosts/{id}/topics")
+ @GET @Path("/virtual-hosts/{id}/topics")
+// @ApiOperation(value = "Gets a list of all the topics that exist on the broker.")
@Produces(Array(APPLICATION_JSON))
def topics(@PathParam("id") id : String, @QueryParam("f") f:java.util.List[String],
@QueryParam("q") q:String, @QueryParam("p") p:java.lang.Integer, @QueryParam("ps") ps:java.lang.Integer, @QueryParam("o") o:java.util.List[String] ):DataPageDTO = {
@@ -527,7 +519,7 @@ case class BrokerResource() extends Reso
}
}
- @GET @Path("virtual-hosts/{id}/topics/{name:.*}")
+ @GET @Path("/virtual-hosts/{id}/topics/{name:.*}")
def topic(@PathParam("id") id : String, @PathParam("name") name : String):TopicStatusDTO = {
with_virtual_host(id) { host =>
val router:LocalRouter = host
@@ -538,7 +530,7 @@ case class BrokerResource() extends Reso
}
}
- @GET @Path("virtual-hosts/{id}/topic-queues/{name:.*}/{qid}")
+ @GET @Path("/virtual-hosts/{id}/topic-queues/{name:.*}/{qid}")
def topic(@PathParam("id") id : String,@PathParam("name") name : String, @PathParam("qid") qid : Long, @QueryParam("entries") entries:Boolean):QueueStatusDTO = {
with_virtual_host(id) { host =>
val router:LocalRouter = host
@@ -552,7 +544,7 @@ case class BrokerResource() extends Reso
}
}
- @GET @Path("virtual-hosts/{id}/queues")
+ @GET @Path("/virtual-hosts/{id}/queues")
@Produces(Array(APPLICATION_JSON))
def queues(@PathParam("id") id : String, @QueryParam("f") f:java.util.List[String],
@QueryParam("q") q:String, @QueryParam("p") p:java.lang.Integer, @QueryParam("ps") ps:java.lang.Integer, @QueryParam("o") o:java.util.List[String] ):DataPageDTO = {
@@ -569,7 +561,7 @@ case class BrokerResource() extends Reso
}
}
- @GET @Path("virtual-hosts/{id}/queues/{name:.*}")
+ @GET @Path("/virtual-hosts/{id}/queues/{name:.*}")
def queue(@PathParam("id") id : String, @PathParam("name") name : String, @QueryParam("entries") entries:Boolean ):QueueStatusDTO = {
with_virtual_host(id) { host =>
val router: LocalRouter = host
@@ -580,7 +572,7 @@ case class BrokerResource() extends Reso
}
}
- @DELETE @Path("virtual-hosts/{id}/queues/{name:.*}")
+ @DELETE @Path("/virtual-hosts/{id}/queues/{name:.*}")
@Produces(Array(APPLICATION_JSON, APPLICATION_XML,TEXT_XML))
def queue_delete(@PathParam("id") id : String, @PathParam("name") name : String):Unit = unwrap_future_result {
with_virtual_host(id) { host =>
@@ -592,14 +584,14 @@ case class BrokerResource() extends Reso
}
}
- @POST @Path("virtual-hosts/{id}/queues/{name:.*}/action/delete")
+ @POST @Path("/virtual-hosts/{id}/queues/{name:.*}/action/delete")
@Produces(Array("text/html;qs=5"))
def post_queue_delete_and_redirect(@PathParam("id") id : String, @PathParam("name") name : String):Unit = unwrap_future_result {
queue_delete(id, name)
result(strip_resolve("../../.."))
}
- @GET @Path("virtual-hosts/{id}/dsubs")
+ @GET @Path("/virtual-hosts/{id}/dsubs")
@Produces(Array(APPLICATION_JSON))
def durable_subscriptions(@PathParam("id") id : String, @QueryParam("f") f:java.util.List[String],
@QueryParam("q") q:String, @QueryParam("p") p:java.lang.Integer, @QueryParam("ps") ps:java.lang.Integer, @QueryParam("o") o:java.util.List[String] ):DataPageDTO = {
@@ -615,7 +607,8 @@ case class BrokerResource() extends Reso
rc
}
}
- @GET @Path("virtual-hosts/{id}/dsubs/{name:.*}")
+
+ @GET @Path("/virtual-hosts/{id}/dsubs/{name:.*}")
def durable_subscription(@PathParam("id") id : String, @PathParam("name") name : String, @QueryParam("entries") entries:Boolean):QueueStatusDTO = {
with_virtual_host(id) { host =>
val router:LocalRouter = host
@@ -627,7 +620,7 @@ case class BrokerResource() extends Reso
}
- @DELETE @Path("virtual-hosts/{id}/dsubs/{name:.*}")
+ @DELETE @Path("/virtual-hosts/{id}/dsubs/{name:.*}")
@Produces(Array(APPLICATION_JSON, APPLICATION_XML,TEXT_XML))
def dsub_delete(@PathParam("id") id : String, @PathParam("name") name : String):Unit = unwrap_future_result {
with_virtual_host(id) { host =>
@@ -639,7 +632,7 @@ case class BrokerResource() extends Reso
}
}
- @POST @Path("virtual-hosts/{id}/dsubs/{name:.*}/action/delete")
+ @POST @Path("/virtual-hosts/{id}/dsubs/{name:.*}/action/delete")
@Produces(Array("text/html;qs=5"))
def post_dsub_delete_and_redirect(@PathParam("id") id : String, @PathParam("name") name : String):Unit = unwrap_future_result {
dsub_delete(id, name)
@@ -659,7 +652,7 @@ case class BrokerResource() extends Reso
q.status(entries)
}
- @GET @Path("connectors")
+ @GET @Path("/connectors")
@Produces(Array(APPLICATION_JSON))
def connectors(@QueryParam("f") f:java.util.List[String], @QueryParam("q") q:String,
@QueryParam("p") p:java.lang.Integer, @QueryParam("ps") ps:java.lang.Integer, @QueryParam("o") o:java.util.List[String] ):DataPageDTO = {
@@ -674,7 +667,7 @@ case class BrokerResource() extends Reso
}
}
- @GET @Path("connectors/{id}")
+ @GET @Path("/connectors/{id}")
def connector(@PathParam("id") id : String):ServiceStatusDTO = {
with_connector(id) { connector =>
monitoring(connector.broker) {
@@ -683,7 +676,7 @@ case class BrokerResource() extends Reso
}
}
- @POST @Path("connectors/{id}/action/stop")
+ @POST @Path("/connectors/{id}/action/stop")
def post_connector_stop(@PathParam("id") id : String):Unit = unwrap_future_result {
with_connector(id) { connector =>
admining(connector.broker) {
@@ -693,7 +686,7 @@ case class BrokerResource() extends Reso
result(strip_resolve(".."))
}
- @POST @Path("connectors/{id}/action/start")
+ @POST @Path("/connectors/{id}/action/start")
def post_connector_start(@PathParam("id") id : String):Unit = unwrap_future_result {
with_connector(id) { connector =>
admining(connector.broker) {
@@ -704,7 +697,7 @@ case class BrokerResource() extends Reso
}
@GET
- @Path("connection-metrics")
+ @Path("/connection-metrics")
def get_connection_metrics(): AggregateConnectionMetricsDTO = {
val f = new ArrayList[String]()
f.add("read_counter")
@@ -730,7 +723,7 @@ case class BrokerResource() extends Reso
}
- @GET @Path("connections")
+ @GET @Path("/connections")
@Produces(Array(APPLICATION_JSON))
def connections(@QueryParam("f") f:java.util.List[String], @QueryParam("q") q:String,
@QueryParam("p") p:java.lang.Integer, @QueryParam("ps") ps:java.lang.Integer, @QueryParam("o") o:java.util.List[String] ):DataPageDTO = {
@@ -748,7 +741,7 @@ case class BrokerResource() extends Reso
}
}
- @GET @Path("connections/{id}")
+ @GET @Path("/connections/{id}")
def connection(@PathParam("id") id : Long):ConnectionStatusDTO = {
with_connection(id){ connection=>
monitoring(connection.connector.broker) {
@@ -757,7 +750,7 @@ case class BrokerResource() extends Reso
}
}
- @DELETE @Path("connections/{id}")
+ @DELETE @Path("/connections/{id}")
@Produces(Array(APPLICATION_JSON, APPLICATION_XML,TEXT_XML))
def connection_delete(@PathParam("id") id : Long):Unit = unwrap_future_result {
with_connection(id){ connection=>
@@ -768,7 +761,7 @@ case class BrokerResource() extends Reso
}
- @POST @Path("connections/{id}/action/delete")
+ @POST @Path("/connections/{id}/action/delete")
@Produces(Array("text/html;qs=5"))
def post_connection_delete_and_redirect(@PathParam("id") id : Long):Unit = unwrap_future_result {
connection_delete(id)
@@ -776,7 +769,7 @@ case class BrokerResource() extends Reso
}
@POST
- @Path("action/shutdown")
+ @Path("/action/shutdown")
def command_shutdown:Unit = unwrap_future_result {
info("JVM shutdown requested via web interface")
with_broker { broker =>
Modified: activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/ConfigurationResource.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/ConfigurationResource.scala?rev=1306002&r1=1306001&r2=1306002&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/ConfigurationResource.scala (original)
+++ activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/ConfigurationResource.scala Tue Mar 27 20:12:52 2012
@@ -30,7 +30,9 @@ case class ListConfigs(files:Array[Strin
/**
* A broker resource is used to represent the configuration of a broker.
*/
-case class ConfigurationResource(parent:BrokerResource, dto:BrokerDTO) extends Resource(parent) {
+@Path("/broker/config")
+@Produces(Array(APPLICATION_JSON, APPLICATION_XML, TEXT_XML, "text/html;qs=5"))
+class ConfigurationResource extends Resource {
lazy val etc_directory = {
val apollo_base = Option(System.getProperty("apollo.base")).getOrElse(result(NOT_FOUND))
@@ -41,6 +43,13 @@ case class ConfigurationResource(parent:
rc
}
+
+ lazy val dto:BrokerDTO = with_broker { broker =>
+ configing(broker) {
+ broker.config
+ }
+ }
+
@GET
@Path("runtime")
@Produces(Array(APPLICATION_JSON, APPLICATION_XML, TEXT_XML))
@@ -62,8 +71,8 @@ case class ConfigurationResource(parent:
}
@GET
+ @Path("/files")
@Produces(Array(APPLICATION_JSON))
- @Path("files")
def list() = {
etc_directory.listFiles().flatMap { file =>
if( file.canRead ) {
@@ -76,14 +85,14 @@ case class ConfigurationResource(parent:
@GET
@Produces(Array(TEXT_HTML))
- @Path("files")
+ @Path("/files")
def list_html() = {
ListConfigs(list())
}
@GET
@Produces(Array(APPLICATION_OCTET_STREAM))
- @Path("files/{name}")
+ @Path("/files/{name}")
def get(@PathParam("name") name:String) = {
val file = etc_directory / name
if( !file.exists() || !file.canRead || file.getParentFile != etc_directory ) {
@@ -94,7 +103,7 @@ case class ConfigurationResource(parent:
@GET
@Produces(Array(TEXT_HTML))
- @Path("files/{name}")
+ @Path("/files/{name}")
def edit_html(@PathParam("name") name:String) = {
val file = etc_directory / name
if( !file.exists() || !file.canRead || file.getParentFile != etc_directory ) {
@@ -105,7 +114,7 @@ case class ConfigurationResource(parent:
@POST
@Consumes(Array(WILDCARD))
- @Path("files/{name}")
+ @Path("/files/{name}")
def put(@PathParam("name") name:String, config:Array[Byte]):Unit = {
val file = etc_directory / name
if( !file.exists() || !file.canWrite || file.getParentFile != etc_directory ) {
@@ -116,7 +125,7 @@ case class ConfigurationResource(parent:
}
@POST
- @Path("files/{name}")
+ @Path("/files/{name}")
@Consumes(Array(APPLICATION_FORM_URLENCODED))
@Produces(Array(APPLICATION_JSON, APPLICATION_XML,TEXT_XML, TEXT_HTML))
def edit_post(@PathParam("name") name:String, @FormParam("config") config:String):Unit = {
Modified: activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/RootResource.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/RootResource.scala?rev=1306002&r1=1306001&r2=1306002&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/RootResource.scala (original)
+++ activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/RootResource.scala Tue Mar 27 20:12:52 2012
@@ -17,10 +17,7 @@
package org.apache.activemq.apollo.web.resources
import javax.ws.rs._
-import core.Response.Status._
import core.Response
-import javax.servlet.http.HttpServletRequest
-import com.sun.jersey.server.impl.ThreadLocalInvoker
import org.apache.activemq.apollo.web.WebModule
import javax.ws.rs.core.MediaType._
@@ -38,28 +35,4 @@ case class RootResource() extends Resour
Response.seeOther(strip_resolve(root_redirect)).build
}
- @Path("{name}")
- def path(@PathParam("name") name:String):AnyRef = {
-
- // Jersey's thread local wrapping messes /w us since we may use the http_request
- // in a different thread. Lets try to unwrap it..
- try {
- val invoker = java.lang.reflect.Proxy.getInvocationHandler(http_request).asInstanceOf[ThreadLocalInvoker[HttpServletRequest]]
- http_request = invoker.get()
- } catch {
- case e:Throwable => e.printStackTrace()
- }
-
- web_resources.get(name).map{func =>
- val resource = func()
- resource match {
- case resource:Resource=>
- // Wishing jersey would just re-inject the sub resources
- resource.copy(this)
- case _ =>
- }
- resource
- }.getOrElse(result(NOT_FOUND))
- }
-
}
Modified: activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/Support.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/Support.scala?rev=1306002&r1=1306001&r2=1306002&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/Support.scala (original)
+++ activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/Support.scala Tue Mar 27 20:12:52 2012
@@ -18,8 +18,8 @@ package org.apache.activemq.apollo.web.r
import java.lang.String
import javax.ws.rs._
-import core.{UriInfo, Response, Context}
import com.sun.jersey.api.view.ImplicitProduces
+import core.{HttpHeaders, UriInfo, Response, Context}
import Response._
import Response.Status._
import java.util.concurrent.TimeUnit
@@ -34,6 +34,13 @@ import java.net.{InetSocketAddress, URI}
import java.security.cert.X509Certificate
import org.apache.activemq.apollo.dto.ErrorDTO
import org.fusesource.hawtdispatch._
+import javax.servlet.ServletConfig
+import com.sun.jersey.server.impl.ThreadLocalInvoker
+import com.sun.jersey.spi.resource.Singleton
+import com.sun.jersey.api.view.ImplicitProduces
+import com.sun.jersey.api.core.ResourceConfig
+// import com.wordnik.swagger.jaxrs.{Help, ApiListing}
+// import com.wordnik.swagger.core.{Documentation, ApiOperation, Api}
object Resource extends Log {
@@ -42,6 +49,8 @@ object Resource extends Log {
val HEADER_AUTHORIZATION: String = "Authorization"
val AUTHENTICATION_SCHEME_BASIC: String = "Basic"
+ val x:ServletConfig = null
+
private def decode_base64(value: String): String = {
var transformed: Array[Byte] = Base64.decode(value)
try {
@@ -58,16 +67,27 @@ object Resource extends Log {
/**
* Defines the default representations to be used on resources
*/
-@ImplicitProduces(Array("text/html;qs=5"))
-@Produces(Array("application/json", "application/xml","text/xml"))
abstract class Resource(parent:Resource=null) {
import Resource._
@Context
var uri_info:UriInfo = null
- @Context
+
var http_request: HttpServletRequest = null
+ @Context
+ def setHttpRequest(value:HttpServletRequest) {
+ // Jersey's thread local wrapping messes /w us since we use the http_request
+ // in a different threads. Lets try to unwrap it..
+ try {
+ http_request = java.lang.reflect.Proxy.getInvocationHandler(value).asInstanceOf[ThreadLocalInvoker[HttpServletRequest]].get()
+ } catch {
+ case e:Throwable =>
+ http_request = value
+ }
+ }
+
+
if( parent!=null ) {
copy(parent)
}
@@ -437,4 +457,3 @@ class ViewHelper {
friendly_duration(System.currentTimeMillis - value)
}
}
-
Modified: activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/WEB-INF/web.xml?rev=1306002&r1=1306001&r2=1306002&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/WEB-INF/web.xml (original)
+++ activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/WEB-INF/web.xml Tue Mar 27 20:12:52 2012
@@ -30,47 +30,12 @@
</description>
<filter>
- <filter-name>Jersey Filter</filter-name>
- <filter-class>com.sun.jersey.spi.container.servlet.ServletContainer</filter-class>
- <!-- <init-param>
- <param-name>com.sun.jersey.config.feature.Trace</param-name>
- <param-value>true</param-value>
- </init-param> -->
- <init-param>
- <param-name>com.sun.jersey.config.feature.Redirect</param-name>
- <param-value>true</param-value>
- </init-param>
- <init-param>
- <param-name>com.sun.jersey.config.feature.ImplicitViewables</param-name>
- <param-value>true</param-value>
- </init-param>
- <init-param>
- <param-name>com.sun.jersey.config.property.resourceConfigClass</param-name>
- <param-value>com.sun.jersey.api.core.ClassNamesResourceConfig</param-value>
- </init-param>
- <init-param>
- <param-name>com.sun.jersey.config.property.classnames</param-name>
- <param-value>
- org.apache.activemq.apollo.web.resources.RootResource,
- org.apache.activemq.apollo.web.resources.JacksonJsonProvider
- org.apache.activemq.apollo.web.resources.JaxrsExceptionMapper
- org.fusesource.scalate.jersey.ScalateTemplateProvider
- org.fusesource.scalate.jersey.ScalateTemplateProcessor
- </param-value>
- </init-param>
- <init-param>
- <param-name>com.sun.jersey.config.feature.FilterForwardOn404</param-name>
- <param-value>true</param-value>
- </init-param>
- <init-param>
- <param-name>com.sun.jersey.config.property.MediaTypeMappings</param-name>
- <param-value>html : text/html, xml : application/xml, json : application/json</param-value>
- </init-param>
-
+ <filter-name>static</filter-name>
+ <filter-class>org.apache.activemq.apollo.web.StaticContentFilter</filter-class>
</filter>
<filter-mapping>
- <filter-name>Jersey Filter</filter-name>
+ <filter-name>static</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
@@ -87,6 +52,17 @@
<url-pattern>/*</url-pattern>
</filter-mapping>
+ <servlet>
+ <servlet-name>jersey</servlet-name>
+ <servlet-class>org.apache.activemq.apollo.web.JerseyServlet</servlet-class>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>jersey</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+
<error-page>
<error-code>500</error-code>
<location>/WEB-INF/scalate/errors/500.scaml</location>