You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nutch.apache.org by su...@apache.org on 2015/10/25 19:51:30 UTC
svn commit: r1710477 -
/nutch/trunk/src/java/org/apache/nutch/service/resources/ConfigResource.java
Author: sujen
Date: Sun Oct 25 18:51:30 2015
New Revision: 1710477
URL: http://svn.apache.org/viewvc?rev=1710477&view=rev
Log:
NUTCH 2128 - Refactor config endpoint, this closes #81. (Sujen Shah)
Modified:
nutch/trunk/src/java/org/apache/nutch/service/resources/ConfigResource.java
Modified: nutch/trunk/src/java/org/apache/nutch/service/resources/ConfigResource.java
URL: http://svn.apache.org/viewvc/nutch/trunk/src/java/org/apache/nutch/service/resources/ConfigResource.java?rev=1710477&r1=1710476&r2=1710477&view=diff
==============================================================================
--- nutch/trunk/src/java/org/apache/nutch/service/resources/ConfigResource.java (original)
+++ nutch/trunk/src/java/org/apache/nutch/service/resources/ConfigResource.java Sun Oct 25 18:51:30 2015
@@ -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 Abst
@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 Abst
}
@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();
}
}