1 / 11

Developing web services with AXIS

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.

noble-kidd
Download Presentation

Developing web services with AXIS

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Developing web services with AXIS

  2. 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.

  3. AXIS web services and POJOS: Weather and WeatherService POJOs

  4. 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.

  5. 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.

  6. 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; }}

  7. 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);

  8. eatherArgs); AXIS web services and POJOS: I provided a popup to display when weather is set…

  9. 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];

  10. AXIS web services and POJOS: Adding the image icon makes it look like NOAA weather, right? Weather setter Weather getter with icon

  11. 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.

More Related