cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Vincenzo Vitale <vincenzo.vit...@gmail.com>
Subject Re: Problem with JAXRSClientFactory after updating to 2.2.2
Date Tue, 16 Jun 2009 12:57:06 GMT
At the moment I can continue using 2.2; I will either upgrade when the fix
is released or change the code with your suggestion (if I will really need a
cxf update).
If a Jira issue will be created, could you please send the link?


Thanks,
V.

On Tue, Jun 16, 2009 at 2:47 PM, Sergey Beryozkin <sberyozk@progress.com>wrote:

> I reproduced it. I didn't realize you were actually using a provider for
> JAXRS Response.
> Typically, if a JAXRS Response is returned then on the client side you just
> write
>
> Response r = proxy.getSomeResponse();
>
> and then directly handling the input stream inside the response.
> But I understand now you actually registered a provider which would do it.
>
> Is there any chance you can try to deal with the actual type which is
> embedded inside the Response ?
>
> Query q = tridionService.executeQuery();
>
> and register a provider for tha type (Query in this example) ?
>
> if you need access to response headers, you can do
> Response r = WebClient.client(tridionService).getResponse();
>
> in meantime I'll fix this regression. I do have a test which returns a
> Response but there no entity body is involved...
>
> thanks, Sergey
>
>
>
>
>
> ----- Original Message ----- From: "Vincenzo Vitale" <
> vincenzo.vitale@gmail.com>
> To: <users@cxf.apache.org>
> Sent: Tuesday, June 16, 2009 12:09 PM
>
> Subject: Re: Problem with JAXRSClientFactory after updating to 2.2.2
>
>
>  When switching to 2.2.2 I get a ResponseImpl object but the entity is
>> null.
>> Have you tried to add the line:
>>
>> assertNotNull(r.getEntity());
>>
>> to your test?
>>
>> On Tue, Jun 16, 2009 at 11:40 AM, Sergey Beryozkin <sberyozk@progress.com
>> >wrote:
>>
>>  I;ve done a test and see no problems so far. here's the code.
>>>
>>> // Client test code
>>> @Test
>>> public void testTridionService() {
>>>
>>> List<MessageBodyReader<org.apache.cxf.systest.jaxrs.Response>> providers
>>> =
>>>
>>> new
>>> ArrayList<MessageBodyReader<org.apache.cxf.systest.jaxrs.Response>>();
>>>
>>> providers.add(new ResponseReader());
>>>
>>>
>>> // We also need to pass the provider for deserializing the response
>>>
>>> // object.
>>>
>>> TridionQueryService tridionQueryServiceProxy =
>>>
>>> JAXRSClientFactory.create("http://localhost:9080",
>>>
>>> TridionQueryService.class, providers);
>>>
>>>
>>> org.apache.cxf.systest.jaxrs.Response r =
>>> tridionQueryServiceProxy.executeQuery("query", "id");
>>>
>>> assertNotNull(r);
>>>
>>>
>>> }
>>>
>>> // sample Response :
>>>
>>>
>>> public class Response {
>>>
>>>
>>> public int id;
>>>
>>>
>>> }
>>>
>>> // Response Reader, used on the client side
>>>
>>> public class ResponseReader implements MessageBodyReader<Response> {
>>>
>>>
>>> public boolean isReadable(Class type, Type genericType, Annotation[]
>>> annotations, MediaType mediaType) {
>>>
>>> // TODO Auto-generated method stub
>>>
>>> return true;
>>>
>>> }
>>>
>>>
>>> public Response readFrom(Class arg0, Type arg1, Annotation[] arg2,
>>> MediaType arg3, MultivaluedMap arg4,
>>>
>>> InputStream arg5) throws IOException, WebApplicationException {
>>>
>>> // TODO Auto-generated method stub
>>>
>>> Response r = new Response();
>>>
>>> XMLSource source = new XMLSource(arg5);
>>>
>>> String id = source.getValue("response/id");
>>>
>>> r.id = Integer.parseInt(id);
>>>
>>> return r;
>>>
>>> }
>>>
>>>
>>> }
>>>
>>> // ResponseWriter, used on the server side :
>>>
>>> public class ResponseWriter implements MessageBodyWriter<Response> {
>>>
>>>
>>> public long getSize(Response t, Class type, Type genericType,
>>> Annotation[]
>>> annotations, MediaType mediaType) {
>>>
>>> // TODO Auto-generated method stub
>>>
>>> return 0;
>>>
>>> }
>>>
>>>
>>> public boolean isWriteable(Class type, Type genericType, Annotation[]
>>> annotations, MediaType mediaType) {
>>>
>>> // TODO Auto-generated method stub
>>>
>>> return true;
>>>
>>> }
>>>
>>>
>>> public void writeTo(Response arg0, Class arg1, Type arg2, Annotation[]
>>> arg3, MediaType arg4,
>>>
>>> MultivaluedMap arg5, OutputStream arg6) throws IOException,
>>> WebApplicationException {
>>>
>>> StringBuilder sb = new StringBuilder();
>>>
>>> sb.append("<response><id>" + arg0.id + "</id></response>");
>>>
>>> arg6.write(sb.toString().getBytes());
>>>
>>> arg6.flush();
>>>
>>> }
>>>
>>>
>>> }
>>>
>>> // TridionQueryServiceImpl :
>>>
>>> public class TridionQueryServiceImpl implements TridionQueryService {
>>>
>>>
>>> public Response executeQuery(String query, String publication) throws
>>> WebApplicationException {
>>>
>>> Response r = new Response();
>>>
>>> r.id = 1;
>>>
>>> return r;
>>>
>>> }
>>>
>>>
>>> }
>>>
>>> // Server start up :
>>>
>>> AXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
>>>
>>> sf.setResourceClasses(TridionQueryServiceImpl.class);
>>>
>>>
>>> List<Object> providers = new ArrayList<Object>();
>>>
>>> providers.add(new ResponseWriter());
>>>
>>> sf.setProviders(providers);
>>>
>>> sf.setResourceProvider(TridionQueryServiceImpl.class,
>>>
>>> new SingletonResourceProvider(new TridionQueryServiceImpl()));
>>>
>>> sf.setAddress("http://localhost:9080/");
>>>
>>>
>>> sf.create();
>>>
>>>
>>> Vicio, can you please provbide more details : post sample response value,
>>> sample Response and ResponseProvider, etc...
>>>
>>> thanks, Sergey
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> ----- Original Message ----- From: "Sergey Beryozkin" <
>>> sberyozk@progress.com>
>>> To: <users@cxf.apache.org>
>>> Sent: Tuesday, June 16, 2009 10:05 AM
>>> Subject: Re: Problem with JAXRSClientFactory after updating to 2.2.2
>>>
>>>
>>>
>>>  Hi
>>>
>>>>
>>>> Sorry, your messages have been caught by the spam filter.
>>>> Can you please use JAXRSClientFactoryBean directly please, may be
>>>> there're
>>>> some overloading issues among the factory utility methods..
>>>> Trying to do a quick test now...
>>>> cheers, Sergey
>>>>
>>>> ----- Original Message ----- From: "Vincenzo Vitale" <
>>>> vincenzo.vitale@gmail.com>
>>>> To: <users@cxf.apache.org>
>>>> Sent: Monday, June 15, 2009 11:59 AM
>>>> Subject: Problem with JAXRSClientFactory after updating to 2.2.2
>>>>
>>>>
>>>>  Hi,
>>>>
>>>>> after updating to CXF 2.2.2 the  JAXRSClientFactory seems to not work
>>>>> anymore having the entity field returned always to null.
>>>>>
>>>>> Here my code:
>>>>>
>>>>>
>>>>>      ArrayList<MessageBodyReader<Response>> providers =
>>>>>              new ArrayList<MessageBodyReader<Response>>();
>>>>>      providers.add(new ResponseProvider());
>>>>>
>>>>>      // We also need to pass the provider for deserializing the
>>>>> response
>>>>>      // object.
>>>>>      tridionQueryServiceProxy =
>>>>>              JAXRSClientFactory.create(getTridionProxyBaseAddress(),
>>>>>                      TridionQueryService.class, providers);
>>>>>
>>>>>
>>>>>
>>>>> and than:
>>>>>
>>>>> tridionProxyResponse
>>>>> = tridionQueryServiceProxy.executeQuery(query.toString(),
>>>>> publicationId);
>>>>>
>>>>>
>>>>> The common interface between server and client is:
>>>>>
>>>>> @Path("/query-service")
>>>>> @Produces("application/xml")
>>>>> public interface TridionQueryService {
>>>>>
>>>>>  /**
>>>>>   * Execute a generic query in the Tridion system through a POST
>>>>> request.
>>>>>   *
>>>>>   * @param query The query to be executed.
>>>>>   * @param publicationId The publication to use (in a normal Tridion
>>>>>   *        implementation the publication id specify the channel to
>>>>> use).
>>>>> If
>>>>>   *        the parameter is not passed a default value (different
>>>>> depending
>>>>>   *        on the implementation) will be used.
>>>>>   * @return A {@link Response} object containing the xml response
>>>>> received
>>>>>   *         from Tridion..
>>>>>   */
>>>>>  @POST
>>>>>  @Path("/execute")
>>>>>  Response executeQuery(@FormParam("query") String query,
>>>>>          @FormParam("channel") String publication)
>>>>>          throws WebApplicationException;
>>>>>
>>>>>
>>>>>
>>>>> Is someone experiencing the same problem. Is it a bug in CXF?
>>>>>
>>>>>
>>>>>
>>>>> Thanks,
>>>>> Vicio.
>>>>>
>>>>>
>>>>>
>>>>
>>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message