Modified classes are not picked by Tomcat - java

I have modified few classes (like HiveConnection.class, HiveDatabaseMetaData.class, HiveResultSetMetaData.class, HiveStatement.class) in hive-jdbc-0.13.1-cdh5.3.3.jar, and created a new jar which contains only modified classes and named it as 0_modified_hive_jdbc.jar.
Those classes has some overriden methods which was throwing method not supported exception. Instead we created class in the same name, we logged message, and not throwing exception.
Placed hive-jdbc-0.13.1-cdh5.3.3.jar inside tomcat/lib (because org.apache.hive.jdbc.HiveDriver is referred as a driver name for a JNDI in server.xml)
I have placed all external jars like this,
/home/nages/external_jar/0_override/0_modified_hive_jdbc.jar
/home/nages/external_jar/hive/hive-jdbc-0.13.1-cdh5.3.3.jar
/home/nages/external_jar/others/commons-lang-2.5.jar
/home/nages/external_jar/others/spring-beans-2.5.3.jar
/home/nages/external_jar/others/spring-context-2.5.3.jar
/home/nages/external_jar/others/spring-core-2.5.3.jar
/home/nages/external_jar/others/spring-jdbc-2.5.3.jar
/home/nages/external_jar/others/spring-tx-2.5.3.jar
etc..
Referred these jars like this
File /home/nages/tomcat/conf/Catalina/localhost/myapp.xml
<Context reloadable="true" path="/myapp">
<Loader className="org.apache.catalina.loader.VirtualWebappLoader" virtualClasspath="/home/nages/external_jar/0_overrider/*.jar;/home/nages/external_jar/hive/*.jar;/home/nages/external_jar/others/*.jar;/etc/hadoop/conf/;"/>
</Context>
Deployed my application (myapp.war) in tomcat.
find.jsp presented in myapp.war.
/home/nages/tomcat/webapps/myapp/find.jsp
Here is the piece of code presented in find.jsp
ClassLoader loader = clazz.getClassLoader();
if (loader == null){
throw new Exception("Class Loader is null.");
}
String fileName = className.replace('.','/')+".class";
URL fileUrl = loader.getResource(fileName);
out.println("<b>Location : </b>" + fileUrl);
When I request for org.apache.hive.jdbc.HiveConnection in find.jsp, it returns,
Location : jar:file:/home/nages/external_jar/0_override/0_modified_hive_jdbc.jar!/org/apache/hive/jdbc/HiveConnection.class.
Inside war there is a java class, which has the following code
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.support.rowset.SqlRowSet;
JdbcTemplate template = new JdbcTemplate(getDataSource("Hive"));
SqlRowSet sqs = template.queryForRowSet(sqlQuery);
I am getting following exception
Caused by: java.sql.SQLException: Method not supported
at org.apache.hive.jdbc.HiveResultSetMetaData.isSigned(HiveResultSetMetaData.java:141)
at com.sun.rowset.CachedRowSetImpl.initMetaData(CachedRowSetImpl.java:726)
at com.sun.rowset.CachedRowSetImpl.populate(CachedRowSetImpl.java:640)
at org.springframework.jdbc.core.SqlRowSetResultSetExtractor.createSqlRowSet(SqlRowSetResultSetExtractor.java:66)
at org.springframework.jdbc.core.SqlRowSetResultSetExtractor.extractData(SqlRowSetResultSetExtractor.java:49)
at org.springframework.jdbc.core.JdbcTemplate$1QueryStatementCallback.doInStatement(JdbcTemplate.java:447)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:395)
... 48 more
Question is why it is not picking org.apache.hive.jdbc.HiveResultSetMetaData.class from overriden jar? find.jsp says the classloader picks this from overriden jar, whereas while executing query it picks from somewhere else.
Java : 1.7_45u
tomcat : 7.0.35

Related

How to set JsonTemplateLayout eventTemplateUri outside of classpath in Log4j2

In Log4j2's JsonTemplateLayout, I have no problem using eventTemplateUri: "classpath:LayoutTemplate.jsson" with json file located in rc/main/resources.
However, I would need to keep this file outside of class path. so I would like to use file location something like he way we add log fileName: c:\...
But it's throwing an error when I use eventTemplateUri: "C:\ ....\LayoutTemplate.json"
rror message is " Could not create plugin of type class org.apache.logging.log4j.layout.template.json.JsonTemplateLa
yout for element JsonTemplateLayout: java.lang.RuntimeException: failed reading URI: C:...
Did I miss anything here?
is it possible to place this json file outside of class path?
Thanks!
All *Uri configuration knobs in JsonTemplateLayout expect a URI string. In your case, the URI scheme is missing. The eventTemplateUri should look like file:///C:/path/to/LayoutTemplate.json in your case. For internals, see how o.a.l.l.l.template.json.util.Uris.readUri(String,Charset) is implemented.

How to resolve exception attempting to load java class in DB2 Java Stored procedure?

I have created Java.sqlj program and done with creating packages and jar, when attempting to call the procedure, facing the error like
ATTEMPTING‬‎ ‪TO‬‎ ‪LOAD‬‎ ‪JAVA‬‎ ‪CLASS‬‎ ‪s1‬‎.‪S1Sal‬‎ ‪FROM‬‎ ‪JAR‬‎ ‪COEDB‬‎.‪S1SAL‬‎
Here s1‬‎.‪S1Sal - Where s1 is the package name and S1Sal is class name and it's defined in the java program.
Error
‪
Run‬‎:‪‬‎ ‪SYSPROC‬‎.‪S1NUM‬‎(‪DECIMAL‬‎(‪4‬‎,‪‬‎ ‪0‬‎)‪‬‎)‪
‬‪‬‎{‪call‬‎ ‪SYSPROC‬‎.‪S1NUM‬‎(‪‬‎?‪‬‎)‪‬‎}‪
‬‪USER‬‎-‪DEFINED‬‎ ‪ROUTINE‬‎ ‪SYSPROC‬‎.‪S1NUM‬‎ ‪ENCOUNTERED‬‎ ‪AN‬‎ ‪ EXCEPTION‬‎ ‪ATTEMPTING‬‎ ‪TO‬‎ ‪LOAD‬‎ ‪JAVA‬‎ ‪CLASS‬‎ ‪s1‬‎.‪S1Sal‬‎ ‪FROM‬‎ ‪JAR‬‎ ‪COEDB‬‎.‪S1SAL‬‎.‪‬‎ ‪ ORIGINAL‬‎ ‪EXCEPTION‬‎:‪‬‎ ‪‬‎(‪none‬‎)‪‬‎.‪‬‎ ‪SQLCODE‬‎=‪‬‎-‪20212‬‎,‪‬‎ ‪SQLSTATE‬‎=‪46103‬‎,‪‬‎ ‪DRIVER‬‎=‪4‬‎.‪22‬‎.‪29
‬‪Run‬‎ ‪of‬‎ ‪routine‬‎ ‪failed‬‎.‪
‬‪‬‎ ‪‬‎-‪‬‎ ‪Roll‬‎ ‪back‬‎ ‪completed‬‎ ‪successfully‬‎.‪

Java getClass().getClassLoader().getResource( "/My_Form.xsd") returns null

Overview: last year, I supervised a contractor who ported a web application from WebSphere 5/Java 4 to Tomcat 7/Java 7. This year, we discovered a little-used feature is broken. Organizational changes have reduced the team working in this area to just me, so I don't have anyone to talk this over with.
I tracked the problem down to getClass().getResource("/My_Form.xsd") returning null. I checked the obvious: the root of the war file does contain My_Form.xsd, and it sits on disk where Tomcat explodes the war file.
Here's the code (slightly refactored from the original Java 4 version):
package com.mycompany;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
...
public class MyFormMaintenanceFactory {
...
public DocumentBuilderFactory getDocumentBuilderFactory()
throws Exception
{
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setValidating(true);
dbf.setNamespaceAware(true);
dbf.setIgnoringComments(true);
dbf.setIgnoringElementContentWhitespace(true);
dbf.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
String schema = "/My_Form.xsd";
URL schemaUrl = getClass().getClassLoader().getResource( schema);
if (schemaUrl == null) {
throw new Exception("Could not getResource " + schema);
}
dbf.setAttribute( JAXP_SCHEMA_SOURCE, schemaUrl.toExternalForm());
return dbf;
}
...
}
The output is a stack trace from the "throw new Exception(...)" line:
17:38:56.756(03/20) INFO MyApp : java.lang.Exception: Could not getResource /My_Form.xsd
and a stack trace.
I've tried other forms of the call. Neither of these work any better:
URL schemaUrl = getClass().getResource("/My_Form.xsd");
URL schemaUrl = DocumentBuilderFactory.class.getClassLoader().getResource( schema);
In response to another question about getResource() returning null, the suggestion was to run jar tf AppName.war.
I did that, and My_Form.xsd is at the root of the war file:
$ jar tf MyApp-3.0.1-SNAPSHOT.war
META-INF/
META-INF/MANIFEST.MF
Global/
...
Modules/
...
shared/
theme/
WEB-INF/
WEB-INF/classes/
WEB-INF/classes/com/
...
WEB-INF/classes/resources/
WEB-INF/lib/
WEB-INF/lib/tomcat_jars/
...
WEB-INF/struts-config/
WEB-INF/taglibs/
Global/css/components/basicControl.css
...
Global/image/arrow.gif
Global/image/atsign.jpg
Global/image/banner_background.gif
...
Global/JavaScript/components/ajax.js
,,,
Global/jsp_pages/components/basicControl.jsp
Global/jsp_pages/components/basicControlTitle.jsp
...
index.jsp
...
Modules/Global_Internal/jsp_pages/body.jsp
Modules/Global_Internal/jsp_pages/layout.jsp
Modules/Global_Internal/jsp_pages/sidebar.jsp
Modules/help/FAQ.html
...
shared/searchUtil.js
...
showAllTickets.jsp
showAllTickets_body.jsp
My_Form.xsd
theme/Master.css
WEB-INF/classes/com/mycompany/MyFormMaintenanceFactory.class
WEB-INF/classes/com/mycompany/MyFormMaintenanceFactory.java
...
WEB-INF/classes/resources/MyApp.properties
...
WEB-INF/lib/commons-beanutils-1.7.0.jar
WEB-INF/lib/commons-beanutils.jar
WEB-INF/lib/commons-chain-1.2.jar
WEB-INF/lib/commons-collections-2.1.jar
...
WEB-INF/web.xml
META-INF/maven/
...
$
I've read the documentation and every page I can find about others having this error, and I can't figure out what the code is doing wrong. The same call worked in WebSphere 5/Java 4. I will gratefully accept any and all suggestions...
Resources need to be in the /WEB-INF/classes folder of the exploded war. The full path of the file needs to be <root-dir>/WEB-INF/classes/My_Form.xsd. Typically if you put the file in src/main/resources in the build project, modern build tools (e.g. Maven) will normally copy them correctly to the war archive at /WEB-INF/classes when the war archive is created.

Osmosis open Resource : NullPointerException at Parameters$Builder.loadResource

According to the Osmosis Github site I've installed Osmosis and I am trying to put an osm package to Elasticsearch by typing:
$ osmosis --read-pbf ~/osm/extract/azores-latest.osm.pbf --write-elasticsearch cluster.hosts="localhost"
The execution fails with:
SEVERE: Execution aborted.
java.lang.NullPointerException at org.openstreetmap.osmosis.plugin.elasticsearch.utils.Parameters$Builder.loadResource(Parameters.java:57)
at org.openstreetmap.osmosis.plugin.elasticsearch.ElasticSearchWriterFactory.buildPluginParameters(ElasticSearchWriterFactory.java:49)
at org.openstreetmap.osmosis.plugin.elasticsearch.ElasticSearchWriterFactory.createTaskManagerImpl(ElasticSearchWriterFactory.java:27)
at org.openstreetmap.osmosis.core.pipeline.common.TaskManagerFactory.createTaskManager(TaskManagerFactory.java:60)
The ElasticSearchWriterFactory handles "plugin.properties" to the Parameters$Builder.loadResource() method. I've tried to figure the problem out by adding some log lines into the /elasticsearch-osmosis-plugin-1.3.0.jar. So I get:
resource: plugin.properties
getClass() : class org.openstreetmap.osmosis.plugin.elasticsearch.utils.Parameters$Builder
getClass().getClassLoader() : ClassRealm[osmosis.core, parent: null]
getClass().getName() : org.openstreetmap.osmosis.plugin.elasticsearch.utils.Parameters$Builder
getClass().getPackage() : package org.openstreetmap.osmosis.plugin.elasticsearch.utils
getClass().getClassLoader().getResource(resource) : null
getClass().getClassLoader().getResource("/opt/osmosis-0.43/" + resource) : null
(The last line in order to test if the relative path was the problem but that does not seem to be the problem.)
I'va also copied plugin.properties to any location / path that I could imagine to be part of interest, i.e. package root etc. ... with no success.
Anybody an idea how to solve that? Thanks very much!

NoClassDefFound error using Jode obfuscator

I'm using jode's obfuscator in an attempt to obfuscate all of the class files in my jar. I've packaged all the class files in the jar, so that I can use the config to specify what I need loading, and what I need preserving.
Here is my package hierarchy:
src
src.loading
src.loading.org
src.loading.sign
Here's what I've specified as my wildcards:
load = new WildCard { value = "src.*" }
preserve = new WildCard { value = "src.loading.org.*" }
And this is the error I get (Decompiling too. It's the only class.)
C:\Users\Kieran\Desktop\jode>java jode.obfuscator.Main project.jos
Jode (c) 1998-2001 Jochen Hoenicke <jochen#gnu.org>
used before: 479080
Loading and preserving classes
Exception in thread "main" java.lang.NoClassDefFoundError: src.loading.Class48
at jode.bytecode.ClassInfo.loadInfo(ClassInfo.java:631)
at jode.obfuscator.ClassIdentifier.initClass(ClassIdentifier.java:371)
Exception while decompiling:java.lang.NoClassDefFoundError: src.loading.Class48
at jode.bytecode.ClassInfo.loadInfo(ClassInfo.java:631)
at jode.decompiler.ClassAnalyzer.<init>(ClassAnalyzer.java:86)
at jode.decompiler.ClassAnalyzer.<init>(ClassAnalyzer.java:123)
at jode.decompiler.Decompiler.decompile(Decompiler.java:191)
at jode.swingui.Main.run(Main.java:204)
at java.lang.Thread.run(Unknown Source)
The class does exist, and I the jar file is fully functional. Why am I getting this error?
This specific class is using reflection, to access java.lang.Runtime, could this be the issue...?

Categories

Resources