Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-12926

null pointer exceptions accessing swagger url in blueprint projects

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.23.0
    • 2.23.0
    • camel-swagger
    • None
    • Unknown

    Description

      When a blueprint like:

      <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.5.0"
                 xsi:schemaLocation="
                   http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
                   http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
        
        <reference id="httpService" interface="org.osgi.service.http.HttpService"/>
      
        <bean class="org.apache.camel.component.servlet.osgi.OsgiServletRegisterer"
              init-method="register"
              destroy-method="unregister">
          <property name="alias" value="/camel-rest-sql"/>
          <property name="httpService" ref="httpService"/>
          <property name="servlet" ref="camelServlet"/>
        </bean>
      
        <bean id="camelServlet" class="org.apache.camel.component.servlet.CamelHttpTransportServlet"/>
      
        <camelContext xmlns="http://camel.apache.org/schema/blueprint">
      
          <restConfiguration
              component="servlet"
              bindingMode="json"
              contextPath="/camel-rest-sql" port="{{env:HTTP_PORT:8181}}"
              apiContextPath="/api-doc">
          </restConfiguration>
      
          <rest path="/books" consumes="application/json" produces="application/json">
            <get uri="/" outType="java.util.String">
              <to uri="log:blueprint-swagger"/>
            </get>
          </rest>
      
        </camelContext>
      </blueprint>
      

      and then one try to access http://localhost:8181/camel-rest-sql/api-doc there is a null pointer exception:

      2018-11-03 08:31:37,062 | INFO  | ead #2 - timer://foo | generateOrder-route              | 120 - org.apache.camel.camel-core - 2.21.0.fuse-720040 | Inserted new order 1
      
      2018-11-03 08:31:37,547 | INFO  | rocessed%20=%20false | processOrder-route               | 120 - org.apache.camel.camel-core - 2.21.0.fuse-720040 | Processed order id 1 item ActiveMQ of 10 copies of ActiveMQ in Action
      
      2018-11-03 08:31:45,741 | WARN  | qtp1210359820-76     | o.a.c.s.RestSwaggerProcessor     | 125 - org.apache.camel.camel-swagger-java - 2.21.0.fuse-720040 | Error rendering Swagger API due null
      
      java.lang.NullPointerException: null
      
      	at org.apache.camel.swagger.RestSwaggerSupport.renderResourceListing(RestSwaggerSupport.java:211) ~[?:?]
      
      	at org.apache.camel.swagger.RestSwaggerProcessor.process(RestSwaggerProcessor.java:119) ~[?:?]
      
      	at org.apache.camel.component.rest.RestApiProducer.process(RestApiProducer.java:36) ~[?:?]
      
      	at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61) ~[?:?]
      
      	at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:148) ~[?:?]
      
      	at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:548) ~[?:?]
      
      	at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) ~[?:?]
      
      	at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) ~[?:?]
      
      	at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:97) ~[?:?]
      
      	at org.apache.camel.http.common.CamelServlet.doService(CamelServlet.java:214) ~[?:?]
      
      	at org.apache.camel.http.common.CamelServlet.service(CamelServlet.java:80) ~[?:?]
      
      	at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) ~[36:javax.servlet-api:3.1.0]
      
      	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:865) ~[?:?]
      
      	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:535) ~[?:?]
      
      	at org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.doHandle(HttpServiceServletHandler.java:71) ~[?:?]
      
      	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:146) ~[?:?]
      
      	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548) ~[?:?]
      
      	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132) ~[?:?]
      
      	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:257) ~[?:?]
      
      	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1595) ~[?:?]
      
      	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255) ~[?:?]
      
      	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1317) ~[?:?]
      
      	at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle(HttpServiceContext.java:293) ~[?:?]
      
      	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203) ~[?:?]
      
      	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:473) ~[?:?]
      
      	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1564) ~[?:?]
      
      	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201) ~[?:?]
      
      	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1219) ~[?:?]
      
      	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144) ~[?:?]
      
      	at org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle(JettyServerHandlerCollection.java:80) ~[?:?]
      
      	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132) ~[?:?]
      
      	at org.eclipse.jetty.server.Server.handle(Server.java:531) ~[?:?]
      
      	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:352) ~[?:?]
      
      	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:260) ~[?:?]
      
      	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:281) ~[?:?]
      
      	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:102) ~[?:?]
      
      	at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:118) ~[?:?]
      
      	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:333) ~[94:org.eclipse.jetty.util:9.4.11.v20180605]
      
      	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:310) ~[94:org.eclipse.jetty.util:9.4.11.v20180605]
      
      	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:168) ~[94:org.eclipse.jetty.util:9.4.11.v20180605]
      
      	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.produce(EatWhatYouKill.java:132) ~[94:org.eclipse.jetty.util:9.4.11.v20180605]
      
      	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:762) [94:org.eclipse.jetty.util:9.4.11.v20180605]
      
      	at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:680) [94:org.eclipse.jetty.util:9.4.11.v20180605]
      
      	at java.lang.Thread.run(Thread.java:748) [?:?]
      

      this is happening because restConfiguration is build with apiProperties as null because there is no tag <apiProperty key="" value=""/> inside <restConfiguration> tag; thus the null pointer here: https://github.com/apache/camel/blob/master/components/camel-swagger-java/src/main/java/org/apache/camel/swagger/RestSwaggerSupport.java#L213-L215

      What do you think is the best approach to fix this:

      • check for null in RestSwaggerSupport.java
      • or investigate why blueprint use initialize apiProperties as null (which I think might be a legitimate behaviour)

      Attachments

        Issue Links

          Activity

            People

              valdar Andrea Tarocchi
              valdar Andrea Tarocchi
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: