You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@wink.apache.org by Francesco Chicchiriccò <il...@apache.org> on 2013/06/04 10:36:06 UTC
InputStream & async examples
Hi all,
I am currently evaluating Wink for a new project.
I have been playing around with some samples and it seems linear to me.
I am not completely convinced, however, of async usage; this is how I
have managed to get it working:
AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
RestClient client = new RestClient(new
AsyncHttpClientConfiguration(asyncHttpClient));
Resource resource =
client.resource("http://services.odata.org/v3/(S(sn4zeecdefwvblk2xxlk425x))/OData/OData.svc/Products");
AtomFeed feed =
resource.contentType("application/atom+xml").accept("application/atom+xml").get(AtomFeed.class);
asyncHttpClient.close();
for (AtomEntry entry : feed.getEntries()) {
System.out.println(entry.getTitle().getValue());
}
Is this the correct usage? Isn't there any way to get something like
Future<AtomFeed> instead?
Moreover, I was also looking for a way to get an InputStream out of a
response, to delay processing: is this possible?
Thanks for your support.
Regards.
--
Francesco Chicchiriccò
ASF Member, Apache Syncope PMC chair, Apache Cocoon PMC Member
http://people.apache.org/~ilgrosso/
Re: InputStream & async examples
Posted by Francesco Chicchiriccò <il...@apache.org>.
On 06/06/2013 09:50, Francesco Chicchiriccò wrote:
> On 05/06/2013 20:48, Luciano Resende wrote:
>> On Tue, Jun 4, 2013 at 6:52 AM, Francesco Chicchiriccò
>> <ilgrosso@apache.org <ma...@apache.org>> wrote:
>>
>> On 04/06/2013 10:36, Francesco Chicchiriccň wrote:
>>
>> Hi all,
>> I am currently evaluating Wink for a new project.
>>
>> I have been playing around with some samples and it seems
>> linear to me.
>> I am not completely convinced, however, of async usage; this
>> is how I have managed to get it working:
>>
>> AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
>> RestClient client = new RestClient(new
>> AsyncHttpClientConfiguration(asyncHttpClient));
>>
>> Resource resource =
>> client.resource("http://services.odata.org/v3/(S(sn4zeecdefwvblk2xxlk425x))/OData/OData.svc/Products
>> <http://services.odata.org/v3/%28S%28sn4zeecdefwvblk2xxlk425x%29%29/OData/OData.svc/Products>");
>>
>> AtomFeed feed =
>> resource.contentType("application/atom+xml").accept("application/atom+xml").get(AtomFeed.class);
>> asyncHttpClient.close();
>>
>> for (AtomEntry entry : feed.getEntries()) {
>> System.out.println(entry.getTitle().getValue());
>> }
>>
>> Is this the correct usage? Isn't there any way to get
>> something like Future<AtomFeed> instead?
>>
>> Moreover, I was also looking for a way to get an InputStream
>> out of a response, to delay processing: is this possible?
>>
>>
>> I guess I've found (this seems to work):
>>
>> RestClient client = new RestClient(new
>> ApacheHttpClientConfig(new DefaultHttpClient()));
>>
>> Resource resource =
>> client.resource("http://localhost:8080/Northwind/Northwind.svc/Categories(1)
>> <http://localhost:8080/Northwind/Northwind.svc/Categories%281%29>");
>>
>> ClientResponse response =
>> resource.accept(MediaType.APPLICATION_ATOM_XML).get();
>> InputStream is = response.getEntity(InputStream.class);
>> System.out.println("********* " + response.getStatusCode());
>> StringWriter writer = new StringWriter();
>> IOUtils.copy(is, writer);
>> System.out.println(writer.toString());
>>
>> I have also been able to create an entry (e.g. POST) only
>> providing InputStream: definitely nice.
>>
>> I'll keep investigating for the Future<T> stuff...
>>
>>
>> It would be great if you could provide some extra documentation on
>> our wiki or any enhanced examples.
>
> Hi Luciano,
> what kind of documentation are you thinking about? Could you also
> provide some coordinate under which I should create a new page /
> update an existing page? My ASF confluence userid is 'ilgrosso', BTW.
>
> About the Future<T> investigation, I've developed a quick example
> using Commons HttpAsyncClient 4.0-beta4 [1]: it looks more like a
> hack, but it works more or less this way:
>
> RestClient client = new RestClient(new
> ApacheHttpAsyncClientConfig());
>
> Resource resource =
> client.resource("http://services.odata.org/v3/(S(sn4zeecdefwvblk2xxlk425x))/OData/OData.svc/Products");
> FutureClientResponse response = (FutureClientResponse)
> resource.accept(MediaType.APPLICATION_ATOM_XML).get();
>
> System.out.println("XXXXXXXXXXX " + response.isDone());
>
> AtomFeed feed = response.get().getEntity(AtomFeed.class);
>
> e.g. FutureClientResponse implements both Future<ClientResponse> and
> ClientResponse
>
> I am not fully satisfied of this result (explicit cast to
> FutureClientResponse, for example...) but it proves at least that it
> could be done.
>
> A possible cleaner extension is to add a new Resource#get() (similar
> to what CXF does [2]), but I am not familiar at all with Wink's
> internals...
>
> As soon as I found enough spare time, I'll push my sample to github.
Here you go: [3].
Regards.
> [1] http://hc.apache.org/httpcomponents-asyncclient-dev/
> [2]
> http://cxf.apache.org/javadoc/latest/org/apache/cxf/jaxrs/client/WebClient.html#get(javax.ws.rs.client.InvocationCallback)
[3] https://github.com/ilgrosso/apacheHttpAsyncWink
--
Francesco Chicchiriccò
ASF Member, Apache Syncope PMC chair, Apache Cocoon PMC Member
http://people.apache.org/~ilgrosso/
Re: InputStream & async examples
Posted by Francesco Chicchiriccò <il...@apache.org>.
On 05/06/2013 20:48, Luciano Resende wrote:
> On Tue, Jun 4, 2013 at 6:52 AM, Francesco Chicchiriccò
> <ilgrosso@apache.org <ma...@apache.org>> wrote:
>
> On 04/06/2013 10:36, Francesco Chicchiriccň wrote:
>
> Hi all,
> I am currently evaluating Wink for a new project.
>
> I have been playing around with some samples and it seems
> linear to me.
> I am not completely convinced, however, of async usage; this
> is how I have managed to get it working:
>
> AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
> RestClient client = new RestClient(new
> AsyncHttpClientConfiguration(asyncHttpClient));
>
> Resource resource =
> client.resource("http://services.odata.org/v3/(S(sn4zeecdefwvblk2xxlk425x))/OData/OData.svc/Products
> <http://services.odata.org/v3/%28S%28sn4zeecdefwvblk2xxlk425x%29%29/OData/OData.svc/Products>");
>
> AtomFeed feed =
> resource.contentType("application/atom+xml").accept("application/atom+xml").get(AtomFeed.class);
> asyncHttpClient.close();
>
> for (AtomEntry entry : feed.getEntries()) {
> System.out.println(entry.getTitle().getValue());
> }
>
> Is this the correct usage? Isn't there any way to get
> something like Future<AtomFeed> instead?
>
> Moreover, I was also looking for a way to get an InputStream
> out of a response, to delay processing: is this possible?
>
>
> I guess I've found (this seems to work):
>
> RestClient client = new RestClient(new
> ApacheHttpClientConfig(new DefaultHttpClient()));
>
> Resource resource =
> client.resource("http://localhost:8080/Northwind/Northwind.svc/Categories(1)
> <http://localhost:8080/Northwind/Northwind.svc/Categories%281%29>");
>
> ClientResponse response =
> resource.accept(MediaType.APPLICATION_ATOM_XML).get();
> InputStream is = response.getEntity(InputStream.class);
> System.out.println("********* " + response.getStatusCode());
> StringWriter writer = new StringWriter();
> IOUtils.copy(is, writer);
> System.out.println(writer.toString());
>
> I have also been able to create an entry (e.g. POST) only
> providing InputStream: definitely nice.
>
> I'll keep investigating for the Future<T> stuff...
>
>
> It would be great if you could provide some extra documentation on our
> wiki or any enhanced examples.
Hi Luciano,
what kind of documentation are you thinking about? Could you also
provide some coordinate under which I should create a new page / update
an existing page? My ASF confluence userid is 'ilgrosso', BTW.
About the Future<T> investigation, I've developed a quick example using
Commons HttpAsyncClient 4.0-beta4 [1]: it looks more like a hack, but it
works more or less this way:
RestClient client = new RestClient(new
ApacheHttpAsyncClientConfig());
Resource resource =
client.resource("http://services.odata.org/v3/(S(sn4zeecdefwvblk2xxlk425x))/OData/OData.svc/Products");
FutureClientResponse response = (FutureClientResponse)
resource.accept(MediaType.APPLICATION_ATOM_XML).get();
System.out.println("XXXXXXXXXXX " + response.isDone());
AtomFeed feed = response.get().getEntity(AtomFeed.class);
e.g. FutureClientResponse implements both Future<ClientResponse> and
ClientResponse
I am not fully satisfied of this result (explicit cast to
FutureClientResponse, for example...) but it proves at least that it
could be done.
A possible cleaner extension is to add a new Resource#get() (similar to
what CXF does [2]), but I am not familiar at all with Wink's internals...
As soon as I found enough spare time, I'll push my sample to github.
Keep you posted.
Regards.
[1] http://hc.apache.org/httpcomponents-asyncclient-dev/
[2]
http://cxf.apache.org/javadoc/latest/org/apache/cxf/jaxrs/client/WebClient.html#get(javax.ws.rs.client.InvocationCallback)
--
Francesco Chicchiriccò
ASF Member, Apache Syncope PMC chair, Apache Cocoon PMC Member
http://people.apache.org/~ilgrosso/
Re: InputStream & async examples
Posted by Luciano Resende <lu...@gmail.com>.
On Tue, Jun 4, 2013 at 6:52 AM, Francesco Chicchiriccò
<il...@apache.org>wrote:
> On 04/06/2013 10:36, Francesco Chicchiriccň wrote:
>
>> Hi all,
>> I am currently evaluating Wink for a new project.
>>
>> I have been playing around with some samples and it seems linear to me.
>> I am not completely convinced, however, of async usage; this is how I
>> have managed to get it working:
>>
>> AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
>> RestClient client = new RestClient(new
>> AsyncHttpClientConfiguration(**asyncHttpClient));
>>
>> Resource resource =
>> client.resource("http://**services.odata.org/v3/(S(**
>> sn4zeecdefwvblk2xxlk425x))/**OData/OData.svc/Products<http://services.odata.org/v3/(S(sn4zeecdefwvblk2xxlk425x))/OData/OData.svc/Products>");
>>
>> AtomFeed feed = resource.contentType("**
>> application/atom+xml").accept(**"application/atom+xml").get(**
>> AtomFeed.class);
>> asyncHttpClient.close();
>>
>> for (AtomEntry entry : feed.getEntries()) {
>> System.out.println(entry.**getTitle().getValue());
>> }
>>
>> Is this the correct usage? Isn't there any way to get something like
>> Future<AtomFeed> instead?
>>
>> Moreover, I was also looking for a way to get an InputStream out of a
>> response, to delay processing: is this possible?
>>
>
> I guess I've found (this seems to work):
>
> RestClient client = new RestClient(new ApacheHttpClientConfig(new
> DefaultHttpClient()));
>
> Resource resource = client.resource("http://**
> localhost:8080/Northwind/**Northwind.svc/Categories(1)<http://localhost:8080/Northwind/Northwind.svc/Categories(1)>
> ");
>
> ClientResponse response = resource.accept(MediaType.**
> APPLICATION_ATOM_XML).get();
> InputStream is = response.getEntity(**InputStream.class);
> System.out.println("********* " + response.getStatusCode());
> StringWriter writer = new StringWriter();
> IOUtils.copy(is, writer);
> System.out.println(writer.**toString());
>
> I have also been able to create an entry (e.g. POST) only providing
> InputStream: definitely nice.
>
> I'll keep investigating for the Future<T> stuff...
>
> Regards.
>
> --
> Francesco Chicchiriccň
>
>
> ASF Member, Apache Syncope PMC chair, Apache Cocoon PMC Member
> http://people.apache.org/~**ilgrosso/<http://people.apache.org/~ilgrosso/>
>
>
It would be great if you could provide some extra documentation on our wiki
or any enhanced examples.
--
Luciano Resende
http://people.apache.org/~lresende
http://twitter.com/lresende1975
http://lresende.blogspot.com/
Re: InputStream & async examples
Posted by Francesco Chicchiriccò <il...@apache.org>.
On 04/06/2013 10:36, Francesco Chicchiriccò wrote:
> Hi all,
> I am currently evaluating Wink for a new project.
>
> I have been playing around with some samples and it seems linear to me.
> I am not completely convinced, however, of async usage; this is how I
> have managed to get it working:
>
> AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
> RestClient client = new RestClient(new
> AsyncHttpClientConfiguration(asyncHttpClient));
>
> Resource resource =
> client.resource("http://services.odata.org/v3/(S(sn4zeecdefwvblk2xxlk425x))/OData/OData.svc/Products");
>
> AtomFeed feed =
> resource.contentType("application/atom+xml").accept("application/atom+xml").get(AtomFeed.class);
> asyncHttpClient.close();
>
> for (AtomEntry entry : feed.getEntries()) {
> System.out.println(entry.getTitle().getValue());
> }
>
> Is this the correct usage? Isn't there any way to get something like
> Future<AtomFeed> instead?
>
> Moreover, I was also looking for a way to get an InputStream out of a
> response, to delay processing: is this possible?
I guess I've found (this seems to work):
RestClient client = new RestClient(new
ApacheHttpClientConfig(new DefaultHttpClient()));
Resource resource =
client.resource("http://localhost:8080/Northwind/Northwind.svc/Categories(1)");
ClientResponse response =
resource.accept(MediaType.APPLICATION_ATOM_XML).get();
InputStream is = response.getEntity(InputStream.class);
System.out.println("********* " + response.getStatusCode());
StringWriter writer = new StringWriter();
IOUtils.copy(is, writer);
System.out.println(writer.toString());
I have also been able to create an entry (e.g. POST) only providing
InputStream: definitely nice.
I'll keep investigating for the Future<T> stuff...
Regards.
--
Francesco Chicchiriccò
ASF Member, Apache Syncope PMC chair, Apache Cocoon PMC Member
http://people.apache.org/~ilgrosso/