Commit 8d9531c04c4110e288fa9dabb3c6e1d8e8df08f2
Exists in
master
Merge remote-tracking branch 'origin/master'
Showing
9 changed files
with
154 additions
and
93 deletions
Show diff stats
cloud/fIle-center/src/main/java/com/sincere/file/FileApplication.java
... | ... | @@ -4,6 +4,7 @@ import org.springframework.boot.SpringApplication; |
4 | 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; |
5 | 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; |
6 | 6 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; |
7 | +import org.springframework.context.annotation.Configuration; | |
7 | 8 | |
8 | 9 | @EnableDiscoveryClient |
9 | 10 | @SpringBootApplication | ... | ... |
cloud/fIle-center/src/main/java/com/sincere/file/Test.java
0 → 100644
... | ... | @@ -0,0 +1,29 @@ |
1 | +package com.sincere.file; | |
2 | + | |
3 | +import org.springframework.core.io.FileSystemResource; | |
4 | +import org.springframework.http.HttpEntity; | |
5 | +import org.springframework.http.HttpHeaders; | |
6 | +import org.springframework.http.MediaType; | |
7 | +import org.springframework.http.ResponseEntity; | |
8 | +import org.springframework.util.LinkedMultiValueMap; | |
9 | +import org.springframework.util.MultiValueMap; | |
10 | +import org.springframework.web.client.RestTemplate; | |
11 | + | |
12 | +import java.io.File; | |
13 | + | |
14 | +public class Test { | |
15 | + | |
16 | + public static void main(String[] args) { | |
17 | +// String url = "http://121.40.30.78:5000/file/fileUpload"; | |
18 | + String url = "http://localhost:5000/file/fileUpload"; | |
19 | + | |
20 | + RestTemplate rest = new RestTemplate(); | |
21 | + FileSystemResource resource = new FileSystemResource(new File("C:\\Users\\Administrator\\Pictures\\闸机权限.png")); | |
22 | + MultiValueMap<String, Object> param = new LinkedMultiValueMap<>(); | |
23 | + param.add("file", resource); | |
24 | +// param.add("fileName", "test.txt"); | |
25 | + String string = rest.postForObject(url, param, String.class); | |
26 | + System.out.println("sssssssssssss:"+string); | |
27 | + } | |
28 | + | |
29 | +} | ... | ... |
cloud/fIle-center/src/main/java/com/sincere/file/control/FileControl.java
... | ... | @@ -31,6 +31,18 @@ public class FileControl { |
31 | 31 | |
32 | 32 | } |
33 | 33 | |
34 | + @PostMapping("fileUpload1") | |
35 | + @ApiOperation("上传文件") | |
36 | + public String fileUpload1(@RequestParam("file") MultipartFile file) throws Exception { | |
37 | + | |
38 | +// String ossPath = request.getHeader("ossPath");//oss的二级目录 | |
39 | +// | |
40 | +// FileInfo fileInfo = fileService.upload(file, ossPath); | |
41 | + | |
42 | + return "111"; | |
43 | + | |
44 | + } | |
45 | + | |
34 | 46 | |
35 | 47 | @DeleteMapping("deleteFile/{fileName}") |
36 | 48 | @ApiOperation("删除文件") | ... | ... |
cloud/fIle-center/src/main/java/com/sincere/file/service/impl/AliyunOssServiceImpl.java
... | ... | @@ -39,7 +39,7 @@ public class AliyunOssServiceImpl extends AbstractFileService { |
39 | 39 | @Override |
40 | 40 | protected void uploadFile(MultipartFile file, FileInfo fileInfo,String filePath) throws Exception { |
41 | 41 | ossClient.putObject(bucketName, filePath+"/"+fileInfo.getName(), file.getInputStream()); |
42 | - fileInfo.setUrl(domain + "/" + fileInfo.getName()); | |
42 | + fileInfo.setUrl(domain+"/" +filePath+ "/" + fileInfo.getName()); | |
43 | 43 | } |
44 | 44 | |
45 | 45 | @Override | ... | ... |
cloud/fIle-center/src/main/resources/bootstrap.yml
... | ... | @@ -11,15 +11,15 @@ spring: |
11 | 11 | multipart: |
12 | 12 | max-request-size: 400MB |
13 | 13 | max-file-size: 400MB |
14 | - | |
15 | -management: | |
16 | - endpoints: | |
17 | - web: | |
18 | - exposure: | |
19 | - include: "*" | |
20 | - endpoint: | |
21 | - health: | |
22 | - show-details: always | |
14 | + | |
15 | +#management: | |
16 | +# endpoints: | |
17 | +# web: | |
18 | +# exposure: | |
19 | +# include: "*" | |
20 | +# endpoint: | |
21 | +# health: | |
22 | +# show-details: always | |
23 | 23 | |
24 | 24 | #eureka client配置 |
25 | 25 | eureka: | ... | ... |
... | ... | @@ -0,0 +1,17 @@ |
1 | +<!DOCTYPE html> | |
2 | +<html lang="en"> | |
3 | +<head> | |
4 | + <meta charset="UTF-8"> | |
5 | + <title>Title</title> | |
6 | +</head> | |
7 | +<body> | |
8 | + | |
9 | +<div class="control-group js_uploadBox"> | |
10 | + <div class="btn-upload"> | |
11 | + <a href="javascript:void(0);"><i class="icon-upload"></i><span class="js_uploadText">上传</span>图片</a> | |
12 | + <input class="js_upFile" type="file" name="cover" id="btnimages"> | |
13 | + </div> | |
14 | + <div class="js_showBox "><img class="js_logoBox" src="" width="100px" ></div> | |
15 | +</div> | |
16 | +</body> | |
17 | +</html> | |
0 | 18 | \ No newline at end of file | ... | ... |
cloud/getaway/src/main/java/com/sincere/getaway/client/config/CorsConfig.java
1 | -//package com.sincere.getaway.client.config; | |
2 | -// | |
3 | -//import org.springframework.cloud.client.discovery.DiscoveryClient; | |
4 | -//import org.springframework.cloud.gateway.discovery.DiscoveryClientRouteDefinitionLocator; | |
5 | -//import org.springframework.cloud.gateway.discovery.DiscoveryLocatorProperties; | |
6 | -//import org.springframework.cloud.gateway.route.RouteDefinitionLocator; | |
7 | -//import org.springframework.context.annotation.Bean; | |
8 | -//import org.springframework.context.annotation.Configuration; | |
9 | -//import org.springframework.http.HttpHeaders; | |
10 | -//import org.springframework.http.HttpMethod; | |
11 | -//import org.springframework.http.HttpStatus; | |
12 | -//import org.springframework.http.codec.ServerCodecConfigurer; | |
13 | -//import org.springframework.http.codec.support.DefaultServerCodecConfigurer; | |
14 | -//import org.springframework.http.server.reactive.ServerHttpRequest; | |
15 | -//import org.springframework.http.server.reactive.ServerHttpResponse; | |
16 | -//import org.springframework.web.cors.reactive.CorsUtils; | |
17 | -//import org.springframework.web.server.ServerWebExchange; | |
18 | -//import org.springframework.web.server.WebFilter; | |
19 | -//import org.springframework.web.server.WebFilterChain; | |
20 | -// | |
21 | -//import reactor.core.publisher.Mono; | |
22 | -// | |
23 | -///** | |
24 | -// * * 程序名 : CorsConfig | |
25 | -// * 建立日期: 2018-09-09 | |
26 | -// * 作者 : someday | |
27 | -// * 模块 : 网关 | |
28 | -// * 描述 : 跨域 | |
29 | -// * 备注 : version20180909001 | |
30 | -// * <p> | |
31 | -// * 修改历史 | |
32 | -// * 序号 日期 修改人 修改原因 | |
33 | -// */ | |
34 | -//@Configuration | |
35 | -//public class CorsConfig { | |
36 | -// private static final String ALL = "*"; | |
37 | -// private static final String MAX_AGE = "18000L"; | |
38 | -// | |
39 | -// @Bean | |
40 | -// public RouteDefinitionLocator discoveryClientRouteDefinitionLocator(DiscoveryClient discoveryClient, | |
41 | -// DiscoveryLocatorProperties properties) { | |
42 | -// return new DiscoveryClientRouteDefinitionLocator(discoveryClient, properties); | |
43 | -// } | |
44 | -// | |
45 | -// @Bean | |
46 | -// public ServerCodecConfigurer serverCodecConfigurer() { | |
47 | -// return new DefaultServerCodecConfigurer(); | |
48 | -// } | |
49 | -// | |
50 | -// @Bean | |
51 | -// public WebFilter corsFilter() { | |
52 | -// return (ServerWebExchange ctx, WebFilterChain chain) -> { | |
53 | -// ServerHttpRequest request = ctx.getRequest(); | |
54 | -// if (!CorsUtils.isCorsRequest(request)) { | |
55 | -// return chain.filter(ctx); | |
56 | -// } | |
57 | -// HttpHeaders requestHeaders = request.getHeaders(); | |
58 | -// ServerHttpResponse response = ctx.getResponse(); | |
59 | -// HttpMethod requestMethod = requestHeaders.getAccessControlRequestMethod(); | |
60 | -// HttpHeaders headers = response.getHeaders(); | |
61 | -// headers.add(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, requestHeaders.getOrigin()); | |
62 | -// headers.addAll(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS, requestHeaders.getAccessControlRequestHeaders()); | |
63 | -// if (requestMethod != null) { | |
64 | -// headers.add(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS, requestMethod.name()); | |
65 | -// } | |
66 | -// headers.add(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS, "true"); | |
67 | -// headers.add(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS, ALL); | |
68 | -// headers.add(HttpHeaders.ACCESS_CONTROL_MAX_AGE, MAX_AGE); | |
69 | -// if (request.getMethod() == HttpMethod.OPTIONS) { | |
70 | -// response.setStatusCode(HttpStatus.OK); | |
71 | -// return Mono.empty(); | |
72 | -// } | |
73 | -// return chain.filter(ctx); | |
74 | -// }; | |
75 | -// } | |
76 | -//} | |
1 | +package com.sincere.getaway.client.config; | |
2 | + | |
3 | +import org.springframework.cloud.client.discovery.DiscoveryClient; | |
4 | +import org.springframework.cloud.gateway.discovery.DiscoveryClientRouteDefinitionLocator; | |
5 | +import org.springframework.cloud.gateway.discovery.DiscoveryLocatorProperties; | |
6 | +import org.springframework.cloud.gateway.route.RouteDefinitionLocator; | |
7 | +import org.springframework.context.annotation.Bean; | |
8 | +import org.springframework.context.annotation.Configuration; | |
9 | +import org.springframework.http.HttpHeaders; | |
10 | +import org.springframework.http.HttpMethod; | |
11 | +import org.springframework.http.HttpStatus; | |
12 | +import org.springframework.http.codec.ServerCodecConfigurer; | |
13 | +import org.springframework.http.codec.support.DefaultServerCodecConfigurer; | |
14 | +import org.springframework.http.server.reactive.ServerHttpRequest; | |
15 | +import org.springframework.http.server.reactive.ServerHttpResponse; | |
16 | +import org.springframework.web.cors.reactive.CorsUtils; | |
17 | +import org.springframework.web.server.ServerWebExchange; | |
18 | +import org.springframework.web.server.WebFilter; | |
19 | +import org.springframework.web.server.WebFilterChain; | |
20 | + | |
21 | +import reactor.core.publisher.Mono; | |
22 | + | |
23 | +/** | |
24 | + * * 程序名 : CorsConfig | |
25 | + * 建立日期: 2018-09-09 | |
26 | + * 作者 : someday | |
27 | + * 模块 : 网关 | |
28 | + * 描述 : 跨域 | |
29 | + * 备注 : version20180909001 | |
30 | + * <p> | |
31 | + * 修改历史 | |
32 | + * 序号 日期 修改人 修改原因 | |
33 | + */ | |
34 | +@Configuration | |
35 | +public class CorsConfig { | |
36 | + private static final String ALL = "*"; | |
37 | + private static final String MAX_AGE = "18000L"; | |
38 | + | |
39 | + @Bean | |
40 | + public RouteDefinitionLocator discoveryClientRouteDefinitionLocator(DiscoveryClient discoveryClient, | |
41 | + DiscoveryLocatorProperties properties) { | |
42 | + return new DiscoveryClientRouteDefinitionLocator(discoveryClient, properties); | |
43 | + } | |
44 | + | |
45 | + @Bean | |
46 | + public ServerCodecConfigurer serverCodecConfigurer() { | |
47 | + return new DefaultServerCodecConfigurer(); | |
48 | + } | |
49 | + | |
50 | + @Bean | |
51 | + public WebFilter corsFilter() { | |
52 | + return (ServerWebExchange ctx, WebFilterChain chain) -> { | |
53 | + ServerHttpRequest request = ctx.getRequest(); | |
54 | + if (!CorsUtils.isCorsRequest(request)) { | |
55 | + return chain.filter(ctx); | |
56 | + } | |
57 | + HttpHeaders requestHeaders = request.getHeaders(); | |
58 | + ServerHttpResponse response = ctx.getResponse(); | |
59 | + HttpMethod requestMethod = requestHeaders.getAccessControlRequestMethod(); | |
60 | + HttpHeaders headers = response.getHeaders(); | |
61 | + headers.add(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, requestHeaders.getOrigin()); | |
62 | + headers.addAll(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS, requestHeaders.getAccessControlRequestHeaders()); | |
63 | + if (requestMethod != null) { | |
64 | + headers.add(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS, requestMethod.name()); | |
65 | + } | |
66 | + headers.add(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS, "true"); | |
67 | + headers.add(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS, ALL); | |
68 | + headers.add(HttpHeaders.ACCESS_CONTROL_MAX_AGE, MAX_AGE); | |
69 | + if (request.getMethod() == HttpMethod.OPTIONS) { | |
70 | + response.setStatusCode(HttpStatus.OK); | |
71 | + return Mono.empty(); | |
72 | + } | |
73 | + return chain.filter(ctx); | |
74 | + }; | |
75 | + } | |
76 | +} | ... | ... |
cloud/getaway/src/main/resources/application.yml
... | ... | @@ -14,12 +14,12 @@ eureka: |
14 | 14 | spring: |
15 | 15 | cloud: |
16 | 16 | gateway: |
17 | - globalcors: | |
18 | - corsConfigurations: | |
19 | - '[/**]': | |
20 | - allowedOrigins: "*" | |
21 | - allowedMethods: "*" | |
22 | - allowedHeaders: "*" | |
17 | +# globalcors: | |
18 | +# corsConfigurations: | |
19 | +# '[/**]': | |
20 | +# allowedOrigins: "*" | |
21 | +# allowedMethods: "*" | |
22 | +# allowedHeaders: "*" | |
23 | 23 | routes: |
24 | 24 | - id: usersearch |
25 | 25 | uri: http://121.40.30.78:9004 |
... | ... | @@ -77,4 +77,4 @@ ribbon: |
77 | 77 | |
78 | 78 | |
79 | 79 | url: |
80 | - ignored: /SmartCampusWebApi/**,/authserver/**,/NewSmartCampus/** | |
81 | 80 | \ No newline at end of file |
81 | + ignored: /SmartCampusWebApi/**,/authserver/**,/NewSmartCampus/**,/file-center/** | |
82 | 82 | \ No newline at end of file | ... | ... |
cloud/haikangface/src/test/java/com/sincere/haikangface/HaikangfaceApplicationTests.java