This commit is contained in:
7
bin/apidoc.bat
Normal file
7
bin/apidoc.bat
Normal file
@@ -0,0 +1,7 @@
|
||||
@ECHO OFF
|
||||
|
||||
SET APP_HOME=%~dp0
|
||||
|
||||
IF NOT EXIST "%APP_HOME%\conf\application.xml" SET APP_HOME=%~dp0..
|
||||
|
||||
java -DCMD=APIDOC -DAPP_HOME=%APP_HOME% -classpath %APP_HOME%\lib\* org.redkale.boot.Application
|
||||
@@ -15,4 +15,4 @@ do
|
||||
done
|
||||
export CLASSPATH=$CLASSPATH:$lib
|
||||
echo "$APP_HOME"
|
||||
java -DCMD=RESTDOC -DAPP_HOME="$APP_HOME" org.redkale.boot.Application
|
||||
java -DCMD=APIDOC -DAPP_HOME="$APP_HOME" org.redkale.boot.Application
|
||||
@@ -1,7 +0,0 @@
|
||||
@ECHO OFF
|
||||
|
||||
SET APP_HOME=%~dp0
|
||||
|
||||
IF NOT EXIST "%APP_HOME%\conf\application.xml" SET APP_HOME=%~dp0..
|
||||
|
||||
java -DCMD=RESTDOC -DAPP_HOME=%APP_HOME% -classpath %APP_HOME%\lib\* org.redkale.boot.Application
|
||||
@@ -17,11 +17,11 @@ import org.redkale.util.*;
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public class RestDocs extends HttpBaseServlet {
|
||||
public class ApiDocs extends HttpBaseServlet {
|
||||
|
||||
private final Application app;
|
||||
|
||||
public RestDocs(Application app) {
|
||||
public ApiDocs(Application app) {
|
||||
this.app = app;
|
||||
}
|
||||
|
||||
@@ -123,18 +123,18 @@ public class RestDocs extends HttpBaseServlet {
|
||||
resultmap.put("servers", serverList);
|
||||
resultmap.put("types", typesmap);
|
||||
final String json = JsonConvert.root().convertTo(resultmap);
|
||||
final FileOutputStream out = new FileOutputStream(new File(app.getHome(), "restdoc.json"));
|
||||
final FileOutputStream out = new FileOutputStream(new File(app.getHome(), "apidoc.json"));
|
||||
out.write(json.getBytes("UTF-8"));
|
||||
out.close();
|
||||
File doctemplate = new File(app.getHome(), "conf/restdoc-template.html");
|
||||
File doctemplate = new File(app.getHome(), "conf/apidoc-template.html");
|
||||
InputStream in = null;
|
||||
if (doctemplate.isFile() && doctemplate.canRead()) {
|
||||
in = new FileInputStream(doctemplate);
|
||||
}
|
||||
if (in == null) in = RestDocs.class.getResourceAsStream("restdoc-template.html");
|
||||
if (in == null) in = ApiDocs.class.getResourceAsStream("apidoc-template.html");
|
||||
String content = Utility.read(in).replace("${content}", json);
|
||||
in.close();
|
||||
FileOutputStream outhtml = new FileOutputStream(new File(app.getHome(), "restdoc.html"));
|
||||
FileOutputStream outhtml = new FileOutputStream(new File(app.getHome(), "apidoc.html"));
|
||||
outhtml.write(content.getBytes("UTF-8"));
|
||||
outhtml.close();
|
||||
}
|
||||
@@ -388,16 +388,16 @@ public final class Application {
|
||||
buffer.flip();
|
||||
channel.send(buffer, address);
|
||||
}
|
||||
} else if ("RESTDOC".equalsIgnoreCase(new String(bytes))) {
|
||||
} else if ("APIDOC".equalsIgnoreCase(new String(bytes))) {
|
||||
try {
|
||||
new RestDocs(application).run();
|
||||
new ApiDocs(application).run();
|
||||
buffer.clear();
|
||||
buffer.put("RESTDOC OK".getBytes());
|
||||
buffer.put("APIDOC OK".getBytes());
|
||||
buffer.flip();
|
||||
channel.send(buffer, address);
|
||||
} catch (Exception ex) {
|
||||
buffer.clear();
|
||||
buffer.put("RESTDOC FAIL".getBytes());
|
||||
buffer.put("APIDOC FAIL".getBytes());
|
||||
buffer.flip();
|
||||
channel.send(buffer, address);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user