diff --git a/pom.xml b/pom.xml
index af53200..d7dab0c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -2,116 +2,103 @@
4.0.0
-
- org.springframework.boot
- spring-boot-starter-parent
- 2.3.12.RELEASE
-
-
- com.example
- demo
- 0.0.1-SNAPSHOT
- demo
- war
- Demo project for Spring Boot
-
-
-
-
- com.google.code.gson
- gson
-
-
-
- org.apache.commons
- commons-lang3
-
-
-
- org.json
- json
- 20160810
-
-
-
-
- org.apache.tomcat.embed
- tomcat-embed-jasper
- provided
-
-
-
- javax.servlet
- jstl
-
-
-
+
+
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 2.7.18
+
+
+
+ com.example
+ profile
+ 0.0.1-SNAPSHOT
+ war
+
+ profile
+ Spring Boot 2.7 WAR for Tomcat 9
+
+
+ 8
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-tomcat
+ provided
+
+
+
+
+ org.mybatis.spring.boot
+ mybatis-spring-boot-starter
+ 2.3.2
+
+
+
+
+ org.mariadb.jdbc
+ mariadb-java-client
+
+
+
commons-fileupload
commons-fileupload
- 1.3.3
+ 1.5
-
-
- commons-io
- commons-io
- 2.6
-
-
+
+
- org.springframework.boot
- spring-boot-starter-web
+ org.apache.tomcat.embed
+ tomcat-embed-jasper
+ provided
+
+
+
+
+ javax.servlet
+ jstl
- org.springframework.boot
- spring-boot-starter-tomcat
- provided
-
-
-
-
- mysql
- mysql-connector-java
-
+ org.json
+ json
+ 20230618
+
- org.mariadb.jdbc
- mariadb-java-client
-
-
-
-
- org.mybatis.spring.boot
- mybatis-spring-boot-starter
- 2.3.2
+ org.apache.commons
+ commons-lang3
- org.springframework.boot
- spring-boot-starter-test
- test
-
-
- org.junit.vintage
- junit-vintage-engine
-
-
+ com.google.code.gson
+ gson
-
+
+
-
- profile
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
-
- 1.8
- 1.8
-
-
-
-
+
+
+ profile
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
diff --git a/src/main/java/com/example/demo/config/HttpUtil.java b/src/main/java/com/example/demo/config/HttpUtil.java
index 1953931..412c670 100644
--- a/src/main/java/com/example/demo/config/HttpUtil.java
+++ b/src/main/java/com/example/demo/config/HttpUtil.java
@@ -8,200 +8,126 @@ import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
import java.util.Iterator;
import javax.servlet.http.HttpServletRequest;
-import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.io.IOUtils;
import org.json.JSONObject;
-
+import org.apache.commons.lang3.StringUtils;
import com.google.gson.Gson;
-
public class HttpUtil {
-
-
- public static void sendGet(String url) {
- try {
-
- URL u = new URL(url);
- HttpURLConnection httpCon = (HttpURLConnection) u.openConnection();
-// httpCon.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
-// httpCon.setDoOutput(true);
-// httpCon.setDoInput(true);
- httpCon.setRequestMethod("GET");
-
- InputStream in = new BufferedInputStream(httpCon.getInputStream());
- String result = org.apache.commons.io.IOUtils.toString(in, "UTF-8");
- System.out.println(result);
- in.close();
- httpCon.disconnect();
-
- } catch(Exception e) {
-
- e.printStackTrace();
-
- }
- }
+ /* ===================== GET ===================== */
+ public static String sendGet(String url) {
- /**
- * 객체를 JSON 문자열로 POST 방식으로 전송한다.
- * @param url
- * @param object
- */
- public static void sendObject2Json(String url, Object object) {
+ HttpURLConnection conn = null;
- try {
- URL u = new URL(url);
- HttpURLConnection httpCon = (HttpURLConnection) u.openConnection();
- httpCon.setRequestProperty("Content-Type", "application/json; charset=EUC-KR");
- httpCon.setDoOutput(true);
- httpCon.setDoInput(true);
- httpCon.setRequestMethod("POST");
- OutputStream raw = httpCon.getOutputStream();
- //OutputStream buffered = new BufferedOutputStream(raw);
- //OutputStreamWriter out = new OutputStreamWriter(buffered,"UTF-8");
- //OutputStreamWriter out = new OutputStreamWriter(buffered);
- //Object -> JSON
- String jsonStr = new Gson().toJson(object);
- System.out.println("ready to send : " + url);
- System.out.println("converted json data: \n" + jsonStr);
- //전송
- raw.write(jsonStr.getBytes("EUC-KR"));
- raw.flush();
- raw.close();
+ try {
+ URL u = new URL(url);
+ conn = (HttpURLConnection) u.openConnection();
+ conn.setRequestMethod("GET");
+ conn.setConnectTimeout(3000);
+ conn.setReadTimeout(3000);
- // read the response
- System.out.println(httpCon.getResponseCode());
- System.out.println(httpCon.getResponseMessage());
+ try (InputStream in = new BufferedInputStream(conn.getInputStream())) {
+ return IOUtils.toString(in, StandardCharsets.UTF_8);
+ }
- InputStream in = new BufferedInputStream(httpCon.getInputStream());
- String result = org.apache.commons.io.IOUtils.toString(in, "UTF-8");
- System.out.println(result);
- in.close();
- httpCon.disconnect();
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ } finally {
+ if (conn != null) conn.disconnect();
+ }
+ }
- } catch(Exception e) {
- e.printStackTrace();
- }
+ /* ===================== POST JSON ===================== */
- }
+ public static String sendObject2Json(String url, Object object) {
- /**
- * 객체를 GET 파라미터 형식의 POST 방식으로 전송한다.
- * @param url
- * @param object
- */
- public static void sendObject2Post(String url, Object object) {
+ HttpURLConnection conn = null;
- try {
- URL u = new URL(url);
- HttpURLConnection httpCon = (HttpURLConnection) u.openConnection();
- httpCon.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
- httpCon.setDoOutput(true);
- httpCon.setDoInput(true);
- httpCon.setRequestMethod("POST");
- OutputStream raw = httpCon.getOutputStream();
- //OutputStream buffered = new BufferedOutputStream(raw);
- //OutputStreamWriter out = new OutputStreamWriter(buffered,"UTF-8");
- //OutputStreamWriter out = new OutputStreamWriter(buffered);
- //Object -> JSON
- String jsonStr = new Gson().toJson(object);
- System.out.println("ready to send : " + url);
- System.out.println("converted json data: \n" + jsonStr);
-
- StringBuilder sb = new StringBuilder();
- JSONObject json = new JSONObject(jsonStr);
- Iterator keys = json.keys();
- //sb.append("?"); //start of query args
- while (keys.hasNext()) {
- String key = keys.next();
- sb.append(key);
- sb.append("=");
- sb.append( URLEncoder.encode((String)json.get(key), "EUC-KR") );
- sb.append("&"); //To allow for another argument.
- }
- String queryStr = sb.toString();
-
- System.out.println( "json to query :" + queryStr );
-
- //전송
- raw.write(queryStr.getBytes("EUC-KR"));
- raw.flush();
- raw.close();
+ try {
+ URL u = new URL(url);
+ conn = (HttpURLConnection) u.openConnection();
- // read the response
- System.out.println(httpCon.getResponseCode());
- System.out.println(httpCon.getResponseMessage());
+ conn.setRequestMethod("POST");
+ conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
+ conn.setDoOutput(true);
+ conn.setConnectTimeout(3000);
+ conn.setReadTimeout(3000);
- InputStream in = new BufferedInputStream(httpCon.getInputStream());
- String result = org.apache.commons.io.IOUtils.toString(in, "UTF-8");
- System.out.println(result);
- in.close();
- httpCon.disconnect();
+ String jsonStr = new Gson().toJson(object);
- } catch(Exception e) {
- e.printStackTrace();
- }
+ try (OutputStream os = conn.getOutputStream()) {
+ os.write(jsonStr.getBytes(StandardCharsets.UTF_8));
+ }
- }
+ try (InputStream in = new BufferedInputStream(conn.getInputStream())) {
+ return IOUtils.toString(in, StandardCharsets.UTF_8);
+ }
-
- /**
- * 객체를 GET 파라미터 형식의 POST 방식으로 전송한다.
- * @param url
- * @param object
- */
- public static void send2PostOrderId(String url, String moduleId, String orderId, String userId) {
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ } finally {
+ if (conn != null) conn.disconnect();
+ }
+ }
- try {
- URL u = new URL(url);
- HttpURLConnection httpCon = (HttpURLConnection) u.openConnection();
- httpCon.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
- httpCon.setDoOutput(true);
- httpCon.setDoInput(true);
- httpCon.setRequestMethod("POST");
- OutputStream raw = httpCon.getOutputStream();
- System.out.println("ready to send : " + url);
+ /* ===================== POST FORM ===================== */
- String queryStr = "moduleId=" + moduleId + "&" + "orderId=" + orderId + "&" + "userId=" + userId;
-
- System.out.println( "json to query :" + queryStr );
-
- //전송
- raw.write(queryStr.getBytes("EUC-KR"));
- raw.flush();
- raw.close();
+ public static String sendObject2Post(String url, Object object) {
- // read the response
- System.out.println(httpCon.getResponseCode());
- System.out.println(httpCon.getResponseMessage());
+ HttpURLConnection conn = null;
- InputStream in = new BufferedInputStream(httpCon.getInputStream());
- String result = org.apache.commons.io.IOUtils.toString(in, "UTF-8");
- System.out.println(result);
- in.close();
- httpCon.disconnect();
+ try {
+ URL u = new URL(url);
+ conn = (HttpURLConnection) u.openConnection();
- } catch(Exception e) {
- e.printStackTrace();
- }
+ conn.setRequestMethod("POST");
+ conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
+ conn.setDoOutput(true);
- }
-
-
- /** 클라이언트 ip 추출
- PROXY SERVER 또는 LOAD BALANCER를 거치는 경우 ip가 접속하기 직전의 ip로 들어오게 된다.
- PROXY SERVER 또는 LOAD BALANCER를 거칠 경우 reuqest header의 HTTP_X_FORWARDED_FOR 키워드에 정보를 남김으로
- 먼저 확인 후 없을 경우 request.getRemoteAddr()로 ip를 추출한다. */
- public static String getClientIp(HttpServletRequest request) throws Exception {
- String ip = request.getHeader("HTTP_X_FORWARDED_FOR");
- if ( StringUtils.isEmpty( ip ) ) {
- ip = request.getRemoteAddr();
- }
- return ip;
- }
+ JSONObject json = new JSONObject(new Gson().toJson(object));
+ StringBuilder sb = new StringBuilder();
-}//end class
\ No newline at end of file
+ Iterator keys = json.keys();
+ while (keys.hasNext()) {
+ String key = keys.next();
+ sb.append(key)
+ .append("=")
+ .append(URLEncoder.encode(json.getString(key), "UTF-8"))
+ .append("&");
+ }
+
+ try (OutputStream os = conn.getOutputStream()) {
+ os.write(sb.toString().getBytes(StandardCharsets.UTF_8));
+ }
+
+ try (InputStream in = new BufferedInputStream(conn.getInputStream())) {
+ return IOUtils.toString(in, StandardCharsets.UTF_8);
+ }
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ } finally {
+ if (conn != null) conn.disconnect();
+ }
+ }
+
+ /* ===================== Client IP ===================== */
+
+ public static String getClientIp(HttpServletRequest request) {
+ String ip = request.getHeader("HTTP_X_FORWARDED_FOR");
+ if (StringUtils.isBlank(ip)) {
+ ip = request.getRemoteAddr();
+ }
+ return ip;
+ }
+}
diff --git a/src/main/java/com/example/demo/controller/JSPController.java b/src/main/java/com/example/demo/controller/JSPController.java
index 5de81fc..afdd5d5 100644
--- a/src/main/java/com/example/demo/controller/JSPController.java
+++ b/src/main/java/com/example/demo/controller/JSPController.java
@@ -10,8 +10,6 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
-import javax.servlet.http.HttpServletRequest;
-
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.http.HttpStatus;
@@ -19,158 +17,112 @@ import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
@Controller
public class JSPController {
-
-// @Value("${openApi.serviceKey}")
-// private String serviceKey;
-//
-// @Value("${openApi.callBackUrl}")
-// private String callBackUrl;
-//
-// @Value("${openApi.dataType}")
-// private String dataType;
-
-
- @GetMapping("/add.do")
- public String addList(Model model) {
-
-
-// System.out.println( id );
-
-// model.addAttribute("id", "id");
-// model.addAttribute("name", "name");
-
-
-
- return "add";
- }
-
-
- @GetMapping("/index.do")
- public String index(Model model) {
-
- ResponseEntity result = callForecastApi();
- JSONObject json = new JSONObject(result);
- JSONArray jsonArr = new JSONArray( json.get("body").toString() );
-
- List