|
@@ -2,6 +2,9 @@ package com.icontrols.kakao.controller;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
+import org.apache.http.conn.ssl.NoopHostnameVerifier;
|
|
|
+import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
+import org.apache.http.impl.client.HttpClients;
|
|
|
import org.json.JSONObject;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -21,11 +24,13 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
+import org.springframework.web.bind.annotation.ResponseStatus;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
import org.springframework.web.server.ResponseStatusException;
|
|
|
|
|
|
import com.icontrols.kakao.utils.JWTUtils;
|
|
|
+import com.sun.net.httpserver.HttpServer;
|
|
|
|
|
|
@RestController
|
|
|
public class MainController {
|
|
@@ -65,8 +70,8 @@ public class MainController {
|
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "/events", method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
|
|
|
- public @ResponseBody String FromValleyServerEvent(@RequestHeader HttpHeaders headers, HttpEntity<String> httpEntity,
|
|
|
- HttpServletResponse response) {
|
|
|
+ public @ResponseStatus @ResponseBody ResponseEntity<?> FromValleyServerEvent(@RequestHeader HttpHeaders headers,
|
|
|
+ HttpEntity<String> httpEntity, HttpServletResponse response) {
|
|
|
|
|
|
logger.info("/events");
|
|
|
|
|
@@ -80,21 +85,31 @@ public class MainController {
|
|
|
// JWTUtils jwt = new JWTUtils();
|
|
|
// String complexIp = jwt.getCmpIpFromToken(token);
|
|
|
// logger.info(complexIp);
|
|
|
+ CloseableHttpClient httpClient = HttpClients.custom().setSSLHostnameVerifier(new NoopHostnameVerifier())
|
|
|
+ .build();
|
|
|
+
|
|
|
HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
|
|
|
- factory.setConnectTimeout(3000);
|
|
|
+ factory.setHttpClient(httpClient);
|
|
|
+ factory.setConnectTimeout(10000);
|
|
|
+ factory.setReadTimeout(10000);
|
|
|
RestTemplate template = new RestTemplate(factory);
|
|
|
- response.setHeader("Content-Type", "application/json");
|
|
|
+ HttpHeaders reqHeaders = new HttpHeaders();
|
|
|
+ reqHeaders.set("Content-Type", "application/json");
|
|
|
if (headers.get("Authorization").get(0) == null)
|
|
|
throw new ResponseStatusException(HttpStatus.UNAUTHORIZED);
|
|
|
- response.setHeader("Authorization", headers.get("Authorization").get(0));
|
|
|
- HttpEntity<String> entity = new HttpEntity<String>(body, headers);
|
|
|
- answer = template.postForObject(KAKAO_SERVER_EVENT, entity, String.class);
|
|
|
-
|
|
|
- return answer;
|
|
|
+ reqHeaders.set("Authorization", headers.get("Authorization").get(0));
|
|
|
+ HttpEntity<String> entity = new HttpEntity<String>(body.toString(), reqHeaders);
|
|
|
+ try {
|
|
|
+ answer = template.postForObject(KAKAO_SERVER_EVENT, entity, String.class);
|
|
|
+ logger.info(answer);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return ResponseEntity.status(HttpStatus.OK).body(answer);
|
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "/events/token", method = RequestMethod.POST)
|
|
|
- public @ResponseBody String FromValleyServerToken(@RequestHeader HttpHeaders headers,
|
|
|
+ public @ResponseStatus @ResponseBody HttpEntity<?> FromValleyServerToken(@RequestHeader HttpHeaders headers,
|
|
|
@RequestParam(value = "refresh_token", required = true) String refresh_token,
|
|
|
@RequestParam(value = "grant_type", required = true) String grant_type, HttpEntity<String> httpEntity,
|
|
|
HttpServletResponse response) {
|
|
@@ -108,10 +123,15 @@ public class MainController {
|
|
|
multiValueMap.add("refresh_token", refresh_token);
|
|
|
multiValueMap.add("grant_type", grant_type);
|
|
|
|
|
|
-// HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
|
|
|
-// factory.setConnectTimeout(3000);
|
|
|
+ CloseableHttpClient httpClient = HttpClients.custom().setSSLHostnameVerifier(new NoopHostnameVerifier())
|
|
|
+ .build();
|
|
|
|
|
|
- RestTemplate template = new RestTemplate();
|
|
|
+ HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
|
|
|
+ factory.setHttpClient(httpClient);
|
|
|
+ factory.setConnectTimeout(10000);
|
|
|
+ factory.setReadTimeout(10000);
|
|
|
+
|
|
|
+ RestTemplate template = new RestTemplate(factory);
|
|
|
|
|
|
HttpHeaders header = new HttpHeaders();
|
|
|
header.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
|
@@ -123,7 +143,7 @@ public class MainController {
|
|
|
|
|
|
answer = template.postForObject(KAKAO_SERVER_EVENT + "/token", entity, String.class);
|
|
|
|
|
|
- return answer;
|
|
|
+ return ResponseEntity.status(HttpStatus.OK).body(answer);
|
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "/aws/healthcheck", method = RequestMethod.GET)
|