300 likes | 477 Views
PROGRAMIRANJE U JAVI: WEB USLUGE. autor: Dario Vuljanić mentor: mr.sc. Marko Čupić. Sadržaj predavanja. 2. Uvod u Web usluge SOAP, WSDL, UDDI Apache Axis Usluga MetricConverter .jws datoteka, SOAP poruke Apache Tomcat BookFinder opisnik Web usluge.
E N D
PROGRAMIRANJE U JAVI: WEB USLUGE autor: Dario Vuljanić mentor: mr.sc. Marko Čupić
Sadržaj predavanja 2 • Uvod u Web usluge • SOAP, WSDL, UDDI • Apache Axis • Usluga MetricConverter • .jws datoteka, SOAP poruke • Apache Tomcat • BookFinder • opisnik Web usluge Seminar: Programiranje u Javi - Web usluge Dario Vuljanić, 2007.
Web usluge 3 • praktične aplikacije na internetu temeljene na XML-u dostupne preko URL adrese • najrašireniji oblik: • pozivanje metoda na udaljenim računalima • (eng. RPC = Remote Procedure Calls) Seminar: Programiranje u Javi - Web usluge Dario Vuljanić, 2007.
RPC 4 metoda arg0,arg1... odgovor I N T E R N E T metoda arg0,arg1... odgovor ... naredba1; RPC_poziv; naredba2; ... metoda(...) { ... return odgovor; } Seminar: Programiranje u Javi - Web usluge Dario Vuljanić, 2007.
Tehnologije Web usluga 5 • SOAP (Simple Object Acces Protocol) • protokol za izmjenu XML poruka koristeći HTTP protokol • WSDL (Web Service Description Language) • temelji se na XML-u • opisuje sučelje usluge Seminar: Programiranje u Javi - Web usluge Dario Vuljanić, 2007.
Tehnologije Web usluga 6 • UDDI (Universal Description, • Discovery and Integration) • protokol koji objavljuje opise web usluga • standardni mehanizam za otkrivanje opisa web usluga Seminar: Programiranje u Javi - Web usluge Dario Vuljanić, 2007.
Način rada Web usluga 7 REGISTAR WEB USLUGA UDDI 2 WSDL 1 WSDL 3 KORISNIK USLUGE PRUŽATELJ USLUGE SOAP Seminar: Programiranje u Javi - Web usluge Dario Vuljanić, 2007.
Apache Axis 8 • okruženje za razvoj SOAP procesora • zadaća: omogućiti SOAP komunikaciju • http://ws.apache.org/axis • alati: • Simple Axis Server • TCP monitor • WSDL podrška • fleksibilan, stabilan, relativno brz Seminar: Programiranje u Javi - Web usluge Dario Vuljanić, 2007.
Usluga MetricConverter 9 • pretvaranje mjernih jedinica • podržane jedinice: • metar (m) • kilometar (km) • jard (yd) • milja (mi) Seminar: Programiranje u Javi - Web usluge Dario Vuljanić, 2007.
MetricConverter.java 10 • publicclass MetricConverter { • public double convertMeterToKilometer (double measure); • public double convertMeterToYard (double measure); • public double convertMeterToMile (double measure); • public double convertKilometerToMeter (double measure); • public double convertKilometerToYard (double measure); • public double convertKilometerToMile (double measure); • public double convertYardToMeter (double measure); • public double convertYardToKilometer (double measure); • public double convertYardToMile (double measure); • public double convertMileToMeter (double measure); • public double convertMileToKilometer (double measure); • public double convertMileToYard (double measure); • } Seminar: Programiranje u Javi - Web usluge Dario Vuljanić, 2007.
MetricConverter - instalacija 11 preimenovanje koda: MetricConverter.java MetricConverter.jws postavljanje na poslužitelj: java org.apache.axis.transport.http.SimpleAxisServer Seminar: Programiranje u Javi - Web usluge Dario Vuljanić, 2007.
MetricConverterClient.java 12 • String url = “http://localhost:8080/MetricConverter.jws”; • String method = “convertMeterToKilometer”; • Service service = new Service(); • Call call = (Call)service.createCall(); • call.setTargetEndpointAddress(new URL(url)); • call.setSOAPActionURI(method); • call.addParameter("measure", Constants.XSD_DOUBLE, ParameterMode.IN); • call.setReturnClass(Double.class); • call.setOperationName(new QName("urn:metricconverter", method)); • output = (Double)call.invoke(new Object[]{new Double(input)}); Seminar: Programiranje u Javi - Web usluge Dario Vuljanić, 2007.
MetricConverter test 13 java MetricConverterClient Seminar: Programiranje u Javi - Web usluge Dario Vuljanić, 2007.
MetricConverter - način rada 14 SOAP zahtjev KLIJENT (MetricConverterClient) POSLUŽITELJ (Simple Axis Server) SOAP odgovor rezultat metode poziv metode USLUGA (MetricConverter) Seminar: Programiranje u Javi - Web usluge Dario Vuljanić, 2007.
Arhitektura SOAP poruke 15 SOAP omotnica SOAP zaglavlje Dijelovi zaglavlja SOAP tijelo Dijelovi tijela (teret) SOAP greška Seminar: Programiranje u Javi - Web usluge Dario Vuljanić, 2007.
SOAP zahtjev 16 • <soapenv:Envelope • xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> • <soapenv:Body> • <ns1:convertMeterToKilometer soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="urn:metricconverter"> • <measure href="#id0"/> • </ns1:convertMeterToKilometer> • <multiRef id="id0" soapenc:root="0" soapenv:encodingStyle=http://schemas.xmlsoap.org/soap/encoding/ • xsi:type="xsd:double" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">123.0 • </multiRef> • </soapenv:Body> • </soapenv:Envelope> Seminar: Programiranje u Javi - Web usluge Dario Vuljanić, 2007.
SOAP odgovor 17 • <soapenv:Envelope • xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> • <soapenv:Body> • <ns1:convertMeterToKilometerResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="urn:metricconverter"> • <convertMeterToKilometerReturn xsi:type="xsd:double">0.123 • </convertMeterToKilometerReturn> • </ns1:convertMeterToKilometerResponse> • </soapenv:Body> • </soapenv:Envelope> Seminar: Programiranje u Javi - Web usluge Dario Vuljanić, 2007.
Apache Tomcat 18 • servlet kontejner • podrška za servlete i JSP • (eng. Java Server Pages) • http://tomcat.apache.org • HTTP poslužitelj za Web usluge • robustan, siguran, podržava višedretvenost Seminar: Programiranje u Javi - Web usluge Dario Vuljanić, 2007.
Usluga BookFinder 19 • pretražuje vlastitu bazu književnih djela • opcije: • pretraživanje po autoru • pretraživanje po djelu publicclass BookFinder { public Vector searchByAuthor (String author); public Vector searchByTitle (String title); } Seminar: Programiranje u Javi - Web usluge Dario Vuljanić, 2007.
Opisnik Web usluge 20 • dokument koji sadrži informacije o usluzi • WSDD • (eng. Web Service Deployment Descriptor) • za rad usluge potreban samo izvršni program (.class) Seminar: Programiranje u Javi - Web usluge Dario Vuljanić, 2007.
BookFinder.wsdd 21 <deployment xmlns=“http://xml.apache.org/axis/wsdd/”xmlns:java=“http://xml.apache.org/ axis/wsdd/providers/java”> <service name=“BookFinder”provider=“java:RPC”> <parameter name=“className” value=“BookFinder”/> <parameter name=“allowedMethods” value=“*”/> </service> </deployment> Seminar: Programiranje u Javi - Web usluge Dario Vuljanić, 2007.
BookFinder - instalacija 22 spremiti BookFinder.class i BookFinder.wsdd u webapps\axis\WEB-INF\classes u tom direktoriju izvršiti naredbu java org.apache.axis.client.AdminClientBookFinder.wsdd Seminar: Programiranje u Javi - Web usluge Dario Vuljanić, 2007.
undeployment.wsdd 23 • dokument za “micanje” usluge • potrebno izvršiti naredbu • java org.apache.axis.client.AdminClientundeployment.wsdd <undeployment xmlns="http://xml.apache.org/axis/wsdd/"> <service name="BookFinder"/> </undeployment> Seminar: Programiranje u Javi - Web usluge Dario Vuljanić, 2007.
BookFinderClient.java 24 • String url = “http://localhost:8080/axis/services/BookFinder”; • String method = “searchByAuthor”; • Service service = new Service(); • Call call = (Call)service.createCall(); • call.setTargetEndpointAddress(new URL(url)); • call.setOperationName(new QName(“BookFinder", method)); • output = (Vector)call.invoke(new Object[]{new String(input)}); Seminar: Programiranje u Javi - Web usluge Dario Vuljanić, 2007.
BookFinder test 25 java BookFinderClient Seminar: Programiranje u Javi - Web usluge Dario Vuljanić, 2007.
BookFinder - način rada 26 SOAP zahtjev KLIJENT (BookFinderClient) POSLUŽITELJ (Apache Tomcat) SOAP odgovor servlet odgovor servlet zahtjev rezultat metode USLUGA (BookFinder) SERVLET (AxisServlet) poziv metode Seminar: Programiranje u Javi - Web usluge Dario Vuljanić, 2007.
Zaključak 27 • Web usluge nas povezuju • Web usluge su dio naše svakodnevnice • Web usluge su praktične • razvoj Java Web usluga je jednostavan • razvoj Java Web usluga je jeftin Seminar: Programiranje u Javi - Web usluge Dario Vuljanić, 2007.
Možete li zamisliti budućnost bez Web usluga?