Download presentation
Presentation is loading. Please wait.
Published byLiliana Hodges Modified over 8 years ago
1
Beginning 자바 웹 서비스 웹 서비스 호출 Meilan JIANG (meelankang@gmail.com)meelankang@gmail.com Cyber infrastructure Research Laboratory Department of Advanced Technology Fusion Konkuk University
2
지난 내용 웹 서비스의 주요 목적 : – 독립성 client ( 요청자 ) 와 server ( 웹 서비스 제공자 ) 웹 서비스 : 애플리케이션 간의 통신을 위한 표 준과 명세서 – 플랫폼, 프로그래밍 언어, 네트워크 프로토콜에 무 관하게 웹 서비스 – 제공되는 인터페이스에 대한 추상화 정의 –Binding 을 위한 프로토콜 정보
3
목차 웹 서비스 호출 모델 – 정적 모델 vs. 동적 모델 XML 기반의 RPC 나 JAX-RPC 를 위한 Java API SOAP 기반이 아닌 웹 서비스
4
웹 서비스 호출 모델 모델 – 정적 모델 Vs. 동적 모델 WSDL 로부터 Java 코드를 생성하는 방법 WSDL 로부터 Java 코드들이 생성되는 시점
5
정적 호출 모델 Step 1 –WSDL 파일의 Element 로부터 Java 인터페이스 생성 Step 2 –WSDL 파일의 Element 로부터 stub 코드 (Java 인터페이스 구현함 ) 생성
6
Client sideWeb Server side Client code compile Using WSDL create stub classes WSDL Web Services run Stub object
7
WSDL 구조 인터페이스 정의 인터페이스 구현 WSDL Document 웹 서비스가 어떤 언어를 말하는가 웹 서비스가 무엇을 하는가 웹 서비스가 어떻게 말을 거는가 웹 서비스를 어디서 찾는가
8
WSDL 인터페이스 구현 <wsdl:operation name=“getQuote” parameterOrder=“in0”> <wsdl:output message=“intf:getQuoteResponse”/> <wsdl:fault message=“intf:Exception” name=“Exception”/> </wsdl:portType
9
WSDL 와 Java Classes = Java 인터페이스 = stub class (Java 인터페이스 구현 ) Application WS Java Interface StockQuote WS Java Stub Class StockQuoteBindingStub getQuote()
10
Stub class StubClass { public method () { call remote real object; } class RealClass { public method () {... real operation } class TestClass { public main () { StubClass stubObj = new StubClass(); stubObj.method() } Real Object Stub Object Main Object
11
WSDL Java 인터페이스 /** * StockQuote.java * * This file was auto-generated from WSDL * by the Apache Axis WSDL2Java emitter. */ package localhost; public interface StockQuote extends java.rmi.Remote { public java.lang.String getQuote(java.lang.String in0) throws java.rmi.RemoteException, localhost.Exception; } getQuoteResponse getQuoteRequest
12
WSDL binding ( 접근 프로토콜 ) SOAP + RPC + HTTP !! format of SOAP body !! <wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost/axis/services/StockQuote" use="encoded"/> <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost/axis/services/StockQuote" use="encoded"/>
13
WSDL 자바 구현 public class StockQuoteSoapBindingStub extends org.apache.axis.client.Stub implements localhost.StockQuote { public java.lang.String getQuote(java.lang.String in0) throws java.rmi.RemoteException, localhost.Exception { if (super.cachedEndpoint == null) { throw new org.apache.axis.NoEndPointException(); } org.apache.axis.client.Call call = createCall();
14
// continued call.addParameter( new javax.xml.namespace.QName("", "in0"), new javax.xml.namespace.QName( "http://..../XMLSchema", "string"), java.lang.String.class, javax.xml.rpc.ParameterMode.IN); call.setReturnType( new javax.xml.namespace.QName( "http://www.w3.org/2001/XMLSchema", "string"),java.lang.String.class);
15
// continued call.setUseSOAPAction(true); call.setSOAPActionURI(""); call.setOperationStyle("rpc"); call.setOperationName( new javax.xml.namespace.QName( "http://localhost:8080/.../StockQuote", "getQuote") ); Object resp = call.invoke(new Object[] {in0});
16
// continued if (resp instanceof java.rmi.RemoteException) { throw (java.rmi.RemoteException)resp; } else { try { return (java.lang.String) resp; } catch (java.lang.Exception exception) { return (java.lang.String) org.apache.axis.utils.JavaUtils.convert( resp, java.lang.String.class); }
17
Client Application Client Application Java Interface Java Interface Client Proxy/Stub Client Proxy/Stub uses implements defined by Web Service SOAP over HTTP described by … … … … WSDL
18
웹 서비스 호출 구현 WSDL 문서 – 웹 서비스와 Client 간의 계약 독립성 –Client 숙지사항 어떻게 구현되었나 ? 어떤 프로그래밍 언어가 사용되었나 ? 어떤 플랫폼에서 제공되나 ?
19
Java 인터페이스와 Java 인터페이스 구현 (class) –WSDL 문서의 와 으로부 터 생성됨 – 서비스에 대한 구체사항은 Client 로부터 숨김 WSDL 문서의 변경사항은 인터페이스와 구현 코드가 재 생성되고 재 컴파일 되어야 함
20
웹 서비스 버전 버전 정보를 제공하지 않는다 WSDL 문서가 변경되었는지 컴파일된 Java Stub 이 여전이 문서에서 기술된 인터 페이스와 일치한가를 확인할 방법이 없다 웹 서비스에 변경이 있다면, Client 호출에 오류가 발생하게 됨
21
웹 서비스 요청 메시지는 버전에 관련된 숫 자나 다른 어떤 것도 포함하고 있지 않다 웹 서비스에 어떤 변화도 서비스의 사용자 에게 혼란을 일으킬 것이다
22
WSDL – Java 코드 - ServiceLocator <wsdl:port binding="intf:StockQuoteSoapBinding “ name="StockQuote"> <wsdlsoap:address location="http://localhost:8080/axis/...StockQuote"/>
23
WSDL - Java code - ServiceLocator /* StockQuoteService.java * This file was auto-generated from WSDL * by the Apache Axis WSDL2Java emitter. */ package localhost; public interface StockQuoteService extends javax.xml.rpc.Service { public String getStockQuoteAddress(); public localhost.StockQuote getStockQuote() throws javax.xml.rpc.ServiceException; public localhost.StockQuote getStockQuote(java.net.URL portAddress) throws javax.xml.rpc.ServiceException; }
24
동적 호출 모델 애플리케이션 간 통신의 자동화 – 애플리케이션들이 서로간의 어떤 자세한 상황 을 모르고도 의사소통 통로를 구축할 수 있다 (beyond the WSDL document describing their web services interface) – 시스템이나 서비스가 바뀌어도, 시스템 사용자 에게 변경 사항을 요구하지 않아도 됨을 의미 한다
25
Server 웹 서비스 Web Services #1 Web Services #1 Development Deployment Client Application Development Web Services Info Client Application Publish Search Communicate Invoke Developer (SOAP) Developer
26
동적 호출 모델 Universal Discovery, Description, and Integration (UDDI) 저장소 – 다양한 WS 이 문서로 표현되는 정보를 담고 있 다 – 저장소를 사용하는 애플리케이션이 동적으로 서비스를 찾고 사용할 수 있게 해준다 – 때문에, 정적인 호출 모델에서와 같이 클라이 언트가 인터페이스, Stub Class 코드를 바꾸지 않고 서비스를 이용하는 방법이 필요하다
27
Web services invoking models – Dynamic(2) Client sideWeb Server side Client code WSDL Web Services Service interface or Call object Read at run-time run compile
28
Client 는 어떤 서비스를 호출할지, 서비스에 대한 WSDL 문서에 정의된 프로토콜 중에 어떤 것을 선택할지에 대한 결정을 할 수 있 어야 한다 WSDL 문서가 변경된다면, Client 는 반드시 코드를 재 컴파일 하지 않고 변경사항을 적 용하여 서비스를 호출할 수 있어야 한다
29
Java 코드 디자인 Use Java code to wrap the invocation of the service on the client So that the client developer need not know or care about how to build requests for different protocols Client developers only needs to care about the functional interface of a service, and not about how it is invoked
30
StockQuote Example StockQuoteClient.class StockQuote.class StockQuoteService.class StockQuoteServiceLocator.class StockQuoteSoapBindingStub.class
31
프로토콜 독립성 WSDL 문서 – 인터페이스 정의 ( ) – 프로토콜 바인딩 ( and ) 목표 – 동적으로 서비스를 사용하는 Java 코드 개발 – 실행시 적절한 요청을 만드는 WSDL 문서를 사 용
32
Example: 위치 독립성 element in element carries information about where the service is located Client should not have any hard-coded dependency on the target URL, rather it should read this address from the WSDL document at run time If the address ever changes, perhaps because the service is moved to a new server, the client code does not have to change
33
인터페이스 독립성 웹 서비스 인터페이스 기술 – element 인터페이스에 변경사항이 발생한다면 –( element) ?
34
JAX-RPC WSDL port-type 정보를 Java 나 다른 것들 로 바꾸는 규칙을 정의한 API 이러한 규칙은 Client 와 서버 쪽 모두에 적 용된다
35
JAX-RPC(1) Define mapping java code with WSDL Define mapping WSDL with java code
36
JAX-RPC(2) Mapping java with WSDL Basic Java types are mapped to basic XML schema types String, Integer, Boolean.. Etc basic type will directly mapping to data type of XML schema Primitive types use Holder classes Like int, short primitive type that Java defines that does not inherit from java.lang.Object for to be handled properly, a so-called Holder class is used that carries the value of the primitive type within a real object.
37
JAX-RPC(3) JavaBean classes are mapped to an XML Schema structure public class Person{ public String firstName; public String lastName; public int age; }
38
JAX-RPC(4) Java artifacts are mapped to the appropriate WSDL artifacts The Java interface must extend java.rmi.Remote and each method must throw a java.rmi.RemoteException WSDL ElementJava class or Interface WSDL Documentpackage inside every elementJava class Java interface Stub class Service interface Service develop (Location) method Java class
39
JAX-RPC(5) Mapping java with WSDL Basic XML Schema types are mapped to basic Java types XML structures and complex types are mapped to a JavaBean Enumerations are turned into public static final attributes (in next page) WSDL artifacts are mapped to the appropriate Java artifacts
40
JAX-RPC(6) … public class MonthType implements Serializable{ String _value; … public static final String _January= “ January ” ; public static final String _February= “ February ” ; … }
41
Service mapping(1) element will define location of web service via eleme nt Using javax.xml.rpc.Service interface to define need class when running client ( using WSDL2java tool to create ) client include method that can invoking web service Means of client invoking web service using Service interface using proxy object : using getPort( ) of Service interface using javax.rmi.rpc.Call object
42
Service mapping(2) Example - Test getPort( ) method 1. run StockQuoteService of Axis 2. download StockQuote.wsdl from web 3. using WSDL2java tool create StubCode 4. using subCode create ClientApplication & compile 5. run the Client download WSDL create stubCode using WSDL2Java if WSDL address was changed need to recompile ClientApp Compare original static & this mixed model using runtime WSDL create stubCode using WSDL2Java if WSDL address was changed doesn’t need to recompile ClientApp originalMixed
43
1. run StockQuoteService of Axis Service mapping(3)
44
2. download StockQuote.wsdl from web Service mapping(4)
45
Service mapping(5) Command: Java org.apache.axis.wsdl.WSDL2Java StockQuote.wsdl 3. using WSDL2java tool create StubCode
46
4. using stubCode create ClientApplication Service mapping(6)
47
5. run the Client Note: Don’t forget import all of libraries in Axis in your classpath Service mapping(7)
48
Service mapping(8) Example - Test createCall ( ) method of StockQuoteService I. run StockQuoteService of Axis II. create ClientApplication & compile III. Run client application using runtime WSDL create stubCode using WSDL2Java Compare original static & this dynamic model using runtime WSDL never create stubCode Mixed Dynamic
49
II. create ClientApplication Service mapping(9)
50
III. Run client Note: Don’t forget import all of libraries in Axis in your classpath Service mapping(10)
51
Practise – complex Type Mapping Type mapping : - In Web Service using xml message exchange - for java application need convert XML constructs into java objects - so need data type mapping registry type of service parameter is complex type and not a simple type (with above examples difference) steps modify WSDL document start web service(tomcat) using WSDD document upload changed service to web server get WSDL document from web server using WSDL2java tool create stub codes create client application compile and run (without first step there is no change, using “stockquote_complextype_document.wsdl” in practice source to practise)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.