场景:
我有一个swagger-ui页面的重定向,以使其更容易到达。(骆驼让我伤感)
当我在本地运行时,我使用HTTP。
当我在测试服务器中运行时,我使用HTTPS。
或者,我也可以通过配置camel流(xml)来更改swagger页面的默认url。
预期- (https重定向到https)和(http重定向到http):
http://localhost:8080/swagger-ui
--> http://localhost:8080/webjars/swagger-ui/index.html?url=/api/swagger&validatorUrl=
https://remote.com/swagger-ui
--> https://remote.com/webjars/swagger-ui/index.html?url=/api/swagger&validatorUrl=
Actual - https & http重定向到http:
http://localhost:8080/swagger-ui
--> http://localhost:8080/webjars/swagger-ui/index.html?url=/api/swagger&validatorUrl=
https://remote.com/swagger-ui
--> http://remote.com/webjars/swagger-ui/index.html?url=/api/swagger&validatorUrl=
代码:
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class SwaggerController {
@RequestMapping("/swagger-ui")
public String redirectToUi() {
return "redirect:/webjars/swagger-ui/index.html?url=/api/swagger&validatorUrl=";
}
@RequestMapping("/swagger-ui.html")
public String redirectToUi2() {
return "redirect:/webjars/swagger-ui/index.html?url=/api/swagger&validatorUrl=";
}
}
<restConfiguration
component="servlet"
apiContextPath="swagger"
contextPath="api"
enableCORS="true"
bindingMode="json">
<dataFormatProperty key="prettyPrint" value="true"/>
<!-- setup swagger api description -->
<apiProperty key="base.path" value="api"/>
<apiProperty key="api.version" value=".0.0.1"/>
<apiProperty key="api.title" value="Some Forms"/>
<apiProperty key="api.description" value="Description Here"/>
<apiProperty key="api.contact.name" value="Contact here"/>
</restConfiguration>
发布于 2019-06-22 00:05:28
这是因为逻辑视图名称(例如" redirect :/myapp/some/resource")会将您的调用重定向到当前的Servlet上下文,在您的例子中,上下文的方案是HTTP。
您需要为这种情况实现不同的上下文(一个用于HTTP,另一个用于HTTPS),然后您可以使用camel-servlet代理调用
上下文1- http:
from("servlet:myapp?matchOnUriPrefix=true")
.to("http://newURL?bridgeEndpoint=true&throwExceptionOnFailure=false")
上下文2- https:
from("servlet:myapp?matchOnUriPrefix=true")
.to("https://newURL?bridgeEndpoint=true&throwExceptionOnFailure=false")
https://stackoverflow.com/questions/56690542
复制相似问题