우체국 송달 조회 api

This commit is contained in:
LJH 2022-08-10 17:00:38 +09:00
parent 9a2e227a0f
commit e9777871d5

View File

@ -1,11 +1,13 @@
package kcc.kccadr.kccadrCom.web;
import java.io.StringReader;
import java.io.ByteArrayInputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javax.annotation.Resource;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
@ -14,6 +16,8 @@ import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import egovframework.rte.psl.dataaccess.util.EgovMap;
import kcc.com.cmm.util.StringUtil;
@ -24,6 +28,8 @@ import kcc.kccadr.kccadrCom.service.KccadrCommonService;
import kcc.kccadr.kccadrCom.service.KccadrCommonVO;
import kcc.let.utl.fcc.service.EgovCryptoUtil;
/**
* 대국민(사용자)
* 공통 호출 URL controller 클래스를 정의한다.
@ -140,12 +146,77 @@ public class KccadrCommonController {
String dngGi3 = "6892023700222";
String dngGi4 = "6892023557914";
String responDate = PostCheckUtill.PostCheck(dngGi1);
/*JAXBContext context = JAXBContext.newInstance(VO.class);
String responData = PostCheckUtill.PostCheck(dngGi1);
/*Map<String, String> testmap = new HashMap<>();
JAXBContext context = JAXBContext.newInstance(VO.class);
JAXBContext context = JAXBContext.newInstance();
Unmarshaller unmarshaller = context.createUnmarshaller();
(VO) unmarshaller.unmarshal(new StringReader(xmlText));*/
(VO) unmarshaller.unmarshal(new StringReader(responDate));*/
// // 1. 빌더 팩토리 생성.
// DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
// // 2. 빌더 팩토리로부터 빌더 생성
// DocumentBuilder builder = builderFactory.newDocumentBuilder();
// // 3. 빌더를 통해 XML 문서를 파싱해서 Document 객체로 가져온다.
// /*Document document = builder.parse(responDate);*/
// Document document = builder.parse(new InputSource(new StringReader(responData.toString())));
// // 문서 구조 안정화 ?
// document.getDocumentElement().normalize();
// // XML 데이터 <person> 태그의 내용을 가져온다.
// NodeList cmmMsgHeaderList = document.getElementsByTagName("LongitudinalDomesticListResponse");
// NodeList addrseNmList = document.getElementsByTagName("addrseNm");
// NodeList applcntNmList = document.getElementsByTagName("applcntNm");
// // <person> 태그 리스트를 하나씩 돌면서 값들을 가져온다.
// /*for (int i = 0; i < cmmMsgHeaderList.getLength(); ++i) {
// // 속성 가져오기.
// String name = cmmMsgHeaderList.item(i).getAttributes().getNamedItem("responseTime").getNodeValue();
// // <person> 태그의 하위 노드들을 가져온다. ( 여기서 노드는 태그를 의미한다. )
// NodeList childNodes = cmmMsgHeaderList.item(i).getChildNodes();
// for (int j = 0; j < childNodes.ge0tLength(); ++j) {
// if ("responseTime".equals(childNodes.item(j).getNodeName())) {
// System.out.println("responseTime :: " + childNodes.item(j).getNodeValue());
// }
// }
// }*/
// Node addrseNmNode = addrseNmList.item(0);
// System.out.println(addrseNmNode.getNodeValue());
List<HashMap<String, Object>> resultList = new ArrayList<HashMap<String,Object>>();
try {
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(new ByteArrayInputStream(responData.getBytes()));
doc.getDocumentElement().normalize();
NodeList resultNode = doc.getElementsByTagName("LongitudinalDomesticListResponse");
for(int i = 0 ; i < resultNode.getLength(); i ++ ){
NodeList nList = resultNode.item(i).getChildNodes();
HashMap<String, Object> rm = new HashMap<String, Object>();
HashMap<String, Object> hm = new HashMap<String, Object>();
for(int j = 0 ; j < nList.getLength(); j++){
String nodeName = nList.item(j).getNodeName();
String nodeValue = nList.item(j).getTextContent();
hm.put(nodeName, nodeValue);
}
rm.put("LongitudinalDomesticListResponse", hm);
resultList.add(rm);
}
} catch (Exception e) {
e.printStackTrace();
}
for(HashMap<String, Object> tmpList : resultList) {
System.out.println("List :: "+tmpList);
}
return "";
}