최초 커밋

master
mjkhan21 1 year ago
commit 700819073b

@ -0,0 +1,147 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cokr.xit.interfaces</groupId>
<artifactId>xit-public-info</artifactId>
<version>23.04.01-SNAPSHOT</version>
<packaging>jar</packaging>
<name>xit-public-info</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>17</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
</properties>
<repositories>
<repository>
<id>mvn2s</id>
<url>https://repo1.maven.org/maven2/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>egovframe</id>
<url>https://maven.egovframe.go.kr/maven/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>maven-public</id>
<url>https://nas.xit.co.kr:8888/repository/maven-public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>cokr.xit.interfaces</groupId>
<artifactId>xit-gpki</artifactId>
<version>23.04.01-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>2.7.2</version>
</dependency>
</dependencies>
<build>
<defaultGoal>install</defaultGoal>
<directory>${basedir}/target</directory>
<finalName>${artifactId}-${version}</finalName>
<resources>
<resource><directory>${basedir}/src/main/resources</directory></resource>
</resources>
<testResources>
<testResource><directory>${basedir}/src/test/resources</directory></testResource>
<testResource><directory>${basedir}/src/main/resources</directory></testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<includes>
<include>**/*.class</include>
</includes>
</configuration>
</plugin>
<!-- EMMA -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<skipTests>true</skipTests>
<reportFormat>xml</reportFormat>
<excludes>
<exclude>**/Abstract*.java</exclude>
<exclude>**/*Suite.java</exclude>
</excludes>
<includes>
<include>**/*Test.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>emma-maven-plugin</artifactId>
<inherited>true</inherited>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Javadoc -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
</plugin>
</plugins>
</build>
<!-- Nexus deploy -->
<distributionManagement>
<snapshotRepository>
<id>maven-snapshot</id>
<url>https://nas.xit.co.kr:8888/repository/maven-snapshots/</url>
</snapshotRepository>
<repository>
<id>maven-release</id>
<url>https://nas.xit.co.kr:8888/repository/maven-releases/</url>
</repository>
</distributionManagement>
<!-- Nexus deploy -->
</project>

@ -0,0 +1,139 @@
package cokr.xit.interfaces.publicinfo;
import java.util.LinkedHashMap;
import java.util.Map;
import org.springframework.core.io.ClassPathResource;
import com.fasterxml.jackson.core.type.TypeReference;
import cokr.xit.foundation.Assert;
import cokr.xit.foundation.data.JSON;
public class Configuration {
private static final LinkedHashMap<String, Configuration> confs;
static {
try {
ClassPathResource res = new ClassPathResource("intf-conf/public-info.conf");
confs = new JSON().parse(res.getInputStream(), new TypeReference<LinkedHashMap<String, Configuration>>() {});
confs.forEach((k, v) -> v.name = k);
} catch (Exception e) {
throw Assert.runtimeException(e);
}
}
public static final Map<String, Configuration> get() {
return confs;
}
public static final Configuration get(String name) {
return Assert.notEmpty(confs.get(name), name);
}
private String
name,
/** 행정정보 공동이용 서비스가 발급한 api key */
apiKey,
/** 서비스 api url */
apiUrl,
/** 이용기관 gpki server id */
userServerId,
/** 보유기관 gpki server id */
providerServerId;
private boolean
/** 데이터 암복호화 사용 여부 */
gpki,
/** 보유기관 가상 데이터 사용 여부 */
mock;
public String getName() {
return name;
}
/** api key .
* @return apiKey
*/
public String getApiKey() {
return apiKey;
}
/** api key .
* @param apiKey apiKey
*/
public void setApiKey(String apiKey) {
this.apiKey = apiKey;
}
/** api url .
* @return api url
*/
public String getApiUrl() {
return apiUrl;
}
/** api url .
* @param apiUrl api url
*/
public void setApiUrl(String apiUrl) {
this.apiUrl = apiUrl;
}
/** gpki server id .
* @return gpki server id
*/
public String getUserServerId() {
return userServerId;
}
/** gpki server id .
* @param userServerId gpki server id
*/
public void setUserServerId(String userServerId) {
this.userServerId = userServerId;
}
/** gpki server id .
* @return gpki server id
*/
public String getProviderServerId() {
return providerServerId;
}
/** gpki server id .
* @param providerServerId gpki server id
*/
public void setProviderServerId(String providerServerId) {
this.providerServerId = providerServerId;
}
/** .
* @return
*/
public boolean isGpki() {
return gpki;
}
/** .
* @param gpki
*/
public void setGpki(boolean gpki) {
this.gpki = gpki;
}
/** .
* @return
*/
public boolean isMock() {
return mock;
}
/** .
* @param mock
*/
public void setMock(boolean mock) {
this.mock = mock;
}
}

@ -0,0 +1,69 @@
package cokr.xit.interfaces.publicinfo;
import java.net.http.HttpResponse;
import cokr.xit.foundation.AbstractComponent;
import cokr.xit.foundation.data.JSON;
import cokr.xit.foundation.web.WebClient;
import cokr.xit.interfaces.gpki.GPKI;
public class ServiceClient extends AbstractComponent {
private JSON json;
private Configuration conf;
private GPKI gpki;
public ServiceClient setConf(String confName) {
conf = Configuration.get(notEmpty(confName, "confName"));
gpki = conf.isGpki() ? new GPKI() : null;
return this;
}
public ServiceClient setJSON(JSON json) {
this.json = json;
return this;
}
public ServiceMessage.Response request(Object... objs) {
if (isEmpty(objs)) return null;
ServiceMessage.Response resp = new ServiceMessage.Response();
try {
HttpResponse<String> hresp = new WebClient().post(req ->
req.uri(conf.getApiUrl())
.json(json)
.header(ServiceMessage.Support.header(conf.getName()))
.bodyData(reqBody(objs))
);
int statusCode = hresp.statusCode();
String body = hresp.body();
log().debug("statusCode: {}", statusCode);
log().debug("body:\n{}", body);
return resp
.setStatus(statusCode)
.setHeaders(hresp.headers().map())
.setBody(200 == statusCode ? respBody(body) : body);
} catch (Exception e) {
return resp.setError(rootCause(e));
}
}
private String reqBody(Object... objs) {
ServiceMessage msg = new ServiceMessage().addData(objs);
String str = json.stringify(msg);
if (gpki != null)
log().debug("request body:\n{}", json.stringify(msg, true));
return gpki == null ? str : gpki.encrypt(conf.getProviderServerId(), str);
}
private String respBody(String str) {
if (gpki == null)
return str;
String body = gpki.decrypt(str);
log().debug("decrypted:\n{}", body);
return body;
}
}

@ -0,0 +1,187 @@
package cokr.xit.interfaces.publicinfo;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Random;
import cokr.xit.foundation.Assert;
/**
* @author mjkhan
*/
public class ServiceMessage {
private List<Object> data;
/**data .
* @return data
*/
public List<Object> getData() {
return Assert.ifEmpty(data, () -> data = new ArrayList<>());
}
/**data .
* @param data data
*/
public void setData(List<Object> data) {
this.data = data;
}
/** .
* @param objs
* @return ServiceMessage
*/
public ServiceMessage addData(Object... objs) {
if (!Assert.isEmpty(objs))
getData().addAll(List.of(objs));
return this;
}
/**
* @author mjkhan
*/
public static class Response {
/** 응답코드 */
private int status;
/** 응답헤더 */
private Map<String, List<String>> headers;
/** 응답본문 */
private String body;
/** 에러 */
private Throwable error;
/** .
* @return
*/
public int getStatus() {
return status;
}
/** .
* @param status
* @return Response
*/
public Response setStatus(int status) {
this.status = status;
return this;
}
/** .
* @return
*/
public Map<String, List<String>> getHeaders() {
return headers;
}
public List<String> getHeader(String name) {
List<String> values = headers != null ? headers.get(name) : null;
return values != null ? values : Collections.emptyList();
}
public String header(String name) {
List<String> values = getHeader(name);
return values.isEmpty() ? values.get(0) : "";
}
/** .
* @param headers
* @return Response
*/
public Response setHeaders(Map<String, List<String>> headers) {
this.headers = headers;
return this;
}
/** .
* @return
*/
public String getBody() {
return body;
}
/** .
* @param body
* @return Response
*/
public Response setBody(String body) {
this.body = body;
return this;
}
public boolean success() {
return error == null && status == 200;
}
/** .
* @return
*/
public Throwable getError() {
return error;
}
/** .
* @param error
* @return Response
*/
public Response setError(Throwable error) {
this.error = error;
return this;
}
}
public static class Support {
private static final SimpleDateFormat dataFormat = new SimpleDateFormat("yyyyMMddHHmmssSSS",Locale.KOREA);
public static final Map<String, String> header(String confName) {
Configuration conf = Configuration.get(confName);
try {
return Map.of(
"api_key", conf.getApiKey(),
"gpki_yn", conf.isGpki() ? "Y" : "N",
"mock_yn", conf.isMock() ? "Y" : "N",
"cert_server_id", conf.getUserServerId(),
"tx_id", txId(),
"SOAPAction", "",
// "Host", InetAddress.getLocalHost().toString(),
"User-Agent", "java-net-httpclient"
);
} catch (Exception e) {
throw Assert.runtimeException(e);
}
}
private static String txId() {
return dataFormat.format(new Date()) + key(8);
}
private static String key(int length) {
char[] chars = new char[length];
Random r = new Random(System.currentTimeMillis());
for (int i = 0; i < length; i++) {
switch (r.nextInt(3)) {
case 0: chars[i] = (char)(r.nextInt(26) + 65); break;
case 1: chars[i] = (char)(r.nextInt(10) + 48); break;
case 2: chars[i] = (char)(r.nextInt(26) + 97); break;
default: chars[i] = (char)r.nextInt(256);
}
}
return String.valueOf(chars);
}
public static String peel(String str) {
String prefix = "\"data\": [";
int pos = str.indexOf(prefix);
if (pos < 0) {
prefix = "\"data\":[";
pos = str.indexOf(prefix);
}
String result = str.substring(pos + prefix.length());
return result.substring(0, result.lastIndexOf("]")).trim();
}
}
}

@ -0,0 +1,25 @@
{
"license": "C:\\GPKI\\Lic", /* 이용기관 GPKI API 라이센스 디렉토리 */
"charset": "UTF-8", /* 문자셋 */
"server": {
"local": "SVR1311000030", /* 이용기관 서버 CN */
"targets": "SVR1500000015" /* 대상기관 서버인증서 아이디, 여러 개일 경우 컴마(,)로 구분 */
},
"ldapUrl": "ldap://10.1.7.118:389/cn=", /* 대상기관 인증서 다운로드를 위한 행정망 LDAP URL */
/*"ldapUrl": "ldap://152.99.57.127:389/cn=", 대상기관 인증서 다운로드를 위한 인터넷망 LDAP URL */
"certDir": "C:\\GPKI\\Certificate\\class1", /* 서버 인증서, 키 저장 디렉토리 */
"env": { /* 이용기관 서버 인증서 */
"certFile": "SVR1311000030_env.cer",
"privateKeyFile": "SVR1311000030_env.key",
"privateKeyPassword": "기후대기3395!"
},
"sig": { /* 이용기관 서버 전자서명 */
"certFile": "SVR1311000030_sig.cer",
"privateKeyFile": "SVR1311000030_sig.key",
"privateKeyPassword": "기후대기3395!"
}
}

@ -0,0 +1,12 @@
{
"basic-info-ext": { /* 자동차 기본정보(연료 제원 포함) 조회 */
"apiKey": "59f26bf09ed196bfbd98210388c4c6ea9dd0f77bde3f35526f082647a305325b", /* 행정정보 공동이용 서비스가 발급한 api key */
/*"apiUrl": "http://10.188.225.25:29001/piss/api/molit/SignguCarBassMatterInqireService", /* 행정정보 운영 url */
"apiUrl": "http://10.188.225.94:29001/piss/api/molit/SignguCarBassMatterInqireService", /* 행정정보 개발 url */
"userServerId": "SVR1311000030", /* 이용기관 gpki server id */
"providerServerId": "SVR1500000015", /* 보유기관 gpki server id */
"gpki": true, /* 데이터 암복호화 사용 여부 */
"mock": false /* 보유기관 가상 데이터 사용 여부 */
}
}

@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
<context:component-scan base-package="cokr.xit">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Component"/>
<context:include-filter type="annotation" expression="org.springframework.stereotype.Service"/>
<context:include-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<bean id="antPathMatcher" class="org.springframework.util.AntPathMatcher" />
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basenames">
<list>
<value>classpath:message/message-common</value>
<value>classpath:message/authentication-message</value>
<value>classpath:org/egovframe/rte/fdl/property/messages/properties</value>
</list>
</property>
<property name="defaultEncoding" value="UTF-8"/>
<property name="cacheSeconds">
<value>60</value>
</property>
</bean>
<bean id="objectMapper" class="com.fasterxml.jackson.databind.ObjectMapper">
<property name="dateFormat" ref="dateFormat"/>
</bean>
<bean id="dateFormat" class="java.text.SimpleDateFormat">
<constructor-arg index="0" value="yyyy-MM-dd HH:mm"/>
</bean>
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
<property name="defaultLocale" value="ko_KR"/>
</bean>
<bean name="propertyService" class="org.egovframe.rte.fdl.property.impl.EgovPropertyServiceImpl" destroy-method="destroy">
<property name="properties">
<map>
<entry key="tempDir" value="D:/workspace/temp"/>
<entry key="pageUnit" value="10"/>
<entry key="pageSize" value="10"/>
</map>
</property>
<property name="extFileName">
<set>
<map>
<entry key="encoding" value="UTF-8"/>
<entry key="filename" value="classpath*:properties/disabled-parking.properties"/>
</map>
</set>
</property>
</bean>
<bean id="leaveaTrace" class="org.egovframe.rte.fdl.cmmn.trace.LeaveaTrace" />
</beans>

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="net.sf.log4jdbc.sql.jdbcapi.DriverSpy"/>
<property name="url" value="jdbc:log4jdbc:mariadb://211.119.124.9:4407/platform?useUnicode=true&amp;characterEncoding=utf8&amp;serverTimezone=Asia/Seoul&amp;useSSL=false" />
<property name="username" value="fimsweb"/>
<property name="password" value="fimsweb!@"/>
<!--
<property name="url" value="jdbc:log4jdbc:mariadb://localhost:3306/xit-base?useUnicode=true&amp;characterEncoding=utf8&amp;serverTimezone=Asia/Seoul&amp;useSSL=false" />
<property name="username" value="root"/>
<property name="password" value="mjkhan"/>
-->
</bean>
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionFactoryBean"
p:dataSource-ref="dataSource"
p:configLocation="classpath:sql/mybatis-config.xml"
p:mapperLocations="classpath:sql/mapper/**/*.xml"
/>
<bean id="mapperConfigurer" class="org.egovframe.rte.psl.dataaccess.mapper.MapperConfigurer">
<property name="basePackage" value="cokr.xit" />
<property name="sqlSessionFactoryBeanName" value="sqlSession"/>
</bean>
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="*" rollback-for="Exception"/>
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="serviceMethod" expression="execution(* cokr.xit..service.bean.*ServiceBean.*(..))" />
<aop:pointcut id="requiredTx" expression="execution(* cokr.xit..service.bean.*ServiceBean.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="requiredTx" />
</aop:config>
</beans>

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cokr.xit.foundation.test.TestMapper">
<insert id="insert" parameterType="map">${sql}</insert>
<update id="update" parameterType="map">${sql}</update>
<delete id="delete" parameterType="map">${sql}</delete>
<update id="commit">COMMIT</update>
</mapper>

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<setting name="mapUnderscoreToCamelCase" value="false"/>
<setting name="cacheEnabled" value="false" />
<setting name="jdbcTypeForNull" value="NULL" />
<setting name="callSettersOnNulls" value="true"/>
</settings>
<typeAliases>
<typeAlias alias="egovMap" type="org.egovframe.rte.psl.dataaccess.util.EgovMap"/>
<typeAlias alias="dataobject" type="cokr.xit.foundation.data.DataObject"/>
</typeAliases>
<typeHandlers>
<typeHandler handler="cokr.xit.foundation.data.RowValueHandler" javaType="java.lang.Object"/>
</typeHandlers>
<plugins>
<plugin interceptor="cokr.xit.foundation.data.paging.PagingSupport" />
</plugins>
</configuration>

@ -0,0 +1,121 @@
package cokr.xit.interfaces.publicinfo;
import java.util.Map;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import cokr.xit.foundation.data.JSON;
import cokr.xit.foundation.test.TestSupport;
public class ConfigurationTest extends TestSupport {
@Test
void get() {
Map<String, Configuration> confs = Configuration.get();
Assertions.assertNotNull(confs);
confs.keySet().forEach(System.out::println);
Configuration conf = Configuration.get("apiName");
Assertions.assertNotNull(conf);
}
@Test
void header() {
ServiceMessage.Support.header("basic-info-ext")
.forEach((k, v) -> System.out.println(String.format("%s = %s", k, v)));
}
@Test
void body() {
Object1 obj1_0 = new Object1();
obj1_0.setId("1_0");
obj1_0.setName("1 zero");
Object2 obj2_0 = new Object2();
obj2_0.setId("2_0");
obj2_0.setName("2 zero");
obj2_0.setPhoneNo("222-2222");
ServiceMessage msg = new ServiceMessage();
msg.getData().add(obj1_0);
msg.getData().add(obj2_0);
JSON json = new JSON();
String str = json.stringify(msg, true);
System.out.println(str);
Object parsed = json.parse(str, ServiceMessage.class);
System.out.println(parsed);
}
public static class Object1 {
private String id;
private String name;
/**id() .
* @return id
*/
public String getId() {
return id;
}
/**id() .
* @param id id
*/
public void setId(String id) {
this.id = id;
}
/**name() .
* @return name
*/
public String getName() {
return name;
}
/**name() .
* @param name name
*/
public void setName(String name) {
this.name = name;
}
}
public static class Object2 {
private String id;
private String name;
private String phoneNo;
/**id() .
* @return id
*/
public String getId() {
return id;
}
/**id() .
* @param id id
*/
public void setId(String id) {
this.id = id;
}
/**name() .
* @return name
*/
public String getName() {
return name;
}
/**name() .
* @param name name
*/
public void setName(String name) {
this.name = name;
}
/**phoneNo() .
* @return phoneNo
*/
public String getPhoneNo() {
return phoneNo;
}
/**phoneNo() .
* @param phoneNo phoneNo
*/
public void setPhoneNo(String phoneNo) {
this.phoneNo = phoneNo;
}
}
}
Loading…
Cancel
Save