feat: mpower

dev
minuk926 2 years ago
parent 24f640d21a
commit 72d5025bd5

@ -229,6 +229,10 @@ dependencies {
//implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.12.5' //implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.12.5'
//-----------------------------------------------------------------------------------// //-----------------------------------------------------------------------------------//
// https://mvnrepository.com/artifact/com.googlecode.juniversalchardet/juniversalchardet
implementation group: 'com.googlecode.juniversalchardet', name: 'juniversalchardet', version: '1.0.3'
//-----------------------------------------------------------------------------------// //-----------------------------------------------------------------------------------//
// Test // Test
//-----------------------------------------------------------------------------------// //-----------------------------------------------------------------------------------//

@ -2,10 +2,12 @@ package com.xit.biz.ctgy.v2.service.impl;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.xit.biz.ctgy.dto.BoardDto; import com.xit.biz.ctgy.dto.BoardDto;
import com.xit.biz.ctgy.dto.JudgeListDto;
import com.xit.biz.ctgy.dto.struct.MinCivBoard680Mapstruct; import com.xit.biz.ctgy.dto.struct.MinCivBoard680Mapstruct;
import com.xit.biz.ctgy.entity.MinCivBoard680; import com.xit.biz.ctgy.entity.MinCivBoard680;
import com.xit.biz.ctgy.repository.IBoardRepository; import com.xit.biz.ctgy.repository.IBoardRepository;
import com.xit.biz.ctgy.v2.service.IBoardService; import com.xit.biz.ctgy.v2.service.IBoardService;
import com.xit.core.config.database.BaseMybatisDaoSupport;
import com.xit.core.constant.ErrorCode; import com.xit.core.constant.ErrorCode;
import com.xit.core.exception.CustomBaseException; import com.xit.core.exception.CustomBaseException;
import com.xit.core.oauth2.utils.HeaderUtil; import com.xit.core.oauth2.utils.HeaderUtil;
@ -13,9 +15,16 @@ import com.xit.core.support.jpa.JpaUtil;
import com.xit.core.util.Checks; import com.xit.core.util.Checks;
import com.xit.core.util.CommUtil; import com.xit.core.util.CommUtil;
import com.xit.core.util.mpower.MpowerUtil; import com.xit.core.util.mpower.MpowerUtil;
import com.xit.core.util.mpower.MpowerUtils;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.mapping.BoundSql;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.data.domain.Example; import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher; import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
@ -24,6 +33,7 @@ import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.nio.charset.Charset;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -35,9 +45,29 @@ import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatc
public class BoardService implements IBoardService { public class BoardService implements IBoardService {
private final PasswordEncoder passwordEncoder; private final PasswordEncoder passwordEncoder;
private final SqlSessionTemplate sqlSessionTemplate;
@Transactional(readOnly = true) @Transactional(readOnly = true)
public List<Map<String, Object>> findAll(final BoardDto dto, Pageable pageable) { public List<Map<String, Object>> findAll(final BoardDto dto, Pageable pageable) {
//MappedStatement ms = sqlSessionFactory.getConfiguration().getMappedStatement("com.xit.biz.ctgy.mapper.IParkingMapper.selectTotParkingJudgeResultGroupByTeamAndChasu");
//SqlSession session = sqlSessionTemplate.getConfiguration().get;
//SqlSession session = sqlSessionTemplate.getConfiguration().getMappedStatement("com.xit.biz.ctgy.mapper.IParkingMapper.selectTotParkingJudgeResultGroupByTeamAndChasu");
JudgeListDto param = new JudgeListDto();
param.setMsChasu(99L);
//param.get
String sql = CommUtil.getMybatisSql(sqlSessionTemplate, "com.xit.biz.ctgy.mapper.IParkingMapper.selectTotParkingJudgeResultGroupByTeamAndChasu", param);
System.out.println(sql);
System.out.println(Charset.defaultCharset().displayName());
//SqlSession sqlSession = SqlMapClient.getSqlSession();
MpowerUtil sendXml = new MpowerUtil(); MpowerUtil sendXml = new MpowerUtil();
String query = "SELECT ci_code ciCode,\n" + String query = "SELECT ci_code ciCode,\n" +
" name ciName,\n" + " name ciName,\n" +

@ -1,10 +1,14 @@
package com.xit.core.config; package com.xit.core.config;
import com.xit.core.config.support.EucKrEncodingFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.filter.OrderedCharacterEncodingFilter; import org.springframework.boot.web.servlet.filter.OrderedCharacterEncodingFilter;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.CharacterEncodingFilter; import org.springframework.web.filter.CharacterEncodingFilter;
import java.nio.charset.StandardCharsets;
/** /**
* UTF-8, encoding EUC-KR ( - -) * UTF-8, encoding EUC-KR ( - -)
* spring.http.encoding.force = false * spring.http.encoding.force = false
@ -13,14 +17,28 @@ import org.springframework.web.filter.CharacterEncodingFilter;
//TODO :: 기본 UTF-8인데, encoding이 EUC-KR로 들어오는 경우가 있는 경우(외부에서 들어오는 - 결재 등 -) 사용 //TODO :: 기본 UTF-8인데, encoding이 EUC-KR로 들어오는 경우가 있는 경우(외부에서 들어오는 - 결재 등 -) 사용
public class EncodingFilterConfig { public class EncodingFilterConfig {
@Bean @Bean
public FilterRegistrationBean encodingFilterBean() { public FilterRegistrationBean<CharacterEncodingFilter> encodingFilterBean() {
FilterRegistrationBean registrationBean = new FilterRegistrationBean(); FilterRegistrationBean<CharacterEncodingFilter> registrationBean = new FilterRegistrationBean<>();
CharacterEncodingFilter filter = new OrderedCharacterEncodingFilter(); CharacterEncodingFilter filter = new OrderedCharacterEncodingFilter();
filter.setForceEncoding(true); filter.setForceEncoding(true);
filter.setEncoding("MS949"); filter.setEncoding("utf-8");
registrationBean.setFilter(filter); registrationBean.setFilter(filter);
registrationBean.addUrlPatterns("/ms949filterUrl/*"); registrationBean.addUrlPatterns("/api/v2/*");
return registrationBean; return registrationBean;
} }
/*
@Bean
public FilterRegistrationBean<EucKrEncodingFilter> encodingFilterBean() {
FilterRegistrationBean<EucKrEncodingFilter> registrationBean = new FilterRegistrationBean<>();
//CharacterEncodingFilter filter = new OrderedCharacterEncodingFilter();
//filter.setForceEncoding(true);
//filter.setEncoding("EUC-KR");
registrationBean.setFilter(new EucKrEncodingFilter());
registrationBean.addUrlPatterns("/api/v2/*");
return registrationBean;
}
*/
} }

@ -0,0 +1,48 @@
package com.xit.core.config.database;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.dao.support.DaoSupport;
import org.springframework.util.Assert;
public abstract class BaseMybatisDaoSupport extends DaoSupport
{
private SqlSession sqlSession;
private SqlSessionFactory sqlSessionFactory;
private boolean extenalSqlSession = false;
public final void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate) {
this.sqlSession = sqlSessionTemplate;
this.extenalSqlSession = true;
}
public final SqlSession getSqlSession() {
return sqlSession;
}
public final void setSqlSession(SqlSession sqlSession) {
this.sqlSession = sqlSession;
}
public final SqlSessionFactory getSqlSessionFactory() {
return sqlSessionFactory;
}
public final void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) {
this.sqlSessionFactory = sqlSessionFactory;
if(!this.extenalSqlSession) {
this.sqlSession = new SqlSessionTemplate(sqlSessionFactory);
}
}
@Override
protected void checkDaoConfig() throws IllegalArgumentException {
Assert.notNull(this.sqlSession, "Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required");
}
}

@ -0,0 +1,11 @@
package com.xit.core.config.support;
import org.springframework.web.filter.CharacterEncodingFilter;
public class EucKrEncodingFilter extends CharacterEncodingFilter {
public EucKrEncodingFilter() {
setEncoding("EUC-KR");
setForceEncoding(true);
}
}

@ -4,6 +4,9 @@ import com.rits.cloning.Cloner;
import eu.bitwalker.useragentutils.UserAgent; import eu.bitwalker.useragentutils.UserAgent;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.mapping.BoundSql;
import org.apache.ibatis.mapping.ParameterMapping;
import org.apache.ibatis.session.SqlSession;
import org.mozilla.universalchardet.UniversalDetector; import org.mozilla.universalchardet.UniversalDetector;
import org.springframework.http.ResponseCookie; import org.springframework.http.ResponseCookie;
import org.springframework.mobile.device.Device; import org.springframework.mobile.device.Device;
@ -18,9 +21,11 @@ import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller; import javax.xml.bind.Unmarshaller;
import java.io.StringReader; import java.io.StringReader;
import java.io.StringWriter; import java.io.StringWriter;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.URL; import java.net.URL;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.*; import java.util.*;
@ -645,6 +650,57 @@ public class CommUtil {
System.out.println(getRanStrKey(16)); System.out.println(getRanStrKey(16));
} }
} }
public static String detectCharset(byte[] bytes) {
UniversalDetector detector = new UniversalDetector(null);
detector.handleData(bytes, 0, bytes.length);
detector.dataEnd();
String detectedCharset = detector.getDetectedCharset();
if (detectedCharset != null && detector.isDone() && Charset.isSupported(detectedCharset)) {
return detectedCharset;
}
return detectedCharset;
}
public static String getMybatisSql(SqlSession sqlSession, String id, Object param) {
BoundSql boundSql = sqlSession.getConfiguration().getMappedStatement(id).getBoundSql(param);
List<ParameterMapping> parameterMappings = new ArrayList<>(boundSql.getParameterMappings());
Map<String, Object> parameters = new HashMap<>();
if (param instanceof Map) {
parameters.putAll((Map) param);
} else {
for (ParameterMapping parameterMapping : parameterMappings) {
try {
String field = parameterMapping.getProperty();
//try {
String methodNm = "get"+field.substring(0,1).toUpperCase()+field.substring(1);
Method method = param.getClass().getMethod(methodNm);
parameters.put(field, method.invoke(param));
//parameters.put(field, param.getClass().getMethod("get"+field.substring(0,1).toUpperCase()+field.substring(1)).invoke(param));
} catch (NoSuchMethodException e) {
e.printStackTrace();
throw new RuntimeException(e);
} catch (InvocationTargetException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
}
String sql = boundSql.getSql();
for (ParameterMapping par : parameterMappings) {
Object parameter = parameters.get(par.getProperty());
if (parameter == null)
sql = sql.replaceFirst("\\?", "NULL");
else
sql = sql.replaceFirst("\\?", "'" + parameter.toString() + "'");
}
return sql;
}
} }

@ -1,5 +1,8 @@
package com.xit.core.util.mpower; package com.xit.core.util.mpower;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.sql.CallableStatement; import java.sql.CallableStatement;
import java.sql.Connection; import java.sql.Connection;
@ -11,7 +14,9 @@ import java.sql.Statement;
import java.util.*; import java.util.*;
import com.plf.client.Client; import com.plf.client.Client;
import com.xit.core.util.CommUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.binary.StringUtils;
@Slf4j @Slf4j
public class MpowerUtil { public class MpowerUtil {
@ -39,7 +44,7 @@ public class MpowerUtil {
static int firstIndex = 0; static int firstIndex = 0;
static int lastIndex = 10; static int lastIndex = 10;
static int recordCountPerPage = 10; static int recordCountPerPage = 10;
static String beforeXml = "<?xml version='1.0' encoding='euc-kr'?><QUERYS DBNAME='"+DbName2+"' DEBUG='true'><QUERY TYPE='select' BATCH='false'><SQL><![CDATA["; static String beforeXml = "<?xml version='1.0' encoding='utf-8'?><QUERYS DBNAME='"+DbName2+"' DEBUG='true'><QUERY TYPE='select' BATCH='false'><SQL><![CDATA[";
static String beforeXmlsp = beforeXml.replace("select", "spcall"); static String beforeXmlsp = beforeXml.replace("select", "spcall");
static String afterXml = "]]></SQL></QUERY></QUERYS>"; static String afterXml = "]]></SQL></QUERY></QUERYS>";
static String afterXmlsp = "]]></SQL>"; static String afterXmlsp = "]]></SQL>";
@ -655,14 +660,27 @@ public class MpowerUtil {
int mListCount = 0; int mListCount = 0;
try { try {
mpower = new Client(hostip,port); mpower = new Client(hostip,port);
mpower.setCryptEnable(false);
mpower.getConnection("MPowerXmlToQuery.xmlQuery1"); mpower.getConnection("MPowerXmlToQuery.xmlQuery1");
mpower.setInput("SQLXML", query); mpower.setInput("SQLXML", query);
mpower.Request(); mpower.Request();
String result = mpower.getString("result", 0, 0); String result = mpower.getString("result", 0, 0);
System.out.println("#######message = "+mpower.getMessage());
String s = mpower.getMessage();
System.out.println("#######message = "+mpower.getFile("list1"));
String s = "답변드립니다";
//System.out.println(CommUtil.detectCharset(s.getBytes()));
System.out.println(URLEncoder.encode(s, "euc-kr"));
System.out.println(URLDecoder.decode(s, "euc-kr"));
String ss = new String("답변드립니다".getBytes("euc-kr"), "euc-kr");
System.out.println(CommUtil.detectCharset(ss.getBytes()));
System.out.println((new String("답변드립니다".getBytes("utf-8"), "euc-kr")));
System.out.println((new String("답변드립니다".getBytes("euc-kr"), "euc-kr")));
// System.out.println(new String(s.getBytes("unicode"), "unicode")); // System.out.println(new String(s.getBytes("unicode"), "unicode"));
// System.out.println(new String(s.getBytes("utf-8"), "utf-8")); // System.out.println(new String(s.getBytes("utf-8"), "utf-8"));
@ -672,19 +690,35 @@ public class MpowerUtil {
// System.out.println(new String(s.getBytes("ms949"), "ms949")); // System.out.println(new String(s.getBytes("ms949"), "ms949"));
// System.out.println(new String(s.getBytes("iso-8859-1"), "iso-8859-1")); // System.out.println(new String(s.getBytes("iso-8859-1"), "iso-8859-1"));
System.out.println(new String(s.getBytes("unicode"), "unicode")); //String originalStr = URLDecoder.decode(mpower.getMessage(), "utf-8");
System.out.println(new String(s.getBytes("utf-8"), "utf-8")); System.out.println(URLDecoder.decode(mpower.getMessage(), "utf-8"));
System.out.println(new String(s.getBytes("utf-16"), "utf-16")); System.out.println(URLDecoder.decode(mpower.getMessage(), "euc-kr"));
System.out.println(new String(s.getBytes("euc-kr"), "euc-kr")); System.out.println(StringUtils.newStringUtf16Le(mpower.getMessage().getBytes()));
System.out.println(new String(s.getBytes("ksc5601"), "ksc5601")); System.out.println(StringUtils.newStringUtf16(mpower.getMessage().getBytes()));
System.out.println(new String(s.getBytes("ms949"), "ms949")); System.out.println(StringUtils.newStringUtf16Be(mpower.getMessage().getBytes()));
System.out.println(new String(s.getBytes("iso-8859-1"), "iso-8859-1")); System.out.println(StringUtils.newStringIso8859_1(mpower.getMessage().getBytes()));
String originalStr = mpower.getMessage();
String [] charSet = {"utf-8","euc-kr","ksc5601","iso-8859-1","x-windows-949", "ms949"};
for (int i=0; i<charSet.length; i++) {
for (int j=0; j<charSet.length; j++) {
try {
System.out.println("[" + charSet[i] +"," + charSet[j] +"] = " + new String(originalStr.getBytes("latin1"), charSet[j]));
}
catch (UnsupportedEncodingException e) {
System.out.println(e.getLocalizedMessage());
}
}
}
//System.out.println(CommUtil.detectCharset(originalStr.getBytes()));
System.out.println("#######data:::result = "+mpower.getData("result"));
System.out.println("#######data:::result = "+mpower.getData("list1"));
System.out.println("#######$$$$$$$$$$$$$$$$$$"+result);
log.debug("#######$$$$$$$$$$$$$$$$$$====>>>>>>"+result);
int row; int row;
if (result.equals("true")){ if (result.equals("true")){
@ -695,8 +729,10 @@ public class MpowerUtil {
Map<String,Object> m = new HashMap<>(); Map<String,Object> m = new HashMap<>();
if(!"".equals(feild) && feild != null){ if(!"".equals(feild) && feild != null){
m.put("cbContent", mpower.getString("list1", i, 4)); m.put("cbContent", mpower.getString("list1", i, 4));
//m.put("cbContent", new String(mpower.getString("list1", i, 4).getBytes("utf-8"), "utf-8"));
}else{ }else{
for(int j=0;j<feilds.size();j++){ for(int j=0;j<feilds.size();j++){
//m.put(feilds.get(j), new String(mpower.getString("list1", i, j).getBytes("utf-8"), "utf-8"));
m.put(feilds.get(j), mpower.getString("list1", i, j)); m.put(feilds.get(j), mpower.getString("list1", i, j));
} }
} }

@ -1,5 +1,8 @@
server: server:
port: 8090 port: 8090
# servlet:
# encoding:
# force-response: true
spring: spring:
config: config:

Loading…
Cancel
Save