110 likes | 199 Views
Developing web services with AXIS. AXIS web services and POJOS. Web services allow clients to make remote procedure calls (RPC). Let’s check the weather! A web service might allow a meteorologist to set the weather on the server. It should also allow users to obtain the weather forecast.
E N D
AXIS web services and POJOS • Web services allow clients to make remote procedure calls (RPC). • Let’s check the weather! • A web service might allow a meteorologist to set the weather on the server. It should also allow users to obtain the weather forecast.
AXIS web services and POJOS: Weather and WeatherService POJOs
AXIS web services and POJOS • RPC must pass object information across the network. • One encoding scheme called SOAP, uses XML representations of objects. • Other mechanisms exist for representing objects – we’ll look at JSON later on.
AXIS web services and POJOS • Visit apache axis site for information: (http://axis.apache.org/axis2/java/core/docs/pojoguide.html#pojo) Axis™ is a second generation SOAP engine… From earlier remarks you may recall this means Axis RPCs transfer XML packets for POJO representation. • Using Axis you can create a web service, deploy it to a container, and access your service via endpoint references where axis is running.
AXIS web services and POJOS: our two POJOs //Weather public class Weather{ float temperature; String forecast; boolean rain; float howMuchRain; public void setTemperature(float temp){ temperature = temp; } public float getTemperature(){ return temperature; } //other getters and setters } //WeatherService public class WeatherService{ Weather weather; public void setWeather(Weather weather) {this.weather= weather;} public Weather getWeather(){ return this.weather; }}
AXIS web services and POJOS: Snippet of client code used to set weather Options options = serviceClient.getOptions(); EndpointReferencetargetEPR = newEndpointReference("http://localhost:8080/axis2/services/WeatherService"); options.setTo(targetEPR); QNameopSetWeather = newQName("http://service.pojo.sample", "setWeather"); Weather w = new Weather(); float temp = (float) Double.parseDouble(args[0]);//I put weather info on command line for program to read w.setTemperature(temp); w.setForecast(args[1]); if(args.length > 2) {//weather details appear on command line for this demo w.setRain(true); float rain = (float) Double.parseDouble(args[2]); w.setHowMuchRain(rain);} Object[] opSetWeatherArgs = new Object[] { w }; serviceClient.invokeRobust(opSetWeather, opSetWeatherArgs);
eatherArgs); AXIS web services and POJOS: I provided a popup to display when weather is set…
AXIS web services and POJOS: snippet of client “get-weather” code RPCServiceClientserviceClient = new RPCServiceClient(); Options options = serviceClient.getOptions(); EndpointReferencetargetEPR = new EndpointReference( "http://localhost:8080/axis2/services/WeatherService"); options.setTo(targetEPR); QNameopGetWeather = new QName("http://service.pojo.sample", "getWeather"); Object[] opGetWeatherArgs = new Object[] { }; Class[] returnTypes = new Class[] { Weather.class }; Object[] response = serviceClient.invokeBlocking(opGetWeather, opGetWeatherArgs, returnTypes); Weather result = (Weather) response[0];
AXIS web services and POJOS: Adding the image icon makes it look like NOAA weather, right? Weather setter Weather getter with icon
AXIS summary • AXIS is designed to be used with a servlet container like Tomcat. • Along with your POJO and POJO-Service classes, the AXIS installation, running in Tomcat, will provide a full-fledged web service. • Remember, web services have no UI, unlike web applications. • In the example here, I provided pop-up windows so we could see our weather information being set, and being sent to the user. • We are using Java here, but there is a C/C++ version of AXIS as well.