package com.moon.server.controller.sys; import com.moon.server.helper.WebHelper; import com.moon.server.service.sys.ProxyService; import com.sun.istack.NotNull; 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.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @SuppressWarnings("ALL") @Api(tags = "运维管理\\代理服务") @RestController @RequestMapping("/proxy") public class ProxyController { @Resource ProxyService proxyService; private static final Log log = LogFactory.getLog(ProxyController.class); @ApiOperation(value = "URL代理", notes = "URL代理") @ApiImplicitParams({ @ApiImplicitParam(name = "token", value = "令牌", dataType = "String", paramType = "path", required = true, example = "1eb2ea8f-5cfd-4e6c-95c9-17ab0f7bce71"), @ApiImplicitParam(name = "id", value = "ID", dataType = "int", paramType = "path", required = true, example = "1"), }) @RequestMapping(value = {"/{token}/{id}/**"}) public void proxyUrl(@NotNull @PathVariable String token, @NotNull @PathVariable int id, HttpServletRequest req, HttpServletResponse res) { try { proxyService.proxyUrl(token, id, false, req, res); } catch (Exception ex) { log.error(ex.getMessage(), ex); WebHelper.writeStr2Page(res, ex.getMessage()); } } @ApiOperation(value = "URL代理", notes = "URL代理") @ApiImplicitParams({ @ApiImplicitParam(name = "token", value = "令牌", dataType = "String", paramType = "path", required = true, example = "1eb2ea8f-5cfd-4e6c-95c9-17ab0f7bce71"), @ApiImplicitParam(name = "id", value = "ID", dataType = "int", paramType = "path", required = true, example = "1"), }) @RequestMapping(value = {"/rest/{token}/{id}/**"}) public void proxyRestUrl(@NotNull @PathVariable String token, @NotNull @PathVariable int id, HttpServletRequest req, HttpServletResponse res) { try { proxyService.proxyUrl(token, id, true, req, res); } catch (Exception ex) { log.error(ex.getMessage(), ex); WebHelper.writeStr2Page(res, ex.getMessage()); } } }