我有一個簡單的REST服務。有客戶,我可以通過它的ID獲得客戶。如果沒有客戶端請求的ID,應找回404找不到。駱駝REST服務在返回null時拋出異常
下面是相關的部分:
rest("/client")
.consumes("application/json").produces("application/json")
.get("{id}")
.to("direct:getClient");
from("direct:getClient")
.bean(clientService, "getClient(${header.id})")
.choice()
.when(simple("${body} == null"))
.setHeader(Exchange.HTTP_RESPONSE_CODE, constant(404));
一切都很好時,可以發現客戶,但是,當客戶端未發現clientService返回null,我得到以下堆棧跟蹤:
org.apache.camel.RuntimeCamelException: java.io.IOException: Stream closed
at org.apache.camel.http.common.HttpMessage.createBody(HttpMessage.java:74)
at org.apache.camel.impl.MessageSupport.getBody(MessageSupport.java:47)
at org.apache.camel.processor.CamelInternalProcessor$StreamCachingAdvice.after(CamelInternalProcessor.java:799)
at org.apache.camel.processor.CamelInternalProcessor$StreamCachingAdvice.after(CamelInternalProcessor.java:767)
at org.apache.camel.processor.CamelInternalProcessor$InternalCallback.done(CamelInternalProcessor.java:246)
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:573)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:120)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197)
at org.apache.camel.component.direct.DirectProducer.process(DirectProducer.java:62)
at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:145)
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:542)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:120)
我無法弄清楚這一點。從bean方法調用返回null應該是可能的,對吧?
什麼駱駝版本你使用?你使用什麼Camel組件作爲HTTP的rest-dsl? –
2.18.0和camel-servlet – verhage
好的...似乎在2.18.0中有一個bug。我降級到2.17.3,它工作正常。這是一個嚴重的問題,我會創建一個測試並報告。 – verhage