Skip to content

Commit 91fe7dd

Browse files
author
jack
committed
README.md
1 parent e8016df commit 91fe7dd

File tree

4 files changed

+171
-147
lines changed

4 files changed

+171
-147
lines changed

README.md

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,51 @@
11
# geditor
2-
A Graph Editor implementing by Spring Boot, Kotlin, Java
2+
3+
## Introduction
4+
5+
A Graph Editor implementing by Spring Boot, Kotlin, Java, based on [jgraphx](https://github.com/jgraph/jgraphx).
6+
7+
## Quick Start
8+
9+
### Environment requirements
10+
11+
```
12+
Java 8
13+
Maven 3
14+
```
15+
16+
### Configuration
17+
18+
```
19+
server:
20+
port: 9999
21+
22+
management:
23+
endpoints:
24+
web:
25+
exposure:
26+
include: "*"
27+
28+
spring:
29+
groovy:
30+
template:
31+
suffix: .groovy
32+
cache: false
33+
configuration:
34+
auto-new-line: true
35+
auto-indent: true
36+
```
37+
38+
Step 1 Clone Code
39+
```
40+
git clone https://github.com/to-be-architect/geditor
41+
```
42+
43+
Step 2 Run Application
44+
```
45+
mvn spring-boot:run
46+
```
47+
48+
Step 3 Visit geditor
49+
50+
http://localhost:9999/
51+

graph-editor-0.0.1-SNAPSHOT.jar

-33.7 MB
Binary file not shown.

src/main/java/com/mxgraph/online/ExportServlet.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.mxgraph.online;
22

3+
import lombok.extern.slf4j.Slf4j;
34
import org.springframework.beans.factory.annotation.Value;
45

56
import javax.servlet.ServletException;
@@ -23,6 +24,7 @@
2324
*/
2425
@SuppressWarnings("serial")
2526
@WebServlet(name = "ExportServlet", urlPatterns = "/export")
27+
@Slf4j
2628
public class ExportServlet extends HttpServlet {
2729

2830
private final String[] supportedServices = {"EXPORT_URL", "PLANTUML_URL", "VSD_CONVERT_URL", "EMF_CONVERT_URL"};
@@ -107,7 +109,6 @@ private void doRequest(String method, HttpServletRequest request,
107109

108110
if (key != null) {
109111
for (String val : entry.getValue()) {
110-
111112
response.addHeader(entry.getKey(), val);
112113
}
113114
}
@@ -127,9 +128,8 @@ private void doRequest(String method, HttpServletRequest request,
127128
out.flush();
128129
out.close();
129130
} catch (Exception e) {
130-
response.setStatus(
131-
HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
132-
e.printStackTrace();
131+
log.info("", e);
132+
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
133133
}
134134
}
135135

@@ -138,17 +138,15 @@ private void doRequest(String method, HttpServletRequest request,
138138
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
139139
*/
140140
@Override
141-
protected void doGet(HttpServletRequest request,
142-
HttpServletResponse response) throws ServletException, IOException {
141+
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
143142
doRequest("GET", request, response);
144143
}
145144

146145
/**
147146
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
148147
*/
149148
@Override
150-
protected void doPost(HttpServletRequest request,
151-
HttpServletResponse response) throws ServletException, IOException {
149+
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
152150
doRequest("POST", request, response);
153151
}
154152

src/main/java/com/mxgraph/online/GitHubServlet.java

Lines changed: 115 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -4,152 +4,129 @@
44
*/
55
package com.mxgraph.online;
66

7-
import java.io.BufferedReader;
8-
import java.io.DataOutputStream;
9-
import java.io.IOException;
10-
import java.io.InputStreamReader;
11-
import java.io.OutputStream;
12-
import java.io.PrintWriter;
13-
import java.net.HttpURLConnection;
14-
import java.net.URL;
15-
167
import javax.servlet.ServletException;
178
import javax.servlet.http.HttpServlet;
189
import javax.servlet.http.HttpServletRequest;
1910
import javax.servlet.http.HttpServletResponse;
11+
import java.io.*;
12+
import java.net.HttpURLConnection;
13+
import java.net.URL;
2014

2115
/**
2216
* Servlet implementation ProxyServlet
2317
*/
2418
@SuppressWarnings("serial")
25-
public class GitHubServlet extends HttpServlet
26-
{
27-
28-
/**
29-
* Path component under war/ to locate iconfinder_key file.
30-
*/
31-
public static final String DEV_CLIENT_SECRET_FILE_PATH = "/WEB-INF/github_dev_client_secret";
32-
33-
34-
/**
35-
* Path component under war/ to locate iconfinder_key file.
36-
*/
37-
public static final String CLIENT_SECRET_FILE_PATH = "/WEB-INF/github_client_secret";
38-
39-
/**
40-
*
41-
*/
42-
private static String DEV_CLIENT_SECRET = null;
43-
44-
/**
45-
*
46-
*/
47-
private static String CLIENT_SECRET = null;
48-
49-
/**
50-
* @see HttpServlet#HttpServlet()
51-
*/
52-
public GitHubServlet()
53-
{
54-
super();
55-
}
56-
57-
/**
58-
* Loads the key.
59-
*/
60-
protected void updateKeys()
61-
{
62-
if (DEV_CLIENT_SECRET == null)
63-
{
64-
try
65-
{
66-
DEV_CLIENT_SECRET = Utils
67-
.readInputStream(getServletContext()
68-
.getResourceAsStream(DEV_CLIENT_SECRET_FILE_PATH))
69-
.replaceAll("\n", "");
70-
}
71-
catch (IOException e)
72-
{
73-
throw new RuntimeException("Dev client secret path invalid.");
74-
}
75-
}
76-
77-
if (CLIENT_SECRET == null)
78-
{
79-
try
80-
{
81-
CLIENT_SECRET = Utils
82-
.readInputStream(getServletContext()
83-
.getResourceAsStream(CLIENT_SECRET_FILE_PATH))
84-
.replaceAll("\n", "");
85-
}
86-
catch (IOException e)
87-
{
88-
throw new RuntimeException("Client secret path invalid.");
89-
}
90-
}
91-
}
92-
93-
/**
94-
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
95-
*/
96-
protected void doGet(HttpServletRequest request,
97-
HttpServletResponse response) throws ServletException, IOException
98-
{
99-
String client = request.getParameter("client_id");
100-
String code = request.getParameter("code");
101-
updateKeys();
102-
103-
if (client != null && code != null)
104-
{
105-
String secret = client.equals("23bc97120b9035515661") ? DEV_CLIENT_SECRET : CLIENT_SECRET;
106-
107-
String url = "https://github.com/login/oauth/access_token";
108-
URL obj = new URL(url);
109-
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
110-
111-
con.setRequestMethod("POST");
112-
con.setRequestProperty("User-Agent", "draw.io");
113-
114-
String urlParameters = "client_id=" + client + "&client_secret="
115-
+ secret + "&code=" + code;
116-
117-
// Send post request
118-
con.setDoOutput(true);
119-
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
120-
wr.writeBytes(urlParameters);
121-
wr.flush();
122-
wr.close();
123-
124-
BufferedReader in = new BufferedReader(
125-
new InputStreamReader(con.getInputStream()));
126-
String inputLine;
127-
StringBuffer res = new StringBuffer();
128-
129-
while ((inputLine = in.readLine()) != null)
130-
{
131-
res.append(inputLine);
132-
}
133-
in.close();
134-
135-
response.setStatus(con.getResponseCode());
136-
137-
OutputStream out = response.getOutputStream();
138-
139-
// Creates XML for stencils
140-
PrintWriter writer = new PrintWriter(out);
141-
142-
// Writes JavaScript and adds function call with
143-
// stylesheet and stencils as arguments
144-
writer.println(res.toString());
145-
146-
writer.flush();
147-
writer.close();
148-
}
149-
else
150-
{
151-
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
152-
}
153-
}
19+
public class GitHubServlet extends HttpServlet {
20+
21+
/**
22+
* Path component under war/ to locate iconfinder_key file.
23+
*/
24+
public static final String DEV_CLIENT_SECRET_FILE_PATH = "/WEB-INF/github_dev_client_secret";
25+
26+
27+
/**
28+
* Path component under war/ to locate iconfinder_key file.
29+
*/
30+
public static final String CLIENT_SECRET_FILE_PATH = "/WEB-INF/github_client_secret";
31+
32+
/**
33+
*
34+
*/
35+
private static String DEV_CLIENT_SECRET = null;
36+
37+
/**
38+
*
39+
*/
40+
private static String CLIENT_SECRET = null;
41+
42+
/**
43+
* @see HttpServlet#HttpServlet()
44+
*/
45+
public GitHubServlet() {
46+
super();
47+
}
48+
49+
/**
50+
* Loads the key.
51+
*/
52+
protected void updateKeys() {
53+
if (DEV_CLIENT_SECRET == null) {
54+
try {
55+
DEV_CLIENT_SECRET = Utils
56+
.readInputStream(getServletContext()
57+
.getResourceAsStream(DEV_CLIENT_SECRET_FILE_PATH))
58+
.replaceAll("\n", "");
59+
} catch (IOException e) {
60+
throw new RuntimeException("Dev client secret path invalid.");
61+
}
62+
}
63+
64+
if (CLIENT_SECRET == null) {
65+
try {
66+
CLIENT_SECRET = Utils
67+
.readInputStream(getServletContext()
68+
.getResourceAsStream(CLIENT_SECRET_FILE_PATH))
69+
.replaceAll("\n", "");
70+
} catch (IOException e) {
71+
throw new RuntimeException("Client secret path invalid.");
72+
}
73+
}
74+
}
75+
76+
/**
77+
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
78+
*/
79+
protected void doGet(HttpServletRequest request,
80+
HttpServletResponse response) throws ServletException, IOException {
81+
String client = request.getParameter("client_id");
82+
String code = request.getParameter("code");
83+
updateKeys();
84+
85+
if (client != null && code != null) {
86+
String secret = client.equals("23bc97120b9035515661") ? DEV_CLIENT_SECRET : CLIENT_SECRET;
87+
88+
String url = "https://github.com/login/oauth/access_token";
89+
URL obj = new URL(url);
90+
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
91+
92+
con.setRequestMethod("POST");
93+
con.setRequestProperty("User-Agent", "draw.io");
94+
95+
String urlParameters = "client_id=" + client + "&client_secret="
96+
+ secret + "&code=" + code;
97+
98+
// Send post request
99+
con.setDoOutput(true);
100+
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
101+
wr.writeBytes(urlParameters);
102+
wr.flush();
103+
wr.close();
104+
105+
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
106+
String inputLine;
107+
StringBuffer res = new StringBuffer();
108+
109+
while ((inputLine = in.readLine()) != null) {
110+
res.append(inputLine);
111+
}
112+
in.close();
113+
114+
response.setStatus(con.getResponseCode());
115+
116+
OutputStream out = response.getOutputStream();
117+
118+
// Creates XML for stencils
119+
PrintWriter writer = new PrintWriter(out);
120+
121+
// Writes JavaScript and adds function call with
122+
// stylesheet and stencils as arguments
123+
writer.println(res.toString());
124+
125+
writer.flush();
126+
writer.close();
127+
} else {
128+
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
129+
}
130+
}
154131

155132
}

0 commit comments

Comments
 (0)