I'll do it with MultipartBody until the fix is released. Thank you, Sergey.

BR,
Marcos

-----Mensaje original-----
De: Sergey Beryozkin [mailto:[email protected]] 
Enviado el: jueves, 27 de enero de 2011 13:18
Para: [email protected]
Asunto: Re: JAX-RS Proxy returns null when Map should be returned

Hi

I've fixed MultipartProvider to support reading the maps for mutipart types
other than multipart/form-data (reading simple multipart/form-data data into
MutivaluedMap is supported).

Returning a map from a resource method (and thus writing) is supported
because the map has all the info needed for
writing individual parts but I did not add a test for a proxy at a time but
only the test using WebClient.

You may want to consider returning MultipartBody or List<Attachment> as a
workaround.

If you do prefer returning a Map then you can read the attachments on the
client side using a WebClient, do something like

webClient.accept("multipart/mixed").getCollection(Book.class)

If you have parts of different types, then either

Collection<Attachement> atts =
webClient.accept("multipart/mixed").getCollection(Attachment.class)

or

webClient.accept("multipart/mixed").get(MultipartBody.class)

If you do need to use a proxy then please check the MultipartProvider source
(readFrom) on the trunk; you may want to register a custom provider
extending it and adding a bit of code to deal with the maps.

What will happen with the fix is that if you return Map<String, Object>

then the proxy/webClient will return the map with Attachment values.

If the parts are of the same type then returning something like Map<String,
Book> will better

cheers, Sergey

2011/1/27 Marcos Díez Fernández <[email protected]>

> Hi,
>
> I have set up a CXF JAX-RS Server which works fine. Among other services,
> it has one that returns a Map when invoked, and it's implemented like this:
>
> @Path("/lqservice/")
> @Produces("application/json")
> public interface LiqService {
>
>            @GET
>            @Produces("multipart/mixed")
>            @Path("/liq/{id}/{v}")
>            Map<String, Object> getLiq(@PathParam("") Solic solicRequest);
> }
>
> public class LiqServiceImpl implements LiqService {
>
>            public Map<String, Object> getLiq(Solic solicRequest) {
>                        Map<String, Object> response = ...;
>                        ...
>                        return response;
>            }
> }
>
> When I invoke the service using cURL I get a correct multipart message:
>
>            C:\>curl http://localhost:8181/cxf/es/lqservice/liq/C1/1
>
> --uuid:54ef3462-a04a-4620-bf06-7d7e84a30c13
> Content-Type: text/xml; charset=UTF-8; type="application/zip";
> Content-Transfer-Encoding: binary
> Content-ID: <[email protected]>
>            ...
> --uuid:54ef3462-a04a-4620-bf06-7d7e84a30c13
> Content-Type: application/json
> Content-Transfer-Encoding: binary
> Content-ID: <1>
> ...
> --uuid:54ef3462-a04a-4620-bf06-7d7e84a30c13-
>
> So I guess the service it's OK.
> The problem comes in the client. I'm using a proxy which I set up like
> this:
>
> List<AbstractJAXBProvider> providers = new
> ArrayList<AbstractJAXBProvider>();
> JSONProvider jsonProvider = new JSONProvider();
> jsonProvider.setConvention("badgerfish");
> providers.add(jsonProvider);
>
> client = JAXRSClientFactory.create("http://localhost:8181/cxf/es";,
> LiquidacionesService.class, providers);
>
> And when I invoke the service like:
>
>            Map<String, Object> map = client.getLiq(solicRequest));
>
> I get NULL.
>
> I've tried using WebClient and I get a Response but I'd prefer using the
> proxy.
> Is there any problem between proxies and maps or multiparts?
> Why does the proxy decide to discard the response if it does so? (Binding
> problem?)
> Which is the correct way to return a Map from a service?
>
> Any help would be appreciated. Thanks in advance.
>
> BR,
>
> Marcos
>
>

Reply via email to