Posts

Showing posts with the label Java

How to terminate application running in background

At times an application do not stop properly and keep running in background, occupying  port. Step 1: Identify the TCP process id binding to a specific port $>netstat -ano | find "8080" TCP 0.0.0.0:8080 0.0.0.0:0 LISTENING 28268 TCP [::]:8080 [::]:0 LISTENING 28268 Step 2: Kill the process $>taskkill /F /PID 28268

BeanDefinitionStoreException: Failed to parse configuration class: Could not find class [javax.jms.ConnectionFactory]

If you are creating a Spring Boot application and see the following error stack . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.2.0.RELEASE) 2020-06-27 19:30:32.786 INFO 35224 --- [ main] SchoolApplication : Starting SchoolApplication on LTUS76179 with PID 35224 (C:\personal\eclipse-workspace\apievolution\target\classes started by 381548 in C:\personal\eclipse-workspace\apievolution) 2020-06-27 19:30:32.796 INFO 35224 --- [ main] SchoolApplication : No active profile set, falling back to default profiles: default 2020-06-27 19:30:32.964 WARN 35224 --- [ main] ionWarningsApplicationContextInitializer : ** WARNING ** : Your ApplicationContext is unli...

Cloud Enabled Scalability – My Story

Image
Something prompted me to blog again after a long time and not sure if I would be motivated to continue. First, I thought to share a long pending experience, which I had the opportunity to have eight years back. The best weapon we have with the rise of Cloud is on demand scalability (my reference is of 8 years back which everyone knows now). Most of the times when we talk about cloud, we are not talking enabling application for cloud adoption but only talk about cloud infrastructure management (which is sad). I am going to talk about my experience in making an application cloud enable and the use of the design principles. As I am talking an experience gained 8 years back (I am a bit rusty now) I will go through the journey with the case study. Thats How it Started So our story start back in 2011 when hero Mr Dan came up with an idea to monetize the online imagery content of advertisement and make some money (back then it was a cool idea, Google was doin...

A required class was missing while executing org.mortbay.jetty:jetty-maven-plugin

When I was running the command mvn jetty:run I got the message [ERROR] Failed to execute goal org.mortbay.jetty:jetty-maven-plugin:8.1.1.v20120215:run (default-cli) on project CabShareService: Execution default-cli of goal org.mortbay.jetty:jetty-maven-plugin:8.1.1.v20120215:run failed: A required class was missing while executing org.mortbay.jetty:jetty-maven-plugin:8.1.1.v201202 15:run: org/slf4j/impl/StaticLoggerBinder My Jetty settings were org.mortbay.jetty jetty-maven-plugin 8.1.1.v20120215 com.jolbox bonecp 0.7.1.RELEASE /${project.artifactId} src/test/resources/jetty.xml true 10 ${project.artifactId}-stop 9999  The reason of the error was that the slf4j implementation was not defined. Tried setting the Logback as the one of the better implementation ( detailed post  ) . Added the following dependency in the jetty dependencies section. ...

Application logging through SLF4J : Quick Reference

The detailed information on SLF4J is available on http://www.slf4j.org . The primary reason of writing the blog is that there is lot of information but usually people do not have the time to do into the details, hense a quick reference is required to get it going. So I would be trying to put forward all the important aspects. The Simple Logging Facade for Java or (SLF4J) serves as a simple facade or abstraction for various logging frameworks, e.g. java.util.logging, log4j and logback, allowing the end user to plug in the desired logging framework at deployment time. Reason The obvious next question was that this is what JCL (Jakarta Commons Logging: http://commons.apache.org/ ) is all about. Why was the need for another facade? SLF4J does answer to few of drawbacks but there is no specific answer to why JCL was not modified. The drawbacks which are taken care as part of SLF4J are: Parameterized log messages solve an important problem associated with logging performance. Mark...

java.lang.nosuchmethoderror org.objectweb.asm.classwriter

I was working on a RESTFul Service based project. Recently I migrated the plain JDBC DAO layer to the hibernate based orm layer. As a first step I migrated one of the DAO class. When I deployed the complete solution in Tomcat, I faced the following error java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter. (Z)V at net.sf.cglib.core.DebuggingClassWriter. (Debu ggingClassWriter.java:47) at net.sf.cglib.core.DefaultGeneratorStrategy.getClas sWriter(DefaultGeneratorStrategy.java:30) at net.sf.cglib.core.DefaultGeneratorStrategy.generat e(DefaultGeneratorStrategy.java:24) at net.sf.cglib.core.AbstractClassGenerator.create(Ab stractClassGenerator.java:216) at net.sf.cglib.core.KeyFactory$Generator.create(KeyF actory.java:145) at net.sf.cglib.core.KeyFactory.create(KeyFactory.jav a:117) at net.sf.cglib.core.KeyFactory.create(KeyFactory.jav a:108) at net.sf.cglib.core.KeyFactory.create(KeyFactory.jav a:104) at net.sf.cglib.proxy.Enhancer. (Enhancer.java :69) at java.lang.Class.forN...

301 Moved Permanently, URLConnection and HTTPURLConnection

If a website has applied a redirection from " BaseUrl" to " BaseUrl /" then what you see the response by hitting " " in your browser "301 Moved Permanently" and redirected to " /" How to deal this situation when creating a URLConnection and know to what URL you have been redirected to? If you specify URLConnection con = new URL(uri).openConnection(); It would create a connection. Later if you try to get the URL from the "con" object. con.getURL().toString(); This would give you the "BaseUrl " and you would not get the redirected URL. But if you create a HttpURLConnection instead of URLConnection. HttpURLConnection httpURLCon = (HttpURLConnection) new URL(uri).openConnection(); then if you try to get the URL it would give the correct redirected URL "BaseUrl/" If anyone does get contradictory results, please do let me know.

java.lang.AbstractMethodError: org.apache.xerces.dom.DocumentImpl.getXmlStandalone()Z

If you are facing this issue than most probably have a wrong version of XercesImpl.jar file I had a 2.0.2 version, which causing conflict. Replacing it with 2.8.1 resolved the issue.

com.mysql.jdbc.MysqlDataTruncation: Data truncation: Truncated incorrect DOUBLE value:

This error may crop up if you are doing any DML operation through IN clause. Example String sql = 'update table set status = true where id in (?)' If you are using the above statement as part of the prepared statement and the 'id' column is of long type. Following would give this error. String str = "1,2,3,4"; PreparedStatement stmt = connection.prepareStatement(sql); stmt.setString(1, str); stmt.executeUpdate(); The last line would give the error. Reason being that the column is of Long(BIGINT) type and value is passed as string. You cannot say stmt.setLong(1, str); as the 'str' contains comma separated values. One of the solution in this case is to create separate place holders for each input value String sql = 'update table set status = true where id in (?,?,?,?)' in this case and pass individual long values to the statement object. Other options are welcome.

Struts 2 + Hibernate CRUD application

We had a requirement to provide some CRUD based screens to perform administrative task. After doing some searching I found a tool. Our requirement changed so have not used it, but thought of sharing the tool with all those extreme programmers to save their time. http://sourceforge.net/projects/struts2builder/ I builds a base project on for CRUD operations on selected tables. Also provide maven based structure.

Error "Document could not be opened"

When we try to open any of the jasper reports in pdf, csv or rtf format, it results in an error saying that the document can't be opened. However, when we first save the report then it can be opened. This problem only occurs when we connect directly to Websphere 6.1. When there is a HTTP server in between, everything works ok. Analysis: We studied the HTTP header information being transmitted in both the cases; with HTTP Server and without HTTP server. Realized that the issue does occur because in case of no HTTP Server the HTTP had the cache settings as "Cache-Control: no-cache" Following is what we have suggested the customer: If you have 'CookiesConfigureNoCache' property already configured in your server, then please change its value to False, restart the server and try to replicate the problem. Otherwise, please add this property following the steps mentioned below. Steps to configure custom property CookiesConfigureNoCache on WAS 6.1: Login to the Administra...

Custom Exception with same name as JDK Exception

If I create an exception example IOException, will there be an conflict with the existion IOException of JDK? In a discussion the qustion popped up for a quick response and most us had it. But if someone has confusions, here is a quick explanation. Lets  create a custom exception IOException as stated below (IOException.java) package my.test; class IOException extends Exception { IOException() { super("MyIOException Has Raised"); } } Next lets create a test program to see what happens (TestException.java). package my.test; public class TestException { public static void main(String[] args) { try { throw new IOException(); } catch(IOException e) { System.out.println(e.getMessage()); } } } When we run the TestException.java file we get the following message: MyIOException Has Raised Now lets include an import statement to import java.io.IOException class. package my.test; import java.io.IOException; public class TestException { public static void main...