web services in cs1/is1. school of information technology reusable components most programs are...

9
Web services in CS1/IS1

Upload: garey-flynn

Post on 16-Dec-2015

216 views

Category:

Documents


0 download

TRANSCRIPT

Web services in CS1/IS1

School of Information Technology

Reusable Components

• Most programs are created by combining components that exist already, not from scratch!

• Reusing components saves time and money.

• Reused components are likely to be better developed, and more reliable.

• New components should designed to be reusable by other applications.Don’t reinvent the wheels!

Source: Savitch & Carrano 2009 CS1 text

School of Information Technology

Software Reuse

Package names

Class names

Description of class Scanner

Source: Savitch & Carrano 2009 CS1 text

School of Information Technology

Software Reuse via SOA/WS

• Latest form of reuse is via “services”• SOA (Service-Oriented Architecture)

– “A system for linking resources on demand. In an SOA, resources are made available to other participants in the network as independent services that are accessed in a standardized way. This provides for more flexible loose coupling of resources than in traditional systems architectures.” –Sybase

– “Architecture that describes an entity (e.g., application or enterprise) as a set of interdependent services. SOA provides for reuse of existing services and the rapid deployment of new business capabilities based on existing assets.” -- CIO.gov

– Many others …

School of Information Technology

Software Reuse via SOA/WS

• One popular way of implementing SOA is via Web services• WS (Web Service)

– "a software system designed to support interoperable machine-to-machine interaction over a network. It has an interface described in a machine-processable format (specifically WSDL). Other systems interact with the Web service in a manner prescribed by its description using SOAP-messages, typically conveyed using HTTP with an XML serialization in conjunction with other Web-related standards.“ – W3C

– Laymen terms: a piece of program that can interact with another program using standardized Web protocols

– Examples: Google Maps API, Flickr API, Twitter API, Amazon Web services. (API = Application Programming Interface)

School of Information Technology

NetBeans Generated Code Templatetry { // Call Web Service Operation <someService> service = new <someService>; < someServicePort> port = service.get<someServicePort>(); // TODO initialize WS operation arguments here declarations of arguments here // TODO process result here <someResult> result = port.methodOfInterest(argument list); System.out.println("Result = "+result);} catch (Exception ex) { // TODO handle custom exceptions here}

Bold: Statements of interests; Wish Exception ex wasprinted as part of the template.

School of Information Technology

Decision Structure try { // Call Web Service Operation com.cdyne.ws.profanityws.profanity.Profanity service = new com.cdyne.ws.profanityws.profanity.Profanity(); com.cdyne.ws.profanityws.profanity.ProfanitySoap port = service.getProfanitySoap(); // TODO initialize WS operation arguments here java.lang.String text = “You smoked weed? Dumb!"; // TODO process result here com.cdyne.ws.profanityws.profanity.FilterReturn result = port.simpleProfanityFilter(text); if (result.isFoundProfanity())

… else

… } catch (Exception ex) { // TODO handle custom exceptions here }

School of Information Technology

Repetition Structuremypackage.ISUDirectoryLookUpService service = new mypackage.ISUDirectoryLookUpService();mypackage.ISUDirectoryLookUp port = service.getISUDirectoryLookUpPort();// TODO initialize WS operation arguments herejava.lang.String lastName = aLastName;java.lang.String firstName = "";java.lang.String city = "";java.lang.String state = "";java.lang.String zip = "";// TODO process result heremypackage.DirectoryResult result = port.findPerson(lastName, firstName, city, state, zip);

School of Information Technology

Repetition Structure (2)Int listingSize = result.getItems().getDirectoryRecord().size();for (int i = 0; i < listingSize; i++) { firstName = result.getItems().getDirectoryRecord().get(i).getFirstName(); lastName = result.getItems().getDirectoryRecord().get(i).getLastName(); zip = result.getItems().getDirectoryRecord().get(i).getZip(); phone = result.getItems().getDirectoryRecord().get(i).getPhone(); state = result.getItems().getDirectoryRecord().get(i).getState(); cityNamePrint = result.getItems().getDirectoryRecord().get(i).getCity();}