Arun Gupta, Miles to go ...

Arun Gupta is a technology enthusiast, a passionate runner, and a community guy who works for Sun Microsystems.
« Previous day (Jun 17, 2007) | Main | Next day (Jun 19, 2007) »

http://blogs.sun.com/arungupta/date/20070618 Monday June 18, 2007

Tango on JavaSE 6

Fabian explained how WSIT features can be configured on Java SE 6 Endpoint API exposed as part of JAX-WS 2.1. In this blog, I start with a Reliable Messaging-enabled endpoint developed using NetBeans IDE 5.5.1 and WSIT plug-in and then provide detailed steps, along with code, to deploy it in Java SE 6.

  1. Create a Reliable Web service endpoint using WSIT plug-in and NetBeans 5.5.1 by watching this screencast.
  2. Download and install WSIT Milestone 5. Copy webservices-api.jar in Java SE 6 'jre\lib\endorsed' directory.
  3. All the capabilities enabled at an endpoint, such as Reliable Messaging for this one, are stored in the WSIT configuration file. In NetBeans IDE, expand your Project, 'Web Pages', 'WEB-INF'. The configuration file be named something similar to 'wsit-server.HelloWebService.xml' following the format 'wsit-<packageName>.<ServiceName>.xml'. Here is how the config file looks like:
    	
    <?xml version="1.0" encoding="UTF-8"?> <definitions
    xmlns="http://schemas.xmlsoap.org/wsdl/"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="HelloWebServiceService" targetNamespace="http://server/" xmlns:tns="http://server/" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsaws="http://www.w3.org/2005/08/addressing" xmlns:wsrm="http://schemas.xmlsoap.org/ws/2005/02/rm/policy">
    <message name="sayHello"/>
    <message name="sayHelloResponse"/>
    <portType name="HelloWebService">
    <wsdl:operation name="sayHello">
    <wsdl:input message="tns:sayHello"/>
    <wsdl:output message="tns:sayHelloResponse"/>
    </wsdl:operation>
    </portType>
    <binding name="HelloWebServicePortBinding" type="tns:HelloWebService">
    <wsp:PolicyReference URI="#HelloWebServicePortBindingPolicy"/>
    <wsdl:operation name="sayHello">
    <wsdl:input/>
    <wsdl:output/>
    </wsdl:operation>
    </binding>
    <service name="HelloWebServiceService">
    <wsdl:port name="HelloWebServicePort" binding="tns:HelloWebServicePortBinding"/>
    </service>
    <wsp:Policy wsu:Id="HelloWebServicePortBindingPolicy">
    <wsp:ExactlyOne>
    <wsp:All>
    <wsaws:UsingAddressing xmlns:wsaws="http://www.w3.org/2006/05/addressing/wsdl"/>
    <wsrm:RMAssertion/>
    </wsp:All>
    </wsp:ExactlyOne>
    </wsp:Policy>
    </definitions>
    Copy this config file by the name wsit-server.HelloWebService.xml in META-INF directory in your classpath.
  4. The Web service implementation class looks like:
    package server;

    import javax.jws.*;

    @WebService(targetNamespace="http://server/")
    public class HelloWebService {
        @WebMethod
        public String hello(@WebParam(name="name")String text) {
            return "Hello " + text;
        }
    }
    As you see, this is a plain JAX-WS Web service endpoint class.
  5. The JAX-WS Endpoint code that starts the Web service endpoint looks like:
    package server;
    
    import java.io.IOException;
    import javax.xml.ws.Endpoint;
    
    public class Main {
    
       private static final int PORT = 58888;
       private static final String HOST = "localhost";
    
       public static void main(String[] args) {
            Endpoint endpoint = Endpoint.create(new HelloWebService());
            String address = "http://" + HOST + ":" + PORT + "/";
            endpoint.publish(address);
            System.out.println("Endpoint hosted at ... " + address);
       }
    }
    
  6. The sequence of commands to deploy the endpoint is:
    "\Program Files\Java\jdk1.6.0_01\bin\javac.exe" -d . server\*.java
    "\Program Files\Java\jdk1.6.0_01\bin\wsgen.exe" -cp . server.HelloWebService
    java -classpath .;\jax-ws-latest-wsit\lib\webservices-rt.jar server.Main
  7. And then you see the following output on the command prompt:
    java -classpath .;C:\testbed\jax-ws-latest-wsit\lib\webservices-rt.jar server.Main
    Jun 18, 2007 4:46:34 PM [com.sun.xml.ws.policy.jaxws.PolicyConfigParser] parse
    INFO: WSP1049: Loaded WSIT configuration from file:
    file:/C:/workarea/wsit/javase6/META-INF/wsit-server.HelloWebService.xml
    Jun 18, 2007 4:46:34 PM [com.sun.xml.ws.tx.common.TxMapUpdateProvider] update
    INFO: WSTX-COMMON-2005: running in a non Java EE container; disable mapping of Container Managed Transaction EJB to WS-AT Policy assertions due to 'javax/ejb/TransactionManagement'
    Endpoint hosted at ... http://localhost:58888/

That's it, the endpoint now deployed at 'http://localhost:58888/MyService?wsdl' is Reliable Messaging enabled. This endpoint can be invoked using any of the methods shown here.

Technorati: webservices wsit jax-ws glassfish javase6

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

Week 18 Mileage - 6 more weeks

Mon: Rest
Tue: 7 miles
Wed: 8.5 miles
Thu: 7 miles
Fri: Rest
Sat: Rest
Sun: 23.3 miles

With Summer just around the corner, here are good reads on hydration:

  • Hydration 101 - What every runner should know about Hydration.
  • Dehydration 101 - As little as 2% dehydration will have negative effect on your race performance.
  • Overhydration in Marathon Training - USA Track & Field says get "guided by your thirst" instead of "stay ahead of your thirst".
  • Hydration Pack Reviews - Best way to stay hydrated on the run. I use the Ultimate Direction Access and have found it be really helpful for long runs.

Technorati: running fitness runninglog

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

Debug application code deployed on GlassFish using NetBeans ?

One of my friends asked how to debug a Servlet deployed on Java Application Platform SDK Update2. Debugging Servlet is no different than debugging any application on the Application Server. However searching on java.sun.com gave really old results. Top-level Search functionality is missing on glassfish.dev.java.net which hopefully will be fixed soon. Googling finally showed Debugging Applications but this is again command-line. So I decided to write a short blog describing the simple steps involved to debug a server-side application using NetBeans/GlassFish. Application Platform SDK Update2 contains Sun Java System Application Server 9.1 Beta2 which is equivalent to GlassFish V2 b41d.
  1. After you've installed GlassFish as 'Runtime' Server, then you need to start the Application Server in debug mode by right-clicking on the Server instance and selecting 'Start in Debug Mode'.

  2. This starts the Application Server on debug port 9009 and you'll see something similar in your NetBeans IDE:

  3. The default web page when you browse your Web project is 'index.jsp'. However if you need to debug your own Servlet then you need to configure it as the default page by right-clicking on Project, selecting Properties, Run category and specify the relative URL of the Servlet as shown below ('/NewServlet' in this case):

  4. That's all it takes to configure GlassFish in debug mode using NetBeans IDE. Deploy your applications on GlassFish or Application Platform SDK and set up break points any where ever you like in your application code. To debug your Web project, the simplest way is to right-select your project and choose 'Debug Project' as shown below:


    If you created a default Servlet using NetBeans IDE, then you can set up breakpoint in 'processRequest' method and watch the debug output in 'Debugger Console', 'Local Variables', 'Call Stack' and much more.

Check NetBeans Debugging Applications for more information.

Technorati: debugging netbeans glassfish

del.icio.us | furl | simpy | slashdot | technorati | digg |
|
« Previous day (Jun 17, 2007) | Main | Next day (Jun 19, 2007) »

Valid HTML! Valid CSS!

This is a personal weblog, I do not speak for my employer.