Thursday, October 29, 2009

Using WSSE with in a Java webservice client

Some webservice requires the client to add WS-Security to the SOAP header for authentication purposes.

E.g.


w900049abc123yg3mGu1yG4MvYG5L6PZIJw==2009-10-26T16:23:36.390Z
12


AA
BB
crmppoc
VLB
A
2008-10-24T11:47:39.105Z


12



33
CDG
2009-11-27T23:00:00
2009-10-12T23:00:00
BOS





Here's one way of doing it by using a message handler:

Using a Message Handler to alter the SOAP Header in a Web Service Client

Tuesday, August 25, 2009

How to run your Java App using Java Web Start

Java Web Start is a cool way to deploy java applications as there's no need to install the application on users deskstops. All that is needed is a URL that points to a special launch file (JNLP file), it causes the browser to launch Java Web Start, which then automatically downloads, caches, and runs the given Java Technology-based application. The entire process is typically completed without requiring any user interaction, except for the initial single click.

For more details, read this.

1. Export application as a Runnable JAR file e.g. MAMessageEditor.jar





2. Sign the jar. You can view the details here.

Note: If you did not sign the jar, you will get a ecurity error - access denied (java.io.FilePermission)

a. Make sure that you have an SDK 1.4.2 keytool and jarsigner in your path.

b.Create a new key in a new keystore as follows:

keytool -genkey -keystore myKeystore -alias myself

You will get prompted for a information about the new key, such as password, name, etc. This will create the myKeystore file on disk.

c. Then create a self-signed test certificate as follows:

keytool -selfcert -alias myself -keystore myKeystore

This will prompt for the password. Generating the certificate may take a few minutes.

d. Check to make sure that everything is okay. To list the contents of the keystore, use this command:

keytool -list -keystore myKeystore





e. Finally, sign the JAR file with the test certificate as follows:

jarsigner -keystore myKeystore test.jar myself

f. Upload the jar file to the server.


3. Create a JNLP file (see example below). For more details, refer to this link : Deploying Java Web Start Applications

E.g.



codebase="http://invicta.app.vic:8888/abc123/"
href="MAMessageEditor.jnlp">

title Ma Message Editor /title
Masrudyn
Ma Message Editor

Edits MA Message Files








href="http://java.sun.com/products/autodl/j2se"/>




4. Create a HTML page to link to the JNLP file.
E.g.
Launch MA Message Editor

5. Ensure that the destop users has JRE installed.

6. Pass the URL to the users to run the application.

Thursday, August 6, 2009

Configuring Glassfish v2.1 to rotate logs

If you do not configure this, your logs files will grow unbounded:


There's a FAQ to do this:
How do I configure GlassFish to delete rotated log files?

Step 1: Login to Admin Console and navigate to Configuration -> System Properties


Step 2: Add in a new property com.sun.enterprise.server.logging.max_history_files


Step 3: Save and restart Glassfish


If the above does not work, set it via the java options:

Wednesday, July 29, 2009

Java and Spreadsheets

As part of my work, I deal with alot of Excel Spreadsheets and CSV (Comma delimited files).

Having a Java tool/program that can work with spreadsheets and csv would be extremely useful. I'm going to be dedicating this post to everything about this topic.

For starters, here are some freeware api/libraries that allows you to manipulate spreadsheets:
Java Excel API - A Java API to read, write, and modify Excel spreadsheets
Less Excel, More Components

GUI Spreadsheets:
Spreadsheet.java
Using JavaFX

JTable:
Sample Demo
Complex JTable Sample
Displaying a CSV File in a JTable
How to Use Tables

CSVs:
OpenCSV
Excel Comma Separated Values (CSV) - com.Ostermiller.util Java Utilities
Mindprod

Tuesday, July 21, 2009

Confused about inner and outer classes?

Well here's a very good article, which cleared alot of my doubt especially when using my DAO methods which uses anonymous inner classes:

Nested Classes
Examples based