swagger + cxf + spring

172 views
Skip to first unread message

Tara Czutno

unread,
Jun 2, 2016, 7:28:40 PM6/2/16
to Swagger
Help!  Can't get swagger + cxf + spring to work in my app.  
I am following swagger's example at https://github.com/swagger-api/swagger-samples/tree/master/java/java-jaxrs-cxf/src.  I got that to work fine.

I have made the swaggerWriter, swaggerResource, and swaggerConfig in applicationContext.xml.
What is happening behind the scenes?  Is a swagger.json file being created?  If so, when and where does it get created.
I am expecting that my app is going to be serving up swagger pages since the swaggerResource was added.  Is this correct?  Please explain the steps.

When my app runs, I am getting swagger debug messages:
2016-06-02T17:02:54,161 DEBUG [main] io.swagger.jaxrs.Reader - picking up response class from method public javax.ws.rs.core.Response com.twc.ctg.ecp.service.rest.EcpResearchRestServiceV1.researchHousehold(java.lang.String,java.lang.String) throws com.twc.atgw.commons.webservices.exception.GenericRestException
But nothing when I surf to localhost:8002

Here's the important config parts:
applicationContext.xml:
<!-- Swagger writers -->
<bean id="swaggerWriter" class="io.swagger.jaxrs.listing.SwaggerSerializers" />

<!-- Swagger API listing resource -->
<bean id="swaggerResource" class="io.swagger.jaxrs.listing.ApiListingResource" />

<!-- this scans the classes for resources -->
<bean id="swaggerConfig" class="io.swagger.jaxrs.config.BeanConfig">
   
<property name="resourcePackage" value="com.twc.ctg.ecp.service.rest"/>
   
<property name="version" value="1.0.0"/>
   
<property name="host" value="0.0.0.0:8002"/>
   
<property name="basePath" value="/api"/>
   
<property name="title" value="ECP REST api"/>
   
<property name="description" value="This is a app."/>
   
<property name="contact" value="xxxxxxxxxxx"/>
   
<property name="license" value="Apache 2.0"/>
   
<property name="licenseUrl" value="http://www.apache.org/licenses/LICENSE-2.0.html"/>
   
<!-- <property name="filterClass" value="ApiAuthorizationFilterImpl"/> -->
   <property name="scan" value="true"/>
</bean>

<jaxrs:server id="ecpWebServices" basePackages="com.twc.ctg.ecp.service.rest.custom" address="http://0.0.0.0:8877" depends-on="activeMQConnectionFactory">
   
<jaxrs:inInterceptors>
     
<ref bean="validationInInterceptor"/>
   
</jaxrs:inInterceptors>
   
<jaxrs:outInterceptors>
     
<ref bean="validationOutInterceptor"/>
   
</jaxrs:outInterceptors>
   
<jaxrs:serviceBeans>
     
<ref bean="ecpAdminRestServiceV1"/>
     
<ref bean="ecpApplicationRestServiceV1"/>
     
<ref bean="ecpEntitlementRestServiceV2"/>
     
<ref bean="ecpTvodRestServiceV1"/>
     
<ref bean="ecpHouseholdHistoryRestServiceV1"/>
     
<ref bean="ecpPromotionRestServiceV1"/>
     
<ref bean="ecpTvodPromotionServiceV1"/>
     
<ref bean="ecpFeatureRestServiceV1"/>
     
<ref bean="ecpPpvServiceV1"/>
     
<ref bean="swaggerResource"/>
   
</jaxrs:serviceBeans>
   
<jaxrs:providers>
     
<bean class="com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider"/>
     
<bean class="org.apache.cxf.rs.security.cors.CrossOriginResourceSharingFilter"/>
     
<ref bean="genericRestExceptionMapper"/>
     
<ref bean="customValidationExceptionMapper"/>
     
<ref bean="swaggerWriter"/>
   
</jaxrs:providers>
</jaxrs:server>


tony tam

unread,
Jun 4, 2016, 6:46:50 PM6/4/16
to Swagger
Hi Tara, where it mounts depends entirely on your configuration--but if you have your API running on localhost:8002, you should see a Swagger document at http://localhost:8002/swagger.json

Tara Czutno

unread,
Jun 6, 2016, 2:53:02 PM6/6/16
to swagger-sw...@googlegroups.com
Okay I got further, but now getting this error.  Any ideas?

ID: 1
Http-Method: GET
Content-Type: 
Headers: {Accept=[text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8], accept-encoding=[gzip, deflate, sdch], Accept-Language=[en-US,en;q=0.8], connection=[keep-alive], Content-Type=[null], Host=[localhost:8877], Upgrade-Insecure-Requests=[1], User-Agent=[Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36]}
--------------------------------------
12:44:00.341 WARN  [qtp1281233469-277] org.apache.cxf.phase.PhaseInterceptorChain – Application {http://rest.service.ecp.ctg.twc.com/}EcpAdminRestServiceV1 has thrown exception, unwinding now java.lang.NullPointerException
at io.swagger.jaxrs.listing.ApiListingResource.getListingJson(ApiListingResource.java:90) ~[swagger-jaxrs-1.5.0.jar:1.5.0]
at io.swagger.jaxrs.listing.ApiListingResource$$FastClassBySpringCGLIB$$664991fa.invoke(<generated>) ~[swagger-jaxrs-1.5.0.jar:1.5.0]
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) ~[spring-core-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:720) ~[spring-aop-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) ~[spring-aop-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:85) ~[spring-aop-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at com.twc.ctg.ecp.service.statsd.StatsDRestServiceAspect.statd(StatsDRestServiceAspect.java:65) ~[classes/:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_91]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_91]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_91]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_91]
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621) ~[spring-aop-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:610) ~[spring-aop-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:68) ~[spring-aop-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:168) ~[spring-aop-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655) ~[spring-aop-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at io.swagger.jaxrs.listing.ApiListingResource$$EnhancerBySpringCGLIB$$5d9455e3.getListingJson(<generated>) ~[swagger-jaxrs-1.5.0.jar:1.5.0]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_91]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_91]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_91]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_91]
at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:180) ~[cxf-core-3.1.4.jar:3.1.4]
at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:96) ~[cxf-core-3.1.4.jar:3.1.4]
... 21 more
Wrapped by: org.apache.cxf.interceptor.Fault
at org.apache.cxf.service.invoker.AbstractInvoker.createFault(AbstractInvoker.java:162) ~[cxf-core-3.1.4.jar:3.1.4]
at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:128) ~[cxf-core-3.1.4.jar:3.1.4]
at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:200) ~[cxf-rt-frontend-jaxrs-3.1.4.jar:3.1.4]
at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:99) ~[cxf-rt-frontend-jaxrs-3.1.4.jar:3.1.4]
at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:59) ~[cxf-core-3.1.4.jar:3.1.4]
at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:96) ~[cxf-core-3.1.4.jar:3.1.4]
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308) [cxf-core-3.1.4.jar:3.1.4]
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121) [cxf-core-3.1.4.jar:3.1.4]
at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:251) [cxf-rt-transports-http-3.1.4.jar:3.1.4]
at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:234) [cxf-rt-transports-http-jetty-3.1.4.jar:3.1.4]
at org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:70) [cxf-rt-transports-http-jetty-3.1.4.jar:3.1.4]
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1129) [jetty-server-9.2.11.v20150529.jar:9.2.11.v20150529]
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1065) [jetty-server-9.2.11.v20150529.jar:9.2.11.v20150529]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) [jetty-server-9.2.11.v20150529.jar:9.2.11.v20150529]
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:215) [jetty-server-9.2.11.v20150529.jar:9.2.11.v20150529]
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97) [jetty-server-9.2.11.v20150529.jar:9.2.11.v20150529]
at org.eclipse.jetty.server.Server.handle(Server.java:499) [jetty-server-9.2.11.v20150529.jar:9.2.11.v20150529]
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310) [jetty-server-9.2.11.v20150529.jar:9.2.11.v20150529]
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257) [jetty-server-9.2.11.v20150529.jar:9.2.11.v20150529]
at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540) [jetty-io-9.2.11.v20150529.jar:9.2.11.v20150529]
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635) [jetty-util-9.2.11.v20150529.jar:9.2.11.v20150529]
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555) [jetty-util-9.2.11.v20150529.jar:9.2.11.v20150529]
at java.lang.Thread.run(Thread.java:745) [?:1.8.0_91]


--
You received this message because you are subscribed to a topic in the Google Groups "Swagger" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/swagger-swaggersocket/nTr6CWSYFu8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Aki Yoshida

unread,
Jun 7, 2016, 4:26:23 AM6/7/16
to Tara Czutno, swagger-sw...@googlegroups.com
it looks like somehow the servlet context is not correctly injected to
the swagger ApiListing resource, which subsequently leads to NPE.
It has probably something to do with some missing dependency or
project setup, but it is hard to tell from your description.

by the way, I saw your posting at users@cxf and wondered why you were
having some difficulty with your cxf+spring+swagger setup.
And indeed I saw there was some version property change that came in
cxf-3.1.6 that made it difficult to use one of those cxf swagger
samples in a plain spring setup. I fixed this issue and also added a
plain cxf swagger-feature spring sample there so that you can use it.

regards, aki
> You received this message because you are subscribed to the Google Groups
> "Swagger" group.
> To unsubscribe from this group and stop receiving emails from it, send an
Reply all
Reply to author
Forward
0 new messages