Skip to content

Commit

Permalink
Merge pull request #97 from 22hours/Server/ver3.0
Browse files Browse the repository at this point in the history
v3.5.0 update
  • Loading branch information
jongwuner authored Apr 27, 2020
2 parents 19916d7 + c0e77c4 commit d8d98f1
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 65 deletions.
2 changes: 1 addition & 1 deletion dev/Server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group = 'com.hours22'
version = '3.4.0-SNAPSHOT'
version = '3.5.1'
sourceCompatibility = '1.8'

repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.filter.ShallowEtagHeaderFilter;

//@EnableCaching
@SpringBootApplication
public class Application {

Expand All @@ -24,11 +24,13 @@ public static void main(String[] args) {
public HttpMessageConverter<String> responseBodyConverter() {
return new StringHttpMessageConverter(Charset.forName("UTF-8"));
}

@Bean
public Filter filter(){
ShallowEtagHeaderFilter filter=new ShallowEtagHeaderFilter();
return filter;
FilterRegistrationBean shallowEtagBean () {
FilterRegistrationBean frb = new FilterRegistrationBean();
frb.setFilter(new ShallowEtagHeaderFilter());
frb.addUrlPatterns("/mobile/*");
frb.setOrder(2);
return frb;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.hours22.system_monitor_ver11;

import javax.servlet.Filter;
import javax.servlet.annotation.WebServlet;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.web.filter.ShallowEtagHeaderFilter;

/*
@WebServlet(asyncSupported = true)
public class FilterRegistration {
@Bean
public Filter filter(){
ShallowEtagHeaderFilter filter=new ShallowEtagHeaderFilter();
return filter;
}
}
*/
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.hours22.system_monitor_ver11.client.ClientInfoController;

@Component
public class CacheController {
@Autowired
ClientInfoController cic;

String Etag = "";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ public ResponseEntity<String> GetIndex(WebRequest req, HttpServletRequest reques
System.out.println("--------------------------------------------------------------------------------------------");
System.out.println("Input : /pc/"+ id +" <- GET method [Client Ip : "+ cic.getClientIp(req) + " ] at " + transFormat.format(new Date()));

lc.getConnection();
//lc.getConnection();
String res = lc.getConnectionHgetall(id);
lc.getConnectionExit();
//lc.getConnectionExit();

return res;
}
Expand All @@ -94,7 +94,7 @@ public void PostPcInstanceData(HttpServletRequest request, HttpServletResponse r
System.out.println("Input : "+ json +" <- POST method [Client : "+ cic.getClientIp(request) + " ] at "+transFormat.format(new Date()));


lc.getConnection();
//lc.getConnection();
lc.getConnectionHset(id, map);
//lc.getConnectionExit();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,14 @@ public ResponseEntity<String> GetPcData(WebRequest req, HttpServletRequest reque
System.out.println("--------------------------------------------------------------------------------------------");
System.out.println("Input : /mobile/pc <- GET method [Client Ip : "+ cic.getClientIp(request)+"] at "+transFormat.format(new Date()) );

lc.getConnection();
//lc.getConnection();

String json = ojm.writeValueAsString(dss.GetAllTypeDataRedis("PC", "pcs"));
json = dss.PrettyPrinter(json);
System.out.println(json);
lc.getConnectionExit();
//lc.getConnectionExit();
cache.SetCache(req.getHeader("If-None-Match"));
System.out.println(req.getHeader("If-None-Match"));
return new ResponseEntity<String>(json, HttpStatus.OK);
}

Expand All @@ -96,7 +97,7 @@ public ResponseEntity<String> GetPcRamCpuData(WebRequest req, HttpServletRequest
return null;
}

lc.getConnection();
//lc.getConnection();
System.out.println("--------------------------------------------------------------------------------------------");
System.out.println("Input : /mobile/pc/"+id+"/data <- GET method [Client Ip : "+ cic.getClientIp(request) +" ] at " + transFormat.format(new Date()));

Expand All @@ -105,19 +106,22 @@ public ResponseEntity<String> GetPcRamCpuData(WebRequest req, HttpServletRequest
System.out.println(json);

//response.getWriter().print(json);
lc.getConnectionExit();
//lc.getConnectionExit();
cache.SetCache(req.getHeader("If-None-Match"));
return new ResponseEntity(json, HttpStatus.OK);
}

@CrossOrigin("*")
@RequestMapping(value = "/mobile/pc/{id}/power/{endTime}", method = RequestMethod.POST)
public ResponseEntity<Map<String, String>> PostPcPower(WebRequest req, HttpServletRequest request, HttpServletResponse response, @RequestBody Map<String, String> map, @PathVariable String id, @PathVariable String endTime) throws IOException, InterruptedException {
@RequestMapping(value = "/mobile/pc/power", method = RequestMethod.POST)
public ResponseEntity<Map<String, String>> PostPcPower(WebRequest req, HttpServletRequest request, HttpServletResponse response, @RequestBody Map<String, String> map) throws IOException, InterruptedException {
response.setCharacterEncoding("UTF-8");

String id = map.get("id");
String endTime = map.get("endTime");

System.out.println("--------------------------------------------------------------------------------------------");
System.out.println("Input : /mobile/pc/"+id+"/power/"+endTime+" <- POST method [Client Ip : " +cic.getClientIp(request)+"] at "+transFormat.format(new Date()) );

Set<Thread> setOfThread = Thread.getAllStackTraces().keySet();
for(Thread thread : setOfThread){
System.out.println("Active Thread's [ Number : " +thread.getId()+" / Name : "+thread.getName()+" ] ");
Expand All @@ -129,16 +133,16 @@ public ResponseEntity<Map<String, String>> PostPcPower(WebRequest req, HttpServl
}
}

lc.getConnection();
//lc.getConnection();
if(lc.getConnectionHkey(id) == false) {
lc.getConnectionExit();
//lc.getConnectionExit();
Map<String, String> jsonObject = new HashMap<String, String>();
jsonObject.put("id", id);
jsonObject.put("msg", "false");
return new ResponseEntity<Map<String, String>>(jsonObject, HttpStatus.OK);
}
lc.getConnectionHset(id, map);
lc.getConnectionExit();
//lc.getConnectionExit();

System.out.println(map.toString());

Expand All @@ -152,20 +156,21 @@ public ResponseEntity<Map<String, String>> PostPcPower(WebRequest req, HttpServl

@CrossOrigin("*")
@RequestMapping(value = "/mobile/login", method = RequestMethod.POST)
public Map<String, String> GetAdminLogin(WebRequest req, HttpServletRequest request, HttpServletResponse response, @RequestBody Map<String, String> map) throws IOException, InterruptedException {
public ResponseEntity<Map<String, String>> GetAdminLogin(WebRequest req, HttpServletRequest request, HttpServletResponse response, @RequestBody Map<String, String> map) throws IOException, InterruptedException {
Map<String, String> jsonObject = new HashMap<String, String>();

lc.getConnection();
//lc.getConnection();
Map<String, String> auth = lc.getLoginSession(map);
String type = auth.get("type");
String ret = auth.get("msg");
if(type.equals("admin") && ret.equals("false")) {
lc.getConnectionExit();
//lc.getConnectionExit();
jsonObject.put("msg", "false");
return jsonObject;
return new ResponseEntity<Map<String, String>>(jsonObject, HttpStatus.NON_AUTHORITATIVE_INFORMATION);
}
lc.getConnectionExit();
return auth;
//lc.getConnectionExit();
auth.put("msg", "true");
return new ResponseEntity<Map<String, String>>(auth, HttpStatus.OK);
}

@CrossOrigin("*")
Expand All @@ -180,13 +185,13 @@ public Map<String, String> GetAdminLogin(WebRequest req, HttpServletRequest requ
System.out.println("--------------------------------------------------------------------------------------------");
System.out.println("Input : /mobile/class <- GET method [Client Ip : "+ cic.getClientIp(request)+"] at "+transFormat.format(new Date()) );

lc.getConnection();
//lc.getConnection();

String json = ojm.writeValueAsString(dss.GetAllTypeDataRedis("CLASS", "classes"));
json = dss.PrettyPrinter(json);
System.out.println(json);

lc.getConnectionExit();
//lc.getConnectionExit();
cache.SetCache(req.getHeader("If-None-Match"));
return json;
}
Expand All @@ -203,31 +208,35 @@ public Map<String, String> GetAdminLogin(WebRequest req, HttpServletRequest requ
System.out.println("--------------------------------------------------------------------------------------------");
System.out.println("Input : /mobile/class/"+classId+" <- GET method [Client Ip : "+ cic.getClientIp(request)+"] at "+transFormat.format(new Date()) );

lc.getConnection();
//lc.getConnection();

String json = ojm.writeValueAsString(dss.ClassPcs(classId));
json = dss.PrettyPrinter(json);
System.out.println(json);

lc.getConnectionExit();
//lc.getConnectionExit();
cache.SetCache(req.getHeader("If-None-Match"));
return json;
}

@CrossOrigin("*")
@RequestMapping(value = "/mobile/class/{classId}/power", method = RequestMethod.POST)
public void PostAllClassPcPower(WebRequest req, HttpServletRequest request, HttpServletResponse response, @PathVariable String classId) throws IOException, InterruptedException {

@RequestMapping(value = "/mobile/class/power", method = RequestMethod.POST)
public ResponseEntity<Map<String, String>> PostAllClassPcPower(WebRequest req, HttpServletRequest request, HttpServletResponse response, @RequestBody Map<String, String> map) throws IOException, InterruptedException {
String classId = map.get("id");

//req.check
System.out.println("--------------------------------------------------------------------------------------------");
System.out.println("Input : /mobile/class/"+classId+"/power <- POST method [Client Ip : "+ cic.getClientIp(request)+"] at "+transFormat.format(new Date()) );

lc.getConnection();

dss.PostClassPcsPowerOff(req, request, response, classId);

lc.getConnectionExit();

//lc.getConnection();
dss.PostClassPcsPowerOff(req, request, response, map);
//PostPcPower(req, request, response, map);

//lc.getConnectionExit();
cache.SetCache(req.getHeader("If-None-Match"));
map.put("message", "success update!");
return new ResponseEntity<Map<String, String>>(map, HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.Async;
Expand All @@ -48,6 +49,7 @@
import java.util.concurrent.ThreadPoolExecutor;

@Controller
@Configuration
@WebServlet(asyncSupported = true)
public class PcController {
@Autowired
Expand All @@ -68,25 +70,30 @@ public class PcController {
SimpleDateFormat transFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");


@RequestMapping(value = "/pc/{id}/data", method = RequestMethod.POST)
public void PostPcData(WebRequest req, HttpServletRequest request, HttpServletResponse response, @RequestBody Map<String, String> map, @PathVariable String id) throws IOException {
@RequestMapping(value = "/pc/data", method = RequestMethod.POST)
public void PostPcData(WebRequest req, HttpServletRequest request, HttpServletResponse response, @RequestBody Map<String, String> map) throws IOException {
response.setCharacterEncoding("UTF-8");

String id = map.get("id");

System.out.println("--------------------------------------------------------------------------------------------");
System.out.println("Input : /pc/"+id+"/data <- POST method [Client Ip : " +cic.getClientIp(request)+"] at "+transFormat.format(new Date()) );
lc.getConnection();
//lc.getConnection();
lc.getConnectionHset(id, map);
lc.getConnectionExit();
//lc.getConnectionExit();
System.out.println(map.toString());

response.getWriter().print("Success /pc/"+id+"/data <- POST method !!");
cache.SetCache(req.getHeader("If-None-Match"));
}

@RequestMapping(value = "/pc/{id}/power/{endTime}", method = RequestMethod.POST)
public ResponseEntity<Map<String, String>> PostPcPower(WebRequest req, HttpServletRequest request, HttpServletResponse response, @RequestBody Map<String, String> map, @PathVariable String id, @PathVariable String endTime) throws IOException, InterruptedException {
@RequestMapping(value = "/pc/power", method = RequestMethod.POST)
public ResponseEntity<Map<String, String>> PostPcPower(WebRequest req, HttpServletRequest request, HttpServletResponse response, @RequestBody Map<String, String> map) throws IOException, InterruptedException {
response.setCharacterEncoding("UTF-8");

String id = map.get("id");
String endTime = map.get("endTime");

System.out.println("--------------------------------------------------------------------------------------------");
System.out.println("Input : /pc/"+id+"/power/"+endTime+" <- POST method [Client Ip : " +cic.getClientIp(request)+"] at "+transFormat.format(new Date()) );

Expand All @@ -101,16 +108,16 @@ public ResponseEntity<Map<String, String>> PostPcPower(WebRequest req, HttpServl
}
}

lc.getConnection();
//lc.getConnection();
if(lc.getConnectionHkey(id) == false) {
lc.getConnectionExit();
//lc.getConnectionExit();
Map<String, String> jsonObject = new HashMap<String, String>();
jsonObject.put("id", id);
jsonObject.put("msg", "false");
return new ResponseEntity<Map<String, String>>(jsonObject, HttpStatus.OK);
}
lc.getConnectionHset(id, map);
lc.getConnectionExit();
//lc.getConnectionExit();

System.out.println(map.toString());

Expand Down Expand Up @@ -152,9 +159,9 @@ public ResponseEntity<Map<String, String>> PostPcPower(WebRequest req, HttpServl


String EndTime;
lc.getConnection();
//lc.getConnection();
EndTime = lc.getConnectionHgetField(id, "endTime");
lc.getConnectionExit();
//lc.getConnectionExit();

System.out.println("일단 redis에서 불러온 값 : "+ EndTime);

Expand All @@ -181,6 +188,7 @@ public ResponseEntity<Map<String, String>> PostPcPower(WebRequest req, HttpServl
return new Callable<Map<String, String>>() {
@Override
public Map<String, String> call() throws Exception {

System.out.println("================================");
System.out.println("PCPowerOffMsg Return 영역");
Thread.currentThread().setName("PCPowerOffMsg-Return-"+id);
Expand All @@ -190,7 +198,6 @@ public Map<String, String> call() throws Exception {
long MSG = endTime;
System.out.println(MSG / 1000 + "초 동안 Thread.sleep();");
System.out.println("알림시간 is " + EndTime +" - "+min+"분");
//Thread.sleep(252000);
// start

long timeToSleep = MSG;
Expand Down Expand Up @@ -218,25 +225,24 @@ public Map<String, String> call() throws Exception {
Map<String, String> jsonObjectExit = new HashMap<String, String>();
jsonObjectExit.put("id", id);
jsonObjectExit.put("msg", "extension");
lc.getConnection();
//lc.getConnection();
String endTime = lc.getConnectionHgetField(id, "endTime");
lc.getConnectionExit();

//lc.getConnectionExit();
jsonObjectExit.put("endTime", endTime);
return jsonObjectExit;
}
else {
// end
// endhttp://localhost/pc/hours22/message/2
JSONObject jsonObject = new JSONObject();

System.out.println("--------------------------------------------------------------------------------------------");
System.out.println("[종료"+ min +"분전 알림 메세지! PC : "+ id +" ] at " + transFormat.format(new Date()));
jsonObject.put("id", id);
jsonObject.put("msg", min);

lc.getConnection();
//lc.getConnection();
String endTime = lc.getConnectionHgetField(id, "endTime");
lc.getConnectionExit();
//lc.getConnectionExit();

jsonObject.put("endTime", endTime);

Expand Down
Loading

0 comments on commit d8d98f1

Please sign in to comment.