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:
Luca Frosini 2017-03-24 16:04:09 +00:00
parent 09dae86c43
commit eed62edff7
7 changed files with 38 additions and 38 deletions

View File

@ -1,6 +1,7 @@
package org.gcube.informationsystem.resourceregistry; package org.gcube.informationsystem.resourceregistry;
import javax.ws.rs.ApplicationPath; import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.MediaType;
import org.gcube.informationsystem.resourceregistry.rest.Access; import org.gcube.informationsystem.resourceregistry.rest.Access;
import org.glassfish.jersey.server.ResourceConfig; import org.glassfish.jersey.server.ResourceConfig;
@ -11,6 +12,8 @@ import org.glassfish.jersey.server.ResourceConfig;
@ApplicationPath("/") @ApplicationPath("/")
public class ResourceInitializer extends ResourceConfig { public class ResourceInitializer extends ResourceConfig {
public static final String APPLICATION_JSON_CHARSET_UTF_8 = MediaType.APPLICATION_JSON + "; charset=UTF-8";
public ResourceInitializer(){ public ResourceInitializer(){
packages(Access.class.getPackage().toString()); packages(Access.class.getPackage().toString());
} }

View File

@ -8,8 +8,8 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam; import javax.ws.rs.PathParam;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam; 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.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.er.ERNotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.er.ERNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException;
@ -29,7 +29,6 @@ import com.tinkerpop.blueprints.Direction;
/** /**
* @author Luca Frosini (ISTI - CNR) * @author Luca Frosini (ISTI - CNR)
* @author Lucio Lelii (ISTI - CNR)
*/ */
@Path(AccessPath.ACCESS_PATH_PART) @Path(AccessPath.ACCESS_PATH_PART)
public class Access { public class Access {
@ -65,7 +64,7 @@ public class Access {
* if the query is invalid or no idempotent * if the query is invalid or no idempotent
*/ */
@GET @GET
@Produces(MediaType.APPLICATION_JSON) @Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
public String query(@QueryParam(AccessPath.QUERY_PARAM) String query, public String query(@QueryParam(AccessPath.QUERY_PARAM) String query,
@QueryParam(AccessPath.LIMIT_PARAM) int limit, @QueryParam(AccessPath.LIMIT_PARAM) int limit,
@QueryParam(AccessPath.FETCH_PLAN_PARAM) String fetchPlan) @QueryParam(AccessPath.FETCH_PLAN_PARAM) String fetchPlan)
@ -84,7 +83,7 @@ public class Access {
@GET @GET
@Path(AccessPath.INSTANCE_PATH_PART + "/" + "{" + TYPE_PATH_PARAM + "}" @Path(AccessPath.INSTANCE_PATH_PART + "/" + "{" + TYPE_PATH_PARAM + "}"
+ "/{" + ID_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, public String getInstance(@PathParam(TYPE_PATH_PARAM) String type,
@PathParam(ID_PATH_PARAM) String id) @PathParam(ID_PATH_PARAM) String id)
throws ERNotFoundException, ResourceRegistryException { throws ERNotFoundException, ResourceRegistryException {
@ -110,7 +109,7 @@ public class Access {
@SuppressWarnings({ "rawtypes" }) @SuppressWarnings({ "rawtypes" })
@GET @GET
@Path(AccessPath.INSTANCES_PATH_PART + "/" + "{" + TYPE_PATH_PARAM + "}") @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, public String getInstances(@PathParam(TYPE_PATH_PARAM) String type,
@QueryParam(AccessPath.POLYMORPHIC_PARAM) Boolean polymorphic, @QueryParam(AccessPath.POLYMORPHIC_PARAM) Boolean polymorphic,
@QueryParam(AccessPath.REFERENCE) String reference, @QueryParam(AccessPath.REFERENCE) String reference,
@ -170,7 +169,7 @@ public class Access {
*/ */
@GET @GET
@Path(AccessPath.SCHEMA_PATH_PART + "/{" + TYPE_PATH_PARAM + "}") @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, public String getSchema(@PathParam(TYPE_PATH_PARAM) String type,
@QueryParam(AccessPath.POLYMORPHIC_PARAM) Boolean polymorphic) @QueryParam(AccessPath.POLYMORPHIC_PARAM) Boolean polymorphic)
throws SchemaNotFoundException, ResourceRegistryException { throws SchemaNotFoundException, ResourceRegistryException {

View File

@ -12,8 +12,8 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam; import javax.ws.rs.PathParam;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam; 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.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextCreationException; import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextCreationException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException; import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException;
@ -26,7 +26,6 @@ import org.slf4j.LoggerFactory;
/** /**
* @author Luca Frosini (ISTI - CNR) * @author Luca Frosini (ISTI - CNR)
* @author Lucio Lelii (ISTI - CNR)
*/ */
@Path(ContextPath.CONTEXT_PATH_PART) @Path(ContextPath.CONTEXT_PATH_PART)
public class ContextManager { public class ContextManager {
@ -50,7 +49,7 @@ public class ContextManager {
* @throws Exception * @throws Exception
*/ */
@PUT @PUT
@Produces(MediaType.APPLICATION_JSON) @Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
public String create( public String create(
@QueryParam(ContextPath.PARENT_CONTEXT_ID_PARAM) String parentUUID, @QueryParam(ContextPath.PARENT_CONTEXT_ID_PARAM) String parentUUID,
@QueryParam(ContextPath.NAME_PARAM) String name) @QueryParam(ContextPath.NAME_PARAM) String name)
@ -67,7 +66,7 @@ public class ContextManager {
*/ */
@DELETE @DELETE
@Path("{" + ID_PATH_PARAM + "}") @Path("{" + ID_PATH_PARAM + "}")
@Produces(MediaType.APPLICATION_JSON) @Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
public boolean delete(@PathParam(ID_PATH_PARAM) String uuid) public boolean delete(@PathParam(ID_PATH_PARAM) String uuid)
throws ContextNotFoundException, ContextException { throws ContextNotFoundException, ContextException {
logger.trace("requested to delete context with id {} ", uuid); logger.trace("requested to delete context with id {} ", uuid);
@ -84,7 +83,7 @@ public class ContextManager {
*/ */
@POST @POST
@Path(ContextPath.RENAME_PATH_PART + "/{" + ID_PATH_PARAM + "}") @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, public String rename(@PathParam(ID_PATH_PARAM) String uuid,
@QueryParam(ContextPath.NAME_PARAM) String name) @QueryParam(ContextPath.NAME_PARAM) String name)
throws ContextNotFoundException, ContextException { throws ContextNotFoundException, ContextException {
@ -102,7 +101,7 @@ public class ContextManager {
*/ */
@POST @POST
@Path(ContextPath.MOVE_PATH_PART + "/{" + ID_PATH_PARAM + "}") @Path(ContextPath.MOVE_PATH_PART + "/{" + ID_PATH_PARAM + "}")
@Produces(MediaType.APPLICATION_JSON) @Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
public String move( public String move(
@PathParam(ID_PATH_PARAM) String uuid, @PathParam(ID_PATH_PARAM) String uuid,
@QueryParam(ContextPath.PARENT_CONTEXT_ID_PARAM) String newParentUUID) @QueryParam(ContextPath.PARENT_CONTEXT_ID_PARAM) String newParentUUID)

View File

@ -15,6 +15,7 @@ import org.gcube.informationsystem.model.entity.Facet;
import org.gcube.informationsystem.model.entity.Resource; import org.gcube.informationsystem.model.entity.Resource;
import org.gcube.informationsystem.model.relation.ConsistsOf; import org.gcube.informationsystem.model.relation.ConsistsOf;
import org.gcube.informationsystem.model.relation.IsRelatedTo; 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.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetAlreadyPresentException; import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetAlreadyPresentException;
@ -32,7 +33,6 @@ import org.slf4j.LoggerFactory;
/** /**
* @author Luca Frosini (ISTI - CNR) * @author Luca Frosini (ISTI - CNR)
* @author Lucio Lelii (ISTI - CNR)
*/ */
@Path(ERPath.ER_PATH_PART) @Path(ERPath.ER_PATH_PART)
public class ERManager { public class ERManager {
@ -59,8 +59,8 @@ public class ERManager {
*/ */
@PUT @PUT
@Path(ERPath.FACET_PATH_PART + "/{" + TYPE_PATH_PARAM + "}") @Path(ERPath.FACET_PATH_PART + "/{" + TYPE_PATH_PARAM + "}")
@Consumes({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON }) @Consumes({ MediaType.TEXT_PLAIN, ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8 })
@Produces(MediaType.APPLICATION_JSON) @Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
public String createFacet(@PathParam(TYPE_PATH_PARAM) String type, public String createFacet(@PathParam(TYPE_PATH_PARAM) String type,
String json) throws FacetAlreadyPresentException, ResourceRegistryException { String json) throws FacetAlreadyPresentException, ResourceRegistryException {
logger.info("requested facet creation for type {} defined by {} ", logger.info("requested facet creation for type {} defined by {} ",
@ -85,8 +85,8 @@ public class ERManager {
*/ */
@POST @POST
@Path(ERPath.FACET_PATH_PART + "/{" + ID_PATH_PARAM + "}") @Path(ERPath.FACET_PATH_PART + "/{" + ID_PATH_PARAM + "}")
@Consumes({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON }) @Consumes({ MediaType.TEXT_PLAIN, ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8 })
@Produces(MediaType.APPLICATION_JSON) @Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
public String updateFacet(@PathParam(ID_PATH_PARAM) String uuid, String json) public String updateFacet(@PathParam(ID_PATH_PARAM) String uuid, String json)
throws FacetNotFoundException, ResourceRegistryException { throws FacetNotFoundException, ResourceRegistryException {
logger.info("requested facet update for id {} with {}", uuid, json); logger.info("requested facet update for id {} with {}", uuid, json);
@ -130,8 +130,8 @@ public class ERManager {
*/ */
@PUT @PUT
@Path(ERPath.RESOURCE_PATH_PART + "/{" + TYPE_PATH_PARAM + "}") @Path(ERPath.RESOURCE_PATH_PART + "/{" + TYPE_PATH_PARAM + "}")
@Consumes({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON }) @Consumes({ MediaType.TEXT_PLAIN, ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8 })
@Produces(MediaType.APPLICATION_JSON) @Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
public String createResource(@PathParam(TYPE_PATH_PARAM) String type, public String createResource(@PathParam(TYPE_PATH_PARAM) String type,
String json) throws ResourceAlreadyPresentException, ResourceRegistryException { String json) throws ResourceAlreadyPresentException, ResourceRegistryException {
logger.info("requested resource creation for type {} with json {}", logger.info("requested resource creation for type {} with json {}",
@ -153,8 +153,8 @@ public class ERManager {
*/ */
@POST @POST
@Path(ERPath.RESOURCE_PATH_PART + "/{" + ID_PATH_PARAM + "}") @Path(ERPath.RESOURCE_PATH_PART + "/{" + ID_PATH_PARAM + "}")
@Consumes({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON }) @Consumes({ MediaType.TEXT_PLAIN, ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8 })
@Produces(MediaType.APPLICATION_JSON) @Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
public String updateResource(@PathParam(ID_PATH_PARAM) String uuid, public String updateResource(@PathParam(ID_PATH_PARAM) String uuid,
String json) throws ResourceNotFoundException, String json) throws ResourceNotFoundException,
ResourceRegistryException { ResourceRegistryException {
@ -206,7 +206,8 @@ public class ERManager {
@Path(ERPath.CONSISTS_OF_PATH_PART + "/" + ERPath.SOURCE_PATH_PART @Path(ERPath.CONSISTS_OF_PATH_PART + "/" + ERPath.SOURCE_PATH_PART
+ "/{" + SOURCE_ID_PATH_PARAM + "}/" + ERPath.TARGET_PATH_PART + "/{" + SOURCE_ID_PATH_PARAM + "}/" + ERPath.TARGET_PATH_PART
+ "/{" + TARGET_ID_PATH_PARAM + "}/{" + TYPE_PATH_PARAM + "}") + "/{" + 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( public String attachFacet(
@PathParam(SOURCE_ID_PATH_PARAM) String resourceUUID, @PathParam(SOURCE_ID_PATH_PARAM) String resourceUUID,
@PathParam(TARGET_ID_PATH_PARAM) String facetUUID, @PathParam(TARGET_ID_PATH_PARAM) String facetUUID,
@ -262,8 +263,8 @@ public class ERManager {
+ ERPath.SOURCE_PATH_PART + "/{" + SOURCE_ID_PATH_PARAM + "}/" + ERPath.SOURCE_PATH_PART + "/{" + SOURCE_ID_PATH_PARAM + "}/"
+ ERPath.TARGET_PATH_PART + "/{" + TARGET_ID_PATH_PARAM + "}/{" + ERPath.TARGET_PATH_PART + "/{" + TARGET_ID_PATH_PARAM + "}/{"
+ TYPE_PATH_PARAM + "}") + TYPE_PATH_PARAM + "}")
@Consumes({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON }) @Consumes({ MediaType.TEXT_PLAIN, ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8 })
@Produces(MediaType.APPLICATION_JSON) @Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
public String attachResource( public String attachResource(
@PathParam(SOURCE_ID_PATH_PARAM) String sourceResourceUUID, @PathParam(SOURCE_ID_PATH_PARAM) String sourceResourceUUID,
@PathParam(TARGET_ID_PATH_PARAM) String targetResourceUUID, @PathParam(TARGET_ID_PATH_PARAM) String targetResourceUUID,

View File

@ -9,6 +9,7 @@ import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import org.gcube.informationsystem.model.AccessType; 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.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException; import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException;
import org.gcube.informationsystem.resourceregistry.api.rest.SchemaPath; import org.gcube.informationsystem.resourceregistry.api.rest.SchemaPath;
@ -19,11 +20,6 @@ import org.slf4j.LoggerFactory;
/** /**
* @author Luca Frosini (ISTI - CNR) * @author Luca Frosini (ISTI - CNR)
* @author Lucio Lelii (ISTI - CNR)
*/
/**
* @author Luca Frosini (ISTI - CNR)
*
*/ */
@ApplicationPath(SchemaPath.SCHEMA_PATH_PART) @ApplicationPath(SchemaPath.SCHEMA_PATH_PART)
public class SchemaManager { public class SchemaManager {
@ -43,8 +39,8 @@ public class SchemaManager {
*/ */
@PUT @PUT
@Path("{" + TYPE_PATH_PARAM + "}") @Path("{" + TYPE_PATH_PARAM + "}")
@Consumes({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON }) @Consumes({ MediaType.TEXT_PLAIN, ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8 })
@Produces(MediaType.APPLICATION_JSON) @Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
public String create( public String create(
@PathParam(TYPE_PATH_PARAM) String type, @PathParam(TYPE_PATH_PARAM) String type,
String json) String json)

View File

@ -6,12 +6,14 @@ HTTP_PORT=:2480
DB=IS DB=IS
# OrientDB root access. Needed to be able to create new databases # OrientDB root access. Needed to be able to create new databases
USERNAME=root ROOT_USERNAME=root
PASSWORD=rootpwd 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_WRITER_USER_PASSWORD=CHANGE_ME
DEFAULT_CREATED_READER_USER_PASSWORD=CHANGE_ME DEFAULT_CREATED_READER_USER_PASSWORD=CHANGE_ME
DEFAULT_ADMIN_USERNAME=admin
DEFAULT_ADMIN_PASSWORD=admin
CHANGED_ADMIN_PASSWORD=CHANGE_ME

View File

@ -194,7 +194,7 @@ public class ContextManagementImplTest {
logger.debug("The DB should be now clean"); logger.debug("The DB should be now clean");
} }
//@Test @Test
public void createDevContext() throws Exception { public void createDevContext() throws Exception {
String gcubeJson = contextManagementImpl.create(null, "gcube"); String gcubeJson = contextManagementImpl.create(null, "gcube");
Context gcubeContext = ISMapper.unmarshal(Context.class, gcubeJson); Context gcubeContext = ISMapper.unmarshal(Context.class, gcubeJson);