Mercurial > hg > digilib-old
comparison servlet/src/digilib/servlet/Scaler.java @ 502:157d4c7d2343 digilibPDF
readded support for direct sending of image files
author | cmielack |
---|---|
date | Mon, 23 Feb 2009 16:03:06 +0100 |
parents | d960b7c68b08 |
children | fdb824bd57ab |
comparison
equal
deleted
inserted
replaced
501:d960b7c68b08 | 502:157d4c7d2343 |
---|---|
20 import digilib.auth.AuthOpException; | 20 import digilib.auth.AuthOpException; |
21 import digilib.auth.AuthOps; | 21 import digilib.auth.AuthOps; |
22 import digilib.image.ImageOpException; | 22 import digilib.image.ImageOpException; |
23 import digilib.io.DocuDirCache; | 23 import digilib.io.DocuDirCache; |
24 import digilib.io.DocuDirent; | 24 import digilib.io.DocuDirent; |
25 import digilib.io.FileOpException; | |
25 import digilib.io.FileOps; | 26 import digilib.io.FileOps; |
26 import digilib.io.ImageFile; | 27 import digilib.io.ImageFile; |
27 import digilib.io.ImageFileset; | 28 import digilib.io.ImageFileset; |
28 | 29 |
29 public class Scaler extends RequestHandler { | 30 public class Scaler extends RequestHandler { |
123 | 124 |
124 if (dlConfig == null) { | 125 if (dlConfig == null) { |
125 throw new ServletException("ERROR: No Configuration!"); | 126 throw new ServletException("ERROR: No Configuration!"); |
126 } | 127 } |
127 | 128 |
129 | |
130 | |
128 accountlog.debug("request: " + request.getQueryString()); | 131 accountlog.debug("request: " + request.getQueryString()); |
129 logger.debug("request: " + request.getQueryString()); | 132 logger.debug("request: " + request.getQueryString()); |
130 | 133 |
131 | 134 |
132 | 135 |
133 // define the job information | 136 // define the job information |
134 ImageJobInformation jobdeclaration = new ImageJobInformation(); | 137 ImageJobInformation jobdeclaration = new ImageJobInformation(); |
135 | |
136 jobdeclaration.setWithRequest(request); | 138 jobdeclaration.setWithRequest(request); |
137 jobdeclaration.setConfig(dlConfig); | 139 jobdeclaration.setConfig(dlConfig); |
138 | 140 |
139 | 141 ImageFile fileToLoad = null; |
140 | 142 try { |
141 | 143 fileToLoad = jobdeclaration.get_fileToLoad(); |
142 // TODO check, if file can be sent without transformations | 144 } catch (IOException e2) { |
143 | 145 // TODO Auto-generated catch block |
144 | 146 e2.printStackTrace(); |
147 return; | |
148 } | |
149 | |
150 | |
151 // if requested, send image as a file | |
152 if(sendFileAllowed && jobdeclaration.checkSendAsFile()){ | |
153 String mt = null; | |
154 if (jobdeclaration.hasOption("mo", "rawfile")) { | |
155 mt = "application/octet-stream"; | |
156 } | |
157 logger.debug("Sending RAW File as is."); | |
158 try { | |
159 ServletOps.sendFile(fileToLoad.getFile(), mt, response); | |
160 } catch (FileOpException e) { | |
161 e.printStackTrace(); | |
162 } | |
163 | |
164 return; | |
165 } | |
166 | |
167 | |
168 | |
169 // if possible, send the image without actually having to transform it | |
170 if(jobdeclaration.noTransformRequired()){ | |
171 logger.debug("Sending File as is."); | |
172 | |
173 try { | |
174 ServletOps.sendFile(fileToLoad.getFile(), null, response); | |
175 } catch (FileOpException e) { | |
176 e.printStackTrace(); | |
177 } | |
178 | |
179 //logger.info("Done in " | |
180 // + (System.currentTimeMillis() - startTime) + "ms"); | |
181 return; | |
182 } | |
183 | |
184 | |
145 | 185 |
146 | 186 |
147 OutputStream outputstream = null; | 187 OutputStream outputstream = null; |
148 try { | 188 try { |
149 outputstream = response.getOutputStream(); | 189 outputstream = response.getOutputStream(); |
150 } catch (IOException e1) { | 190 } catch (IOException e1) { |
151 // TODO Auto-generated catch block | 191 // TODO Auto-generated catch block |
152 e1.printStackTrace(); | 192 e1.printStackTrace(); |
153 logger.error(e1.getMessage()); | 193 logger.error(e1.getMessage()); |
154 } | 194 } |
195 | |
196 | |
197 | |
198 | |
199 if (! DigilibWorker.canRun()) { | |
200 logger.error("Servlet overloaded!"); | |
201 try { | |
202 response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE); | |
203 } catch (IOException e) { | |
204 e.printStackTrace(); | |
205 } | |
206 return; | |
207 } | |
208 | |
209 | |
210 | |
155 | 211 |
156 | 212 |
157 DigilibWorker job=null; | 213 DigilibWorker job=null; |
158 try { | 214 try { |
159 | 215 |
209 | 265 |
210 try { | 266 try { |
211 outputstream.flush(); | 267 outputstream.flush(); |
212 logger.debug("Job Processing Time: "+ (System.currentTimeMillis()-startTime) + "ms"); | 268 logger.debug("Job Processing Time: "+ (System.currentTimeMillis()-startTime) + "ms"); |
213 } catch (IOException e) { | 269 } catch (IOException e) { |
214 // TODO Auto-generated catch block | |
215 e.printStackTrace(); | 270 e.printStackTrace(); |
216 logger.error(e.getMessage()); | 271 logger.error(e.getMessage()); |
217 response.sendError(1); | 272 response.sendError(1); |
218 } | 273 } |
219 | 274 |