A Picture From Oracle Coherence Workshop in Istanbul

We had a very nice 3 day Oracle Coherence Workshop in Istanbul last month. Andras Jokuthy from Hungary was next to me during this event. We chatted about Istanbul, Hungary, traffic jams, life in two countries, and about weather and water etc. I hope he liked Istanbul and wish to meet him someday in the future again. May be in Budapest… why not 🙂

First Impression Is Really Important

I have attended a 3 day workshop for Oracle Coherence Product. Altough I am a veteran Eclipse user, we used JDeveloper 11g Technology Preview 3 during our lab sessions. During those lab sessions, I noticed an ugly thing related with JDeveloper. JDeveloper provides some IDE mechanism to generate equals and hashCode methods for your classes. However, it fails to generate hashCode methods correctly when your classes contain primitive fields which need to be included in hashCode generation.

public class Foo {
	private int id;
	public int hashCode() {
		final int PRIME = 37;
		int result = 1;
		return result;
	}
}

Above is the code block I just generated using JDeveloper. Altough I chosed id to include in when generating hashCode, it doesn’t have it. As a result, you have same hashCode value for all your Foo objects. Not good if you are dealing with data structures like Hashtable in your application. In order to generate it correctly, you simply need to convert your primitive type to its Java wrapper equivalent. After this conversion, it looks more appropriate than above;

public int hashCode() {
	final int PRIME = 37;
	int result = 1;
	result = PRIME * result + id == null) ? 0 : id.hashCode(?;
	return result;
}

In summary, I think, it is really important for a new product to handle some fundamental tasks appropriately in order to get acceptance by its users.

Dealing with HTTP Response Redirects within Oracle Web Cache Deployed Environments

I don’t think there exists an application which doesn’t make use of HttpServletResponse’s sendRedirect method. Even your application doesn’t directly depend on it, I am sure you have one or more frameworks which heavily make use of it.

In one of our projects we installed Oracle Web Cache to compress HTTP responses generated by our web application. It is physically deployed in another server than that web application. User requests should contain URL of web cache in order to perform its job, and then it will pass those requests to corresponding web application.

Let’s say our web cache is installed on machine with IP: 10.10.10.1, and our web application (foo) is deployed to OC4J instance running on machine with IP: 10.10.10.2. Therefore, our user requests should be like that: http:/10.10.10.1/foo/swf.faces?_flowId=login-flow, so that HTTP communication will be initiated over web cache and it will compress HTTP response if required. If user requests were contained 10.10.10.2, then web cache would be bypassed totally and no comporession would be performed.

The case is not closed once our users submit to correct URL. Our web application and several of the frameworks it uses make use of HttpServletResponse’s sendRedirect method. The below is an excerpt copied from JEE 5 API;

“Sends a temporary redirect response to the client using the specified redirect location URL. This method can accept relative URLs; the servlet container must convert the relative URL to an absolute URL before sending the response to the client. If the location is relative without a leading ‘/’ the container interprets it as relative to the current request URI. If the location is relative with a leading ‘/’ the container interprets it as relative to the servlet container root.”

As it is stated above, servlet container translates redirect location to an absolute URL. Servlet container unfortunately knows nothing about our web cache configuration, and therefore translated absolute URL contains servlet container’s IP, which is 10.10.10.2 in this case. As a result, even though we initiate communication with correct URL at first, over time web cache will be bypassed at first redirect if redirect URL is relative. We need to provide sendRedirect method with absolute URLs and they should contain IP of web cache so that HTTP communication can flow over web cache. Unfortunately, it is not hundred percent possible to achieve this requirement, because we use several frameworks which make use of sendRedirect method with relative URLs, and it is not possible or logical to modify all those places in which sendRedirect is called.

It would be very nice to have a global place to prepend correct URL, and convert all those relative URLs into absolute before calling sendRedirect. Well, actually this is possible with HttpServletResponseWrapper. If we code a Filter which will intercept current HTTP request before all other parts of our system, and wrap current HttpServletResponse object with a HttpServletResponseWrapper instance and then pass that instance into FilterChain. Inside that wrapper we override sendRedirect method and examine redirect location URL.

 

public void sendRedirect(String location) throws IOException {

if(StringUtils.isNotEmpty(location)) {

if(!(location.startsWith("http") location.startsWith("https"))) {

if(location.startsWith("/")) {

location = location.substring(1);

}

if(location.startsWith(contextPath)) {

location = location.substring(contextPath.length());

}

if(!location.startsWith("/")) {

location = "/" + location;

}

location = appUrl + location;

}

}

if(logger.isDebugEnabled()) {

logger.debug("Redirecting to url :" + location);

}

super.sendRedirect(location);

}

 

We first check if location starts with http/https. If it is, then it means location is absolute and there is nothing to do. Otherwise, we check if location against contextPath and leading slash, and prepend appUrl (with 10.10.10.1 IP in it) appropriately.

ORA-12519 When Using Oracle XE

I recently installed Oracle XE on my laptop and tried to run our project which normally uses Oracle 10g in our company. After creating a db user and enabling it, I created tables, sequences, triggers and stored procedures etc by running db init scripts through ant without any problem. When it came to starting application in application server, I got “ORA-12519, TNS:no appropriate service handler found” messages. Thanks to this and this blog entries to reach at a quick solution. The problem was a bug in how Oracle XE handles monitoring processes, and you need to execute “ALTER SYSTEM SET PROCESSES=150 SCOPE=SPFILE;” statement and then restart your database to get rid of it.

After overcoming this problem, I came up with a Turkish character encoding problem within my Hibernate generated sql statements but I am not hundred percent sure if I installed Oracle XE to deal with non latin characters appropriately. Anyway, it is easy to get rid of such encoding problems by setting user.language and user.country system properties to en and US consecutively.