정기교육_개발가이드_20140217

Download Report

Transcript 정기교육_개발가이드_20140217

Morpheus Server 2.0 정기교육
Version 1.0
2014.02.19
목차
Morpheus Server 2.0
SpringFramework
API 개발
Morpheus Admin
실습
About Morpheus Server2.0
System Configuration for Mobile System
4/40
Morpheus Structure
Morpheus Client
Runtime
User Interface
HTML(5)
JavaScript
Morpheus Adapter Set
Morpheus Server
Image
CSS
Native Framework
DB Manager
Authentication
Morpheus Store
User Web
Mobile Web
Morpheus PUSH
Core Library
PUBLIC
EXT Library
Wizard
Store
Admin
Security
EXT3 EXT2 EXT1
Morpheus
IDE
PUSH
Admin
Mobile
System
Web-Native Interface 1.0
Mobile
Admin
Morpheus Legacy
Adapter set
Web-Native
Interface 2.0
Execute Config.
Morpheus 통합 Admin
Editor
PRIVATE
Browser
Emulator
5/40
MQTT
Version
Debugger
다양한 형태로 변형된 시스템
즉시 연동할 수 있는 Knowhow 보유 필요
Morpheus Server-Client API Protocol
Morpheus Server
Morpheus Mobile
User Interface
Local Resource
HTML
CSS
Image
iOS
framework
iOS
Phone
Control & Service Layer
App 실행 시
JS
Resource download
Resource Integration Manager
리소스
Android
framework
iOS
Tablet
Android
Phone
Android
Tablet
통신
HTTP(JSON)
Resource Deploy Management
배포용 리소스 압축파일 관리
(zip 일괄/분할 압축 방식 제공)
Resource Security Management
리소스 파일 암복호화 관리
(AES128bit 암호화 및 MD5 적용)
Resource download Management
클라이언트 리소스 다운로드 관리
(일괄, 분할 다운로드 서비스)
Resource file Management
Morpheus PC Client
HTML
User Interface
Biz Layer
Resource 요청 시
Remote Resource
HTML
CSS
Image
JS
CSS
업무 로직 및 전문
Resource download
Images
Common Layer Framework
PC Web framework
Safari
Chrome
통합 리소스 파일 관리
WAS
Firefox
6/40
WEB
JavaScript
Morpheus Server System Architecture
7/40
Software Configuration
8/40
Software Requirement
구분
System S/W
구성요소
OS
제품내역
Server
Linux, Unix, Windows 계열 OS
Network
TCP/IP
DBMS
Oracle, MSSQL, MySQL
WAS
Weblogic, JEUS, Tomcat, JBOSS(most overall
WAS 지원)
Web Server
WebtoB, Apache, IIS (most overall Web
Server 지원)
Application S/W
개발 환경
Server
JDK SE 1.6 권장 (JDK 1.5 이상 지원)
Spring 3.1.2 Version, Mybatis 3.2.2 Version
Oracle
개발 환경
Client
JDK SE 1.6 권장 (JDK 1.5 이상 지원), Eclipse
Helios 이상 권장
9/40
Morpheus Mobile Project Process
10/40
About SpringFramework
(Spring MVC)
About SpringFramework
스프링의 탄생
Rod Johnson : Expert One-on-One J2EE Development without EJB
EJB를 사용하지 않고 엔터프라이즈 어플리케이션을 개발하는 방법소
개
Spring is a lightweight dependency injection and
aspect-oriented
container and framework.
- 매우 가벼운 프레임워크로 엔터프라이즈 서비스를 쉽게 구축
- 의존성 주입(Dependency Injection)을 통한 유연한 (느슨한 결합)
- 관점지향 프로그래밍(Aspect oriented Programming) 지원
- 평범한 자바빈으로(POJO) 프로그래밍 모델 가능
- 다양한 API, 프레임워크와의 연동을 지원함
- 반복적인 코드의 제거, 생산성 향상
12/40
About SpringFramework
13/40
About SpringFramework
- DispatcherServlet
14/40
SpringFramework
- DispatcherServlet
15/40
Morpheus를 구성하는 SpringFramework 기술
<mvc:annotation-driven />
- HandlerMapping : DefaultAnnotationHandlerMapping
- Adapter : AnnotationMethodHandlerAdapter
- ViewResolver :
1. BeanNameViewResolver
<beans:bean class="org.springframework.web.servlet.view.BeanNameViewResolver" p:order="1"/>
2. VelocityLayoutViewResolver
<beans:bean id="viewResolver" class="kr.morpheus.ui.velocity.VelocityLayoutViewResolver">
- View : MappingJacksonJsonView, FileView
<beans:bean id="defaultJsonView" class="kr.morpheus.base.dto.DefaultJsonView"/>
<beans:bean id=“fileView" class="kr.morpheus.download.view.FileView”/>
- PropertyConfigure : apache CommonsConfiguration
16/40
MorpheusServer를 이용한
API 개발
개발환경
Check Point!!
1. Java version / Dynamic WebProject 개발환경
2. Site URL 정책에 의한 Servlet mapping(web.xml)
3. License 체크(개발용 라이선스 발급적용)
4. Datasource 체크 (Connection Pool 설정)
5. 환경설정(morpheus.xml)
6. API 정의
7. 개발 및 테스트
18/40
Morpheus Directory Structure
19/40
환경설정(root-context.xml)
20/40
환경설정(config/morpheus.xml)
21/40
환경설정(mybatis-context.xml)
22/40
환경설정(morpheus-context.xml)
23/40
Sample Controller
24/40
API 서비스 개발
Spring MVC를 기본 구조로 함.
1. Controller 생성
구성요소
설명
@Controller
Controller 클래스를 정의
@Autowired
의존관계를 자동으로 설정한다.
@RequestMapping
웹 요청에 대한 메소드 매핑 Annotation
@RequestParam
웹 요청의 파라미터와 메소드 파라미터간의 매핑 Annotation
@PathVariable
메소드에 매개 변수 주석을 사용하여 URI 변수의 값에 바인딩 한다.
@ResponseBody
메소드에서 리턴되는 값을 view가 아닌 HTTP Response Body 에 직접
쓰여진다.
@RequestBody
HTTP Request Body를 핸츨러 메소드에서 직업 사용 가능
25/40
API 서비스 개발
SampleController 소스
public class SampleController {
//어노테이션으로 SampleService 클래스를 주입받는다.
@Autowired(required=true)
private SampleService sampleService;
@SuppressWarnings("unchecked")
@ResponseBody
@RequestMapping(method=RequestMethod.POST, value="/api/sample/{id}")
public String get(HttpServletRequest request, HttpServletResponse response,
@PathVariable String id , @RequestBody String body)
throws Exception {
// JSON 문자열을 Map or List Object 로 변환
body = URLDecoder.decode(body, "UTF-8");
ObjectMapper om = new ObjectMapper();
Map<String, Object> requestMap =
om.readValue(body, new TypeReference<Map<String, Object>>(){});
//비지니스 로직 실행
requestMap =
(Map<String, Object>) sampleService.getCompanySample( requestMap , id );
//Map Object를 JSON 문자열로 변환
ObjectMapper mapper = new ObjectMapper();
String data = mapper.writeValueAsString(requestMap);
return data;
}
}
26/40
API 서비스 개발
SampleController 소스
@Controller
public class SampleController {
//어노테이션으로 SampleService 클래스를 주입받는다.
@Autowired(required=true)
private SampleService sampleService;
@RequestMapping(method=RequestMethod.POST, value="/api/sample")
public ModelAndView sampleApi(HttpServletRequest request, HttpServletResponse
response) throws Exception {
MobileMap requestMap = new MobileMap(request, response);
MobileMap responseMap = new MobileMap();//new MobileMap(request, response);
responseMap.setHeadMap(requestMap.getHeadMap());
//비지니스 로직 실행
Map<String, Object> map = (Map<String, Object>)sampleService.getCompanyList();
responseMap.setBodyMap(map);
return new ModelAndView(“defaultJsonView”,responseMap);
}
27/40
API 서비스 개발
Service 생성
//어노테이션으로 SampleSession bean 등록
@Service
public class SampleService {
//어노테이션으로 SqlSession을 주입받는다.
@Autowired(required=true)
private SqlSessionTemplate sqlSession;
public Object getCompanySample( Map<String, Object> requestMap , String id ){
//HEAD 와 BODY 를 담은 MAP Object
Map<String, Object> responseMap = new HashMap<String, Object>();
//HEAD 정보가 담길 MAP Object
@SuppressWarnings("unchecked")
Map<String, Object> responseHeadMap = (Map<String, Object>) requestMap.get("head");
//BODY 정보가 담길 MAP Object
Map<String, Object> responseBodyMap = new HashMap<String, Object>();
SampleDto sampleDto = new SampleDto();
sampleDto.setCID(id);
//Mapper class 생성
//DB에서 정보를 조회 한다.
SampleMapper sampleMapper = sqlSession.getMapper(SampleMapper.class);
sampleDto = sampleMapper.getCompanySample(sampleDto);
//조회 결과를 BODY MAP에 담는다.
responseBodyMap.put("CID", sampleDto.getCID());
responseBodyMap.put("DEPT", sampleDto.getDEPT());
responseBodyMap.put("USER_NAME", sampleDto.getUSER_NAME());
responseBodyMap.put("COMPANY", sampleDto.getCOMPANY());
responseMap.put( "head", responseHeadMap );
responseMap.put( "body", responseBodyMap );
return responseMap;
}
}
28/40
API 서비스 개발
Mapper Interface 생성
public interface SampleMapper {
//Mybatis의 select문 id와 메소드명을 동일하게 작업
SampleDto getCompanySample(SampleDto sampleDto);
}
Domain class 생성
public class SampleDto
private String
private String
private String
private String
{
cid;
dept;
userName;
company;
public String getCid() {
return cid;
}
public void setCid(String cid) {
cid = cid;
}
public String getDept() {
return dept;
}
public void setDept(String dept) {
dept = dept;
}
… 중략 ..
}
29/40
API 서비스 개발
MyBatis mapper xml 생성
<!-- 맵핑될 Mapper 클래스 경로 입력-->
<mapper namespace="kr.morpheus.sample.mapper.SampleMapper">
<select id="getCompanySample"
parameterType="kr.morpheus.sample.dto.SampleDto"
resultType="kr.morpheus.sample.dto.SampleDto">
SELECT CID
, DEPT
, USER_NAME
, COMPANY
FROM SAMPLE
WHRER CID = CID
</select>
</mapper>
30/40
API 규격
- HTTP Request Header
헤더명
값 범위
Accept
application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8,application/json,text/html
기본값
필수
application/json
Y
설명
요청 데이터 유형
- HTTP Request Body
JSON 키
head
필수
JSON
기본값
값 범위
여부
설명
app_version
””
Y
단말의 해당 application 버전
app_name
””
Y
단말의 해당 application 이름
system_version
””
Y
단말 OS 버전
system_name
””
Y
단말의 시스템 OS 명
device_id
””
Y
단말 고유 식별 번호
device_md
””
Y
단말 모델명 (SHW-M110S)
phone_no
””
단말 전화번호(아이폰은 지원하지 않으나 디폴드값 Empty 값으로 고정)
callback_function
””
HTTP 응답 수신후 Native 에서 호출할 함수명
callback_request_data_flag
y/n
n
Y
전문 요청 데이터를 응답 데이터에 포함시켜 수신할지에 대한 여부
screen_id
””
appid
””
user_id
””
사용자 아이디(G/W 서버 1.3 버젼 이상 반영됨)/ 통계 정보를 조회하기 위해서는 필수 입력
항목이다.
user_name
””
사용자 이름(G/W 서버 1.3 버젼 이상 반영됨)/ 통계 정보를 조회하기 위해서는 필수 입력
항목이다.
page_name
””
리소스 파일명(G/W 서버 1.3 버젼 이상 반영됨)
packet_seq
””
화면 UI 동기화 처리를 위한 패킷 순번(G/W 서버 1.3 버젼 이상 반영됨)
body 사용자 정의 부분
화면 아이디
Y
모바일 앱 아이디(G/W 서버 1.1.2 버젼 이상 반영됨)
각 업무별 필요한 데이터를 정의하여 사용한다.
31/40
API 규격
- HTTP Response Header
- HTTP Response Body
SON 키 JSON 키
head
body
JSON 값 범위 기본값 필수여부 설명
result_code
””
Y
G/W 시스템과의 전문 응답 결과 코드
result_msg
””
Y
G/W 시스템과의 전문 응답 결과 메시지
callback_function
””
HTTP 응답 수신후 Native 에서 호출할 함수명
screen_id
””
화면 아이디(API 호출되는 화면 ID)
packet_seq
””
화면 UI 동기화 처리를 위한 패킷 순번(G/W 서버 1.3 버젼 이상 반영됨)
사용자 정의
””
각 업무별 필요한 데이터를 정의하여 사용한다.
32/40
Morpheus Server-Client 통신
Morpheus Server
Morpheus Client
Morpheus Admin
1 리소스 등록
2 리소스 배포
3 Auto-Update
4
Response
1. 리소스 목록
2. 앱 업데이트 정보
3. 공지사항
5 리소스 다운로드 및 설치
다운로드 이력 추가
6 App 실행 및 업데이트 확인
7 App 실행 후 사용자 인증
8 인증 결과 응답
33/40
Auth System
Legacy / DB
API Sample
Sample API
리소스 업데이트 : http://localhost:8080/gw/api/res/auto-update)
HTTP RequestHeader
Accept : application/json
HTTP RequestBody
{"head":{"callback_function":"","screen_id":"MENU_ID_001","phone_no":"010-12345678","system_name":"Android","alert_flag":"Y","device_md":"SHWM110S","app_version":"1.0.0.0","device_id":"123456789","app_name":"Morpheus
App","callback_request_data_flag":"N","system_version":"2.3","appid":"kr.co.morpheus.mobile1"},
"body":{"deploy":"0","version":"000000","rsp":"F774E0BC79910F41DA3E00AFD3C25FC3B457CE73F8DC
D6EC4D2C39D1FA622DAC7B8E4C52F9B477E759343F07969BFE1D"}}
34/40
API Sample
Sample API
- HTTP Response Body (JSON Format)
JSON Key
head
Type
필수
result_code
String
M
처리 응답 결과 코드
result_msg
String
O
처리 응답 결과 메시지
url
String
M
라이선스 정보
md5
String
M
다운로드 배포 파일의 MD5 문자열
String
M
버전별 배포 파일의 전체 크기
files
total_file_size
설명
삭제된 리소스 파일명
update_files
remove_files
String
M
예: www/html/sample.html
(res 폴더 하위 폴더부터 시작)
배포유형 (1, 0)
body
version
String
M
0 = 개발
1 = 운영
app_version_info
notice
download_market_url
String
M
앱 다운로드 주소
required_app_version
String
M
필수 앱 버전
current_app_version
String
M
현재 앱 버전
title
String
M
공지사항 제목
contents
String
M
공지사항 내용
35/40
API Test
1. RestClient
https://code.google.com/p/rest-client/
36/40
API Test
2. Postman RestClient
https://chrome.google.com/webstore/detail/postman-restclient/fdmmgilgnpjigdojojpjoooidkmcomcm
37/40
감사합니다.
38/40