init
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
package com.eactive.eai.common.util;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.ConnectException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
public class HttpUtil {
|
||||
|
||||
protected static final Logger logger = Logger.getLogger(HttpUtil.class);
|
||||
|
||||
public static String httpCall(String urlStr, String httpMethod) throws Exception {
|
||||
return httpCall(urlStr, httpMethod, Charset.defaultCharset().toString());
|
||||
}
|
||||
|
||||
public static String httpCall(String urlStr, String httpMethod, String encoding) throws Exception {
|
||||
|
||||
logger.debug("httpCall (" +httpMethod+ ") : " + urlStr);
|
||||
|
||||
StringBuilder result = new StringBuilder();
|
||||
|
||||
try {
|
||||
HttpURLConnection conn = (HttpURLConnection) new URL(urlStr).openConnection();
|
||||
conn.setRequestMethod(httpMethod);
|
||||
BufferedReader rd = null;
|
||||
|
||||
if (conn.getResponseCode() >= 200 && conn.getResponseCode() <= 300) {
|
||||
InputStreamReader inputStreamReader = new InputStreamReader(conn.getInputStream(), encoding);
|
||||
rd = new BufferedReader(inputStreamReader);
|
||||
} else {
|
||||
logger.error(urlStr + " / ResponseCode : " + conn.getResponseCode());
|
||||
return null;
|
||||
}
|
||||
|
||||
String line;
|
||||
|
||||
while ((line = rd.readLine()) != null) {
|
||||
result.append(line);
|
||||
}
|
||||
|
||||
rd.close();
|
||||
conn.disconnect();
|
||||
} catch (ConnectException e) {
|
||||
logger.error(urlStr + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public static String httpCall(String urlStr, String httpMethod, String encoding, Map<String, String> paramMap) throws Exception {
|
||||
|
||||
if(paramMap.size() < 0) {
|
||||
return httpCall(urlStr, httpMethod, encoding);
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(urlStr);
|
||||
sb.append("?");
|
||||
|
||||
paramMap.forEach((k, v) -> {
|
||||
sb.append(k);
|
||||
sb.append("=");
|
||||
sb.append(v);
|
||||
sb.append("&");
|
||||
});
|
||||
|
||||
return httpCall(sb.toString(), httpMethod, encoding);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.eactive.eai.common.util;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
|
||||
public class JdbcTest {
|
||||
|
||||
// String driver = "org.mariadb.jdbc.Driver";
|
||||
// String driver = "com.mysql.jdbc.Driver";
|
||||
String driver = "com.ibm.db2.jcc.DB2Driver"; //db2
|
||||
// String url = "jdbc:mariadb://localhost:4406/eai?useUnicode=true&characterEncoding=euckr";
|
||||
String url = "jdbc:db2://localhost:50000/DSEADT";
|
||||
String uId = "db2admin";
|
||||
String uPwd = "e1001";
|
||||
|
||||
Connection con;
|
||||
PreparedStatement pstmt;
|
||||
ResultSet rs;
|
||||
|
||||
public JdbcTest() {
|
||||
try {
|
||||
Class.forName(driver);
|
||||
con = DriverManager.getConnection(url, uId, uPwd);
|
||||
System.out.println(con);
|
||||
if( con != null ){ System.out.println("데이터 베이스 접속 성공"); }
|
||||
|
||||
} catch (ClassNotFoundException e) {
|
||||
//e.printStackTrace();
|
||||
System.out.println("드라이버 로드 실패");
|
||||
}
|
||||
catch (SQLException e) {
|
||||
//e.printStackTrace();
|
||||
System.out.println(e);
|
||||
System.out.println("데이터 베이스 접속 실패");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void insert(String id, String name){
|
||||
String sql = "insert into test values(?, ?)";
|
||||
try {
|
||||
pstmt = con.prepareStatement(sql);
|
||||
pstmt.setString(1, id);
|
||||
pstmt.setString(2, name);
|
||||
pstmt.executeQuery();
|
||||
|
||||
} catch (SQLException e) {
|
||||
//e.printStackTrace();
|
||||
System.out.println("쿼리 수행 실패");
|
||||
}
|
||||
}
|
||||
|
||||
public void select(){
|
||||
String sql = "select * from test";
|
||||
try {
|
||||
pstmt = con.prepareStatement(sql);
|
||||
rs = pstmt.executeQuery();
|
||||
while(rs.next()){
|
||||
System.out.println("id : " + rs.getString("id"));
|
||||
System.out.println("name : " + rs.getString("name"));
|
||||
}
|
||||
} catch (SQLException e) { System.out.println("쿼리 수행 실패"); }
|
||||
finally {
|
||||
try { if(rs!=null) rs.close();} catch(Exception e) {}
|
||||
try { if(con!=null) con.close();} catch(Exception e) {}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args){
|
||||
JdbcTest dbm = new JdbcTest();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package com.eactive.eai.common.util;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 1. 기능 : Date, Time 관련 Utility Method 정의
|
||||
* 2. 처리 개요 :
|
||||
*
|
||||
* 3. 주의사항
|
||||
*
|
||||
* @author :
|
||||
* @version : v 1.0.0
|
||||
* @see :
|
||||
* @since :
|
||||
*/
|
||||
public final class NullControl {
|
||||
|
||||
|
||||
/**
|
||||
* Private 생성자
|
||||
* Instance를 생성하지 못함
|
||||
*/
|
||||
private NullControl()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 1. 기능 : Null값을 공백으로 변경
|
||||
* 2. 처리 개요 :
|
||||
* - ""나 Null를 입력받아 SPACE로 변환한다.
|
||||
* 3. 주의사항
|
||||
*
|
||||
* @param "", Null
|
||||
* @return String
|
||||
* @exception
|
||||
**/
|
||||
public static String addSpace(String val)
|
||||
{
|
||||
if(val == null || val.equals("")){
|
||||
val = " ";
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
/**
|
||||
* 1. 기능 : 입력값을 트림하여 화이트스페이스를 없앤다.
|
||||
* 2. 처리 개요 :
|
||||
* - 입력받은 값을 트림하여 리턴한다.
|
||||
* 3. 주의사항
|
||||
*
|
||||
* @param "", Null
|
||||
* @return String
|
||||
* @exception
|
||||
**/
|
||||
|
||||
public static String trimSpace(String val)
|
||||
{
|
||||
if(val == null || val.equals("")){
|
||||
val = ""; // ""나 Null을 체크하여 트림하여 에러가 발생하지 않도록 한다..
|
||||
}else{
|
||||
val = val.trim();
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
public static String trimSpace2(String val)
|
||||
{
|
||||
if(val == null || val.equals("")){
|
||||
return ""; // ""나 Null을 체크하여 트림하여 에러가 발생하지 않도록 한다..
|
||||
}
|
||||
if (val.trim().length() > 0){
|
||||
return val;
|
||||
}
|
||||
else{
|
||||
return val.trim();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.eactive.eai.common.util;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* 1. 기능 : EAI서버 Rule 정보를 DB로 부터 로딩해 메모리에 관리하는 Manager 클래스
|
||||
* 2. 처리 개요 : DB Rule 정보에 저장된 필드 추출 Rule 정보를 메모리에 로딩 관리한다.
|
||||
* 3. 주의사항
|
||||
*
|
||||
* @author :
|
||||
* @version : v 1.0.0
|
||||
* @see : 관련 기능을 참조
|
||||
* @since :
|
||||
* :
|
||||
*/
|
||||
public class SystemUtil
|
||||
{
|
||||
|
||||
public static final String EAI_SYSTEMMODE = "eai.systemmode";
|
||||
private static final String EAI_PRODUCT = "P";
|
||||
private static final String EAI_STAGING = "T";
|
||||
private static final String EAI_DEVELOP = "D";
|
||||
|
||||
//시스템 운영환경 구분코드
|
||||
private static final String SYSOPEREVIRNDSTCD_PRODUCT = "P";
|
||||
private static final String SYSOPEREVIRNDSTCD_STAGING = "T";
|
||||
private static final String SYSOPEREVIRNDSTCD_DEVELOP = "D";
|
||||
|
||||
|
||||
|
||||
public static boolean isProdServer() {
|
||||
String systemMode = System.getProperty(EAI_SYSTEMMODE);
|
||||
|
||||
if (EAI_PRODUCT.equals(systemMode)){
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public static boolean isDevServer() {
|
||||
String systemMode = System.getProperty(EAI_SYSTEMMODE);
|
||||
|
||||
if (EAI_DEVELOP.equals(systemMode)|| "".equals(systemMode)){
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isStagingServer() {
|
||||
String systemMode = System.getProperty(EAI_SYSTEMMODE);
|
||||
|
||||
if (EAI_STAGING.equals(systemMode)){
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public static String getSysOperEvirnDstcd(){
|
||||
if (isProdServer()){
|
||||
return SYSOPEREVIRNDSTCD_PRODUCT;
|
||||
} else if (isStagingServer()){
|
||||
return SYSOPEREVIRNDSTCD_STAGING;
|
||||
} else if (isDevServer()){
|
||||
return SYSOPEREVIRNDSTCD_DEVELOP;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static String getSystemModeTitle(){
|
||||
String systemModeTitle = System.getProperty("systemModeTitle", "");
|
||||
if(StringUtils.isBlank(systemModeTitle)){
|
||||
if (SystemUtil.isDevServer()){
|
||||
systemModeTitle = "개발";
|
||||
}else if(SystemUtil.isStagingServer()){
|
||||
systemModeTitle = "스테이징";
|
||||
// systemModeTitle = "테스트";
|
||||
}else if(SystemUtil.isProdServer()){
|
||||
systemModeTitle = "운영";
|
||||
}
|
||||
}
|
||||
if(StringUtils.isNotBlank(systemModeTitle)){
|
||||
systemModeTitle = "["+systemModeTitle+"] ";
|
||||
}
|
||||
return systemModeTitle;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.eactive.eai.common.util;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class XmlUtil {
|
||||
|
||||
private static final String CDATA_START = "<![CDATA[";
|
||||
private static final String CDATA_END = "]]>";
|
||||
private static final String CDATA_PSEUDO_END = "]]>";
|
||||
private static final String CDATA_EMBEDED_END = CDATA_END + CDATA_PSEUDO_END + CDATA_START;
|
||||
private static final int CDATA_END_LEN = CDATA_END.length();
|
||||
|
||||
/**
|
||||
* This method takes a string which may contain HTML tags (ie,
|
||||
* <b>, <table>, etc) and replaces any
|
||||
* '<', '>' , '&' or '"'
|
||||
* characters with respective predefined entity references.
|
||||
*
|
||||
* @param input The text to be converted.
|
||||
* @return The input string with the special characters replaced.
|
||||
* */
|
||||
static public String escapeTags(final String input) {
|
||||
// Check if the string is null, zero length or devoid of special characters
|
||||
// if so, return what was sent in.
|
||||
|
||||
if(input == null
|
||||
|| input.length() == 0
|
||||
|| (input.indexOf('"') == -1 &&
|
||||
input.indexOf('&') == -1 &&
|
||||
input.indexOf('<') == -1 &&
|
||||
input.indexOf('>') == -1)) {
|
||||
return input;
|
||||
}
|
||||
|
||||
StringBuffer buf = new StringBuffer(input.length() + 6);
|
||||
char ch;
|
||||
|
||||
int len = input.length();
|
||||
for(int i=0; i < len; i++) {
|
||||
ch = input.charAt(i);
|
||||
if (ch > '>') {
|
||||
buf.append(ch);
|
||||
} else if(ch == '<') {
|
||||
buf.append("<");
|
||||
} else if(ch == '>') {
|
||||
buf.append(">");
|
||||
} else if(ch == '&') {
|
||||
buf.append("&");
|
||||
} else if(ch == '"') {
|
||||
buf.append(""");
|
||||
} else {
|
||||
buf.append(ch);
|
||||
}
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that embeded CDEnd strings (]]>) are handled properly
|
||||
* within message, NDC and throwable tag text.
|
||||
*
|
||||
* @param buf StringBuffer holding the XML data to this point. The
|
||||
* initial CDStart (<![CDATA[) and final CDEnd (]]>) of the CDATA
|
||||
* section are the responsibility of the calling method.
|
||||
* @param str The String that is inserted into an existing CDATA Section within buf.
|
||||
* */
|
||||
static public void appendEscapingCDATA(final StringBuffer buf,
|
||||
final String str) {
|
||||
if (str != null) {
|
||||
int end = str.indexOf(CDATA_END);
|
||||
if (end < 0) {
|
||||
buf.append(str);
|
||||
} else {
|
||||
int start = 0;
|
||||
while (end > -1) {
|
||||
buf.append(str.substring(start, end));
|
||||
buf.append(CDATA_EMBEDED_END);
|
||||
start = end + CDATA_END_LEN;
|
||||
if (start < str.length()) {
|
||||
end = str.indexOf(CDATA_END, start);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
buf.append(str.substring(start));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user