package com.topsy.jmxproxy.resource;

import com.topsy.jmxproxy.service.JMXConnectionManager;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.apache.log4j.Logger;

import org.springframework.stereotype.Service;

import com.sun.jersey.api.core.InjectParam;

@Service
@Path("/")
public class JMXProxyResource {
    private static Logger LOG = Logger.getLogger(JMXProxyResource.class);

    @InjectParam
    private static JMXConnectionManager manager;

    @GET
    @Path("/{host}:{port:\\d+}")
    @Produces(MediaType.APPLICATION_JSON)
    public Response getJMXDataJSON(@PathParam("host") String host, @PathParam("port") int port) {
        LOG.debug("request jmx domains as json for " + host + ":" + port);

        try {
            return Response.ok(manager.getHost(host + ":" + port)).build();
        } catch (Exception e) {
            LOG.debug("failed parameters: " + host + ":" + port, e);
            return Response.status(Response.Status.NOT_FOUND).build();
        }
    }
}

@@ -23,19 +23,47 @@
 roxy
-.resource;%0A
+;%0A%0Aimport com.topsy.jmxproxy.core.Host;
 %0Aimp
@@ -89,19 +89,12 @@
 oxy.
-service.JMX
+jmx.
 Conn
@@ -291,153 +291,176 @@
 se;%0A
-%0A
 import 
-org.apache.log4j.Logger;%0A%0Aimport org.springframework.stereotype.Service
+javax.ws.rs.WebApplicationException;%0A%0Aimport org.slf4j.Logger
 ;%0A
-%0A
 import 
-com.sun.jersey.api.core.InjectParam;%0A%0A@Service%0A@Path(%22/%22
+org.slf4j.LoggerFactory;%0A%0A@Path(%22/%7Bhost%7D:%7Bport:%5C%5Cd+%7D%22)%0A@Produces(MediaType.APPLICATION_JSON
 )%0Apu
@@ -508,16 +508,22 @@
  static 
+final 
 Logger L
@@ -533,16 +533,23 @@
 = Logger
+Factory
 .getLogg
@@ -584,44 +584,79 @@
 %0A   
+ 
- @InjectParam%0A    private static JMX
+private final ConnectionManager manager;%0A%0A    public JMXProxyResource(
 Conn
@@ -680,129 +680,90 @@
 ager
-;%0A
+) %7B
 %0A    
-@GET%0A    @Path(%22/%7Bhost%7D:%7Bport:%5C%5Cd+%7D%22)%0A    @Produces(MediaType.APPLICATION_JSON)%0A    public Response getJMXDataJSON
+    this.manager = manager;%0A    %7D%0A%0A    @GET%0A    public Host getJMXHostData
 (@Pa
@@ -845,35 +845,25 @@
 ug(%22
-request jmx domains as json
+fetching jmx data
  for
@@ -925,20 +925,8 @@
 urn 
-Response.ok(
 mana
@@ -955,25 +955,16 @@
  + port)
-).build()
 ;%0A      
@@ -1074,30 +1074,41 @@
     
-return Response.status
+throw new WebApplicationException
 (Res
@@ -1134,16 +1134,8 @@
 UND)
-.build()
 ;%0A  

Convert Resource to support dropwizard service.