Project

General

Profile

« Previous | Next » 

Revision 1cb9d1f1

Added by Andreas Kohlbecker over 10 years ago

fixing #3974: NPE in MediaController.doGetMediaMetaData()

View differences:

cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/BaseController.java
45 45
import eu.etaxonomy.cdm.model.reference.INomenclaturalReference;
46 46
import eu.etaxonomy.cdm.remote.controller.util.PagerParameters;
47 47
import eu.etaxonomy.cdm.remote.editor.UUIDPropertyEditor;
48
import eu.etaxonomy.cdm.remote.exception.NoRecordsMatchException;
48 49

  
49 50
/**
50 51
 * based on org.cateproject.controller.common
......
284 285
        CDM_BASE cdmBaseObject = service.load(uuid, pathProperties);
285 286
        if (cdmBaseObject == null) {
286 287
            HttpStatusMessage.UUID_NOT_FOUND.send(response);
288
            throw new NoRecordsMatchException("No instance found for UUID " + uuid.toString());
287 289
        }
288 290
        return cdmBaseObject;
289 291
        }
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/HttpStatusMessage.java
36 36

  
37 37
    private int statusCode;
38 38

  
39
    private String message;
39
    private final String message;
40 40

  
41
    private  String statusMessage;
41
    private final  String statusMessage;
42 42

  
43 43
    private static Hashtable<String , HttpStatusMessage> cache;
44 44

  
......
65 65
        return message;
66 66
    }
67 67

  
68
    @Override
68 69
    public String toString() {
69 70
        return statusMessage;
70 71
    }
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/MediaController.java
32 32
import eu.etaxonomy.cdm.common.media.ImageInfo;
33 33
import eu.etaxonomy.cdm.model.media.Media;
34 34
import eu.etaxonomy.cdm.model.media.MediaRepresentation;
35
import eu.etaxonomy.cdm.remote.exception.NoRecordsMatchException;
35 36

  
36 37
/**
37 38
 * TODO write controller documentation
......
63 64
    public ModelAndView doGetMediaMetaData(@PathVariable("uuid") UUID uuid,
64 65
            HttpServletRequest request, HttpServletResponse response) throws IOException {
65 66
        Map<String, String> result;
66
        Media media = getCdmBaseInstance(uuid, response, MEDIA_INIT_STRATEGY);
67 67

  
68
        Set<MediaRepresentation> representations = media.getRepresentations();
69
        //get first representation and retrieve the according metadata
70

  
71
        Object[] repArray = representations.toArray();
72
        Object mediaRep = repArray[0];
73 68
        ModelAndView mv = new ModelAndView();
74
        URI uri = null;
75
        try {
76
            if (mediaRep instanceof MediaRepresentation){
77
                MediaRepresentation medRep = (MediaRepresentation) mediaRep;
78
                uri = medRep.getParts().get(0).getUri();
79
                ImageInfo imageInfo = ImageInfo.NewInstanceWithMetaData(uri, 3000);
80
                result = imageInfo.getMetaData();
81
                if(result != null) {
82
                    mv.addObject(result);
69
        try{
70
            Media media = getCdmBaseInstance(uuid, response, MEDIA_INIT_STRATEGY);
71

  
72
            Set<MediaRepresentation> representations = media.getRepresentations();
73
            //get first representation and retrieve the according metadata
74

  
75
            Object[] repArray = representations.toArray();
76
            Object mediaRep = repArray[0];
77
            URI uri = null;
78
            try {
79
                if (mediaRep instanceof MediaRepresentation){
80
                    MediaRepresentation medRep = (MediaRepresentation) mediaRep;
81
                    uri = medRep.getParts().get(0).getUri();
82
                    ImageInfo imageInfo = ImageInfo.NewInstanceWithMetaData(uri, 3000);
83
                    result = imageInfo.getMetaData();
84
                    if(result != null) {
85
                        mv.addObject(result);
86
                    }
83 87
                }
88
            } catch (HttpException e) {
89
                HttpStatusMessage.fromString("Reading media file from " + uri.toString() + " failed").setStatusCode(400).send(response);
84 90
            }
85
        } catch (HttpException e) {
86
            HttpStatusMessage.fromString("Reading media file from " + uri.toString() + " failed").setStatusCode(400).send(response);
91
        } catch (NoRecordsMatchException e){
92
           /* IGNORE */
93
           /* java.lang.IllegalStateException: STREAM is thrown by the servlet container
94
            * if the model and view is returned after the http error has been send
95
            * so we return null here
96
            */
97
            return null;
98

  
87 99
        }
88 100
        return mv;
89 101

  

Also available in: Unified diff