I wrote a Hbase Java basic code that works fine with Java.
public class HBaseTest {
public static String newFunc() throws IOException {
// Instantiating configuration class
Configuration config = HBaseConfiguration.create();
Connection connection = ConnectionFactory.createConnection(config);
Table table = connection.getTable(TableName.valueOf("customer"));
Get g = new Get(Bytes.toBytes("jsmith"));
Result result = table.get(g);
// Reading values from Result class object
byte[] value = result.getValue(Bytes.toBytes("addr"), Bytes.toBytes("city"));
return Bytes.toString(value);
}
}
So I decided to use this code and Hbase as a part of my web application development and so I opened a new Dynamic Web Project in Eclipse Java EE IDE and added this file, changed the name of function and called it from one of the servlets. I also added the required jar files.
But I am stuck with the following error:
java.lang.ClassNotFoundException: org.apache.hadoop.hbase.HBaseConfiguration
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1332)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1166)
at HBaseTest.newFunc(HBaseTest.java:18)
at BakwasServlet.doGet(BakwasServlet.java:16)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1099)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:670)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
This error is frustrating me now. Has anyone encountered such a case before or can anyone help me on this? I don't have hbase_home variable set up. I didn't need it for the java code as well.
Thanks in advance!
Where have you added the HBase JAR file? It should be in the WEB-INF/lib folder of your web application (or in the server's lib folder, but it's better to keep it within the app).
Related
I'm working on implementing Amazon Pay, and instead of converting one of the SDKs to CF, figured I would just use the java sdk - but, I haven't ever worked with anything that is not part of the java core install. Any ideas why this
createObject('java', 'com.amazon.pay.api.WebstoreClient')
is not working ( Object instantiation exception. Error: org/json/JSONException.) when I drop the jar in cfusion\wwwroot\web_inf\lib.
the jar file came from here: https://github.com/amzn/amazon-pay-api-sdk-java/releases
I suspect that the issue is with the import statements for the "core" libraries, but don't know why CF wouldn't be able to find them (seems pretty basic) so I must be doing something wrong.
Windows 10 dev box running CF2016, dev install with a single instance, both restarted and rebooted.
ANSWERED BY #SOS IN THE COMMENTS - reposted here.
Downloaded the sdk to c:/path/to/lib/amazon-pay-api-2.5.1.jar.
Added
this.javaSettings = {
LoadPaths = [ "c:/path/to/lib/amazon-pay-api-2.5.1.jar"],
loadColdFusionClassPath=true };
Restarted Application.cfc
Edited to add code and complete error
This is the complete contents of the file that errors. I have tried both ways and get the same error -
<!--- <cfobject action="create" type="java" class="com.amazon.pay.api.WebstoreClient" name="WebstoreClient"> --->
<cfset wsClient=createObject('java', 'com.amazon.pay.api.WebstoreClient')>
<cfdump var="#wsClient#">
The error
Object instantiation exception.
An exception occurred while instantiating a Java object.
Error: org/json/JSONException.
The error occurred in E:/webroot/striking/d.cfm: line 2
1 : <!--- <cfobject action="create" type="java" class="com.amazon.pay.api.WebstoreClient" name="WebstoreClient"> --->
2 : <cfset wsClient=createObject('java', 'com.amazon.pay.api.WebstoreClient')>
3 :
4 : <cfdump var="#wsClient#">
Resources:
Check the ColdFusion documentation to verify that you are using the correct syntax.
Search the Knowledge Base to find a solution to your problem.
Browser Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.61 Safari/537.36
Remote Address 127.0.0.1
Referrer
Date/Time 27-May-22 10:20 AM
Stack Trace
at cfd2ecfm486526222.runPage(E:/webroot/striking/d.cfm:2) at cfd2ecfm486526222.runPage(E:/webroot/striking/d.cfm:2)
java.lang.NoClassDefFoundError: org/json/JSONException
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Class.java:2583)
at java.lang.Class.privateGetPublicFields(Class.java:2614)
at java.lang.Class.getFields(Class.java:1557)
at coldfusion.runtime.java.ObjectHandler.Initialize(ObjectHandler.java:35)
at coldfusion.runtime.java.ObjectHandler.<init>(ObjectHandler.java:30)
at coldfusion.runtime.java.ReflectionCache.get(ReflectionCache.java:47)
at coldfusion.runtime.java.JavaProxy.<init>(JavaProxy.java:35)
at coldfusion.runtime.java.JavaProxyFactory.getProxy(JavaProxyFactory.java:121)
at coldfusion.runtime.ProxyFactory.getProxy(ProxyFactory.java:68)
at coldfusion.runtime.CFPage.createObjectProxy(CFPage.java:6608)
at coldfusion.runtime.CFPage.CreateObject(CFPage.java:6571)
at coldfusion.runtime.CFPage.CreateObject(CFPage.java:6505)
at coldfusion.runtime.CFPage.CreateObject(CFPage.java:6431)
at coldfusion.runtime.CFPage.CreateObject(CFPage.java:6372)
at cfd2ecfm486526222.runPage(E:\webroot\striking\d.cfm:2)
at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:251)
at coldfusion.tagext.lang.IncludeTag.handlePageInvoke(IncludeTag.java:737)
at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:573)
at coldfusion.filter.CfincludeFilter.invoke(CfincludeFilter.java:65)
at coldfusion.filter.IpFilter.invoke(IpFilter.java:45)
at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:505)
at coldfusion.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:43)
at coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40)
at coldfusion.filter.PathFilter.invoke(PathFilter.java:153)
at coldfusion.filter.LicenseFilter.invoke(LicenseFilter.java:30)
at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:94)
at coldfusion.filter.BrowserDebugFilter.invoke(BrowserDebugFilter.java:78)
at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28)
at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38)
at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:60)
at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38)
at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)
at coldfusion.filter.CachingFilter.invoke(CachingFilter.java:62)
at coldfusion.CfmServlet.service(CfmServlet.java:219)
at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:42)
at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at coldfusion.inspect.weinre.MobileDeviceDomInspectionFilter.doFilter(MobileDeviceDomInspectionFilter.java:121)
at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at com.seefusion.Filter.doFilter(Filter.java:109)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at com.seefusion.SeeFusionValve.invoke(SeeFusionValve.java:52)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:536)
at org.apache.coyote.ajp.AbstractAjpProcessor.process(AbstractAjpProcessor.java:898)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: org.json.JSONException
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1308)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1142)
... 68 more
Regards,
M
I have a problem and I don't know how to solve it.
My web application MyApp is a Maven web application project (Java 8 and Java EE 5). To run an updated version as test instance on the same server, I changed the Context Path of the application from MyApp to MyAppTest. As servlet container, I'm using Tomcat 8.
The MyApp instance is working as expected. However the MyAppTest instance is throwing an exception when forwarding the request to one of my servlets. Even if MyApp and MyAppTest are identical except the context path, this exception occurs. The Servlets are mapped via Guice's ServletModule.
Message:
java.lang.StringIndexOutOfBoundsException: String index out of range: -4
StackTrace:
java.lang.String.substring(Unknown Source)
com.google.inject.servlet.ServletDefinition$2.getPathInfo(ServletDefinition.java:212)
org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:376)
org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:318)
myapp.base.MainEntryServlet.service(MainEntryServlet.java:49)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
com.google.inject.servlet.ServletDefinition.doServiceImpl(ServletDefinition.java:286)
com.google.inject.servlet.ServletDefinition.doService(ServletDefinition.java:276)
com.google.inject.servlet.ManagedServletPipeline$1.doServiceImpl(ManagedServletPipeline.java:154)
com.google.inject.servlet.ManagedServletPipeline$1.forward(ManagedServletPipeline.java:140)
myapp.auth.LogoutServlet.service(LogoutServlet.java:57)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
com.google.inject.servlet.ServletDefinition.doServiceImpl(ServletDefinition.java:286)
com.google.inject.servlet.ServletDefinition.doService(ServletDefinition.java:276)
com.google.inject.servlet.ServletDefinition.service(ServletDefinition.java:181)
com.google.inject.servlet.ManagedServletPipeline.service(ManagedServletPipeline.java:91)
com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:85)
com.google.inject.servlet.ManagedFilterPipeline.dispatch(ManagedFilterPipeline.java:120)
com.google.inject.servlet.GuiceFilter.doFilter(GuiceFilter.java:135)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528)
org.apache.coyote.ajp.AbstractAjpProcessor.process(AbstractAjpProcessor.java:873)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:670)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Unknown Source)
The Servlet forwarding the Request does this:
RequestDispatcher dispatcher = request.getRequestDispatcher("/index.jsp");
if (!response.isCommitted()) {
dispatcher.forward(request, response);
}
The URL index.jsp is mapped to another Servlet. It forwards the request to a JSP:
request.getRequestDispatcher("/theme/index.jsp").forward(request, response);
There the exception occurs. Some other JSPs are included into the index.jsp like this:
<jsp:include flush="true" page="menu.jsp"/>
The menu.jsp is located in the same folder as the index.jsp.
As mentioned before, everything works fine as long as the Context path is MyApp. When changed to MyAppTest the exception occurs. It must have something to do with the Context path itself. When changing the Path to MyAppTest, the exception message is "String index out of range: -4". When I change the Path to MyAppTesting, the exception message changes to "String index out of range: -7".
To solve this I tried the following:
Changing the Context path and the docBase to MyAppTest in the context.xml of the project.
Changing the Artifact ID of the project to MyAppTest.
Changing the Project Name to MyAppTest.
Nothing worked. And I don't know what causes the exeption: Maven, Tomcat or Guice.
I am making a dynamic web project, which requires to use an external jar file. That jar uses several JNI so files. Now I have the jar and all the required so files. I have added the jar to the java build path, but I am not sure how to introduce the so files to the tomcat server.
I tried adding path to the so file as "LD_LIBRARY_PATH":
(Properties->Run/Debug Settings->edit->Environment->Select) and also
adding the path to "java.library.path"(Run
As->RunConfigurations->Tomcat v8 Server->Arguments->VM arguments)
flag.
Still it is not working, I am getting below error, whenever the my code is trying to access functions/classes from the above mentioned jar:
SEVERE: Servlet.service() for servlet [org.iotivity.simulator.agent.LaunchSimulator] in context with path
[/SimulatorAgent] threw exception [Servlet execution threw an
exception] with root cause java.lang.ClassNotFoundException:
org.oic.simulator.server.SimulatorResource$Type at
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1305)
at
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1139)
at
org.iotivity.simulator.agent.LaunchSimulator.doPost(LaunchSimulator.java:86)
at
org.iotivity.simulator.agent.LaunchSimulator.doGet(LaunchSimulator.java:45)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:622) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:729) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522)
at
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095)
at
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
at
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1502)
at
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1458)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
I have tried the same code with a simple Java Application, and it works fine by setting the LD_LIBRARY_PATH variable.
Any suggestion will be highly appreciated.
Your error is a ClassNotFoundException, which would suggest that the JAR isn't properly included. If there was a problem with the native library, you'd get a UnsatisfiedLinkError instead. To make the JAR available to Tomcat, you'd need to add it to the classpath (-classpath=/path/to/your.jar) or include it in your WAR. The latter depends on your build system, but if you use Maven it's rather easy using the maven-shade-plugin (this only works for the JAR though, the native code you'll have to keep on distributing separately). Hope that helps!
I want to store my H2 database as an encrypted file and access its web interface.
I configured H2 database so that I can access web interface to manipulate the database under console/db address.
When I do not use encryption everything works fine.
When I add CIPHER=AES to db.url I cannot log into the database and get below exception:
File corrupted while reading record: null. Possible solution: use the recovery tool [90030-191] 90030/90030 (Help)
org.h2.jdbc.JdbcSQLException: Uszkodzenie pliku podczas wczytywania rekordu: null
File corrupted while reading record: null. Possible solution: use the recovery tool [90030-191]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
at org.h2.message.DbException.get(DbException.java:168)
at org.h2.mvstore.db.MVTableEngine$Store.convertIllegalStateException(MVTableEngine.java:195)
at org.h2.mvstore.db.MVTableEngine$Store.open(MVTableEngine.java:167)
at org.h2.mvstore.db.MVTableEngine.init(MVTableEngine.java:99)
at org.h2.engine.Database.getPageStore(Database.java:2460)
at org.h2.engine.Database.open(Database.java:692)
at org.h2.engine.Database.openDatabase(Database.java:270)
at org.h2.engine.Database.<init>(Database.java:264)
at org.h2.engine.Engine.openSession(Engine.java:65)
at org.h2.engine.Engine.openSession(Engine.java:175)
at org.h2.engine.Engine.createSessionAndValidate(Engine.java:153)
at org.h2.engine.Engine.createSession(Engine.java:136)
at org.h2.engine.Engine.createSession(Engine.java:28)
at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:349)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:107)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:91)
at org.h2.Driver.connect(Driver.java:72)
at org.h2.server.web.WebServer.getConnection(WebServer.java:735)
at org.h2.server.web.WebApp.login(WebApp.java:955)
at org.h2.server.web.WebApp.process(WebApp.java:211)
at org.h2.server.web.WebApp.processRequest(WebApp.java:170)
at org.h2.server.web.WebServlet.doGet(WebServlet.java:125)
at org.h2.server.web.WebServlet.doPost(WebServlet.java:162)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1502)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1458)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalStateException: Store header is corrupt: nio:/home/robak/db/adzfo.mv.db [1.4.191/6]
at org.h2.mvstore.DataUtils.newIllegalStateException(DataUtils.java:773)
at org.h2.mvstore.MVStore.readStoreHeader(MVStore.java:603)
at org.h2.mvstore.MVStore.<init>(MVStore.java:353)
at org.h2.mvstore.MVStore$Builder.open(MVStore.java:2888)
at org.h2.mvstore.db.MVTableEngine$Store.open(MVTableEngine.java:154)
... 47 more
Database Configuration
db.driver=org.h2.Driver
db.url=jdbc:h2:file:~/db/app_name;AUTO_SERVER=TRUE;CIPHER=AES
db.username=user
db.password=password
Servlet Context
private void configureDatabaseConsole(ServletContext servletContext) {
ServletRegistration.Dynamic h2Servlet = servletContext.addServlet("h2console", WebServlet.class);
h2Servlet.setLoadOnStartup(2);
h2Servlet.addMapping("/console/db/*");
}
Data source
#Bean
public DataSource dataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(getProperty(DRIVER));
dataSource.setUrl(getProperty(URL));
dataSource.setUsername(getProperty(USERNAME));
dataSource.setPassword(FILE_PASSWORD + " " + getProperty(PASSWORD));
return dataSource;
}
What should I do to have an encrypted database as a file on a hard drive and to access its console via web interface?
Are you sure you using the right password. Quoting from the H2 documentation File Encryption
The encryption algorithm is set in the database URL, and the file
password is specified in the password field, before the user
password. A single space separates the file password and the user
password; the file password itself may not contain spaces. File
passwords and user passwords are case sensitive. Here is an example
to connect to a password-encrypted database:
Class.forName("org.h2.Driver");
String url = "jdbc:h2:~/test;CIPHER=AES";
String user = "sa";
String pwds = "filepwd userpwd";
conn = DriverManager.
getConnection(url, user, pwds);
If you don't provide the correct password you won't get a connection.
Configuration
jdk version : 1.8.0_60-b27
project : maven jsp project
Mysql connector : mysql-connector-java-5.1.38 (Copied to Tomcat's lib)
Pom.xml
<!--MySql Connector/J Dependency-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
<scope>provided</scope>
</dependency>
Code Causing Error :
try(Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/myDatabase","root","")){
connection=con;
} catch (SQLException e) {
e.printStackTrace();
return null;
}
Error log
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/myDatabase
at java.sql.DriverManager.getConnection(DriverManager.java:689)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at util.DBConnectivity.getDBConnection(DBConnectivity.java:16)
at controller.MyController.doGet(MyController.java:25)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:217)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2503)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2492)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
I tried both of the scopes [provided and compile] in pom.xml but no change in the output!!!
Tried hundred times but can't figure out why project is not able to find the driver????
What you need to do is just these two steps, and not more:
Include your dependency properly:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>
Notice that scope is not configures, so by default it will be compile, which will make it available at runtime too.
The combination of manually copying this file to WEB-INF\lib then redeploy with scope=provided will not work because the folder will get recreated. In case you would like to make this jar available only at runtime, you need to place it to Tomcat\lib.
You need to manually load the driver before you attempt to connect anywhere. Make sure you do this before using DriverManager.
Class.forName("com.mysql.jdbc.Driver");
you are not getting the connection from a datasource hence you are not using the mysql driver in the tomcat lib.
Using DriverManager you need to load the jdbc library yourself using Class.forName("com.mysql.jdbc.Driver").newInstance(); and by removing the provided entry for it in the pom.xml or... use a datasource :)