Thursday, November 26, 2009

Why not 2GB of Heap Memory on Windows

Here's a good article why you can't allocated 2GB of heap memory on windows:

Read it here

Wednesday, November 25, 2009

Changing Heap Memory Size in Websphere

Here's how you change the heap memory size in Websphere:

1. Click on Application Server on the LHS:


2. Expand Java and Process Management


3. Click on Process Management


4. Enter the values in Initial Heap Size and Maximum Heap Size


5. Click Apply, save configuration and then restart the app server.

Change Heap Memory Size in Websphere without Admin Console

I've been playing around with Websphere6.1 of late so I thought I should document some of the tasks I've done.

One of problem with Websphere is that if you run out of heap memory, you can't start the appserver including the admin console. You will need to change it manually. Here's how it is done:

1. Go to the profile configuration dir for that node e.g. D:\IBM\WebSphere\AppServer\profiles\AppSrv01\config\cells\matrixNode01Cell\nodes\matrixNode01\servers\server1

If you can't find it, do a search:



2. Edit the file server.xml and change the setting:



3. Restart the appserver via Windows Services (you can also use the command "startServer server1" in D:\IBM\WebSphere\AppServer\bin)

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

Thursday, July 16, 2009

Is it FINAL?

Here's a very good article that summarizes why/how/when the final keyword should be used :

The Final Word On the final Keyword

Sunday, June 21, 2009

Getting started on EJBs

I wanted to schedule some monitoring jobs in my J2EE container and intend to use EJB Timer to do it. I'm researching on good links on how to use Eclipse for EJBs.

Here are some:

EJB Fundamentals:
An Introduction to Enterprise JavaBeans
Building your first EJB

EJB on Glassfish
EJB FAQ
EJB 3 Development for Glassfish using Eclipse 3.2 Tutorial

Building EJBs in Eclipse:
WTP Tutorials - Building a Simple EJB Application
Java EJB 3 tutorial using Eclipse, Ant and JBoss Tutorial

Using EJB Timer:
Using Timers in J2EE Applications
EJB 3 Timer Service

Wednesday, June 10, 2009

Problematic JDK versions on AIX

Note: Glassfish 2.1 does not support JDK6 on AIX. 2.1.1 will support JDK6.

Version that works (JDK5):
32 bit:
java full version "J2RE 1.5.0 IBM AIX build pap32devifx-20090327 (SR9-SSU )"
64 bit:
java full version "J2RE 1.5.0 IBM AIX build pap64devifx-20090327 (SR9-SSU )"


JDK5 64-Bit
./java -fullversion
java full version "J2RE 1.5.0 IBM AIX build pap64devifx-20060124"

- Does not allow most of the -X flags in Glassfish
- If comment out -X, calls NullExcetion in thread
- Very slow

JDK6 64-Bit
./java -fullversion
java full version "JRE 1.6.0 IBM AIX build pap6460sr4-20090219_01 (SR4)"
JDK6 32-Bit
./java -fullversion
java full version "JRE 1.6.0 IBM AIX build pap3260sr4ifx-20090417_02 (SR4)"

- Throws the following error, thereafter will hang when using connection pool (see this):
recursive call into SystemOutandErrhandler
java.lang.RuntimeException: recursivecall
at com.sun.enterprise.server.logging.SystemOutandErrHandler$LoggingByteArrayOutputStream.flush(SystemOutandErrHandler.java:359)
at java.io.PrintStream.write(PrintStream.java:445)
at com.sun.enterprise.server.logging.SystemOutandErrHandler$LoggingPrintStream.write(SystemOutandErrHandler.java:293)
at sun.nio.cs.StreamEncoder$CharsetSE.writeBytes(StreamEncoder.java:355)
at sun.nio.cs.StreamEncoder$CharsetSE.implWrite(StreamEncoder.java:416)
at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:159)
at java.io.OutputStreamWriter.emptyBuffer(OutputStreamWriter.java:290)
at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:273)
at java.util.logging.StreamHandler.flush(StreamHandler.java:271)
at java.util.logging.ConsoleHandler.publish(ConsoleHandler.java:73)
at java.util.logging.Logger.log(Logger.java:1097)
at java.util.logging.Logger.log(Logger.java:994)
at com.sun.enterprise.server.logging.SystemOutandErrHandler$LoggingByteArrayOutputStream.flush(SystemOutandErrHandler.java:368)
at java.io.PrintStream.write(PrintStream.java:445)
at com.sun.enterprise.server.logging.SystemOutandErrHandler$LoggingPrintStream.write(SystemOutandErrHandler.java:293)
at sun.nio.cs.StreamEncoder$CharsetSE.writeBytes(StreamEncoder.java:355)
at sun.nio.cs.StreamEncoder$CharsetSE.implFlushBuffer(StreamEncoder.java:425)
at sun.nio.cs.StreamEncoder$CharsetSE.implFlush(StreamEncoder.java:429)
at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:175)
at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:274)
at java.util.logging.StreamHandler.flush(StreamHandler.java:271)
at java.util.logging.ConsoleHandler.publish(ConsoleHandler.java:73)
at java.util.logging.Logger.log(Logger.java:1097)
at java.util.logging.Logger.log(Logger.java:1035)
at com.sun.enterprise.server.ApplicationServer.printStartupInfo(ApplicationServer.java:618)
at com.sun.enterprise.server.ApplicationServer.onInitialization(ApplicationServer.java:170)
at com.sun.enterprise.server.ondemand.OnDemandServer.onInitialization(OnDemandServer.java:103)
at com.sun.enterprise.server.PEMain.run(PEMain.java:399)
at com.sun.enterprise.server.PEMain.main(PEMain.java:336)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:599)
at com.sun.enterprise.server.PELaunch.main(PELaunch.java:415)

Getting Java stack trace from Glassfish

If you run into problems with Glassfish (e.g. Glassfish hangs) and need to get a stack trace of the java process, here's how you do it without using jstack:

1. Start glassfish using asadmin

mclaren> asadmin stop-domain
Domain domain1 stopped.
mclaren> asadmin
Use "exit" to exit and "help" for online help.
asadmin> start-domain
Starting Domain domain1, please wait.
Default Log location is /home/affinium7/mas/tmp/glassfish/domains/domain1/logs/server.log.
Redirecting output to /home/affinium7/mas/tmp/glassfish/domains/domain1/logs/server.log
Domain domain1 is ready to receive client requests. Additional services are being started in background.
Domain [domain1] is running [Sun GlassFish Enterprise Server v2.1 (9.1.1) (build b60e-fcs)] with its configuration and logs at: [/home/affinium7/mas/tmp/glassfish/domains].
Admin Console is available at [http://localhost:4848].
Use the same port [4848] for "asadmin" commands.
User web applications are available at these URLs:
[http://localhost:8888 https://localhost:8181 ].
Following web-contexts are available:
[/web1 /__wstx-services ].
Standard JMX Clients (like JConsole) can connect to JMXServiceURL:
[service:jmx:rmi:///jndi/rmi://mclaren:8686/jmxrmi] for domain management purposes.
Domain listens on at least following ports for connections:
[8888 8181 4848 3700 3820 3920 8686 ].
Domain does not support application server clusters and other standalone instances.



2. Remain in asadmin (do not exit)

3. Open another terminal window and get the process id of the running domain
(normally this is the process running com.sun.enterprise.cli.framework.CLIMain)


mclaren> ps -ef| grep glass
affiniu7 479618 565548 120 09:44:38 pts/8 27:47 /usr/java5_64/jre/../bin/java -Dcom.sun.aas.instanceRoot=/home/affinium7/mas/tmp/glassfish/domains/domain1 -Dcom.sun.aas.ClassPathPrefix= -Dcom.sun.aas.ClassPathSuffix= -Dcom.sun.aas.ServerClassPath= -Dcom.sun.aas.classloader.appserverChainJars.ee= -Dcom.sun.aas.classloader.appserverChainJars=admin-cli.jar,admin-cli-ee.jar,j2ee-svc.jar -Dcom.sun.aas.classloader.excludesList=admin-cli.jar,appserv-upgrade.jar,sun-appserv-ant.jar -Dcom.sun.aas.classloader.optionalOverrideableChain.ee= -Dcom.sun.aas.classloader.optionalOverrideableChain=webservices-rt.jar,webservices-tools.jar -Dcom.sun.aas.classloader.serverClassPath.ee=/lib/hadbjdbc4.jar,/home/affinium7/mas/tmp/glassfish/lib/SUNWjdmk/5.1/lib/jdmkrt.jar,/lib/dbstate.jar,/lib/hadbm.jar,/lib/hadbmgt.jar,/lib/mfwk_instrum_tk.jar -Dcom.sun.aas.classloader.serverClassPath=/home/affinium7/mas/tmp/glassfish/lib/install/applications/jmsra/imqjmsra.jar,/home/affinium7/mas/tmp/glassfish/imq/lib/jaxm-api.jar,/home/affinium7/mas/tmp/glassfish/imq/lib/fscontext.jar,/home/affinium7/mas/tmp/glassfish/imq/lib/imqbroker.jar,/home/affinium7/mas/tmp/glassfish/imq/lib/imqjmx.jar,/home/affinium7/mas/tmp/glassfish/lib/ant/lib/ant.jar,/home/affinium7/mas/tmp/glassfish/lib/SUNWjdmk/5.1/lib/jdmkrt.jar -Dcom.sun.aas.classloader.sharedChainJars.ee=appserv-se.jar,appserv-ee.jar,jesmf-plugin.jar,/lib/dbstate.jar,/lib/hadbjdbc4.jar,jgroups-all.jar,/lib/mfwk_instrum_tk.jar -Dcom.sun.aas.classloader.sharedChainJars=javaee.jar,/usr/java5_64/jre/../lib/tools.jar,install/applications/jmsra/imqjmsra.jar,com-sun-commons-launcher.jar,com-sun-commons-logging.jar,/home/affinium7/mas/tmp/glassfish/imq/lib/jaxm-api.jar,/home/affinium7/mas/tmp/glassfish/imq/lib/fscontext.jar,/home/affinium7/mas/tmp/glassfish/imq/lib/imqbroker.jar,/home/affinium7/mas/tmp/glassfish/imq/lib/imqjmx.jar,/home/affinium7/mas/tmp/glassfish/imq/lib/imqxm.jar,webservices-rt.jar,webservices-tools.jar,mail.jar,appserv-jstl.jar,jmxremote_optional.jar,/home/affinium7/mas/tmp/glassfish/lib/SUNWjdmk/5.1/lib/jdmkrt.jar,activation.jar,appserv-rt.jar,appserv-admin.jar,appserv-cmp.jar,/home/affinium7/mas/tmp/glassfish/updatecenter/lib/updatecenter.jar,/home/affinium7/mas/tmp/glassfish/jbi/lib/jbi.jar,/home/affinium7/mas/tmp/glassfish/imq/lib/imqjmx.jar,/home/affinium7/mas/tmp/glassfish/lib/ant/lib/ant.jar,dbschema.jar -Dcom.sun.aas.configName=server-config -Dcom.sun.aas.configRoot=/home/affinium7/mas/tmp/glassfish/config -Dcom.sun.aas.defaultLogFile=/home/affinium7/mas/tmp/glassfish/domains/domain1/logs/server.log -Dcom.sun.aas.domainName=domain1 -Dcom.sun.aas.installRoot=/home/affinium7/mas/tmp/glassfish -Dcom.sun.aas.instanceName=server -Dcom.sun.aas.processLauncher=SE -Dcom.sun.aas.promptForIdentity=true -Dcom.sun.enterprise.config.config_environment_factory_class=com.sun.enterprise.config.serverbeans.AppserverConfigEnvironmentFactory -Dcom.sun.enterprise.overrideablejavaxpackages=javax.help,javax.portlet -Dcom.sun.enterprise.taglibs=appserv-jstl.jar,jsf-impl.jar -Dcom.sun.enterprise.taglisteners=jsf-impl.jar -Dcom.sun.updatecenter.home=/home/affinium7/mas/tmp/glassfish/updatecenter -Ddomain.name=domain1 -Djava.endorsed.dirs=/home/affinium7/mas/tmp/glassfish/lib/endorsed -Djava.ext.dirs=/usr/java5_64/jre/../lib/ext:/usr/java5_64/jre/../jre/lib/ext:/home/affinium7/mas/tmp/glassfish/domains/domain1/lib/ext:/home/affinium7/mas/tmp/glassfish/javadb/lib -Djava.library.path=/home/affinium7/mas/tmp/glassfish/lib:/home/affinium7/mas/tmp/glassfish/lib:/home/affinium7/mas/tmp/glassfish/lib -Djava.security.auth.login.config=/home/affinium7/mas/tmp/glassfish/domains/domain1/config/login.conf -Djava.security.policy=/home/affinium7/mas/tmp/glassfish/domains/domain1/config/server.policy -Djava.util.logging.manager=com.sun.enterprise.server.logging.ServerLogManager -Djavax.management.builder.initial=com.sun.enterprise.admin.server.core.jmx.AppServerMBeanServerBuilder -Djavax.net.ssl.keyStore=/home/affinium7/mas/tmp/glassfish/domains/domain1/config/keystore.jks -Djavax.net.ssl.trustStore=/home/affinium7/mas/tmp/glassfish/domains/domain1/config/cacerts.jks -Djdbc.drivers=org.apache.derby.jdbc.ClientDriver -Djmx.invoke.getters=true -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Xmx512m -cp /home/affinium7/mas/tmp/glassfish/lib/jhall.jar:/home/affinium7/mas/tmp/glassfish/lib/appserv-launch.jar:/home/affinium7/mas/tmp/glassfish/domains/domain1/lib/log4j com.sun.enterprise.server.PELaunch start
affiniu7 508166 610564 0 10:11:12 pts/6 0:00 grep glass
affiniu7 565548 729806 0 09:44:27 pts/8 0:15 /usr/java5_64/jre/../bin/java -Dcom.sun.aas.instanceName=server -Djava.library.path=/home/affinium7/mas/tmp/glassfish/lib:/home/affinium7/mas/tmp/glassfish/lib:/home/affinium7/mas/tmp/glassfish/lib -Dcom.sun.aas.configRoot=/home/affinium7/mas/tmp/glassfish/config -Djava.endorsed.dirs=/home/affinium7/mas/tmp/glassfish/lib/endorsed -Dcom.sun.aas.processLauncher=SE -cp /home/affinium7/mas/tmp/glassfish/javadb/lib/derby.jar:/home/affinium7/mas/tmp/glassfish/jbi/lib/jbi-admin-cli.jar:/home/affinium7/mas/tmp/glassfish/jbi/lib/jbi-admin-common.jar:/home/affinium7/mas/tmp/glassfish/lib:/home/affinium7/mas/tmp/glassfish/lib/comms-appserv-rt.jar:/home/affinium7/mas/tmp/glassfish/lib/appserv-rt.jar:/home/affinium7/mas/tmp/glassfish/lib/appserv-ext.jar:/home/affinium7/mas/tmp/glassfish/lib/javaee.jar:/home/affinium7/mas/tmp/glassfish/lib/appserv-se.jar:/home/affinium7/mas/tmp/glassfish/lib/comms-appserv-admin-cli.jar:/home/affinium7/mas/tmp/glassfish/lib/admin-cli.jar:/home/affinium7/mas/tmp/glassfish/lib/appserv-admin.jar:/home/affinium7/mas/tmp/glassfish/lib/commons-launcher.jar:/home/affinium7/mas/tmp/glassfish/lib/install/applications/jmsra/imqjmsra.jar -Dcom.sun.appserv.admin.pluggable.features=com.sun.enterprise.ee.admin.pluggable.EEClientPluggableFeatureImpl com.sun.enterprise.cli.framework.CLIMain


4. Do a kill -3

mclaren> kill -3 565548

5. Switch back to asadmin terminal and you will see the location of the stack trace:

asadmin> JVMDUMP006I Processing Dump Event "user", detail "" - Please Wait.
JVMDUMP007I JVM Requesting Java Dump using '/home/affinium7/mas/tmp/glassfish/bin/javacore.20090610.101131.565548.txt'
JVMDUMP010I Java Dump written to /home/affinium7/mas/tmp/glassfish/bin/javacore.20090610.101131.565548.txt
JVMDUMP013I Processed Dump Event "user", detail "".


6. View the file to debug further :-)

Problems installing Glassfish on AIX with JDK1.5

If you are using an older version of JDK1.5 on AIX, you may encounter the following errors when starting up glassfish:

> asadmin start-domain
Starting Domain domain1, please wait.
Default Log location is /home/affinium7/mas/tmp/glassfish/domains/domain1/logs/server.log.
Redirecting output to /home/affinium7/mas/tmp/glassfish/domains/domain1/logs/server.log
JVMJ9VM007E Command-line option unrecognised: -client
Could not create the Java virtual machine.

Usage: java [-options] class [args...]
(to execute a class)
or java [-jar] [-options] jarfile [args...]
(to execute a jar file)

where options include:
-cp -classpath
set search path for application classes and resources
-D=
set a system property
-verbose[:class|gc|jni]
enable verbose output
-version print product version
-version:
require the specified version to run
-showversion print product version and continue
-jre-restrict-search | -no-jre-restrict-search
include/exclude user private JREs in the version search
-agentlib:[=]
load native agent library , e.g. -agentlib:hprof
see also, -agentlib:jdwp=help and -agentlib:hprof=help
-agentpath:[=]
load native agent library by full pathname
-javaagent:[=]
load Java programming language agent, see java.lang.instrument
-? -help print this help message
-X print help on non-standard options
-assert print help on assert options



Check your JDK Version using the command "java -fullversion":

> java -fullversion
java full version "J2RE 1.5.0 IBM AIX build pap64devifx-20060124"
>


The above is an old version, you will need to upgrade it (get the Sys Admin to do it)

Or, you can do the following:
1. In /domains/domain1/config/domain.xml , comment off:
-XX:MaxPermSize=192m
-client
-XX:NewRatio=2

2. In /lib/processLauncher.xml, comment off:




You should be able to do a start-domain now.

Friday, June 5, 2009

Java Decompilers

My harddisk gave up on me 2 days ago. I lost tonnes of data and files including more than a week's work of development. If you still have the class files, decompilers can help to save time in re-writing your code.

I found a very good list of java decompilers, if you should need it. Check it out here.

Thursday, June 4, 2009

Configuring log4j in Glassfish

I've found several links on how to configure log4j in Glassfish but it didn't work for me.

Here's what worked:

1. Copy the following jars to glassfish\lib:
log4j-1.2.15.jar
commons-logging-1.1.1.jar

2. Create a directory called logging under \glassfish\domains\domain1\lib

3. Copy log4j.properties to the logging directory created in Step 2

4. Login to admin console of Glassfish and navigate to:
Application Server > JVM Settings > Path Settings

5. Add the logging subdirectory created in Step 2 to System Classpath

6. Click Save and Restart Glassfish

7. Check that the logs are created

8. If the logs are not created:
- check your log4j.properties (class names must match)
- exit from asadmin after you stop domain (if you are in asadmin)

JAX-WS Links

Here's a compilation of JAX-WS links I've found useful:

Official JAX-WS FAQ
Web Services Made Easy with JAX-WS 2.0
Introducing JAX-WS 2.0 With the Java SE 6 Platform

Tuesday, May 26, 2009

Creating a webservice using JAXWS - High Level Steps

1. Get the WSDL and XSD files of the webservice you need to implement.
Eg. For my webservice, I needed:
parlayx_terminal_location_notification_service_2_2.wsdl
parlayx_terminal_location_notification_interface_2_2.wsdl
parlayx_terminal_location_types_2_2.xsd
parlayx_common_types_2_1.xsd

2. Use WSIMPORT to generate the code stubs
Eg. command I used:
F:\EclipseWorkspaces\MANDPLBS\MAWS_Stubs>F:\Apache\jaxws-ri\bin\wsimport parlayx_terminal_location_notification_service_2_2.wsdl -keep -s src -d build\classes

I generated the source files in src and clases in build\classes so that I can use this directory as a project directory in Eclipse workspace

When you run it, you will see:
parsing WSDL...


generating code...


compiling code...

3. Amend the source files to implement your logic.
- Most of wsdl will generate an interface class
- You might want to implement that interface using a different class
- Eg. My interface class: TerminalLocationNotification
My implementation class TerminalLocationNotificationImpl
- If you change the package name, you will need to change the classname annotations

4. You can rename the classes but each object must be defined in ObjectFactory
Note: When I didn't comment out the classname wsgen (next step) created another package with jaxws

5. Generate the WSDL and artifacts using the following command:
>D:\Apache\jaxws-ri\bin\wsgen -cp ../build/classes -r ../WebContent/wsdl -s . -d ../build/classes -keep com..lbs.server.TerminalLocationNotificationImpl -wsdl

-r to generate WSDL to the right dir
-s to generate the source files to the right dir
-d to generate the class files to the right dir

6. Export as war and deploy on app server.

Monday, May 25, 2009

Thursday, May 21, 2009

Changing Glassfish default ports

By default, Glassfish will run on port 8080 (HTTP), 8181 (HTTPS). To change the ports, you can

1. Change setup.xml (if you have not created the domain)
2. Change domain.xml (if you have created the domain). This file is found in glassfish/domains/domain1/config/domain.xml

Look for the following line:
="http-listener-1" port="8080" security-enabled="false" server-name="" xpowered-by="true">

And change 8080 to your new port.

Installing Glassfish on AIX

At this point in time, V3 is not available on AIX, so I will be using 2.1

1. Install JDK 1.5 or 1.6. You can download this from IBM AIX website.


2. Download Glassfish bundle from here. For AIX, downloaded glassfish-installer-v2.1-b60e-aix.jar size (61M). Note: ml stands for multi-language

3. Run the following command

% java -Xmx256m -jar glassfish-installer-v2.1-b60e-aix.jar


This command will unbundle GlassFish and create a new directory structure rooted under a directory named 'glassfish'.


4. CD to the glassfish subdirectory.

% cd glassfish

5. Set the execute permission for the Ant binaries that are included with the GlassFish bundle.

% chmod -R +x lib/ant/bin

% lib/ant/bin/ant -f setup.xml


6. On AIX, you may run into the following error:

create.domain:
[exec] Using port 4848 for Admin.
[exec] Using port 8080 for HTTP Instance.
[exec] Using port 7676 for JMS.
[exec] Using port 3700 for IIOP.
[exec] Using port 8181 for HTTP_SSL.
[exec] Using default port 3820 for IIOP_SSL.
[exec] Using default port 3920 for IIOP_MUTUALAUTH.
[exec] Using default port 8686 for JMX_ADMIN.
[exec] Domain being created with profile:developer, as specified by variable AS_ADMIN_PROFILE in configuration file.
[exec] ------ Using Profile [developer] to create the domain ------
[exec] XML processing for profile: Base document [/home/affinium7/mas/glassfish/lib/install/templates/default-domain.xml.template]. Profile name
property [domain.xml.style-sheets].
[exec] Security Store uses: JKS
[exec] File {0} not found.
[exec] CLI130 Could not create domain, domain1
BUILD FAILED
/home/affinium7/mas/glassfish/setup.xml:177: The following error occurred while executing this line:
/home/affinium7/mas/glassfish/setup.xml:607: exec returned: 1
Total time: 53 seconds


7. If you get the above error, it means .asadmintruststore was not created during installation and you will need to generate a new key. For full discussion on this, visit this post.

8. Run the following commmand to solve the problem:

keytool -genkey -keyalg RSA -keystore ~/.asadmintruststore -alias junk


9. Your actions will be as follows:
mclaren> keytool -genkey -keyalg RSA -keystore ~/.asadmintruststore -alias junk
Enter keystore password:
Re-enter new password:
What is your first and last name?
[Unknown]: XXX
What is the name of your organizational unit?
[Unknown]: Consumer Marketing
What is the name of your organization?
[Unknown]: XXX
What is the name of your City or Locality?
[Unknown]: Singapore
What is the name of your State or Province?
[Unknown]: Singapore
What is the two-letter country code for this unit?
[Unknown]: SG
Is CN=XXX, OU=Consumer Marketing, O=XXX, L=Singapore, ST=Singapore, C=SG correct? (type "yes" or "no")
[no]: yes
Enter key password for :
(RETURN if same as keystore password):
mclaren>


10. Once that is done, re-run the setup and your BUILD should be successful:
create.domain:
[exec] Using port 4848 for Admin.
[exec] Using port 8080 for HTTP Instance.
[exec] Using port 7676 for JMS.
[exec] Using port 3700 for IIOP.
[exec] Using port 8181 for HTTP_SSL.
[exec] Using default port 3820 for IIOP_SSL.
[exec] Using default port 3920 for IIOP_MUTUALAUTH.
[exec] Using default port 8686 for JMX_ADMIN.
[exec] Domain being created with profile:developer, as specified by variable AS_ADMIN_PROFILE in configuration file.
[exec] ------ Using Profile [developer] to create the domain ------
[exec] XML processing for profile: Base document [/home/affinium7/mas/glassfish/lib/install/templates/default-domain.xml.template]. Profile name [developer]. Processing property [domain.xml.style-sheets].
[exec] Security Store uses: JKS
[exec] Domain domain1 created.
[exec] Login information relevant to admin user name [admin] for this domain [domain1] stored at [/home/affinium7/.asadminpass] successfully.
[exec] Make sure that this file remains protected. Information stored in this file will be used by asadmin commands to manage this domain.
[delete] Deleting: /home/affinium7/mas/glassfish/passfile
BUILD SUCCESSFUL
Total time: 36 seconds


11. To start the app server:
cd glassfish/bin
asadmin start-domain

Domain domain1 is ready to receive client requests. Additional services are being started in background.
Domain [domain1] is running [Sun GlassFish Enterprise Server v2.1 (9.1.1) (build b60e-fcs)] with its configuration and logs at: [/home/affinium7/mas/glassfish/domains].
Admin Console is available at [http://localhost:4848].
Use the same port [4848] for "asadmin" commands.
User web applications are available at these URLs:
[http://localhost:8080 https://localhost:8181 ].
Following web-contexts are available:
[/web1 /__wstx-services HelloWorldService ].
Standard JMX Clients (like JConsole) can connect to JMXServiceURL:
[service:jmx:rmi:///jndi/rmi://mclaren:8686/jmxrmi] for domain management purposes.
Domain listens on at least following ports for connections:
[8080 8181 4848 3700 3820 3920 8686 ].
Domain does not support application server clusters and other standalone instances.


12. The default ports are:
admin port: 4848
app port: 8080

13. The default login to the admin server is
User: admin
Password: adminamin


Here's another good link that documents the installation/configuration of Glassfish. Click here.

Tuesday, May 19, 2009

Creating HelloWorldClient using WTP

1. Create a new project for the HelloWorld client (an ordinary Java project is sufficient)


2. Create a Web Service Client



3. Click on browse and choose the WSDL location






4. Increase the settings to "Test Client"


5. Choose Default settings and Click Next


6. Choose Default settings and Click Finish


7. Eclipse will publish a test client to Glassfish


8. A test page will appear


9. Check TCP/IP Monitor window to see if the SOAP calls are ok

Configuring Oracle datasource on Glassfish

1. Stop Glassfish server and copy the database driver jar to /lib. (I am using ojdbc14.jar file)



2. Once copied to the lib dir, start Glassfish again. Reload the admin console and login.


3. Expand the Resources menu item and then the JDBC menu item in the menu to the left. The JDBC menu contains two submenus, being JDBC Resources and Connection Pools. The JDBC Resource is exposed to (web) applications through JNDI. In order to create a JDBC Resource, we’ll need a Connection Pool first. To define an Oracle Connection Pool, click on connection Pools in the menu to the left.



4. Next, click the New button to enter the Connection Pool wizard. The first thing to do is specify the Connection Pool Name, Resource Type and Database Vendor. The Resource Type should be javax.sql.ConnectionPoolDatasource. Select the database vendor from the select box. Since we are creating an Oracle connection pool, select Oracle and click the Next button.


5. In the General Settings section, make sure the Datasource Classname is set to either oracle.jdbc.pool.OracleConnectionPoolDataSource (which is the default) or oracle.jdbc.xa.client.OracleXADataSource. Set all the other parameters as you like and scroll down to the Additional Properties section.

In this section, three or four properties are needed. All others can be discarded. The three needed ones are User, Password and URL. The fourth, optional, property is xa-driver-does-not-support-non-tx-operations. This property is only needed if both non-XA and XA connections are retrieved from the same connection pool.

So, specify the username, password and url. The last one is of the form jdbc:oracle:thin:@:: where usually is 1521. E.g. jdbc:oracle:thin:@pagani_s1:1521:ORCL



6. After specifying these properties, click Finish. This will bring you back to the connection Pool overview. Click on the Connection Pool name you just created and then the Ping button to see if the connection can be established.


7. If you see Ping Succeeded the connection pool has been setup correctly.


8. Now click on the JDBC Resources menu item in the menu to the left and then on the New button to create a new JDBC Resource.



9.Enter the name for the JDBC Resource and bear in mind that JNDI JDBC datasource names usually start with "jdbc/" so enter a name like "jdbc/mandplbs" or so. Also select the Connection Pool name you just created and successfully pinged from the select box. Hit the OK button and you’re done.

Monday, May 18, 2009

Configuring Apache CXF on Eclipse

1. Install Apache CXF. If you haven't, follow the steps here.

2. In Eclipse, go to Windows -> Preferences


3. Go to SOA Tools -> Installed Runtimes

4. Select Apache CXF 2.1


5. Set the appropriate paths to your Apache CXF install directory


6. You will the Apache CXF Runtime added