Impala Kerberos authentication issue with long running program - jdbc

I developed a Java program that runs on a Hadoop Edge Node (Cloudera CDH 5.9.1). It runs "for ever" as it is a (micro)service replying to requests. It receives requests from a webapp running somewhere else and extract data from Impala using Impala JDBC driver and send back data.
It runs well during roughly 10 hours, then it becomes unable to get Impala JDBC connections. You will find stacktrace and the end of this question. In short, it throws javax.security.auth.login.LoginException: Unable to obtain Principal Name for authentication.
My understanding is that Impala JDBC driver becomes enable to authenticate against Kerberos because the Kerberos ticket expired. So to be sure that the user with who the program is launched has a Kerberos ticket, I added a piece of code before the JDBC connection creation. I read those 2 Stackoverflow threads :
Should I call ugi.checkTGTAndReloginFromKeytab() before every action on hadoop?
HBase Kerberos connection renewal strategy
They explained very well the issue and the solution. Here is my attempt to implement that (I don't understand why it fails for Impala) :
public class KerberosRelogger {
private final static Logger logger = LogManager.getLogger();
public static String userName;
public static String user;
public static String keytab;
public static Configuration conf;
private static UserGroupInformation ugi;
static {
try {
init();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static void init() throws IOException {
userName = System.getProperty("user.name");
user = userName + "#MY_REALM";
keytab = System.getProperty("user.home") + "/" + userName + ".keytab";
conf = new Configuration();
conf.addResource(new Path("file:///etc/hadoop/conf/core-site.xml"));
conf.addResource(new Path("file:///etc/hadoop/conf/hdfs-site.xml"));
UserGroupInformation.setConfiguration(conf);
ugi = UserGroupInformation.loginUserFromKeytabAndReturnUGI(user, keytab);
logger.debug("userName : {}", userName);
logger.debug("user : {}", user);
logger.debug("keytab : {}", keytab);
}
public static void testHadoopConnexion() throws IOException {
ugi.checkTGTAndReloginFromKeytab();
FileSystem fs = FileSystem.get(conf);
FileStatus[] statuses = fs.listStatus(new Path("/"));
List<String> dirNames = new ArrayList<>();
for (FileStatus status : statuses) {
dirNames.add(status.getPath().getName());
}
logger.debug("HDFS root dirs : " + dirNames);
}
private static Connection createImpalaConnection() throws IOException {
ugi.checkTGTAndReloginFromKeytab();
String IMPALAD_HOST = "my_node";
String jdbcUrl = "jdbc:impala://" + IMPALAD_HOST + ":21050;AuthMech=1;KrbRealm=MY_REALM;KrbHostFQDN=" + IMPALAD_HOST + ";KrbServiceName=impala;SSL=1";
Properties props = new Properties();
props.put("user", userName);
props.put("password", "");
try {
Connection connection = DriverManager.getConnection(jdbcUrl, props);
return connection;
} catch (SQLException e) {
throw new RuntimeException("Fail to create JDBC connection", e);
}
}
private static void testImpalaConnection() throws IOException, SQLException {
int n = 0;
try (Connection cnx = createImpalaConnection()) {
String sql = "show databases";
try (PreparedStatement ps = cnx.prepareStatement(sql)) {
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
n++;
}
}
}
}
logger.debug("{} Impala databases", n);
}
public static void main(String[] args) {
ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
scheduledExecutorService.scheduleAtFixedRate(new Runnable() {
#Override
public void run() {
try {
logger.debug("Test Hadoop connection");
testHadoopConnexion();
logger.debug("Hadoop connection - SUCCESS");
} catch (Exception e) {
logger.error("Hadoop connection - FAIL", e);
}
System.out.println();
try {
logger.debug("Test Impala connection");
testImpalaConnection();
logger.debug("Impala connection - SUCCESS");
} catch (Exception e) {
logger.error("Impala connection - FAIL", e);
}
}
}, 1, 10, TimeUnit.SECONDS);
}
}
If the ticket expired or if I perform a "kdestroy" with the command line, Hadoop HDFS listing still works but Impala JDBC driver is unable to get a connection.
Why Impala cannot authenticate whereas Hadoop API calls works ? It the Hadoop API works, it means that the programmatic relogin worked and that a "fresh" ticket is there. Am i right ? Why Impala failed on its side ?
Exception stacktrace
Caused by: java.sql.SQLException: [Simba][ImpalaJDBCDriver](500168) Error creating login context using ticket cache: Unable to obtain Principal Name for authentication .
at com.cloudera.hivecommon.api.HiveServer2ClientFactory.createTransport(Unknown Source) ~[ImpalaJDBC41.jar:ImpalaJDBC_2.5.41.1061]
at com.cloudera.hivecommon.api.HiveServer2ClientFactory.createClient(Unknown Source) ~[ImpalaJDBC41.jar:ImpalaJDBC_2.5.41.1061]
at com.cloudera.hivecommon.core.HiveJDBCCommonConnection.establishConnection(Unknown Source) ~[ImpalaJDBC41.jar:ImpalaJDBC_2.5.41.1061]
at com.cloudera.impala.core.ImpalaJDBCConnection.establishConnection(Unknown Source) ~[ImpalaJDBC41.jar:ImpalaJDBC_2.5.41.1061]
at com.cloudera.jdbc.core.LoginTimeoutConnection.connect(Unknown Source) ~[ImpalaJDBC41.jar:ImpalaJDBC_2.5.41.1061]
at com.cloudera.jdbc.common.BaseConnectionFactory.doConnect(Unknown Source) ~[ImpalaJDBC41.jar:ImpalaJDBC_2.5.41.1061]
at com.cloudera.jdbc.common.AbstractDriver.connect(Unknown Source) ~[ImpalaJDBC41.jar:ImpalaJDBC_2.5.41.1061]
at java.sql.DriverManager.getConnection(DriverManager.java:664) ~[?:1.8.0_92]
at java.sql.DriverManager.getConnection(DriverManager.java:208) ~[?:1.8.0_92]
...
Caused by: com.cloudera.support.exceptions.GeneralException: [Simba][ImpalaJDBCDriver](500168) Error creating login context using ticket cache: Unable to obtain Principal Name for authentication .
at com.cloudera.hivecommon.api.HiveServer2ClientFactory.createTransport(Unknown Source) ~[ImpalaJDBC41.jar:ImpalaJDBC_2.5.41.1061]
at com.cloudera.hivecommon.api.HiveServer2ClientFactory.createClient(Unknown Source) ~[ImpalaJDBC41.jar:ImpalaJDBC_2.5.41.1061]
at com.cloudera.hivecommon.core.HiveJDBCCommonConnection.establishConnection(Unknown Source) ~[ImpalaJDBC41.jar:ImpalaJDBC_2.5.41.1061]
at com.cloudera.impala.core.ImpalaJDBCConnection.establishConnection(Unknown Source) ~[ImpalaJDBC41.jar:ImpalaJDBC_2.5.41.1061]
at com.cloudera.jdbc.core.LoginTimeoutConnection.connect(Unknown Source) ~[ImpalaJDBC41.jar:ImpalaJDBC_2.5.41.1061]
at com.cloudera.jdbc.common.BaseConnectionFactory.doConnect(Unknown Source) ~[ImpalaJDBC41.jar:ImpalaJDBC_2.5.41.1061]
at com.cloudera.jdbc.common.AbstractDriver.connect(Unknown Source) ~[ImpalaJDBC41.jar:ImpalaJDBC_2.5.41.1061]
at java.sql.DriverManager.getConnection(DriverManager.java:664) ~[?:1.8.0_92]
at java.sql.DriverManager.getConnection(DriverManager.java:208) ~[?:1.8.0_92]
...
Caused by: javax.security.auth.login.LoginException: Unable to obtain Principal Name for authentication
at com.sun.security.auth.module.Krb5LoginModule.promptForName(Krb5LoginModule.java:841) ~[?:1.8.0_92]
at com.sun.security.auth.module.Krb5LoginModule.attemptAuthentication(Krb5LoginModule.java:704) ~[?:1.8.0_92]
at com.sun.security.auth.module.Krb5LoginModule.login(Krb5LoginModule.java:617) ~[?:1.8.0_92]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_92]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_92]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_92]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_92]
at javax.security.auth.login.LoginContext.invoke(LoginContext.java:755) ~[?:1.8.0_92]
at javax.security.auth.login.LoginContext.access$000(LoginContext.java:195) ~[?:1.8.0_92]
at javax.security.auth.login.LoginContext$4.run(LoginContext.java:682) ~[?:1.8.0_92]
at javax.security.auth.login.LoginContext$4.run(LoginContext.java:680) ~[?:1.8.0_92]
at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_92]
at javax.security.auth.login.LoginContext.invokePriv(LoginContext.java:680) ~[?:1.8.0_92]
at javax.security.auth.login.LoginContext.login(LoginContext.java:587) ~[?:1.8.0_92]
at com.cloudera.jdbc.kerberos.Kerberos.getSubjectViaTicketCache(Unknown Source) ~[ImpalaJDBC41.jar:ImpalaJDBC_2.5.41.1061]
at com.cloudera.hivecommon.api.HiveServer2ClientFactory.createTransport(Unknown Source) ~[ImpalaJDBC41.jar:ImpalaJDBC_2.5.41.1061]
at com.cloudera.hivecommon.api.HiveServer2ClientFactory.createClient(Unknown Source) ~[ImpalaJDBC41.jar:ImpalaJDBC_2.5.41.1061]
at com.cloudera.hivecommon.core.HiveJDBCCommonConnection.establishConnection(Unknown Source) ~[ImpalaJDBC41.jar:ImpalaJDBC_2.5.41.1061]
at com.cloudera.impala.core.ImpalaJDBCConnection.establishConnection(Unknown Source) ~[ImpalaJDBC41.jar:ImpalaJDBC_2.5.41.1061]
at com.cloudera.jdbc.core.LoginTimeoutConnection.connect(Unknown Source) ~[ImpalaJDBC41.jar:ImpalaJDBC_2.5.41.1061]
at com.cloudera.jdbc.common.BaseConnectionFactory.doConnect(Unknown Source) ~[ImpalaJDBC41.jar:ImpalaJDBC_2.5.41.1061]
at com.cloudera.jdbc.common.AbstractDriver.connect(Unknown Source) ~[ImpalaJDBC41.jar:ImpalaJDBC_2.5.41.1061]
at java.sql.DriverManager.getConnection(DriverManager.java:664) ~[?:1.8.0_92]
at java.sql.DriverManager.getConnection(DriverManager.java:208) ~[?:1.8.0_92]
...

Related

JPackage Unable to Launch JVM - Circular loading of URL stream handler providers detected

After running jpackage on my JavaFX application using following command:
.\jpackage.exe
--input C:\Users\My\Documents\NetBeansProjects\MyFX\target\
--dest C:\Users\My\Documents\NetBeansProjects\MyFX\
--name "MyFX"
--main-jar C:\Users\My\Documents\NetBeansProjects\MyFX\target\MyFX-2.0.jar
--main-class my.myfx.App
--module-path 'C:\Program Files\Java\jmods\\'
--add-modules javafx.controls,javafx.fxml,java.sql --win-console
I'm getting error on launching the program:
Unable to launch JVM
Error on console:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.Error: Circular loading of URL stream handler providers detected
at java.base/java.net.URL.lookupViaProviders(Unknown Source)
at java.base/java.net.URL.getURLStreamHandler(Unknown Source)
at java.base/java.net.URL.<init>(Unknown Source)
at java.base/jdk.internal.loader.URLClassPath$JarLoader.tryResolveFile(Unknown Source)
at java.base/jdk.internal.loader.URLClassPath$JarLoader.tryResolve(Unknown Source)
at java.base/jdk.internal.loader.URLClassPath$JarLoader.parseClassPath(Unknown Source)
at java.base/jdk.internal.loader.URLClassPath$JarLoader.getClassPath(Unknown Source)
at java.base/jdk.internal.loader.URLClassPath.getLoader(Unknown Source)
at java.base/jdk.internal.loader.URLClassPath$1.next(Unknown Source)
at java.base/jdk.internal.loader.URLClassPath$1.hasMoreElements(Unknown Source)
at java.base/jdk.internal.loader.BuiltinClassLoader$1.hasNext(Unknown Source)
at java.base/jdk.internal.loader.BuiltinClassLoader$1.hasMoreElements(Unknown Source)
at java.base/java.lang.CompoundEnumeration.next(Unknown Source)
at java.base/java.lang.CompoundEnumeration.hasMoreElements(Unknown Source)
at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.nextProviderClass(Unknown Source)
at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNextService(Unknown Source)
at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNext(Unknown Source)
at java.base/java.util.ServiceLoader$2.hasNext(Unknown Source)
at java.base/java.util.ServiceLoader$3.hasNext(Unknown Source)
at java.base/java.net.URL$1.getNext(Unknown Source)
at java.base/java.net.URL$1.hasNext(Unknown Source)
at java.base/java.net.URL$2.run(Unknown Source)
at java.base/java.net.URL$2.run(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Unknown Source)
at java.base/java.net.URL.lookupViaProviders(Unknown Source)
at java.base/java.net.URL.getURLStreamHandler(Unknown Source)
at java.base/java.net.URL.<init>(Unknown Source)
at java.base/jdk.internal.loader.URLClassPath$JarLoader.tryResolveFile(Unknown Source)
at java.base/jdk.internal.loader.URLClassPath$JarLoader.tryResolve(Unknown Source)
at java.base/jdk.internal.loader.URLClassPath$JarLoader.parseClassPath(Unknown Source)
at java.base/jdk.internal.loader.URLClassPath$JarLoader.getClassPath(Unknown Source)
at java.base/jdk.internal.loader.URLClassPath.getLoader(Unknown Source)
at java.base/jdk.internal.loader.URLClassPath.getResource(Unknown Source)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(Unknown Source)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(Unknown Source)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Unknown Source)
at java.base/sun.launcher.LauncherHelper.loadMainClass(Unknown Source)
at java.base/sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Failed to launch JVM
Are there any more libraries to add? any more JMods? What does "Circular loading of URL streams" have to do with this?
EDIT: MyFX.App
package my.myfx;
public static javafx.scene.image.Image loadingImg,tickImg,appIconImg;
public static javafx.scene.image.ImageView loading,tick,appIcon;
private static javafx.scene.Scene scene;
#Override
public void start(javafx.stage.Stage stage) throws java.io.IOException {
try{
appIcon=new ImageView();
appIconImg=new Image(getClass().getResource("icons/icon.png").toURI().toString());
appIcon.setImage(appIconImg);
loading=new ImageView();
loadingImg=new Image(getClass().getResource("icons/loading.gif").toURI().toString());
loading.setImage(loadingImg);
javafx.concurrent.Task<Exception>work=new javafx.concurrent.Task<>(){
#Override
protected Exception call(){
try{
Thread.sleep(500); //Simulate IO operation
}catch(Exception ex){
return ex;
}
return null;
}
};
new Thread(work).start();
scene = new javafx.scene.Scene(new javafx.fxml.FXMLLoader(getClass().getResource("fxml/main.fxml")).load(), 640, 480);
stage.setScene(scene);
stage.setMaximized(true);
stage.setTitle("MyFX");
stage.getIcons().add(appIconImg);
stage.show();
work.setOnSucceeded(e->{
try{
if(work.get()==null){
System.out.println("Folders initialized");
tick=new ImageView();
tickImg=new Image(getClass().getResource("icons/tick.png").toURI().toString(),true);
tick.setImage(tickImg);
}else{
System.out.println(work.get());
}
}catch(Exception ex){
System.out.println(ex);
}
});
stage.setOnCloseRequest((javafx.stage.WindowEvent t) -> {
Platform.exit();
System.exit(0);
});
}catch(Exception ex){
System.out.println(ex);
}
}
public static void main(String[] args) {
launch();
}
static void setRoot(){
try{
scene.setRoot(new javafx.fxml.FXMLLoader(App.class.getResource("fxml/main.fxml")).load());
}catch(Exception ex){
System.out.println(ex);
}
}
This also contains some functions but they're mostly getters for other classes

java action to access kerberos Hive(SSL enabled)

I have been trying to access Hive(Kerberos and SSL enabled) server from java action.
I need to perform some Hive actions like accessing Hive database and tables, working with hive partitions etc.
public static void main(String[] args) throws Exception, IOException {
Configuration conf=new Configuration();
UserGroupInformation.setConfiguration(conf);
conf.set("hadoop.security.authentication", "kerberos");
conf.set("hadoop.security.authorization", "true");
System.setProperty("java.security.auth.login.config","C:\\krb\\jaas.conf");
System.setProperty("sun.security.jgss.debug","true");
System.setProperty("javax.security.auth.useSubjectCredsOnly","false");
String principalConfig = System.getProperty("kerberosPrincipal", "hive/cdlk-tars-control#ABC.COM");
String keytab = System.getProperty("kerberosKeytab", "C:\\krb\\hive.keytab");
UserGroupInformation.setConfiguration(conf);
UserGroupInformation.loginUserFromKeytab(principalConfig, keytab);
final UserGroupInformation ugi = UserGroupInformation.getLoginUser();
System.out.println("Login as: " + ugi.getUserName());
HiveConf hiveConf=new HiveConf();
hiveConf.setVar(HiveConf.ConfVars.METASTOREURIS, args[0]);
Hive hive = Hive.get(hiveConf);
hive.getConf().setIntVar(HiveConf.ConfVars.METASTORE_CLIENT_SOCKET_TIMEOUT, METASTORE_CLIENT_TIMEOUT);
List<String> database=hive.getAllDatabases();
//database.forEach(x->System.out.println(x));
}
Able to login, but unable to fetch Hive with metastore.
Login as: hive/cdlk-tars-control#ABC.COM
Exception in thread "main" org.apache.hadoop.hive.ql.metadata.HiveException: org.apache.hadoop.hive.ql.metadata.HiveException: org.apache.thrift.transport.TTransportException
at org.apache.hadoop.hive.ql.metadata.Hive.registerAllFunctionsOnce(Hive.java:242)
at org.apache.hadoop.hive.ql.metadata.Hive.<init>(Hive.java:394)
at org.apache.hadoop.hive.ql.metadata.Hive.create(Hive.java:338)
at org.apache.hadoop.hive.ql.metadata.Hive.getInternal(Hive.java:318)
at org.apache.hadoop.hive.ql.metadata.Hive.get(Hive.java:294)
at com.cdlk.util.hive.HiveTest.main(HiveTest.java:36)
Caused by: org.apache.hadoop.hive.ql.metadata.HiveException: org.apache.thrift.transport.TTransportException
at org.apache.hadoop.hive.ql.metadata.Hive.getAllFunctions(Hive.java:4108)
at org.apache.hadoop.hive.ql.metadata.Hive.reloadFunctions(Hive.java:254)
at org.apache.hadoop.hive.ql.metadata.Hive.registerAllFunctionsOnce(Hive.java:237)
... 5 more
Caused by: org.apache.thrift.transport.TTransportException
at org.apache.thrift.transport.TIOStreamTransport.read(TIOStreamTransport.java:132)
at org.apache.thrift.transport.TTransport.readAll(TTransport.java:86)
at org.apache.thrift.protocol.TBinaryProtocol.readAll(TBinaryProtocol.java:429)
at org.apache.thrift.protocol.TBinaryProtocol.readI32(TBinaryProtocol.java:318)
at org.apache.thrift.protocol.TBinaryProtocol.readMessageBegin(TBinaryProtocol.java:219)
at org.apache.thrift.TServiceClient.receiveBase(TServiceClient.java:77)
at org.apache.hadoop.hive.metastore.api.ThriftHiveMetastore$Client.recv_get_all_functions(ThriftHiveMetastore.java:3727)
at org.apache.hadoop.hive.metastore.api.ThriftHiveMetastore$Client.get_all_functions(ThriftHiveMetastore.java:3715)
at org.apache.hadoop.hive.metastore.HiveMetaStoreClient.getAllFunctions(HiveMetaStoreClient.java:2628)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.hadoop.hive.metastore.RetryingMetaStoreClient.invoke(RetryingMetaStoreClient.java:154)
at com.sun.proxy.$Proxy10.getAllFunctions(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.hadoop.hive.metastore.HiveMetaStoreClient$SynchronizedHandler.invoke(HiveMetaStoreClient.java:2562)
at com.sun.proxy.$Proxy10.getAllFunctions(Unknown Source)
at org.apache.hadoop.hive.ql.metadata.Hive.getAllFunctions(Hive.java:4105)
... 7 more
jass configuration
com.sun.security.jgss.initiate {
com.sun.security.auth.module.Krb5LoginModule required
useKeyTab=true
useTicketCache=false
principal="hive/cdlk-tars-control#ABC.COM"
doNotPrompt=true
keyTab="C:\krb\hive.keytab"
debug=false;
};
Please suggest the way to access Hive from java

aws serverless spring boot set up is failing

here is my setup below,
#SpringBootApplication
#ComponentScan(basePackages = "com.amazonaws.serverless.sample.springboot.controller")
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
public class LambdaHandler implements RequestStreamHandler {
private SpringBootLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler;
private static ObjectMapper mapper = new ObjectMapper();
private Logger log = LoggerFactory.getLogger(LambdaHandler.class);
#Override
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context)
throws IOException {
if (handler == null) {
try {
handler = SpringBootLambdaContainerHandler.getAwsProxyHandler(Application.class);
} catch (ContainerInitializationException e) {
e.printStackTrace();
outputStream.close();
return;
}
}
AwsProxyRequest request = mapper.readValue(inputStream, AwsProxyRequest.class);
AwsProxyResponse resp = handler.proxy(request, context);
mapper.writeValue(outputStream, resp);
// just in case it wasn't closed by the mapper
outputStream.close();
}
}
each time when when I am trying invoke my lambda from local console using command - "serverless invoke local -f hello" I am getting below exception,
j
ava.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.serverless.InvokeBridge.invoke(InvokeBridge.java:102)
at com.serverless.InvokeBridge.<init>(InvokeBridge.java:40)
at com.serverless.InvokeBridge.main(InvokeBridge.java:153)
Caused by: java.lang.NoClassDefFoundError: javax/servlet/ServletContainerInitializer
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at com.amazonaws.serverless.proxy.spring.SpringBootLambdaContainerHandler.initialize(SpringBootLambdaContainerHandler.java:167)
at com.amazonaws.serverless.proxy.spring.SpringBootLambdaContainerHandler.getAwsProxyHandler(SpringBootLambdaContainerHandler.java:77)
at com.techprimers.serverless.services.AWSLambdaHandler.handleRequest(AWSLambdaHandler.java:172)
... 7 more
Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletContainerInitializer
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 23 more
at line - "handler = SpringBootLambdaContainerHandler.getAwsProxyHandler(Application.class);"
Please HELP me resolve this, I tried various ways of boot setup with aws lambda but failed every time. Please help me fix this or help me out in setting up in any other way. Thanks.
In your logs we can see :
NoClassDefFoundError: javax/servlet/ServletContainerInitializer
ClassNotFoundException: javax.servlet.ServletContainerInitializer
Could you please check if libs are loaded , there must be something missing and not loaded up correctly
Also, something like this has been done
<dependency>
<groupId>com.amazonaws.serverless</groupId>
<artifactId>aws-serverless-java-container-spring</artifactId>
<version>1.3.2</version>
</dependency>
Also double check steps in :
https://github.com/awslabs/aws-serverless-java-container/wiki/Quick-start---Spring-Boot
I had the same issue. I was using version 0.2 of aws-serverless-java-container-spring and had to switch to version 1.3.2 as the former version didn't have SpringBootLambdaContainerHandler class.

How can i stop the connection from getting closed while reading data from Oracle DB using Spring Batch?

I have a Spring Batch with Spring boot Application in which I am reading data from external Oracle DB and Writing it to SQL Server in production environment. I am validating the connection before reading the data but even then getting Closed Connection issue.Is anyone aware of this issue ? Below is the Datasource config code and error logs.
#Slf4j
#Configuration
public class DataSourceReaderConfig {
private static final Logger LOGGER = LoggerFactory.getLogger(DataSourceReaderConfig.class);
#Autowired
private Environment env;
#SuppressWarnings("deprecation")
#ConfigurationProperties(prefix = "oracle.datasource")
#Bean(name="dataSourceReader")
#Primary
public DataSource dataSourceReader() {
LOGGER.info("Inside dataSourceReader Method");
DataSource datasource = new DataSource();
OracleDataSource ocpds = null;
try {
ocpds = new OracleDataSource();
} catch (SQLException e1) {
LOGGER.error("Error getting Oracle Datasource Connection = " + e1.getMessage());
}
ocpds.setURL(env.getProperty("oracle.datasource.url"));
ocpds.setUser(env.getProperty("oracle.datasource.username"));
ocpds.setPassword(env.getProperty("oracle.datasource.password"));
try {
ocpds.setImplicitCachingEnabled(true);
} catch (SQLException e2) {
LOGGER.error("Error Setting OracleDataSource ImplicitCachingEnabled = " + e2.getMessage());
}
try {
ocpds.setConnectionCachingEnabled(true);
} catch (SQLException e1) {
LOGGER.error("Error Setting OracleDataSource ConnectionCachingEnabled = " + e1.getMessage());
}
Properties cacheProps = new Properties();
cacheProps.setProperty("ValidateConnection","true");
try {
ocpds.setConnectionCacheProperties(cacheProps);
} catch (SQLException e) {
LOGGER.error("Error Setting OracleDataSource Connection Cache Properites = " + e.getMessage());
}
datasource.setDataSource(ocpds);
return datasource;
}
}
[0m[0m09:00:00,000 INFO [com.elm.salamah.scheduler.batch.configuration.CityBatchConfiguration] (pool-3130-thread-1) Job2 importCitiesJob Started at : Thu Dec 07 09:00:00 AST 2017
[0m[31m09:00:00,066 ERROR [org.springframework.scheduling.support.TaskUtils$LoggingErrorHandler] (pool-3130-thread-1) Unexpected error occurred in scheduled task.: org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is java.sql.SQLRecoverableException: Closed Connection
at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:289)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:373)
at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:447)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:277)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy3242.getLastJobExecution(Unknown Source)
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:98)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$PassthruAdvice.invoke(SimpleBatchConfiguration.java:127)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy3241.run(Unknown Source)
at com.elm.salamah.scheduler.batch.configuration.CityBatchConfiguration.performSecondJob(CityBatchConfiguration.java:88)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65)
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.sql.SQLRecoverableException: Closed Connection
at oracle.jdbc.driver.PhysicalConnection.needLine(PhysicalConnection.java:5389)
at oracle.jdbc.driver.OracleStatement.closeOrCache(OracleStatement.java:1578)
at oracle.jdbc.driver.OracleStatement.close(OracleStatement.java:1563)
at oracle.jdbc.driver.OracleStatementWrapper.close(OracleStatementWrapper.java:94)
at oracle.jdbc.driver.PhysicalConnection.setTransactionIsolation(PhysicalConnection.java:4620)
at sun.reflect.GeneratedMethodAccessor276.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tomcat.jdbc.pool.ProxyConnection.invoke(ProxyConnection.java:126)
at org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:108)
at org.apache.tomcat.jdbc.pool.interceptor.AbstractCreateStatementInterceptor.invoke(AbstractCreateStatementInterceptor.java:79)
at org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:108)
at org.apache.tomcat.jdbc.pool.DisposableConnectionFacade.invoke(DisposableConnectionFacade.java:81)
at com.sun.proxy.$Proxy3237.setTransactionIsolation(Unknown Source)
at org.springframework.jdbc.datasource.DataSourceUtils.prepareConnectionForTransaction(DataSourceUtils.java:193)
at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:256)
... 34 more

Https Connection rejected by server

I am trying to write a standalone program that will be called by a bat file. I found something like a trust all certificate manager.
TrustManager[] trustAllCerts = new TrustManager[]{
new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(
java.security.cert.X509Certificate[] certs, String authType) {
}
public void checkServerTrusted(
java.security.cert.X509Certificate[] certs, String authType) {
}
}
};
// Install the all-trusting trust manager
try {
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
URL url = new URL("--insert server url here--");
//url.openStream();
// URLConnection urlConnection = url.openConnection();
HttpsURLConnection urlConnection = (HttpsURLConnection) url.openConnection();
} catch (MalformedURLException mfe) {
mfe.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
it works fine in my ide but after I built in and run it via the bat file it keeps giving me this error
javax.net.ssl.SSLException: Server key
at sun.security.ssl.Handshaker.throwSSLException(Unknown Source)
at sun.security.ssl.ClientHandshaker.processMessage(Unknown Source)
at sun.security.ssl.Handshaker.processLoop(Unknown Source)
at sun.security.ssl.Handshaker.process_record(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source
)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at sun.net.www.protocol.https.HttpsClient.afterConnect(Unknown Source)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect
(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown So
urce)
at java.net.HttpURLConnection.getResponseCode(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(Unk
nown Source)
at sss.Sss.main(Sss.java:65)
Caused by: java.security.NoSuchAlgorithmException: NONEwithRSA Signature not ava
ilable
at java.security.Signature.getInstance(Unknown Source)
at sun.security.ssl.JsseJce.getSignature(Unknown Source)
at sun.security.ssl.RSASignature.<init>(Unknown Source)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Sou
rce)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at java.security.Provider$Service.newInstance(Unknown Source)
at sun.security.jca.GetInstance.getInstance(Unknown Source)
at java.security.Signature.getInstance(Unknown Source)
at sun.security.ssl.JsseJce.getSignature(Unknown Source)
at sun.security.ssl.RSASignature.getInstance(Unknown Source)
at sun.security.ssl.HandshakeMessage$DH_ServerKeyExchange.<init>(Unknown
Source)
... 13 more
am I doing something wrong? Should I sign a certificate in order to connect to the server?
Have found the answer for the problem above, will need to include the sunjce_provider.jar into the lib folder of the standalone program.

Resources