Swagger UI CORS configuration Java CXF jersey REST API

84 views
Skip to first unread message

Sajith Vijesekara

unread,
Apr 23, 2015, 6:58:38 AM4/23/15
to swagger-sw...@googlegroups.com

Hi i have problem with swagger UI. I have configuration file which similar to this one.

<bean id="resourceWriter" class="com.wordnik.swagger.jaxrs.listing.ResourceListingProvider" />
<bean id="apiWriter" class="com.wordnik.swagger.jaxrs.listing.ApiDeclarationProvider" />
<bean id="swaggerResourceJSON" class="com.wordnik.swagger.jaxrs.listing.ApiListingResourceJSON" />

<jaxrs:server id="swaggerAPI" address="/swagger">
    <jaxrs:serviceBeans>
        <ref bean="swaggerResourceJSON"/>
    </jaxrs:serviceBeans>
    <jaxrs:providers>
        <bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/>
        <bean class="com.ge.aviation.svc.fss.exception.WebExceptionHandler"/>
        <ref bean="resourceWriter"/>
        <ref bean="apiWriter"/>
    </jaxrs:providers>
</jaxrs:server>

<bean id="swaggerConfig" class="com.wordnik.swagger.jaxrs.config.BeanConfig">
    <property name="resourcePackage" value="package.of.my.service"/>
    <property name="version" value="1.0.0"/>
    <property name="basePath" value="http://localhost:8090/"/>
    <property name="title" value="Sample Service"/>
    <property name="description" value="Service for storing, searching, and retrieving files."/>
    <property name="contact" value="sup...@example.com"/>
    <property name="scan" value="true"/>
</bean>

Then My server running perfectly and there is end point for swagger UI. http://localhost:8095/api/api-docs/ Then i copy this URL in browser it will show the Json file.But I have copied swagger UI dist file in my tomcat(not same server above mention) then add the above URL then IT says Can't read from server. It may not have the appropriate access-control-origin settings.I found the cause of the error ishttps://github.com/swagger-api/swagger-ui/issues/146 and https://github.com/swagger-api/swagger-ui#cors-support But I want to know how to cors set for ApiListingResourceJSON class which have api-docs end point.

Reply all
Reply to author
Forward
0 new messages