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