90 likes | 241 Views
Web services in CS1/IS1 . 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.
E N D
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
Description of class Scanner Package names Class names Software Reuse Source: Savitch & Carrano 2009 CS1 text
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 …
Software Reuse via SOA/WS • One popular way of implementing SOA is via Web services • WS (Web Service) • "a software system designed to support interoperablemachine-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)
NetBeans Generated Code Template try { // 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 was printed as part of the template.
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 }
Repetition Structure mypackage.ISUDirectoryLookUpService service = new mypackage.ISUDirectoryLookUpService(); mypackage.ISUDirectoryLookUp port = service.getISUDirectoryLookUpPort(); // TODO initialize WS operation arguments here java.lang.StringlastName = aLastName; java.lang.StringfirstName = ""; java.lang.String city = ""; java.lang.String state = ""; java.lang.String zip = ""; // TODO process result here mypackage.DirectoryResult result = port.findPerson(lastName, firstName, city, state, zip);
Repetition Structure (2) IntlistingSize = result.getItems().getDirectoryRecord().size(); for (inti = 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(); }