List of usage examples for javax.activation MimeType MimeType
public MimeType(String rawdata) throws MimeTypeParseException
From source file:com.portfolio.rest.RestServicePortfolio.java
/*****************************/ @Path("/resources/resource/{node-parent-id}") @GET// www .ja v a 2 s. c o m @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes(MediaType.APPLICATION_XML) public String getResource(@CookieParam("user") String user, @CookieParam("credential") String token, @QueryParam("group") int groupId, @PathParam("node-parent-id") String nodeParentUuid, @Context ServletConfig sc, @Context HttpServletRequest httpServletRequest, @HeaderParam("Accept") String accept, @QueryParam("user") Integer userId) { UserInfo ui = checkCredential(httpServletRequest, user, token, null); try { String returnValue = dataProvider .getResource(new MimeType("text/xml"), nodeParentUuid, ui.userId, groupId).toString(); if (returnValue.equals("faux")) { throw new RestWebApplicationException(Status.FORBIDDEN, "Vous n'avez pas les droits necessaires"); } if (accept.equals(MediaType.APPLICATION_JSON)) returnValue = XML.toJSONObject(returnValue).toString(); logRestRequest(httpServletRequest, null, returnValue, Status.OK.getStatusCode()); return returnValue; } catch (RestWebApplicationException ex) { throw new RestWebApplicationException(Status.FORBIDDEN, ex.getResponse().getEntity().toString()); } catch (SQLException ex) { logRestRequest(httpServletRequest, null, null, Status.NOT_FOUND.getStatusCode()); throw new RestWebApplicationException(Status.NOT_FOUND, "Resource " + nodeParentUuid + " not found"); } catch (Exception ex) { ex.printStackTrace(); logRestRequest(httpServletRequest, null, ex.getMessage() + "\n\n" + javaUtils.getCompleteStackTrace(ex), Status.INTERNAL_SERVER_ERROR.getStatusCode()); throw new RestWebApplicationException(Status.INTERNAL_SERVER_ERROR, ex.getMessage()); } finally { dataProvider.disconnect(); } }
From source file:com.portfolio.rest.RestServicePortfolio.java
@Path("/resources/portfolios/{portfolio-id}") @GET/*from w w w . j a va2 s. c om*/ @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public String getResources(@CookieParam("user") String user, @CookieParam("credential") String token, @QueryParam("group") int groupId, @PathParam("portfolio-id") String portfolioUuid, @Context ServletConfig sc, @Context HttpServletRequest httpServletRequest, @HeaderParam("Accept") String accept, @QueryParam("user") Integer userId) { UserInfo ui = checkCredential(httpServletRequest, user, token, null); try { String returnValue = dataProvider .getResources(new MimeType("text/xml"), portfolioUuid, ui.userId, groupId).toString(); if (accept.equals(MediaType.APPLICATION_JSON)) returnValue = XML.toJSONObject(returnValue).toString(); logRestRequest(httpServletRequest, null, returnValue, Status.OK.getStatusCode()); return returnValue; } catch (Exception ex) { ex.printStackTrace(); logRestRequest(httpServletRequest, null, ex.getMessage() + "\n\n" + javaUtils.getCompleteStackTrace(ex), Status.INTERNAL_SERVER_ERROR.getStatusCode()); throw new RestWebApplicationException(Status.INTERNAL_SERVER_ERROR, ex.getMessage()); } finally { dataProvider.disconnect(); } }
From source file:com.portfolio.rest.RestServicePortfolio.java
@Path("/resources/resource/{node-parent-uuid}") @PUT//w w w. j a va 2 s . c o m @Produces(MediaType.APPLICATION_XML) public String putResource(String xmlResource, @CookieParam("user") String user, @CookieParam("credential") String token, @QueryParam("group") int groupId, @PathParam("node-parent-uuid") String nodeParentUuid, @Context ServletConfig sc, @Context HttpServletRequest httpServletRequest, @QueryParam("user") Integer userId) { UserInfo ui = checkCredential(httpServletRequest, user, token, null); KEvent event = new KEvent(); event.requestType = KEvent.RequestType.POST; event.eventType = KEvent.EventType.NODE; event.uuid = nodeParentUuid; event.inputData = xmlResource; try { String returnValue = dataProvider .putResource(new MimeType("text/xml"), nodeParentUuid, xmlResource, ui.userId, groupId) .toString(); logRestRequest(httpServletRequest, xmlResource, returnValue, Status.OK.getStatusCode()); eventbus.processEvent(event); return returnValue; } catch (RestWebApplicationException ex) { ex.printStackTrace(); logRestRequest(httpServletRequest, xmlResource, ex.getMessage() + "\n\n" + javaUtils.getCompleteStackTrace(ex), Status.INTERNAL_SERVER_ERROR.getStatusCode()); throw ex; } catch (Exception ex) { ex.printStackTrace(); logRestRequest(httpServletRequest, xmlResource, ex.getMessage() + "\n\n" + javaUtils.getCompleteStackTrace(ex), Status.INTERNAL_SERVER_ERROR.getStatusCode()); throw new RestWebApplicationException(Status.INTERNAL_SERVER_ERROR, ex.getMessage()); } finally { dataProvider.disconnect(); } }
From source file:com.portfolio.rest.RestServicePortfolio.java
@Path("/resources/{node-parent-uuid}") @POST//from ww w .j a v a2s.c o m @Produces(MediaType.APPLICATION_XML) public String postResource(String xmlResource, @CookieParam("user") String user, @CookieParam("credential") String token, @QueryParam("group") int groupId, @PathParam("node-parent-uuid") String nodeParentUuid, @Context ServletConfig sc, @Context HttpServletRequest httpServletRequest, @QueryParam("user") Integer userId) { UserInfo ui = checkCredential(httpServletRequest, user, token, null); try { //TODO userId String returnValue = dataProvider .postResource(new MimeType("text/xml"), nodeParentUuid, xmlResource, ui.userId, groupId) .toString(); if (returnValue.equals("faux")) { throw new RestWebApplicationException(Status.FORBIDDEN, "Vous n'avez pas les droits necessaires"); } logRestRequest(httpServletRequest, xmlResource, returnValue, Status.OK.getStatusCode()); return returnValue; } catch (RestWebApplicationException ex) { throw new RestWebApplicationException(Status.FORBIDDEN, ex.getResponse().getEntity().toString()); } catch (Exception ex) { ex.printStackTrace(); logRestRequest(httpServletRequest, xmlResource, ex.getMessage() + "\n\n" + javaUtils.getCompleteStackTrace(ex), Status.INTERNAL_SERVER_ERROR.getStatusCode()); throw new RestWebApplicationException(Status.INTERNAL_SERVER_ERROR, ex.getMessage()); } finally { dataProvider.disconnect(); } }
From source file:com.portfolio.rest.RestServicePortfolio.java
@Path("/resources") @POST//from ww w . j a va 2s. c om @Produces(MediaType.APPLICATION_XML) public String postResource(String xmlResource, @CookieParam("user") String user, @CookieParam("credential") String token, @QueryParam("group") int groupId, @Context ServletConfig sc, @Context HttpServletRequest httpServletRequest, @QueryParam("type") Integer type, @QueryParam("resource") String resource, @QueryParam("user") Integer userId) { UserInfo ui = checkCredential(httpServletRequest, user, token, null); try { //TODO userId String returnValue = dataProvider .postResource(new MimeType("text/xml"), resource, xmlResource, ui.userId, groupId).toString(); if (returnValue.equals("faux")) { throw new RestWebApplicationException(Status.FORBIDDEN, "Vous n'avez pas les droits necessaires"); } logRestRequest(httpServletRequest, xmlResource, returnValue, Status.OK.getStatusCode()); return returnValue; } catch (RestWebApplicationException ex) { throw new RestWebApplicationException(Status.FORBIDDEN, ex.getResponse().getEntity().toString()); } catch (Exception ex) { ex.printStackTrace(); logRestRequest(httpServletRequest, xmlResource, ex.getMessage() + "\n\n" + javaUtils.getCompleteStackTrace(ex), Status.INTERNAL_SERVER_ERROR.getStatusCode()); throw new RestWebApplicationException(Status.INTERNAL_SERVER_ERROR, ex.getMessage()); } finally { dataProvider.disconnect(); } }
From source file:com.portfolio.rest.RestServicePortfolio.java
@Path("/roles/portfolio/{portfolio-id}") @GET//w w w.ja va 2s.c o m @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public String getRolePortfolio(@CookieParam("user") String user, @CookieParam("credential") String token, @QueryParam("group") int groupId, @QueryParam("role") String role, @PathParam("portfolio-id") String portfolioId, @Context ServletConfig sc, @Context HttpServletRequest httpServletRequest, @HeaderParam("Accept") String accept) { UserInfo ui = checkCredential(httpServletRequest, user, token, null); try { String returnValue = dataProvider .getRolePortfolio(new MimeType("text/xml"), role, portfolioId, ui.userId).toString(); // if(accept.equals(MediaType.APPLICATION_JSON)) // returnValue = XML.toJSONObject(returnValue).toString(); logRestRequest(httpServletRequest, null, returnValue, Status.OK.getStatusCode()); return returnValue; } catch (Exception ex) { ex.printStackTrace(); logRestRequest(httpServletRequest, null, ex.getMessage() + "\n\n" + javaUtils.getCompleteStackTrace(ex), Status.INTERNAL_SERVER_ERROR.getStatusCode()); throw new RestWebApplicationException(Status.INTERNAL_SERVER_ERROR, ex.getMessage()); } finally { dataProvider.disconnect(); } }
From source file:com.portfolio.rest.RestServicePortfolio.java
@Path("/roles/role/{role-id}") @GET/*from w ww . j a v a 2s.c o m*/ @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public String getRole(@CookieParam("user") String user, @CookieParam("credential") String token, @QueryParam("group") int groupId, @PathParam("role-id") Integer roleId, @Context ServletConfig sc, @Context HttpServletRequest httpServletRequest, @HeaderParam("Accept") String accept) { UserInfo ui = checkCredential(httpServletRequest, user, token, null); try { String returnValue = dataProvider.getRole(new MimeType("text/xml"), roleId, ui.userId).toString(); if (returnValue.equals("")) { logRestRequest(httpServletRequest, null, null, Status.NOT_FOUND.getStatusCode()); throw new RestWebApplicationException(Status.NOT_FOUND, "Role " + roleId + " not found"); } // if(accept.equals(MediaType.APPLICATION_JSON)) // returnValue = XML.toJSONObject(returnValue).toString(); logRestRequest(httpServletRequest, null, returnValue, Status.OK.getStatusCode()); return returnValue; } catch (RestWebApplicationException ex) { logRestRequest(httpServletRequest, null, null, Status.NOT_FOUND.getStatusCode()); throw new RestWebApplicationException(Status.NOT_FOUND, "Role " + roleId + " not found"); } catch (Exception ex) { ex.printStackTrace(); logRestRequest(httpServletRequest, null, ex.getMessage() + "\n\n" + javaUtils.getCompleteStackTrace(ex), Status.INTERNAL_SERVER_ERROR.getStatusCode()); throw new RestWebApplicationException(Status.INTERNAL_SERVER_ERROR, ex.getMessage()); } finally { dataProvider.disconnect(); } }
From source file:com.portfolio.rest.RestServicePortfolio.java
@Path("/models") @GET//from ww w .j av a 2 s .c o m @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public String getModels(@CookieParam("user") String user, @CookieParam("credential") String token, @QueryParam("group") int groupId, @Context ServletConfig sc, @Context HttpServletRequest httpServletRequest, @HeaderParam("Accept") String accept) { UserInfo ui = checkCredential(httpServletRequest, user, token, null); try { String returnValue = dataProvider.getModels(new MimeType("text/xml"), ui.userId).toString(); if (returnValue.equals("")) { logRestRequest(httpServletRequest, null, null, Status.NOT_FOUND.getStatusCode()); throw new RestWebApplicationException(Status.NOT_FOUND, "Role " + " not found"); } // if(accept.equals(MediaType.APPLICATION_JSON)) // returnValue = XML.toJSONObject(returnValue).toString(); logRestRequest(httpServletRequest, null, returnValue, Status.OK.getStatusCode()); return returnValue; } catch (RestWebApplicationException ex) { logRestRequest(httpServletRequest, null, null, Status.NOT_FOUND.getStatusCode()); throw new RestWebApplicationException(Status.NOT_FOUND, "Role " + " not found"); } catch (Exception ex) { ex.printStackTrace(); logRestRequest(httpServletRequest, null, ex.getMessage() + "\n\n" + javaUtils.getCompleteStackTrace(ex), Status.INTERNAL_SERVER_ERROR.getStatusCode()); throw new RestWebApplicationException(Status.INTERNAL_SERVER_ERROR, ex.getMessage()); } finally { dataProvider.disconnect(); } }
From source file:com.portfolio.rest.RestServicePortfolio.java
@Path("/models/{model-id}") @GET/* ww w. ja va 2 s . c o m*/ @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public String getModel(@CookieParam("user") String user, @CookieParam("credential") String token, @QueryParam("group") int groupId, @PathParam("model-id") Integer modelId, @Context ServletConfig sc, @Context HttpServletRequest httpServletRequest, @HeaderParam("Accept") String accept) { UserInfo ui = checkCredential(httpServletRequest, user, token, null); try { String returnValue = dataProvider.getModel(new MimeType("text/xml"), modelId, ui.userId).toString(); if (returnValue.equals("")) { logRestRequest(httpServletRequest, null, null, Status.NOT_FOUND.getStatusCode()); throw new RestWebApplicationException(Status.NOT_FOUND, "Role " + " not found"); } // if(accept.equals(MediaType.APPLICATION_JSON)) // returnValue = XML.toJSONObject(returnValue).toString(); logRestRequest(httpServletRequest, null, returnValue, Status.OK.getStatusCode()); return returnValue; } catch (RestWebApplicationException ex) { logRestRequest(httpServletRequest, null, null, Status.NOT_FOUND.getStatusCode()); throw new RestWebApplicationException(Status.NOT_FOUND, "Role " + " not found"); } catch (Exception ex) { ex.printStackTrace(); logRestRequest(httpServletRequest, null, ex.getMessage() + "\n\n" + javaUtils.getCompleteStackTrace(ex), Status.INTERNAL_SERVER_ERROR.getStatusCode()); throw new RestWebApplicationException(Status.INTERNAL_SERVER_ERROR, ex.getMessage()); } finally { dataProvider.disconnect(); } }
From source file:com.portfolio.rest.RestServicePortfolio.java
@Path("/models") @POST/*from w w w . j a v a 2 s .com*/ @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public String postModel(String xmlModel, @CookieParam("user") String user, @CookieParam("credential") String token, @QueryParam("group") int groupId, @Context ServletConfig sc, @Context HttpServletRequest httpServletRequest, @HeaderParam("Accept") String accept) { UserInfo ui = checkCredential(httpServletRequest, user, token, null); try { String returnValue = dataProvider.postModels(new MimeType("text/xml"), xmlModel, ui.userId).toString(); if (returnValue.equals("")) { logRestRequest(httpServletRequest, null, null, Status.NOT_FOUND.getStatusCode()); throw new RestWebApplicationException(Status.NOT_FOUND, "Role " + " not found"); } // if(accept.equals(MediaType.APPLICATION_JSON)) // returnValue = XML.toJSONObject(returnValue).toString(); logRestRequest(httpServletRequest, null, returnValue, Status.OK.getStatusCode()); return returnValue; } catch (RestWebApplicationException ex) { logRestRequest(httpServletRequest, null, null, Status.NOT_FOUND.getStatusCode()); throw new RestWebApplicationException(Status.NOT_FOUND, "Role " + " not found"); } catch (Exception ex) { ex.printStackTrace(); logRestRequest(httpServletRequest, null, ex.getMessage() + "\n\n" + javaUtils.getCompleteStackTrace(ex), Status.INTERNAL_SERVER_ERROR.getStatusCode()); throw new RestWebApplicationException(Status.INTERNAL_SERVER_ERROR, ex.getMessage()); } finally { dataProvider.disconnect(); } }