spring and pojo-based remote services

57
Spring In Action 2nd Spring and POJO-based remote services 백백백 [email protected] http:// whiteship.tistory.com www.springframework.co.kr

Upload: sema

Post on 12-Jan-2016

69 views

Category:

Documents


0 download

DESCRIPTION

Spring and POJO-based remote services. 백기선 [email protected] http://whiteship.tistory.com. 차례. Spring Remoting 개요 RMI 사용하기 Hessian 과 Burlap 사용하기 Http Invoker 사용하기 웹 서비스 사용하기 정리. Spring Remoting 개요. Remoting. 클라이언트 애플리케이션과 원격에 위치한 서버가 제공하는 서비스의 동기적인 의사소통. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Spring and POJO-based remote services

Spring In Action 2nd

Spring and POJO-based remote services

백기선[email protected]://whiteship.tistory.com

www.springframework.co.kr

Page 2: Spring and POJO-based remote services

Spring In Action 2nd

차례

• Spring Remoting 개요• RMI 사용하기• Hessian 과 Burlap 사용하기• Http Invoker 사용하기• 웹 서비스 사용하기• 정리

www.springframework.co.kr

Page 3: Spring and POJO-based remote services

Spring In Action 2nd

www.springframework.co.kr

Spring Remoting 개요

Page 4: Spring and POJO-based remote services

Spring In Action 2nd

Remoting

• 클라이언트 애플리케이션과 원격에 위치한 서버가 제공하는 서비스의 동기적인 의사소통 .

www.springframework.co.kr

Page 5: Spring and POJO-based remote services

Spring In Action 2nd

Remote Procedure Call 모델

• Remote Method Invocation(RMI)• Caucho’s Hessian and Burlap• 스프링의 Http invoker• Web services using SOAP and JAX-

RPC

• 뭐가 이렇게 많을까요 ?

www.springframework.co.kr

Page 6: Spring and POJO-based remote services

Spring In Action 2nd

RPC 모델들의 특징

www.springframework.co.kr

사용 가능한 플랫폼은 ?사용하는 프로토콜은 ?

Page 7: Spring and POJO-based remote services

Spring In Action 2nd

스프링이 해주는 일

• 서버의 POJO 자신이 클라이언트에게 원격으로 제공된다는 사실을 몰라도 됩니다 .– 오직 설정을 통해서 처리합니다 .– Non-invasion

• 클라이언트는 마치 OJO 를 사용하듯이 서비스를 사용할 수 있습니다 .– Proxy 사용 .

• 클라이언트의 호출에 대한 응답으로 예외가 발생하면 unchecked exception 으로 변환해 줍니다 .– 예외 처리를 강제하지 않습니다 .– 스프링은 Unchecked Exception 을 좋아합니다 .

www.springframework.co.kr

Page 8: Spring and POJO-based remote services

Spring In Action 2nd

어떻게 그런 일을…RemoteExporter 가 있거든요 .

www.springframework.co.kr

Page 9: Spring and POJO-based remote services

Spring In Action 2nd

www.springframework.co.kr

RMI 사용하기

Page 10: Spring and POJO-based remote services

Spring In Action 2nd

RMI

• JDK 1.1 부터 사용할 수 있게 됐습니다 .

• 그전에는 CORBA 를 사용하거나 직접 소켓 프로그래밍을 해야 했습니다 .

• 그러나 사용하기가 좀 복잡합니다 .

www.springframework.co.kr

Page 11: Spring and POJO-based remote services

Spring In Action 2nd

지금부터 이런 순서대로 살펴보겠습니다 .

• 서비스를 사용하는 쪽– 스프링의 도움 없이 RMI 를 사용할 때 .– 스프링이 도와줄 때 .

• 서비스를 제공하는 쪽– 스프링의 도움 없이 서비스를 RMI 로 제공할

때 .– 스프링이 도와줄 때 .

www.springframework.co.kr

Page 12: Spring and POJO-based remote services

Spring In Action 2nd

서비스를 사용하는 쪽-스프링의 도움 없이 RMI를 사용할 때 -

• 반드시 잡거나 던져야 하는 예외가 발생합니다 .

• CitationService 가 필요한 모든 클래스에 위의 코드 중복이 발생합니다 .

www.springframework.co.kr

Page 13: Spring and POJO-based remote services

Spring In Action 2nd

서비스를 사용하는 쪽-스프링이 도와줄 때 -

• 예외를 잡지 않아도 됩니다 .• CitationService 를 가져오는 코드를

직접 작성하지 않아도 됩니다 .

www.springframework.co.kr

Page 14: Spring and POJO-based remote services

Spring In Action 2nd

RmiProxyFactoryBean

www.springframework.co.kr

Page 15: Spring and POJO-based remote services

Spring In Action 2nd

서비스를 사용하는 쪽

• 그냥 POJO 주입 하듯이…

www.springframework.co.kr

Page 16: Spring and POJO-based remote services

Spring In Action 2nd

서비스를 제공하는 쪽- 스프링의 도움 없이 서비스를 RMI로 제공할 때 -

1. 서비스 구현체의 메소드 구현할 때 RemoteException 던지도록 선언하기 .

2. 서비스 인터페이스에 extends Remote 추가하기 .

3. RMI 컴파일러 실행하여 stub 과 skeleton 생성하기 .

4. 서비스 호스팅을 위해 RMI 레지스트리 시작하기 .

5. RMI 레지스트리에 서비스 등록하기 .

www.springframework.co.kr

Page 17: Spring and POJO-based remote services

Spring In Action 2nd

서비스를 제공하는 쪽-스프링이 도와줄 때 -

• 서비스 인터페이스가 Remote 인터페이스 구현할 필요 없음 .

• 서비스 구현체의 메소드에서 RemoteException 을 던질 필요 없음 .

• 앗 !! 그럼 그냥 POJO 자나 ? BINGO• RMI 레지스트리 시작과 등록은

누가해주지 ? RmiServiceExporter

www.springframework.co.kr

Page 18: Spring and POJO-based remote services

Spring In Action 2nd

RmiServiceExporter 가 하는 일

• 스프링 컨테이너에 들어있는 특정 bean 을 RMI 서비스로 공개시켜줍니다 .

• 레지스트리에 해당 서비스를 등록해 줍니다 .

• 만약 설정한 포트에 레지스트리 서비스가 없다면 새로 생성해 줍니다 .

www.springframework.co.kr

Page 19: Spring and POJO-based remote services

Spring In Action 2nd

RmiServiceExporter 사용 법

www.springframework.co.kr

Page 20: Spring and POJO-based remote services

Spring In Action 2nd

RMI + Spring 예제

• 메아리 서비스 .• 입력 받은 메시지를 다섯 번 반복한

메아리를 돌려줍니다 .

• Src/chapter8/client/Keesun.java• Src/chapter8/server/

EchoServiceImpl.java• Test/chapter8/

EchoServiceServer.javawww.springframework.co.kr

Page 21: Spring and POJO-based remote services

Spring In Action 2nd

퀴즈다음은 누구 ( 사용자 , 제공자 ) 를 위한 작업 일까요 ?

• RMI 서비스를 간단하게 스프링의 bean 으로 등록할 수 있도록 합니다 .– Proxy Factory Bean 제공 .

• 스프링이 관리하는 bean 을 RMI 서비스로 변환해줍니다 .– Remote Exporter

www.springframework.co.kr

Page 22: Spring and POJO-based remote services

Spring In Action 2nd

RMI 를 사용한 RPC 정리

• RMI 는 방화벽을 넘어야 합니다 .– 별도의 포트를 사용해야 하기 때문에…

• 자바 기반입니다 .– 클라이언트와 서버가 모두 반드시 자바로

작성되어야 합니다 .– 직렬화 Serialization 를 사용하기 때문에…

www.springframework.co.kr

Page 23: Spring and POJO-based remote services

Spring In Action 2nd

www.springframework.co.kr

Hessian 과 Burlap 사용하기

Page 24: Spring and POJO-based remote services

Spring In Action 2nd

Hessian and Burlap

• Caucho Technology(www.caucho.com)• Lightweight remote service over HTTP

– 84KB– No External Dependencies

• Hessian– 바이너리 메시지 사용 .– 자바 뿐만 아니라 다른 언어에서도 사용 가능 .

• Burlap– XML 기반 리모팅 기술 .– XML 을 파싱 할 수 있는 모든 언어에서 사용 가능 .

www.springframework.co.kr

Page 25: Spring and POJO-based remote services

Spring In Action 2nd

Hessian/Burlap 으로 서비스 제공하기 . (1)

• HessianServiceExporter 사용하기 .– RmiServiceExporter 와 동일한 일을

해줍니다 .– 단 , 이 녀석은 Spring MVC 컨트롤러 입니

다 .

www.springframework.co.kr

Page 26: Spring and POJO-based remote services

Spring In Action 2nd

퀴즈 2

1. RmiServiceExporter 가 해주는 일은 ?( 구체적으로… )

www.springframework.co.kr

Page 27: Spring and POJO-based remote services

Spring In Action 2nd

Hessian/Burlap 으로 서비스 제공하기 . (2)

• HessianServiceExporter 등록하기 .

• URL 핸들러 맵핑을 등록해야 합니다 .

www.springframework.co.kr

Page 28: Spring and POJO-based remote services

Spring In Action 2nd

Hessian/Burlap 으로 서비스 제공하기 . (3)

• Web.xml 에 Dispatcher Servlet 등록하기

www.springframework.co.kr

Page 29: Spring and POJO-based remote services

Spring In Action 2nd

Hessian/Burlap 이 제공하는 서비스 사용하기 . (1)

• Bean 설정만 바뀝니다 .– 사용할 ProxyFactoryBean 변경 .

www.springframework.co.kr

Page 30: Spring and POJO-based remote services

Spring In Action 2nd

Hessian/Burlap 이 제공하는 서비스 사용하기 . (2)

• HessianProxyFactoryBean 설정하기

www.springframework.co.kr

Page 31: Spring and POJO-based remote services

Spring In Action 2nd

퀴즈 3

• RmiProxyFactoryBean 또는 HessianProxyFactoryBean 을 사용하면 좋은 점은 ?

• ( 오늘 “ Spring 을 사용한 Remoting”을 들으러 오신 이유입니다 .)

www.springframework.co.kr

Page 32: Spring and POJO-based remote services

Spring In Action 2nd

Hessian/Burlap 을 사용한 RPC 정리

• HTTP 를 사용하기 때문에 , 방화벽 걱정을 하지 않아도 됩니다 .

• 별도의 직렬화 방법을 사용하기 때문에 , Complex 타입의 자바 객체가 전달되면 깨집니다 .– RMI 는 자바의 직렬화를 사용하기 때문에 ,

그럴 걱정이 없지만 말이죠 .

www.springframework.co.kr

Page 33: Spring and POJO-based remote services

Spring In Action 2nd

www.springframework.co.kr

Http Invoker 사용하기

Page 34: Spring and POJO-based remote services

Spring In Action 2nd

Http Invoker

• 스프링 프레임워크에서 구현한 RPC.

• Java 의 표준 직렬화 사용 .– RMI 의 특징 .

• Http 사용 .– Hessian/Burlap 의 특징 .

www.springframework.co.kr

Page 35: Spring and POJO-based remote services

Spring In Action 2nd

Http Invoker 를 사용하여서비스 제공하기 (1)

• HttpInvokerServiceExporter 사용합니다 .

• HessianServiceExporter 와 동일합니다 .– 컨트롤러 입니다 .

www.springframework.co.kr

Page 36: Spring and POJO-based remote services

Spring In Action 2nd

Http Invoker 를 사용하여서비스 제공하기 (2)

• HttpInvokerServiceExporter 등록하기

• URL 핸들러 맵핍 등록하기

www.springframework.co.kr

Page 37: Spring and POJO-based remote services

Spring In Action 2nd

Http Invoker 를 사용하여서비스 제공하기 (3)

• Web.xml 에 Dispatcher Servlet 등록하기

www.springframework.co.kr

Page 38: Spring and POJO-based remote services

Spring In Action 2nd

Http Invoker 이 제공하는서비스 사용하기 (1)

• HttpInvokerProxyFactoryBean 을 사용합니다 .– HessianProxyFactoryBean 과 동일합니다 .

www.springframework.co.kr

Page 39: Spring and POJO-based remote services

Spring In Action 2nd

Http Invoker 이 제공하는서비스 사용하기 (2)

• HttpInvokerFactoryBean 등록하기

www.springframework.co.kr

Page 40: Spring and POJO-based remote services

Spring In Action 2nd

Http Invoker 사용한 RPC 정리

• 유일한 단점은 클라이언트와 서버 모두 스프링을 사용해야 합니다 .– 즉 자바 기반에서만 동작합니다 .

• 자바의 표준 직렬화 방식을 사용합니다 .

www.springframework.co.kr

Page 41: Spring and POJO-based remote services

Spring In Action 2nd

www.springframework.co.kr

웹 서비스 사용하기

Page 42: Spring and POJO-based remote services

Spring In Action 2nd

SOA

• 근래에 가장 떠들썩한 TLA(three-letter acronyms)

• 모든 애플리케이션에서 동일한 기능을 제각각 작성하지 않도록 서비스로 제공해야 한다는 것이 골자 .

www.springframework.co.kr

Page 43: Spring and POJO-based remote services

Spring In Action 2nd

웹 서비스로 제공하기 위해스프링이 해주는 일

• 없습니다 .– 전혀 ~– 아무것도 ~– 왜 ..

• XFire 가 해줍니다 .– POJO 를 웹 서비스로 제공해줍니다 .

www.springframework.co.kr

Page 44: Spring and POJO-based remote services

Spring In Action 2nd

XFire 로 POJO 를웹 서비스로 제공하기 (1)

• 앞서 살펴봤었던 , HessianServiceExporter, HttpInvokerServiceExporter 와 동일합니다 .– 컨트롤러입니다 .

• XFireExporter 를 사용합니다 .

www.springframework.co.kr

Page 45: Spring and POJO-based remote services

Spring In Action 2nd

XFire 로 POJO 를웹 서비스로 제공하기 (2)

• XFireExporter 등록하기

• <import> 엘리먼트로 필요한 bean 설정 포함시키기

www.springframework.co.kr

Page 46: Spring and POJO-based remote services

Spring In Action 2nd

XFire 로 POJO 를웹 서비스로 제공하기 (3)

• URL 핸들러 맵핑 등록하기– 생략…

• Web.xml 에 Dispatcher Servlet 등록하기– 생략…

www.springframework.co.kr

Page 47: Spring and POJO-based remote services

Spring In Action 2nd

XFire 로 POJO 를웹 서비스로 제공하기 (4)

• 애노테이션을 사용하여 웹 서비스로 설정하기 .– JSR-181 Web Services Metadata for the

Java Platform– xfire-jaxws 종속성 필요함 .

• JSR 181 핸들러 맵핑 등록하기 .– 애노테이션 메타데이터를 읽는 핸들러 .

www.springframework.co.kr

Page 48: Spring and POJO-based remote services

Spring In Action 2nd

JSR-181 애노테이션으로웹 서비스 제공하기 (1)

• 제공하려는 서비스마다 XML 덩어리가 하나씩 필요합니다 .

• “ 애노테이션 핸들러 맵핑” 빈을 등록해두면 , 애노테이션으로 웹 서비스를 설정할 수 있습니다 .

www.springframework.co.kr

Page 49: Spring and POJO-based remote services

Spring In Action 2nd

JSR-181 애노테이션으로웹 서비스 제공하기 (2)

www.springframework.co.kr

Page 50: Spring and POJO-based remote services

Spring In Action 2nd

JSR-181 애노테이션으로웹 서비스 제공하기 (3)

• 애노테이션을 POJO 에 붙여주기 .

www.springframework.co.kr

Page 51: Spring and POJO-based remote services

Spring In Action 2nd

JSR-181 애노테이션으로웹 서비스 제공하기 (4)

• 애노테이션 핸들러 맵핑 등록하기 .

www.springframework.co.kr

Page 52: Spring and POJO-based remote services

Spring In Action 2nd

웹 서비스 사용하기 (1)

• 스프링이 제공하는 구현체 사용하는 방법– JaxRpcPortProxyFactoryBean– 설정 해야 하는 속성이 비교적 많음 .

• XFire 가 제공하는 구현체 사용하는 방법– XFireClientFactoryBean– 설정이 매우 간단함 .

www.springframework.co.kr

Page 53: Spring and POJO-based remote services

Spring In Action 2nd

퀴즈 4

• 둘 중에 무엇을 사용하고 싶으세요 ?

www.springframework.co.kr

Page 54: Spring and POJO-based remote services

Spring In Action 2nd

웹 서비스 사용하기 (2)

• XFireClientFactoryBean 등록하기 .

www.springframework.co.kr

Page 55: Spring and POJO-based remote services

Spring In Action 2nd

Live Coding(HttpInvoker 사용하기 .)

www.springframework.co.kr

Page 56: Spring and POJO-based remote services

Spring In Action 2nd

www.springframework.co.kr

정리

Page 57: Spring and POJO-based remote services

Spring In Action 2nd

Summary

• 어떤 종류의 Remote 서비스를 사용하던지 관계없이 Proxy Factory Bean 을 제공해 줍니다 .– Client 에서 Remote 서비스에 종속성이

발생하지 않습니다 .– Remote Exception 을 Uncatched

Exception 으로 변환해 줍니다 .

• 로컬 서비스보다 성능이 떨어집니다 .• SOA 맛보기에 해당합니다 .

www.springframework.co.kr