You are on page 1of 61

Web Services 1) JAX WS Project Structure ::-

ReadMe.txt (firstexample) :: WebService has an interface and an implementation class


Step 1 ::Step 2 ::Step 3 ::Code the TimeServer interface Code the TimeServerImpl class implementing the TimeServer interface Code the TimeServerPublisher class EndPoint takes a url which can be any arbitary url Here we have used 'http://localhost:9876/ts', but it can be anything like 'http://localhost:9876/abc' running on port 9876 the port number also can be changed arbitarily Run the TimeServerPublisher as a java applicaton In Firefox, Open the url specified as the first parameter of EndPoint along with wsdl parameter http://localhost:9876/ts?wsdl

Step 4 ::Step 5 ::-

Take the targetNamespace and name values which are as follows :targetNamespace="http://firstexample.chapter1.notes.my/" // the / at the last is mandatory name="TimeServerImplService" Step 6 ::Code the TimeClient class The QName object takes 2 parameters the first one is the value of targetNamespace from step 5 the second parameter is the value of name from step 5

Code of package 'my.notes.chapter1.firstexample' ::TimeServer.java package my.notes.chapter1.firstexample; import javax.jws.WebService; import javax.jws.WebMethod; import javax.jws.soap.SOAPBinding; import javax.jws.soap.SOAPBinding.Style;

/** * The annotation @WebService signals that this is the SEI (Service Endpoint * Interface). @WebMethod signals that each method is a service operation. * * The @SOAPBinding annotation impacts the under-the-hood construction of the * service contract, the WSDL (Web Services Definition Language) document. * Style.RPC simplifies the contract and makes deployment easier. */ @WebService @SOAPBinding(style = Style.RPC) // more on this later public interface TimeServer { @WebMethod String getTimeAsString(); @WebMethod long getTimeAsElapsed(); } TimeServerImpl.java package my.notes.chapter1.firstexample; import java.util.Date; import javax.jws.WebService; /** * The @WebService property endpointInterface links the SIB (this class) to the * SEI (ch01.ts.TimeServer). Note that the method implementations are not * annotated as @WebMethods. */ @WebService(endpointInterface = "my.notes.chapter1.firstexample.TimeServer") public class TimeServerImpl implements TimeServer { public String getTimeAsString() { return new Date().toString(); } public long getTimeAsElapsed() { return new Date().getTime(); } } TimeServerPublisher.java
package my.notes.chapter1.firstexample; import javax.xml.ws.Endpoint; /** * This application publishes the Web service whose SIB is * ch01.ts.TimeServerImpl. For now, the service service is published at network * address 127.0.0.1., which is localhost, and at port number 9876, as this port * is likely available on any desktop machine. The publication path is /ts, an * arbitrary name. *

* The Endpoint class has an overloaded publish method. In this two-argument * version, the first argument is the publication URL as a string and the second * argument is an instance of the service SIB, in this case * ch01.ts.TimeServerImpl. * * The application runs indefinitely, awaiting service requests. It needs to be * terminated at the command prompt with control-C or the equivalent. * * Once the applicatation is started, open a browser to the URL * * http://127.0.0.1:9876/ts?wsdl * http://localhost:9876/ts?wsdl * * to view the service contract, the WSDL document. This is an easy test to * determine whether the service has deployed successfully. If the test * succeeds, a client then can be executed against the service. */ public class TimeServerPublisher { public static void main(String[] args) { System.out.println("Publishing the TimeServer..."); // 1st argument is the publication URL // 2nd argument is an SIB instance // Endpoint.publish("http://127.0.0.1:9876/ts", new TimeServerImpl()); Endpoint.publish("http://localhost:9876/ts", new TimeServerImpl()); } }

TimeClient.java package my.notes.chapter1.firstexample; import javax.xml.namespace.QName; import javax.xml.ws.Service; import java.net.URL; public class TimeClient { public static void main(String args[]) throws Exception { URL url = new URL("http://localhost:9876/ts?wsdl"); // // // // // // // // In Firefox, Open the url specified as the first parameter of EndPoint along with wsdl parameter http://localhost:9876/ts?wsdl Take the targetNamespace and name values which are as follows :targetNamespace="http://firstexample.chapter1.notes.my/" -- the / at the last is mandatory name="TimeServerImplService"

// Qualified name of the service: // 1st arg is the service URI // 2nd is the service name published in the WSDL QName qname = new QName("http://firstexample.chapter1.notes.my/", "TimeServerImplService"); // Create, in effect, a factory for the service. Service service = Service.create(url, qname);

// Extract the endpoint interface, the service "port". TimeServer eif = service.getPort(TimeServer.class); System.out.println(eif.getTimeAsString()); System.out.println(eif.getTimeAsElapsed()); } } Code of package 'my.notes.chapter1.secondexample' ::ReadMe.txt (secondexample) :: WebService has no interface only an implementation class
Step 1 ::- The TimeServer is the WebService and it is not an interface.

Step 2a ::- Use the wsgen on the TimeServerImpl class. Change to the bin folder which has the TimeServerImpl.class as follows --E:\MyApp\Eclipse\EclipseWorkSpaces\Eclipse Indigo\JavaWebServicesUpAndRunning\bin>wsgen -d ./my/notes/chapter1/secondexample -classpath . my.notes.chapter1.secondexample.TimeServerImpl The wsgen when executed generates the class files in the subdirectory jaxws under the folder E:\MyApp\Eclipse\EclipseWorkSpaces\Eclipse Indigo\JavaWebServicesUpAndRunning\bin\my\notes\chapter1\secondexample Note :---@SoapBinding (style = Style.RPC) should not be present in the WebService, otherwise wsgen does not generate any class files. Step 2b ::- Run the TimeServerPublisher as a java applicaton, before running the wsimport command. Step 3 ::E:\MyApp\Eclipse\EclipseWorkSpaces\Eclipse Indigo\JavaWebServicesUpAndRunning\bin> wsimport -p my.notes.chapter1.secondexample.timeC -keep http://localhost:9876/ts?wsdl The wsimport command generates the class files in the subdirectory as specified by the -p which is my.notes.chapter1. secondexample.timeC under the E:\MyApp\Eclipse\EclipseWorkSpaces\Eclipse Indigo\JavaWebServicesUpAndRunning\bin folder Step 4 ::Create a new package with the name my.notes.chapter1.secondexample.timeC Copy all the java files generated from step 3 above. See the file in the TimeClient.java uses the classes generated in step 4 above Run the TimeServerPublisher Run the TimeClient and see the results my.notes.chapter1.secondexample

Step 5 ::Step 6 ::-

Code of package

TimeServerImpl.java package my.notes.chapter1.secondexample;

import java.util.Date; import import import import javax.jws.WebMethod; javax.jws.WebService; javax.jws.soap.SOAPBinding; javax.jws.soap.SOAPBinding.Style;

/** * This WebService does not implement any interface * * @SOAPBinding(style = Style.RPC) must not be given otherwise the wsimport does * not generate any class files */ @WebService public class TimeServerImpl { @WebMethod public String getTimeAsString() { return new Date().toString(); } @WebMethod public long getTimeAsElapsed() { return new Date().getTime(); }

TimeServerPublisher.java package my.notes.chapter1.secondexample; import javax.xml.ws.Endpoint; /** * This application publishes the Web service whose SIB is * ch01.ts.TimeServerImpl. For now, the service service is published at network * address 127.0.0.1., which is localhost, and at port number 9876, as this port * is likely available on any desktop machine. The publication path is /ts, an * arbitrary name. * * The Endpoint class has an overloaded publish method. In this two-argument * version, the first argument is the publication URL as a string and the second * argument is an instance of the service SIB, in this case * ch01.ts.TimeServerImpl. * * The application runs indefinitely, awaiting service requests. It needs to be * terminated at the command prompt with control-C or the equivalent. * * Once the applicatation is started, open a browser to the URL * * http://127.0.0.1:9876/ts?wsdl * http://localhost:9876/ts?wsdl * * to view the service contract, the WSDL document. This is an easy test to * determine whether the service has deployed successfully. If the test * succeeds, a client then can be executed against the service. */ public class TimeServerPublisher { public static void main(String[] args) { System.out.println("Publishing the TimeServer..."); // 1st argument is the publication URL // 2nd argument is an SIB instance // Endpoint.publish("http://127.0.0.1:9876/ts", new TimeServerImpl());

} }

Endpoint.publish("http://localhost:9876/ts", new TimeServerImpl());

TimeClient.java package my.notes.chapter1.secondexample; import my.notes.chapter1.secondexample.timeC.TimeServerImplService; import my.notes.chapter1.secondexample.timeC.TimeServerImpl; class TimeClient { public static void main(String args[]) throws Exception { // Create, in effect, a factory for the service. TimeServerImplService service = new TimeServerImplService(); // Extract the endpoint interface, the service "port". TimeServerImpl eif = service.getTimeServerImplPort(); System.out.println(eif.getTimeAsString()); System.out.println(eif.getTimeAsElapsed()); } }

Classes generated by the wsimport and wsgen utilities Code of subpackage my.notes.chapter1.secondexample.timeC GetTimeAsElapsed.java package my.notes.chapter1.secondexample.timeC; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlType; /** * <p>Java class for getTimeAsElapsed complex type. * * <p>The following schema fragment specifies the expected content contained within this class. * * <pre> * &lt;complexType name="getTimeAsElapsed"> * &lt;complexContent> * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * &lt;sequence> * &lt;/sequence> * &lt;/restriction> * &lt;/complexContent> * &lt;/complexType> * </pre> * * */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "getTimeAsElapsed") public class GetTimeAsElapsed {

} GetTimeAsElapsedResponse.java package my.notes.chapter1.secondexample.timeC; import import import import javax.xml.bind.annotation.XmlAccessType; javax.xml.bind.annotation.XmlAccessorType; javax.xml.bind.annotation.XmlElement; javax.xml.bind.annotation.XmlType;

/** * <p>Java class for getTimeAsElapsedResponse complex type. * * <p>The following schema fragment specifies the expected content contained within this class. * * <pre> * &lt;complexType name="getTimeAsElapsedResponse"> * &lt;complexContent> * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * &lt;sequence> * &lt;element name="return" type="{http://www.w3.org/2001/XMLSchema}long"/> * &lt;/sequence> * &lt;/restriction> * &lt;/complexContent> * &lt;/complexType> * </pre> * * */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "getTimeAsElapsedResponse", propOrder = { "_return" }) public class GetTimeAsElapsedResponse { @XmlElement(name = "return") protected long _return; /** * Gets the value of the return property. * */ public long getReturn() { return _return; } /** * Sets the value of the return property. * */ public void setReturn(long value) { this._return = value; } } GetTimeAsString.java package my.notes.chapter1.secondexample.timeC;

import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlType; /** * <p>Java class for getTimeAsString complex type. * * <p>The following schema fragment specifies the expected content contained within this class. * * <pre> * &lt;complexType name="getTimeAsString"> * &lt;complexContent> * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * &lt;sequence> * &lt;/sequence> * &lt;/restriction> * &lt;/complexContent> * &lt;/complexType> * </pre> * * */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "getTimeAsString") public class GetTimeAsString { } GetTimeAsStringResponse.java package my.notes.chapter1.secondexample.timeC; import import import import javax.xml.bind.annotation.XmlAccessType; javax.xml.bind.annotation.XmlAccessorType; javax.xml.bind.annotation.XmlElement; javax.xml.bind.annotation.XmlType;

/** * <p>Java class for getTimeAsStringResponse complex type. * * <p>The following schema fragment specifies the expected content contained within this class. * * <pre> * &lt;complexType name="getTimeAsStringResponse"> * &lt;complexContent> * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * &lt;sequence> * &lt;element name="return" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/> * &lt;/sequence> * &lt;/restriction> * &lt;/complexContent> * &lt;/complexType> * </pre> * * */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "getTimeAsStringResponse", propOrder = {

"_return" }) public class GetTimeAsStringResponse { @XmlElement(name = "return") protected String _return; /** * Gets the value of the return property. * * @return * possible object is * {@link String } * */ public String getReturn() { return _return; } /** * Sets the value of the return property. * * @param value * allowed object is * {@link String } * */ public void setReturn(String value) { this._return = value; } } ObjectFactory.java package my.notes.chapter1.secondexample.timeC; import import import import javax.xml.bind.JAXBElement; javax.xml.bind.annotation.XmlElementDecl; javax.xml.bind.annotation.XmlRegistry; javax.xml.namespace.QName;

/** * This object contains factory methods for each * Java content interface and Java element interface * generated in the my.notes.chapter1.secondexample.timeC package. * <p>An ObjectFactory allows you to programatically * construct new instances of the Java representation * for XML content. The Java representation of XML * content can consist of schema derived interfaces * and classes representing the binding of schema * type definitions, element declarations and model * groups. Factory methods for each of these are * provided in this class. * */ @XmlRegistry public class ObjectFactory { private final static QName _GetTimeAsElapsedResponse_QNAME = new QName("http://secondexample.chapter1.notes.my/", "getTimeAsElapsedResponse"); private final static QName _GetTimeAsElapsed_QNAME = new QName("http://secondexample.chapter1.notes.my/", "getTimeAsElapsed"); private final static QName _GetTimeAsString_QNAME = new

QName("http://secondexample.chapter1.notes.my/", "getTimeAsString"); private final static QName _GetTimeAsStringResponse_QNAME = new QName("http://secondexample.chapter1.notes.my/", "getTimeAsStringResponse"); /** * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: my.notes.chapter1.secondexample.timeC * */ public ObjectFactory() { } /** * Create an instance of {@link GetTimeAsElapsedResponse } * */ public GetTimeAsElapsedResponse createGetTimeAsElapsedResponse() { return new GetTimeAsElapsedResponse(); } /** * Create an instance of {@link GetTimeAsElapsed } * */ public GetTimeAsElapsed createGetTimeAsElapsed() { return new GetTimeAsElapsed(); } /** * Create an instance of {@link GetTimeAsString } * */ public GetTimeAsString createGetTimeAsString() { return new GetTimeAsString(); } /** * Create an instance of {@link GetTimeAsStringResponse } * */ public GetTimeAsStringResponse createGetTimeAsStringResponse() { return new GetTimeAsStringResponse(); } /** * Create an instance of {@link JAXBElement }{@code <}{@link GetTimeAsElapsedResponse }{@code >}} * */ @XmlElementDecl(namespace = "http://secondexample.chapter1.notes.my/", name = "getTimeAsElapsedResponse") public JAXBElement<GetTimeAsElapsedResponse> createGetTimeAsElapsedResponse(GetTimeAsElapsedResponse value) { return new JAXBElement<GetTimeAsElapsedResponse>(_GetTimeAsElapsedResponse_QNAME, GetTimeAsElapsedResponse.class, null, value); } /** * Create an instance of {@link JAXBElement }{@code <}{@link GetTimeAsElapsed }{@code >}} * */ @XmlElementDecl(namespace = "http://secondexample.chapter1.notes.my/", name

= "getTimeAsElapsed") public JAXBElement<GetTimeAsElapsed> createGetTimeAsElapsed(GetTimeAsElapsed value) { return new JAXBElement<GetTimeAsElapsed>(_GetTimeAsElapsed_QNAME, GetTimeAsElapsed.class, null, value); } /** * Create an instance of {@link JAXBElement }{@code <}{@link GetTimeAsString }{@code >}} * */ @XmlElementDecl(namespace = "http://secondexample.chapter1.notes.my/", name = "getTimeAsString") public JAXBElement<GetTimeAsString> createGetTimeAsString(GetTimeAsString value) { return new JAXBElement<GetTimeAsString>(_GetTimeAsString_QNAME, GetTimeAsString.class, null, value); } /** * Create an instance of {@link JAXBElement }{@code <}{@link GetTimeAsStringResponse }{@code >}} * */ @XmlElementDecl(namespace = "http://secondexample.chapter1.notes.my/", name = "getTimeAsStringResponse") public JAXBElement<GetTimeAsStringResponse> createGetTimeAsStringResponse(GetTimeAsStringResponse value) { return new JAXBElement<GetTimeAsStringResponse>(_GetTimeAsStringResponse_QNAME, GetTimeAsStringResponse.class, null, value); } } package-info.java -----------------@javax.xml.bind.annotation.XmlSchema(namespace = "http://secondexample.chapter1.notes.my/") package my.notes.chapter1.secondexample.timeC; TimeServerImpl.java ------------------package my.notes.chapter1.secondexample.timeC; import import import import import javax.jws.WebMethod; javax.jws.WebResult; javax.jws.WebService; javax.xml.ws.RequestWrapper; javax.xml.ws.ResponseWrapper;

/** * This class was generated by the JAXWS SI. * JAX-WS RI 2.0_02-b08-fcs * Generated source version: 2.0 * */ @WebService(name = "TimeServerImpl", targetNamespace = "http://secondexample.chapter1.notes.my/")

public interface TimeServerImpl { /** * * @return * returns java.lang.String */ @WebMethod @WebResult(targetNamespace = "") @RequestWrapper(localName = "getTimeAsString", targetNamespace = "http://secondexample.chapter1.notes.my/", className = "my.notes.chapter1.secondexample.timeC.GetTimeAsString") @ResponseWrapper(localName = "getTimeAsStringResponse", targetNamespace = "http://secondexample.chapter1.notes.my/", className = "my.notes.chapter1.secondexample.timeC.GetTimeAsStringResponse") public String getTimeAsString(); /** * * @return * returns long */ @WebMethod @WebResult(targetNamespace = "") @RequestWrapper(localName = "getTimeAsElapsed", targetNamespace = "http://secondexample.chapter1.notes.my/", className = "my.notes.chapter1.secondexample.timeC.GetTimeAsElapsed") @ResponseWrapper(localName = "getTimeAsElapsedResponse", targetNamespace = "http://secondexample.chapter1.notes.my/", className = "my.notes.chapter1.secondexample.timeC.GetTimeAsElapsedResponse") public long getTimeAsElapsed(); } TimeServerImplService.java package my.notes.chapter1.secondexample.timeC; import import import import import import java.net.MalformedURLException; java.net.URL; javax.xml.namespace.QName; javax.xml.ws.Service; javax.xml.ws.WebEndpoint; javax.xml.ws.WebServiceClient;

/** * This class was generated by the JAXWS SI. * JAX-WS RI 2.0_02-b08-fcs * Generated source version: 2.0 * */ @WebServiceClient(name = "TimeServerImplService", targetNamespace = "http://secondexample.chapter1.notes.my/", wsdlLocation = "http://localhost:9876/ts?wsdl") public class TimeServerImplService extends Service { private final static URL TIMESERVERIMPLSERVICE_WSDL_LOCATION; static {

URL url = null; try { url = new URL("http://localhost:9876/ts?wsdl"); } catch (MalformedURLException e) { e.printStackTrace(); } TIMESERVERIMPLSERVICE_WSDL_LOCATION = url;

public TimeServerImplService(URL wsdlLocation, QName serviceName) { super(wsdlLocation, serviceName); } public TimeServerImplService() { super(TIMESERVERIMPLSERVICE_WSDL_LOCATION, new QName("http://secondexample.chapter1.notes.my/", "TimeServerImplService")); } /** * * @return * returns TimeServerImpl */ @WebEndpoint(name = "TimeServerImplPort") public TimeServerImpl getTimeServerImplPort() { return (TimeServerImpl)super.getPort(new QName("http://secondexample.chapter1.notes.my/", "TimeServerImplPort"), TimeServerImpl.class); } } Code of package 'my.notes.chapter1.thirdexample' ::ReadMe.txt(thirdexample) ::- WebService returns complex objects instead of simple types Step 1 ::- There is no interface for the WebService here. Step 2 ::- Code the Teams Web Service class (this class does not implement any interface unlike previous example where we have an interface and an implementation) Step 3 ::- Code the TeamsPublisher class EndPoint takes a url which can be any arbitary url Here we have used 'http://localhost:8888/teams' but it can be anything like 'http://localhost:9876/abc' running on port 9876 the port number also can be changed arbitarily Step 4 ::- Run the TeamsPublisher as a java applicaton Step 5 ::- In Firefox, Open the url specified as the first parameter of EndPoint along with wsdl parameter http://localhost:8888/teams?wsdl Take the targetNamespace and name values which are as follows :targetNamespace="http://secondexample.chapter1.notes.my/" -- the / at the last is mandatory name="TeamsService" Step 6 ::Unlike the [The QName (the first Code the TeamClient class previous example, this TeamClient class does not take a QName object takes 2 parameters one is the value of targetNamespace from step 5,

the second parameter is the value of name from step 5)] See the wsdl, which is as shown below :<service name="TeamsService"> <port name="TeamsPort" binding="tns:TeamsPortBinding"> <soap:address location="http://localhost:8888/teams"/> </port> </service> So create a TeamsService object 'teamsSvc' and then use the teamsSvc object to get the port (which as per the wsdl above has the name 'TeamsPort') as follows :teamsSvc.getTeamsPort() and then do what you like with it, for ex: print the teams, etc Now when you run the client, it does not work. In order to make it work do the following :----------------------------------------Stop the TeamsPublisher from running Step 7 ::Use the wsgen on the Teams class. Change to the bin folder which has the Teams.class as follows

--E:\MyApp\Eclipse\EclipseWorkSpaces\Eclipse Indigo\JavaWebServicesUpAndRunning\bin>wsgen -d ./my/notes/chapter1/thirdexample -classpath . my.notes.chapter1.thirdexample.Teams The wsgen when executed generates the class files in the subdirectory jaxws under the folder E:\MyApp\Eclipse\EclipseWorkSpaces\Eclipse Indigo\JavaWebServicesUpAndRunning\bin\my\notes\chapter1\thirdexample This utility generates various artifacts; that is, Java types needed by the method Endpoint.publish to generate the services WSDL. Note :---@SoapBinding (style = Style.RPC) should not be present in the WebService, otherwise wsgen does not generate any class files. Step 8 ::- Execute the TeamsPublisher as a java application, before running the wsimport command. Step 9 ::E:\MyApp\Eclipse\EclipseWorkSpaces\Eclipse Indigo\JavaWebServicesUpAndRunning\bin> wsimport -p my.notes.chapter1.thirdexample.teamsC -keep http://localhost:8888/teams?wsdl The wsimport command generates the class files in the subdirectory as specified by the -p which is my.notes.chapter1.thirdexample.teamsC under the E:\MyApp\Eclipse\EclipseWorkSpaces\Eclipse Indigo\JavaWebServicesUpAndRunning\bin folder This utility generates various classes in the subdirectory teamsC (the -p flag stands for package). These classes make it easier to write a client against the service. Step 10 ::- Create a new package with the name my.notes.chapter1.thirdexample.teamsC Copy all the java files generated from step 9 above.

Step 11 ::- See the file in the TeamsClient.java uses the classes generated in step 10 above Step 12 ::- Run the TeamsPublisher Run the TimeClient and see the results Teams.java package my.notes.chapter1.thirdexample; import java.util.List; import javax.jws.WebService; import javax.jws.WebMethod; @WebService public class Teams { private TeamsUtility utils; public Teams() { utils = new TeamsUtility(); utils.make_test_teams(); } @WebMethod public Team getTeam(String name) { return utils.getTeam(name); } @WebMethod public List<Team> getTeams() { return utils.getTeams(); }

TeamsUtility.java package my.notes.chapter1.thirdexample; import import import import import java.util.Set; java.util.List; java.util.ArrayList; java.util.Map; java.util.HashMap;

public class TeamsUtility { private Map<String, Team> team_map; public TeamsUtility() { team_map = new HashMap<String, Team>(); make_test_teams(); } public Team getTeam(String name) { return team_map.get(name); } public List<Team> getTeams() { List<Team> list = new ArrayList<Team>(); Set<String> keys = team_map.keySet(); for (String key : keys) list.add(team_map.get(key)); return list;

} public void make_test_teams() { List<Team> teams = new ArrayList<Team>(); Player burns = new Player("George Burns", "George"); Player allen = new Player("Gracie Allen", "Gracie"); List<Player> ba = new ArrayList<Player>(); ba.add(burns); ba.add(allen); Team burns_and_allen = new Team("Burns and Allen", ba); teams.add(burns_and_allen); Player abbott = new Player("William Abbott", "Bud"); Player costello = new Player("Louis Cristillo", "Lou"); List<Player> ac = new ArrayList<Player>(); ac.add(abbott); ac.add(costello); Team abbott_and_costello = new Team("Abbott and Costello", ac); teams.add(abbott_and_costello); Player chico = new Player("Leonard Marx", "Chico"); Player groucho = new Player("Julius Marx", "Groucho"); Player harpo = new Player("Adolph Marx", "Harpo"); List<Player> mb = new ArrayList<Player>(); mb.add(chico); mb.add(groucho); mb.add(harpo); Team marx_brothers = new Team("Marx Brothers", mb); teams.add(marx_brothers); store_teams(teams); } private void store_teams(List<Team> teams) { for (Team team : teams) team_map.put(team.getName(), team); } } Team.java package my.notes.chapter1.thirdexample; import java.util.List; public class Team { private List<Player> players; private String name; public Team() { } public Team(String name, List<Player> players) { setName(name); setPlayers(players); } public void setName(String name) { this.name = name; } public String getName() {

return name;

public void setPlayers(List<Player> players) { this.players = players; } public List<Player> getPlayers() { return players; } public void setRosterCount(int n) { } // no-op but needed for property public int getRosterCount() { return (players == null) ? 0 : players.size(); }

Player.java package my.notes.chapter1.thirdexample; public class Player { private String name; private String nickname; public Player() { } public Player(String name, String nickname) { setName(name); setNickname(nickname); } public void setName(String name) { this.name = name; } public String getName() { return name; } public void setNickname(String nickname) { this.nickname = nickname; } public String getNickname() { return nickname; } } TeamsPublisher.java package my.notes.chapter1.thirdexample; import javax.xml.ws.Endpoint; class TeamsPublisher { public static void main(String[] args) { int port = 8888; String url = "http://localhost:" + port + "/teams"; System.out.println("Publishing Teams on port " + port); Endpoint.publish(url, new Teams());

TeamClient.java package my.notes.chapter1.thirdexample; import import import import import my.notes.chapter1.thirdexample.teamsC.TeamsService; my.notes.chapter1.thirdexample.teamsC.Teams; my.notes.chapter1.thirdexample.teamsC.Team; my.notes.chapter1.thirdexample.teamsC.Player; java.util.List;

public class TeamClient { public static void main(String[] args) { TeamsService teamsSvc = new TeamsService(); my.notes.chapter1.thirdexample.teamsC.Teams port = teamsSvc .getTeamsPort(); List<Team> teams = port.getTeams(); for (Team team : teams) { System.out.println("Team name: " + team.getName() + " (roster count: " + team.getRosterCount() + for (Player player : team.getPlayers()) System.out.println(" Player: " + player.getNickname()); } } Classes generated by the wsimport and wsgen utilities GetTeam.java package my.notes.chapter1.thirdexample.teamsC; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlType; /** * <p>Java class for getTeam complex type. * * <p>The following schema fragment specifies the expected content contained within this class. * * <pre> * &lt;complexType name="getTeam"> * &lt;complexContent> * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * &lt;sequence> * &lt;element name="arg0" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/> * &lt;/sequence> * &lt;/restriction> * &lt;/complexContent> * &lt;/complexType> * </pre> * * */ @XmlAccessorType(XmlAccessType.FIELD) }

")");

@XmlType(name = "getTeam", propOrder = { "arg0" }) public class GetTeam { protected String arg0; /** * Gets the value of the arg0 property. * * @return * possible object is * {@link String } * */ public String getArg0() { return arg0; } /** * Sets the value of the arg0 property. * * @param value * allowed object is * {@link String } * */ public void setArg0(String value) { this.arg0 = value; } } GetTeamResponse.java package my.notes.chapter1.thirdexample.teamsC; import import import import javax.xml.bind.annotation.XmlAccessType; javax.xml.bind.annotation.XmlAccessorType; javax.xml.bind.annotation.XmlElement; javax.xml.bind.annotation.XmlType;

/** * <p>Java class for getTeamResponse complex type. * * <p>The following schema fragment specifies the expected content contained within this class. * * <pre> * &lt;complexType name="getTeamResponse"> * &lt;complexContent> * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * &lt;sequence> * &lt;element name="return" type="{http://thirdexample.chapter1.notes.my/}team" minOccurs="0"/> * &lt;/sequence> * &lt;/restriction> * &lt;/complexContent> * &lt;/complexType> * </pre> * * */

@XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "getTeamResponse", propOrder = { "_return" }) public class GetTeamResponse { @XmlElement(name = "return") protected Team _return; /** * Gets the value of the return property. * * @return * possible object is * {@link Team } * */ public Team getReturn() { return _return; } /** * Sets the value of the return property. * * @param value * allowed object is * {@link Team } * */ public void setReturn(Team value) { this._return = value; } } GetTeams.java package my.notes.chapter1.thirdexample.teamsC; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlType; /** * <p>Java class for getTeams complex type. * * <p>The following schema fragment specifies the expected content contained within this class. * * <pre> * &lt;complexType name="getTeams"> * &lt;complexContent> * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * &lt;sequence> * &lt;/sequence> * &lt;/restriction> * &lt;/complexContent> * &lt;/complexType> * </pre> * * */ @XmlAccessorType(XmlAccessType.FIELD)

@XmlType(name = "getTeams") public class GetTeams { } GetTeamsResponse.java package my.notes.chapter1.thirdexample.teamsC; import import import import import import java.util.ArrayList; java.util.List; javax.xml.bind.annotation.XmlAccessType; javax.xml.bind.annotation.XmlAccessorType; javax.xml.bind.annotation.XmlElement; javax.xml.bind.annotation.XmlType;

/** * <p>Java class for getTeamsResponse complex type. * * <p>The following schema fragment specifies the expected content contained within this class. * * <pre> * &lt;complexType name="getTeamsResponse"> * &lt;complexContent> * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * &lt;sequence> * &lt;element name="return" type="{http://thirdexample.chapter1.notes.my/}team" maxOccurs="unbounded" minOccurs="0"/> * &lt;/sequence> * &lt;/restriction> * &lt;/complexContent> * &lt;/complexType> * </pre> * * */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "getTeamsResponse", propOrder = { "_return" }) public class GetTeamsResponse { @XmlElement(name = "return") protected List<Team> _return; /** * Gets the value of the return property. * * <p> * This accessor method returns a reference to the live list, * not a snapshot. Therefore any modification you make to the * returned list will be present inside the JAXB object. * This is why there is not a <CODE>set</CODE> method for the return property. * * <p> * For example, to add a new item, do as follows: * <pre> * getReturn().add(newItem); * </pre> *

* * <p> * Objects of the following type(s) are allowed in the list * {@link Team } * * */ public List<Team> getReturn() { if (_return == null) { _return = new ArrayList<Team>(); } return this._return; } } ObjectFactory.java package my.notes.chapter1.thirdexample.teamsC; import import import import javax.xml.bind.JAXBElement; javax.xml.bind.annotation.XmlElementDecl; javax.xml.bind.annotation.XmlRegistry; javax.xml.namespace.QName;

/** * This object contains factory methods for each * Java content interface and Java element interface * generated in the my.notes.chapter1.thirdexample.teamsC package. * <p>An ObjectFactory allows you to programatically * construct new instances of the Java representation * for XML content. The Java representation of XML * content can consist of schema derived interfaces * and classes representing the binding of schema * type definitions, element declarations and model * groups. Factory methods for each of these are * provided in this class. * */ @XmlRegistry public class ObjectFactory { private final static QName _GetTeam_QNAME = new QName("http://thirdexample.chapter1.notes.my/", "getTeam"); private final static QName _GetTeams_QNAME = new QName("http://thirdexample.chapter1.notes.my/", "getTeams"); private final static QName _GetTeamsResponse_QNAME = new QName("http://thirdexample.chapter1.notes.my/", "getTeamsResponse"); private final static QName _GetTeamResponse_QNAME = new QName("http://thirdexample.chapter1.notes.my/", "getTeamResponse"); /** * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: my.notes.chapter1.thirdexample.teamsC * */ public ObjectFactory() { } /** * Create an instance of {@link GetTeamResponse } *

*/ public GetTeamResponse createGetTeamResponse() { return new GetTeamResponse(); } /** * Create an instance of {@link GetTeams } * */ public GetTeams createGetTeams() { return new GetTeams(); } /** * Create an instance of {@link GetTeamsResponse } * */ public GetTeamsResponse createGetTeamsResponse() { return new GetTeamsResponse(); } /** * Create an instance of {@link GetTeam } * */ public GetTeam createGetTeam() { return new GetTeam(); } /** * Create an instance of {@link Team } * */ public Team createTeam() { return new Team(); } /** * Create an instance of {@link Player } * */ public Player createPlayer() { return new Player(); } /** * Create an instance of {@link JAXBElement }{@code <}{@link GetTeam }{@code

>}}

* */ @XmlElementDecl(namespace = "http://thirdexample.chapter1.notes.my/", name = "getTeam") public JAXBElement<GetTeam> createGetTeam(GetTeam value) { return new JAXBElement<GetTeam>(_GetTeam_QNAME, GetTeam.class, null, value); } /** * Create an instance of {@link JAXBElement }{@code <}{@link GetTeams } {@code >}} * */ @XmlElementDecl(namespace = "http://thirdexample.chapter1.notes.my/", name = "getTeams")

public JAXBElement<GetTeams> createGetTeams(GetTeams value) { return new JAXBElement<GetTeams>(_GetTeams_QNAME, GetTeams.class, null, value); } /** * Create an instance of {@link JAXBElement }{@code <}{@link GetTeamsResponse }{@code >}} * */ @XmlElementDecl(namespace = "http://thirdexample.chapter1.notes.my/", name = "getTeamsResponse") public JAXBElement<GetTeamsResponse> createGetTeamsResponse(GetTeamsResponse value) { return new JAXBElement<GetTeamsResponse>(_GetTeamsResponse_QNAME, GetTeamsResponse.class, null, value); } /** * Create an instance of {@link JAXBElement }{@code <}{@link GetTeamResponse }{@code >}} * */ @XmlElementDecl(namespace = "http://thirdexample.chapter1.notes.my/", name = "getTeamResponse") public JAXBElement<GetTeamResponse> createGetTeamResponse(GetTeamResponse value) { return new JAXBElement<GetTeamResponse>(_GetTeamResponse_QNAME, GetTeamResponse.class, null, value); } } package-info.java @javax.xml.bind.annotation.XmlSchema(namespace = "http://thirdexample.chapter1.notes.my/") package my.notes.chapter1.thirdexample.teamsC; Player.java package my.notes.chapter1.thirdexample.teamsC; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlType; /** * <p>Java class for player complex type. * * <p>The following schema fragment specifies the expected content contained within this class. * * <pre> * &lt;complexType name="player"> * &lt;complexContent> * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * &lt;sequence> * &lt;element name="name" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/> * &lt;element name="nickname" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>

* &lt;/sequence> * &lt;/restriction> * &lt;/complexContent> * &lt;/complexType> * </pre> * * */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "player", propOrder = { "name", "nickname" }) public class Player { protected String name; protected String nickname; /** * Gets the value of the name property. * * @return * possible object is * {@link String } * */ public String getName() { return name; } /** * Sets the value of the name property. * * @param value * allowed object is * {@link String } * */ public void setName(String value) { this.name = value; } /** * Gets the value of the nickname property. * * @return * possible object is * {@link String } * */ public String getNickname() { return nickname; } /** * Sets the value of the nickname property. * * @param value * allowed object is * {@link String } * */ public void setNickname(String value) { this.nickname = value;

} } Team.java package my.notes.chapter1.thirdexample.teamsC; import import import import import import java.util.ArrayList; java.util.List; javax.xml.bind.annotation.XmlAccessType; javax.xml.bind.annotation.XmlAccessorType; javax.xml.bind.annotation.XmlElement; javax.xml.bind.annotation.XmlType;

/** * <p>Java class for team complex type. * * <p>The following schema fragment specifies the expected content contained within this class. * * <pre> * &lt;complexType name="team"> * &lt;complexContent> * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * &lt;sequence> * &lt;element name="name" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/> * &lt;element name="players" type="{http://thirdexample.chapter1.notes.my/}player" maxOccurs="unbounded" minOccurs="0"/> * &lt;element name="rosterCount" type="{http://www.w3.org/2001/XMLSchema}int"/> * &lt;/sequence> * &lt;/restriction> * &lt;/complexContent> * &lt;/complexType> * </pre> * * */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "team", propOrder = { "name", "players", "rosterCount" }) public class Team { protected String name; @XmlElement(nillable = true) protected List<Player> players; protected int rosterCount; /** * Gets the value of the name property. * * @return * possible object is * {@link String } * */

public String getName() { return name; } /** * Sets the value of the name property. * * @param value * allowed object is * {@link String } * */ public void setName(String value) { this.name = value; } /** * Gets the value of the players property. * * <p> * This accessor method returns a reference to the live list, * not a snapshot. Therefore any modification you make to the * returned list will be present inside the JAXB object. * This is why there is not a <CODE>set</CODE> method for the players property. * * <p> * For example, to add a new item, do as follows: * <pre> * getPlayers().add(newItem); * </pre> * * * <p> * Objects of the following type(s) are allowed in the list * {@link Player } * * */ public List<Player> getPlayers() { if (players == null) { players = new ArrayList<Player>(); } return this.players; } /** * Gets the value of the rosterCount property. * */ public int getRosterCount() { return rosterCount; } /** * Sets the value of the rosterCount property. * */ public void setRosterCount(int value) { this.rosterCount = value; } }

Teams.java package my.notes.chapter1.thirdexample.teamsC; import import import import import import import java.util.List; javax.jws.WebMethod; javax.jws.WebParam; javax.jws.WebResult; javax.jws.WebService; javax.xml.ws.RequestWrapper; javax.xml.ws.ResponseWrapper;

/** * This class was generated by the JAXWS SI. * JAX-WS RI 2.0_02-b08-fcs * Generated source version: 2.0 * */ @WebService(name = "Teams", targetNamespace = "http://thirdexample.chapter1.notes.my/") public interface Teams { /** * * @param arg0 * @return * returns my.notes.chapter1.thirdexample.teamsC.Team */ @WebMethod @WebResult(targetNamespace = "") @RequestWrapper(localName = "getTeam", targetNamespace = "http://thirdexample.chapter1.notes.my/", className = "my.notes.chapter1.thirdexample.teamsC.GetTeam") @ResponseWrapper(localName = "getTeamResponse", targetNamespace = "http://thirdexample.chapter1.notes.my/", className = "my.notes.chapter1.thirdexample.teamsC.GetTeamResponse") public Team getTeam( @WebParam(name = "arg0", targetNamespace = "") String arg0); /** * * @return * returns java.util.List<my.notes.chapter1.thirdexample.teamsC.Team> */ @WebMethod @WebResult(targetNamespace = "") @RequestWrapper(localName = "getTeams", targetNamespace = "http://thirdexample.chapter1.notes.my/", className = "my.notes.chapter1.thirdexample.teamsC.GetTeams") @ResponseWrapper(localName = "getTeamsResponse", targetNamespace = "http://thirdexample.chapter1.notes.my/", className = "my.notes.chapter1.thirdexample.teamsC.GetTeamsResponse") public List<Team> getTeams(); }

TeamsService.java package my.notes.chapter1.thirdexample.teamsC; import import import import import import java.net.MalformedURLException; java.net.URL; javax.xml.namespace.QName; javax.xml.ws.Service; javax.xml.ws.WebEndpoint; javax.xml.ws.WebServiceClient;

/** * This class was generated by the JAXWS SI. * JAX-WS RI 2.0_02-b08-fcs * Generated source version: 2.0 * */ @WebServiceClient(name = "TeamsService", targetNamespace = "http://thirdexample.chapter1.notes.my/", wsdlLocation = "http://localhost:8888/teams?wsdl") public class TeamsService extends Service { private final static URL TEAMSSERVICE_WSDL_LOCATION; static { URL url = null; try { url = new URL("http://localhost:8888/teams?wsdl"); } catch (MalformedURLException e) { e.printStackTrace(); } TEAMSSERVICE_WSDL_LOCATION = url; } public TeamsService(URL wsdlLocation, QName serviceName) { super(wsdlLocation, serviceName); } public TeamsService() { super(TEAMSSERVICE_WSDL_LOCATION, new QName("http://thirdexample.chapter1.notes.my/", "TeamsService")); } /** * * @return * returns Teams */ @WebEndpoint(name = "TeamsPort") public Teams getTeamsPort() { return (Teams)super.getPort(new QName("http://thirdexample.chapter1.notes.my/", "TeamsPort"), Teams.class); } }

FourthExample :: Code of Soap Demo DemoSoap.java package my.notes.chapter1.fourthexample; import java.util.Date; import java.util.Iterator; import java.io.InputStream; import java.io.ByteArrayOutputStream; import java.io.ByteArrayInputStream; import java.io.IOException; import javax.xml.soap.MessageFactory; import javax.xml.soap.SOAPMessage; import javax.xml.soap.SOAPEnvelope; import javax.xml.soap.SOAPHeader; import javax.xml.soap.SOAPBody; import javax.xml.soap.SOAPPart; import javax.xml.soap.SOAPElement; import javax.xml.soap.SOAPException; import javax.xml.soap.Node; import javax.xml.soap.Name; public class DemoSoap { private static final String LocalName = "TimeRequest"; private static final String Namespace = "http://ch01/mysoap/"; private static final String NamespacePrefix = "ms"; private ByteArrayOutputStream out; private ByteArrayInputStream in; public static void main(String[] args) { new DemoSoap().request(); } private void request() { try { // Build a SOAP message to send to an output stream. SOAPMessage msg = create_soap_message(); // Inject the appropriate information into the message. // In this case, only the (optional) message header is used // and the body is empty. SOAPEnvelope env = msg.getSOAPPart().getEnvelope(); SOAPHeader hdr = env.getHeader(); // Add an element to the SOAP header. Name lookup_name = create_qname(msg); hdr.addHeaderElement(lookup_name).addTextNode("time_request");

// Simulate sending the SOAP message to a remote system by // writing it to a ByteArrayOutputStream. out = new ByteArrayOutputStream(); msg.writeTo(out); trace("The sent SOAP message:", msg); SOAPMessage response = process_request(); extract_contents_and_print(response); } catch (SOAPException e) { System.err.println(e); } catch (IOException e) { System.err.println(e); } } private SOAPMessage process_request() { process_incoming_soap(); coordinate_streams(); return create_soap_message(in); } private void process_incoming_soap() { try { // Copy output stream to input stream to simulate // coordinated streams over a network connection. coordinate_streams(); // Create the "received" SOAP message from the // input stream. SOAPMessage msg = create_soap_message(in); // Inspect the SOAP header for the keyword 'time_request' // and process the request if the keyword occurs. Name lookup_name = create_qname(msg); SOAPHeader header = msg.getSOAPHeader(); Iterator it = header.getChildElements(lookup_name); Node next = (Node) it.next(); String value = (next == null) ? "Error!" : next.getValue(); // If SOAP message contains request for the time, create a // new SOAP message with the current time in the body. if (value.toLowerCase().contains("time_request")) { // Extract the body and add the current time as an element. String now = new Date().toString(); SOAPBody body = msg.getSOAPBody(); body.addBodyElement(lookup_name).addTextNode(now); msg.saveChanges();

// Write to the output stream. msg.writeTo(out); trace("The received/processed SOAP message:", msg); } } catch (SOAPException e) { System.err.println(e); } catch (IOException e) { System.err.println(e); } } private void extract_contents_and_print(SOAPMessage msg) { try { SOAPBody body = msg.getSOAPBody(); Name lookup_name = create_qname(msg); Iterator it = body.getChildElements(lookup_name); Node next = (Node) it.next(); String value = (next == null) ? "Error!" : next.getValue(); System.out.println("\n\nReturned from server: " + value); } catch (SOAPException e) { System.err.println(e); } } private SOAPMessage create_soap_message() { SOAPMessage msg = null; try { MessageFactory mf = MessageFactory.newInstance(); msg = mf.createMessage(); } catch (SOAPException e) { System.err.println(e); } return msg; } private SOAPMessage create_soap_message(InputStream in) { SOAPMessage msg = null; try { MessageFactory mf = MessageFactory.newInstance(); msg = mf.createMessage(null, // ignore MIME headers in); // stream source } catch (SOAPException e) { System.err.println(e); } catch (IOException e) { System.err.println(e); } return msg; } private Name create_qname(SOAPMessage msg) {

Name name = null; try { SOAPEnvelope env = msg.getSOAPPart().getEnvelope(); name = env.createName(LocalName, NamespacePrefix, Namespace); } catch (SOAPException e) { System.err.println(e); } return name; } private void trace(String s, SOAPMessage m) { System.out.println("\n"); System.out.println(s); try { m.writeTo(System.out); } catch (SOAPException e) { System.err.println(e); } catch (IOException e) { System.err.println(e); } } private void coordinate_streams() { in = new ByteArrayInputStream(out.toByteArray()); out.reset(); } } ReadMe.txt (fifthexample) :: WebService publisher using multiple threads
Step 1 ::Step 2 ::Step 3 ::Code the TimeServer interface Code the TimeServerImpl class implementing the TimeServer interface Code the TimeServerPublisher class (this is multi-threaded and uses MyThreadPool) EndPoint takes a url which can be any arbitary url Here we have used 'http://localhost:9876/ts' but it can be anything like 'http://localhost:9876/abc' running on port 9876 the port number also can be changed arbitarily Run the TimeServerPublisher as a java applicaton In Firefox, Open the url specified as the first parameter of EndPoint along with wsdl parameter http://localhost:9876/ts?wsdl

Step 4 ::Step 5 ::-

Take the targetNamespace and name values which are as follows :targetNamespace="http://firstexample.chapter1.notes.my/" -- the / at the last is mandatory name="TimeServerImplService" Step 6 ::Code the TimeClient class The QName object takes 2 parameters the first one is the value of targetNamespace from step 5 the second parameter is the value of name from step 5

TimeServer.java package my.notes.chapter1.fifthexample; import javax.jws.WebService; import javax.jws.WebMethod; import javax.jws.soap.SOAPBinding; import javax.jws.soap.SOAPBinding.Style; /** * The annotation @WebService signals that this is the SEI (Service Endpoint * Interface). @WebMethod signals that each method is a service operation. * * The @SOAPBinding annotation impacts the under-the-hood construction of the * service contract, the WSDL (Web Services Definition Language) document. * Style.RPC simplifies the contract and makes deployment easier. */ @WebService @SOAPBinding(style = Style.RPC) // more on this later public interface TimeServer { @WebMethod String getTimeAsString(); @WebMethod long getTimeAsElapsed(); } TimeServerImpl.java package my.notes.chapter1.fifthexample; import java.util.Date; import javax.jws.WebService; /** * The @WebService property endpointInterface links the SIB (this class) to the * SEI (ch01.ts.TimeServer). Note that the method implementations are not * annotated as @WebMethods. */ @WebService(endpointInterface = "my.notes.chapter1.fifthexample.TimeServer") public class TimeServerImpl implements TimeServer { public String getTimeAsString() { return new Date().toString(); } public long getTimeAsElapsed() { return new Date().getTime(); } }

MyThreadPool.java package my.notes.chapter1.fifthexample; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.Condition; public class MyThreadPool extends ThreadPoolExecutor { private static final int pool_size = 10; private boolean is_paused; private ReentrantLock pause_lock = new ReentrantLock(); private Condition unpaused = pause_lock.newCondition(); public MyThreadPool() { super(pool_size, // core pool size pool_size, // maximum pool size 0L, // keep-alive time for idle thread TimeUnit.SECONDS, // time unit for keep-alive setting new LinkedBlockingQueue<Runnable>(pool_size)); // work queue } // some overrides protected void beforeExecute(Thread t, Runnable r) { super.beforeExecute(t, r); pause_lock.lock(); try { while (is_paused) unpaused.await(); } catch (InterruptedException e) { t.interrupt(); } finally { pause_lock.unlock(); } } public void pause() { pause_lock.lock(); try { is_paused = true; } finally { pause_lock.unlock(); } } public void resume() { pause_lock.lock(); try { is_paused = false; unpaused.signalAll();

} finally { pause_lock.unlock(); } } } TimeServerPublisher.java /** * Multi-threaded TimeServerPublisher */ package my.notes.chapter1.fifthexample; import javax.xml.ws.Endpoint; /** * @author admin */ class TimeServerPublisher { private Endpoint endpoint; public static void main(String[] args) { TimeServerPublisher self = new TimeServerPublisher(); self.create_endpoint(); self.configure_endpoint(); self.publish(); } private void create_endpoint() { endpoint = Endpoint.create(new TimeServerImpl()); } private void configure_endpoint() { endpoint.setExecutor(new MyThreadPool()); } private void publish() { int port = 9876; String url = "http://localhost:" + port + "/ts"; endpoint.publish(url); System.out.println("Publishing TimeServer on port " + port); } } TimeClient.java package my.notes.chapter1.fifthexample; import javax.xml.namespace.QName; import javax.xml.ws.Service; import java.net.URL;

class TimeClient { public static void main(String args[]) throws Exception { URL url = new URL("http://localhost:9876/ts?wsdl"); // parameter // // // // mandatory // In Firefox, Open the url specified as the first parameter of EndPoint along with wsdl http://localhost:9876/ts?wsdl Take the targetNamespace and name values which are as follows :targetNamespace="http://firstexample.chapter1.notes.my/" -- the / at the last is name="TimeServerImplService"

// Qualified name of the service: // 1st arg is the service URI // 2nd is the service name published in the WSDL QName qname = new QName("http://fifthexample.chapter1.notes.my/", "TimeServerImplService"); // Create, in effect, a factory for the service. Service service = Service.create(url, qname); // Extract the endpoint interface, the service "port". TimeServer eif = service.getPort(TimeServer.class); System.out.println(eif.getTimeAsString()); System.out.println(eif.getTimeAsElapsed()); } }

2) SOAP web service using Axis example in java using eclipse ReadMe.txt
Example taken from the url http://javapostsforlearning.blogspot.in/2013/03/soap-web-service-example-injava-using.html also refer to the following url for more information http://rantincsharp.wordpress.com/2008/10/14/a-simple-soap-web-service-examplein-eclipse-ganymede/ -------------------------------------------------------------------------------In this post,we will create hello world SOAP web service example in eclipse. Step 1 ::Create new dynamic web project and name it "SimpleSOAPExample". Select Target Runtime :: Apache Tomcat v7.0 Dynamic Web Module Version :: 2.4 Configuration :: Default Configuration for Apache Tomcate v7.0 Click Finish.

Step 2 ::-

Create new package named "org.arpit.javapostsforlearning.webservices" and click Finish

Step 3 ::- Create a simple java class named "HelloWorld.java" package org.arpit.javapostsforlearning.webservices; public class HelloWorld { public String sayHelloWorld(String name) { return "Hello world from "+ name; } }

Step 4 ::- Right Click on the project --> New --> Other --> Web Services --> WebService

Step 5 ::- Enter the following for the WebServices configuration ::Service Implementation :: org.arpit.javapostsforlearning.webservices.HelloWorld Test Service -----------Increase the left most bar to maximum Client Type :: Java Proxy Increase the left most bar to maximum Click on Finish. This creates the HelloWorld.wsdl file in the wsdl folder of WebContent directory Also this creates the SimpleSOAPExampleClient project

In service implementation text box,write fully qualified class name of above created class(HelloWorld.java) and move both above slider to maximum level (i.e. Test service and Test Client level) and click on finish.You are done!!A new project named "SimpleSOAPExampleClient" will be created in your work space.

Step 6 ::-

Start the tomcat server with both the 'SimpleSOAPExample' and 'SimpleSOAPExampleClient' projects http://localhost:8080/SimpleSOAPExampleClient/sampleHelloWorldProxy/TestClient.j sp

Click on the sayHelloWorld(java.lang.String) and enter arpit and click on the Invoke button.

Result ::- Hello world from arpit

Project Structure ::-

Generated Files / Classes ::MANIFEST.MF


Manifest-Version: 1.0 Class-Path: HelloWorldService and its subdirectories and their associated files under WEBINF are generated

deploy.wsdd
<?xml version="1.0" encoding="UTF-8"?><!-- Use this file to deploy some handlers/chains and services --><!-- Two ways to do this: --><!-java org.apache.axis.client.AdminClient deploy.wsdd --><!-after the axis server is running --><!-- or --><!-java org.apache.axis.utils.Admin client|server deploy.wsdd --><!--

from the same directory that the Axis engine runs --> <deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"> <!-- Services from HelloWorldService WSDL service --> <service name="HelloWorld" provider="java:RPC" style="wrapped" use="literal"> <parameter name="wsdlTargetNamespace" value="http://webservices.javapostsforlearning.arpit.org"/> <parameter name="wsdlServiceElement" value="HelloWorldService"/> <parameter name="schemaQualified" value="http://webservices.javapostsforlearning.arpit.org"/> <parameter name="wsdlServicePort" value="HelloWorld"/> <parameter name="className" value="org.arpit.javapostsforlearning.webservices.HelloWorld"/> <parameter name="wsdlPortType" value="HelloWorld"/> <parameter name="typeMappingVersion" value="1.2"/> <operation xmlns:operNS="http://webservices.javapostsforlearning.arpit.org" xmlns:retNS="http://webservices.javapostsforlearning.arpit.org" xmlns:rtns="http://www.w3.org/2001/XMLSchema" name="sayHelloWorld" qname="operNS:sayHelloWorld" returnQName="retNS:sayHelloWorldReturn" returnType="rtns:string" soapAction=""> <parameter xmlns:pns="http://webservices.javapostsforlearning.arpit.org" xmlns:tns="http://www.w3.org/2001/XMLSchema" qname="pns:name" type="tns:string"/> </operation> <parameter name="allowedMethods" value="sayHelloWorld"/> </service> </deployment>

undeploy.wsdd
<!-- Use this file to undeploy some handlers/chains and services <!-- Two ways to do this: <!-java org.apache.axis.client.AdminClient undeploy.wsdd <!-after the axis server is running <!-- or <!-java org.apache.axis.utils.Admin client|server undeploy.wsdd <!-from the same directory that the Axis engine runs <undeployment xmlns="http://xml.apache.org/axis/wsdd/"> <!-- Services from HelloWorldService WSDL service --> <service name="HelloWorld"/> </undeployment> --> --> --> --> --> --> -->

server-config.wsdd
<ns1:deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java" xmlns:ns1="http://xml.apache.org/axis/wsdd/"> <ns1:globalConfiguration> <ns1:parameter name="sendMultiRefs" value="true"/> <ns1:parameter name="disablePrettyXML" value="true"/> <ns1:parameter name="adminPassword" value="admin"/> <ns1:parameter name="attachments.Directory" value="E:\MyApp\Eclipse\EclipseWorkSpaces\Eclipse Indigo\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\SimpleSOAP

Example\WEB-INF\attachments"/> <ns1:parameter name="dotNetSoapEncFix" value="true"/> <ns1:parameter name="enableNamespacePrefixOptimization" value="false"/> <ns1:parameter name="sendXMLDeclaration" value="true"/> <ns1:parameter name="sendXsiTypes" value="true"/> <ns1:parameter name="attachments.implementation" value="org.apache.axis.attachments.AttachmentsImpl"/> <ns1:requestFlow> <ns1:handler type="java:org.apache.axis.handlers.JWSHandler"> <ns1:parameter name="scope" value="session"/> </ns1:handler> <ns1:handler type="java:org.apache.axis.handlers.JWSHandler"> <ns1:parameter name="scope" value="request"/> <ns1:parameter name="extension" value=".jwr"/> </ns1:handler> </ns1:requestFlow> </ns1:globalConfiguration> <ns1:handler name="URLMapper" type="java:org.apache.axis.handlers.http.URLMapper"/> <ns1:handler name="LocalResponder" type="java:org.apache.axis.transport.local.LocalResponder"/> <ns1:handler name="Authenticate" type="java:org.apache.axis.handlers.SimpleAuthenticationHandler"/> <ns1:service name="AdminService" provider="java:MSG"> <ns1:parameter name="allowedMethods" value="AdminService"/> <ns1:parameter name="enableRemoteAdmin" value="false"/> <ns1:parameter name="className" value="org.apache.axis.utils.Admin"/> <ns1:namespace>http://xml.apache.org/axis/wsdd/</ns1:namespace> </ns1:service> <ns1:service name="Version" provider="java:RPC"> <ns1:parameter name="allowedMethods" value="getVersion"/> <ns1:parameter name="className" value="org.apache.axis.Version"/> </ns1:service> <ns1:service name="HelloWorld" provider="java:RPC" style="wrapped" use="literal"> <ns2:operation name="sayHelloWorld" qname="ns1:sayHelloWorld" returnQName="ns1:sayHelloWorldReturn" returnType="xsd:string" soapAction="" xmlns:ns1="http://webservices.javapostsforlearning.arpit.org" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns2="http://xml.apache.org/axis/wsdd/"> <ns2:parameter qname="ns1:name" type="xsd:string"/> </ns2:operation> <ns1:parameter name="allowedMethods" value="sayHelloWorld"/> <ns1:parameter name="typeMappingVersion" value="1.2"/> <ns1:parameter name="wsdlPortType" value="HelloWorld"/> <ns1:parameter name="className" value="org.arpit.javapostsforlearning.webservices.HelloWorld"/> <ns1:parameter name="wsdlServicePort" value="HelloWorld"/> <ns1:parameter name="schemaQualified" value="http://webservices.javapostsforlearning.arpit.org"/> <ns1:parameter name="wsdlTargetNamespace" value="http://webservices.javapostsforlearning.arpit.org"/> <ns1:parameter name="wsdlServiceElement" value="HelloWorldService"/> </ns1:service> <ns1:transport name="http"> <ns1:requestFlow> <ns1:handler type="URLMapper"/> <ns1:handler type="java:org.apache.axis.handlers.http.HTTPAuthHandler"/> </ns1:requestFlow> <ns1:parameter name="qs:list" value="org.apache.axis.transport.http.QSListHandler"/> <ns1:parameter name="qs:wsdl" value="org.apache.axis.transport.http.QSWSDLHandler"/> <ns1:parameter name="qs.list"

value="org.apache.axis.transport.http.QSListHandler"/> <ns1:parameter name="qs.method" value="org.apache.axis.transport.http.QSMethodHandler"/> <ns1:parameter name="qs:method" value="org.apache.axis.transport.http.QSMethodHandler"/> <ns1:parameter name="qs.wsdl" value="org.apache.axis.transport.http.QSWSDLHandler"/> </ns1:transport> <ns1:transport name="local"> <ns1:responseFlow> <ns1:handler type="LocalResponder"/> </ns1:responseFlow> </ns1:transport> </ns1:deployment>

web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <display-name>SimpleSOAPExample</display-name> <servlet> <display-name>Apache-Axis Servlet</display-name> <servlet-name>AxisServlet</servlet-name> <servlet-class>org.apache.axis.transport.http.AxisServlet</servletclass> </servlet> <servlet> <display-name>Axis Admin Servlet</display-name> <servlet-name>AdminServlet</servlet-name> <servlet-class>org.apache.axis.transport.http.AdminServlet</servletclass> <load-on-startup>100</load-on-startup> </servlet> <servlet-mapping> <servlet-name>AxisServlet</servlet-name> <url-pattern>/servlet/AxisServlet</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>AxisServlet</servlet-name> <url-pattern>*.jws</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>AxisServlet</servlet-name> <url-pattern>/services/*</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>AdminServlet</servlet-name> <url-pattern>/servlet/AdminServlet</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> </web-app>

HelloWorld.wsdl
<?xml version="1.0" encoding="UTF-8"?> <wsdl:definitions targetNamespace="http://webservices.javapostsforlearning.arpit.org" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://webservices.javapostsforlearning.arpit.org" xmlns:intf="http://webservices.javapostsforlearning.arpit.org" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <!--WSDL created by Apache Axis version: 1.4 Built on Apr 22, 2006 (06:55:48 PDT)--> <wsdl:types> <schema elementFormDefault="qualified" targetNamespace="http://webservices.javapostsforlearning.arpit.org" xmlns="http://www.w3.org/2001/XMLSchema"> <element name="sayHelloWorld"> <complexType> <sequence> <element name="name" type="xsd:string"/> </sequence> </complexType> </element> <element name="sayHelloWorldResponse"> <complexType> <sequence> <element name="sayHelloWorldReturn" type="xsd:string"/> </sequence> </complexType> </element> </schema> </wsdl:types> <wsdl:message name="sayHelloWorldRequest"> <wsdl:part element="impl:sayHelloWorld" name="parameters"> </wsdl:part> </wsdl:message> <wsdl:message name="sayHelloWorldResponse"> <wsdl:part element="impl:sayHelloWorldResponse" name="parameters"> </wsdl:part> </wsdl:message> <wsdl:portType name="HelloWorld"> <wsdl:operation name="sayHelloWorld"> <wsdl:input message="impl:sayHelloWorldRequest" name="sayHelloWorldRequest"> </wsdl:input> <wsdl:output message="impl:sayHelloWorldResponse"

name="sayHelloWorldResponse"> </wsdl:output> </wsdl:operation> </wsdl:portType> <wsdl:binding name="HelloWorldSoapBinding" type="impl:HelloWorld"> <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="sayHelloWorld"> <wsdlsoap:operation soapAction=""/> <wsdl:input name="sayHelloWorldRequest"> <wsdlsoap:body use="literal"/> </wsdl:input> <wsdl:output name="sayHelloWorldResponse"> <wsdlsoap:body use="literal"/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="HelloWorldService"> <wsdl:port binding="impl:HelloWorldSoapBinding" name="HelloWorld"> <wsdlsoap:address location="http://localhost:8080/SimpleSOAPExample/services/HelloWorld"/> </wsdl:port> </wsdl:service> </wsdl:definitions>

Project structure of 'SimpleSOAPExampleClient'

Generated files HelloWorld.java


/** * HelloWorld.java * * This file was auto-generated from WSDL * by the Apache Axis 1.4 Apr 22, 2006 (06:55:48 PDT) WSDL2Java emitter. */ package org.arpit.javapostsforlearning.webservices; public interface HelloWorld extends java.rmi.Remote { public java.lang.String sayHelloWorld(java.lang.String name) throws java.rmi.RemoteException; }

HelloWorldProxy.java
package org.arpit.javapostsforlearning.webservices; public class HelloWorldProxy implements org.arpit.javapostsforlearning.webservices.HelloWorld { private String _endpoint = null; private org.arpit.javapostsforlearning.webservices.HelloWorld helloWorld = null; public HelloWorldProxy() { _initHelloWorldProxy(); } public HelloWorldProxy(String endpoint) { _endpoint = endpoint; _initHelloWorldProxy(); } private void _initHelloWorldProxy() { try { helloWorld = (new org.arpit.javapostsforlearning.webservices.HelloWorldServiceLocator()).getHelloW orld(); if (helloWorld != null) { if (_endpoint != null) ((javax.xml.rpc.Stub)helloWorld)._setProperty("javax.xml.rpc.service.endpoint.ad dress", _endpoint); else _endpoint = (String) ((javax.xml.rpc.Stub)helloWorld)._getProperty("javax.xml.rpc.service.endpoint.ad dress"); } } catch (javax.xml.rpc.ServiceException serviceException) {}

public String getEndpoint() { return _endpoint; } public void setEndpoint(String endpoint) { _endpoint = endpoint; if (helloWorld != null) ((javax.xml.rpc.Stub)helloWorld)._setProperty("javax.xml.rpc.service.endpoint.ad dress", _endpoint); } public org.arpit.javapostsforlearning.webservices.HelloWorld getHelloWorld() { if (helloWorld == null) _initHelloWorldProxy(); return helloWorld; } public java.lang.String sayHelloWorld(java.lang.String name) throws java.rmi.RemoteException{ if (helloWorld == null) _initHelloWorldProxy(); return helloWorld.sayHelloWorld(name);

HelloWorldService.java /** * HelloWorldService.java * * This file was auto-generated from WSDL * by the Apache Axis 1.4 Apr 22, 2006 (06:55:48 PDT) WSDL2Java emitter. */ package org.arpit.javapostsforlearning.webservices; public interface HelloWorldService extends javax.xml.rpc.Service { public java.lang.String getHelloWorldAddress(); public org.arpit.javapostsforlearning.webservices.HelloWorld getHelloWorld() throws javax.xml.rpc.ServiceException; public org.arpit.javapostsforlearning.webservices.HelloWorld getHelloWorld(java.net.URL portAddress) throws javax.xml.rpc.ServiceException; } HelloWorldServiceLocator.java /** * HelloWorldServiceLocator.java * * This file was auto-generated from WSDL * by the Apache Axis 1.4 Apr 22, 2006 (06:55:48 PDT) WSDL2Java emitter. */ package org.arpit.javapostsforlearning.webservices; public class HelloWorldServiceLocator extends org.apache.axis.client.Service implements org.arpit.javapostsforlearning.webservices.HelloWorldService { public HelloWorldServiceLocator() { } public HelloWorldServiceLocator(org.apache.axis.EngineConfiguration config) } super(config);

public HelloWorldServiceLocator(java.lang.String wsdlLoc, javax.xml.namespace.QName sName) throws javax.xml.rpc.ServiceException { super(wsdlLoc, sName); } // Use to get a proxy class for HelloWorld private java.lang.String HelloWorld_address = "http://localhost:8080/SimpleSOAPExample/services/HelloWorld"; public java.lang.String getHelloWorldAddress() { return HelloWorld_address; } // The WSDD service name defaults to the port name. private java.lang.String HelloWorldWSDDServiceName = "HelloWorld"; public java.lang.String getHelloWorldWSDDServiceName() {

return HelloWorldWSDDServiceName;

public void setHelloWorldWSDDServiceName(java.lang.String name) { HelloWorldWSDDServiceName = name; } public org.arpit.javapostsforlearning.webservices.HelloWorld getHelloWorld() throws javax.xml.rpc.ServiceException { java.net.URL endpoint; try { endpoint = new java.net.URL(HelloWorld_address); } catch (java.net.MalformedURLException e) { throw new javax.xml.rpc.ServiceException(e); } return getHelloWorld(endpoint); } public org.arpit.javapostsforlearning.webservices.HelloWorld getHelloWorld(java.net.URL portAddress) throws javax.xml.rpc.ServiceException { try { org.arpit.javapostsforlearning.webservices.HelloWorldSoapBindingStub _stub = new org.arpit.javapostsforlearning.webservices.HelloWorldSoapBindingStub(portAddress , this); _stub.setPortName(getHelloWorldWSDDServiceName()); return _stub; } catch (org.apache.axis.AxisFault e) { return null; } } public void setHelloWorldEndpointAddress(java.lang.String address) { HelloWorld_address = address; } /** * For the given interface, get the stub implementation. * If this service has no port for the given interface, * then ServiceException is thrown. */ public java.rmi.Remote getPort(Class serviceEndpointInterface) throws javax.xml.rpc.ServiceException { try { if (org.arpit.javapostsforlearning.webservices.HelloWorld.class.isAssignableFrom(se rviceEndpointInterface)) { org.arpit.javapostsforlearning.webservices.HelloWorldSoapBindingStub _stub = new org.arpit.javapostsforlearning.webservices.HelloWorldSoapBindingStub(new java.net.URL(HelloWorld_address), this); _stub.setPortName(getHelloWorldWSDDServiceName()); return _stub; } } catch (java.lang.Throwable t) { throw new javax.xml.rpc.ServiceException(t); } throw new javax.xml.rpc.ServiceException("There is no stub implementation for the interface: " + (serviceEndpointInterface == null ? "null" : serviceEndpointInterface.getName())); }

/** * For the given interface, get the stub implementation. * If this service has no port for the given interface, * then ServiceException is thrown. */ public java.rmi.Remote getPort(javax.xml.namespace.QName portName, Class serviceEndpointInterface) throws javax.xml.rpc.ServiceException { if (portName == null) { return getPort(serviceEndpointInterface); } java.lang.String inputPortName = portName.getLocalPart(); if ("HelloWorld".equals(inputPortName)) { return getHelloWorld(); } else { java.rmi.Remote _stub = getPort(serviceEndpointInterface); ((org.apache.axis.client.Stub) _stub).setPortName(portName); return _stub; } } public javax.xml.namespace.QName getServiceName() { return new javax.xml.namespace.QName("http://webservices.javapostsforlearning.arpit.org", "HelloWorldService"); } private java.util.HashSet ports = null; public java.util.Iterator getPorts() { if (ports == null) { ports = new java.util.HashSet(); ports.add(new javax.xml.namespace.QName("http://webservices.javapostsforlearning.arpit.org", "HelloWorld")); } return ports.iterator(); } /** * Set the endpoint address for the specified port name. */ public void setEndpointAddress(java.lang.String portName, java.lang.String address) throws javax.xml.rpc.ServiceException { if ("HelloWorld".equals(portName)) { setHelloWorldEndpointAddress(address); } else { // Unknown Port Name throw new javax.xml.rpc.ServiceException(" Cannot set Endpoint Address for Unknown Port" + portName); } } /** * Set the endpoint address for the specified port name. */ public void setEndpointAddress(javax.xml.namespace.QName portName, java.lang.String address) throws javax.xml.rpc.ServiceException { setEndpointAddress(portName.getLocalPart(), address); }

} HelloWorldSoapBindingStub.java /** * HelloWorldSoapBindingStub.java * * This file was auto-generated from WSDL * by the Apache Axis 1.4 Apr 22, 2006 (06:55:48 PDT) WSDL2Java emitter. */ package org.arpit.javapostsforlearning.webservices; public class HelloWorldSoapBindingStub extends org.apache.axis.client.Stub implements org.arpit.javapostsforlearning.webservices.HelloWorld { private java.util.Vector cachedSerClasses = new java.util.Vector(); private java.util.Vector cachedSerQNames = new java.util.Vector(); private java.util.Vector cachedSerFactories = new java.util.Vector(); private java.util.Vector cachedDeserFactories = new java.util.Vector(); static org.apache.axis.description.OperationDesc [] _operations; static { _operations = new org.apache.axis.description.OperationDesc[1]; _initOperationDesc1(); } private static void _initOperationDesc1(){ org.apache.axis.description.OperationDesc oper; org.apache.axis.description.ParameterDesc param; oper = new org.apache.axis.description.OperationDesc(); oper.setName("sayHelloWorld"); param = new org.apache.axis.description.ParameterDesc(new javax.xml.namespace.QName("http://webservices.javapostsforlearning.arpit.org", "name"), org.apache.axis.description.ParameterDesc.IN, new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"), java.lang.String.class, false, false); oper.addParameter(param); oper.setReturnType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string")); oper.setReturnClass(java.lang.String.class); oper.setReturnQName(new javax.xml.namespace.QName("http://webservices.javapostsforlearning.arpit.org", "sayHelloWorldReturn")); oper.setStyle(org.apache.axis.constants.Style.WRAPPED); oper.setUse(org.apache.axis.constants.Use.LITERAL); _operations[0] = oper; } public HelloWorldSoapBindingStub() throws org.apache.axis.AxisFault { this(null); } public HelloWorldSoapBindingStub(java.net.URL endpointURL, javax.xml.rpc.Service service) throws org.apache.axis.AxisFault { this(service); super.cachedEndpoint = endpointURL; } public HelloWorldSoapBindingStub(javax.xml.rpc.Service service) throws org.apache.axis.AxisFault { if (service == null) {

super.service = new org.apache.axis.client.Service(); } else { super.service = service; } ((org.apache.axis.client.Service)super.service).setTypeMappingVersion("1.2"); } protected org.apache.axis.client.Call createCall() throws java.rmi.RemoteException { try { org.apache.axis.client.Call _call = super._createCall(); if (super.maintainSessionSet) { _call.setMaintainSession(super.maintainSession); } if (super.cachedUsername != null) { _call.setUsername(super.cachedUsername); } if (super.cachedPassword != null) { _call.setPassword(super.cachedPassword); } if (super.cachedEndpoint != null) { _call.setTargetEndpointAddress(super.cachedEndpoint); } if (super.cachedTimeout != null) { _call.setTimeout(super.cachedTimeout); } if (super.cachedPortName != null) { _call.setPortName(super.cachedPortName); } java.util.Enumeration keys = super.cachedProperties.keys(); while (keys.hasMoreElements()) { java.lang.String key = (java.lang.String) keys.nextElement(); _call.setProperty(key, super.cachedProperties.get(key)); } return _call; } catch (java.lang.Throwable _t) { throw new org.apache.axis.AxisFault("Failure trying to get the Call object", _t); } } public java.lang.String sayHelloWorld(java.lang.String name) throws java.rmi.RemoteException { if (super.cachedEndpoint == null) { throw new org.apache.axis.NoEndPointException(); } org.apache.axis.client.Call _call = createCall(); _call.setOperation(_operations[0]); _call.setUseSOAPAction(true); _call.setSOAPActionURI(""); _call.setEncodingStyle(null); _call.setProperty(org.apache.axis.client.Call.SEND_TYPE_ATTR, Boolean.FALSE); _call.setProperty(org.apache.axis.AxisEngine.PROP_DOMULTIREFS, Boolean.FALSE); _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS); _call.setOperationName(new javax.xml.namespace.QName("http://webservices.javapostsforlearning.arpit.org", "sayHelloWorld")); setRequestHeaders(_call);

try { {name});

setAttachments(_call); java.lang.Object _resp = _call.invoke(new java.lang.Object[]

if (_resp instanceof java.rmi.RemoteException) { throw (java.rmi.RemoteException)_resp; } else { extractAttachments(_call); try { return (java.lang.String) _resp; } catch (java.lang.Exception _exception) { return (java.lang.String) org.apache.axis.utils.JavaUtils.convert(_resp, java.lang.String.class); } } } catch (org.apache.axis.AxisFault axisFaultException) { throw axisFaultException; } } } MANIFEST.MF Manifest-Version: 1.0 Class-Path: Input.jsp <%@page contentType="text/html;charset=UTF-8"%> <HTML> <HEAD> <TITLE>Inputs</TITLE> </HEAD> <BODY> <H1>Inputs</H1> <% String method = request.getParameter("method"); int methodID = 0; if (method == null) methodID = -1; boolean valid = true; if(methodID != -1) methodID = Integer.parseInt(method); switch (methodID){ case 2: valid = false; %> <FORM METHOD="POST" ACTION="Result.jsp" TARGET="result"> <INPUT TYPE="HIDDEN" NAME="method" VALUE="< %=org.eclipse.jst.ws.util.JspUtils.markup(method)%>"> <BR> <INPUT TYPE="SUBMIT" VALUE="Invoke"> <INPUT TYPE="RESET" VALUE="Clear"> </FORM> <% break; case 5: valid = false; %> <FORM METHOD="POST" ACTION="Result.jsp" TARGET="result"> <INPUT TYPE="HIDDEN" NAME="method" VALUE="<

%=org.eclipse.jst.ws.util.JspUtils.markup(method)%>"> <TABLE> <TR> <TD COLSPAN="1" ALIGN="LEFT">endpoint:</TD> <TD ALIGN="left"><INPUT TYPE="TEXT" NAME="endpoint8" SIZE=20></TD> </TR> </TABLE> <BR> <INPUT TYPE="SUBMIT" VALUE="Invoke"> <INPUT TYPE="RESET" VALUE="Clear"> </FORM> <% break; case 10: valid = false; %> <FORM METHOD="POST" ACTION="Result.jsp" TARGET="result"> <INPUT TYPE="HIDDEN" NAME="method" VALUE="< %=org.eclipse.jst.ws.util.JspUtils.markup(method)%>"> <BR> <INPUT TYPE="SUBMIT" VALUE="Invoke"> <INPUT TYPE="RESET" VALUE="Clear"> </FORM> <% break; case 13: valid = false; %> <FORM METHOD="POST" ACTION="Result.jsp" TARGET="result"> <INPUT TYPE="HIDDEN" NAME="method" VALUE="< %=org.eclipse.jst.ws.util.JspUtils.markup(method)%>"> <TABLE> <TR> <TD COLSPAN="1" ALIGN="LEFT">name:</TD> <TD ALIGN="left"><INPUT TYPE="TEXT" NAME="name16" SIZE=20></TD> </TR> </TABLE> <BR> <INPUT TYPE="SUBMIT" VALUE="Invoke"> <INPUT TYPE="RESET" VALUE="Clear"> </FORM> <% break; case 1111111111: valid = false; %> <FORM METHOD="POST" ACTION="Result.jsp" TARGET="result"> <INPUT TYPE="HIDDEN" NAME="method" VALUE="< %=org.eclipse.jst.ws.util.JspUtils.markup(method)%>"> <TABLE> <TR> <TD COLSPAN="1" ALIGN="LEFT">URLString:</TD> <TD ALIGN="left"><INPUT TYPE="TEXT" NAME="url1111111111" SIZE=20></TD> </TR> </TABLE> <BR> <INPUT TYPE="SUBMIT" VALUE="Invoke"> <INPUT TYPE="RESET" VALUE="Clear"> </FORM> <% break; case 1111111112: valid = false; %>

<FORM METHOD="POST" ACTION="Result.jsp" TARGET="result"> <INPUT TYPE="HIDDEN" NAME="method" VALUE="< %=org.eclipse.jst.ws.util.JspUtils.markup(method)%>"> <BR> <INPUT TYPE="SUBMIT" VALUE="Invoke"> <INPUT TYPE="RESET" VALUE="Clear"> </FORM> <% break; } if (valid) { %> Select a method to test. <% } %> </BODY> </HTML> Method.jsp <%@page contentType="text/html;charset=UTF-8"%><HTML> <HEAD> <TITLE>Methods</TITLE> </HEAD> <BODY> <H1>Methods</H1> <UL> <LI><A HREF="Input.jsp?method=2" TARGET="inputs"> getEndpoint()</A></LI> <LI><A HREF="Input.jsp?method=5" TARGET="inputs"> setEndpoint(java.lang.String)</A></LI> <LI><A HREF="Input.jsp?method=10" TARGET="inputs"> getHelloWorld()</A></LI> <LI><A HREF="Input.jsp?method=13" TARGET="inputs"> sayHelloWorld(java.lang.String)</A></LI> </UL> </BODY> </HTML> Result.jsp <%@page contentType="text/html;charset=UTF-8"%> <% request.setCharacterEncoding("UTF-8"); %> <HTML> <HEAD> <TITLE>Result</TITLE> </HEAD> <BODY> <H1>Result</H1> <jsp:useBean id="sampleHelloWorldProxyid" scope="session" class="org.arpit.javapostsforlearning.webservices.HelloWorldProxy" /> <% if (request.getParameter("endpoint") != null && request.getParameter("endpoint").length() > 0) sampleHelloWorldProxyid.setEndpoint(request.getParameter("endpoint")); %> <% String method = request.getParameter("method"); int methodID = 0; if (method == null) methodID = -1;

if(methodID != -1) methodID = Integer.parseInt(method); boolean gotMethod = false; try { switch (methodID){ case 2: gotMethod = true; java.lang.String getEndpoint2mtemp = sampleHelloWorldProxyid.getEndpoint(); if(getEndpoint2mtemp == null){ %> <%=getEndpoint2mtemp %> <% }else{ String tempResultreturnp3 = org.eclipse.jst.ws.util.JspUtils.markup(String.valueOf(getEndpoint2mtemp)); %> <%= tempResultreturnp3 %> <% } break; case 5: gotMethod = true; String endpoint_0id= request.getParameter("endpoint8"); java.lang.String endpoint_0idTemp = null; if(!endpoint_0id.equals("")){ endpoint_0idTemp = endpoint_0id; } sampleHelloWorldProxyid.setEndpoint(endpoint_0idTemp); break; case 10: gotMethod = true; org.arpit.javapostsforlearning.webservices.HelloWorld getHelloWorld10mtemp = sampleHelloWorldProxyid.getHelloWorld(); if(getHelloWorld10mtemp == null){ %> <%=getHelloWorld10mtemp %> <% }else{ if(getHelloWorld10mtemp!= null){ String tempreturnp11 = getHelloWorld10mtemp.toString(); %> <%=tempreturnp11%> <% }} break; case 13: gotMethod = true; String name_1id= request.getParameter("name16"); java.lang.String name_1idTemp = null; if(!name_1id.equals("")){ name_1idTemp = name_1id; } java.lang.String sayHelloWorld13mtemp = sampleHelloWorldProxyid.sayHelloWorld(name_1idTemp); if(sayHelloWorld13mtemp == null){ %> <%=sayHelloWorld13mtemp %> <% }else{ String tempResultreturnp14 = org.eclipse.jst.ws.util.JspUtils.markup(String.valueOf(sayHelloWorld13mtemp)); %> <%= tempResultreturnp14 %>

<% } break; } } catch (Exception e) { %> Exception: <%= org.eclipse.jst.ws.util.JspUtils.markup(e.toString()) %> Message: <%= org.eclipse.jst.ws.util.JspUtils.markup(e.getMessage()) %> <% return; } if(!gotMethod){ %> result: N/A <% } %> </BODY> </HTML> TestClient.jsp <%@page contentType="text/html;charset=UTF-8"%><HTML> <HEAD> <TITLE>Web Services Test Client</TITLE> </HEAD> <FRAMESET COLS="220,*"> <FRAME SRC="Method.jsp" NAME="methods" MARGINWIDTH="1" MARGINHEIGHT="1" SCROLLING="yes" FRAMEBORDER="1"> <FRAMESET ROWS="80%,20%"> <FRAME SRC="Input.jsp" NAME="inputs" MARGINWIDTH="1" MARGINHEIGHT="1" SCROLLING="yes" FRAMEBORDER="1"> <% StringBuffer resultJSP = new StringBuffer("Result.jsp"); resultJSP.append("?"); java.util.Enumeration resultEnum = request.getParameterNames();while (resultEnum.hasMoreElements()) { Object resultObj = resultEnum.nextElement(); resultJSP.append(resultObj.toString()).append("=").append(request.getParameter(r esultObj.toString())).append("&"); } %> <FRAME SRC="<%=org.eclipse.jst.ws.util.JspUtils.markup(resultJSP.toString())%>" NAME="result" MARGINWIDTH="1" MARGINHEIGHT="1" SCROLLING="yes" FRAMEBORDER="1"> </FRAMESET> <NOFRAMES> <BODY> The Web Services Test Client requires a browser that supports frames. </BODY> </NOFRAMES> </FRAMESET> </HTML>