Skip to content

Commit

Permalink
Merge pull request #94 from 22hours/Server/ver3.0
Browse files Browse the repository at this point in the history
Server/ver3.0
  • Loading branch information
jongwuner authored Apr 19, 2020
2 parents 28e5644 + d16c977 commit 19916d7
Show file tree
Hide file tree
Showing 9 changed files with 535 additions and 400 deletions.
4 changes: 3 additions & 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 = '2.3.8-SNAPSHOT'
version = '3.4.0-SNAPSHOT'
sourceCompatibility = '1.8'

repositories {
Expand All @@ -24,6 +24,8 @@ dependencies {
compile('org.springframework.boot:spring-boot-starter-data-redis')
compile group: 'redis.clients', name: 'jedis', version: '2.9.0'
compile 'com.googlecode.json-simple:json-simple:1.1.1'
compile('org.springframework.boot:spring-boot-starter-cache')
testCompile('org.springframework.boot:spring-boot-starter-test')
}

test {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

import java.nio.charset.Charset;

import javax.servlet.Filter;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
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 @@ -20,5 +24,11 @@ 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;
}

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

import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Component;

@Component
public class CacheController {

String Etag = "";

public boolean IsCached() {
if(!Etag.equals(null)) return true;
else return false;
}

public String GetCache() {
return Etag;
}
public void SetCache(String etag) {
this.Etag = etag;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.context.request.WebRequest;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.hours22.system_monitor_ver11.client.ClientInfoController;
Expand All @@ -41,17 +45,25 @@ public class CommonController {

@Autowired
ClientInfoController cic;

@Autowired
CacheController cache;

SimpleDateFormat transFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");

@CrossOrigin("*")
@RequestMapping(value = "/", method = RequestMethod.GET)
public void GetIndex(HttpServletRequest req, HttpServletResponse response) throws IOException {
public ResponseEntity<String> GetIndex(WebRequest req, HttpServletRequest request, HttpServletResponse response) throws IOException {
response.setContentType("text/html;charset=UTF-8");
response.getWriter().println("Welcome 22Hours!<br>");
response.getWriter().println("This is system-monitor project.<br>");
response.getWriter().println("서버작업중 by jongchu. 2020-03-28 11:30<br><br><br><br>");
if (req.checkNotModified(cache.GetCache())) {
return null;
}
String msg = "Welcome 22Hours!<br>" + "This is system-monitor project. Version 3.0<br>" + "서버작업중 by jongchu. 2020-04-08<br><br><br><br>";

System.out.println("--------------------------------------------------------------------------------------------");
System.out.println("Input : / <- GET method [Client Ip : "+ cic.getClientIp(req) +" ] at " + transFormat.format(new Date()));
System.out.println("Input : / <- GET method [Client Ip : "+ cic.getClientIp(request) +" ] at " + transFormat.format(new Date()));
cache.SetCache(req.getHeader("If-None-Match"));
return new ResponseEntity<String>(msg, HttpStatus.OK);
}

@RequestMapping(value = "/testpage", method = RequestMethod.GET)
Expand All @@ -62,6 +74,7 @@ public void GetIndex(HttpServletRequest req, HttpServletResponse response) throw
return "Test Page";
}


@RequestMapping(value = "/pc/{id}", method = RequestMethod.GET)
public @ResponseBody String GetPcInstanceData(HttpServletRequest req, HttpServletResponse response, @PathVariable String id) throws IOException {
System.out.println("--------------------------------------------------------------------------------------------");
Expand Down
Loading

0 comments on commit 19916d7

Please sign in to comment.