DataAPI refactoring

This commit is contained in:
KNKIM 2021-12-17 10:41:29 +09:00
parent 04ff068df9
commit fcc8b1135e
44 changed files with 467 additions and 804 deletions

View File

@ -5,8 +5,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import nlib.restful.service.DataApiReqVO;
import nlib.restful.service.DataApiResVO;
import nlib.restful.DataApiReqVO;
import nlib.restful.DataApiResVO;
import nlib.user.service.NlibLoginVO;
public interface BoardService

View File

@ -1,8 +1,8 @@
package nlib.bbs.service;
import nlib.restful.service.DataApiReqVO;
import nlib.restful.service.DataApiResVO;
import nlib.restful.DataApiReqVO;
import nlib.restful.DataApiResVO;
/**
* <pre>

View File

@ -5,8 +5,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import nlib.restful.service.DataApiReqVO;
import nlib.restful.service.DataApiResVO;
import nlib.restful.DataApiReqVO;
import nlib.restful.DataApiResVO;
import nlib.user.service.NlibLoginVO;
import nlib.util.StringUtil;

View File

@ -9,7 +9,7 @@ import org.springframework.stereotype.Repository;
import egovframework.com.cmm.service.impl.EgovComAbstractDAO;
import egovframework.rte.psl.dataaccess.mapper.Mapper;
import nlib.cmm.service.NotificationVO;
import nlib.restful.service.DataApiReqVO;
import nlib.restful.DataApiReqVO;
import nlib.bbs.service.ArticleVO;
import nlib.bbs.service.AttachFileVO;
import nlib.cmm.service.NlibProperty;

View File

@ -7,8 +7,8 @@ import org.springframework.stereotype.Repository;
import nlib.cmm.web.MainController;
import nlib.restful.DataApi;
import nlib.restful.service.DataApiReqVO;
import nlib.restful.service.DataApiResVO;
import nlib.restful.DataApiReqVO;
import nlib.restful.DataApiResVO;
@Repository("boardDAO")
public class BoardDAOApi extends DataApi

View File

@ -8,8 +8,8 @@ import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import nlib.bbs.service.BoardServiceApi;
import nlib.restful.service.DataApiReqVO;
import nlib.restful.service.DataApiResVO;
import nlib.restful.DataApiReqVO;
import nlib.restful.DataApiResVO;
@Service("boardService")
public class BoardServiceImplApi implements BoardServiceApi

View File

@ -2,7 +2,7 @@ package nlib.bbs.service.impl;
import egovframework.rte.psl.dataaccess.mapper.Mapper;
import nlib.bbs.service.ArticleVO;
import nlib.restful.service.DataApiReqVO;
import nlib.restful.DataApiReqVO;
@Mapper("qnaDAO")
public interface QnaDAO extends BoardDAO {

View File

@ -32,8 +32,8 @@ import nlib.cmm.service.CodeService;
import nlib.cmm.service.NlibProperty;
import nlib.cmm.service.NotificationVO;
import nlib.cmm.service.PagingVO;
import nlib.restful.service.DataApiReqVO;
import nlib.restful.service.DataApiResVO;
import nlib.restful.DataApiReqVO;
import nlib.restful.DataApiResVO;
import nlib.user.service.NlibLoginVO;
import nlib.util.StringUtil;

View File

@ -24,7 +24,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import nlib.cmm.exception.ErrorMessage;
import nlib.restful.service.DataApiResVO;
import nlib.restful.DataApiResVO;
import nlib.security.SecUserVO;
import nlib.user.service.LoginService;
import nlib.user.service.NlibLoginVO;

View File

@ -26,8 +26,8 @@ import nlib.cmm.service.NotificationService;
import nlib.cmm.service.NotificationVO;
import nlib.cmm.service.PagingVO;
import nlib.cmm.service.NlibProperty;
import nlib.restful.service.DataApiReqVO;
import nlib.restful.service.DataApiResVO;
import nlib.restful.DataApiReqVO;
import nlib.restful.DataApiResVO;
import nlib.util.StringUtil;
/**

View File

@ -2,8 +2,8 @@ package nlib.col.service;
import java.util.List;
import nlib.restful.service.DataApiReqVO;
import nlib.restful.service.DataApiResVO;
import nlib.restful.DataApiReqVO;
import nlib.restful.DataApiResVO;
public interface InterestService
{

View File

@ -4,7 +4,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import nlib.restful.service.DataApiResVO;
import nlib.restful.DataApiResVO;
/**
* <pre>

View File

@ -5,8 +5,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import nlib.restful.service.DataApiReqVO;
import nlib.restful.service.DataApiResVO;
import nlib.restful.DataApiReqVO;
import nlib.restful.DataApiResVO;
public interface RentService
{

View File

@ -3,8 +3,8 @@ package nlib.col.service;
import java.util.List;
import nlib.restful.service.DataApiReqVO;
import nlib.restful.service.DataApiResVO;
import nlib.restful.DataApiReqVO;
import nlib.restful.DataApiResVO;
public interface RisService
{

View File

@ -14,9 +14,9 @@ import org.springframework.stereotype.Service;
import nlib.col.service.CollectionService;
import nlib.col.service.CollectionVO;
import nlib.restful.DataApi;
import nlib.restful.service.DataApiReqVO;
import nlib.restful.service.DataApiResVO;
import nlib.restful.service.XmlConverter;
import nlib.restful.DataApiReqVO;
import nlib.restful.DataApiResVO;
import nlib.restful.XmlConverter;
import nlib.util.StringUtil;
/**

View File

@ -10,8 +10,8 @@ import egovframework.com.cmm.service.impl.EgovComAbstractDAO;
import nlib.col.service.CollectionVO;
import nlib.col.service.DeptVO;
import nlib.restful.DataApi;
import nlib.restful.service.DataApiReqVO;
import nlib.restful.service.DataApiResVO;
import nlib.restful.DataApiReqVO;
import nlib.restful.DataApiResVO;
@Repository("interestDAO")
public class InterestDAO extends EgovComAbstractDAO

View File

@ -12,8 +12,8 @@ import nlib.col.service.CartService;
import nlib.col.service.CollectionVO;
import nlib.col.service.DeptVO;
import nlib.col.service.InterestService;
import nlib.restful.service.DataApiReqVO;
import nlib.restful.service.DataApiResVO;
import nlib.restful.DataApiReqVO;
import nlib.restful.DataApiResVO;
@Service("interestService")
public class InterestServiceImpl implements InterestService

View File

@ -15,8 +15,8 @@ import nlib.col.service.CollectionVO;
import nlib.col.service.ReadService;
import nlib.info.service.InformService;
import nlib.restful.DataApi;
import nlib.restful.service.DataApiReqVO;
import nlib.restful.service.DataApiResVO;
import nlib.restful.DataApiReqVO;
import nlib.restful.DataApiResVO;
import nlib.util.StringUtil;
@Service("readService")

View File

@ -17,9 +17,9 @@ import nlib.col.service.CartService;
import nlib.col.service.CollectionVO;
import nlib.col.service.RentService;
import nlib.restful.DataApi;
import nlib.restful.service.DataApiReqVO;
import nlib.restful.service.DataApiResVO;
import nlib.restful.service.XmlConverter;
import nlib.restful.DataApiReqVO;
import nlib.restful.DataApiResVO;
import nlib.restful.XmlConverter;
import nlib.util.StringUtil;
@Service("rentService")

View File

@ -11,8 +11,8 @@ import nlib.col.service.CollectionVO;
import nlib.col.service.DeptVO;
import nlib.col.service.RisVO;
import nlib.restful.DataApi;
import nlib.restful.service.DataApiReqVO;
import nlib.restful.service.DataApiResVO;
import nlib.restful.DataApiReqVO;
import nlib.restful.DataApiResVO;
import java.util.HashMap;
import java.util.List;

View File

@ -13,8 +13,8 @@ import nlib.col.service.RisService;
import nlib.col.service.CollectionVO;
import nlib.col.service.DeptVO;
import nlib.col.service.RisVO;
import nlib.restful.service.DataApiReqVO;
import nlib.restful.service.DataApiResVO;
import nlib.restful.DataApiReqVO;
import nlib.restful.DataApiResVO;
@Service("risService")
public class RisServiceImpl implements RisService

View File

@ -21,7 +21,7 @@ import nlib.cmm.service.PagingVO;
import nlib.col.service.CollectionService;
import nlib.col.service.CollectionVO;
import nlib.col.service.ReadService;
import nlib.restful.service.DataApiResVO;
import nlib.restful.DataApiResVO;
import nlib.util.StringUtil;
/**

View File

@ -28,9 +28,9 @@ import nlib.cmm.service.PagingVO;
import nlib.col.service.CollectionService;
import nlib.col.service.CollectionVO;
import nlib.col.service.RentService;
import nlib.restful.service.DataApiReqVO;
import nlib.restful.service.DataApiResVO;
import nlib.restful.service.DataApiVO;
import nlib.restful.DataApiReqVO;
import nlib.restful.DataApiResVO;
import nlib.restful.DataApiVO;
import nlib.util.StringUtil;
/**

View File

@ -37,8 +37,8 @@ import nlib.col.service.CollectionVO;
import nlib.col.service.DeptVO;
import nlib.col.service.InterestService;
import nlib.col.service.RisVO;
import nlib.restful.service.DataApiReqVO;
import nlib.restful.service.DataApiResVO;
import nlib.restful.DataApiReqVO;
import nlib.restful.DataApiResVO;
import nlib.user.service.NlibLoginVO;
import nlib.util.StringUtil;

View File

@ -10,8 +10,8 @@ import org.springframework.stereotype.Service;
import nlib.cmm.service.NlibProperty;
import nlib.info.service.InformService;
import nlib.restful.service.DataApiReqVO;
import nlib.restful.service.DataApiResVO;
import nlib.restful.DataApiReqVO;
import nlib.restful.DataApiResVO;
import nlib.util.StringUtil;
/**

View File

@ -18,8 +18,8 @@ import nlib.cmm.NlibCommonController;
import nlib.cmm.service.NlibProperty;
import nlib.info.service.InformService;
import nlib.info.service.impl.InformServiceImpl;
import nlib.restful.service.DataApiReqVO;
import nlib.restful.service.DataApiResVO;
import nlib.restful.DataApiReqVO;
import nlib.restful.DataApiResVO;
import nlib.util.StringUtil;
/**

View File

@ -1,13 +1,30 @@
package nlib.restful;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.stereotype.Repository;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.HttpServerErrorException;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
import nlib.restful.service.DataApiReqVO;
import nlib.restful.service.DataApiResVO;
import nlib.restful.service.impl.DataApiTempXml;
import nlib.restful.service.impl.DataApiRESTful;
import nlib.util.StringUtil;
/**
@ -16,12 +33,6 @@ import nlib.restful.service.impl.DataApiRESTful;
*
* @Description : 통합자료관리시스템에 RESTful API를 통해 질의/응답을 처리한다.
*
* 개발 기간 , RESTful API 서버 기능이 준비될 동안 로컬 XML 파일 읽기로 처리 가능하며,
* 이를 위해서는 상속 클래스를 변경해 준다.
*
* - DataApiRESTful : RESTful API 서버에 접속하여 받아온 값으로 응답 처리
* - DataApiTempXml : 로컬파일(dataapi.temp.xml.path) 읽어서 응답 처리
*
* @프로젝트명: 지방문화원 통합자료관리시스템 구축사업 (2021)
*
* </pre>
@ -31,20 +42,390 @@ import nlib.restful.service.impl.DataApiRESTful;
* @ ------------ -------- ---------------------------
* @ 2021. 7. 9. KNKIM 최초 생성
*
*
* @author 이씨플라자 * DIGITALSHIP KNKIM
* @since 2021. 7. 9.
* @version 1.0
*
*/
@Repository("dataApi")
public class DataApi extends DataApiRESTful { // RESTFul 서버에 접속하여 요청/응답처리를 수행하는 경우
//public class DataApi extends DataApiTempXml { // 로컬파일에서 읽어와서 요청/응답처리를 수행하는 경우
public class DataApi {
private static final Logger log = LoggerFactory.getLogger(DataApi.class);
/* DataApi 접속 서버 정보 */
@Value("#{properties['dataapi.server.ip']}")
private String DAPI_SERVER_IP;
@Value("#{properties['dataapi.server.port']}")
private String DAPI_SERVER_PORT;
@Value("#{properties['dataapi.server.protocol']}")
private String DAPI_SERVER_PROTOCOL;
/**
* 실제 RESTful API 서버로 요청을 전송하고, 응답받은 자료를 응답VO에 담아서 리턴한다.
*
* @param reqVO
* @param method
* @return
*/
public DataApiResVO request(DataApiReqVO reqVO) {
return super.request(reqVO);
log.debug("request > " + reqVO.getReqMethod());
DataApiResVO resVO = null;
try {
//-----------------------------------
// 입력값 검증작업
//-----------------------------------
resVO = checkReqCommonParams(reqVO);
if(resVO != null) return resVO;
HttpMethod method = reqVO.getReqMethod();
//-----------------------------------
// 파라메터 생성 작업 요청 처리
//-----------------------------------
String url = DAPI_SERVER_PROTOCOL + "://" + DAPI_SERVER_IP + ("80".equals(DAPI_SERVER_PORT) ? "" : ":" + DAPI_SERVER_PORT) + reqVO.getReqUrl();
log.debug("REQ URL : " + url);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
ResponseEntity<String> responseEntity = null;
RestTemplate restTemplate = new RestTemplate();
restTemplate.getMessageConverters()
.add(0, new StringHttpMessageConverter(StandardCharsets.UTF_8));
HttpStatus statusCode = HttpStatus.OK;
String resultXML = null;
if(method == HttpMethod.GET) {
HttpEntity requestEntity = new HttpEntity(headers);
try {
responseEntity = restTemplate.exchange (makeRequestParamUrl(url, reqVO), method, requestEntity, String.class);
statusCode = responseEntity.getStatusCode();
resultXML = responseEntity.getBody();
} catch(HttpClientErrorException e) {
log.error("request > HttpClientErrorException 발생 : " + e.toString());
resultXML = e.getResponseBodyAsString();
statusCode = e.getStatusCode();
} catch(HttpServerErrorException e) {
log.error("request > HttpServerErrorException 발생 : " + e.toString());
resultXML = e.getResponseBodyAsString();
statusCode = e.getStatusCode();
}
} else if(method == HttpMethod.POST) {
MultiValueMap<String, String> parameters = makeRequestParamMultiValueMap(reqVO);
parameters.forEach((k, v) -> log.debug("params > " + k + " : " + v));
HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity(parameters, headers);
try {
responseEntity = restTemplate.postForEntity(url, requestEntity , String.class);
statusCode = responseEntity.getStatusCode();
resultXML = responseEntity.getBody();
} catch(HttpClientErrorException e) {
log.error("request > HttpClientErrorException 발생 : " + e.toString());
resultXML = e.getResponseBodyAsString();
statusCode = e.getStatusCode();
} catch(HttpServerErrorException e) {
log.error("request > HttpServerErrorException 발생 : " + e.toString());
resultXML = e.getResponseBodyAsString();
statusCode = e.getStatusCode();
}
} else {
String message = "RESTFul API Http Method 설정 오류입니다. : POST, GET 방식만 허용됩니다.";
log.error("request > " + message);
return makeErrorRes("E_ERR_METHOD", message);
}
//-----------------------------------
// 응답 처리
//-----------------------------------
log.debug("RES StatusCode : " + statusCode);
log.debug("RES resultXML : " + resultXML);
// 응답 자료 객체화
resVO = convertXmlToResVO(resultXML);
// 처리결과 코드 확인
if(StringUtil.isEmpty(resVO.getResultCode())) {
String resultMessage = resVO.getResultMessage();
if (statusCode == HttpStatus.OK) {
resVO.setResultCode("S_HTTP_STATUS_OK");
resVO.setResultMessage(StringUtil.isEmpty(resultMessage) ? "정상처리되었습니다." : resultMessage);
} else {
resVO.setResultCode("E_STATUS_CODE_FAIL");
resVO.setResultMessage(StringUtil.isEmpty(resultMessage) ? String.format("처리에 실패하였습니다. (HTTP상태코드 : %s)", statusCode.toString()) : resultMessage);
}
}
log.debug("RES resVO : resultCode = " + resVO.getResultCode());
log.debug("RES resVO : resultMessage = " + resVO.getResultMessage());
}catch(HttpClientErrorException e) {
log.error("request > HttpClientErrorException 발생 : " + e.toString());
return makeErrorRes("E_REQ_HTTPCLIENTERROREXCEPTION", e.toString());
}catch(HttpServerErrorException e) {
log.error("request > HttpServerErrorException 발생 : " + e.toString());
return makeErrorRes("E_REQ_HTTPSERVERERROREXCEPTION", e.toString());
} catch(Exception e) {
log.error("request > Exception 발생 : " + e.toString());
return makeErrorRes("E_REQ_EXCEPTION", e.toString());
}
return resVO;
}
/**
* [POST용] 요청 VO의 입력변수값을 API 요청을 위한 MultiValueMap 형태로 변환한다.
*
* @param reqVO
* @return
*/
public static MultiValueMap<String, String> makeRequestParamMultiValueMap(DataApiReqVO reqVO) {
MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
// 추가 정보
if(reqVO.hasInfo()) {
HashMap<String, String> info = reqVO.getInfo();
for(String key : info.keySet()) {
String val = null;
if(DataApiVO.XML_EL_NAME_MB_INFO_ID.equals(key)) {
val = reqVO.getEncMbInfoId();
} else {
val = info.get(key);
}
/*
String encVal = null;
try {
encVal = URLEncoder.encode((String)val, "UTF-8");
} catch(Exception e) {
log.error("makeRequestParamUrl > " + e.toString());
continue;
}
*/
map.add(key, val);
}
}
if(reqVO.hasList()) {
HashMap<String,List<HashMap<String,String>>> listMap = reqVO.getListMap();
if(listMap != null) {
for(String listName : listMap.keySet() ) {
List<HashMap<String,String>> list = listMap.get(listName);
// 목록변수명은 있으나, 값이 없는 경우, 배열 JSON값 설정
if(list == null || list.size() < 1) {
map.add(listName, "[]");
continue;
}
// 목록변수명에 대한 목록 자료 존재하는 경우, JSON 생성 처리
map.add(listName, makeJsonStrFromListMap(list));
} // for
} // if(listMap != null)
} // if(reqVO.hasList())
// 요청 파라메타 확인
for(String key : map.keySet()) {
log.debug("MultiValueMap > " + key + "=" + map.get(key));
}
return map;
}
/**
* [GET용] 요청 VO의 입력변수값을 API 요청을 위한 URL 쿼리 형태의 문자열로 리턴한다.
*
* @param url
* @param reqVO
* @return
*/
public static String makeRequestParamUrl(String url, DataApiReqVO reqVO) {
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url);
// 추가 정보
if(reqVO.hasInfo()) {
HashMap<String, String> info = reqVO.getInfo();
for(String key : info.keySet()) {
Object val = null;
if(DataApiVO.XML_EL_NAME_MB_INFO_ID.equals(key)) {
val = reqVO.getEncMbInfoId();
} else {
val = info.get(key);
}
/*
String encVal = null;
try {
encVal = URLEncoder.encode((String)val, "UTF-8");
} catch(Exception e) {
log.error("makeRequestParamUrl > " + e.toString());
continue;
}*/
builder.queryParam(key, (String)val);
}
}
if(reqVO.hasList()) {
HashMap<String,List<HashMap<String,String>>> listMap = reqVO.getListMap();
if(listMap != null) {
for(String listName : listMap.keySet() ) {
List<HashMap<String,String>> list = listMap.get(listName);
// 목록변수명은 있으나, 값이 없는 경우, 배열 JSON값 설정
if(list == null || list.size() < 1) {
builder.queryParam(listName, "[]");
continue;
}
// 목록변수명에 대한 목록 자료 존재하는 경우, JSON 생성 처리
builder.queryParam(listName, makeJsonStrFromListMap(list));
} // for
} // if(listMap != null)
} // if(reqVO.hasList())
String retUrl = builder.toUriString();
log.debug("makeRequestParamUrl > queryUrl = " + retUrl);
return retUrl;
}
/**
* HashMap를 목록의 요소로 하는 리스트를 받아서 해당 요소들의 배열을 가진 JSON 객체 문자열을 생성하여 리턴한다.
* : [{"name":"James", "city":"Miracle", ...}, ..., {"name":"James", "city":"Miracle", ...}]
*
* @param list
* @return
*/
public static String makeJsonStrFromListMap(List<HashMap<String,String>> list) {
// 목록변수명은 있으나, 값이 없는 경우, 배열 JSON값 설정
if(list == null || list.size() < 1) {
return "[]";
}
// 목록변수명에 대한 목록 자료 존재하는 경우, JSON 생성 처리
String jsonListStr = "";
for(int i=0; i<list.size(); i++) {
HashMap<String, String> record = list.get(i);
String jsonRecordStr = makeJsonStrFromMap(record);
if(StringUtil.isEmpty(jsonRecordStr)) continue;
if(jsonListStr.length() > 0) jsonListStr += ",";
jsonListStr += jsonRecordStr;
}
return "[" + jsonListStr + "]";
}
/**
* HashMap을 받아서 해당 요소들을 맴버변수로 하는 JSON객체 문자열을 생성하여 리턴한다.
* : {"name":"James", "city":"Miracle", ...}
*
* @param record
* @return
*/
public static String makeJsonStrFromMap(HashMap<String,String> record) {
if(record == null || record.size() < 1) return null;
String jsonRecordStr = "";
for(String subKey : record.keySet()) {
String subVal = record.get(subKey);
if(jsonRecordStr.length() > 0) jsonRecordStr += ",";
jsonRecordStr += "\"" + subKey + ":" + (subVal == null? "null" : "\"" + subVal + "\"");
}
return "{" + jsonRecordStr + "}";
}
/**
* 요청전 공통 필수 입력 매개변수를 체크하여 결과를 리턴한다.
*
* @param reqVO
* @return
* @throws Exception :
*/
public static DataApiResVO checkReqCommonParams(DataApiReqVO reqVO) {
if(reqVO == null) {
return new DataApiResVO("ERR_NO_REQ", "데이터송수신 요청객체가 존재하지 않습니다.");
}
if(StringUtil.isEmpty(reqVO.getReqUrl())) {
return new DataApiResVO("ERR_NO_RURL", "데이터 요청 업무ID에 대한 URL/RUI 정보가 존재하지 않습니다.");
}
if(reqVO.getReqMethod() == null) {
return new DataApiResVO("ERR_NO_METHOD", "데이터 요청 방식 정보가 존재하지 않습니다.");
}
return null;
}
/**
* 처리결과 정보를 입력받아 DataApiResVO를 생성한다.
*
* @param resultCode
* @param resultMessage
* @return
*/
public static DataApiResVO makeErrorRes(String resultCode, String resultMessage) {
return new DataApiResVO(resultCode, resultMessage);
}
/**
* 응답받은 XML 문자열을 DataApiResVO (내부 Map객체 포함) 객체로 변환하여 리턴한다.
*
* @param xmlStr
* @return
*/
public static DataApiResVO convertXmlToResVO(String xmlStr) {
DataApiResVO resVO = new DataApiResVO();
Map<String, Object> map = null;
try {
map = XmlConverter.convert(xmlStr, DataApiVO.XML_EL_NAME_ROOT_NAME);
} catch(Exception e) {
resVO.setResultCode("ERR_RES_XML_FORMAT");
resVO.setResultMessage(String.format("올바르지 않은 XML 형식의 응답입니다. : [%s]", xmlStr));
log.error("convertXmlToResVO > " + resVO.getResultMessage());
e.printStackTrace();
return resVO;
}
// 처리결과 확인
List<HashMap<String, String>> recordList = null;
for( String key : map.keySet()) {
if(key.equalsIgnoreCase(DataApiVO.XML_EL_NAME_RESULT_CODE)) resVO.setResultCode((String)map.get(key));
else if(key.equalsIgnoreCase(DataApiVO.XML_EL_NAME_RESULT_MESSAGE)) resVO.setResultMessage((String)map.get(key));
else if(key.equalsIgnoreCase(DataApiVO.XML_EL_NAME_RECORD)) {
// 다건 목록 데이터인 경우
Object obj = map.get(DataApiVO.XML_EL_NAME_RECORD);
if(obj instanceof HashMap) {
// 맵인 경우, 리스트형식으로 저장 처리
List<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>();
list.add((HashMap)obj);
resVO.setList(DataApiVO.XML_EL_NAME_RECORD, list);
} else if(obj instanceof List) {
resVO.setList(DataApiVO.XML_EL_NAME_RECORD, (List)obj);
} else {
resVO.setResultCode("ERR_RES_XML_FORMAT_RECORD");
resVO.setResultMessage(DataApiVO.XML_EL_NAME_RECORD + " 요소가 알수 없는 형식으로 객체화되었습니다. 확인바랍니다. : " + obj.toString());
log.error("convertXmlToResVO > " + resVO.getResultMessage());
return resVO;
}
} else resVO.putInfoItem(key, (String)map.get(key));
}
return resVO;
}
}

View File

@ -1,4 +1,4 @@
package nlib.restful.service;
package nlib.restful;
import org.springframework.http.HttpMethod;
import nlib.cmm.crypto.AriaCrypto;

View File

@ -1,4 +1,4 @@
package nlib.restful.service;
package nlib.restful;
import nlib.util.StringUtil;

View File

@ -1,4 +1,4 @@
package nlib.restful.service;
package nlib.restful;
import java.util.ArrayList;
import java.util.HashMap;

View File

@ -1,4 +1,4 @@
package nlib.restful.service;
package nlib.restful;
import java.io.ByteArrayInputStream;
import java.util.ArrayList;

View File

@ -1,307 +0,0 @@
package nlib.restful.service;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
import nlib.util.StringUtil;
/**
* <pre>
* @Class Name : DataApiInterface.java
*
* @Description : DAO에서 상속할 DataApi의 부모 클래스들을 위한 인터페이스
*
*
* @프로젝트명: 지방문화원 통합자료관리시스템 구축사업 (2021)
*
* </pre>
*
* @ ------------ -------- ---------------------------
* @ 수정일 수정자 수정내용
* @ ------------ -------- ---------------------------
* @ 2021. 7. 9. KNKIM 최초 생성
*
*
* @author 이씨플라자 * DIGITALSHIP KNKIM
* @since 2021. 7. 9.
* @version 1.0
*
*/
public interface DataApiInterface {
static final Logger log = LoggerFactory.getLogger(DataApiInterface.class);
/**
* 실제 RESTful API 서버로 요청을 전송하고, 응답받은 자료를 응답VO에 담아서 리턴한다.
*
* @param reqVO
* @param method
* @return
*/
public DataApiResVO request(DataApiReqVO reqVO);
/**
* [POST용] 요청 VO의 입력변수값을 API 요청을 위한 MultiValueMap 형태로 변환한다.
*
* @param reqVO
* @return
*/
public static MultiValueMap<String, String> makeRequestParamMultiValueMap(DataApiReqVO reqVO) {
MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
// 추가 정보
if(reqVO.hasInfo()) {
HashMap<String, String> info = reqVO.getInfo();
for(String key : info.keySet()) {
String val = null;
if(DataApiVO.XML_EL_NAME_MB_INFO_ID.equals(key)) {
val = reqVO.getEncMbInfoId();
} else {
val = info.get(key);
}
/*
String encVal = null;
try {
encVal = URLEncoder.encode((String)val, "UTF-8");
} catch(Exception e) {
log.error("makeRequestParamUrl > " + e.toString());
continue;
}
*/
map.add(key, val);
}
}
if(reqVO.hasList()) {
HashMap<String,List<HashMap<String,String>>> listMap = reqVO.getListMap();
if(listMap != null) {
for(String listName : listMap.keySet() ) {
List<HashMap<String,String>> list = listMap.get(listName);
// 목록변수명은 있으나, 값이 없는 경우, 배열 JSON값 설정
if(list == null || list.size() < 1) {
map.add(listName, "[]");
continue;
}
// 목록변수명에 대한 목록 자료 존재하는 경우, JSON 생성 처리
map.add(listName, makeJsonStrFromListMap(list));
} // for
} // if(listMap != null)
} // if(reqVO.hasList())
// 요청 파라메타 확인
for(String key : map.keySet()) {
log.debug("MultiValueMap > " + key + "=" + map.get(key));
}
return map;
}
/**
* [GET용] 요청 VO의 입력변수값을 API 요청을 위한 URL 쿼리 형태의 문자열로 리턴한다.
*
* @param url
* @param reqVO
* @return
*/
public static String makeRequestParamUrl(String url, DataApiReqVO reqVO) {
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url);
// 추가 정보
if(reqVO.hasInfo()) {
HashMap<String, String> info = reqVO.getInfo();
for(String key : info.keySet()) {
Object val = null;
if(DataApiVO.XML_EL_NAME_MB_INFO_ID.equals(key)) {
val = reqVO.getEncMbInfoId();
} else {
val = info.get(key);
}
/*
String encVal = null;
try {
encVal = URLEncoder.encode((String)val, "UTF-8");
} catch(Exception e) {
log.error("makeRequestParamUrl > " + e.toString());
continue;
}*/
builder.queryParam(key, (String)val);
}
}
if(reqVO.hasList()) {
HashMap<String,List<HashMap<String,String>>> listMap = reqVO.getListMap();
if(listMap != null) {
for(String listName : listMap.keySet() ) {
List<HashMap<String,String>> list = listMap.get(listName);
// 목록변수명은 있으나, 값이 없는 경우, 배열 JSON값 설정
if(list == null || list.size() < 1) {
builder.queryParam(listName, "[]");
continue;
}
// 목록변수명에 대한 목록 자료 존재하는 경우, JSON 생성 처리
builder.queryParam(listName, makeJsonStrFromListMap(list));
} // for
} // if(listMap != null)
} // if(reqVO.hasList())
String retUrl = builder.toUriString();
log.debug("makeRequestParamUrl > queryUrl = " + retUrl);
return retUrl;
}
/**
* HashMap를 목록의 요소로 하는 리스트를 받아서 해당 요소들의 배열을 가진 JSON 객체 문자열을 생성하여 리턴한다.
* : [{"name":"James", "city":"Miracle", ...}, ..., {"name":"James", "city":"Miracle", ...}]
*
* @param list
* @return
*/
public static String makeJsonStrFromListMap(List<HashMap<String,String>> list) {
// 목록변수명은 있으나, 값이 없는 경우, 배열 JSON값 설정
if(list == null || list.size() < 1) {
return "[]";
}
// 목록변수명에 대한 목록 자료 존재하는 경우, JSON 생성 처리
String jsonListStr = "";
for(int i=0; i<list.size(); i++) {
HashMap<String, String> record = list.get(i);
String jsonRecordStr = makeJsonStrFromMap(record);
if(StringUtil.isEmpty(jsonRecordStr)) continue;
if(jsonListStr.length() > 0) jsonListStr += ",";
jsonListStr += jsonRecordStr;
}
return "[" + jsonListStr + "]";
}
/**
* HashMap을 받아서 해당 요소들을 맴버변수로 하는 JSON객체 문자열을 생성하여 리턴한다.
* : {"name":"James", "city":"Miracle", ...}
*
* @param record
* @return
*/
public static String makeJsonStrFromMap(HashMap<String,String> record) {
if(record == null || record.size() < 1) return null;
String jsonRecordStr = "";
for(String subKey : record.keySet()) {
String subVal = record.get(subKey);
if(jsonRecordStr.length() > 0) jsonRecordStr += ",";
jsonRecordStr += "\"" + subKey + ":" + (subVal == null? "null" : "\"" + subVal + "\"");
}
return "{" + jsonRecordStr + "}";
}
/**
* 요청전 공통 필수 입력 매개변수를 체크하여 결과를 리턴한다.
*
* @param reqVO
* @return
* @throws Exception :
*/
public static DataApiResVO checkReqCommonParams(DataApiReqVO reqVO) {
if(reqVO == null) {
return new DataApiResVO("ERR_NO_REQ", "데이터송수신 요청객체가 존재하지 않습니다.");
}
if(StringUtil.isEmpty(reqVO.getReqUrl())) {
return new DataApiResVO("ERR_NO_RURL", "데이터 요청 업무ID에 대한 URL/RUI 정보가 존재하지 않습니다.");
}
if(reqVO.getReqMethod() == null) {
return new DataApiResVO("ERR_NO_METHOD", "데이터 요청 방식 정보가 존재하지 않습니다.");
}
return null;
}
/**
* 처리결과 정보를 입력받아 DataApiResVO를 생성한다.
*
* @param resultCode
* @param resultMessage
* @return
*/
public static DataApiResVO makeErrorRes(String resultCode, String resultMessage) {
return new DataApiResVO(resultCode, resultMessage);
}
/**
* 응답받은 XML 문자열을 DataApiResVO (내부 Map객체 포함) 객체로 변환하여 리턴한다.
*
* @param xmlStr
* @return
*/
public static DataApiResVO convertXmlToResVO(String xmlStr) {
DataApiResVO resVO = new DataApiResVO();
Map<String, Object> map = null;
try {
map = XmlConverter.convert(xmlStr, DataApiVO.XML_EL_NAME_ROOT_NAME);
} catch(Exception e) {
resVO.setResultCode("ERR_RES_XML_FORMAT");
resVO.setResultMessage(String.format("올바르지 않은 XML 형식의 응답입니다. : [%s]", xmlStr));
log.error("convertXmlToResVO > " + resVO.getResultMessage());
e.printStackTrace();
return resVO;
}
// 처리결과 확인
List<HashMap<String, String>> recordList = null;
for( String key : map.keySet()) {
if(key.equalsIgnoreCase(DataApiVO.XML_EL_NAME_RESULT_CODE)) resVO.setResultCode((String)map.get(key));
else if(key.equalsIgnoreCase(DataApiVO.XML_EL_NAME_RESULT_MESSAGE)) resVO.setResultMessage((String)map.get(key));
else if(key.equalsIgnoreCase(DataApiVO.XML_EL_NAME_RECORD)) {
// 다건 목록 데이터인 경우
Object obj = map.get(DataApiVO.XML_EL_NAME_RECORD);
if(obj instanceof HashMap) {
// 맵인 경우, 리스트형식으로 저장 처리
List<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>();
list.add((HashMap)obj);
resVO.setList(DataApiVO.XML_EL_NAME_RECORD, list);
} else if(obj instanceof List) {
resVO.setList(DataApiVO.XML_EL_NAME_RECORD, (List)obj);
} else {
resVO.setResultCode("ERR_RES_XML_FORMAT_RECORD");
resVO.setResultMessage(DataApiVO.XML_EL_NAME_RECORD + " 요소가 알수 없는 형식으로 객체화되었습니다. 확인바랍니다. : " + obj.toString());
log.error("convertXmlToResVO > " + resVO.getResultMessage());
return resVO;
}
} else resVO.putInfoItem(key, (String)map.get(key));
}
return resVO;
}
}

View File

@ -1,59 +0,0 @@
package nlib.restful.service;
/**
* <pre>
* @Class Name : DataApiServerResponseVO.java
*
* @Description : RESUTful 임시 서버에서 응답을 위해 사용하는 VO 클래스
*
*
* @프로젝트명: 지방문화원 통합자료관리시스템 구축사업 (2021)
*
* </pre>
*
* @ ------------ -------- ---------------------------
* @ 수정일 수정자 수정내용
* @ ------------ -------- ---------------------------
* @ 2021. 7. 9. KNKIM 최초 생성
*
*
* @author 이씨플라자 * DIGITALSHIP KNKIM
* @since 2021. 7. 9.
* @version 1.0
*
*/
public class DataApiServerResponseVO {
private String code;
private String message;
/**
* 생성자 : 처리결과코드와 메시지를 입력받아 DataApiServerResponseVO 객체를 생성한다.
* @param code
* @param message
*/
public DataApiServerResponseVO(String code, String message) {
this.code = code;
this.message = message;
}
/**
* 처리결과코드 리턴한다.
*
* @return
*/
public String getCode() {
return code;
}
/**
* 처리결과메시지 리턴한다.
*
* @return
*/
public String getMessage() {
return message;
}
}

View File

@ -1,177 +0,0 @@
package nlib.restful.service.impl;
import java.nio.charset.StandardCharsets;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.HttpServerErrorException;
import org.springframework.web.client.RestTemplate;
import nlib.restful.service.DataApiInterface;
import nlib.restful.service.DataApiReqVO;
import nlib.restful.service.DataApiResVO;
import nlib.util.StringUtil;
/**
* <pre>
* @Class Name : DataApiRESTful.java
*
* @Description : 통합자료관리시스템에 RESTful API를 통해 질의/응답을 처리한다.
*
*
* @프로젝트명: 지방문화원 통합자료관리시스템 구축사업 (2021)
*
* </pre>
*
* @ ------------ -------- ---------------------------
* @ 수정일 수정자 수정내용
* @ ------------ -------- ---------------------------
* @ 2021. 6. 22. KNKIM 최초 생성
*
*
* @author 이씨플라자 * DIGITALSHIP KNKIM
* @since 2021. 6. 22.
* @version 1.0
*
*/
public class DataApiRESTful implements DataApiInterface {
private static final Logger log = LoggerFactory.getLogger(DataApiRESTful.class);
/* DataApi 접속 서버 정보 */
@Value("#{properties['dataapi.server.ip']}")
private String DAPI_SERVER_IP;
@Value("#{properties['dataapi.server.port']}")
private String DAPI_SERVER_PORT;
@Value("#{properties['dataapi.server.protocol']}")
private String DAPI_SERVER_PROTOCOL;
/**
* 실제 RESTful API 서버로 요청을 전송하고, 응답받은 자료를 응답VO에 담아서 리턴한다.
*
* @param reqVO
* @param method
* @return
*/
public DataApiResVO request(DataApiReqVO reqVO) {
log.debug("request > " + reqVO.getReqMethod());
DataApiResVO resVO = null;
try {
//-----------------------------------
// 입력값 검증작업
//-----------------------------------
resVO = DataApiInterface.checkReqCommonParams(reqVO);
if(resVO != null) return resVO;
HttpMethod method = reqVO.getReqMethod();
//-----------------------------------
// 파라메터 생성 작업 요청 처리
//-----------------------------------
String url = DAPI_SERVER_PROTOCOL + "://" + DAPI_SERVER_IP + ("80".equals(DAPI_SERVER_PORT) ? "" : ":" + DAPI_SERVER_PORT) + reqVO.getReqUrl();
log.debug("REQ URL : " + url);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
ResponseEntity<String> responseEntity = null;
RestTemplate restTemplate = new RestTemplate();
restTemplate.getMessageConverters()
.add(0, new StringHttpMessageConverter(StandardCharsets.UTF_8));
HttpStatus statusCode = HttpStatus.OK;
String resultXML = null;
if(method == HttpMethod.GET) {
HttpEntity requestEntity = new HttpEntity(headers);
try {
responseEntity = restTemplate.exchange (DataApiInterface.makeRequestParamUrl(url, reqVO), method, requestEntity, String.class);
statusCode = responseEntity.getStatusCode();
resultXML = responseEntity.getBody();
} catch(HttpClientErrorException e) {
log.error("request > HttpClientErrorException 발생 : " + e.toString());
resultXML = e.getResponseBodyAsString();
statusCode = e.getStatusCode();
} catch(HttpServerErrorException e) {
log.error("request > HttpServerErrorException 발생 : " + e.toString());
resultXML = e.getResponseBodyAsString();
statusCode = e.getStatusCode();
}
} else if(method == HttpMethod.POST) {
MultiValueMap<String, String> parameters = DataApiInterface.makeRequestParamMultiValueMap(reqVO);
parameters.forEach((k, v) -> log.debug("params > " + k + " : " + v));
HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity(parameters, headers);
try {
responseEntity = restTemplate.postForEntity(url, requestEntity , String.class);
statusCode = responseEntity.getStatusCode();
resultXML = responseEntity.getBody();
} catch(HttpClientErrorException e) {
log.error("request > HttpClientErrorException 발생 : " + e.toString());
resultXML = e.getResponseBodyAsString();
statusCode = e.getStatusCode();
} catch(HttpServerErrorException e) {
log.error("request > HttpServerErrorException 발생 : " + e.toString());
resultXML = e.getResponseBodyAsString();
statusCode = e.getStatusCode();
}
} else {
String message = "RESTFul API Http Method 설정 오류입니다. : POST, GET 방식만 허용됩니다.";
log.error("request > " + message);
return DataApiInterface.makeErrorRes("E_ERR_METHOD", message);
}
//-----------------------------------
// 응답 처리
//-----------------------------------
log.debug("RES StatusCode : " + statusCode);
log.debug("RES resultXML : " + resultXML);
// 응답 자료 객체화
resVO = DataApiInterface.convertXmlToResVO(resultXML);
// 처리결과 코드 확인
if(StringUtil.isEmpty(resVO.getResultCode())) {
String resultMessage = resVO.getResultMessage();
if (statusCode == HttpStatus.OK) {
resVO.setResultCode("S_HTTP_STATUS_OK");
resVO.setResultMessage(StringUtil.isEmpty(resultMessage) ? "정상처리되었습니다." : resultMessage);
} else {
resVO.setResultCode("E_STATUS_CODE_FAIL");
resVO.setResultMessage(StringUtil.isEmpty(resultMessage) ? String.format("처리에 실패하였습니다. (HTTP상태코드 : %s)", statusCode.toString()) : resultMessage);
}
}
log.debug("RES resVO : resultCode = " + resVO.getResultCode());
log.debug("RES resVO : resultMessage = " + resVO.getResultMessage());
}catch(HttpClientErrorException e) {
log.error("request > HttpClientErrorException 발생 : " + e.toString());
return DataApiInterface.makeErrorRes("E_REQ_HTTPCLIENTERROREXCEPTION", e.toString());
}catch(HttpServerErrorException e) {
log.error("request > HttpServerErrorException 발생 : " + e.toString());
return DataApiInterface.makeErrorRes("E_REQ_HTTPSERVERERROREXCEPTION", e.toString());
} catch(Exception e) {
log.error("request > Exception 발생 : " + e.toString());
return DataApiInterface.makeErrorRes("E_REQ_EXCEPTION", e.toString());
}
return resVO;
}
}

View File

@ -1,178 +0,0 @@
package nlib.restful.service.impl;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.util.MultiValueMap;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import nlib.restful.service.DataApiInterface;
import nlib.restful.service.DataApiReqVO;
import nlib.restful.service.DataApiResVO;
import nlib.restful.service.DataApiServerResponseVO;
import nlib.restful.service.DataApiVO;
import nlib.util.StringUtil;
/**
* <pre>
* @Class Name : DataApiTempXml.java
*
* @Description : DataAPI의 요청에 대해서 로컬의 테스트용 XML 파일을 읽어서 응답을 처리한다. (자체 선개발 진행용)
*
*
* @프로젝트명: 지방문화원 통합자료관리시스템 구축사업 (2021)
*
* </pre>
*
* @ ------------ -------- ---------------------------
* @ 수정일 수정자 수정내용
* @ ------------ -------- ---------------------------
* @ 2021. 7. 9. KNKIM 최초 생성
*
*
* @author 이씨플라자 * DIGITALSHIP KNKIM
* @since 2021. 7. 9.
* @version 1.0
*
*/
public class DataApiTempXml implements DataApiInterface {
private static final Logger log = LoggerFactory.getLogger(DataApiTempXml.class);
/* DataApi 접속 서버 정보 */
@Value("#{properties['dataapi.temp.xml.path']}")
private String DAPI_TEMP_XML_PATH;
/**
* 실제 RESTful API 서버로 요청을 전송하고, 응답받은 자료를 응답VO에 담아서 리턴한다.
*
* @param reqVO
* @param method
* @return
*/
public DataApiResVO request(DataApiReqVO reqVO) {
log.debug("request > " + reqVO.getReqMethod());
DataApiResVO resVO = null;
try {
//-----------------------------------
// 입력값 검증작업
//-----------------------------------
resVO = DataApiInterface.checkReqCommonParams(reqVO);
if(resVO != null) return resVO;
HttpMethod method = reqVO.getReqMethod();
//-----------------------------------
// 파라메터 생성 작업 (요청데이터 확인용)
//-----------------------------------
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
MultiValueMap<String, String> parameters = DataApiInterface.makeRequestParamMultiValueMap(reqVO);
//-----------------------------------
// 응답 처리
//-----------------------------------
HttpStatus statusCode = HttpStatus.OK;
String resultXML = getTempDataFromXmlFile(reqVO);
//log.debug("RES resultXML : " + resultXML);
// 응답 자료 객체화
resVO = DataApiInterface.convertXmlToResVO(resultXML);
// 처리결과 코드 확인
if(StringUtil.isEmpty(resVO.getResultCode())) {
String resultMessage = resVO.getResultMessage();
if (statusCode == HttpStatus.OK) {
resVO.setResultCode("S_HTTP_STATUS_OK");
resVO.setResultMessage(StringUtil.isEmpty(resultMessage) ? "정상처리되었습니다." : resultMessage);
} else {
resVO.setResultCode("E_STATUS_CODE_FAIL");
resVO.setResultMessage(StringUtil.isEmpty(resultMessage) ? String.format("처리에 실패하였습니다. (HTTP상태코드 : %s)", statusCode.toString()) : resultMessage);
}
}
log.debug("RES resVO : resultCode = " + resVO.getResultCode());
log.debug("RES resVO : resultMessage = " + resVO.getResultMessage());
} catch(JsonProcessingException e) {
log.error("JsonProcessingException at DataApiTempXml.request : " + e.toString());
return DataApiInterface.makeErrorRes("E_REQ_EXCEPTION", e.toString());
}
return resVO;
}
/**
* 요청 URI와 메소드를 기반으로 임시 응답 XML 파일을 찾아서 내용을 문자열로 리턴한다.
*
* @param reqVO
* @param method
* @return
* @throws Exception
*/
private String getTempDataFromXmlFile(DataApiReqVO reqVO) throws JsonProcessingException {
HttpMethod method = reqVO.getReqMethod();
String fileName = reqVO.getReqUrl().substring(1).replaceAll("/", ".");
String xmlPath = DAPI_TEMP_XML_PATH + "/" + fileName + "_" + method.toString().toUpperCase() + ".xml";
String returnXmlStr = null;
log.info("XML FILE PATH : " + xmlPath);
DataApiServerResponseVO resVO = null;
File xmlFile = new File(xmlPath);
if(!xmlFile.exists()) {
resVO = new DataApiServerResponseVO("-20", String.format("%s 파일을 찾을 수 없습니다.",xmlPath));
XmlMapper mapper = new XmlMapper();
returnXmlStr = mapper.writer().withRootName("result").writeValueAsString(resVO);
}
if(resVO == null && !xmlFile.isFile()) {
resVO = new DataApiServerResponseVO("-21", String.format("%s는 파일이어야 합니다.",xmlPath));
XmlMapper mapper = new XmlMapper();
returnXmlStr = mapper.writer().withRootName(DataApiVO.XML_EL_NAME_ROOT_NAME).writeValueAsString(resVO);
}
if(resVO == null) {
StringBuilder strBd = new StringBuilder();
try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(xmlPath),StandardCharsets.UTF_8))) {
String line;
int i = 0;
while ((line = br.readLine()) != null) {
strBd.append(line + "\n");
}
returnXmlStr = strBd.toString();
} catch (IOException e) {
log.error("XML 파일 읽는 중 오류 발생 : " + e.toString());
resVO = new DataApiServerResponseVO("-22", String.format("%s 파일을 읽는 중 오류가 발생하였습니다(%s). ",xmlPath, e.toString()));
XmlMapper mapper = new XmlMapper();
returnXmlStr = mapper.writer().withRootName(DataApiVO.XML_EL_NAME_ROOT_NAME).writeValueAsString(resVO);
}
}
//log.info("RESUTN XML STR : " + returnXmlStr);
return returnXmlStr;
}
}

View File

@ -13,8 +13,8 @@ import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
import nlib.restful.service.DataApiReqVO;
import nlib.restful.service.DataApiResVO;
import nlib.restful.DataApiReqVO;
import nlib.restful.DataApiResVO;
/**
* <pre>

View File

@ -6,8 +6,8 @@ import java.util.HashMap;
import javax.servlet.http.HttpServletRequest;
import egovframework.com.ext.oauth.service.OAuthUniversalUser;
import nlib.restful.service.DataApiReqVO;
import nlib.restful.service.DataApiResVO;
import nlib.restful.DataApiReqVO;
import nlib.restful.DataApiResVO;
public interface LoginService
{

View File

@ -5,8 +5,8 @@ import java.util.HashMap;
import java.util.List;
import egovframework.com.ext.oauth.service.OAuthUniversalUser;
import nlib.restful.service.DataApiReqVO;
import nlib.restful.service.DataApiResVO;
import nlib.restful.DataApiReqVO;
import nlib.restful.DataApiResVO;
/**
* Description :

View File

@ -7,8 +7,8 @@ import org.springframework.stereotype.Repository;
import egovframework.com.cmm.service.impl.EgovComAbstractDAO;
import nlib.cmm.crypto.AriaCrypto;
import nlib.restful.service.DataApiReqVO;
import nlib.restful.service.DataApiResVO;
import nlib.restful.DataApiReqVO;
import nlib.restful.DataApiResVO;
import nlib.user.service.NlibLoginVO;
@Repository("loginDAO")

View File

@ -21,8 +21,8 @@ import org.springframework.stereotype.Service;
import egovframework.com.ext.oauth.service.OAuthUniversalUser;
import nlib.cmm.session.SessionConfig;
import nlib.restful.service.DataApiReqVO;
import nlib.restful.service.DataApiResVO;
import nlib.restful.DataApiReqVO;
import nlib.restful.DataApiResVO;
import nlib.user.service.LoginService;
import nlib.user.service.NlibLoginVO;
import nlib.util.StringUtil;

View File

@ -8,8 +8,8 @@ import org.springframework.stereotype.Repository;
import egovframework.com.ext.oauth.service.OAuthUniversalUser;
import egovframework.rte.psl.dataaccess.mapper.Mapper;
import nlib.restful.service.DataApiReqVO;
import nlib.restful.service.DataApiResVO;
import nlib.restful.DataApiReqVO;
import nlib.restful.DataApiResVO;
import nlib.user.service.NlibLoginVO;
import nlib.user.service.NlibSmsVO;

View File

@ -16,8 +16,8 @@ import org.springframework.stereotype.Service;
import egovframework.com.ext.oauth.service.OAuthUniversalUser;
import egovframework.rte.fdl.cryptography.EgovPasswordEncoder;
import nlib.cmm.crypto.AriaCrypto;
import nlib.restful.service.DataApiReqVO;
import nlib.restful.service.DataApiResVO;
import nlib.restful.DataApiReqVO;
import nlib.restful.DataApiResVO;
import nlib.user.service.MemberService;
import nlib.user.service.NlibLoginVO;
import nlib.user.service.NlibSmsVO;

View File

@ -38,7 +38,7 @@ import nlib.col.service.CollectionVO;
import nlib.col.service.InterestService;
import nlib.col.service.ReadService;
import nlib.col.service.RentService;
import nlib.restful.service.DataApiResVO;
import nlib.restful.DataApiResVO;
import nlib.security.SecUserDetailsService;
import nlib.security.SecUserVO;
import nlib.user.service.LoginService;

View File

@ -27,10 +27,13 @@ domain.host.localhost = nlib-dev
# \ub85c\uadf8\uc778/\ud68c\uc6d0\uac00\uc785\uad00\ub828 URL \uc815\ubcf4
#----------------------------------------
member.new.url = /login/memberSnsForm.do
# \ub85c\uadf8\uc778 \ub610\ub294 \uad8c\ud55c\uc5c6\ub294 \uacbd\uc6b0, \ub85c\uadf8\uc778\uc73c\ub85c \uc804\ud658\ucc98\ub9ac\ub418\uc5b4 \uc811\uc18d\ub418\ub294 \ucd5c\ucd08 \uc8fc\uc18c
login.url = /login/loginForm.do
# \ub85c\uadf8\uc778 \ubb38\uc81c \ubc1c\uc0dd \uc2dc, \ub2e4\uc2dc \ub9ac\ub2e4\uc774\ub809\ud2b8\ub420 \uc8fc\uc18c
login.back.url = /login/loginGuide.do
# \ud734\uba74\uacc4\uc88c \ud574\uc9c0\uc548\ub0b4 \uc8fc\uc18c
login.dormant.url = /login/activateDormantAccForm.do