Skip to main content

Developing Webservices using Glassfish AS 9.1 and JDK 6

Posted by bhaktimehta on January 2, 2007 at 2:08 PM EST
Developing Webservices using Glassfish AS 9.1 and JDK 6

This blog will show how to develop, run and deploy JAX-WS  based webservices with Glassfish v2 Milestone 3 build using JDK 6.
It will demonstrate step by step instructions using the hello-jaxws sample from the following glassfish-samples.

What is different when trying with JDK 6?

JDK 6.0 has  JAXB/JAX-WS 2.0 versions of the apis.
In the latest Glassfish v2 we are integrating the implementation classes compliant with JAXB/JAX-WS 2.1 versions
of the apis which are present in  javaee.jar .

So when we run with Glassfish and JDK 6.0 (without putting anything in the <AS HOME>/lib/endorsed directory),
the APIs/Annotation classes for JAX-WS 2.0 and JAXB 2.0 will be picked up instead of JAX-WS 2.1 and JAXB 2.1.

To avoid this we need to use the endorsed standards to override the 2.0 apis by putting javaee.jar in $AS_HOME/lib/endorsed.
This is a temporary workaround for now and this issue will be fixed soon.

Steps to run the sample with JDK 6

Install JDK 6 from http://download.java.net/jdk6/binaries/

Install  GlassFish v2 Milestone 3

Install  from https://glassfish.dev.java.net/public/downloadsindex.html
Follow these instructions to unbundle and configure glassfish .

Check the version of JDK used by Glassfish to be JDK 6.0

For those users who have already installed GlassFish and wish to change the JDK version. That's equally simple. The JDK path is stored in one location :
  1. Check the following file where AS_HOME is the location where Glassfish is installed
    <$AS_HOME>/config/asenv.conf for AS_JAVA
  2. Modify  $AS_JAVA to point to JDK 6 if that is not already set
    AS_JAVA="location of JDK 6" 

Download the  glassfish-samples from the following site https://glassfish-samples.dev.java.net/

  1. Run :
     java -jar javaee5-samples-installer-1.0-b08.jar
  2. Edit : <location of samples>/bp-project/build.properties to point to $AS_HOME for e.g
     javaee.home="location of Glassfish"
  3. Check the java version on the client side
     /usr/glassfish-samples/javaee5/webservices %java -version
           java version "1.6.0-rc"
           Java(TM) SE Runtime Environment (build 1.6.0-rc-b104)
           Java HotSpot(TM) Client VM (build 1.6.0-rc-b104, mixed mode,   sharing)

Add javaee.jar to $AS_HOME/lib/endorsed

As mentioned earlier this extra step will be required for running with JDK 6.0

  1. mkdir -p $AS_HOME/lib/endorsed
  2. mv $AS_HOME/lib/javaee.jar $AS_HOME/lib/endorsed
Start Appserver
/usr/glassfish/bin %$AS_HOME/bin/asadmin* start-domain domain1


Run the Sample
  1. Modify <location  of samples>/javaee5/webservices/hello-jaxws/build.xml to point to
    $AS_HOME/lib/endorsed/javaee.jar in classpath. Currently the samples point to j2ee.jar in the build.xml
  2. Replace references of j2ee.jar with location of javaee.jar
    <path id="classpath">
        <pathelement location="${javaee.home}/lib/endorsed/javaee.jar"/>
        <pathelement location="${classesdir}"/>
    </path>

    and
    <target name="compile-deploy-service" depends="init">
    <mkdir dir="${classesdir}"/>
    <echo message="${javaee.home}"/>
    <javac
    srcdir="./src"
    includes="endpoint/**"
    destdir="${autodeploydir}"
    classpath="${javaee.home}/lib/endorsed/javaee.jar"
    />
    ...
    </target>


  3. Run:
    /usr/glassfish-samples/javaee5/webservices/hello-jaxws %ant

This is how the output looks like on the client side
/usr/glassfish-samples/javaee5/webservices/hello-jaxws %ant
Buildfile: build.xml

init:

compile-deploy-service:
     [echo] /usr/glassfish

get-artifacts-unix:
     [exec] parsing WSDL...

     [exec] generating code...

get-artifacts-windows:

get-artifacts:

compile-client:
    [javac] Compiling 1 source file to /usr/glassfish-samples/javaee5/webservices
hello-jaxws/build

run-client-unix:
     [exec] Hello result = Hello Administrator!

run-client-windows:

run-client:

all:

BUILD SUCCESSFUL
Total time: 13 seconds










Related Topics >>

Comments

Developing Webservices using

This seems related to what you're saying. I've put Xalan in the endorsed libs of both Glassfish and the JDK but still get this exception. Ideas?
Caused by: org.apache.xml.serializer.utils.WrappedRuntimeException: org.apache.xml.serializer.ToXMLSAXHandler cannot be cast to org.apache.xml.serializer.SerializationHandler
at org.apache.xml.serializer.SerializerFactory.getSerializer(SerializerFactory.java:179)
at org.apache.xalan.transformer.TransformerIdentityImpl.createResultContentHandler(TransformerIdentityImpl.java:260)
at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:330)
at org.apache.cxf.interceptor.LoggingInInterceptor.writePayload(LoggingInInterceptor.java:124)
at org.apache.cxf.interceptor.LoggingInInterceptor.logging(LoggingInInterceptor.java:197)