Mercurial > hg > digilib-old
annotate servlet/src/digilib/servlet/Scaler.java @ 543:919e008ab1fb digilibPDF
more steps towards more standard java.util.concurrent design
author | robcast |
---|---|
date | Thu, 14 Oct 2010 14:24:33 +0200 |
parents | e2ff961001af |
children | 5ff500d6812a |
rev | line source |
---|---|
1 | 1 package digilib.servlet; |
2 | |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
3 import java.io.File; |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
4 import java.io.IOException; |
500 | 5 import java.io.OutputStream; |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
6 import java.util.List; |
543
919e008ab1fb
more steps towards more standard java.util.concurrent design
robcast
parents:
542
diff
changeset
|
7 import java.util.concurrent.ExecutionException; |
919e008ab1fb
more steps towards more standard java.util.concurrent design
robcast
parents:
542
diff
changeset
|
8 import java.util.concurrent.ExecutorService; |
919e008ab1fb
more steps towards more standard java.util.concurrent design
robcast
parents:
542
diff
changeset
|
9 import java.util.concurrent.Future; |
1 | 10 |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
11 import javax.servlet.ServletConfig; |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
12 import javax.servlet.ServletContext; |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
13 import javax.servlet.ServletException; |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
14 import javax.servlet.http.HttpServletRequest; |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
15 import javax.servlet.http.HttpServletResponse; |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
16 |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
17 import digilib.auth.AuthOpException; |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
18 import digilib.auth.AuthOps; |
543
919e008ab1fb
more steps towards more standard java.util.concurrent design
robcast
parents:
542
diff
changeset
|
19 import digilib.image.DocuImage; |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
20 import digilib.image.ImageOpException; |
86 | 21 import digilib.io.DocuDirCache; |
335 | 22 import digilib.io.DocuDirectory; |
23 import digilib.io.DocuDirent; | |
181 | 24 import digilib.io.FileOpException; |
25 import digilib.io.FileOps; | |
161 | 26 import digilib.io.ImageFile; |
1 | 27 |
28 | |
511 | 29 // TODO digilibError is not used anymore and may need to get reintegrated |
1 | 30 |
500 | 31 public class Scaler extends RequestHandler { |
263 | 32 |
298
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
33 /** digilib servlet version (for all components) */ |
543
919e008ab1fb
more steps towards more standard java.util.concurrent design
robcast
parents:
542
diff
changeset
|
34 public static final String dlVersion = "1.8.1a"; |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
35 |
298
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
36 /** general error code */ |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
37 public static final int ERROR_UNKNOWN = 0; |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
38 |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
39 /** error code for authentication error */ |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
40 public static final int ERROR_AUTH = 1; |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
41 |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
42 /** error code for file operation error */ |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
43 public static final int ERROR_FILE = 2; |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
44 |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
45 /** error code for image operation error */ |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
46 public static final int ERROR_IMAGE = 3; |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
47 |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
48 /** DocuDirCache instance */ |
86 | 49 DocuDirCache dirCache; |
161 | 50 |
543
919e008ab1fb
more steps towards more standard java.util.concurrent design
robcast
parents:
542
diff
changeset
|
51 /** Image executor */ |
919e008ab1fb
more steps towards more standard java.util.concurrent design
robcast
parents:
542
diff
changeset
|
52 ExecutorService imageJobCenter; |
919e008ab1fb
more steps towards more standard java.util.concurrent design
robcast
parents:
542
diff
changeset
|
53 |
298
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
54 /** authentication error image file */ |
153 | 55 File denyImgFile; |
298
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
56 |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
57 /** image error image file */ |
153 | 58 File errorImgFile; |
298
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
59 |
363 | 60 /** not found error image file */ |
61 File notfoundImgFile; | |
62 | |
298
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
63 /** subsampling before scaling */ |
153 | 64 float minSubsample = 2f; |
298
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
65 |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
66 /** send files as is? */ |
153 | 67 boolean sendFileAllowed = true; |
298
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
68 |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
69 /** default scaling quality */ |
153 | 70 int defaultQuality = 1; |
1 | 71 |
298
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
72 /** DigilibConfiguration instance */ |
73 | 73 DigilibConfiguration dlConfig; |
1 | 74 |
298
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
75 /** use authorization database */ |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
76 boolean useAuthorization = true; |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
77 |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
78 /** AuthOps instance */ |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
79 AuthOps authOp; |
1 | 80 |
100 | 81 // EXPRIMENTAL |
298
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
82 /** try to enlarge cropping area for "oblique" angles */ |
100 | 83 boolean wholeRotArea = false; |
84 | |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
85 |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
86 protected long getLastModified(HttpServletRequest request) { |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
87 accountlog.debug("GetLastModified from " + request.getRemoteAddr() |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
88 + " for " + request.getQueryString()); |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
89 long mtime = -1; |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
90 // create new request with defaults |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
91 DigilibRequest dlReq = new DigilibRequest(); |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
92 // set with request parameters |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
93 dlReq.setWithRequest(request); |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
94 // find the requested file |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
95 DocuDirent f = findFile(dlReq); |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
96 if (f != null) { |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
97 DocuDirectory dd = (DocuDirectory) f.getParent(); |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
98 mtime = dd.getDirMTime() / 1000 * 1000; |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
99 } |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
100 return mtime; |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
101 } |
543
919e008ab1fb
more steps towards more standard java.util.concurrent design
robcast
parents:
542
diff
changeset
|
102 |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
103 /** |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
104 * Returns the DocuDirent corresponding to the DigilibRequest. |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
105 * |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
106 * @param dlRequest |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
107 * @return |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
108 */ |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
109 public DocuDirent findFile(DigilibRequest dlRequest) { |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
110 // find the file(set) |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
111 DocuDirent f = dirCache.getFile(dlRequest.getFilePath(), dlRequest |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
112 .getAsInt("pn"), FileOps.CLASS_IMAGE); |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
113 return f; |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
114 } |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
115 |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
116 |
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
117 |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
118 /** |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
119 * Initialisation on first run. |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
120 * @throws ServletException |
73 | 121 * |
122 * @see javax.servlet.Servlet#init(javax.servlet.ServletConfig) | |
123 */ | |
124 public void init(ServletConfig config) throws ServletException { | |
125 super.init(config); | |
1 | 126 |
298
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
127 System.out |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
128 .println("***** Digital Image Library Image Scaler Servlet (version " |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
129 + dlVersion + ") *****"); |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
130 // say hello in the log file |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
131 logger |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
132 .info("***** Digital Image Library Image Scaler Servlet (version " |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
133 + dlVersion + ") *****"); |
1 | 134 |
73 | 135 // get our ServletContext |
136 ServletContext context = config.getServletContext(); | |
137 // see if there is a Configuration instance | |
298
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
138 dlConfig = (DigilibConfiguration) context |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
139 .getAttribute("digilib.servlet.configuration"); |
73 | 140 if (dlConfig == null) { |
298
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
141 // no Configuration |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
142 throw new ServletException("No Configuration!"); |
335 | 143 } |
73 | 144 // set our AuthOps |
298
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
145 useAuthorization = dlConfig.getAsBoolean("use-authorization"); |
153 | 146 authOp = (AuthOps) dlConfig.getValue("servlet.auth.op"); |
181 | 147 |
86 | 148 // DocuDirCache instance |
153 | 149 dirCache = (DocuDirCache) dlConfig.getValue("servlet.dir.cache"); |
543
919e008ab1fb
more steps towards more standard java.util.concurrent design
robcast
parents:
542
diff
changeset
|
150 |
919e008ab1fb
more steps towards more standard java.util.concurrent design
robcast
parents:
542
diff
changeset
|
151 // Executor |
919e008ab1fb
more steps towards more standard java.util.concurrent design
robcast
parents:
542
diff
changeset
|
152 imageJobCenter = (ExecutorService) dlConfig.get("servlet.worker.imageexecutor"); |
919e008ab1fb
more steps towards more standard java.util.concurrent design
robcast
parents:
542
diff
changeset
|
153 |
394
31643c12d939
digilib can now take its error-icons from the web app
robcast
parents:
363
diff
changeset
|
154 denyImgFile = ServletOps.getFile((File) dlConfig.getValue("denied-image"), config); |
31643c12d939
digilib can now take its error-icons from the web app
robcast
parents:
363
diff
changeset
|
155 errorImgFile = ServletOps.getFile((File) dlConfig.getValue("error-image"), config); |
31643c12d939
digilib can now take its error-icons from the web app
robcast
parents:
363
diff
changeset
|
156 notfoundImgFile = ServletOps.getFile((File) dlConfig.getValue("notfound-image"), config); |
153 | 157 sendFileAllowed = dlConfig.getAsBoolean("sendfile-allowed"); |
158 minSubsample = dlConfig.getAsFloat("subsample-minimum"); | |
159 defaultQuality = dlConfig.getAsInt("default-quality"); | |
73 | 160 } |
1 | 161 |
511 | 162 |
163 | |
164 | |
500 | 165 @Override |
166 public void processRequest(HttpServletRequest request, | |
167 HttpServletResponse response) throws ServletException, ImageOpException { | |
1 | 168 |
500 | 169 |
298
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
170 if (dlConfig == null) { |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
171 throw new ServletException("ERROR: No Configuration!"); |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
172 } |
502 | 173 |
335 | 174 accountlog.debug("request: " + request.getQueryString()); |
175 logger.debug("request: " + request.getQueryString()); | |
500 | 176 |
1 | 177 |
500 | 178 // define the job information |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
179 ImageJobInformation jobdeclaration = new ImageJobInformation(dlConfig); |
500 | 180 jobdeclaration.setWithRequest(request); |
181 | |
502 | 182 ImageFile fileToLoad = null; |
183 try { | |
184 fileToLoad = jobdeclaration.get_fileToLoad(); | |
185 } catch (IOException e2) { | |
186 // TODO Auto-generated catch block | |
187 e2.printStackTrace(); | |
188 return; | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
189 } |
500 | 190 |
191 | |
502 | 192 // if requested, send image as a file |
193 if(sendFileAllowed && jobdeclaration.checkSendAsFile()){ | |
194 String mt = null; | |
195 if (jobdeclaration.hasOption("mo", "rawfile")) { | |
196 mt = "application/octet-stream"; | |
197 } | |
198 logger.debug("Sending RAW File as is."); | |
199 try { | |
200 ServletOps.sendFile(fileToLoad.getFile(), mt, response); | |
201 } catch (FileOpException e) { | |
202 e.printStackTrace(); | |
203 } | |
1 | 204 |
502 | 205 return; |
73 | 206 } |
487 | 207 |
500 | 208 |
209 | |
502 | 210 // if possible, send the image without actually having to transform it |
211 if(jobdeclaration.noTransformRequired()){ | |
212 logger.debug("Sending File as is."); | |
213 | |
214 try { | |
215 ServletOps.sendFile(fileToLoad.getFile(), null, response); | |
216 } catch (FileOpException e) { | |
217 e.printStackTrace(); | |
218 } | |
219 | |
220 //logger.info("Done in " | |
221 // + (System.currentTimeMillis() - startTime) + "ms"); | |
222 return; | |
149 | 223 } |
502 | 224 |
225 | |
226 | |
500 | 227 |
542
e2ff961001af
first step towards more standard java.util.concurrent design
robcast
parents:
536
diff
changeset
|
228 if (! DigilibWorker1.canRun()) { |
502 | 229 logger.error("Servlet overloaded!"); |
230 try { | |
231 response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE); | |
232 } catch (IOException e) { | |
233 e.printStackTrace(); | |
234 } | |
235 return; | |
335 | 236 } |
1 | 237 |
502 | 238 |
543
919e008ab1fb
more steps towards more standard java.util.concurrent design
robcast
parents:
542
diff
changeset
|
239 //DigilibWorker1 job=null; |
919e008ab1fb
more steps towards more standard java.util.concurrent design
robcast
parents:
542
diff
changeset
|
240 ImageWorker job = null; |
73 | 241 try { |
500 | 242 |
243 long startTime = System.currentTimeMillis(); | |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
244 |
543
919e008ab1fb
more steps towards more standard java.util.concurrent design
robcast
parents:
542
diff
changeset
|
245 OutputStream outputstream = null; |
919e008ab1fb
more steps towards more standard java.util.concurrent design
robcast
parents:
542
diff
changeset
|
246 outputstream = response.getOutputStream(); |
919e008ab1fb
more steps towards more standard java.util.concurrent design
robcast
parents:
542
diff
changeset
|
247 |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
248 /* check permissions */ |
298
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
249 if (useAuthorization) { |
73 | 250 // get a list of required roles (empty if no restrictions) |
531
9cedd170b581
* PDF generation works now even with subdirectories
robcast
parents:
527
diff
changeset
|
251 List<String> rolesRequired; |
501 | 252 try { |
253 rolesRequired = authOp.rolesForPath(jobdeclaration.getFilePath(), request); | |
254 if (rolesRequired != null) { | |
255 authlog.debug("Role required: " + rolesRequired); | |
256 authlog.debug("User: " + request.getRemoteUser()); | |
257 // is the current request/user authorized? | |
258 if (!authOp.isRoleAuthorized(rolesRequired, request)) { | |
259 // send deny answer and abort | |
260 throw new AuthOpException(); | |
261 } | |
487 | 262 } |
263 | |
501 | 264 } catch (AuthOpException e) { |
265 // TODO Auto-generated catch block | |
266 e.printStackTrace(); | |
181 | 267 } |
268 } | |
269 | |
500 | 270 |
543
919e008ab1fb
more steps towards more standard java.util.concurrent design
robcast
parents:
542
diff
changeset
|
271 //job = new DigilibImageWorker1(dlConfig, outputstream , jobdeclaration); |
919e008ab1fb
more steps towards more standard java.util.concurrent design
robcast
parents:
542
diff
changeset
|
272 //job.run(); |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
273 |
543
919e008ab1fb
more steps towards more standard java.util.concurrent design
robcast
parents:
542
diff
changeset
|
274 // create job |
919e008ab1fb
more steps towards more standard java.util.concurrent design
robcast
parents:
542
diff
changeset
|
275 job = new ImageWorker(dlConfig, jobdeclaration); |
919e008ab1fb
more steps towards more standard java.util.concurrent design
robcast
parents:
542
diff
changeset
|
276 // submit job |
919e008ab1fb
more steps towards more standard java.util.concurrent design
robcast
parents:
542
diff
changeset
|
277 Future<DocuImage> jobResult = imageJobCenter.submit(job); |
919e008ab1fb
more steps towards more standard java.util.concurrent design
robcast
parents:
542
diff
changeset
|
278 // wait for result |
919e008ab1fb
more steps towards more standard java.util.concurrent design
robcast
parents:
542
diff
changeset
|
279 DocuImage img = jobResult.get(); |
919e008ab1fb
more steps towards more standard java.util.concurrent design
robcast
parents:
542
diff
changeset
|
280 // send image |
919e008ab1fb
more steps towards more standard java.util.concurrent design
robcast
parents:
542
diff
changeset
|
281 ServletOps.writeImage(img, null, outputstream); |
919e008ab1fb
more steps towards more standard java.util.concurrent design
robcast
parents:
542
diff
changeset
|
282 |
919e008ab1fb
more steps towards more standard java.util.concurrent design
robcast
parents:
542
diff
changeset
|
283 logger.debug("Job Processing Time: "+ (System.currentTimeMillis()-startTime) + "ms"); |
500 | 284 |
285 } catch (IOException e) { | |
286 e.printStackTrace(); | |
287 logger.error(e.getClass()+": "+ e.getMessage()); | |
288 //response.sendError(1); | |
543
919e008ab1fb
more steps towards more standard java.util.concurrent design
robcast
parents:
542
diff
changeset
|
289 } catch (InterruptedException e) { |
919e008ab1fb
more steps towards more standard java.util.concurrent design
robcast
parents:
542
diff
changeset
|
290 // TODO Auto-generated catch block |
919e008ab1fb
more steps towards more standard java.util.concurrent design
robcast
parents:
542
diff
changeset
|
291 e.printStackTrace(); |
919e008ab1fb
more steps towards more standard java.util.concurrent design
robcast
parents:
542
diff
changeset
|
292 logger.error(e.getClass()+": "+ e.getMessage()); |
919e008ab1fb
more steps towards more standard java.util.concurrent design
robcast
parents:
542
diff
changeset
|
293 } catch (ExecutionException e) { |
919e008ab1fb
more steps towards more standard java.util.concurrent design
robcast
parents:
542
diff
changeset
|
294 // TODO Auto-generated catch block |
919e008ab1fb
more steps towards more standard java.util.concurrent design
robcast
parents:
542
diff
changeset
|
295 e.printStackTrace(); |
919e008ab1fb
more steps towards more standard java.util.concurrent design
robcast
parents:
542
diff
changeset
|
296 logger.error(e.getClass()+": "+ e.getMessage()); |
919e008ab1fb
more steps towards more standard java.util.concurrent design
robcast
parents:
542
diff
changeset
|
297 logger.error("caused by: "+ e.getCause().getMessage()); |
919e008ab1fb
more steps towards more standard java.util.concurrent design
robcast
parents:
542
diff
changeset
|
298 } |
405
ffb2036da205
first stab at PDF printer servlet. DOES NOT WORK YET!
robcast
parents:
394
diff
changeset
|
299 |
335 | 300 } |
500 | 301 |
302 | |
335 | 303 /** |
298
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
304 * Sends an error to the client as text or image. |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
305 * |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
306 * @param asHTML |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
307 * @param type |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
308 * @param msg |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
309 * @param response |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
310 */ |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
311 public void digilibError(boolean asHTML, int type, String msg, |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
312 HttpServletResponse response) { |
335 | 313 try { |
298
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
314 File img = null; |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
315 if (type == ERROR_AUTH) { |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
316 if (msg == null) { |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
317 msg = "ERROR: Unauthorized access!"; |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
318 } |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
319 img = denyImgFile; |
363 | 320 } else if (type == ERROR_FILE) { |
321 if (msg == null) { | |
322 msg = "ERROR: Image file not found!"; | |
323 } | |
324 img = notfoundImgFile; | |
335 | 325 } else { |
298
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
326 if (msg == null) { |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
327 msg = "ERROR: Other image error!"; |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
328 } |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
329 img = this.errorImgFile; |
335 | 330 } |
298
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
331 if (asHTML && (img != null)) { |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
332 ServletOps.htmlMessage(msg, response); |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
333 } else { |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
334 ServletOps.sendFile(img, null, response); |
335 | 335 } |
298
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
336 } catch (IOException e) { |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
337 logger.error("Error sending error!", e); |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
338 } |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
339 |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
340 } |
1ecaf9c1fd8a
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
288
diff
changeset
|
341 |
500 | 342 public static String getVersion(){ |
489
882ee6a055bd
try to fix small problem with version number display
robcast
parents:
487
diff
changeset
|
343 return dlVersion; |
882ee6a055bd
try to fix small problem with version number display
robcast
parents:
487
diff
changeset
|
344 } |
500 | 345 |
489
882ee6a055bd
try to fix small problem with version number display
robcast
parents:
487
diff
changeset
|
346 |
500 | 347 } |