Dropwizard HttpClient Example

6,642 views
Skip to first unread message

Paras Goel

unread,
Mar 12, 2013, 6:38:10 PM3/12/13
to dropwiz...@googlegroups.com
Hi ,

I am looking some example for dropwizard http client. I need to call another webservice from my existing dropwizrad service.
I was looking in the dropwizard core tutorial but it is not complete.

Please help here to complete my example project.

Regards,

paras 

Jochen Schalanda

unread,
Mar 12, 2013, 7:01:24 PM3/12/13
to dropwiz...@googlegroups.com
Hi!

On 12.03.2013 23:38, Paras Goel wrote:
> I am looking some example for dropwizard http client.

There is no Dropwizard HTTP Client but the framework will provide you
with a working Jersey HTTP Client which is nicely managed and
instrumented [1]. From that point on you can simply follow the
formidable Jersey documentation for using the Client class [2].


[1]: http://dropwizard.codahale.com/manual/client/#jersey-client
[2]:
http://jersey.java.net/nonav/documentation/1.15/user-guide.html#client-api

Regards,
Jochen

Paras Goel

unread,
Mar 13, 2013, 9:37:14 AM3/13/13
to dropwiz...@googlegroups.com, joc...@schalanda.name
Thanks Jochen,

But I want to add that in dropwizard manual guide i have read that there are two type of client i.e  Apache HttpClient and Jersey Client.


So is it recommended that we should use jersey client?

Regards,

Paras Goel

Christophe Furmaniak

unread,
Mar 13, 2013, 9:53:20 AM3/13/13
to dropwiz...@googlegroups.com, joc...@schalanda.name
The jersey client is recommended if you don't want/know how to deal with the "raw" http client.


I tried to write the code so that each piece can be as testable as possible, that's why everything is sliced (highly inspired by the "Clean Code" book).

Christophe

Jochen Schalanda

unread,
Mar 13, 2013, 11:24:53 AM3/13/13
to dropwiz...@googlegroups.com
Hi,

On 13.03.2013 14:37, Paras Goel wrote:
> So is it recommended that we should use jersey client?

The Jersey Client class is basically just a wrapper around Apache
HttpClient which provides a nice abstraction for RESTful HTTP
interfaces. If you want to access another RESTful service I recommend
using Jersey Client.


Regards,
Jochen

Paras Goel

unread,
Mar 13, 2013, 11:30:34 AM3/13/13
to dropwiz...@googlegroups.com, joc...@schalanda.name
Thanks again Jochen,

I choose the jersey client to make the client but  while implementing the example I found another class "environment.addResource(new ExternalServiceResource(client));"
So what is ExternalServiceResource i could not find it anywhere.
from where i can find its jar?.

Regards,

paras Goel 

Coda Hale

unread,
Mar 13, 2013, 12:10:18 PM3/13/13
to dropwiz...@googlegroups.com
That's an example of what you should do: pass the client instance to whatever classes require it via constructors.

I need to be more literal-minded when writing documentation.
--
You received this message because you are subscribed to the Google Groups "dropwizard-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dropwizard-us...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 


--
Coda Hale
http://codahale.com

Jochen Schalanda

unread,
Mar 13, 2013, 12:11:44 PM3/13/13
to dropwiz...@googlegroups.com
On 13.03.2013 16:30, Paras Goel wrote:
> So what is ExternalServiceResource i could not find it anywhere.
> from where i can find its jar?.

It's just an example class named like this for example's sake. There
isn't any actual class called ExternalServiceResource in Dropwizard.

It should just show that this JAX-RS resource class depends on an
external service and thus receives the initialized client (Jersey
Client) object via its constructor.


Regards,
Jochen
Reply all
Reply to author
Forward
0 new messages