Introducing the Sample
This sample demonstrates how to build and call a Web service using a given WSDL file. This approach is also called contract-first.
Info | |
---|---|
Infor | For more information on contact-first Web services, refer to: http://cxf.apache.org/docs/defining-contract-first-webservices-wi thwith-wsdl-generation-from-java.html |
...
This sample consists of three sections as follows:
- Creating the server and client code stubs from the WSDL.
- Service implementation.
- Client implementation.
Code
...
generation Anchor code code
code | |
code |
Code generation in Maven is done using the cxf-codegen-plugin. For infomation, refer to http://cxf.apache.org/docs/maven-cxf-codegen-plugin-wsdl-to-java.html. Code generation is activated using a binding.xml file. In this case, the normal java Date is used for xsd:date and xsd:DateTime. If this is not present, the XMLGregorianCalendar will be used.
Another common use of the binding file is to generate asynchronous stubs. The line jaxws:enableAsyncMapping has to be uncommented to use this. More information about the binding file can be found here:
http://jax-ws.java.net/jax-ws-20-fcs/docs/customizations.html.
Service
...
implementation Anchor service service
service | |
service |
The service is implemented in the class CustomerServiceImpl, which simply implements the previously-generated service interface. The method getCustomersByName demonstrates how a query function looks like. The idea is to search and return all customers with the given name. If the searched name is null, the method returns an exception to indicate that no matching customer was found. (In a real implementation, a list of
zero objects can typically be used). For any other name, the method returns a list of two customer objects. The number of objects can be increased to test how fast CXF works for larger data.
Client
...
implementation Anchor client client
client | |
client |
The main client code lives in the class CustomerServiceTester, which needs a proxy to the service and demonstrates some calls and their expected outcome using junit assertions.
The first call is a request getCustomersByName for all customers with name "Smith" and the result is checked. Then, the same method is called with the invalid name "None". In this case a NoSuchCustomerException is expected. The third call shows that the one way method updateCustomer will return instantly even if the service needs some time to process the request.
The classes CustomerServiceClient and CustomerServiceSpringClient show how to get a service proxy using JAX-WS and how to wire it to your business class (in this case, CustomerServiceTester).
Building and
...
running the
...
Using Maven
1. Install and run the WSO2 Application Server. Refer to the Installing Features for instructions.
...
sample
This sample can be found at <AS_HOME>\samples\Jaxws-Jaxrs\wsdl_first_jaxws
) , the maven pom.xml file can be used to build and run the sample using either UNIX or Windows.
3. To build the sample and create a WAR file, run mvn clean install command.
4. Start the Application Server (run bin/wso2server.sh/.bat).
- mvn -Pdeploy (deploys the generated WAR file on WSO2 AS with related logs on the console)
- mvn -Pclient (runs the client)
Using Apache Ant
1. Run "ant" on <CARBON_HOME>\samples\Jaxws-Jaxrs\ wsdl_first_jaxws directory to deploy the " wsdl_first_jaxws" service on the server.
2. Start the application server and access its Management Console at https://localhost:9443/carbon.
3. Go to "Services -> List" menu to find the "wsdl_first_jaxws" service listed on the "Deployed Services" window.
4. Execute "sh run-client.sh" or "run-client.bat" to run the client.
...
For information on building and running the sample, see Building and Running JAX-WS Samples.
Info | ||
---|---|---|
JAX-WS sample describing how to build and invoke a service using a WSDL in WSO2 Application Server
| ||
Excerpt | ||
| ||
|