leeheejo 5 tahun lalu
induk
melakukan
2536cadc8d
2 mengubah file dengan 34 tambahan dan 19 penghapusan
  1. 1 0
      pom.xml
  2. 33 19
      src/main/java/com/icontrols/kakao/controller/MainController.java

+ 1 - 0
pom.xml

@@ -44,6 +44,7 @@
 			<artifactId>json</artifactId>
 			<version>20160810</version>
 		</dependency>
+		
 	</dependencies>
 
 	<build>

+ 33 - 19
src/main/java/com/icontrols/kakao/controller/MainController.java

@@ -5,12 +5,15 @@ import javax.servlet.http.HttpServletResponse;
 import org.json.JSONObject;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.core.ParameterizedTypeReference;
+import org.springframework.hateoas.PagedResources;
 import org.springframework.http.HttpEntity;
 import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
 import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
-import org.springframework.stereotype.Controller;
 import org.springframework.util.LinkedMultiValueMap;
 import org.springframework.util.MultiValueMap;
 import org.springframework.web.bind.annotation.RequestHeader;
@@ -18,28 +21,36 @@ 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.RestController;
 import org.springframework.web.client.RestTemplate;
 import org.springframework.web.server.ResponseStatusException;
 
-@Controller
+import com.icontrols.kakao.utils.JWTUtils;
+
+@RestController
 public class MainController {
 
-	public String COMPLEX_SERVER = "http://61.33.215.54:8002/kakao/danzi"; // 의현씨 컴퓨터
+	public String COMPLEX_SERVER = "http://61.33.215.54:8003/kakao/danzi";
+	String KAKAO_SERVER_EVENT = "https://kakaohome-api.i.kakao.com/events";
+//	String KAKAO_SERVER_EVENT = "https://kakaohome-api-beta.i.kakao.com/events";
+	String KAKAO_SERVER_EVENT_SANDBOX = "https://kakaohome-api-sandbox.i.kakao.com/events";
 
 	private static final Logger logger = LoggerFactory.getLogger(MainController.class);
 
 	@RequestMapping(value = "/kakao", method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
 	public @ResponseBody String From3rdServer(@RequestHeader HttpHeaders headers, HttpEntity<String> httpEntity,
 			HttpServletResponse response) {
-		logger.info("/iotservice");
+		logger.info("/kakao");
 		String answer = "";
 		String body = httpEntity.getBody();
 		logger.info("Body: " + body);
 		JSONObject obj = new JSONObject(body);
 		String token = obj.get("authorization").toString();
-//		JWTUtils jwt = new JWTUtils();
-//		String complexIp = jwt.getCmpIpFromToken(token);
-//		logger.info(complexIp);
+
+		JWTUtils jwt = new JWTUtils();
+		String complexIp = jwt.getCmpIpFromToken(token);
+		logger.info(complexIp);
+		String complexServer = "http://" + complexIp + ":8003/kakao/danzi";
 
 		HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
 		factory.setConnectTimeout(3000);
@@ -48,7 +59,7 @@ public class MainController {
 		response.setHeader("Content-Type", "application/json");
 //		response.setHeader("Authorization", headers.get("Authorization").get(0));
 		HttpEntity<String> entity = new HttpEntity<String>(body, headers);
-		answer = template.postForObject(COMPLEX_SERVER, entity, String.class);
+		answer = template.postForObject(complexServer, entity, String.class);
 
 		return answer;
 	}
@@ -57,8 +68,10 @@ public class MainController {
 	public @ResponseBody String FromValleyServerEvent(@RequestHeader HttpHeaders headers, HttpEntity<String> httpEntity,
 			HttpServletResponse response) {
 
-		logger.info("/iotservice");
-		String KAKAO_SERVER_EVENT = "https://kakaohome-api.i.kakao.com/events";
+		logger.info("/events");
+
+		// beta version
+//		String KAKAO_SERVER_EVENT = "https://kakaohome-api-beta.i.kakao.com/events";
 		String answer = "";
 		String body = httpEntity.getBody();
 		logger.info("Body: " + body);
@@ -86,7 +99,9 @@ public class MainController {
 			@RequestParam(value = "grant_type", required = true) String grant_type, HttpEntity<String> httpEntity,
 			HttpServletResponse response) {
 		logger.info(refresh_token);
-		String KAKAO_SERVER_EVENT = "https://kakaohome-api.i.kakao.com/events/token";
+//		String KAKAO_SERVER_EVENT = "https://kakaohome-api.i.kakao.com/events/token";
+		// beta version
+//		String KAKAO_SERVER_EVENT = "https://kakaohome-api.i.kakao.com/events/token";
 		String answer = "";
 
 		MultiValueMap<String, String> multiValueMap = new LinkedMultiValueMap<>();
@@ -103,19 +118,18 @@ public class MainController {
 		header.add("Authorization", headers.get("Authorization").get(0));
 
 		HttpEntity<MultiValueMap<String, String>> entity = new HttpEntity<>(multiValueMap, header);
-		answer = template.postForObject(KAKAO_SERVER_EVENT, entity, String.class);
+
+		logger.info(entity.toString());
+
+		answer = template.postForObject(KAKAO_SERVER_EVENT + "/token", entity, String.class);
 
 		return answer;
 	}
 
-	@RequestMapping(value = "/test", method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
-	public @ResponseBody String Complex(HttpEntity<String> httpEntity) {
-		logger.info("/test");
-		String answer = "";
-		String body = httpEntity.getBody();
-		logger.info("Body: " + body);
+	@RequestMapping(value = "/aws/healthcheck", method = RequestMethod.GET)
+	public void healthCheck(HttpEntity<String> httpEntity) {
 
-		return body;
+		return;
 	}
 
 }