O'Reilly logo

Java Web Services: Up and Running by Martin Kalin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Deploying @WebServices and @WebServiceProviders

The SOAP-based Teams web service from Chapter 1 has four classes: Player, Team, TeamsUtility, and the SIB Teams. For this example, the four files reside in the directory ch06/team and all are in the Java package ch06.team. For review, here is the original SIB but in the new package:

package ch06.team;

import java.util.List;
import javax.jws.WebService;
import javax.jws.WebMethod;

@WebService
public class Teams {
    private TeamsUtility utils;
    public Teams() { utils = new TeamsUtility(); }

    @WebMethod
    public Team getTeam(String name) { return utils.getTeam(name); }
    @WebMethod
    public List<Team> getTeams() { return utils.getTeams(); }
}

After compilation, the .class files are copied to the directory ch06/team/WEB-INF/classes/ch06/team because Tomcat, the web container for GlassFish, expects compiled classes to reside in the WEB-INF/classes tree. A WAR file is created with the command:

% jar cvf team.war WEB-INF

and the WAR file then is copied to AS_HOME/domains/domain1/autodeploy. Although the Teams service is document-style, there is no need to generate manually, using wsgen, the JAX-B artifacts that such a service requires. GlassFish ships with the current Metro release, which automatically generates these artifacts.

The client-side wsimport artifacts are generated in the usual way:

% wsimport -keep -p clientC http://localhost:8081/team/TeamsService?wsdl

Here is a sample client that uses the wsimport-generated artifacts:

import teamsC.TeamsService; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required