Ignore:
Timestamp:
01/06/14 17:20:05 (10 years ago)
Author:
olhsha
Message:

files INSTALL, UPDATED, CHANGES and README are corrected. The bug with the wrong server diagnostic (403 instead of 404), when a resource's give id is not found, is fixed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/CachedRepresentationResource.java

    r4207 r4217  
    2929import javax.imageio.ImageIO;
    3030import javax.servlet.http.HttpServletRequest;
     31import javax.servlet.http.HttpServletResponse;
    3132import javax.ws.rs.GET;
    3233import javax.ws.rs.Path;
     
    4950@Component
    5051@Path("/cached")
    51 @Transactional(rollbackFor={Exception.class, SQLException.class, IOException.class, ParserConfigurationException.class})
     52@Transactional(rollbackFor = {Exception.class, SQLException.class, IOException.class, ParserConfigurationException.class})
    5253public class CachedRepresentationResource {
    5354
     
    5657    @Context
    5758    private HttpServletRequest httpServletRequest;
     59    @Context
     60    private HttpServletResponse httpServletResponse;
    5861    @Context
    5962    private UriInfo uriInfo;
     
    6871    @Produces(MediaType.TEXT_XML)
    6972    @Path("{cachedid: " + BackendConstants.regExpIdentifier + "}/metadata")
    70     @Secured("ROLE_USER")   
    71     @Transactional(readOnly=true)
    72     public JAXBElement<CachedRepresentationInfo> getCachedRepresentationInfo(@PathParam("cachedid") String externalId) throws SQLException {
     73    @Secured("ROLE_USER")
     74    @Transactional(readOnly = true)
     75    public JAXBElement<CachedRepresentationInfo> getCachedRepresentationInfo(@PathParam("cachedid") String externalId) throws SQLException, IOException {
    7376        dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
    7477        final Number cachedID = dbIntegrityService.getCachedRepresentationInternalIdentifier(UUID.fromString(externalId));
    75         final CachedRepresentationInfo cachedInfo = dbIntegrityService.getCachedRepresentationInfo(cachedID);
    76         return new ObjectFactory().createCashedRepresentationInfo(cachedInfo);
     78        if (cachedID != null) {
     79            final CachedRepresentationInfo cachedInfo = dbIntegrityService.getCachedRepresentationInfo(cachedID);
     80            return new ObjectFactory().createCashedRepresentationInfo(cachedInfo);
     81        } else {
     82            httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The cached representation with the given id is not found in the database");
     83            return null;
     84        }
    7785    }
    7886
     
    8088    @Produces({"image/jpeg", "image/png"})
    8189    @Path("{cachedid: " + BackendConstants.regExpIdentifier + "}/content")
    82     @Secured("ROLE_USER")   
    83     @Transactional(readOnly=true)
     90    @Secured("ROLE_USER")
     91    @Transactional(readOnly = true)
    8492    public BufferedImage getCachedRepresentationContent(@PathParam("cachedid") String externalId) throws SQLException, IOException {
    8593        dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
    8694        final Number cachedID = dbIntegrityService.getCachedRepresentationInternalIdentifier(UUID.fromString(externalId));
    87         InputStream dbRespond = dbIntegrityService.getCachedRepresentationBlob(cachedID);
    88         ImageIO.setUseCache(false);
    89         BufferedImage result = ImageIO.read(dbRespond);
    90         return result;
     95        if (cachedID != null) {
     96            InputStream dbRespond = dbIntegrityService.getCachedRepresentationBlob(cachedID);
     97            ImageIO.setUseCache(false);
     98            BufferedImage result = ImageIO.read(dbRespond);
     99            return result;
     100        } else {
     101            httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The cached representation  with the given id is not found in the database");
     102            return null;
     103        }
    91104    }
    92    
    93    
    94105}
Note: See TracChangeset for help on using the changeset viewer.