eureka
tanghc 4 years ago
parent eecbce1e4d
commit 3fce909a35
  1. 13
      sop-gateway/src/main/java/com/gitee/sop/gateway/interceptor/MyRouteInterceptor.java
  2. 11
      sop-gateway/src/main/resources/META-INF/gateway.properties
  3. 3
      sop-gateway/src/main/resources/application-dev.properties
  4. BIN
      sop-test/src/main/resources/large_img.png
  5. 23
      sop-test/src/test/java/com/gitee/sop/test/AllInOneTest.java

@ -4,7 +4,6 @@ import com.gitee.sop.gatewaycommon.interceptor.RouteInterceptor;
import com.gitee.sop.gatewaycommon.interceptor.RouteInterceptorContext;
import com.gitee.sop.gatewaycommon.param.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.stereotype.Component;
/**
@ -19,16 +18,16 @@ public class MyRouteInterceptor implements RouteInterceptor {
@Override
public void preRoute(RouteInterceptorContext context) {
ApiParam apiParam = context.getApiParam();
log.info("请求接口:{}, ip:{}", apiParam.fetchNameVersion(), apiParam.fetchIp());
log.info("请求接口:{}, request_id:{}, app_id:{}, ip:{}",
apiParam.fetchNameVersion(),
apiParam.fetchRequestId(),
apiParam.fetchAppKey(),
apiParam.fetchIp()
);
}
@Override
public void afterRoute(RouteInterceptorContext context) {
ServiceInstance serviceInstance = context.getServiceInstance();
log.info("请求成功,serviceId:{}({}:{}),微服务返回结果:{}",
serviceInstance.getServiceId(),
serviceInstance.getHost(),serviceInstance.getPort(),
context.getServiceResult());
}
@Override

@ -3,6 +3,10 @@ spring.application.name=sop-gateway
# 不用改,如果要改,请全局替换修改
sop.secret=MZZOUSTua6LzApIWXCwEgbBmxSzpzC
# 文件上传配置
spring.servlet.multipart.enabled=true
spring.servlet.multipart.max-file-size=10MB
# 网关入口
sop.gateway-index-path=/
@ -33,10 +37,3 @@ mybatis.mapper-locations=classpath:mybatis/mapper/*.xml
mybatis.fill.com.gitee.fastmybatis.core.support.DateFillInsert=gmt_create
mybatis.fill.com.gitee.fastmybatis.core.support.DateFillUpdate=gmt_modified
# POST请求最大缓存,默认是262144(256KB),即:256 * 1024
# 如果需要传输大文本可以把值设置高一点
spring.codec.max-in-memory-size=262144
# 文件上传配置
spring.servlet.multipart.enabled=true
spring.servlet.multipart.max-file-size=10MB

@ -9,4 +9,7 @@ mysql.password=root
# nacos注册中心地址
register.url=127.0.0.1:8848
# 上传文件最大容量,默认10MB
spring.servlet.multipart.max-file-size=10MB
logging.level.com.gitee=debug

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB

@ -224,6 +224,29 @@ public class AllInOneTest extends TestBase {
client.execute(requestBuilder);
}
/**
* 演示大文件上传先配置网关参数spring.servlet.multipart.max-file-size=1MB
*/
public void testBigFile() {
Client client = new Client(url, appId, privateKey);
String root = System.getProperty("user.dir");
Client.RequestBuilder requestBuilder = new Client.RequestBuilder()
.method("file.upload3")
.version("1.0")
.bizContent(new BizContent().add("remark", "test file upload"))
// 添加文件
.addFile("image", new File(root + "/src/main/resources/large_img.png"))
.callback((requestInfo, responseData) -> {
System.out.println(responseData);
JSONObject jsonObject = JSON.parseObject(responseData);
JSONObject data = jsonObject.getJSONObject(requestInfo.getDataNode());
Assert.assertEquals(data.getString("sub_code"), "isv.invalid-file-size");
})
;
client.execute(requestBuilder);
}
/**
* 传递header
*/

Loading…
Cancel
Save