带着码头的骡子大摇大摆的一代
swagger generation in mule with jetty
我正在尝试从我的 apis.I 中使用 mule 生成 swagger,并为此添加了这个码头连接器。我的 mule 服务器在 8080
上 运行
<jetty:connector name="jettyConnector">
<jetty:webapps directory="${app.home}/webapps" port="8083"/>
</jetty:connector>
我在src/main/app/webapps/swaggerdoc/WEB-INF/web.xml下添加了web.xml,内容是:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>Swagger doc</display-name>
<description>swagger doc</description>
<servlet>
<servlet-name>JerseyJaxrsConfig</servlet-name>
<servlet-class>com.wordnik.swagger.jersey.config.JerseyJaxrsConfig</servlet-class>
<init-param>
<param-name>api.version</param-name>
<param-value>1.0.0</param-value>
</init-param>
<init-param>
<param-name>swagger.api.basepath</param-name>
<param-value>http://localhost:8002/api</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet>
<servlet-name>jersey</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.rest.types.resource;com.wordnik.swagger.jersey.listing</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>jersey</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
并且 pom 文件具有此依赖项:
<dependency>
<groupId>com.wordnik</groupId>
<artifactId>swagger-jaxrs_2.10</artifactId>
<version>1.3.12</version>
</dependency>
但是当我击中 http://localhost:8080/api 时启动 mule 后,它会抛出 "Not Authorized"。我已正确使用 api 上的所有注释。
任何帮助将不胜感激。最近几天我一直被这个问题困扰。
我试图从中生成 swagger 的接口:
@Path("/api-docs")
@Api(value = "/transactions", description = "Update APIs")
public interface BaseResource {
@PUT
@ApiOperation(value = "updateTransactions", notes = "update Transaction.", httpMethod = "PUT")
@ApiResponses({ @ApiResponse(code = HttpServletResponse.SC_ACCEPTED, message = "Accepted"),
@ApiResponse(code = HttpServletResponse.SC_BAD_REQUEST, message = "Bad Request"),
@ApiResponse(code = HttpServletResponse.SC_UNAUTHORIZED, message = "Unauthorized "),
@ApiResponse(code = HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message = "Internal Server Error") })
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
BaseResource.PutTransactionsResponse updateTransactions(
@ApiParam(name = "Authorization",
defaultValue = "",
required = true) @HeaderParam("Authorization") String authorizationHeader,
UpdateRequest entity)
throws Exception;
}
骡子流:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:jetty="http://www.mulesoft.org/schema/mule/jetty"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:jersey="http://www.mulesoft.org/schema/mule/jersey"
xmlns:apikit="http://www.mulesoft.org/schema/mule/apikit" xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:jms="http://www.mulesoft.org/schema/mule/jms" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking"
xmlns:vm="http://www.mulesoft.org/schema/mule/vm" xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.6.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/jetty http://www.mulesoft.org/schema/mule/jetty/current/mule-jetty.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-current.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/jms http://www.mulesoft.org/schema/mule/jms/current/mule-jms.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/apikit http://www.mulesoft.org/schema/mule/apikit/current/mule-apikit.xsd
http://www.mulesoft.org/schema/mule/jersey http://www.mulesoft.org/schema/mule/jersey/current/mule-jersey.xsd">
<context:property-placeholder location="classpath:mule-app.properties" />
<spring:beans>
<spring:bean id="apiListingJSON"
class="com.wordnik.swagger.mule.ApiListingJSON" />
<spring:bean id="swaggerConfig"
class="com.wordnik.swagger.jaxrs.config.BeanConfig">
<spring:property name="resourcePackage" value="com.rest.types.resource" />
<spring:property name="version" value="1.0.0" />
<spring:property name="basePath" value="http://0.0.0.0:8080" />
<spring:property name="scan" value="true" />
</spring:bean>
</spring:beans>
<spring:beans>
<spring:bean id="sampleResourceBean"
class="com.rest.types.resource.UpdateApiImpl" />
</spring:beans>
<flow name="services_all" doc:name="services_all">
<http:inbound-endpoint exchange-pattern="request-response"
host="0.0.0.0" port="8080" mimeType="application/json" doc:name="HTTP" />
<logger level="INFO" doc:name="Log Incoming Request"/>
<choice doc:name="ContextRootRouting">
<when
expression="#[message.inboundProperties['http.request'] contains '/api-docs']">
<object-to-string-transformer doc:name="Object to String" />
<logger message="About to call Transaction Service, #[payload]"
doc:name="Logger" />
<jersey:resources doc:name="REST">
<component>
<spring-object bean="sampleResourceBean" />
</component>
<component>
<spring-object bean="apiListingJSON" />
</component>
</jersey:resources>
</when>
</mule>
我们在 swagger-core 存储库中有一个包含教程和示例的 mule 特定模块,它根本 depend/require jetty。
https://github.com/swagger-api/swagger-core/wiki/Swagger-Core-Mule-Project-Setup
本教程包含您需要的所有信息,包括示例的依赖项和 link。
如果可能,我会选择此处找到的 1.5 版本 - https://github.com/swagger-api/swagger-core/wiki/Swagger-Core-Mule-Project-Setup-1.5 - 即使该版本的 Mule 模块尚未发布(但可以从 develop_2 编译)。 0 个分支)。
我正在尝试从我的 apis.I 中使用 mule 生成 swagger,并为此添加了这个码头连接器。我的 mule 服务器在 8080
上 运行 <jetty:connector name="jettyConnector">
<jetty:webapps directory="${app.home}/webapps" port="8083"/>
</jetty:connector>
我在src/main/app/webapps/swaggerdoc/WEB-INF/web.xml下添加了web.xml,内容是:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>Swagger doc</display-name>
<description>swagger doc</description>
<servlet>
<servlet-name>JerseyJaxrsConfig</servlet-name>
<servlet-class>com.wordnik.swagger.jersey.config.JerseyJaxrsConfig</servlet-class>
<init-param>
<param-name>api.version</param-name>
<param-value>1.0.0</param-value>
</init-param>
<init-param>
<param-name>swagger.api.basepath</param-name>
<param-value>http://localhost:8002/api</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet>
<servlet-name>jersey</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.rest.types.resource;com.wordnik.swagger.jersey.listing</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>jersey</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
并且 pom 文件具有此依赖项:
<dependency>
<groupId>com.wordnik</groupId>
<artifactId>swagger-jaxrs_2.10</artifactId>
<version>1.3.12</version>
</dependency>
但是当我击中 http://localhost:8080/api 时启动 mule 后,它会抛出 "Not Authorized"。我已正确使用 api 上的所有注释。
任何帮助将不胜感激。最近几天我一直被这个问题困扰。
我试图从中生成 swagger 的接口:
@Path("/api-docs")
@Api(value = "/transactions", description = "Update APIs")
public interface BaseResource {
@PUT
@ApiOperation(value = "updateTransactions", notes = "update Transaction.", httpMethod = "PUT")
@ApiResponses({ @ApiResponse(code = HttpServletResponse.SC_ACCEPTED, message = "Accepted"),
@ApiResponse(code = HttpServletResponse.SC_BAD_REQUEST, message = "Bad Request"),
@ApiResponse(code = HttpServletResponse.SC_UNAUTHORIZED, message = "Unauthorized "),
@ApiResponse(code = HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message = "Internal Server Error") })
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
BaseResource.PutTransactionsResponse updateTransactions(
@ApiParam(name = "Authorization",
defaultValue = "",
required = true) @HeaderParam("Authorization") String authorizationHeader,
UpdateRequest entity)
throws Exception;
}
骡子流:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:jetty="http://www.mulesoft.org/schema/mule/jetty"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:jersey="http://www.mulesoft.org/schema/mule/jersey"
xmlns:apikit="http://www.mulesoft.org/schema/mule/apikit" xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:jms="http://www.mulesoft.org/schema/mule/jms" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking"
xmlns:vm="http://www.mulesoft.org/schema/mule/vm" xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.6.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/jetty http://www.mulesoft.org/schema/mule/jetty/current/mule-jetty.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-current.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/jms http://www.mulesoft.org/schema/mule/jms/current/mule-jms.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/apikit http://www.mulesoft.org/schema/mule/apikit/current/mule-apikit.xsd
http://www.mulesoft.org/schema/mule/jersey http://www.mulesoft.org/schema/mule/jersey/current/mule-jersey.xsd">
<context:property-placeholder location="classpath:mule-app.properties" />
<spring:beans>
<spring:bean id="apiListingJSON"
class="com.wordnik.swagger.mule.ApiListingJSON" />
<spring:bean id="swaggerConfig"
class="com.wordnik.swagger.jaxrs.config.BeanConfig">
<spring:property name="resourcePackage" value="com.rest.types.resource" />
<spring:property name="version" value="1.0.0" />
<spring:property name="basePath" value="http://0.0.0.0:8080" />
<spring:property name="scan" value="true" />
</spring:bean>
</spring:beans>
<spring:beans>
<spring:bean id="sampleResourceBean"
class="com.rest.types.resource.UpdateApiImpl" />
</spring:beans>
<flow name="services_all" doc:name="services_all">
<http:inbound-endpoint exchange-pattern="request-response"
host="0.0.0.0" port="8080" mimeType="application/json" doc:name="HTTP" />
<logger level="INFO" doc:name="Log Incoming Request"/>
<choice doc:name="ContextRootRouting">
<when
expression="#[message.inboundProperties['http.request'] contains '/api-docs']">
<object-to-string-transformer doc:name="Object to String" />
<logger message="About to call Transaction Service, #[payload]"
doc:name="Logger" />
<jersey:resources doc:name="REST">
<component>
<spring-object bean="sampleResourceBean" />
</component>
<component>
<spring-object bean="apiListingJSON" />
</component>
</jersey:resources>
</when>
</mule>
我们在 swagger-core 存储库中有一个包含教程和示例的 mule 特定模块,它根本 depend/require jetty。
https://github.com/swagger-api/swagger-core/wiki/Swagger-Core-Mule-Project-Setup
本教程包含您需要的所有信息,包括示例的依赖项和 link。
如果可能,我会选择此处找到的 1.5 版本 - https://github.com/swagger-api/swagger-core/wiki/Swagger-Core-Mule-Project-Setup-1.5 - 即使该版本的 Mule 模块尚未发布(但可以从 develop_2 编译)。 0 个分支)。