DB 접속 업데이트 및 소스 정리
This commit is contained in:
parent
1e4e48e521
commit
b67430acc1
163
pom.xml
163
pom.xml
|
|
@ -2,116 +2,103 @@
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<parent>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-parent</artifactId>
|
|
||||||
<version>2.3.12.RELEASE</version>
|
|
||||||
<relativePath/> <!-- lookup parent from repository -->
|
|
||||||
</parent>
|
|
||||||
<groupId>com.example</groupId>
|
|
||||||
<artifactId>demo</artifactId>
|
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
|
||||||
<name>demo</name>
|
|
||||||
<packaging>war</packaging>
|
|
||||||
<description>Demo project for Spring Boot</description>
|
|
||||||
|
|
||||||
<dependencies>
|
<!-- 🔴 Tomcat 9 표준 -->
|
||||||
|
<parent>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
|
<version>2.7.18</version>
|
||||||
|
<relativePath/>
|
||||||
|
</parent>
|
||||||
|
|
||||||
<dependency>
|
<groupId>com.example</groupId>
|
||||||
<groupId>com.google.code.gson</groupId>
|
<artifactId>profile</artifactId>
|
||||||
<artifactId>gson</artifactId>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
</dependency>
|
<packaging>war</packaging>
|
||||||
|
|
||||||
<dependency>
|
<name>profile</name>
|
||||||
<groupId>org.apache.commons</groupId>
|
<description>Spring Boot 2.7 WAR for Tomcat 9</description>
|
||||||
<artifactId>commons-lang3</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<properties>
|
||||||
<groupId>org.json</groupId>
|
<java.version>8</java.version>
|
||||||
<artifactId>json</artifactId>
|
</properties>
|
||||||
<version>20160810</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!--<scope>provided</scope> provided로 지정하면 패키징시 제외됩니다. -->
|
<dependencies>
|
||||||
|
|
||||||
|
<!-- REST API -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 외부 Tomcat 9 배포 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-tomcat</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- MyBatis -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mybatis.spring.boot</groupId>
|
||||||
|
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||||
|
<version>2.3.2</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- DB Driver (MariaDB 기준, 하나만 선택) -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mariadb.jdbc</groupId>
|
||||||
|
<artifactId>mariadb-java-client</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- File Upload -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-fileupload</groupId>
|
||||||
|
<artifactId>commons-fileupload</artifactId>
|
||||||
|
<version>1.5</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- JSP 엔진 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.tomcat.embed</groupId>
|
<groupId>org.apache.tomcat.embed</groupId>
|
||||||
<artifactId>tomcat-embed-jasper</artifactId>
|
<artifactId>tomcat-embed-jasper</artifactId>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- JSTL -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.servlet</groupId>
|
<groupId>javax.servlet</groupId>
|
||||||
<artifactId>jstl</artifactId>
|
<artifactId>jstl</artifactId>
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Commons FileUpload -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>commons-fileupload</groupId>
|
|
||||||
<artifactId>commons-fileupload</artifactId>
|
|
||||||
<version>1.3.3</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>commons-io</groupId>
|
|
||||||
<artifactId>commons-io</artifactId>
|
|
||||||
<version>2.6</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.json</groupId>
|
||||||
<artifactId>spring-boot-starter-tomcat</artifactId>
|
<artifactId>json</artifactId>
|
||||||
<scope>provided</scope>
|
<version>20230618</version>
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>mysql</groupId>
|
|
||||||
<artifactId>mysql-connector-java</artifactId>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mariadb.jdbc</groupId>
|
<groupId>org.apache.commons</groupId>
|
||||||
<artifactId>mariadb-java-client</artifactId>
|
<artifactId>commons-lang3</artifactId>
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- https://mvnrepository.com/artifact/org.mybatis.spring.boot/mybatis-spring-boot-starter -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.mybatis.spring.boot</groupId>
|
|
||||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
|
||||||
<version>2.3.2</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>com.google.code.gson</groupId>
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>gson</artifactId>
|
||||||
<scope>test</scope>
|
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>org.junit.vintage</groupId>
|
|
||||||
<artifactId>junit-vintage-engine</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<build>
|
</dependencies>
|
||||||
<finalName>profile</finalName>
|
|
||||||
<plugins>
|
<build>
|
||||||
<plugin>
|
<!-- WAR 이름 -->
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<finalName>profile</finalName>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<configuration>
|
<plugins>
|
||||||
<source>1.8</source>
|
<plugin>
|
||||||
<target>1.8</target>
|
<groupId>org.springframework.boot</groupId>
|
||||||
</configuration>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
||||||
|
|
@ -8,200 +8,126 @@ import java.io.OutputStream;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
|
|
||||||
public class HttpUtil {
|
public class HttpUtil {
|
||||||
|
|
||||||
|
/* ===================== GET ===================== */
|
||||||
|
|
||||||
public static void sendGet(String url) {
|
public static String sendGet(String url) {
|
||||||
|
|
||||||
try {
|
HttpURLConnection conn = null;
|
||||||
|
|
||||||
URL u = new URL(url);
|
try {
|
||||||
HttpURLConnection httpCon = (HttpURLConnection) u.openConnection();
|
URL u = new URL(url);
|
||||||
// httpCon.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
|
conn = (HttpURLConnection) u.openConnection();
|
||||||
// httpCon.setDoOutput(true);
|
conn.setRequestMethod("GET");
|
||||||
// httpCon.setDoInput(true);
|
conn.setConnectTimeout(3000);
|
||||||
httpCon.setRequestMethod("GET");
|
conn.setReadTimeout(3000);
|
||||||
|
|
||||||
InputStream in = new BufferedInputStream(httpCon.getInputStream());
|
try (InputStream in = new BufferedInputStream(conn.getInputStream())) {
|
||||||
String result = org.apache.commons.io.IOUtils.toString(in, "UTF-8");
|
return IOUtils.toString(in, StandardCharsets.UTF_8);
|
||||||
System.out.println(result);
|
}
|
||||||
in.close();
|
|
||||||
httpCon.disconnect();
|
|
||||||
|
|
||||||
} catch(Exception e) {
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
} finally {
|
||||||
|
if (conn != null) conn.disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
e.printStackTrace();
|
/* ===================== POST JSON ===================== */
|
||||||
|
|
||||||
}
|
public static String sendObject2Json(String url, Object object) {
|
||||||
}
|
|
||||||
|
|
||||||
|
HttpURLConnection conn = null;
|
||||||
|
|
||||||
/**
|
try {
|
||||||
* 객체를 JSON 문자열로 POST 방식으로 전송한다.
|
URL u = new URL(url);
|
||||||
* @param url
|
conn = (HttpURLConnection) u.openConnection();
|
||||||
* @param object
|
|
||||||
*/
|
|
||||||
public static void sendObject2Json(String url, Object object) {
|
|
||||||
|
|
||||||
try {
|
conn.setRequestMethod("POST");
|
||||||
URL u = new URL(url);
|
conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
|
||||||
HttpURLConnection httpCon = (HttpURLConnection) u.openConnection();
|
conn.setDoOutput(true);
|
||||||
httpCon.setRequestProperty("Content-Type", "application/json; charset=EUC-KR");
|
conn.setConnectTimeout(3000);
|
||||||
httpCon.setDoOutput(true);
|
conn.setReadTimeout(3000);
|
||||||
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();
|
|
||||||
|
|
||||||
// read the response
|
String jsonStr = new Gson().toJson(object);
|
||||||
System.out.println(httpCon.getResponseCode());
|
|
||||||
System.out.println(httpCon.getResponseMessage());
|
|
||||||
|
|
||||||
InputStream in = new BufferedInputStream(httpCon.getInputStream());
|
try (OutputStream os = conn.getOutputStream()) {
|
||||||
String result = org.apache.commons.io.IOUtils.toString(in, "UTF-8");
|
os.write(jsonStr.getBytes(StandardCharsets.UTF_8));
|
||||||
System.out.println(result);
|
}
|
||||||
in.close();
|
|
||||||
httpCon.disconnect();
|
|
||||||
|
|
||||||
} catch(Exception e) {
|
try (InputStream in = new BufferedInputStream(conn.getInputStream())) {
|
||||||
e.printStackTrace();
|
return IOUtils.toString(in, StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
} finally {
|
||||||
|
if (conn != null) conn.disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/* ===================== POST FORM ===================== */
|
||||||
* 객체를 GET 파라미터 형식의 POST 방식으로 전송한다.
|
|
||||||
* @param url
|
|
||||||
* @param object
|
|
||||||
*/
|
|
||||||
public static void sendObject2Post(String url, Object object) {
|
|
||||||
|
|
||||||
try {
|
public static String sendObject2Post(String url, Object object) {
|
||||||
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();
|
HttpURLConnection conn = null;
|
||||||
JSONObject json = new JSONObject(jsonStr);
|
|
||||||
Iterator<String> 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 );
|
try {
|
||||||
|
URL u = new URL(url);
|
||||||
|
conn = (HttpURLConnection) u.openConnection();
|
||||||
|
|
||||||
//전송
|
conn.setRequestMethod("POST");
|
||||||
raw.write(queryStr.getBytes("EUC-KR"));
|
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
|
||||||
raw.flush();
|
conn.setDoOutput(true);
|
||||||
raw.close();
|
|
||||||
|
|
||||||
// read the response
|
JSONObject json = new JSONObject(new Gson().toJson(object));
|
||||||
System.out.println(httpCon.getResponseCode());
|
StringBuilder sb = new StringBuilder();
|
||||||
System.out.println(httpCon.getResponseMessage());
|
|
||||||
|
|
||||||
InputStream in = new BufferedInputStream(httpCon.getInputStream());
|
Iterator<String> keys = json.keys();
|
||||||
String result = org.apache.commons.io.IOUtils.toString(in, "UTF-8");
|
while (keys.hasNext()) {
|
||||||
System.out.println(result);
|
String key = keys.next();
|
||||||
in.close();
|
sb.append(key)
|
||||||
httpCon.disconnect();
|
.append("=")
|
||||||
|
.append(URLEncoder.encode(json.getString(key), "UTF-8"))
|
||||||
|
.append("&");
|
||||||
|
}
|
||||||
|
|
||||||
} catch(Exception e) {
|
try (OutputStream os = conn.getOutputStream()) {
|
||||||
e.printStackTrace();
|
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 ===================== */
|
||||||
* 객체를 GET 파라미터 형식의 POST 방식으로 전송한다.
|
|
||||||
* @param url
|
|
||||||
* @param object
|
|
||||||
*/
|
|
||||||
public static void send2PostOrderId(String url, String moduleId, String orderId, String userId) {
|
|
||||||
|
|
||||||
try {
|
public static String getClientIp(HttpServletRequest request) {
|
||||||
URL u = new URL(url);
|
String ip = request.getHeader("HTTP_X_FORWARDED_FOR");
|
||||||
HttpURLConnection httpCon = (HttpURLConnection) u.openConnection();
|
if (StringUtils.isBlank(ip)) {
|
||||||
httpCon.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
|
ip = request.getRemoteAddr();
|
||||||
httpCon.setDoOutput(true);
|
}
|
||||||
httpCon.setDoInput(true);
|
return ip;
|
||||||
httpCon.setRequestMethod("POST");
|
}
|
||||||
OutputStream raw = httpCon.getOutputStream();
|
}
|
||||||
System.out.println("ready to send : " + url);
|
|
||||||
|
|
||||||
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();
|
|
||||||
|
|
||||||
// read the response
|
|
||||||
System.out.println(httpCon.getResponseCode());
|
|
||||||
System.out.println(httpCon.getResponseMessage());
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/** 클라이언트 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}//end class
|
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,6 @@ import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
|
|
@ -19,158 +17,112 @@ import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class JSPController {
|
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() {
|
||||||
|
return "add";
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/add.do")
|
@GetMapping("/index.do")
|
||||||
public String addList(Model model) {
|
public String index(Model model) {
|
||||||
|
|
||||||
|
List<HashMap<String, String>> list = fetchUserList();
|
||||||
|
model.addAttribute("list", list);
|
||||||
|
|
||||||
// System.out.println( id );
|
return "index";
|
||||||
|
}
|
||||||
|
|
||||||
// model.addAttribute("id", "id");
|
@GetMapping("/list.do")
|
||||||
// model.addAttribute("name", "name");
|
public String list(Model model) {
|
||||||
|
|
||||||
|
model.addAttribute("start", "start....OK");
|
||||||
|
|
||||||
|
List<HashMap<String, String>> list = fetchUserList();
|
||||||
|
model.addAttribute("list", list);
|
||||||
|
|
||||||
return "add";
|
return "hello";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ===================== API 처리 ===================== */
|
||||||
|
|
||||||
@GetMapping("/index.do")
|
private List<HashMap<String, String>> fetchUserList() {
|
||||||
public String index(Model model) {
|
|
||||||
|
|
||||||
ResponseEntity<String> result = callForecastApi();
|
ResponseEntity<String> response = callForecastApi();
|
||||||
JSONObject json = new JSONObject(result);
|
String body = response.getBody();
|
||||||
JSONArray jsonArr = new JSONArray( json.get("body").toString() );
|
|
||||||
|
|
||||||
List<Object> list = new ArrayList<Object>();
|
JSONArray jsonArr = new JSONArray(body);
|
||||||
for ( int i = 0; i < jsonArr.length(); i++) {
|
|
||||||
HashMap<String, String> map = new HashMap<String, String>();
|
|
||||||
JSONObject obj = jsonArr.getJSONObject(i);
|
|
||||||
map.put( "id", obj.getString("phone") );
|
|
||||||
map.put( "name", obj.getString("name") );
|
|
||||||
map.put( "phone", obj.getString("phone") );
|
|
||||||
map.put( "address", obj.getString("address") );
|
|
||||||
map.put( "filepath", obj.getString("filepath") );
|
|
||||||
list.add(map);
|
|
||||||
}
|
|
||||||
|
|
||||||
model.addAttribute("list", list);
|
List<HashMap<String, String>> list = new ArrayList<>();
|
||||||
|
|
||||||
return "index";
|
for (int i = 0; i < jsonArr.length(); i++) {
|
||||||
}
|
JSONObject obj = jsonArr.getJSONObject(i);
|
||||||
|
|
||||||
@GetMapping("/list.do")
|
HashMap<String, String> map = new HashMap<>();
|
||||||
public String home(Model model) {
|
map.put("id", obj.optString("phone"));
|
||||||
|
map.put("name", obj.optString("name"));
|
||||||
|
map.put("phone", obj.optString("phone"));
|
||||||
|
map.put("address", obj.optString("address"));
|
||||||
|
map.put("filepath", obj.optString("filepath"));
|
||||||
|
|
||||||
model.addAttribute("start", "start....OK");
|
list.add(map);
|
||||||
|
}
|
||||||
|
|
||||||
ResponseEntity<String> result = callForecastApi();
|
return list;
|
||||||
// System.out.println(result);
|
}
|
||||||
|
|
||||||
JSONObject json = new JSONObject(result);
|
/* ===================== HTTP 호출 ===================== */
|
||||||
model.addAttribute("name", result);
|
|
||||||
|
|
||||||
JSONArray jsonArr = new JSONArray( json.get("body").toString() );
|
public ResponseEntity<String> callForecastApi() {
|
||||||
// System.out.println( jsonArr );
|
|
||||||
|
|
||||||
List<Object> list = new ArrayList<Object>();
|
HttpURLConnection conn = null;
|
||||||
for ( int i = 0; i < jsonArr.length(); i++) {
|
|
||||||
HashMap<String, String> map = new HashMap<String, String>();
|
|
||||||
JSONObject obj = jsonArr.getJSONObject(i);
|
|
||||||
map.put( "id", obj.getString("phone") );
|
|
||||||
map.put( "name", obj.getString("name") );
|
|
||||||
map.put( "phone", obj.getString("phone") );
|
|
||||||
map.put( "address", obj.getString("phone") );
|
|
||||||
map.put( "filepath", obj.getString("filepath") );
|
|
||||||
list.add(map);
|
|
||||||
}
|
|
||||||
|
|
||||||
model.addAttribute("list", list);
|
|
||||||
return "hello";
|
|
||||||
}
|
|
||||||
|
|
||||||
// public ResponseEntity<String> callForecastApi(
|
|
||||||
// @RequestParam(value="base_time") String baseTime,
|
|
||||||
// @RequestParam(value="base_date") String baseDate,
|
|
||||||
// @RequestParam(value="beach_num") String beachNum ) {
|
|
||||||
|
|
||||||
public ResponseEntity<String> callForecastApi() {
|
|
||||||
|
|
||||||
HttpURLConnection urlConnection = null;
|
|
||||||
InputStream stream = null;
|
InputStream stream = null;
|
||||||
String result = null;
|
String result = "";
|
||||||
|
|
||||||
// String urlStr = callBackUrl +
|
|
||||||
// "serviceKey=" + serviceKey +
|
|
||||||
// "&dataType=" + dataType +
|
|
||||||
// "&base_date=" + baseDate +
|
|
||||||
// "&base_time=" + baseTime +
|
|
||||||
// "&beach_num=" + beachNum;
|
|
||||||
|
|
||||||
String urlStr = "https://api.leejk0523.com/profile/user/all";
|
String urlStr = "https://api.leejk0523.com/profile/user/all";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
URL url = new URL(urlStr);
|
URL url = new URL(urlStr);
|
||||||
|
conn = (HttpURLConnection) url.openConnection();
|
||||||
|
|
||||||
urlConnection = (HttpURLConnection) url.openConnection();
|
conn.setConnectTimeout(3000);
|
||||||
stream = getNetworkConnection(urlConnection);
|
conn.setReadTimeout(3000);
|
||||||
|
conn.setRequestMethod("GET");
|
||||||
|
|
||||||
|
if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) {
|
||||||
|
throw new IOException("HTTP error : " + conn.getResponseCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
stream = conn.getInputStream();
|
||||||
result = readStreamToString(stream);
|
result = readStreamToString(stream);
|
||||||
|
|
||||||
if (stream != null) stream.close();
|
} catch (Exception e) {
|
||||||
} catch(IOException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
if (urlConnection != null) {
|
try {
|
||||||
urlConnection.disconnect();
|
if (stream != null) stream.close();
|
||||||
}
|
} catch (IOException e) {}
|
||||||
|
if (conn != null) conn.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ResponseEntity<>(result, HttpStatus.OK);
|
return new ResponseEntity<>(result, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* URLConnection 을 전달받아 연결정보 설정 후 연결, 연결 후 수신한 InputStream 반환 */
|
private String readStreamToString(InputStream stream) throws IOException {
|
||||||
private InputStream getNetworkConnection(HttpURLConnection urlConnection) throws IOException {
|
|
||||||
urlConnection.setConnectTimeout(3000);
|
|
||||||
urlConnection.setReadTimeout(3000);
|
|
||||||
urlConnection.setRequestMethod("GET");
|
|
||||||
urlConnection.setDoInput(true);
|
|
||||||
|
|
||||||
if(urlConnection.getResponseCode() != HttpURLConnection.HTTP_OK) {
|
|
||||||
throw new IOException("HTTP error code : " + urlConnection.getResponseCode());
|
|
||||||
}
|
|
||||||
|
|
||||||
return urlConnection.getInputStream();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* InputStream을 전달받아 문자열로 변환 후 반환 */
|
|
||||||
private String readStreamToString(InputStream stream) throws IOException{
|
|
||||||
StringBuilder result = new StringBuilder();
|
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
BufferedReader br = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
|
BufferedReader br = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
|
||||||
|
|
||||||
String readLine;
|
String line;
|
||||||
while((readLine = br.readLine()) != null) {
|
while ((line = br.readLine()) != null) {
|
||||||
result.append(readLine + "\n\r");
|
sb.append(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
br.close();
|
br.close();
|
||||||
|
return sb.toString();
|
||||||
return result.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,11 @@ public class UserProfileController {
|
||||||
this.mapper = mapper;
|
this.mapper = mapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/user/test")
|
||||||
|
public Object test() {
|
||||||
|
return "OK";
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/user/{id}")
|
@GetMapping("/user/{id}")
|
||||||
public UserProfile getUserProfile(@PathVariable String id) {
|
public UserProfile getUserProfile(@PathVariable String id) {
|
||||||
return mapper.getUserProfile(id);
|
return mapper.getUserProfile(id);
|
||||||
|
|
@ -43,9 +48,10 @@ public class UserProfileController {
|
||||||
@Value("${server.url.img}")
|
@Value("${server.url.img}")
|
||||||
private String SERVER_URL_IMG;
|
private String SERVER_URL_IMG;
|
||||||
|
|
||||||
@Value("server.servlet.context-path")
|
@Value("${server.servlet.context-path}")
|
||||||
private String CONTEXT_PATH;
|
private String CONTEXT_PATH;
|
||||||
|
|
||||||
|
|
||||||
@PostMapping("/user/{id}")
|
@PostMapping("/user/{id}")
|
||||||
// public HashMap<String, Object> putUserProfile(@PathVariable String id, @RequestParam String name,
|
// public HashMap<String, Object> putUserProfile(@PathVariable String id, @RequestParam String name,
|
||||||
// public void putUserProfile(@PathVariable String id, @RequestParam String name,
|
// public void putUserProfile(@PathVariable String id, @RequestParam String name,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
# DB
|
# DB
|
||||||
spring.datasource.url=jdbc:mariadb://leejk0523.com:3306/profile?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Seoul&autoReconnect=true&verifyServerCertificate=false&useSSL=false
|
spring.datasource.url=jdbc:mariadb://linuxserver-mariadb-1:3306/profile?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Seoul&autoReconnect=true&verifyServerCertificate=false&useSSL=false
|
||||||
spring.datasource.username=leejk0523
|
spring.datasource.username=root
|
||||||
spring.datasource.password=Ghtkssk0325
|
spring.datasource.password=Ghtkssk0325
|
||||||
|
|
||||||
# Encoding
|
# Encoding
|
||||||
|
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
package com.example.demo;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
|
|
||||||
@SpringBootTest
|
|
||||||
class DemoApplicationTests {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void contextLoads() {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue