-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
71 changed files
with
3,641 additions
and
343 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
.sts4-cache | ||
|
||
### IntelliJ IDEA ### | ||
.idea | ||
.idea/ | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module type="JAVA_MODULE" version="4" /> | ||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> | ||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8"> | ||
<output url="file://$MODULE_DIR$/target/classes" /> | ||
<output-test url="file://$MODULE_DIR$/target/test-classes" /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" /> | ||
<excludeFolder url="file://$MODULE_DIR$/target" /> | ||
</content> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
<orderEntry type="library" name="Maven: io.netty:netty-all:4.1.44.Final" level="project" /> | ||
<orderEntry type="library" name="Maven: com.alibaba:fastjson:1.2.62" level="project" /> | ||
<orderEntry type="library" name="Maven: org.ow2.asm:asm:6.1" level="project" /> | ||
<orderEntry type="library" name="Maven: ch.qos.logback:logback-classic:1.2.3" level="project" /> | ||
<orderEntry type="library" name="Maven: ch.qos.logback:logback-core:1.2.3" level="project" /> | ||
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" /> | ||
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" /> | ||
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" /> | ||
</component> | ||
</module> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package cn.codeyourlife; | ||
|
||
import cn.codeyourlife.controller.ExceptionController; | ||
import cn.codeyourlife.interceptor.CorsInterceptor; | ||
import cn.codeyourlife.server.WebServer; | ||
|
||
/** | ||
* Author: [email protected] | ||
* Copyright: http://codeyourlife.cn | ||
* Platform: Win10 Jdk8 | ||
* Date: 2020/1/13 | ||
*/ | ||
public class JDEApplication { | ||
public static void main(String[] args) { | ||
// 忽略指定url | ||
WebServer.getIgnoreUrls().add("/favicon.ico"); | ||
|
||
// 全局异常处理 | ||
WebServer.setExceptionHandler(new ExceptionController()); | ||
|
||
// 设置监听端口号 | ||
WebServer server = new WebServer(2006); | ||
|
||
// 设置Http最大内容长度(默认 为10M) | ||
server.setMaxContentLength(1024 * 1024 * 50); | ||
|
||
// 设置Controller所在包 | ||
server.setControllerBasePackage("cn.codeyourlife.controller"); | ||
|
||
// 添加拦截器,按照添加的顺序执行。 | ||
// 跨域拦截器 | ||
server.addInterceptor(new CorsInterceptor(), "/不用拦截的url"); | ||
|
||
try { | ||
server.start(); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,4 +112,4 @@ public byte[] getCompiledBytes() { | |
return outputStream.toByteArray(); | ||
} | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/cn/codeyourlife/controller/ExceptionController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package cn.codeyourlife.controller; | ||
|
||
import cn.codeyourlife.server.HttpContextHolder; | ||
import cn.codeyourlife.server.HttpResponse; | ||
import cn.codeyourlife.server.HttpStatus; | ||
import cn.codeyourlife.server.controller.ExceptionHandler; | ||
import cn.codeyourlife.server.exception.ResourceNotFoundException; | ||
|
||
public class ExceptionController implements ExceptionHandler { | ||
|
||
/** | ||
* 处理异常 | ||
* @param e | ||
*/ | ||
@Override | ||
public void doHandle(Exception e) { | ||
HttpStatus status = HttpStatus.INTERNAL_SERVER_ERROR; | ||
if(e instanceof ResourceNotFoundException) { | ||
status = HttpStatus.NOT_FOUND; | ||
} | ||
String errorMessage = e.getCause() == null ? "" : e.getCause().getMessage(); | ||
if(errorMessage == null) { | ||
errorMessage = e.getMessage(); | ||
} | ||
HttpResponse response = HttpContextHolder.getResponse(); | ||
response.write(status, errorMessage); | ||
response.closeChannel(); | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/cn/codeyourlife/controller/RunCodeController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,32 @@ | ||
package cn.codeyourlife.controller; | ||
|
||
import cn.codeyourlife.server.ResponseEntity; | ||
import cn.codeyourlife.server.annotation.GetMapping; | ||
import cn.codeyourlife.server.annotation.JsonResponse; | ||
import cn.codeyourlife.server.annotation.RequestMapping; | ||
import cn.codeyourlife.server.annotation.RestController; | ||
|
||
/** | ||
* Author: [email protected] | ||
* Copyright: http://codeyourlife.cn | ||
* Platform: Win10 Jdk8 | ||
* Date: 2020/1/8 | ||
*/ | ||
|
||
@RestController | ||
@RequestMapping("/ide") | ||
public class RunCodeController { | ||
private static final String defaultSource = "public class Run {\n" | ||
+ " public static void main(String[] args) {\n" | ||
+ " \n" | ||
+ " }\n" | ||
+ "}"; | ||
|
||
@GetMapping("") | ||
public ResponseEntity<?> hello() { | ||
return ResponseEntity.ok().build("hello world"); | ||
} | ||
|
||
// public String entry(Model model) { | ||
// model.addAttribute("lastSource", defaultSource); | ||
// return "ide"; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/java/cn/codeyourlife/interceptor/CorsInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package cn.codeyourlife.interceptor; | ||
|
||
import cn.codeyourlife.server.HttpResponse; | ||
import cn.codeyourlife.server.interceptor.Interceptor; | ||
import io.netty.handler.codec.http.FullHttpRequest; | ||
|
||
/** | ||
* 跨域拦截器 | ||
* @author Leo | ||
*/ | ||
public final class CorsInterceptor implements Interceptor { | ||
|
||
@Override | ||
public boolean preHandle(FullHttpRequest request, HttpResponse response) throws Exception { | ||
response.getHeaders().put("Access-Control-Allow-Origin", "*"); | ||
response.getHeaders().put("Access-Control-Allow-Methods", "POST, PUT, GET, OPTIONS, DELETE"); | ||
response.getHeaders().put("Access-Control-Max-Age", "3600"); | ||
response.getHeaders().put("Access-Control-Allow-Headers", "Content-Type, X-Token"); | ||
return true; | ||
} | ||
|
||
@Override | ||
public void postHandle(FullHttpRequest request, HttpResponse response) throws Exception { | ||
} | ||
|
||
@Override | ||
public void afterCompletion(FullHttpRequest request, HttpResponse response) { | ||
} | ||
|
||
} |
Oops, something went wrong.