use of org.apache.jasper.JasperException in project tomcat70 by apache.
the class ImplicitTagLibraryInfo method getTagFile.
/**
* Checks to see if the given tag name maps to a tag file path,
* and if so, parses the corresponding tag file.
*
* @return The TagFileInfo corresponding to the given tag name, or null if
* the given tag name is not implemented as a tag file
*/
@Override
public TagFileInfo getTagFile(String shortName) {
TagFileInfo tagFile = super.getTagFile(shortName);
if (tagFile == null) {
String path = tagFileMap.get(shortName);
if (path == null) {
return null;
}
TagInfo tagInfo = null;
try {
tagInfo = TagFileProcessor.parseTagFileDirectives(pc, shortName, path, pc.getJspCompilationContext().getTagFileJarResource(path), this);
} catch (JasperException je) {
throw new RuntimeException(je.toString(), je);
}
tagFile = new TagFileInfo(shortName, path, tagInfo);
vec.addElement(tagFile);
this.tagFiles = new TagFileInfo[vec.size()];
vec.copyInto(this.tagFiles);
}
return tagFile;
}
use of org.apache.jasper.JasperException in project tomcat by apache.
the class JspRuntimeLibrary method handleSetPropertyExpression.
// __end lookupReadMethodMethod
// handles <jsp:setProperty> with EL expression for 'value' attribute
public static void handleSetPropertyExpression(Object bean, String prop, String expression, PageContext pageContext, ProtectedFunctionMapper functionMapper) throws JasperException {
try {
Method method = getWriteMethod(bean.getClass(), prop);
method.invoke(bean, new Object[] { PageContextImpl.proprietaryEvaluate(expression, method.getParameterTypes()[0], pageContext, functionMapper) });
} catch (Exception ex) {
Throwable thr = ExceptionUtils.unwrapInvocationTargetException(ex);
ExceptionUtils.handleThrowable(thr);
throw new JasperException(ex);
}
}
use of org.apache.jasper.JasperException in project tomcat by apache.
the class JspRuntimeLibrary method getReadMethod.
public static Method getReadMethod(Class<?> beanClass, String prop) throws JasperException {
Method result = null;
Class<?> type = null;
if (GRAAL) {
String setter = "get" + capitalize(prop);
Method[] methods = beanClass.getMethods();
for (Method method : methods) {
if (setter.equals(method.getName())) {
return method;
}
}
} else {
try {
java.beans.BeanInfo info = java.beans.Introspector.getBeanInfo(beanClass);
java.beans.PropertyDescriptor[] pd = info.getPropertyDescriptors();
for (java.beans.PropertyDescriptor propertyDescriptor : pd) {
if (propertyDescriptor.getName().equals(prop)) {
result = propertyDescriptor.getReadMethod();
type = propertyDescriptor.getPropertyType();
break;
}
}
} catch (Exception ex) {
throw new JasperException(ex);
}
}
if (result == null) {
if (type == null) {
throw new JasperException(Localizer.getMessage("jsp.error.beans.noproperty", prop, beanClass.getName()));
} else {
throw new JasperException(Localizer.getMessage("jsp.error.beans.nomethod", prop, beanClass.getName()));
}
}
return result;
}
use of org.apache.jasper.JasperException in project tomcat by apache.
the class JspServletWrapper method getServlet.
public Servlet getServlet() throws ServletException {
/*
* DCL on 'reload' requires that 'reload' be volatile
* (this also forces a read memory barrier, ensuring the new servlet
* object is read consistently).
*
* When running in non development mode with a checkInterval it is
* possible (see BZ 62603) for a race condition to cause failures
* if a Servlet or tag is reloaded while a compile check is running
*/
if (getReloadInternal() || theServlet == null) {
synchronized (this) {
// of different pages, but not the same page.
if (getReloadInternal() || theServlet == null) {
// 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 (theServlet != null) {
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 tomcat 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 https://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();
}
// Find the first stack frame that represents code generated by
// Jasper
StackTraceElement[] frames = realException.getStackTrace();
StackTraceElement jspFrame = null;
String servletPackageName = ctxt.getBasePackageName();
for (StackTraceElement frame : frames) {
if (frame.getClassName().startsWith(servletPackageName)) {
jspFrame = frame;
break;
}
}
SmapStratum smap = null;
if (jspFrame != null) {
smap = ctxt.getCompiler().getSmap(jspFrame.getClassName());
}
if (smap == null) {
// smap to hand, we can't really add anything
return new JasperException(ex);
}
@SuppressWarnings("null") int javaLineNumber = jspFrame.getLineNumber();
SmapInput source = smap.getInputLineNumber(javaLineNumber);
// where in the JSP things went wrong
if (source.getLineNumber() < 1) {
throw new JasperException(ex);
}
JavacErrorDetail detail = new JavacErrorDetail(jspFrame.getMethodName(), javaLineNumber, source.getFileName(), source.getLineNumber(), null, ctxt);
if (options.getDisplaySourceFragment()) {
return new JasperException(Localizer.getMessage("jsp.exception", detail.getJspFileName(), "" + source.getLineNumber()) + System.lineSeparator() + System.lineSeparator() + detail.getJspExtract() + System.lineSeparator() + System.lineSeparator() + "Stacktrace:", ex);
}
return new JasperException(Localizer.getMessage("jsp.exception", detail.getJspFileName(), "" + source.getLineNumber()), 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