NoClassDefFoundError Being Encountered Intermittently When Using ZoneRulesProvider - noclassdeffounderror

I know that this is somehow similar to this question, but the answer there doesn't seem to help me. But I am also encountering the same issue.. here's a snippet of the logs,
java.lang.NoClassDefFoundError: Could not initialize class
java.time.zone.ZoneRulesProvider
java.time.ZoneRegion.ofId(ZoneRegion.java:120)
java.time.ZoneId.of(ZoneId.java:411)
java.time.ZoneId.of(ZoneId.java:359)
java.time.ZoneId.of(ZoneId.java:315)
java.util.TimeZone.toZoneId(TimeZone.java:556)
java.time.ZoneId.systemDefault(ZoneId.java:274)
And it seems like it's coming from using ZoneId.systemDefault() in my utility method,
public static String formatDate(Date date) {
if(Objects.nonNull(date)) {
LocalDate localDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
return localDate.format(<some_formats_here>);
}
return null;
}
The environment is using,
openjdk version "1.8.0_242"
OpenJDK Runtime Environment (build 1.8.0_242-b08)
OpenJDK 64-Bit Server VM (build 25.242-b08, mixed mode)
Any help would be appreciated!
By the way, this occurs intermittently and happens after deploying the latest codes to the server. I have not encountered it in my local machine's build even though the environment set up are the same with production environment.
Thanks!

Turns out that JVM_HOME must be declared on a system level according to my colleague. This part of code was the one spitting up the problem:
try {
String libDir = System.getProperty("java.home") + File.separator + "lib";
try (DataInputStream dis = new DataInputStream(
new BufferedInputStream(new FileInputStream(
new File(libDir, "tzdb.dat"))))) {
load(dis);
}
} catch (Exception ex) {
throw new ZoneRulesException("Unable to load TZDB time-zone rules", ex);
}
Unfortunately I can't really elaborate on how it was really solved but so far it worked for us. Might help others.

Related

Embedded Jetty Server giving Same response for different urls , without restarting its not working,

I have developed the embedded jetty server to implement the rest service.
I have setup the eclipse project in the eclipse.
I have written the sample program which returns some details through rest url,
I was successfully compiled the program and created a Runnable jar.
I was successfully able to run the Jar files and the server started and running on the port which i gave ,
I have the testing url
http://localhost:1234/getuser/1
it gave me the user details in the response
<username>test1</username>
I ran the same url with different id no
http://localhost:1234/getuser/2
Again it gave me the same result,
`<username>test1</username>`
So i have restarted the server and then it got me the proper details,
<username>test2</username>
public static void main(String[] args) {
// TODO Auto-generated method stub
ServletContextHandler context = new
ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
Server jettyServer = new Server(1234);
jettyServer.setHandler(context);
ServletHolder jerseyServlet = context.addServlet(org.glassfish.jersey.servlet.ServletContainer.class, "/*");
jerseyServlet.setInitOrder(0);
jerseyServlet.setInitParameter("jersey.config.server.provider.classnames", org.test.test.getuser.class.getCanonicalName());
try {
jettyServer.start();
jettyServer.join();
} catch (Exception e) {
e.printStackTrace();
} finally{
jettyServer.destroy();
}
}
Without restarting the jetty web server how to get the proper results.
Is there any thing i need to add in the code to get it worked.
or any settings i need to do for this auto refresh?
I have found the answer, jetty server was able to refresh automatically, there was a object refresh didnt happened in the back end, resolved it from myside and it worked

Java 11: Kerberos using GSS API

I'm upgrading a project to Java 11. I realized that some of the internal packages such as sun.security.krb5.Config & sun.security.krb5.KrbException are no longer "visible" due to modules.
Few examples of how the codebase is consuming these packages are below:
Exception cause = ExceptionUtils.findCause(ne, KrbException.class);
LoginException le = (LoginException) ne.getCause();
if (le.getCause() instanceof KrbException) {
KrbException ke = (KrbException) le.getCause();
try {
sun.security.krb5.Config.refresh();
} catch (KrbException e) {
//log something
}
I read that these internal packages are supposed to be implemented using GSS APIs.
I have been going through the GSS classes and tutorials but couldn't find anything on replacing the internal packages mentioned above.
Take the LoginException as-is. JAAS is supposed to abstract from everything. You just have bad code.

Calling Watson on Bluemix from java causes Trust Manager error

Trying out some code to call a Watson Service I provisioned on Bluemix. I get the following error:
Unable to extract the trust manager on
okhttp3.internal.Platform#e19ef72e, sslSocketFactory is class
com.ibm.jsse2.SSLSocketFactoryImpl
Here is my code:
try {
DocumentConversion service = new DocumentConversion("2016-05-25");
service.setUsernameAndPassword("*****", "*****");
File doc = new File("C:/Sample1.pdf");
Answers htmlToAnswers = service.convertDocumentToAnswer(doc).execute();
System.out.println(htmlToAnswers);
} catch(Exception e) {
System.out.println("Error! -> " + e.getMessage());
}
Thoughts? Do I need to import a cert from Bluemix? Thanks.
Looks like it is a known problem in the okhttp library. Are you using Java SDK to use the IBM Watson version 3.0.0-RC1? If so, try with 2.10.0 as it has an older version of the okhttp library which may not suffer from this problem.

Memory Leak in Grails with MongoDB

I've found a strange issue when saving or updating several objects in Grails with MongoDB. Currently I'm using Grails 2.2.3 and MongoDB plugin 1.3.0.
The problem seems to be that the instances of MiUsuario are never GC neither when I manually call the GC. In our main application we don't make batch updates, but when doing load tests (with JMeter and monitoring JVM with Java VisualVM) this problem causes memory filling and Tomcat stops responding.
I've created a small new application to show the problem.
A simple domain object:
class MiUsuario {
ObjectId id
String nickName
}
My controller:
import pruebasrendimiento.Prueba
class MiUsuarioController {
def doLogin(String privateKey, String id){
MiUsuario user = MiUsuario.get(id)
user.nickName = new Random().nextInt().toString()
user.save(failOnError:true)
render 'ok'
}
}
My BuildConfig (Just the dependencies and plugins part):
dependencies {
}
plugins {
// runtime ":hibernate:$grailsVersion"
runtime ":jquery:1.8.3"
runtime ":resources:1.2"
build ":tomcat:$grailsVersion"
// runtime ":database-migration:1.3.2"
// compile ':cache:1.0.1'
runtime ":mongodb:1.3.0"
}
I've also tried something that Burt said a long time ago (http://burtbeckwith.com/blog/?p=73), but DomainClassGrailsPlugin.PROPERTY_INSTANCE_MAP.get().clear() doesn't make any difference. And the other option that's said in that page, RequestContextHolder.resetRequestAttributes(), gives me an exception.
I had similar problem and it solves upgrading to grails 2.3.1. Try it.

Has anyone successfully deployed a GWT app on Heroku?

Heroku recently began supporting Java apps. Looking through the docs, it seems to resemble the Java Servlet Standard. Does anyone know of an instance where a GWT app has been successfully deployed on Heroku? If so, are there any limitations?
Yes, I've got a successful deployment using the getting started with Java instructions here:
http://devcenter.heroku.com/articles/java
I use the Maven project with appassembler plugin approach but added gwt-maven-plugin to compile a GWT app during the build.
When you push to heroku you see the GWT compile process running, on one thread only so quite slow but it works fine.
The embedded Jetty instance is configured to serve up static resources at /static from src/main/resources/static and I copy the compiled GWT app to this location during the build and then reference the .nocache.js as normal.
What else do you want to know?
You've got a choice, either build the Javascript representation of your GWT app locally into your Maven project, commit it and the read it from your app, or to generate it inside Heroku via the gwt-maven-plugin as I mentioned.
The code to serve up files from a static location inside your jar via embedded Jetty is something like this inside a Guice ServletModule:
(See my other answer below for a simpler and less Guice-driven way to do this.)
protected void configureServlets() {
bind(DefaultServlet.class).in(Singleton.class);
Map<String, String> initParams = new HashMap<String, String>();
initParams.put("pathInfoOnly", "true");
initParams.put("resourceBase", staticResourceBase());
serve("/static/*").with(DefaultServlet.class, initParams);
}
private String staticResourceBase() {
try {
return WebServletModule.class.getResource("/static").toURI().toString();
}
catch (URISyntaxException e) {
e.printStackTrace();
return "couldn't resolve real path to static/";
}
}
There's a few other tricks to getting embedded Jetty working with guice-servlet, let me know if this isn't enough.
My first answer to this turned out to have problems when GWT tried to read its serialization policy. In the end I went for a simpler approach that was less Guice-based. I had to step through the Jetty code to understand why setBaseResource() was the way to go - it's not immediately obvious from the Javadoc.
Here's my server class - the one with the main() method that you point Heroku at via your app-assembler plugin as per the Heroku docs.
public class MyServer {
public static void main(String[] args) throws Exception {
if (args.length > 0) {
new MyServer().start(Integer.valueOf(args[0]));
}
else {
new MyServer().start(Integer.valueOf(System.getenv("PORT")));
}
}
public void start(int port) throws Exception {
Server server = new Server(port);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setBaseResource(createResourceForStatics());
context.setContextPath("/");
context.addEventListener(new AppConfig());
context.addFilter(GuiceFilter.class, "/*", null);
context.addServlet(DefaultServlet.class, "/");
server.setHandler(context);
server.start();
server.join();
}
private Resource createResourceForStatics() throws MalformedURLException, IOException {
String staticDir = getClass().getClassLoader().getResource("static/").toExternalForm();
Resource staticResource = Resource.newResource(staticDir);
return staticResource;
}
}
AppConfig.java is a GuiceServletContextListener.
You then put your static resources under src/main/resources/static/.
In theory, one should be able to run GWT using the embedded versions of Jetty or Tomcat, and bootstrap the server in main as described in the Heroku Java docs.