CXF Pors Multipart/form-data 文件名中的特殊符号

CXF Pors Multipart/form-data special symbol in filename

我需要通过 REST 上传文件,并使用 CXF。

@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces("text/html; charset=UTF-8")
public Response upload(@PathParam("param1") String serviceId,
            @Multipart(value = "param2", required = false) String bundleName,
            @Multipart(value = "param3", required = false) List<String> types,
            @Multipart(value = "file") Attachment attachment) { ... }

一切正常,但我需要在文件名中使用特殊符号,例如“;”。当我尝试做 POST (test;01;21.txt)- CXF return exception:

javax.ws.rs.WebApplicationException: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
    at org.apache.cxf.jaxrs.utils.JAXRSUtils.readFromMessageBody(JAXRSUtils.java:1046)
    at org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameter(JAXRSUtils.java:614)
    at org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameters(JAXRSUtils.java:578)
    at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:238)
    at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSInInterceptor.java:89)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:262)[122:org.apache.cxf.cxf-api:2.6.0.redhat-60024]
    at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)[122:org.apache.cxf.cxf-api:2.6.0.redhat-60024]
    at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:236)[127:org.apache.cxf.cxf-rt-transports-http:2.6.0.redhat-60024]
    at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:214)
    at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:194)
    at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:130)
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:221)
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:141)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:713)[77:org.apache.geronimo.specs.geronimo-servlet_2.5_spec:1.2]
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:197)
    at sun.reflect.GeneratedMethodAccessor226.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[:1.7.0_80]
    at java.lang.reflect.Method.invoke(Method.java:606)[:1.7.0_80]
    at org.ops4j.pax.web.service.internal.HttpServiceStarted.invoke(HttpServiceStarted.java:182)[97:org.ops4j.pax.web.pax-web-runtime:1.1.11]
    at org.ops4j.pax.web.service.internal.$Proxy1.service(Unknown Source)[97:org.ops4j.pax.web.pax-web-runtime:1.1.11]
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:652)[88:org.eclipse.jetty.servlet:7.6.7.v20120910]
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:447)[88:org.eclipse.jetty.servlet:7.6.7.v20120910]
    at org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.doHandle(HttpServiceServletHandler.java:70)[98:org.ops4j.pax.web.pax-web-jetty:1.1.11]
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)[86:org.eclipse.jetty.server:7.6.7.v20120910]
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:534)[87:org.eclipse.jetty.security:7.6.7.v20120910]
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:227)[86:org.eclipse.jetty.server:7.6.7.v20120910]
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1038)[86:org.eclipse.jetty.server:7.6.7.v20120910]
    at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle(HttpServiceContext.java:117)[98:org.ops4j.pax.web.pax-web-jetty:1.1.11]
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:374)[88:org.eclipse.jetty.servlet:7.6.7.v20120910]
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:189)[86:org.eclipse.jetty.server:7.6.7.v20120910]
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:972)[86:org.eclipse.jetty.server:7.6.7.v20120910]
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)[86:org.eclipse.jetty.server:7.6.7.v20120910]
    at org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle(JettyServerHandlerCollection.java:75)[98:org.ops4j.pax.web.pax-web-jetty:1.1.11]
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)[86:org.eclipse.jetty.server:7.6.7.v20120910]
    at org.eclipse.jetty.server.Server.handle(Server.java:363)[86:org.eclipse.jetty.server:7.6.7.v20120910]
    at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:483)[86:org.eclipse.jetty.server:7.6.7.v20120910]
    at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:931)[86:org.eclipse.jetty.server:7.6.7.v20120910]
    at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:992)[86:org.eclipse.jetty.server:7.6.7.v20120910]
    at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:856)[82:org.eclipse.jetty.http:7.6.7.v20120910]
    at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)[82:org.eclipse.jetty.http:7.6.7.v20120910]
    at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)[86:org.eclipse.jetty.server:7.6.7.v20120910]
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:627)[81:org.eclipse.jetty.io:7.6.7.v20120910]
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:51)[81:org.eclipse.jetty.io:7.6.7.v20120910]
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)[80:org.eclipse.jetty.util:7.6.7.v20120910]
    at org.eclipse.jetty.util.thread.QueuedThreadPool.run(QueuedThreadPool.java:543)[80:org.eclipse.jetty.util:7.6.7.v20120910]
    at java.lang.Thread.run(Thread.java:745)[:1.7.0_80]
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
    at java.lang.String.substring(String.java:1911)[:1.7.0_80]
    at org.apache.cxf.attachment.AttachmentUtil.createAttachment(AttachmentUtil.java:230)
    at org.apache.cxf.attachment.AttachmentDeserializer.createAttachment(AttachmentDeserializer.java:289)
    at org.apache.cxf.attachment.AttachmentDeserializer.readNext(AttachmentDeserializer.java:192)
    at org.apache.cxf.attachment.LazyAttachmentCollection.loadAll(LazyAttachmentCollection.java:55)
    at org.apache.cxf.attachment.LazyAttachmentCollection.size(LazyAttachmentCollection.java:120)
    at org.apache.cxf.jaxrs.ext.MessageContextImpl.createAttachments(MessageContextImpl.java:266)[132:org.apache.cxf.cxf-rt-frontend-jaxrs:2.6.0.redhat-60024]
    at org.apache.cxf.jaxrs.ext.MessageContextImpl.get(MessageContextImpl.java:75)[132:org.apache.cxf.cxf-rt-frontend-jaxrs:2.6.0.redhat-60024]
    at org.apache.cxf.jaxrs.impl.tl.ThreadLocalMessageContext.get(ThreadLocalMessageContext.java:38)
    at org.apache.cxf.jaxrs.utils.multipart.AttachmentUtils.getMultipartBody(AttachmentUtils.java:89)
    at org.apache.cxf.jaxrs.utils.multipart.AttachmentUtils.getAttachments(AttachmentUtils.java:94)
    at org.apache.cxf.jaxrs.provider.MultipartProvider.readFrom(MultipartProvider.java:137)
    at org.apache.cxf.jaxrs.utils.JAXRSUtils.readFromMessageBody(JAXRSUtils.java:1038)
    ... 45 more

有人可以帮忙吗?

我有旧版本的 CXF,从 3.0.4 开始修复了错误 http://cxf.apache.org/docs/jax-rs-multiparts.html#JAX-RSMultiparts-Content-DispositionUTF-8filenames