WSO2 application server 5.0.1 jsp using javax.crypto package fails to compile

510 Views Asked by At

We are using the WSO2 application server version 5.0.1. If I use javax.crypto package in a JSP page, it fails to compile when accessed. To verify this I copied the jce.jar file in WEB-INF/lib folder of our web application. If the jce.jar file is present in WEB-INF/lib folder, the jsp compiles fine but if I remove the jce.jar from there, the compilation fails with following errors :

Generated servlet error:
The type javax.activation.DataHandler cannot be resolved. It is indirectly referenced from required .class files

An error occurred at line: 10 in the jsp file: /processPassword.jsp
Generated servlet error:
PBEKeySpec cannot be resolved to a type

An error occurred at line: 10 in the jsp file: /processPassword.jsp
Generated servlet error:
SecretKeyFactory cannot be resolved to a type

An error occurred at line: 10 in the jsp file: /processPassword.jsp
Generated servlet error:
SecretKeyFactory cannot be resolved

] with root cause
org.apache.jasper.JasperException: Unable to compile class for JSP

Generated servlet error:
The type javax.activation.DataHandler cannot be resolved. It is indirectly referenced from required .class files

An error occurred at line: 10 in the jsp file: /processPassword.jsp
Generated servlet error:
PBEKeySpec cannot be resolved to a type

An error occurred at line: 10 in the jsp file: /processPassword.jsp
Generated servlet error:
SecretKeyFactory cannot be resolved to a type

An error occurred at line: 10 in the jsp file: /processPassword.jsp
Generated servlet error:
SecretKeyFactory cannot be resolved


    at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
    at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
    at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:414)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:297)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
    at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:303)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at com.isomorphic.servlet.CompressionFilter.doFilter(CompressionFilter.java:260)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:581)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.wso2.carbon.tomcat.ext.valves.CompositeValve.invoke(CompositeValve.java:172)
    at org.wso2.carbon.tomcat.ext.valves.CarbonContextCreatorValve.invoke(CarbonContextCreatorValve.java:52)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1653)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:701)

Wonder what could be causing these compile errors and how to avoid them without having to put the jce.jar in WEB-INF/lib

If I use javax.crypto package in a servlet it compiles and runs fine. Which leads me to believe there is a classpath problem with jsp compilation on WSO2 application server version 5.0.1.

Any suggestions?

2

There are 2 best solutions below

0
On

Since jce.jar is part of jre, it should be available on jsp compilation classpath. As such it should require no extra web-application specific classloading e.g. via webapp-classloading.xml. Below is the start of a jsp page that fails to compile & run on 5.0.1 :

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page language="java" import="java.util.*" %>
<%@ page language="java" import="org.apache.axiom.om.util.Base64"%>
<%@ page language="java" import="java.security.SecureRandom"%>
<%@ page language="java" import="java.security.spec.KeySpec"%>
<%@ page language="java" import="javax.crypto.SecretKeyFactory"%>
<%@ page language="java" import="javax.crypto.spec.PBEKeySpec"%>

Can you confirm this works in 5.1.0 without having to set web-app specific classpath?

0
On

This could be a classloading issue in app server, But we ave fixed it on 5.1.0 version. We have introduce a new xml file named as webapp-classloading.xml to avoid classloading issues.

Please refer http://docs.wso2.org/display/AS510/Webapp+ClassLoading