如何使用camel-jetty组件上传图像

时间:2016-04-04 12:33:13

标签: java apache-camel image-upload

我正在使用camel-jetty组件创建一个图像文件上传器。图像将作为多部分表单数据附加在请求正文中,并且必须将其上载到S3。

这是我的路线: from(“jetty:http://localhost:8889/imageservice?enableMultipartFilter=true”)。process(processor);

但是在请求到达处理器之前,它会抛出以下异常。我在谷歌搜索但无处可去。请帮我解决这个问题。

org.apache.camel.RuntimeCamelException: Cannot populate attachments
    at org.apache.camel.component.jetty9.AttachmentHttpBinding.populateAttachments(AttachmentHttpBinding.java:56)
    at org.apache.camel.http.common.DefaultHttpBinding.readRequest(DefaultHttpBinding.java:175)
    at org.apache.camel.http.common.HttpMessage.<init>(HttpMessage.java:52)
    at org.apache.camel.component.jetty.CamelContinuationServlet.service(CamelContinuationServlet.java:134)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:808)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1669)
    at org.eclipse.jetty.servlets.MultiPartFilter.doFilter(MultiPartFilter.java:200)
    at org.apache.camel.component.jetty.CamelFilterWrapper.doFilter(CamelFilterWrapper.java:43)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:585)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
    at org.eclipse.jetty.server.Server.handle(Server.java:499)
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310)
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)
    at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
    at java.lang.Thread.run(Thread.java:745)

Caused by: java.lang.NullPointerException
    at org.apache.camel.component.jetty9.AttachmentHttpBinding.populateAttachments(AttachmentHttpBinding.java:48)
    ... 22 more

1 个答案:

答案 0 :(得分:2)

Follow the NullPointerException stacktrace... When the org.eclipse.jetty.util.MultiPartInputStreamParser parses the request into parts, one of those parts is null. This indicates there's something wrong with the format of the request...

Try setting on the jetty url the property 'disableStreamCache' to true. Per http://camel.apache.org/jetty, "By default Camel will cache the Jetty input stream to support reading it multiple times to ensure it Camel can retrieve all data from the stream. However you can set this option to true when you for example need to access the raw stream, such as streaming it directly to a file or other persistent store."