管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2023-02-19 83cfcab6774fef02fb9a19745cab044c0b7a2d1a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package com.lf.server.controller.data;
 
import com.lf.server.annotation.SysLog;
import com.lf.server.entity.all.StaticData;
import com.lf.server.helper.GdalHelper;
import com.lf.server.helper.StringHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
 
/**
 * WMTS服务
 * @author WWW
 */
@Api(tags = "数据管理\\WMTS服务")
@RestController
@RequestMapping("/wmts")
public class WmtsController {
    private final static Log log = LogFactory.getLog(WmtsController.class);
 
    @SysLog()
    @ApiOperation(value = "查询WMTS元数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌", dataType = "String", required = true, defaultValue = "token", paramType = "path")})
    @GetMapping("select/metas/{token}")
    public void selectMetas(String service, String version, String request, @PathVariable(name = "token") String token, HttpServletRequest req, HttpServletResponse res) {
        try {
            if (!StaticData.WMTS.equals(service) || !StaticData.CAPABILITY.equals(request)) {
                return;
            }
 
            ClassPathResource resource = new ClassPathResource("wmts/web.xml");
            if (!resource.exists()) {
                return;
            }
 
            InputStream stream = resource.getInputStream();
            byte[] data = new byte[stream.available()];
            stream.read(data);
            stream.close();
 
            String result = new String(data, StandardCharsets.UTF_8);
            byte[] bytes = result.getBytes(StandardCharsets.UTF_8);
 
            res.setHeader("Content-Type", "application/xml;charset=UTF-8");
            ServletOutputStream os = res.getOutputStream();
            os.write(bytes);
            os.flush();
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
        }
    }
}