RestServicePubDocs", "PubDocs")
public class RestPublicDocs implements IPublic, IPlat1Service {
@Override
public boolean isReady() {
return true;
}
....
}
Following the example I've added the swagger annotations and also declared the class:
@Path("/PubDocs.json")
@Api(value = "/PubDocs", description = "Operations about pubDocs")
@Produces({"application/json"})
public class RestPublicDocsJSON extends RestPublicDocs{}
...then I've published the end point in a similar way:
private Server publishRestServerSwagger(String addr,
List<Interceptor<? extends Message>> inInterceptors,
List<Interceptor<? extends Message>> outInterceptors){
Server simpl=null;
try {
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
sf.setServiceBean(new RestPublicDocsJSON()); //the implementor
sf.setServiceBean(new ApiListingResourceJSON()); //required from swagger
sf.setAddress(addr);
sf.setProvider(new JacksonJsonProvider()); //required from swagger
BasicApplication ba = new BasicApplication();
ba.setResourcePackage("com.prova.restPubDocs");
sf.setApplication(ba); //required from swagger
sf.setProvider(new RestExceptionHandler()); //my exception mapper
if (inInterceptors != null) {
for (Interceptor<? extends Message> interceptor : inInterceptors) {
sf.getInInterceptors().add(interceptor);
}
}
if (outInterceptors != null) {
for (Interceptor<? extends Message> interceptor : outInterceptors) {
sf.getOutInterceptors().add(interceptor);
}
}
//add new rest fault interceptor
sf.getOutFaultInterceptors().add(new RestFaultInterceptor());
//new management end
simpl = sf.create();
log.info("Endpoint has been published on " + addr);
} catch (Exception e) {
log.warn("Error publishing endpoint: " + e.toString(), e);
}
return simpl;
}
The publication seems to be successful and no exception occurs but two different problems occur:
1) when I call the ws, a javax.ws.rs.WebApplicationException with status 404 and all values null occurs.
If I remove the annotations @Path("/PubDocs.json") from the RestPublicDocsJSON class the api works properly and no exception occurs.
Why this happens?
I can skip this problem removing the annotation @Path("/PubDocs.json")?
Or this is is mandatory for swagger right behavior?
2) Continuing the test I have also another problem using swagger ui:
I open the swagger-ui-master/dist/index.html and replace the url with my url
"http://localhost:8162/PubDocs/api-docs.json"
then I click the "Explore" button...
but a NULL Pointer Exception occurs because the
param array that arrives in the ApiListing class has the ServletConfig null.
This the param array in input to ApiListing class:
[com.wordnik.swagger.sample.util.BasicApplication@cb9a647, null, org.apache.cxf.jaxrs.impl.HttpHeadersImpl@705385d7, org.apache.cxf.jaxrs.impl.UriInfoImpl@7b781fdd]
Why this is happens? And how cai I solve this?
Someone can help me?
Thanks a lot,
Andrea
<bean id="resourceWriter" class="com.wordnik.swagger.jaxrs.listing.ResourceListingProvider" /><bean id="apiWriter" class="com.wordnik.swagger.jaxrs.listing.ApiDeclarationProvider" />and<property name="providers"><list>...<!-- required for writing swagger classes --><ref bean="resourceWriter" /><ref bean="apiWriter" /></list></property>
{"apiVersion":"1.0.0","swaggerVersion":null,"basePath":"http://10.0.3.39:8161"}even if I've annotated the endpoint with swagger annoattions and the log on the console show{"apiVersion":"1.0.0","swaggerVersion":null,"basePath":"http://10.0.3.39:8162/PubDocs"}in which the basePath is that corresponding to the latest BeanConfig I've created at publication time.