use of digilib.io.ImageInput in project digilib by robcast.
the class ScalerNoThread method processRequest.
/**
* Service this request using the response.
*
* @param request
* @param response
* @throws ServletException
*/
public void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException {
if (dlConfig == null) {
logger.error("ERROR: No Configuration!");
throw new ServletException("NO VALID digilib CONFIGURATION!");
}
accountlog.debug("request: " + request.getQueryString());
logger.debug("request: " + request.getQueryString());
long startTime = System.currentTimeMillis();
// parse request
DigilibServletRequest dlRequest = new DigilibServletRequest(request, dlConfig);
// type of error reporting
ErrMsg errMsgType = ErrMsg.IMAGE;
if (dlRequest.hasOption(DigilibOption.errtxt)) {
errMsgType = ErrMsg.TEXT;
} else if (dlRequest.hasOption(DigilibOption.errcode)) {
errMsgType = ErrMsg.CODE;
}
try {
// extract the job information
ImageJobDescription jobTicket = ImageJobDescription.getInstance(dlRequest, dlConfig);
/*
* check if we can fast-track without scaling
*/
ImageInput fileToLoad = (ImageInput) jobTicket.getInput();
// check permissions
if (useAuthorization) {
// is the current request/user authorized?
if (!authzOp.isAuthorized(dlRequest)) {
// send deny answer and abort
throw new AuthOpException();
}
}
// if requested, send image as a file
if (sendFileAllowed && jobTicket.getSendAsFile()) {
String mt = null;
if (jobTicket.hasOption(DigilibOption.rawfile)) {
mt = "application/octet-stream";
}
logger.debug("Sending RAW File as is.");
ServletOps.sendFile(fileToLoad.getFile(), mt, null, response, logger);
logger.info("Done in " + (System.currentTimeMillis() - startTime) + "ms");
return;
}
// it
if (!jobTicket.isTransformRequired()) {
logger.debug("Sending File as is.");
ServletOps.sendFile(fileToLoad.getFile(), null, null, response, logger);
logger.info("Done in " + (System.currentTimeMillis() - startTime) + "ms");
return;
}
// create job
ImageWorker job = new ImageWorker(dlConfig, jobTicket);
// get result immediately
DocuImage img = job.call();
// forced destination image type
String mt = null;
if (jobTicket.hasOption(DigilibOption.jpg)) {
mt = "image/jpeg";
} else if (jobTicket.hasOption(DigilibOption.png)) {
mt = "image/png";
}
// send image
ServletOps.sendImage(img, mt, response, logger);
logger.debug("Job Processing Time: " + (System.currentTimeMillis() - startTime) + "ms");
} catch (ImageOpException e) {
logger.error(e.getClass() + ": " + e.getMessage());
digilibError(errMsgType, Error.IMAGE, null, response);
} catch (IOException e) {
logger.error(e.getClass() + ": " + e.getMessage());
digilibError(errMsgType, Error.FILE, null, response);
} catch (AuthOpException e) {
logger.error(e.getClass() + ": " + e.getMessage());
digilibError(errMsgType, Error.AUTH, null, response);
}
}
use of digilib.io.ImageInput in project digilib by robcast.
the class Manifester method writeCanvases.
/**
* @param dlDir
* @param url
* @param manifest
* @param servletUrl
*/
protected void writeCanvases(JsonGenerator manifest, ManifestParams params) {
/*
* list of canvases
*/
manifest.writeStartArray("canvases");
int idx = 0;
for (DocuDirent imgFile : params.docuDir) {
idx += 1;
ImageFileSet imgFs = (ImageFileSet) imgFile;
ImageInput img = imgFs.getBiggest();
ImageSize imgSize = img.getSize();
if (imgSize == null)
continue;
/*
* canvas
*/
writeCanvas(manifest, idx, imgFile, imgSize, params);
}
// canvases
manifest.writeEnd();
}
use of digilib.io.ImageInput in project digilib by robcast.
the class JAIDocuImage method identify.
/* Check image size and type and store in ImageFile f */
public ImageInput identify(ImageInput input) throws IOException {
this.input = input;
// try parent method first
ImageInput imf = super.identify(input);
if (imf != null) {
return imf;
}
/*
* try JAI
*/
logger.debug("identifying (JAI) " + input);
try {
RenderedOp img = null;
if (input.hasFile()) {
String t = FileOps.mimeForFile(input.getFile());
input.setMimetype(t);
img = JAI.create("fileload", input.getFile().getAbsolutePath());
} else if (input.hasInputStream()) {
img = JAI.create("stream", input.getInputStream());
// FIXME: where do we get the mimetype?
} else {
throw new FileOpException("unable to get data for image!");
}
ImageSize d = new ImageSize(img.getWidth(), img.getHeight());
input.setSize(d);
logger.debug("image size: " + d);
return input;
} catch (Exception e) {
throw new FileOpException("ERROR: unable to identify image!");
}
}
use of digilib.io.ImageInput in project digilib by robcast.
the class Scaler method processRequest.
/**
* Service this request using the response.
*
* @param request
* @param response
* @throws ServletException
*/
public void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException {
if (dlConfig == null) {
logger.error("ERROR: No Configuration!");
throw new ServletException("NO VALID digilib CONFIGURATION!");
}
accountlog.debug("request: " + request.getQueryString());
logger.debug("request: " + request.getQueryString());
// logger.debug("processRequest response committed=" + response.isCommitted());
if (response.isCommitted()) {
logger.error("Crap: response committed before we got a chance!");
}
final long startTime = System.currentTimeMillis();
// parse request
DigilibServletRequest dlRequest = new DigilibServletRequest(request, dlConfig);
// type of error reporting
ErrMsg errMsgType = defaultErrMsgType;
if (dlRequest.hasOption(DigilibOption.errimg)) {
errMsgType = ErrMsg.IMAGE;
} else if (dlRequest.hasOption(DigilibOption.errtxt)) {
errMsgType = ErrMsg.TEXT;
} else if (dlRequest.hasOption(DigilibOption.errcode)) {
errMsgType = ErrMsg.CODE;
}
try {
// extract the job information
final ImageJobDescription jobTicket = ImageJobDescription.getInstance(dlRequest, dlConfig);
// handle the IIIF info-request
if (dlRequest.hasOption(DigilibOption.info)) {
ServletOps.sendIiifInfo(dlRequest, response, logger);
return;
}
if (dlRequest.hasOption(DigilibOption.redirect_info)) {
StringBuffer url = request.getRequestURL();
if (url.toString().endsWith("/")) {
url.append("info.json");
} else {
url.append("/info.json");
}
// TODO: the redirect should have code 303
response.sendRedirect(url.toString());
return;
}
// error out if request was bad
if (dlRequest.errorMessage != null) {
digilibError(errMsgType, Error.UNKNOWN, dlRequest.errorMessage, response);
return;
}
/*
* check permissions
*/
if (useAuthorization) {
// is the current request/user authorized?
if (!authzOp.isAuthorized(dlRequest)) {
// send deny answer and abort
throw new AuthOpException("Access denied!");
}
}
/*
* get the input file
*/
ImageInput fileToLoad = jobTicket.getInput();
/*
* if requested, send image as a file
*/
if (sendFileAllowed && jobTicket.getSendAsFile()) {
String mt = null;
if (jobTicket.hasOption(DigilibOption.rawfile)) {
// mo=rawfile sends as octet-stream
mt = "application/octet-stream";
}
logger.debug("Sending RAW File as is.");
ServletOps.sendFile(fileToLoad.getFile(), mt, null, response, logger);
logger.info("Done in " + (System.currentTimeMillis() - startTime) + "ms");
return;
}
/*
* send the image if it's possible without having to transform it
*/
if (!jobTicket.isTransformRequired()) {
logger.debug("Sending File as is.");
ServletOps.sendFile(fileToLoad.getFile(), null, null, response, logger);
logger.info("Done in " + (System.currentTimeMillis() - startTime) + "ms");
return;
}
/*
* check load of workers
*/
if (imageJobCenter.isBusy()) {
logger.error("Servlet overloaded!");
response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
return;
}
/*
* dispatch worker job to be done asynchronously
*/
AsyncContext asyncCtx = request.startAsync();
// create job
AsyncServletWorker job = new AsyncServletWorker(dlConfig, jobTicket, asyncCtx, errMsgType, startTime);
// AsyncServletWorker is its own AsyncListener
asyncCtx.addListener(job);
// submit job
imageJobCenter.submit(job);
// we're done for now
} catch (ImageOpException e) {
logger.error(e.getClass() + ": " + e.getMessage());
digilibError(errMsgType, Error.IMAGE, null, response);
} catch (IOException e) {
logger.error(e.getClass() + ": " + e.getMessage());
digilibError(errMsgType, Error.FILE, null, response);
} catch (AuthOpException e) {
logger.error(e.getClass() + ": " + e.getMessage());
digilibError(errMsgType, Error.AUTH, null, response);
} catch (Exception e) {
logger.error("Other Exception: ", e);
// TODO: should we rethrow or swallow?
// throw new ServletException(e);
}
}
Aggregations