Author: stevel Date: Wed May 14 09:45:40 2014 New Revision: 1594525 URL: http://svn.apache.org/r1594525 Log: SLIDER-50 (some work on the registry URIs at the same time, partly unintentionallly)
Modified: incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/server/services/registry/RegistryRestResources.java Modified: incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/server/services/registry/RegistryRestResources.java URL: http://svn.apache.org/viewvc/incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/server/services/registry/RegistryRestResources.java?rev=1594525&r1=1594524&r2=1594525&view=diff ============================================================================== --- incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/server/services/registry/RegistryRestResources.java (original) +++ incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/server/services/registry/RegistryRestResources.java Wed May 14 09:45:40 2014 @@ -26,7 +26,6 @@ import org.apache.slider.core.registry.i import org.apache.slider.server.appmaster.web.rest.RestPaths; import org.apache.slider.server.services.curator.CuratorServiceInstance; import org.apache.slider.server.services.curator.CuratorServiceInstances; -import org.apache.slider.server.services.curator.RegistryBinderService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -42,6 +41,7 @@ import javax.ws.rs.WebApplicationExcepti import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import java.net.URI; import java.net.URL; import java.util.List; import java.util.Random; @@ -49,6 +49,8 @@ import java.util.Random; @Singleton @Path(RestPaths.SLIDER_PATH_REGISTRY) public class RegistryRestResources extends DiscoveryResource<ServiceInstanceData> { + public static final String SERVICE_NAME = "v1/service/{name}"; + public static final String SERVICE_NAME_ID = "v1/service/{name}/{id}"; protected static final Logger log = LoggerFactory.getLogger(RegistryRestResources.class); private final SliderRegistryService registry; @@ -65,7 +67,7 @@ public class RegistryRestResources exten @GET public Response getWadl (@Context HttpServletRequest request) { try { - java.net.URI location = new URL(request.getScheme(), + URI location = new URL(request.getScheme(), request.getServerName(), request.getServerPort(), "/application.wadl").toURI(); @@ -79,13 +81,13 @@ public class RegistryRestResources exten @Override @javax.ws.rs.GET - @javax.ws.rs.Path("v1/service/{name}") - @javax.ws.rs.Produces({"application/json"}) + @javax.ws.rs.Path(SERVICE_NAME) + @javax.ws.rs.Produces({MediaType.APPLICATION_JSON}) public Response getAll(@PathParam("name") String name) { try { List<CuratorServiceInstance<ServiceInstanceData>> instances = registry.listInstances(name); - return Response.ok(new CuratorServiceInstances<ServiceInstanceData>(instances)).build(); + return Response.ok(new CuratorServiceInstances<>(instances)).build(); } catch (Exception e) { log.error("Error during generation of response", e); return Response.serverError().build(); @@ -94,7 +96,7 @@ public class RegistryRestResources exten @Override @GET - @Path("v1/service/{name}/{id}") + @Path(SERVICE_NAME_ID) @Produces(MediaType.APPLICATION_JSON) public Response get(@PathParam("name") String name, @PathParam("id") String id) { @@ -122,7 +124,7 @@ public class RegistryRestResources exten try { List<CuratorServiceInstance<ServiceInstanceData>> instances = registry.listInstances(name); - if (instances == null || instances.size() == 0) { + if (instances == null || instances.isEmpty()) { return Response.status(Response.Status.NOT_FOUND).build(); } @@ -141,7 +143,7 @@ public class RegistryRestResources exten @Override @PUT - @Path("v1/service/{name}/{id}") + @Path(SERVICE_NAME_ID) @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response putService(ServiceInstance<ServiceInstanceData> instance, @@ -152,7 +154,7 @@ public class RegistryRestResources exten @Override @DELETE - @Path("v1/service/{name}/{id}") + @Path(SERVICE_NAME_ID) public Response removeService(@PathParam("name") String name, @PathParam("id") String id) { throw new UnsupportedOperationException("removeService not supported");