users@jersey.java.net

[Jersey] Re: How to send a client POST with both class type and callback

From: Pavel Bucek <pavel.bucek_at_oracle.com>
Date: Thu, 1 Oct 2015 20:34:09 +0200

I almost don't believe that you'll get 400 just by not passing reference
to "MyClass".

Passing InvocationCallback<Response> is the only way how to get Response
object, so you should do that. You can get the entiy by calling
Response.readEntity(MyClass.class)..

Anyway, shouldn't have any relation to the actual request, since it only
tells Jersey which MessageBodyReader should be invoked when the response
arrives.

Do you have any control of the server side? Do you have anything better
than "400"? Stacktrace/log message/...?


On 01/10/15 20:11, Raúl Guerrero Deschamps wrote:
> Hi Pavel,
>
> Thanks for the quick reply.
>
> I want to know about the actual response as a JAX-RS Response object,
> so I would have to do something like:
>
> InvocationCallback<Response>() {
> @Override
> public void completed(Response response) {
> ...
> }
> }
>
> Which means that if I specify my object class as
> InvocationCallback<myClass>() then how can I read the Response object
> for that? for example, how do I read the status code of the error and
> the error message if I have to pass my class as the T parameter for
> InvocationCallback?
>
> And like I said, if I don't pass the myClass somewhere I get a 400 error.
>
> Thanks,
>
> Raul
>
>
> 2015-10-01 13:05 GMT-05:00 Pavel Bucek <pavel.bucek_at_oracle.com
> <mailto:pavel.bucek_at_oracle.com>>:
>
> Hi Raul,
>
> just put the type as a generic parameter of the callback:
>
> new InvocationCallback<MyClass>() { @Override public void
> completed(MyClass myClass) { } @Override public void
> failed(Throwable throwable) { } });
>
> then you are notified when the action (response is received and
> read) is completed or when the error occurs.
>
> Hope it helps,
> Pavel
>
>
>
> On 01/10/15 19:37, Raúl Guerrero Deschamps wrote:
>> Hi,
>>
>> I'm trying to do a client post using something like:
>> client
>> .target(url)
>> .async()
>> .post(Entity.entity(myObject, MediaType.APPLICATION_JSON),
>> MyClass.class));
>>
>> But I want to be able to also specify an InvocationCallback to
>> see the server's response, but seeing the API signatures, I see
>> that there is no way of doing that, I only have the following
>> options:
>> post(entity)
>> post(entity, class)
>> post(entity, callback)
>>
>> There is not one that specifies something like post(entity,
>> class, callback) and this is a problem, because if I don't
>> specify the class, I get a 400 error, and if I specify only
>> entity and class, how can I specify a callback to handle
>> something like an error?
>>
>> Thanks,
>>
>> Raul
>
>