Merge branch 'master' into registry-nacos

pull/1/head
tanghc 5 years ago
commit 459f04a459
  1. 3
      sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/AlipayController.java
  2. 9
      sop-website/website-front/pages/sandbox/sandbox.js
  3. 1
      sop-website/website-server/src/main/java/com/gitee/sop/websiteserver/bean/DocItem.java
  4. 78
      sop-website/website-server/src/main/java/com/gitee/sop/websiteserver/bean/HttpTool.java
  5. 3
      sop-website/website-server/src/main/java/com/gitee/sop/websiteserver/controller/SandboxController.java
  6. 10
      sop-website/website-server/src/main/java/com/gitee/sop/websiteserver/manager/SwaggerDocParser.java
  7. 1947
      sop-website/website-server/src/main/resources/api.json

@ -10,6 +10,7 @@ import io.swagger.annotations.ApiOperation;
import lombok.Data;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
@ -126,7 +127,7 @@ public class AlipayController {
* @return
*/
@ApiOperation(value="获取分类信息", notes = "演示表格树")
@ApiMapping(value = "alipay.category.get")
@ApiMapping(value = "alipay.category.get", method = RequestMethod.POST)
public Category getCategory(Category story) {
StoryVO storyVO = new StoryVO();
storyVO.id = 1L;

@ -101,10 +101,11 @@ function doTest() {
var method = currentItem.name;
var version = currentItem.version;
var data = {
appId: $('#appId').val(),
privateKey: $('#privateKey').val(),
method: method,
version: version
appId: $('#appId').val()
, privateKey: $('#privateKey').val()
, method: method
, version: version
, httpMethod: currentItem.httpMethod
};
var uploadFileObjects = getUploadFileObjects();
var $inputs = $body.find('.test-input');

@ -16,6 +16,7 @@ public class DocItem {
private String description;
// 是否多文件上传
private boolean multiple;
private String httpMethod;
List<DocParameter> requestParameters;
List<DocParameter> responseParameters;

@ -46,6 +46,7 @@ public class HttpTool {
public void saveFromResponse(HttpUrl httpUrl, List<Cookie> list) {
cookieStore.put(httpUrl.host(), list);
}
public List<Cookie> loadForRequest(HttpUrl httpUrl) {
List<Cookie> cookies = cookieStore.get(httpUrl.host());
return cookies != null ? cookies : new ArrayList<Cookie>();
@ -55,11 +56,17 @@ public class HttpTool {
@Data
public static class HttpToolConfig {
/** 请求超时时间 */
/**
* 请求超时时间
*/
private int connectTimeoutSeconds = 10;
/** http读取超时时间 */
/**
* http读取超时时间
*/
private int readTimeoutSeconds = 10;
/** http写超时时间 */
/**
* http写超时时间
*/
private int writeTimeoutSeconds = 10;
}
@ -84,33 +91,15 @@ public class HttpTool {
/**
* 提交表单
*
* @param url url
* @param form 参数
* @param url url
* @param form 参数
* @param header header
* @param method 请求方式postget等
* @return
* @throws IOException
*/
public String request(String url, Map<String, String> form, Map<String, String> header, String method) throws IOException {
Request.Builder requestBuilder;
if (METHOD_GET.equalsIgnoreCase(method)) {
HttpUrl.Builder urlBuilder = HttpUrl.parse(url).newBuilder();
for (Map.Entry<String, String> entry : form.entrySet()) {
urlBuilder.addQueryParameter(entry.getKey(), entry.getValue());
}
requestBuilder = new Request.Builder()
.url(urlBuilder.build())
.get();
} else {
FormBody.Builder paramBuilder = new FormBody.Builder(StandardCharsets.UTF_8);
for (Map.Entry<String, String> entry : form.entrySet()) {
paramBuilder.add(entry.getKey(), entry.getValue());
}
FormBody formBody = paramBuilder.build();
requestBuilder = new Request.Builder()
.url(url)
.method(method, formBody);
}
Request.Builder requestBuilder = buildRequestBuilder(url, form, method);
// 添加header
addHeader(requestBuilder, header);
@ -125,6 +114,47 @@ public class HttpTool {
}
}
public static Request.Builder buildRequestBuilder(String url, Map<String, String> form, String method) {
switch (method) {
case "get":
return new Request.Builder()
.url(buildHttpUrl(url, form))
.get();
case "head":
return new Request.Builder()
.url(buildHttpUrl(url, form))
.head();
case "put":
return new Request.Builder()
.url(url)
.put(buildFormBody(form));
case "delete":
return new Request.Builder()
.url(url)
.delete(buildFormBody(form));
default:
return new Request.Builder()
.url(url)
.post(buildFormBody(form));
}
}
public static HttpUrl buildHttpUrl(String url, Map<String, String> form) {
HttpUrl.Builder urlBuilder = HttpUrl.parse(url).newBuilder();
for (Map.Entry<String, String> entry : form.entrySet()) {
urlBuilder.addQueryParameter(entry.getKey(), entry.getValue());
}
return urlBuilder.build();
}
public static FormBody buildFormBody(Map<String, String> form) {
FormBody.Builder paramBuilder = new FormBody.Builder(StandardCharsets.UTF_8);
for (Map.Entry<String, String> entry : form.entrySet()) {
paramBuilder.add(entry.getKey(), entry.getValue());
}
return paramBuilder.build();
}
/**
* 提交表单并且上传文件
*

@ -58,6 +58,7 @@ public class SandboxController {
, @RequestParam String method
, @RequestParam String version
, @RequestParam String bizContent
, @RequestParam(defaultValue = "get") String httpMethod
, HttpServletRequest request) throws AlipayApiException {
Assert.isTrue(StringUtils.isNotBlank(appId), "AppId不能为空");
@ -112,7 +113,7 @@ public class SandboxController {
if (!CollectionUtils.isEmpty(files)) {
responseData = httpTool.requestFile(url, params, Collections.emptyMap(), files);
} else {
responseData = httpTool.request(url, params, Collections.emptyMap(), "get");
responseData = httpTool.request(url, params, Collections.emptyMap(), httpMethod);
}
result.apiResult = responseData;
return result;

@ -30,14 +30,16 @@ public class SwaggerDocParser implements DocParser {
JSONObject paths = docRoot.getJSONObject("paths");
Set<String> pathNameSet = paths.keySet();
for (String pathName : pathNameSet) {
JSONObject pathInfo = paths.getJSONObject(pathName);
for (String apiPath : pathNameSet) {
JSONObject pathInfo = paths.getJSONObject(apiPath);
// key: get,post,head...
Set<String> pathSet = pathInfo.keySet();
Optional<String> first = pathSet.stream().findFirst();
if (first.isPresent()) {
String path = first.get();
JSONObject docInfo = pathInfo.getJSONObject(path);
String method = first.get();
JSONObject docInfo = pathInfo.getJSONObject(method);
DocItem docItem = buildDocItem(docInfo, docRoot);
docItem.setHttpMethod(method);
docItems.add(docItem);
}
}

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save