Apache Nutch is an extensible and scalable web crawler
NUTCH 2128 - Refactor config endpoint, this closes #81. (Sujen Shah)
Sujen Shah252eb2a87c21
diff --git a/src/java/org/apache/nutch/service/resources/ConfigResource.java b/src/java/org/apache/nutch/service/resources/ConfigResource.javaindex d45e89180..34572b6af 100644--- a/src/java/org/apache/nutch/service/resources/ConfigResource.java+++ b/src/java/org/apache/nutch/service/resources/ConfigResource.java@@ -25,8 +25,10 @@ import javax.ws.rs.Consumes;import javax.ws.rs.DELETE;import javax.ws.rs.GET;import javax.ws.rs.POST;+import javax.ws.rs.PUT;import javax.ws.rs.Path;import javax.ws.rs.PathParam;+import javax.ws.rs.Produces;import javax.ws.rs.WebApplicationException;import javax.ws.rs.core.MediaType;import javax.ws.rs.core.Response;@@ -57,6 +59,7 @@ public class ConfigResource extends AbstractResource{@GET@Path("/{configId}/{propertyId}")+ @Produces(MediaType.TEXT_PLAIN)@JacksonFeatures(serializationEnable = { SerializationFeature.INDENT_OUTPUT })public String getProperty(@PathParam("configId") String configId,@PathParam("propertyId") String propertyId) {@@ -70,13 +73,33 @@ public class ConfigResource extends AbstractResource{}@POST- @Path("/{configId}")+ @Path("/create")@Consumes(MediaType.APPLICATION_JSON)- public String createConfig(NutchConfig newConfig) {+ @Produces(MediaType.TEXT_PLAIN)+ public Response createConfig(NutchConfig newConfig) {if (newConfig == null) {- throw new WebApplicationException(Response.status(Status.BAD_REQUEST)- .entity("Nutch configuration cannot be empty!").build());+ return Response.status(400)+ .entity("Nutch configuration cannot be empty!").build();+ }+ try{+ configManager.create(newConfig);+ }catch(Exception e){+ return Response.status(400)+ .entity(e.getMessage()).build();+ }+ return Response.ok(newConfig.getConfigId()).build();+ }++ @PUT+ @Path("/{configId}/{propertyId}")+ @Consumes(MediaType.TEXT_PLAIN)+ public Response updateProperty(@PathParam("configId")String confId,+ @PathParam("propertyId")String propertyKey, String value) {+ try{+ configManager.setProperty(confId, propertyKey, value);+ }catch(Exception e) {+ return Response.status(400).entity(e.getMessage()).build();}- return configManager.create(newConfig);+ return Response.ok().build();}}