This commit is contained in:
Redkale
2016-09-26 09:05:44 +08:00
parent bc8a52eef8
commit b365b18be0
6 changed files with 18 additions and 18 deletions

7
bin/apidoc.bat Normal file
View 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

View File

@@ -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

View File

@@ -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

View File

@@ -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();
}

View File

@@ -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);
}