spring boot

Spring Data error: getOutputStream() has already been called for this response

Spring data with spring boot error when using mapping

Spring boot has made life of the java developers a bliss. Thanks a million for the dedicated guys in spring.

Saying that, if you are working typical database related project with spring boot, you might have some error like this


java.lang.IllegalStateException: getOutputStream() has already been called for this response
at org.apache.catalina.connector.Response.getWriter(Response.java:624) ~[tomcat-embed-core-8.5.16.jar!/:8.5.16]
at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:211) ~[tomcat-embed-core-8.5.16.jar!/:8.5.16]
Continue reading Spring Data error: getOutputStream() has already been called for this response

setting JAVA_HOME on mac osx

How to set JAVA_HOME ON MAC OSX computer

Setting java_home as environment variable might be almost required especially when you use frameworks. Frameworks like axis2 web server and others. Also some code editors require that too.

What is environment variable

Those are variables that would allow you to execute command line actions from any directory, basically from everywhere.

The simplest example is using java -version. In this case, if you don’t have explicit environment variable on where to look for, it requires you to either be in the java folder or to fully list the whole path till bin folder.

Setting JAVA_HOME in mac osx

The first part is to make sure you have java installed in your machine.

java -version

If this is giving you an output with the version, then it means java is installed, otherwise, you should first install it.

The following task will be to find out where the binary files are located.

Click the apple icon on the left top corner of your mac and select system preferences..

system preference

system preference

And from there click Java and you will get the path information from there.

Once you got where the java is located, usually on /Library/Java/JavaVirtualMachines/jdk1.***/Contents/Home

Open the bash properties file


vi ~/.bash_profile

And add the java path here

export JAVA_HOME=export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home

The above would be what it would look like fro jkd 1.8 on my El Capitan macbook pro.

hello world weblogic – hello world tutorial on weblogic

hello world weblogic app server

There are lots of application servers for java and oracle weblogic is one of them. As of this writing the current and latest weblogic server is 12c

I will show a simple hello world tutorial on weblogic. The tutorial is for beginners of weblogic server.

This hello world weblogic tutorial assumes you have java skill already.

Installing weblogic server

First thing first, lets install and configure weblogic server
Continue reading hello world weblogic – hello world tutorial on weblogic

Simple Servlet example without eclipse

Simple servlet example – how to create servlet without eclipse

These days we are all surrounded by heavy frameworks that make life easier for us. Like maven, spring and hibernate and more. But how can we create a simple servlet website without the need of all those.

The main idea of servlet lies around very simple and intuitive files and structures. Knowing those only is good enough to built a good web app and that is what I will be showing here.

The main parts of the java web app are the following.

1. The Servlet – the java class that is handling the POST and GET http verbs
2. the deployment descriptor – web.xml. File telling how the webapp should be interacted like the url pattern
3. Servlet jar file – This is the jar handling the magic of interaction with the web for the servlet.

Structure of the webapp

Consuming SOAP tutorial – Using java eclipse

Consuming SOAP tutorial from java step by step

SOAP, Simple Object Access Protocol, is older and still usable protocol for exchanging messages between systems.

Since soap is xml based, it is language and operating system independent. You can publish a soap service through your wsdl using Java on Linux and you can consume it through PHP application running on windows.

These days, SOAP is a bit lagging behind RESTful services which are rather more of architectural approaches than being protocol by themselves.

This is a tutorial showing how to consume an existing SOAP service using java language.

For this example, I will use a WSDL published on http://www.webservicex.com/globalweather.asmx?WSDL

In this one, I use already established wsdl for weather related tasks.

Eclipse has a nice tool to make life easier to consume SOAP related messages and I will show you here step by step.

Consuming SOAP tutorial step by step

1. Go ahead and create a new dynamic java project on your Eclipse

dynamic java project

java project

dynamic web project

dynamic web project


Continue reading Consuming SOAP tutorial – Using java eclipse

Passing composite object parameter to jersey in Restful Java web

How to pass complex object parameter to jersey

In this tutorial, I will try to show how to pass composite object as a parameter to jersey’s endpoint java application.

It seems like you are working on RESTful API based java application. In that case, chances are high that you are working with jersey.

If you are not familiar with jersey, jersey is an implementation of JAX-RS APIs. Hence, it is a seamless framework by which API based java projects can be implemented.

As of this writing, the current version of jersey is 2.23.
Continue reading Passing composite object parameter to jersey in Restful Java web

J2EE Maven Eclipse Hello World Tutorial Part Two

Hello World Beginner Tutorial using J2EE and Maven

This is part two of J2EE application with maven continued from Part One.

If you haven’t accomplished J2EE with Maven tutorial, please first complete it by going here

Maven relies highly on the pom.xml file that we would put on the project root folder. Lets do that.

In this part of J2EE tutorial and Maven tutorial, we will proceed from creating a pom.xml file which is the heart of maven.

3 Create the pom and compile the project using maven.

3.a put the following pom file in the MavenEclipseJ2EE directory.
Continue reading J2EE Maven Eclipse Hello World Tutorial Part Two

Java solution for checking anagram strings – tell if phrases are anagrams

Anagram Algorithm in Java solving if two strings are anagrams or not

This is the java solution for checking if the given two strings are anagrams or not. For the examples of anagrams and the approach I used and analysis of the code, see analysis of anagram algorithm

Find missing numbers from billion number lists with limited memory

Anagram algorithm in Java solution


package algorithm;

import java.util.Arrays;

/**
 * Determine if the given two strings are anagrams or not 
 * A solution in java programming language
 * @author https://gullele.com
 * 
 * Analysis - this would run in o(nlogn) for the sorting part and all other others would be in o(n)
 * Hence it is o(nlogn) + o(n) ==> o(nlogn) assuming worst case sorting.
 */
public class Anagram implements AnagramFinder {

	public static void main(String string[]) {
		String string1 = "Debit Card ";
		String string2 = "bad credit";
		
		AnagramFinder anagramFinder = new Anagram();
		if (anagramFinder.areAnagrams(string1, string2)) {
			System.out.println("Anagrams");
		} else {
			System.out.println("Not Anagrams");
		}
	}
	
	public Anagram() {
		
	}
	
	@Override
	/**
	 * Verify if the given words are anagrams or not
	 */
	public boolean areAnagrams(String s1, String s2) {
		if (s1 == null || s2 == null) { //I don't think we would assume null is anagram at all..
			return false;
		}
		
		//get rid of the spaces 
		s1 = s1.replaceAll("\\s+", "").toLowerCase();
		s2 = s2.replaceAll("\\s+", "").toLowerCase();
		
		//no need to proceed if the length is not the same. assumed the anagrams are the same in length
		if (s1.length() != s2.length()) {
			return false;
		}
		
		//then order the string in characters
		char[] ordereds1 = sortChars(createCharArray(s1)); //o(nlogn)
 	 	char[] ordereds2 = sortChars(createCharArray(s2)); //o(nlogn)
		
 	 	//first thing first, if the size is not the same, then we are done
 	 	int index = 0;
 	 	while (index < ordereds1.length) { //this would run o(n)
 	 		if (ordereds1[index] != ordereds2[index]) {
 	 			return false;
 	 		}
 	 		index++;
 	 	}
 	 	
		return true;
	}
	
	/**
	 * Takes the string and converts it to characters
	 * @param string
	 * @return
	 */
	private char[] createCharArray(String string) {
		return new char[string.length()];
	}
	
	/**
	 * if I have to implement it I can use quick sort and make it at least n(logn)
	 * @param chars
	 * @return array
	 */
	private char[] sortChars(char[] chars) {
		Arrays.sort(chars);
		return chars;
	}
}

The above anagram algorithm solution is in java but it can be performed in any programming language.

No Persistence provider for EntityManager named Hibernate error

No Persistence provider for EntityManager named

If you are working on hibernate, then there are two ways to provide the configuration to it. Either you would be using hibernate.cfg.xml or persistence.xml

In both cases, hibernate would be using the information like the connection string information and classes associated with tables.

If you are using persistence.xml and you are getting No Persistence provider for EntityManager named error, then there the following would be an issue and here is how you solve those.
Continue reading No Persistence provider for EntityManager named Hibernate error