Fix the application path (was clashing with jersey) and move the declaration to the io module.

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/resource-management/resource-manager@160249 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Manuele Simi 2017-12-10 03:26:37 +00:00
parent 83ad08446c
commit 34bb1f57ff
4 changed files with 14 additions and 11 deletions

View File

@ -7,6 +7,8 @@ package org.gcube.resourcemanagement.manager.io.rs;
*
*/
public class RMContextPath {
public static final String APPLICATION_PATH = "/resource-manager";
public static final String CONTEXT_ROOT = "context";

View File

@ -3,13 +3,14 @@ package org.gcube.resourcemanagement.manager.webapp;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.MediaType;
import org.gcube.resourcemanagement.manager.io.rs.RMContextPath;
import org.gcube.resourcemanagement.manager.webapp.rs.RMContext;
import org.glassfish.jersey.server.ResourceConfig;
/**
* @author Manuele Simi (ISTI - CNR)
*/
@ApplicationPath("/")
@ApplicationPath(RMContextPath.APPLICATION_PATH)
public class ResourceInitializer extends ResourceConfig {
public static final String APPLICATION_JSON_CHARSET_UTF_8 = MediaType.APPLICATION_JSON + ";charset=UTF-8";

View File

@ -22,30 +22,29 @@ import com.fasterxml.jackson.databind.JsonMappingException;
/**
* Methods for manipulating {@link Context}s.
*
* @author Manuele Simi (ISTI-CNR)
* @author Manuele Simi (ISTI-CNR)
*
*/
@Path(RMContextPath.CONTEXT_ROOT)
public class RMContext {
private static Logger logger = LoggerFactory.getLogger(RMContext.class);
/*
* e.g. POST /resource-manager/context/
*/
@POST
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
public Response create(String json) throws JsonParseException, JsonMappingException, IOException, IllegalArgumentException
{
logger.info("Requested to create context {} with json {}",
Context.NAME, json);
public Response create(String json)
throws JsonParseException, JsonMappingException, IOException, IllegalArgumentException {
logger.info("Requested to create context {} with json {}", Context.NAME, json);
Context inputContext = ISMapper.unmarshal(Context.class, json);
if (Objects.nonNull(inputContext.getParent()))
return Response.status(Status.BAD_REQUEST).build();
String response = "All good";
//TODO
return Response.status(Status.CREATED).entity(response).
type(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8).build();
// TODO
return Response.status(Status.CREATED).entity(response).type(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
.build();
}
}

View File

@ -65,6 +65,7 @@ public class RMContextTest extends JerseyTest {
public void step1_Create() {
Context newContext = new ContextImpl(contextName);
try {
System.out.print(ISMapper.marshal(newContext));
Response create = target("context").request()
.post(Entity.entity(ISMapper.marshal(newContext), MediaType.APPLICATION_JSON + ";charset=UTF-8"));