Java EE 6 SDK 

Samples Main Page

The Hello-JAXWS Sample Application

This is a very simple JAX Web Service. This sample demonstrates the lowest possible effort way to:

Web Service

package endpoint;

import javax.jws.WebService;

@WebService
public class Hello
{
public String getHello(String name)
{
return "Hello " + name + "!";
}
}

This is as simple a Webservice as possible. All you need to create the Webservice is one extra line:
@WebService

Deployment

We create a simple war and deploy it to v3. No wsgen is used to generate artifacts. JAXWS 2.2 dynamically generates all the artifacts.

You can verify the Webservice is active by entering this in a browser (example server host and port):

http://localhost:8080/hello-jaxws2.2/HelloService?wsdl

Getting the Artifact files

In order to compile a client, we need some special files that the Hello Webservice will give us. This is required so that the client has the webservice interfaces and ports available. We use wsimport, an App Server-supplied program to do this like so:

${javaee.home}/bin/wsimport -Xendorsed -d ./build http://${javaee.server.name}:${javaee.server.port}/hellojaxws2.2/HelloService?wsdl"/>
Note: the Xendorsed option since JDK 6 u4 JAXWS 2.1 is packaged as part of rt.jar. We want to use JAXWS 2.2 apis and need to override the JAXWS 2.1 which is part of JDK 6u4 so we need to use Xendorsed"

Compiling the Client

The Client is also simple:

package client; import endpoint.HelloService;
import endpoint.Hello;

public class Client
{

public static void main(String[] args)
{
Client client = new Client();
client.doHello();
}

public void doHello()
{
try
{
HelloService service =new HelloService();
Hello port = service.getHelloPort();
String ret = port.getHello(System.getProperty("user.name"));
System.out.println("Hello result = " + ret);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}

Running the Client

You can run the client using appclient see the build.xml for more information

The client will print out a greeting from the Webservice using your name.

Building, Deploying, and Running the Application

Perform the following steps to build, deploy, and run the application:

  1. Set up your build environment and configure the application server with which the build system has to work by following the common build instructions.
  2. app_dir is the sample application base directory: samples_install_dir/javaee6/webservices/hello-jaxws2.2.
  3. Change directory to app_dir.
  4. Build, deploy, and run the sample application using the all target.
  5. app_dir> ant all

  6. Use the target clean to undeploy the sample application and to remove the temporary directories such as build and dist.

    app_dir> ant clean

Building, Deploying, and Running the Application in NetBeans IDE

Perform the following steps to build, deploy, and run the application using NetBeans IDE:

  1. Refer to the common build instructions for setting up NetBeans IDE and Java EE 6 SDK.
  2. In the NetBeans IDE, choose File → Open Project (Ctrl-Shift-O), navigate to the samples_install_dir/javaee6/webservices/ directory, select hello-jaxws2.2, and click Open Project.
  3. In the Projects tab, right click hello-jaxws2.2 and select Run to build, deploy, and run the project.

Troubleshooting

If you have problems when running the application, refer the troubleshooting document.


Copyright © 1997-2010 Oracle and/or its affiliates. All rights reserved.