diff --git a/src/main/java/nlib/restful/service/impl/DataApiRESTful.java b/src/main/java/nlib/restful/service/impl/DataApiRESTful.java index 8723c6f4..a533a791 100644 --- a/src/main/java/nlib/restful/service/impl/DataApiRESTful.java +++ b/src/main/java/nlib/restful/service/impl/DataApiRESTful.java @@ -1,168 +1,168 @@ -package nlib.restful.service.impl; - -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.util.MultiValueMap; -import org.springframework.web.client.RestTemplate; - -import nlib.restful.service.DataApiReqVO; -import nlib.restful.service.DataApiResVO; -import nlib.restful.service.DataApiInterface; -import nlib.util.StringUtil; - -/** - *
- * @Class Name : DataApiRESTful.java
- * 
- * @Description : 통합자료관리시스템에 RESTful API를 통해 질의/응답을 처리한다.
- * 
- * 
- * @프로젝트명: 지방문화원 통합자료관리시스템 구축사업 (2021)
- *
- * 
- * - * @ ------------ -------- --------------------------- - * @ 수정일 수정자 수정내용 - * @ ------------ -------- --------------------------- - * @ 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; - - - /** - * 조회 - * - * @param reqVO - * @return - */ - public DataApiResVO get(DataApiReqVO reqVO) { - - return send(reqVO, HttpMethod.GET); - } - - /** - * 등록 - * - * @param reqVO - * @return - */ - public DataApiResVO put(DataApiReqVO reqVO) { - return send(reqVO, HttpMethod.PUT); - } - - /** - * 수정 - * - * @param reqVO - * @return - */ - public DataApiResVO post(DataApiReqVO reqVO) { - return send(reqVO, HttpMethod.POST); - } - - /** - * 삭제 - * - * @param reqVO - * @return - */ - public DataApiResVO delete (DataApiReqVO reqVO) { - return send(reqVO, HttpMethod.DELETE); - } - - /** - * 실제 RESTful API 서버로 요청을 전송하고, 응답받은 자료를 응답VO에 담아서 리턴한다. - * - * @param reqVO - * @param method - * @return - */ - public DataApiResVO send(DataApiReqVO reqVO, HttpMethod method) { - - DataApiResVO resVO = null; - - try { - //----------------------------------- - // 입력값 검증작업 - //----------------------------------- - resVO = DataApiInterface.checkReqCommonParams(reqVO); - if(resVO != null) return resVO; - if(method == null) return new DataApiResVO("ERR_NO_METHOD", "HTTP 요청 Method가 유효하지 않습니다."); - - //----------------------------------- - // 폼 파라메터 생성 작업 - //----------------------------------- - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); - MultiValueMap parameters = DataApiInterface.makeParamMap(reqVO); - HttpEntity> requestEntity = new HttpEntity(parameters, headers); - - //----------------------------------- - // 요청 처리 - //----------------------------------- - RestTemplate restTemplate = new RestTemplate(); - String url = DAPI_SERVER_PROTOCOL + "://" + DAPI_SERVER_IP + ("80".equals(DAPI_SERVER_PORT) ? "" : ":" + DAPI_SERVER_PORT) + reqVO.getReqUrl(); - log.debug("REQ URL : " + reqVO.getReqUrl()); - - ResponseEntity responseEntity = restTemplate.exchange(url, method, requestEntity, String.class); - - //----------------------------------- - // 응답 처리 - //----------------------------------- - HttpStatus statusCode = responseEntity.getStatusCode(); - log.debug("RES StatusCode : " + statusCode); - String resultXML = ""; - resultXML = responseEntity.getBody(); - log.debug("RES resultXML : " + resultXML); - - // 응답 자료 객체화 - resVO = DataApiInterface.convertXmlToResVO(resultXML); - - // 처리결과 코드 확인 - if(StringUtil.isEmpty(resVO.getResultCode())) { - if (statusCode == HttpStatus.OK) { - resVO.setResultCode("S_HTTP_STATUS_OK"); - resVO.setResultMessage("정상처리되었습니다."); - } else { - resVO.setResultCode("E_STATUS_CODE_FAIL"); - resVO.setResultMessage(String.format("처리에 실패하였습니다. (HTTP상태코드 : %s)", statusCode.toString())); - } - } - - //log.debug("RES resVO : " + resVO); - - } catch(Exception e) { - e.printStackTrace(); - return DataApiInterface.makeErrorRes("E_REQ_EXCEPTION", e.toString()); - } - - return resVO; - } - - -} +package nlib.restful.service.impl; + +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.util.MultiValueMap; +import org.springframework.web.client.RestTemplate; + +import nlib.restful.service.DataApiReqVO; +import nlib.restful.service.DataApiResVO; +import nlib.restful.service.DataApiInterface; +import nlib.util.StringUtil; + +/** + *
+ * @Class Name : DataApiRESTful.java
+ * 
+ * @Description : 통합자료관리시스템에 RESTful API를 통해 질의/응답을 처리한다.
+ * 
+ * 
+ * @프로젝트명: 지방문화원 통합자료관리시스템 구축사업 (2021)
+ *
+ * 
+ * + * @ ------------ -------- --------------------------- + * @ 수정일 수정자 수정내용 + * @ ------------ -------- --------------------------- + * @ 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; + + + /** + * 조회 + * + * @param reqVO + * @return + */ + public DataApiResVO get(DataApiReqVO reqVO) { + + return send(reqVO, HttpMethod.GET); + } + + /** + * 등록 + * + * @param reqVO + * @return + */ + public DataApiResVO put(DataApiReqVO reqVO) { + return send(reqVO, HttpMethod.PUT); + } + + /** + * 수정 + * + * @param reqVO + * @return + */ + public DataApiResVO post(DataApiReqVO reqVO) { + return send(reqVO, HttpMethod.POST); + } + + /** + * 삭제 + * + * @param reqVO + * @return + */ + public DataApiResVO delete (DataApiReqVO reqVO) { + return send(reqVO, HttpMethod.DELETE); + } + + /** + * 실제 RESTful API 서버로 요청을 전송하고, 응답받은 자료를 응답VO에 담아서 리턴한다. + * + * @param reqVO + * @param method + * @return + */ + public DataApiResVO send(DataApiReqVO reqVO, HttpMethod method) { + + DataApiResVO resVO = null; + + try { + //----------------------------------- + // 입력값 검증작업 + //----------------------------------- + resVO = DataApiInterface.checkReqCommonParams(reqVO); + if(resVO != null) return resVO; + if(method == null) return new DataApiResVO("ERR_NO_METHOD", "HTTP 요청 Method가 유효하지 않습니다."); + + //----------------------------------- + // 폼 파라메터 생성 작업 + //----------------------------------- + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); + MultiValueMap parameters = DataApiInterface.makeParamMap(reqVO); + HttpEntity> requestEntity = new HttpEntity(parameters, headers); + + //----------------------------------- + // 요청 처리 + //----------------------------------- + RestTemplate restTemplate = new RestTemplate(); + String url = DAPI_SERVER_PROTOCOL + "://" + DAPI_SERVER_IP + ("80".equals(DAPI_SERVER_PORT) ? "" : ":" + DAPI_SERVER_PORT) + reqVO.getReqUrl(); + log.debug("REQ URL : " + reqVO.getReqUrl()); + + ResponseEntity responseEntity = restTemplate.exchange(url, method, requestEntity, String.class); + + //----------------------------------- + // 응답 처리 + //----------------------------------- + HttpStatus statusCode = responseEntity.getStatusCode(); + log.debug("RES StatusCode : " + statusCode); + String resultXML = ""; + resultXML = responseEntity.getBody(); + log.debug("RES resultXML : " + resultXML); + + // 응답 자료 객체화 + resVO = DataApiInterface.convertXmlToResVO(resultXML); + + // 처리결과 코드 확인 + if(StringUtil.isEmpty(resVO.getResultCode())) { + if (statusCode == HttpStatus.OK) { + resVO.setResultCode("S_HTTP_STATUS_OK"); + resVO.setResultMessage("정상처리되었습니다."); + } else { + resVO.setResultCode("E_STATUS_CODE_FAIL"); + resVO.setResultMessage(String.format("처리에 실패하였습니다. (HTTP상태코드 : %s)", statusCode.toString())); + } + } + + //log.debug("RES resVO : " + resVO); + + } catch(Exception e) { + e.printStackTrace(); + return DataApiInterface.makeErrorRes("E_REQ_EXCEPTION", e.toString()); + } + + return resVO; + } + + +} diff --git a/src/main/java/nlib/restful/service/impl/DataApiTempXml.java b/src/main/java/nlib/restful/service/impl/DataApiTempXml.java index e0b0387b..8f3eda72 100644 --- a/src/main/java/nlib/restful/service/impl/DataApiTempXml.java +++ b/src/main/java/nlib/restful/service/impl/DataApiTempXml.java @@ -1,216 +1,216 @@ -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.HttpEntity; -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.dataformat.xml.XmlMapper; - -import nlib.restful.service.DataApiReqVO; -import nlib.restful.service.DataApiResVO; -import nlib.restful.service.DataApiServerResponseVO; -import nlib.restful.service.DataApiInterface; -import nlib.util.StringUtil; - -/** - *
- * @Class Name : DataApiTempXml.java
- * 
- * @Description : DataAPI의 요청에 대해서 로컬의 테스트용 XML 파일을 읽어서 응답을 처리한다. (자체 선개발 진행용) 
- * 
- * 
- * @프로젝트명: 지방문화원 통합자료관리시스템 구축사업 (2021)
- *
- * 
- * - * @ ------------ -------- --------------------------- - * @ 수정일 수정자 수정내용 - * @ ------------ -------- --------------------------- - * @ 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; - - - /** - * 조회 - * - * @param reqVO - * @return - */ - public DataApiResVO get(DataApiReqVO reqVO) { - - return send(reqVO, HttpMethod.GET); - } - - /** - * 등록 - * - * @param reqVO - * @return - */ - public DataApiResVO put(DataApiReqVO reqVO) { - return send(reqVO, HttpMethod.PUT); - } - - /** - * 수정 - * - * @param reqVO - * @return - */ - public DataApiResVO post(DataApiReqVO reqVO) { - return send(reqVO, HttpMethod.POST); - } - - /** - * 삭제 - * - * @param reqVO - * @return - */ - public DataApiResVO delete (DataApiReqVO reqVO) { - return send(reqVO, HttpMethod.DELETE); - } - - /** - * 실제 RESTful API 서버로 요청을 전송하고, 응답받은 자료를 응답VO에 담아서 리턴한다. - * - * @param reqVO - * @param method - * @return - */ - public DataApiResVO send(DataApiReqVO reqVO, HttpMethod method) { - - DataApiResVO resVO = null; - - try { - //----------------------------------- - // 입력값 검증작업 - //----------------------------------- - resVO = DataApiInterface.checkReqCommonParams(reqVO); - if(resVO != null) return resVO; - if(method == null) return new DataApiResVO("ERR_NO_METHOD", "HTTP 요청 Method가 유효하지 않습니다."); - - //----------------------------------- - // 폼 파라메터 생성 작업 - //----------------------------------- - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); - MultiValueMap parameters = DataApiInterface.makeParamMap(reqVO); - HttpEntity> requestEntity = new HttpEntity(parameters, headers); - - //----------------------------------- - // 응답 처리 - //----------------------------------- - HttpStatus statusCode = HttpStatus.OK; - String resultXML = getTempDataFromXmlFile(reqVO, method); - log.debug("RES resultXML : " + resultXML); - - // 응답 자료 객체화 - resVO = DataApiInterface.convertXmlToResVO(resultXML); - - // 처리결과 코드 확인 - if(StringUtil.isEmpty(resVO.getResultCode())) { - if (statusCode == HttpStatus.OK) { - resVO.setResultCode("S_HTTP_STATUS_OK"); - resVO.setResultMessage("정상처리되었습니다."); - } else { - resVO.setResultCode("E_STATUS_CODE_FAIL"); - resVO.setResultMessage(String.format("처리에 실패하였습니다. (HTTP상태코드 : %s)", statusCode.toString())); - } - } - - //log.debug("RES resVO : " + resVO); - - } catch(Exception e) { - e.printStackTrace(); - return DataApiInterface.makeErrorRes("E_REQ_EXCEPTION", e.toString()); - } - - return resVO; - } - - /** - * 요청 URI와 메소드를 기반으로 임시 응답 XML 파일을 찾아서 내용을 문자열로 리턴한다. - * - * @param reqVO - * @param method - * @return - * @throws Exception - */ - private String getTempDataFromXmlFile(DataApiReqVO reqVO, HttpMethod method) throws Exception { - - 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("result").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()); - e.printStackTrace(); - - resVO = new DataApiServerResponseVO("-22", String.format("%s 파일을 읽는 중 오류가 발생하였습니다(%s). ",xmlPath, e.toString())); - XmlMapper mapper = new XmlMapper(); - returnXmlStr = mapper.writer().withRootName("result").writeValueAsString(resVO); - } - - } - - log.info("RESUTN XML STR : " + returnXmlStr); - return returnXmlStr; - } - -} +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.HttpEntity; +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.dataformat.xml.XmlMapper; + +import nlib.restful.service.DataApiReqVO; +import nlib.restful.service.DataApiResVO; +import nlib.restful.service.DataApiServerResponseVO; +import nlib.restful.service.DataApiInterface; +import nlib.util.StringUtil; + +/** + *
+ * @Class Name : DataApiTempXml.java
+ * 
+ * @Description : DataAPI의 요청에 대해서 로컬의 테스트용 XML 파일을 읽어서 응답을 처리한다. (자체 선개발 진행용) 
+ * 
+ * 
+ * @프로젝트명: 지방문화원 통합자료관리시스템 구축사업 (2021)
+ *
+ * 
+ * + * @ ------------ -------- --------------------------- + * @ 수정일 수정자 수정내용 + * @ ------------ -------- --------------------------- + * @ 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; + + + /** + * 조회 + * + * @param reqVO + * @return + */ + public DataApiResVO get(DataApiReqVO reqVO) { + + return send(reqVO, HttpMethod.GET); + } + + /** + * 등록 + * + * @param reqVO + * @return + */ + public DataApiResVO put(DataApiReqVO reqVO) { + return send(reqVO, HttpMethod.PUT); + } + + /** + * 수정 + * + * @param reqVO + * @return + */ + public DataApiResVO post(DataApiReqVO reqVO) { + return send(reqVO, HttpMethod.POST); + } + + /** + * 삭제 + * + * @param reqVO + * @return + */ + public DataApiResVO delete (DataApiReqVO reqVO) { + return send(reqVO, HttpMethod.DELETE); + } + + /** + * 실제 RESTful API 서버로 요청을 전송하고, 응답받은 자료를 응답VO에 담아서 리턴한다. + * + * @param reqVO + * @param method + * @return + */ + public DataApiResVO send(DataApiReqVO reqVO, HttpMethod method) { + + DataApiResVO resVO = null; + + try { + //----------------------------------- + // 입력값 검증작업 + //----------------------------------- + resVO = DataApiInterface.checkReqCommonParams(reqVO); + if(resVO != null) return resVO; + if(method == null) return new DataApiResVO("ERR_NO_METHOD", "HTTP 요청 Method가 유효하지 않습니다."); + + //----------------------------------- + // 폼 파라메터 생성 작업 + //----------------------------------- + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); + MultiValueMap parameters = DataApiInterface.makeParamMap(reqVO); + HttpEntity> requestEntity = new HttpEntity(parameters, headers); + + //----------------------------------- + // 응답 처리 + //----------------------------------- + HttpStatus statusCode = HttpStatus.OK; + String resultXML = getTempDataFromXmlFile(reqVO, method); + log.debug("RES resultXML : " + resultXML); + + // 응답 자료 객체화 + resVO = DataApiInterface.convertXmlToResVO(resultXML); + + // 처리결과 코드 확인 + if(StringUtil.isEmpty(resVO.getResultCode())) { + if (statusCode == HttpStatus.OK) { + resVO.setResultCode("S_HTTP_STATUS_OK"); + resVO.setResultMessage("정상처리되었습니다."); + } else { + resVO.setResultCode("E_STATUS_CODE_FAIL"); + resVO.setResultMessage(String.format("처리에 실패하였습니다. (HTTP상태코드 : %s)", statusCode.toString())); + } + } + + //log.debug("RES resVO : " + resVO); + + } catch(Exception e) { + e.printStackTrace(); + return DataApiInterface.makeErrorRes("E_REQ_EXCEPTION", e.toString()); + } + + return resVO; + } + + /** + * 요청 URI와 메소드를 기반으로 임시 응답 XML 파일을 찾아서 내용을 문자열로 리턴한다. + * + * @param reqVO + * @param method + * @return + * @throws Exception + */ + private String getTempDataFromXmlFile(DataApiReqVO reqVO, HttpMethod method) throws Exception { + + 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("result").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()); + e.printStackTrace(); + + resVO = new DataApiServerResponseVO("-22", String.format("%s 파일을 읽는 중 오류가 발생하였습니다(%s). ",xmlPath, e.toString())); + XmlMapper mapper = new XmlMapper(); + returnXmlStr = mapper.writer().withRootName("result").writeValueAsString(resVO); + } + + } + + log.info("RESUTN XML STR : " + returnXmlStr); + return returnXmlStr; + } + +} diff --git a/src/main/java/nlib/sample/service/SampleDataApiService.java b/src/main/java/nlib/sample/service/SampleDataApiService.java index 6be6c327..ba272f70 100644 --- a/src/main/java/nlib/sample/service/SampleDataApiService.java +++ b/src/main/java/nlib/sample/service/SampleDataApiService.java @@ -1,32 +1,32 @@ -package nlib.sample.service; - -import nlib.restful.service.DataApiReqVO; -import nlib.restful.service.DataApiResVO; - -/** - *
- * @Class Name : SampleDataApiService.java
- * 
- * @Description : RESTful API 호출 샘플
- * 
- * 
- * @프로젝트명: 지방문화원 통합자료관리시스템 구축사업 (2021)
- *
- * 
- * - * @ ------------ -------- --------------------------- - * @ 수정일 수정자 수정내용 - * @ ------------ -------- --------------------------- - * @ 2021. 6. 22. KNKIM 최초 생성 - * - * - * @author 이씨플라자 * DIGITALSHIP KNKIM - * @since 2021. 6. 22. - * @version 1.0 - * - */ -public interface SampleDataApiService { - - public DataApiResVO getSampleInfo(DataApiReqVO reqVO) throws Exception; - -} +package nlib.sample.service; + +import nlib.restful.service.DataApiReqVO; +import nlib.restful.service.DataApiResVO; + +/** + *
+ * @Class Name : SampleDataApiService.java
+ * 
+ * @Description : RESTful API 호출 샘플
+ * 
+ * 
+ * @프로젝트명: 지방문화원 통합자료관리시스템 구축사업 (2021)
+ *
+ * 
+ * + * @ ------------ -------- --------------------------- + * @ 수정일 수정자 수정내용 + * @ ------------ -------- --------------------------- + * @ 2021. 6. 22. KNKIM 최초 생성 + * + * + * @author 이씨플라자 * DIGITALSHIP KNKIM + * @since 2021. 6. 22. + * @version 1.0 + * + */ +public interface SampleDataApiService { + + public DataApiResVO getSampleInfo(DataApiReqVO reqVO) throws Exception; + +} diff --git a/src/main/java/nlib/sample/service/impl/SampleDataApiDAO.java b/src/main/java/nlib/sample/service/impl/SampleDataApiDAO.java index d3f48a58..43c3b769 100644 --- a/src/main/java/nlib/sample/service/impl/SampleDataApiDAO.java +++ b/src/main/java/nlib/sample/service/impl/SampleDataApiDAO.java @@ -1,47 +1,47 @@ -package nlib.sample.service.impl; - -import org.springframework.stereotype.Repository; - -import nlib.restful.DataApi; -import nlib.restful.service.DataApiReqVO; -import nlib.restful.service.DataApiResVO; - -/** - *
- * @Class Name : SampleDataApiDAO.java
- * 
- * @Description : RESTful API 호출 샘플
- * 
- * 
- * @프로젝트명: 지방문화원 통합자료관리시스템 구축사업 (2021)
- *
- * 
- * - * @ ------------ -------- --------------------------- - * @ 수정일 수정자 수정내용 - * @ ------------ -------- --------------------------- - * @ 2021. 6. 22. KNKIM 최초 생성 - * - * - * @author 이씨플라자 * DIGITALSHIP KNKIM - * @since 2021. 6. 22. - * @version 1.0 - * - */ -@Repository("sampleDataApiDAO") -public class SampleDataApiDAO extends DataApi { - - /** - * 주 자원의 URI - */ - public static final String RESOURCE_URI = "/uac/service/exports"; - - public DataApiResVO getSampleInfo(DataApiReqVO reqVO) throws Exception { - - // URI가 다른 경우, 해당 URI 설정 - reqVO.setReqUrl(RESOURCE_URI); - - return get(reqVO); - } - -} +package nlib.sample.service.impl; + +import org.springframework.stereotype.Repository; + +import nlib.restful.DataApi; +import nlib.restful.service.DataApiReqVO; +import nlib.restful.service.DataApiResVO; + +/** + *
+ * @Class Name : SampleDataApiDAO.java
+ * 
+ * @Description : RESTful API 호출 샘플
+ * 
+ * 
+ * @프로젝트명: 지방문화원 통합자료관리시스템 구축사업 (2021)
+ *
+ * 
+ * + * @ ------------ -------- --------------------------- + * @ 수정일 수정자 수정내용 + * @ ------------ -------- --------------------------- + * @ 2021. 6. 22. KNKIM 최초 생성 + * + * + * @author 이씨플라자 * DIGITALSHIP KNKIM + * @since 2021. 6. 22. + * @version 1.0 + * + */ +@Repository("sampleDataApiDAO") +public class SampleDataApiDAO extends DataApi { + + /** + * 주 자원의 URI + */ + public static final String RESOURCE_URI = "/uac/service/exports"; + + public DataApiResVO getSampleInfo(DataApiReqVO reqVO) throws Exception { + + // URI가 다른 경우, 해당 URI 설정 + reqVO.setReqUrl(RESOURCE_URI); + + return get(reqVO); + } + +} diff --git a/src/main/java/nlib/sample/service/impl/SampleDataApiServiceImpl.java b/src/main/java/nlib/sample/service/impl/SampleDataApiServiceImpl.java index 10d87081..ccf9ee1a 100644 --- a/src/main/java/nlib/sample/service/impl/SampleDataApiServiceImpl.java +++ b/src/main/java/nlib/sample/service/impl/SampleDataApiServiceImpl.java @@ -1,44 +1,44 @@ -package nlib.sample.service.impl; - -import javax.annotation.Resource; - -import org.springframework.stereotype.Service; - -import nlib.restful.service.DataApiReqVO; -import nlib.restful.service.DataApiResVO; -import nlib.sample.service.SampleDataApiService; - -/** - *
- * @Class Name : SampleDataApiServiceImpl.java
- * 
- * @Description : RESTful API 호출 샘플
- * 
- * 
- * @프로젝트명: 지방문화원 통합자료관리시스템 구축사업 (2021)
- *
- * 
- * - * @ ------------ -------- --------------------------- - * @ 수정일 수정자 수정내용 - * @ ------------ -------- --------------------------- - * @ 2021. 6. 22. KNKIM 최초 생성 - * - * - * @author 이씨플라자 * DIGITALSHIP KNKIM - * @since 2021. 6. 22. - * @version 1.0 - * - */ -@Service("sampleDataApiService") -public class SampleDataApiServiceImpl implements SampleDataApiService { - - /** SampleDataApiDAO */ - @Resource(name = "sampleDataApiDAO") - private SampleDataApiDAO sampleDataApiDAO; - - public DataApiResVO getSampleInfo(DataApiReqVO reqVO) throws Exception { - return sampleDataApiDAO.getSampleInfo(reqVO); - } - -} +package nlib.sample.service.impl; + +import javax.annotation.Resource; + +import org.springframework.stereotype.Service; + +import nlib.restful.service.DataApiReqVO; +import nlib.restful.service.DataApiResVO; +import nlib.sample.service.SampleDataApiService; + +/** + *
+ * @Class Name : SampleDataApiServiceImpl.java
+ * 
+ * @Description : RESTful API 호출 샘플
+ * 
+ * 
+ * @프로젝트명: 지방문화원 통합자료관리시스템 구축사업 (2021)
+ *
+ * 
+ * + * @ ------------ -------- --------------------------- + * @ 수정일 수정자 수정내용 + * @ ------------ -------- --------------------------- + * @ 2021. 6. 22. KNKIM 최초 생성 + * + * + * @author 이씨플라자 * DIGITALSHIP KNKIM + * @since 2021. 6. 22. + * @version 1.0 + * + */ +@Service("sampleDataApiService") +public class SampleDataApiServiceImpl implements SampleDataApiService { + + /** SampleDataApiDAO */ + @Resource(name = "sampleDataApiDAO") + private SampleDataApiDAO sampleDataApiDAO; + + public DataApiResVO getSampleInfo(DataApiReqVO reqVO) throws Exception { + return sampleDataApiDAO.getSampleInfo(reqVO); + } + +} diff --git a/src/main/java/nlib/sample/web/SampleDataApiController.java b/src/main/java/nlib/sample/web/SampleDataApiController.java index b8a9cca4..96c8fd09 100644 --- a/src/main/java/nlib/sample/web/SampleDataApiController.java +++ b/src/main/java/nlib/sample/web/SampleDataApiController.java @@ -1,85 +1,85 @@ -package nlib.sample.web; - -import java.util.Map; - -import javax.annotation.Resource; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; - -import nlib.restful.service.DataApiReqVO; -import nlib.restful.service.DataApiResVO; -import nlib.sample.service.SampleDataApiService; - -/** - *
- * @Class Name : SampleDataApiController.java
- * 
- * @Description : RESTful API 호출 샘플
- * 
- * 
- * @프로젝트명: 지방문화원 통합자료관리시스템 구축사업 (2021)
- *
- * 
- * - * @ ------------ -------- --------------------------- - * @ 수정일 수정자 수정내용 - * @ ------------ -------- --------------------------- - * @ 2021. 6. 22. KNKIM 최초 생성 - * - * - * @author 이씨플라자 * DIGITALSHIP KNKIM - * @since 2021. 6. 22. - * @version 1.0 - * - */ -@Controller -public class SampleDataApiController { - - /** SampleDataApiService */ - @Resource(name = "sampleDataApiService") - private SampleDataApiService sampleDataApiService; - - - /* DataApi 접속 서버 정보 */ - @Value("#{properties['dataapi.server.ip']}") - private String dataapiServerIp; - - @Value("#{properties['dataapi.server.port']}") - private String dataapiServerPort; - - @Value("#{properties['dataapi.server.protocol']}") - private String dataapiServerProtocol; - - - @RequestMapping("/sample/getSampleInfoForm.do") - public String getSampleInfoForm(ModelMap model) throws Exception { - - model.addAttribute("serverProtocol", dataapiServerIp); - model.addAttribute("serverIp", dataapiServerPort); - model.addAttribute("serverPort", dataapiServerProtocol); - return "nlib/sample/getSampleInfoForm"; - } - - @RequestMapping("/sample/getSampleInfo.do") - public String getSampleInfo(@RequestParam Map commandMap, ModelMap model) throws Exception { - - String authKey = (String) commandMap.get("authKey"); - String page = (String) commandMap.get("page"); - String rows = (String) commandMap.get("rows"); - - DataApiReqVO reqVO = new DataApiReqVO(); - reqVO.setAuthKey(authKey); - reqVO.setPageNo(page); - reqVO.setPageRows(rows); - - DataApiResVO resVO = sampleDataApiService.getSampleInfo(reqVO); - model.addAttribute("result", resVO); - - return "nlib/sample/getSampleInfo"; - } - -} +package nlib.sample.web; + +import java.util.Map; + +import javax.annotation.Resource; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; + +import nlib.restful.service.DataApiReqVO; +import nlib.restful.service.DataApiResVO; +import nlib.sample.service.SampleDataApiService; + +/** + *
+ * @Class Name : SampleDataApiController.java
+ * 
+ * @Description : RESTful API 호출 샘플
+ * 
+ * 
+ * @프로젝트명: 지방문화원 통합자료관리시스템 구축사업 (2021)
+ *
+ * 
+ * + * @ ------------ -------- --------------------------- + * @ 수정일 수정자 수정내용 + * @ ------------ -------- --------------------------- + * @ 2021. 6. 22. KNKIM 최초 생성 + * + * + * @author 이씨플라자 * DIGITALSHIP KNKIM + * @since 2021. 6. 22. + * @version 1.0 + * + */ +@Controller +public class SampleDataApiController { + + /** SampleDataApiService */ + @Resource(name = "sampleDataApiService") + private SampleDataApiService sampleDataApiService; + + + /* DataApi 접속 서버 정보 */ + @Value("#{properties['dataapi.server.ip']}") + private String dataapiServerIp; + + @Value("#{properties['dataapi.server.port']}") + private String dataapiServerPort; + + @Value("#{properties['dataapi.server.protocol']}") + private String dataapiServerProtocol; + + + @RequestMapping("/sample/getSampleInfoForm.do") + public String getSampleInfoForm(ModelMap model) throws Exception { + + model.addAttribute("serverProtocol", dataapiServerIp); + model.addAttribute("serverIp", dataapiServerPort); + model.addAttribute("serverPort", dataapiServerProtocol); + return "nlib/sample/getSampleInfoForm"; + } + + @RequestMapping("/sample/getSampleInfo.do") + public String getSampleInfo(@RequestParam Map commandMap, ModelMap model) throws Exception { + + String authKey = (String) commandMap.get("authKey"); + String page = (String) commandMap.get("page"); + String rows = (String) commandMap.get("rows"); + + DataApiReqVO reqVO = new DataApiReqVO(); + reqVO.setAuthKey(authKey); + reqVO.setPageNo(page); + reqVO.setPageRows(rows); + + DataApiResVO resVO = sampleDataApiService.getSampleInfo(reqVO); + model.addAttribute("result", resVO); + + return "nlib/sample/getSampleInfo"; + } + +} diff --git a/src/main/java/nlib/sample/web/SampleEncoderController.java b/src/main/java/nlib/sample/web/SampleEncoderController.java index fcfee737..05a08d9f 100644 --- a/src/main/java/nlib/sample/web/SampleEncoderController.java +++ b/src/main/java/nlib/sample/web/SampleEncoderController.java @@ -1,108 +1,108 @@ -package nlib.sample.web; - -import javax.annotation.Resource; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; - -import egovframework.rte.fdl.cryptography.EgovEnvCryptoService; -import egovframework.rte.fdl.cryptography.EgovPasswordEncoder; -import egovframework.rte.fdl.cryptography.impl.EgovARIACryptoServiceImpl; -import nlib.cmm.crypto.AriaCrypto; -import nlib.util.StringUtil; - -/** - *
- * @Class Name : SampleEncoderController.java
- * 
- * @Description : 비밀번호 등 인코딩값 조회/생성
- * 
- * 
- * @프로젝트명: 지방문화원 통합자료관리시스템 구축사업 (2021)
- *
- * 
- * - * @ ------------ -------- --------------------------- - * @ 수정일 수정자 수정내용 - * @ ------------ -------- --------------------------- - * @ 2021. 7. 8. KNKIM 최초 생성 - * - * - * @author 이씨플라자 * DIGITALSHIP KNKIM - * @since 2021. 7. 8. - * @version 1.0 - * - */ -@Controller -public class SampleEncoderController { - - private static final Logger log = LoggerFactory.getLogger(SampleEncoderController.class); - - /** 암호화서비스 */ - @Resource(name = "egovEnvCryptoService") - EgovEnvCryptoService cryptoService; - - @Resource(name = "egovEnvPasswordEncoderService") - EgovPasswordEncoder egovPasswordEncoder; - - - @Resource(name = "ariaCrypto") - AriaCrypto ariaCrypto; - - @Value("#{properties['dataapi.server.ip']}") - private String dataapiServerIp; - - @RequestMapping("/sample/password/getSampleEncoder.do") - public String getSampleInfoForm(ModelMap model - , @RequestParam(required=false) String hash - , @RequestParam(required=false) String plainText - , @RequestParam(required=false) String key - ) throws Exception { - - String msg = null; - String encodedText = null; - String decodedText = null; - - if(StringUtil.isEmpty(hash)) { - msg = "암호화 알고리즘을 선택하여 주시기 바랍니다."; - } else if(StringUtil.isEmpty(plainText)) { - msg = "암호화할 문자열을 입력하여 주시기 바랍니다."; - } else { - - log.debug("암호화 처리 시작 =" + plainText + "="); - - if("sha-256".equals(hash)) { - encodedText = egovPasswordEncoder.encryptPassword(plainText); - } else if("aria".equals(hash)) { - - if(StringUtil.isEmpty(key)) encodedText = ariaCrypto.encode(plainText); - else encodedText = ariaCrypto.encode(plainText, key); - - log.debug(" Aria plainText=" + plainText); - log.debug(" Aria encodedText=" + encodedText); - - if(StringUtil.isEmpty(key)) decodedText = ariaCrypto.decode(encodedText); - else decodedText = ariaCrypto.decode(encodedText, key); - - log.debug(" Aria after decoding, decodedText=" + decodedText); - } else { - msg = "암호화 알고리즘이 적합하지 않습니다."; - } - } - - model.addAttribute("msg", msg); - model.addAttribute("hash", hash); - model.addAttribute("plainText", plainText); - model.addAttribute("encodedText", encodedText); - model.addAttribute("decodedText", decodedText); - model.addAttribute("key", key); - - return "nlib/sample/getSampleEncoder"; - } - -} +package nlib.sample.web; + +import javax.annotation.Resource; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; + +import egovframework.rte.fdl.cryptography.EgovEnvCryptoService; +import egovframework.rte.fdl.cryptography.EgovPasswordEncoder; +import egovframework.rte.fdl.cryptography.impl.EgovARIACryptoServiceImpl; +import nlib.cmm.crypto.AriaCrypto; +import nlib.util.StringUtil; + +/** + *
+ * @Class Name : SampleEncoderController.java
+ * 
+ * @Description : 비밀번호 등 인코딩값 조회/생성
+ * 
+ * 
+ * @프로젝트명: 지방문화원 통합자료관리시스템 구축사업 (2021)
+ *
+ * 
+ * + * @ ------------ -------- --------------------------- + * @ 수정일 수정자 수정내용 + * @ ------------ -------- --------------------------- + * @ 2021. 7. 8. KNKIM 최초 생성 + * + * + * @author 이씨플라자 * DIGITALSHIP KNKIM + * @since 2021. 7. 8. + * @version 1.0 + * + */ +@Controller +public class SampleEncoderController { + + private static final Logger log = LoggerFactory.getLogger(SampleEncoderController.class); + + /** 암호화서비스 */ + @Resource(name = "egovEnvCryptoService") + EgovEnvCryptoService cryptoService; + + @Resource(name = "egovEnvPasswordEncoderService") + EgovPasswordEncoder egovPasswordEncoder; + + + @Resource(name = "ariaCrypto") + AriaCrypto ariaCrypto; + + @Value("#{properties['dataapi.server.ip']}") + private String dataapiServerIp; + + @RequestMapping("/sample/password/getSampleEncoder.do") + public String getSampleInfoForm(ModelMap model + , @RequestParam(required=false) String hash + , @RequestParam(required=false) String plainText + , @RequestParam(required=false) String key + ) throws Exception { + + String msg = null; + String encodedText = null; + String decodedText = null; + + if(StringUtil.isEmpty(hash)) { + msg = "암호화 알고리즘을 선택하여 주시기 바랍니다."; + } else if(StringUtil.isEmpty(plainText)) { + msg = "암호화할 문자열을 입력하여 주시기 바랍니다."; + } else { + + log.debug("암호화 처리 시작 =" + plainText + "="); + + if("sha-256".equals(hash)) { + encodedText = egovPasswordEncoder.encryptPassword(plainText); + } else if("aria".equals(hash)) { + + if(StringUtil.isEmpty(key)) encodedText = ariaCrypto.encode(plainText); + else encodedText = ariaCrypto.encode(plainText, key); + + log.debug(" Aria plainText=" + plainText); + log.debug(" Aria encodedText=" + encodedText); + + if(StringUtil.isEmpty(key)) decodedText = ariaCrypto.decode(encodedText); + else decodedText = ariaCrypto.decode(encodedText, key); + + log.debug(" Aria after decoding, decodedText=" + decodedText); + } else { + msg = "암호화 알고리즘이 적합하지 않습니다."; + } + } + + model.addAttribute("msg", msg); + model.addAttribute("hash", hash); + model.addAttribute("plainText", plainText); + model.addAttribute("encodedText", encodedText); + model.addAttribute("decodedText", decodedText); + model.addAttribute("key", key); + + return "nlib/sample/getSampleEncoder"; + } + +}