Accessing JAX-WS endpoints from Applets
By sameert on Jul 13, 2006
Though the usecase for such an application is rare, some developers want to access JAX-WS web services via Applets - this is indeed possible. To demonstrate the steps, lets use the endpoint based on the "Using XML in the SOAP body" strategy described here. Assuming you have the endpoint deployed successfully, modify the client to work as an Applet. For our example we will have a simple TextArea and Button to make the web service call and display the results.The source for the Applet can be found in file JAXWSApplet.java To get this Applet running a few basic steps need take place
a) Package the Applet and artifacts generated by the wsimport in a Jar file
b) Make the JAX-WS runtime available to the client. If you're using Java SE 6.0 (Mustang) and the browser plugin for that, then you should be all set. However if you're using J2SE 1.5 or an older version of Java then the JAX-WS Jars need to be made available to the browser. You can make these available in one of two ways. i) Get the JAX-WS distribution from Java.net and get the jars from the lib directory or ii) If you're using JAX-WS with Glassfish then locate the appserv-ws.jar and javaee.jar files in the lib directory.
c) Sign all the necessary JAR files using keytool and the jarsigner utility. This is a two step process that involves key generation and Jar file signing. A good technical article detailing this can be found here
keytool -genkey -alias signFiles -keystore mystore -keypass mykeypass -dname cn=Sun -storepass mystorepass
jarsigner -keystore mystore -storepass mystorepass -keypass mykeypass -signedjar SignedApplet.jar JAXWSApplet.jar signFiles
d) Place the signed JAR files and the HTML page with the Applet tag on the web server. In Glassfish, simply place all these contents in the glassfish\\docroot directory
Run the above example using targets in the following order to first build deploy and test the endpoint using a stand alone client ant create-war deploy-war run-wsdl-client. Then run the target sign-jaxws-ri which packages the Applet , signs the applet and signs the Glassfish Jars, plaing them in the build/signedjars directory along with an HTML file. Place the contents of this directory on your web server.Access the web page through the browser or appletviewer and you should see a result similar to the screen below when the button is pressed.