Revision 1cb9d1f1
Added by Andreas Kohlbecker over 10 years ago
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
fixing #3974: NPE in MediaController.doGetMediaMetaData()