use of org.apache.jasper.JasperException in project Payara by payara.
the class AllJSPsMustBeCompilable method check.
public Result check(WebBundleDescriptor descriptor) {
Result result = getInitializedResult();
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
// initialize good result
addGoodDetails(result, compName);
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "All JSPs are compilable."));
// set default status to PASSED
result.setStatus(Result.PASSED);
// initialize error results.
addErrorDetails(result, compName);
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".exception", "Error: Some JSPs bundled inside [ {0} ] could not be compiled. See details below.", new Object[] { descriptor.getName() }));
for (JasperException e : compile(descriptor)) {
result.failed(formatMessage(descriptor, e.toString()));
}
return result;
}
use of org.apache.jasper.JasperException in project tomcat70 by apache.
the class ParserUtils method parseXMLDocument.
// --------------------------------------------------------- Public Methods
/**
* Parse the specified XML document, and return a <code>TreeNode</code>
* that corresponds to the root node of the document tree.
*
* @param location Location (eg URI) of the XML document being parsed
* @param is Input source containing the deployment descriptor
*
* @exception JasperException if an input/output error occurs
* @exception JasperException if a parsing error occurs
*/
public TreeNode parseXMLDocument(String location, InputSource is) throws JasperException {
Document document = null;
// Perform an XML parse of this document, via JAXP
ClassLoader original;
if (Constants.IS_SECURITY_ENABLED) {
PrivilegedGetTccl pa = new PrivilegedGetTccl();
original = AccessController.doPrivileged(pa);
} else {
original = Thread.currentThread().getContextClassLoader();
}
try {
if (Constants.IS_SECURITY_ENABLED) {
PrivilegedSetTccl pa = new PrivilegedSetTccl(ParserUtils.class.getClassLoader());
AccessController.doPrivileged(pa);
} else {
Thread.currentThread().setContextClassLoader(ParserUtils.class.getClassLoader());
}
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
factory.setValidating(validating);
if (validating) {
// Enable DTD validation
factory.setFeature("http://xml.org/sax/features/validation", true);
// Enable schema validation
factory.setFeature("http://apache.org/xml/features/validation/schema", true);
}
DocumentBuilder builder = factory.newDocumentBuilder();
builder.setEntityResolver(entityResolverInstance);
XmlErrorHandler handler = new XmlErrorHandler();
builder.setErrorHandler(handler);
document = builder.parse(is);
if (!handler.getErrors().isEmpty()) {
// throw the first to indicate there was a error during processing
throw handler.getErrors().iterator().next();
}
} catch (ParserConfigurationException ex) {
throw new JasperException(Localizer.getMessage("jsp.error.parse.xml", location), ex);
} catch (SAXParseException ex) {
throw new JasperException(Localizer.getMessage("jsp.error.parse.xml.line", location, Integer.toString(ex.getLineNumber()), Integer.toString(ex.getColumnNumber())), ex);
} catch (SAXException sx) {
throw new JasperException(Localizer.getMessage("jsp.error.parse.xml", location), sx);
} catch (IOException io) {
throw new JasperException(Localizer.getMessage("jsp.error.parse.xml", location), io);
} finally {
if (Constants.IS_SECURITY_ENABLED) {
PrivilegedSetTccl pa = new PrivilegedSetTccl(original);
AccessController.doPrivileged(pa);
} else {
Thread.currentThread().setContextClassLoader(original);
}
}
// Convert the resulting document to a graph of TreeNodes
return (convert(null, document.getDocumentElement()));
}
use of org.apache.jasper.JasperException in project tomcat70 by apache.
the class JspServletWrapper method service.
public void service(HttpServletRequest request, HttpServletResponse response, boolean precompile) throws ServletException, IOException, FileNotFoundException {
Servlet servlet;
try {
if (ctxt.isRemoved()) {
throw new FileNotFoundException(jspUri);
}
if ((available > 0L) && (available < Long.MAX_VALUE)) {
if (available > System.currentTimeMillis()) {
response.setDateHeader("Retry-After", available);
response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, Localizer.getMessage("jsp.error.unavailable"));
return;
}
// Wait period has expired. Reset.
available = 0;
}
/*
* (1) Compile
*/
if (options.getDevelopment() || firstTime) {
synchronized (this) {
firstTime = false;
// The following sets reload to true, if necessary
ctxt.compile();
}
} else {
if (compileException != null) {
// Throw cached compilation exception
throw compileException;
}
}
/*
* (2) (Re)load servlet class file
*/
servlet = getServlet();
// If a page is to be precompiled only, return.
if (precompile) {
return;
}
} catch (ServletException ex) {
if (options.getDevelopment()) {
throw handleJspException(ex);
}
throw ex;
} catch (FileNotFoundException fnfe) {
// File has been removed. Let caller handle this.
throw fnfe;
} catch (IOException ex) {
if (options.getDevelopment()) {
throw handleJspException(ex);
}
throw ex;
} catch (IllegalStateException ex) {
if (options.getDevelopment()) {
throw handleJspException(ex);
}
throw ex;
} catch (Exception ex) {
if (options.getDevelopment()) {
throw handleJspException(ex);
}
throw new JasperException(ex);
}
try {
/*
* (3) Handle limitation of number of loaded Jsps
*/
if (unloadAllowed) {
synchronized (this) {
if (unloadByCount) {
if (unloadHandle == null) {
unloadHandle = ctxt.getRuntimeContext().push(this);
} else if (lastUsageTime < ctxt.getRuntimeContext().getLastJspQueueUpdate()) {
ctxt.getRuntimeContext().makeYoungest(unloadHandle);
lastUsageTime = System.currentTimeMillis();
}
} else {
if (lastUsageTime < ctxt.getRuntimeContext().getLastJspQueueUpdate()) {
lastUsageTime = System.currentTimeMillis();
}
}
}
}
/*
* (4) Service request
*/
if (servlet instanceof SingleThreadModel) {
// of the page is determined right before servicing
synchronized (this) {
servlet.service(request, response);
}
} else {
servlet.service(request, response);
}
} catch (UnavailableException ex) {
String includeRequestUri = (String) request.getAttribute(RequestDispatcher.INCLUDE_REQUEST_URI);
if (includeRequestUri != null) {
// servlet engine.
throw ex;
}
int unavailableSeconds = ex.getUnavailableSeconds();
if (unavailableSeconds <= 0) {
// Arbitrary default
unavailableSeconds = 60;
}
available = System.currentTimeMillis() + (unavailableSeconds * 1000L);
response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, ex.getMessage());
} catch (ServletException ex) {
if (options.getDevelopment()) {
throw handleJspException(ex);
}
throw ex;
} catch (IOException ex) {
if (options.getDevelopment()) {
throw new IOException(handleJspException(ex).getMessage(), ex);
}
throw ex;
} catch (IllegalStateException ex) {
if (options.getDevelopment()) {
throw handleJspException(ex);
}
throw ex;
} catch (Exception ex) {
if (options.getDevelopment()) {
throw handleJspException(ex);
}
throw new JasperException(ex);
}
}
use of org.apache.jasper.JasperException in project tomcat70 by apache.
the class JspServletWrapper method getServlet.
public Servlet getServlet() throws ServletException {
// new servlet object is read consistently)
if (reload) {
synchronized (this) {
// of different pages, but not the same page.
if (reload) {
// This is to maintain the original protocol.
destroy();
final Servlet servlet;
try {
InstanceManager instanceManager = InstanceManagerFactory.getInstanceManager(config);
servlet = (Servlet) instanceManager.newInstance(ctxt.getFQCN(), ctxt.getJspLoader());
} catch (Exception e) {
Throwable t = ExceptionUtils.unwrapInvocationTargetException(e);
ExceptionUtils.handleThrowable(t);
throw new JasperException(t);
}
servlet.init(config);
if (!firstTime) {
ctxt.getRuntimeContext().incrementJspReloadCount();
}
theServlet = servlet;
reload = false;
// Volatile 'reload' forces in order write of 'theServlet' and new servlet object
}
}
}
return theServlet;
}
use of org.apache.jasper.JasperException in project tomcat70 by apache.
the class JspServletWrapper method handleJspException.
/**
* <p>Attempts to construct a JasperException that contains helpful information
* about what went wrong. Uses the JSP compiler system to translate the line
* number in the generated servlet that originated the exception to a line
* number in the JSP. Then constructs an exception containing that
* information, and a snippet of the JSP to help debugging.
* Please see http://bz.apache.org/bugzilla/show_bug.cgi?id=37062 and
* http://www.tfenne.com/jasper/ for more details.
*</p>
*
* @param ex the exception that was the cause of the problem.
* @return a JasperException with more detailed information
*/
protected JasperException handleJspException(Exception ex) {
try {
Throwable realException = ex;
if (ex instanceof ServletException) {
realException = ((ServletException) ex).getRootCause();
}
// First identify the stack frame in the trace that represents the JSP
StackTraceElement[] frames = realException.getStackTrace();
StackTraceElement jspFrame = null;
for (int i = 0; i < frames.length; ++i) {
if (frames[i].getClassName().equals(this.getServlet().getClass().getName())) {
jspFrame = frames[i];
break;
}
}
if (jspFrame == null || this.ctxt.getCompiler().getPageNodes() == null) {
// parsed JSP to hand, we can't really add anything
return new JasperException(ex);
}
int javaLineNumber = jspFrame.getLineNumber();
JavacErrorDetail detail = ErrorDispatcher.createJavacError(jspFrame.getMethodName(), this.ctxt.getCompiler().getPageNodes(), null, javaLineNumber, ctxt);
// If the line number is less than one we couldn't find out
// where in the JSP things went wrong
int jspLineNumber = detail.getJspBeginLineNumber();
if (jspLineNumber < 1) {
throw new JasperException(ex);
}
if (options.getDisplaySourceFragment()) {
return new JasperException(Localizer.getMessage("jsp.exception", detail.getJspFileName(), "" + jspLineNumber) + Constants.NEWLINE + Constants.NEWLINE + detail.getJspExtract() + Constants.NEWLINE + Constants.NEWLINE + "Stacktrace:", ex);
}
return new JasperException(Localizer.getMessage("jsp.exception", detail.getJspFileName(), "" + jspLineNumber), ex);
} catch (Exception je) {
// If anything goes wrong, just revert to the original behaviour
if (ex instanceof JasperException) {
return (JasperException) ex;
}
return new JasperException(ex);
}
}
Aggregations