• Enter Slide 1 Title Here

    This is slide 1 description. Go to Edit HTML of your blogger blog. Find these sentences. You can replace these sentences with your own words.

  • Enter Slide 2 Title Here

    This is slide 2 description. Go to Edit HTML of your blogger blog. Find these sentences. You can replace these sentences with your own words.

  • Enter Slide 3 Title Here

    This is slide 3 description. Go to Edit HTML of your blogger blog. Find these sentences. You can replace these sentences with your own words.

Wednesday, October 27, 2010

[Tomcat] How to change default JSESSIONID cookie/parameter identifier

Changing default JSESSIONID name of cookie and/or parameter is the objective. Deployed J2EE web applications use browser cookie or parameter based session management technique. By default session cookie name is defined as “JSESSIONID” and session id parameter as “jsessionid” in Apache Tomcat servers. These names can be renamed by specifying required values for correct system properties.

Requirements

This system properties based feature is only available in releases newer than Tomcat 5.5.28 and Tomcat 6.0.20.

System properties

Related system properties are;
  • org.apache.catalina.SESSION_COOKIE_NAME (for cookie name)
  • org.apache.catalina.SESSION_PARAMETER_NAME (for parameter name)

Passing system properties

System property can be passed using standard methodology; use “-D” parameter of Java command similar to following.
java -D<key>=<value>

Modify catalina.sh to pass system properties

Following extract is from a modified bin/catalina.sh to pass these system properties; similarly bin/catalina.bat can be modified for Windows based installations.

#!/bin/sh
# // .....
# ------------------------------------------
# Start/Stop Script for the CATALINA Server
# // .....
# ------------------------------------------
JAVA_OPTS="$JAVA_OPTS
-Dorg.apache.catalina.SESSION_COOKIE_NAME=MYJSESSIONID
-Dorg.apache.catalina.SESSION_PARAMETER_NAME=myjsessionid"
# // .....
Note:
The decision on whether cookie based or parameter based session management is used depend on client browser settings.

Related Articles

Wednesday, October 20, 2010

Thunderbird 3.1.5 Release with Critical security fixes

Mozilla Thunderbird 3.1.5 version released today. This free and open source email client is one of the better standalone ones available. Since development is done by a community of developers with the help of security experts; issue identification and resolution process is so efficient. Thunderbird 3.1.5 can be downloaded from here for any platform (Windows, Mac OS and Linux) in around fifty languages.

This release has fixes for five critical security vulnerabilities as shown below.
  • Unsafe library loading Vulnerabilities
  • Dangling pointer vulnerability in LookupGetterOrSetter
  • Use-after-free error in nsBarProp
  • Buffer overflow and memory corruption using document.write
  • Miscellaneous memory safety hazards (rv:1.9.2.11/ 1.9.1.14)

An upgrade to latest 3.1.5 version is advised to avoid any security issues. All credit goes to those great people who devote their time and effort on getting another release out.

[Linux] Find filenames list by content search and file format

Generally computer users can memorize the locations of different files that they read or store. As the number of files increases, they can use descriptive filenames making it easy to guess the content by looking at the file name. However when the number of files grows higher & higher in number, it becomes a pain to remember locations or filenames. Also when a computer is used by some other person than the owner, it becomes even harder to locate some files.

Search by partial name

find -name "<filename pattern>"

Above command is useful only if you can remember the filenames at least some parts of the file name. If you are a software developer, you know how many times you would want to search files based on the content.

Search by content

find <path> -name "<file name pattern>" -exec grep -l "<text to search>" {} \;

Above command can be used to find the files based on content search. For example to find a file with a value say "db.user" in a properties file inside "/opt/work/project" folder (including sub folders) following command can be used.

find /opt/work/project -name "*.properties" -exec grep -l "db.user" {} \;

IgnoreCase search can be done by adding "-i" attribute to grep command; check following command.

find /opt/work/project -name "*.properties" -exec grep -il "db.user" {} \;

When would content search be used?

  • You remember some parts of the content but not the file name
  • Find which property file contains an specific property used in your program
  • Locate the Style sheet (css file) containing a specific style class or property
  • Find Java class files that references some methods like "indexOf"
  • and so on...

Tuesday, October 19, 2010

[Java] The enum constant reference cannot be qualified in a case label of switch statement

The enum constant reference cannot be qualified in a case label is an error message you may encounter while using Java enum values against a switch statement. I assume you are aware Java allows enums to be used in switch statements other than convertible int values.

In Short

When a Java switch statement uses an enum parameter; qualified names of the enum values should not be used in case labels, but only the unqualified names; then switch statement will consider all the labels are referring to the enum type that is used as the parameter.

Why only unqualified values?

If qualified references were allowed for case labels; there would be no means to restrict the enum type used in the labels to be same as the parameter type of switch statement.

In Detail

An enum named “Status” which represent two statuses of an entity will be used in sample code.

package org.kamal.learnenum.user;

public enum Status {
REGISTERED,
TERMINATED
}

Following sample code uses “Status” enum to create a a greeting message (based on a complex logic). Look at the way the case label is written in switch statement; consider the differences in lines marked as 1 & 2.

package org.kamal.learnenum.test;

import org.kamal.learnenum.user.Status;

public class TestStatus {
public static String getMessage(Status status) {
String message;
switch (status) {
// case Status.REGISTERED: // line 1
case REGISTERED: // line 2
message = "Welcome";
break;
default:
message = "Good bye";
break;
}
return message;
}

public static void main(String[] args) {
String name = "John";
System.out.println(getMessage(Status.REGISTERED) + " " + name);
System.out.println(getMessage(Status.TERMINATED) + " " + name);
}
}

Status & TestStatus classes are in two different packaged; so to refer to a Status enum value inside TestStatus class we must use qualified name like follows.

Status status = Status.REGISTERED;

However when it comes to case labels of switch statements; enum should not be referred using qualified name. What? Are you sure? Yes; that is the truth. Only unqualified enum value must be used for case labels. The compiler will simply look at the type of the enum parameter to the switch() statement and refer to that enum class to locate the enum values.