/** * @author Hyacinthe MENIET * Created on 22 juil. 07 */ package net.dotmyself.wsclient; import javax.xml.ws.AsyncHandler; import javax.xml.ws.Response; import net.dotmyself.ws.Department; import net.dotmyself.ws.DepartmentInformationService; import net.dotmyself.ws.DepartmentService; import net.dotmyself.ws.GetDepartmentResponse; /** * Asynchronous Client for Department's Web service */ public class AsynchDepartmentWSClient { /** * The main method. * @param args the department's code * @throws Exception */ public static void main(String[] args) throws Exception { if(args == null || args.length < 1) { throw new IllegalArgumentException("You must indicate a department code"); } int code = Integer.parseInt(args[0]); DepartmentInformationService departInfoService = new DepartmentInformationService(); DepartmentService departService = departInfoService.getDepartmentServicePort(); departService.getDepartmentAsync(code, new AsyncHandler() { @Override public void handleResponse(Response res) { // Asynchronous Invocation try { if (!res.isCancelled() && res.isDone()) { GetDepartmentResponse message = res.get(); Department dept = message.getDepartment(); System.out.println("Population ="+dept.getPopulation()+" habs, " +"Surface="+dept.getSurface()+" km2, " +"Urbanization="+dept.getUrbanization()); } } catch (Exception ex) { ex.printStackTrace(); } } }); // give 10 secondes to asynchronous call to complete Thread.sleep(10000); } }