XFireHome DocumentationJavadocs QuicklinksAegis Binding DevelopersDeveloper Space |
This guide leads you through the steps of writing a simple service using JSR 181 annotations. JSR 181 annotations allow you to customize your service and the resulting WSDL relatively easily. This guide assumes you're already familiar with the concepts of getting up and running with XFire outlined in the Quick Start guide. The full example can be found in "examples/jsr181" in the distribution. First one needs to write the service class. In this example we will allow our users to add Customers to our database and also list them. There will also be some authorization, which comes in the form of the UserToken class. Often authorization information is put in the soap header, so we've declared that all the UserTokens are headers via the @WebParam(header=true) annotation. Here is the customer service: package org.codehaus.xfire.demo; import java.util.ArrayList; import java.util.Collection; import java.util.List; import javax.jws.WebMethod; import javax.jws.WebParam; import javax.jws.WebResult; import javax.jws.WebService; @WebService public class CustomerService { private List<Customer> customers = new ArrayList<Customer>(); public CustomerService() { } @WebMethod @WebResult(name="Customers") public Collection<Customer> getCustomers(@WebParam(name="UserToken", header=true) UserToken auth) { authorize(auth); return customers; } private void authorize(UserToken auth) { System.out.println(auth.getUsername()); System.out.println(auth.getPassword()); } @WebMethod public String addCustomer(@WebParam(name="UserToken", header=true) UserToken auth, @WebParam(name="customer") Customer customer) { authorize(auth); customers.add(customer); return ""; } } The authorization token: package org.codehaus.xfire.demo; public class UserToken { private String username; private String password; public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } } The customer object: package org.codehaus.xfire.demo; public class Customer { private String name; private String email; private String phone; public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPhone() { return phone; } public void setPhone(String phone) { this.phone = phone; } } And finally our configuration xml: <beans xmlns="http://xfire.codehaus.org/config/1.0"> <service> <serviceClass>org.codehaus.xfire.demo.CustomerService</serviceClass> <serviceFactory>jsr181</serviceFactory> </service> </beans> |