Hi,
I am struggling with the following topic for days now. And I don't find any
solution, tutorial or explanation anywhere. So I thought of asking here, hoping
to get enlightened. :)
I am trying to create a webservice to upload a file which then gets processed
on the server. I know that file upload is more complicated that it looks in
first place. But this one is driving me crazy.
First I tried to use Jersey for the file upload. So I added
org.glassfish.jersey.media.multipart as a dependency and created a method like
this:
@POST
@Path("/app4mc/converter")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.TEXT_HTML)
public Response upload(@FormDataParam("file") InputStream fileInputStream,
@FormDataParam("file") FormDataContentDisposition fileMetaData)
This resulted in 415 Unsupported Media Type when I tried to upload a file.
My guess was that I have to register the MultipartFeature.class, and as I did
not know how to do this, I used the approach to register a new
@JaxrsApplication via whiteboard and configure it there. This led to severe
errors on startup as Aries is implemented using CXF, and a mixture of CXF and
Jersey seems to be not possible.
As I did not find a solution for this, I thought of using CXF to upload a file.
So I added cxf-rt-frontend-jaxrs as a dependency and changed the method to this
@POST
@Path("/app4mc/converter")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.TEXT_HTML)
public Response upload(MultipartBody body)
Still 415.
Then I read something about org.apache.cxf.jaxrs.provider.MultipartProvider
that needs to be registered. So I thought maybe it would work using the
@JaxrsExtension as the application is already a CXF application from what I can
see in the startup trace. As the CXF MultipartProvider is not annotated with
the needed JAX-RS Whiteboard annotations, I created this class for the
registeration:
@Component(
scope = PROTOTYPE,
property="serialize.to<http://serialize.to/>=MULTIPART")
@JaxrsExtension
@JaxrsMediaType(MULTIPART_FORM_DATA)
public class Multipart extends MultipartProvider implements
MessageBodyReader<Object>, MessageBodyWriter<Object> {
}
This results in a IllegalArgumentException:
java.lang.IllegalArgumentException: interface
org.apache.cxf.jaxrs.impl.tl.ThreadLocalProxy is not visible from class loader
at java.lang.reflect.Proxy$ProxyClassFactory.apply(Proxy.java:581)
at java.lang.reflect.Proxy$ProxyClassFactory.apply(Proxy.java:557)
at java.lang.reflect.WeakCache$Factory.get(WeakCache.java:230)
at java.lang.reflect.WeakCache.get(WeakCache.java:127)
at java.lang.reflect.Proxy.getProxyClass0(Proxy.java:419)
at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:719)
at
org.apache.cxf.jaxrs.utils.InjectionUtils.createThreadLocalProxy(InjectionUtils.java:1080)
I am running out of ideas. Does anybody has a hint or a small example to solve
this? I am happy to write a blog post about the findings to help others in the
future! :)
Sorry for having posted this on the bndtools google group. The mailing list is
surely a better place to ask such a question.
Mit freundlichen Grüßen / Best regards
Dirk Fauth
Cross Automotive Platforms - Systems, Software and Tools, (CAP-SST/ESM1)
Robert Bosch GmbH | Postfach 30 02 40 | 70442 Stuttgart | GERMANY |
www.bosch.com
Tel. +49 7153 666-1155 | [email protected]<mailto:[email protected]>
Sitz: Stuttgart, Registergericht: Amtsgericht Stuttgart, HRB 14000;
Aufsichtsratsvorsitzender: Franz Fehrenbach; Geschäftsführung: Dr. Volkmar
Denner,
Prof. Dr. Stefan Asenkerschbaumer, Dr. Michael Bolle, Dr. Christian Fischer,
Dr. Stefan Hartung,
Dr. Markus Heyn, Harald Kröger, Christoph Kübel, Rolf Najork, Uwe Raschke,
Peter Tyroller
_______________________________________________
OSGi Developer Mail List
[email protected]
https://mail.osgi.org/mailman/listinfo/osgi-dev