users@jersey.java.net

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

From: Raúl Guerrero Deschamps <raul_at_jimi.com.mx>
Date: Thu, 1 Oct 2015 13:11:24 -0500

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>:

> 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
>
>
>