Example usage for javax.activation MimeType MimeType

List of usage examples for javax.activation MimeType MimeType

Introduction

In this page you can find the example usage for javax.activation MimeType MimeType.

Prototype

public MimeType(String rawdata) throws MimeTypeParseException 

Source Link

Document

Constructor that builds a MimeType from a String.

Usage

From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswEndpoint.java

private CswRecordCollection queryProductById(String id, String rangeValue)
        throws CswException, UnsupportedQueryException {

    final ResourceRequestById resourceRequest = new ResourceRequestById(id);

    long bytesToSkip = getRange(rangeValue);
    if (bytesToSkip > 0) {
        LOGGER.debug("Bytes to skip: {}", String.valueOf(bytesToSkip));
        resourceRequest.getProperties().put(CswConstants.BYTES_TO_SKIP, bytesToSkip);
    }//  w  w  w.j  av  a2s. c  om
    ResourceResponse resourceResponse;
    try {
        resourceResponse = framework.getLocalResource(resourceRequest);
    } catch (IOException | ResourceNotFoundException | ResourceNotSupportedException e) {
        throw new CswException(String.format(ERROR_ID_PRODUCT_RETRIEVAL, id), e);
    }

    Resource resource = resourceResponse.getResource();
    MimeType mimeType = resource.getMimeType();
    if (mimeType == null) {
        try {
            mimeType = new MimeType(MediaType.APPLICATION_OCTET_STREAM);
            resource = new ResourceImpl(resource.getInputStream(), mimeType, resource.getName());
        } catch (MimeTypeParseException e) {
            throw new CswException(String.format("Could not create mime type upon null mimeType, for mime %s.",
                    MediaType.APPLICATION_OCTET_STREAM), e);
        }
    }
    CswRecordCollection cswRecordCollection = new CswRecordCollection();
    cswRecordCollection.setResource(resource);
    cswRecordCollection.setOutputSchema(OCTET_STREAM_OUTPUT_SCHEMA);
    LOGGER.debug("{} successfully retrieved product for ID: {}", id);
    return cswRecordCollection;
}

From source file:com.portfolio.rest.RestServicePortfolio.java

@Path("/portfolios")
@POST/*from   ww w  .j  ava 2 s .com*/
@Consumes(MediaType.APPLICATION_XML)
@Produces(MediaType.APPLICATION_XML)
public String postPortfolio(String xmlPortfolio, @CookieParam("user") String user,
        @CookieParam("credential") String token, @QueryParam("group") int groupId, @Context ServletConfig sc,
        @Context HttpServletRequest httpServletRequest, @QueryParam("user") Integer userId,
        @QueryParam("model") String modelId) {
    UserInfo ui = checkCredential(httpServletRequest, user, token, null);

    try {
        String returnValue = dataProvider.postPortfolio(new MimeType("text/xml"), new MimeType("text/xml"),
                xmlPortfolio, ui.userId, groupId, modelId, ui.subId).toString();
        logRestRequest(httpServletRequest, xmlPortfolio, returnValue, Status.OK.getStatusCode());

        return returnValue;
    } catch (RestWebApplicationException ex) {
        logRestRequest(httpServletRequest, null, null, ex.getResponse().getStatus());

        throw new RestWebApplicationException(ex.getStatus(), ex.getCustomMessage());
    } catch (Exception ex) {
        ex.printStackTrace();
        logRestRequest(httpServletRequest, xmlPortfolio,
                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("/portfolios/zip")
@POST//from   w  ww . j a  v  a2 s .c om
@Consumes("application/zip") // Envoie donne brut
public String postPortfolioZip(@CookieParam("user") String user, @CookieParam("credential") String token,
        @QueryParam("group") int groupId, @Context ServletConfig sc,
        @Context HttpServletRequest httpServletRequest, @QueryParam("user") Integer userId,
        @QueryParam("model") String modelId) {
    UserInfo ui = checkCredential(httpServletRequest, user, token, null);

    try {
        String returnValue = dataProvider.postPortfolioZip(new MimeType("text/xml"), new MimeType("text/xml"),
                httpServletRequest, ui.userId, groupId, modelId, ui.subId).toString();
        logRestRequest(httpServletRequest, returnValue, returnValue, Status.OK.getStatusCode());

        return returnValue;
    } catch (Exception ex) {
        ex.printStackTrace();
        logRestRequest(httpServletRequest, ex.getMessage() + "\n\n" + javaUtils.getCompleteStackTrace(ex),
                modelId, 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("/nodes/node/{node-id}")
@GET//from   w ww  .  j ava  2 s . co m
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Consumes(MediaType.APPLICATION_XML)
public String getNode(@CookieParam("user") String user, @CookieParam("credential") String token,
        @QueryParam("group") int groupId, @PathParam("node-id") String nodeUuid, @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
                .getNode(new MimeType("text/xml"), nodeUuid, false, ui.userId, groupId, this.label).toString();
        if (returnValue.length() != 0) {
            if (accept.equals(MediaType.APPLICATION_JSON))
                returnValue = XML.toJSONObject(returnValue).toString();
            logRestRequest(httpServletRequest, null, returnValue, Status.OK.getStatusCode());
        } else {
            throw new RestWebApplicationException(Status.FORBIDDEN, "Vous n'avez pas les droits necessaires");
        }

        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, "Node " + nodeUuid + " not found");
    } catch (NullPointerException ex) {
        logRestRequest(httpServletRequest, null, null, Status.NOT_FOUND.getStatusCode());

        throw new RestWebApplicationException(Status.NOT_FOUND, "Node " + nodeUuid + " 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("/nodes/node/{node-id}/children")
@GET/*from w  w  w  .jav a2 s  . c  o m*/
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Consumes(MediaType.APPLICATION_XML)
public String getNodeWithChildren(@CookieParam("user") String user, @CookieParam("credential") String token,
        @QueryParam("group") int groupId, @PathParam("node-id") String nodeUuid, @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
                .getNode(new MimeType("text/xml"), nodeUuid, true, ui.userId, groupId, this.label).toString();
        if (returnValue.length() != 0) {
            if (accept.equals(MediaType.APPLICATION_JSON))
                returnValue = XML.toJSONObject(returnValue).toString();
            logRestRequest(httpServletRequest, null, returnValue, Status.OK.getStatusCode());

            return returnValue;
        } else {
            throw new RestWebApplicationException(Status.FORBIDDEN, "Vous n'avez pas les droits necessaires");
        }
    } 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, "Node " + nodeUuid + " 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("/nodes/node/{nodeid}/metadatawad")
@GET/*ww  w . ja  va  2 s  .c o m*/
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Consumes(MediaType.APPLICATION_XML)
public String getNodeMetadataWad(@CookieParam("user") String user, @CookieParam("credential") String token,
        @QueryParam("group") int groupId, @PathParam("nodeid") String nodeUuid, @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
                .getNodeMetadataWad(new MimeType("text/xml"), nodeUuid, true, ui.userId, groupId, this.label)
                .toString();
        if (returnValue.length() != 0) {
            if (accept.equals(MediaType.APPLICATION_JSON))
                returnValue = XML.toJSONObject(returnValue).toString();
            logRestRequest(httpServletRequest, null, returnValue, Status.OK.getStatusCode());

            return returnValue;
        } else {
            throw new RestWebApplicationException(Status.FORBIDDEN, "Vous n'avez pas les droits necessaires");
        }
    } catch (RestWebApplicationException ex) {
        throw new RestWebApplicationException(Status.FORBIDDEN, ex.getResponse().getEntity().toString());
    } 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.data.provider.MysqlAdminProvider.java

@Override
public Object getPortfolioByCode(MimeType mimeType, String portfolioCode, int userId, int groupId,
        String resources) throws Exception {
    PreparedStatement st = null;//from   w w  w .  j  a  v  a  2 s. c  o  m
    String sql;
    ResultSet res = null;
    String pid = this.getPortfolioUuidByPortfolioCode(portfolioCode);
    Boolean withResources = false;
    String result = "";

    try {
        withResources = Boolean.parseBoolean(resources);

    } catch (Exception ex) {
    }

    if (withResources) {

        return this.getPortfolio(new MimeType("text/xml"), pid, userId, groupId, null, null, null).toString();
    } else {
        try {
            sql = "SELECT  bin2uuid(portfolio_id) AS portfolio_id,bin2uuid(root_node_uuid) as root_node_uuid, modif_user_id,modif_date, active, user_id "
                    + "FROM portfolio " + "WHERE portfolio_id = uuid2bin(?) ";
            st = connection.prepareStatement(sql);
            st.setString(1, pid);
            res = st.executeQuery();

        } catch (Exception e) {
            e.printStackTrace();
        }

        if (res.next()) {
            result += "<portfolio ";
            result += DomUtils.getXmlAttributeOutput("id", res.getString("portfolio_id")) + " ";
            result += DomUtils.getXmlAttributeOutput("root_node_id", res.getString("root_node_uuid")) + " ";
            result += ">";
            result += getNodeXmlOutput(res.getString("root_node_uuid"), false, "nodeRes", userId, groupId, null,
                    false);
            result += "</portfolio>";
        }
    }

    return result;
}

From source file:com.portfolio.data.provider.MysqlDataProvider.java

@Override
public Object getPortfolioByCode(MimeType mimeType, String portfolioCode, int userId, int groupId,
        String resources, int substid) throws Exception {
    //return this.getPortfolio(mimeType, this.getPortfolioUuidByPortfolioCode(portfolioCode), userId, groupId, null);

    PreparedStatement st = null;/*from   ww w  . j a  v a  2  s . c  o  m*/
    String sql;
    ResultSet res = null;
    String pid = this.getPortfolioUuidByPortfolioCode(portfolioCode);
    Boolean withResources = false;
    String result = "";

    try {
        withResources = Boolean.parseBoolean(resources);
    } catch (Exception ex) {
    }

    if (withResources) {
        return this.getPortfolio(new MimeType("text/xml"), pid, userId, groupId, null, null, null, substid)
                .toString();
    } else {
        try {
            sql = "SELECT  bin2uuid(portfolio_id) AS portfolio_id,bin2uuid(root_node_uuid) as root_node_uuid, modif_user_id,modif_date, active, user_id "
                    + "FROM portfolio " + "WHERE portfolio_id = uuid2bin(?) ";
            st = connection.prepareStatement(sql);
            st.setString(1, pid);
            res = st.executeQuery();
        } catch (Exception e) {
            e.printStackTrace();
        }

        if (res.next()) {
            result += "<portfolio ";
            result += DomUtils.getXmlAttributeOutput("id", res.getString("portfolio_id")) + " ";
            result += DomUtils.getXmlAttributeOutput("root_node_id", res.getString("root_node_uuid")) + " ";
            result += ">";
            result += getNodeXmlOutput(res.getString("root_node_uuid"), false, "nodeRes", userId, groupId, null,
                    false);
            result += "</portfolio>";
        }
    }

    return result;
}

From source file:com.portfolio.rest.RestServicePortfolio.java

@Path("/nodes/firstbysemantictag/{portfolio-uuid}/{semantictag}")
@GET//from   w  w w .  j  a  v  a2  s  .  c  o  m
@Produces({ MediaType.APPLICATION_XML })
@Consumes(MediaType.APPLICATION_XML)
public String getNodeBySemanticTag(@CookieParam("user") String user, @CookieParam("credential") String token,
        @QueryParam("group") int groupId, @PathParam("portfolio-uuid") String portfolioUuid,
        @PathParam("semantictag") String semantictag, @Context ServletConfig sc,
        @Context HttpServletRequest httpServletRequest, @HeaderParam("Accept") String accept) {
    UserInfo ui = checkCredential(httpServletRequest, user, token, null);

    try {
        String returnValue = dataProvider
                .getNodeBySemanticTag(new MimeType("text/xml"), portfolioUuid, semantictag, ui.userId, groupId)
                .toString();
        if (returnValue.length() != 0) {
            logRestRequest(httpServletRequest, null, returnValue, Status.OK.getStatusCode());

            return returnValue;
        } else {
            throw new RestWebApplicationException(Status.FORBIDDEN, "Vous n'avez pas les droits necessaires");
        }
    } catch (RestWebApplicationException ex) {
        throw new RestWebApplicationException(Status.FORBIDDEN, "Vous n'avez pas les droits necessaires");
    } 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("/nodes/bysemantictag/{portfolio-uuid}/{semantictag}")
@GET/*from   w w  w .j a va2  s . c  o  m*/
@Produces({ MediaType.APPLICATION_XML })
@Consumes(MediaType.APPLICATION_XML)
public String getNodesBySemanticTag(@CookieParam("user") String user, @CookieParam("credential") String token,
        @QueryParam("group") int groupId, @PathParam("portfolio-uuid") String portfolioUuid,
        @PathParam("semantictag") String semantictag, @Context ServletConfig sc,
        @Context HttpServletRequest httpServletRequest, @HeaderParam("Accept") String accept) {
    UserInfo ui = checkCredential(httpServletRequest, user, token, null);

    try {
        String returnValue = dataProvider
                .getNodesBySemanticTag(new MimeType("text/xml"), ui.userId, groupId, portfolioUuid, semantictag)
                .toString();
        if (returnValue.length() != 0) {
            logRestRequest(httpServletRequest, null, returnValue, Status.OK.getStatusCode());

            return returnValue;
        } else {

            throw new RestWebApplicationException(Status.FORBIDDEN, "Vous n'avez pas les droits necessaires");
        }
    } catch (RestWebApplicationException ex) {
        throw new RestWebApplicationException(Status.FORBIDDEN, ex.getResponse().getEntity().toString());
    } 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();
    }
}