Added charset=UTF-8 on REST api @Consumes and @Produces for proper json management
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@146333 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
09dae86c43
commit
eed62edff7
|
@ -1,6 +1,7 @@
|
|||
package org.gcube.informationsystem.resourceregistry;
|
||||
|
||||
import javax.ws.rs.ApplicationPath;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.gcube.informationsystem.resourceregistry.rest.Access;
|
||||
import org.glassfish.jersey.server.ResourceConfig;
|
||||
|
@ -11,6 +12,8 @@ import org.glassfish.jersey.server.ResourceConfig;
|
|||
@ApplicationPath("/")
|
||||
public class ResourceInitializer extends ResourceConfig {
|
||||
|
||||
public static final String APPLICATION_JSON_CHARSET_UTF_8 = MediaType.APPLICATION_JSON + "; charset=UTF-8";
|
||||
|
||||
public ResourceInitializer(){
|
||||
packages(Access.class.getPackage().toString());
|
||||
}
|
||||
|
|
|
@ -8,8 +8,8 @@ import javax.ws.rs.Path;
|
|||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.gcube.informationsystem.resourceregistry.ResourceInitializer;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.er.ERNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException;
|
||||
|
@ -29,7 +29,6 @@ import com.tinkerpop.blueprints.Direction;
|
|||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
* @author Lucio Lelii (ISTI - CNR)
|
||||
*/
|
||||
@Path(AccessPath.ACCESS_PATH_PART)
|
||||
public class Access {
|
||||
|
@ -65,7 +64,7 @@ public class Access {
|
|||
* if the query is invalid or no idempotent
|
||||
*/
|
||||
@GET
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
||||
public String query(@QueryParam(AccessPath.QUERY_PARAM) String query,
|
||||
@QueryParam(AccessPath.LIMIT_PARAM) int limit,
|
||||
@QueryParam(AccessPath.FETCH_PLAN_PARAM) String fetchPlan)
|
||||
|
@ -84,7 +83,7 @@ public class Access {
|
|||
@GET
|
||||
@Path(AccessPath.INSTANCE_PATH_PART + "/" + "{" + TYPE_PATH_PARAM + "}"
|
||||
+ "/{" + ID_PATH_PARAM + "}")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
||||
public String getInstance(@PathParam(TYPE_PATH_PARAM) String type,
|
||||
@PathParam(ID_PATH_PARAM) String id)
|
||||
throws ERNotFoundException, ResourceRegistryException {
|
||||
|
@ -110,7 +109,7 @@ public class Access {
|
|||
@SuppressWarnings({ "rawtypes" })
|
||||
@GET
|
||||
@Path(AccessPath.INSTANCES_PATH_PART + "/" + "{" + TYPE_PATH_PARAM + "}")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
||||
public String getInstances(@PathParam(TYPE_PATH_PARAM) String type,
|
||||
@QueryParam(AccessPath.POLYMORPHIC_PARAM) Boolean polymorphic,
|
||||
@QueryParam(AccessPath.REFERENCE) String reference,
|
||||
|
@ -170,7 +169,7 @@ public class Access {
|
|||
*/
|
||||
@GET
|
||||
@Path(AccessPath.SCHEMA_PATH_PART + "/{" + TYPE_PATH_PARAM + "}")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
||||
public String getSchema(@PathParam(TYPE_PATH_PARAM) String type,
|
||||
@QueryParam(AccessPath.POLYMORPHIC_PARAM) Boolean polymorphic)
|
||||
throws SchemaNotFoundException, ResourceRegistryException {
|
||||
|
|
|
@ -12,8 +12,8 @@ import javax.ws.rs.Path;
|
|||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.gcube.informationsystem.resourceregistry.ResourceInitializer;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextCreationException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException;
|
||||
|
@ -26,7 +26,6 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
* @author Lucio Lelii (ISTI - CNR)
|
||||
*/
|
||||
@Path(ContextPath.CONTEXT_PATH_PART)
|
||||
public class ContextManager {
|
||||
|
@ -50,7 +49,7 @@ public class ContextManager {
|
|||
* @throws Exception
|
||||
*/
|
||||
@PUT
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
||||
public String create(
|
||||
@QueryParam(ContextPath.PARENT_CONTEXT_ID_PARAM) String parentUUID,
|
||||
@QueryParam(ContextPath.NAME_PARAM) String name)
|
||||
|
@ -67,7 +66,7 @@ public class ContextManager {
|
|||
*/
|
||||
@DELETE
|
||||
@Path("{" + ID_PATH_PARAM + "}")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
||||
public boolean delete(@PathParam(ID_PATH_PARAM) String uuid)
|
||||
throws ContextNotFoundException, ContextException {
|
||||
logger.trace("requested to delete context with id {} ", uuid);
|
||||
|
@ -84,7 +83,7 @@ public class ContextManager {
|
|||
*/
|
||||
@POST
|
||||
@Path(ContextPath.RENAME_PATH_PART + "/{" + ID_PATH_PARAM + "}")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
||||
public String rename(@PathParam(ID_PATH_PARAM) String uuid,
|
||||
@QueryParam(ContextPath.NAME_PARAM) String name)
|
||||
throws ContextNotFoundException, ContextException {
|
||||
|
@ -102,7 +101,7 @@ public class ContextManager {
|
|||
*/
|
||||
@POST
|
||||
@Path(ContextPath.MOVE_PATH_PART + "/{" + ID_PATH_PARAM + "}")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
||||
public String move(
|
||||
@PathParam(ID_PATH_PARAM) String uuid,
|
||||
@QueryParam(ContextPath.PARENT_CONTEXT_ID_PARAM) String newParentUUID)
|
||||
|
|
|
@ -15,6 +15,7 @@ import org.gcube.informationsystem.model.entity.Facet;
|
|||
import org.gcube.informationsystem.model.entity.Resource;
|
||||
import org.gcube.informationsystem.model.relation.ConsistsOf;
|
||||
import org.gcube.informationsystem.model.relation.IsRelatedTo;
|
||||
import org.gcube.informationsystem.resourceregistry.ResourceInitializer;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetAlreadyPresentException;
|
||||
|
@ -32,7 +33,6 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
* @author Lucio Lelii (ISTI - CNR)
|
||||
*/
|
||||
@Path(ERPath.ER_PATH_PART)
|
||||
public class ERManager {
|
||||
|
@ -59,8 +59,8 @@ public class ERManager {
|
|||
*/
|
||||
@PUT
|
||||
@Path(ERPath.FACET_PATH_PART + "/{" + TYPE_PATH_PARAM + "}")
|
||||
@Consumes({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes({ MediaType.TEXT_PLAIN, ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8 })
|
||||
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
||||
public String createFacet(@PathParam(TYPE_PATH_PARAM) String type,
|
||||
String json) throws FacetAlreadyPresentException, ResourceRegistryException {
|
||||
logger.info("requested facet creation for type {} defined by {} ",
|
||||
|
@ -85,8 +85,8 @@ public class ERManager {
|
|||
*/
|
||||
@POST
|
||||
@Path(ERPath.FACET_PATH_PART + "/{" + ID_PATH_PARAM + "}")
|
||||
@Consumes({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes({ MediaType.TEXT_PLAIN, ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8 })
|
||||
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
||||
public String updateFacet(@PathParam(ID_PATH_PARAM) String uuid, String json)
|
||||
throws FacetNotFoundException, ResourceRegistryException {
|
||||
logger.info("requested facet update for id {} with {}", uuid, json);
|
||||
|
@ -130,8 +130,8 @@ public class ERManager {
|
|||
*/
|
||||
@PUT
|
||||
@Path(ERPath.RESOURCE_PATH_PART + "/{" + TYPE_PATH_PARAM + "}")
|
||||
@Consumes({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes({ MediaType.TEXT_PLAIN, ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8 })
|
||||
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
||||
public String createResource(@PathParam(TYPE_PATH_PARAM) String type,
|
||||
String json) throws ResourceAlreadyPresentException, ResourceRegistryException {
|
||||
logger.info("requested resource creation for type {} with json {}",
|
||||
|
@ -153,8 +153,8 @@ public class ERManager {
|
|||
*/
|
||||
@POST
|
||||
@Path(ERPath.RESOURCE_PATH_PART + "/{" + ID_PATH_PARAM + "}")
|
||||
@Consumes({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes({ MediaType.TEXT_PLAIN, ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8 })
|
||||
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
||||
public String updateResource(@PathParam(ID_PATH_PARAM) String uuid,
|
||||
String json) throws ResourceNotFoundException,
|
||||
ResourceRegistryException {
|
||||
|
@ -206,7 +206,8 @@ public class ERManager {
|
|||
@Path(ERPath.CONSISTS_OF_PATH_PART + "/" + ERPath.SOURCE_PATH_PART
|
||||
+ "/{" + SOURCE_ID_PATH_PARAM + "}/" + ERPath.TARGET_PATH_PART
|
||||
+ "/{" + TARGET_ID_PATH_PARAM + "}/{" + TYPE_PATH_PARAM + "}")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes({ MediaType.TEXT_PLAIN, ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8 })
|
||||
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
||||
public String attachFacet(
|
||||
@PathParam(SOURCE_ID_PATH_PARAM) String resourceUUID,
|
||||
@PathParam(TARGET_ID_PATH_PARAM) String facetUUID,
|
||||
|
@ -262,8 +263,8 @@ public class ERManager {
|
|||
+ ERPath.SOURCE_PATH_PART + "/{" + SOURCE_ID_PATH_PARAM + "}/"
|
||||
+ ERPath.TARGET_PATH_PART + "/{" + TARGET_ID_PATH_PARAM + "}/{"
|
||||
+ TYPE_PATH_PARAM + "}")
|
||||
@Consumes({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes({ MediaType.TEXT_PLAIN, ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8 })
|
||||
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
||||
public String attachResource(
|
||||
@PathParam(SOURCE_ID_PATH_PARAM) String sourceResourceUUID,
|
||||
@PathParam(TARGET_ID_PATH_PARAM) String targetResourceUUID,
|
||||
|
|
|
@ -9,6 +9,7 @@ import javax.ws.rs.Produces;
|
|||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.gcube.informationsystem.model.AccessType;
|
||||
import org.gcube.informationsystem.resourceregistry.ResourceInitializer;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.rest.SchemaPath;
|
||||
|
@ -19,11 +20,6 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
* @author Lucio Lelii (ISTI - CNR)
|
||||
*/
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*
|
||||
*/
|
||||
@ApplicationPath(SchemaPath.SCHEMA_PATH_PART)
|
||||
public class SchemaManager {
|
||||
|
@ -43,8 +39,8 @@ public class SchemaManager {
|
|||
*/
|
||||
@PUT
|
||||
@Path("{" + TYPE_PATH_PARAM + "}")
|
||||
@Consumes({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes({ MediaType.TEXT_PLAIN, ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8 })
|
||||
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
||||
public String create(
|
||||
@PathParam(TYPE_PATH_PARAM) String type,
|
||||
String json)
|
||||
|
|
|
@ -6,12 +6,14 @@ HTTP_PORT=:2480
|
|||
DB=IS
|
||||
|
||||
# OrientDB root access. Needed to be able to create new databases
|
||||
USERNAME=root
|
||||
PASSWORD=rootpwd
|
||||
ROOT_USERNAME=root
|
||||
ROOT_PASSWORD=rootpwd
|
||||
|
||||
DEFAULT_ADMIN_USERNAME=admin
|
||||
CHANGED_ADMIN_USERNAME=CHANGE_ME
|
||||
|
||||
DEFAULT_ADMIN_PASSWORD=admin
|
||||
CHANGED_ADMIN_PASSWORD=CHANGE_ME
|
||||
|
||||
DEFAULT_CREATED_WRITER_USER_PASSWORD=CHANGE_ME
|
||||
DEFAULT_CREATED_READER_USER_PASSWORD=CHANGE_ME
|
||||
|
||||
DEFAULT_ADMIN_USERNAME=admin
|
||||
DEFAULT_ADMIN_PASSWORD=admin
|
||||
CHANGED_ADMIN_PASSWORD=CHANGE_ME
|
|
@ -194,7 +194,7 @@ public class ContextManagementImplTest {
|
|||
logger.debug("The DB should be now clean");
|
||||
}
|
||||
|
||||
//@Test
|
||||
@Test
|
||||
public void createDevContext() throws Exception {
|
||||
String gcubeJson = contextManagementImpl.create(null, "gcube");
|
||||
Context gcubeContext = ISMapper.unmarshal(Context.class, gcubeJson);
|
||||
|
|
Loading…
Reference in New Issue