Uploaded image for project: 'Red Hat build of Apache Camel for Spring Boot'
  1. Red Hat build of Apache Camel for Spring Boot
  2. CSB-8358

Camel throws NullPointerException when returning a Response with null entity form jax-rs

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Normal Normal
    • None
    • CSB-4.14.2
    • Camel
    • None
    • False
    • Hide

      None

      Show
      None
    • False
    • Moderate
    • Very Likely
    • 0

      In a jax-rs service, if I set a jakarta.ws.rs.core.Response with a null entity as the inMessage body; AND execute a log statement in the route, like:

      from(CXFRS_ENDPOINT_URI).routeId("testRoute")
          .process(x -> {
              x.getIn().setBody(Response.status(Response.Status.NO_CONTENT).build());
          .log("Processed request, responding with 204 No Content");
          })
      

      a NullPointerException is thrown:

      Caused by: java.lang.NullPointerException: Cannot invoke "Object.getClass()" because "is" is null
      	at org.apache.camel.component.cxf.jaxrs.CxfConverter.toStreamCache(CxfConverter.java:132)
      

      The issue is at the line #132 of the CxfConverter.java class:

      127     @Converter(allowNull = true)
      128     public static StreamCache toStreamCache(Response response, Exchange exchange) {
      129         InputStream is = toInputStream(response, exchange);
      130 
      131         TypeConverterRegistry registry = exchange.getContext().getTypeConverterRegistry();
      132         TypeConverter tc = registry.lookup(StreamCache.class, is.getClass());
      133 
      134         if (tc != null) {
      135             return tc.convertTo(StreamCache.class, exchange, is);
      136         }
      137 
      138         return null;
      139     }
      

      since the InputStream "is" was null at line #129.

              Unassigned Unassigned
              rhn-support-qluo Joe Luo
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated: