Initial import from local backup (Documents-Playground/pakerpale)

This commit is contained in:
jeonghwa
2026-07-03 05:27:37 +09:00
commit 7d60ea3f6b
22 changed files with 548 additions and 0 deletions

20
.classpath Normal file
View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/classes" path="src">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry exported="true" kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
target/

23
.project Normal file
View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>CMScheduler</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@@ -0,0 +1,2 @@
eclipse.preferences.version=1
org.eclipse.jdt.apt.aptEnabled=false

View File

@@ -0,0 +1,16 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.processAnnotations=disabled
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8

View File

@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

View File

@@ -0,0 +1,5 @@
eclipse.preferences.version=1
org.springframework.ide.eclipse.xml.namespaces.default.version.check.classpath=true
org.springframework.ide.eclipse.xml.namespaces.enable.project.preferences=false
org.springframework.ide.eclipse.xml.namespaces.loadNamespaceHandlerFromClasspath=true
org.springframework.ide.eclipse.xml.namespaces.use.https.for.new.namespace.locations=false

1
README.md Normal file
View File

@@ -0,0 +1 @@
# cm-app-scheduler

0
manifest.txt Normal file
View File

73
pom.xml Normal file
View File

@@ -0,0 +1,73 @@
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>CMScheduler</groupId>
<artifactId>CMScheduler</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.sun.net.httpserver/http -->
<dependency>
<groupId>com.sun.net.httpserver</groupId>
<artifactId>http</artifactId>
<version>20070405</version>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.47</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,49 @@
package com.crossmap.scheduler;
import static org.quartz.CronScheduleBuilder.cronSchedule;
import static org.quartz.JobBuilder.newJob;
import static org.quartz.TriggerBuilder.newTrigger;
import java.net.InetSocketAddress;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerFactory;
import org.quartz.Trigger;
import org.quartz.impl.StdSchedulerFactory;
import com.crossmap.scheduler.controller.CacheController;
import com.crossmap.scheduler.controller.MelonController;
import com.crossmap.scheduler.job.DisplayContentJob;
import com.sun.net.httpserver.HttpServer;
public class Application {
public static void main(String[] args) {
SchedulerFactory schedulerFactory = new StdSchedulerFactory();
try {
Scheduler scheduler = schedulerFactory.getScheduler();
JobDetail job = newJob(DisplayContentJob.class)
.withIdentity("jobName", Scheduler.DEFAULT_GROUP)
.build();
Trigger trigger = newTrigger()
.withIdentity("trggerName", Scheduler.DEFAULT_GROUP)
.withSchedule(cronSchedule("5 * * * * ?"))
.build();
scheduler.scheduleJob(job, trigger);
scheduler.start();
startServer();
} catch(Exception e) {
e.printStackTrace();
}
}
private static void startServer() throws Exception {
// 8000포트로, /test 컨텍스트로 서비스
HttpServer server = HttpServer.create(new InetSocketAddress(8000), 0);
server.createContext("/melon", new MelonController());
server.createContext("/cache", new CacheController());
server.setExecutor(null); // creates a default executor
server.start();
}
}

View File

@@ -0,0 +1,72 @@
package com.crossmap.scheduler.controller;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.Map;
import com.google.gson.Gson;
import com.sun.net.httpserver.Headers;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
public class BaseController implements HttpHandler {
@Override
public void handle(HttpExchange t) throws IOException {
Map<String, String> query = parseQueryString(t.getRequestURI().getRawQuery());
System.out.println("#" + query + "#");
String response = "This is the response";
t.sendResponseHeaders(200, response.length());
OutputStream os = t.getResponseBody();
os.write(response.getBytes());
os.close();
}
// GET 방식으로 전달되는 파라미터를 해석하려고 추가로 코딩한 부분.
// POST방식 전달 파라미터도 이렇게 해석이 되는지는 모르겠음. 좀 더 공부 필요.
private Map<String, String> parseQueryString(String queryString) {
Map<String, String> param = new HashMap<String, String>();
if (queryString == null)
return param;
String[] queryParts = queryString.split("[&]");
for (String queryPart : queryParts) {
int idx = queryPart.indexOf('=');
if (idx < 0) {
param.put(decode(queryPart), null);
} else {
param.put(decode(queryPart.substring(0, idx)), decode(queryPart.substring(idx + 1)));
}
}
return param;
}
// 위의 함수의 보조
private String decode(String str) {
try {
return URLDecoder.decode(str, "UTF-8");
} catch (UnsupportedEncodingException e) {
return "?";
}
}
protected void response(HttpExchange t, Object data) {
try {
Gson gs = new Gson();
String response = gs.toJson(data);
Headers responseHeaders = t.getResponseHeaders();
responseHeaders.set("Content-Type", "applicaton/json");
t.sendResponseHeaders(200, response.length());
OutputStream os = t.getResponseBody();
os.write(response.getBytes());
os.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

View File

@@ -0,0 +1,44 @@
package com.crossmap.scheduler.controller;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.Map;
import com.sun.net.httpserver.HttpExchange;
public class CacheController extends BaseController {
@Override
public void handle(HttpExchange t) throws IOException {
Map<String, String> query = parseQueryString(t.getRequestURI().getRawQuery());
response(t, query);
}
private Map<String, String> parseQueryString(String queryString) {
Map<String, String> param = new HashMap<String, String>();
if (queryString == null)
return param;
String[] queryParts = queryString.split("[&]");
for (String queryPart : queryParts) {
int idx = queryPart.indexOf('=');
if (idx < 0) {
param.put(decode(queryPart), null);
} else {
param.put(decode(queryPart.substring(0, idx)), decode(queryPart.substring(idx + 1)));
}
}
return param;
}
// À§ÀÇ ÇÔ¼öÀÇ º¸Á¶
private String decode(String str) {
try {
return URLDecoder.decode(str, "UTF-8");
} catch (UnsupportedEncodingException e) {
return "?";
}
}
}

View File

@@ -0,0 +1,53 @@
package com.crossmap.scheduler.controller;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.Map;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
public class MelonController implements HttpHandler {
@Override
public void handle(HttpExchange t) throws IOException {
Map<String, String> query = parseQueryString(t.getRequestURI().getRawQuery());
System.out.println("#" + query + "#");
String response = "This is the response";
t.sendResponseHeaders(200, response.length());
OutputStream os = t.getResponseBody();
os.write(response.getBytes());
os.close();
}
// GET 방식으로 전달되는 파라미터를 해석하려고 추가로 코딩한 부분.
// POST방식 전달 파라미터도 이렇게 해석이 되는지는 모르겠음. 좀 더 공부 필요.
private Map<String, String> parseQueryString(String queryString) {
Map<String, String> param = new HashMap<String, String>();
if (queryString == null)
return param;
String[] queryParts = queryString.split("[&]");
for (String queryPart : queryParts) {
int idx = queryPart.indexOf('=');
if (idx < 0) {
param.put(decode(queryPart), null);
} else {
param.put(decode(queryPart.substring(0, idx)), decode(queryPart.substring(idx + 1)));
}
}
return param;
}
// 위의 함수의 보조
private String decode(String str) {
try {
return URLDecoder.decode(str, "UTF-8");
} catch (UnsupportedEncodingException e) {
return "?";
}
}
}

View File

@@ -0,0 +1,22 @@
package com.crossmap.scheduler.job;
import java.util.Date;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
public class CmtvCacheJob implements Job {
@Override
public void execute(JobExecutionContext arg0) throws JobExecutionException {
System.out.println("Job Executed [" + new Date(System.currentTimeMillis()) + "]");
}
public void updateDisplay() {
}
}

View File

@@ -0,0 +1,74 @@
package com.crossmap.scheduler.job;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import com.crossmap.scheduler.mapper.LifeMapper;
public class DisplayContentJob implements Job {
@Override
public void execute(JobExecutionContext arg0) throws JobExecutionException {
updateDisplay("http://crossmap.co.kr");
System.out.println("Job Executed [" + new Date(System.currentTimeMillis()) + "]");
}
public void updateDisplay(String url) {
String resource = "com/crossmap/scheduler/mybatis-config.xml";
InputStream inputStream;
try {
inputStream = Resources.getResourceAsStream(resource);
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
System.out.println("Create db sesson successfully");
try (SqlSession session = sqlSessionFactory.openSession()) {
LifeMapper mapper = session.getMapper(LifeMapper.class);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date toDate = new Date();
Integer updated = mapper.updateDisplay(sdf.format(toDate));
System.out.printf("Crossmap Life Reserved contents Auto published count: %d%n", updated);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void get(String requestURL) {
try {
HttpClient client = HttpClientBuilder.create().build();
HttpGet getRequest = new HttpGet(requestURL);
HttpResponse response = client.execute(getRequest);
if (response.getStatusLine().getStatusCode() == 200) {
ResponseHandler<String> handler = new BasicResponseHandler();
String body = handler.handleResponse(response);
System.out.println("Success");
} else {
System.out.println("response is error : " + response.getStatusLine().getStatusCode());
}
System.out.println("Executed");
} catch (Exception e) {
System.err.println(e.toString());
}
}
}

View File

@@ -0,0 +1,5 @@
package com.crossmap.scheduler.mapper;
public interface LifeMapper {
Integer updateDisplay(String now);
}

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.crossmap.scheduler.mapper.LifeMapper">
<update id="updateDisplay" parameterType="String">
update life set
is_display= 'Y' where is_display = 'N' and is_del = 'N' and display_date &lt;= #{now}
</update>
</mapper>

View File

@@ -0,0 +1,11 @@
package com.crossmap.scheduler.model;
public class Life {
private int Id;
public int getId() {
return Id;
}
}

View File

@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC" />
<dataSource type="POOLED">
<property name="driver" value="com.mysql.jdbc.Driver" />
<property name="url"
value="jdbc:mysql://localhost:3306/crossmap_legacy?verifyServerCertificate=false&amp;useSSL=false" />
<property name="username" value="root" />
<property name="password" value="" />
</dataSource>
</environment>
<environment id="production">
<transactionManager type="JDBC" />
<dataSource type="POOLED">
<property name="driver" value="com.mysql.jdbc.Driver" />
<property name="url"
value="jdbc:mysql://localhost:3306/crossmap?verifyServerCertificate=false&amp;useSSL=false" />
<property name="username" value="crossmap" />
<property name="password" value="oI#B^!lcr@pL" />
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource="com/crossmap/scheduler/mapper/LifeMapper.xml" />
</mappers>
</configuration>

View File

@@ -0,0 +1,29 @@
package com.crossmap.scheduler.service;
import java.io.IOException;
import java.io.InputStream;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
public class BaseService {
public static final String dbConfigXml = "com/crossmap/scheduler/mybatis-config.xml";
public SqlSession getSqlSession() {
SqlSessionFactory sqlSessionFactory = null;
try {
InputStream inputStream = Resources.getResourceAsStream(BaseService.dbConfigXml);
sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
System.out.println("Create db sesson successfully");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try (SqlSession session = sqlSessionFactory.openSession()) {
return session;
}
}
}

7
src/log4j.properties Normal file
View File

@@ -0,0 +1,7 @@
# Set root logger level to DEBUG and its only appender to A1.
log4j.rootLogger=INFO, A1
# A1 is set to be a ConsoleAppender.
log4j.appender.A1=org.apache.log4j.ConsoleAppender
# A1 uses PatternLayout.
log4j.appender.A1.layout=org.apache.log4j.PatternLayout