Async REST web services calls

Daniel Zwolenski zonski at gmail.com
Fri Feb 15 17:46:18 PST 2013


And another alternative:

http://www.zenjava.com/2012/12/04/javafx-with-a-springmvc-rest-server-in-5-minutes/

This is both client and server but the client bit should work with any rest server. 

Threading model from here would apply too:

http://www.zenjava.com/2012/02/25/going-remote-javafx-and-spring-remoting/

(not a rest example but same deal)

Add security with something like this:

http://www.zenjava.com/2012/03/27/javafx-and-spring-security/


If you have a pure java client and a pure java server I'd highly recommend spring remoting (with httpinvoker) over Rest. You only really need/want rest if you are targeting cross-language clients and the programming model is then messier as a result. 


On 16/02/2013, at 12:15 PM, Гулько Александр <kirhog at gmail.com> wrote:

> Sebastian,
> 
> Try Apache HttpComponents library for HTTP requests:
> http://hc.apache.org/. Your code will be much more simpler.
> 
> Furthermore it has async client (
> http://hc.apache.org/httpcomponents-asyncclient-dev/index.html) and the
> example (
> http://hc.apache.org/httpcomponents-asyncclient-dev/httpasyncclient/examples/org/apache/http/examples/nio/client/AsyncClientHttpExchangeFutureCallback.java)
> special for your case.
> 
> Regards,
> Alexander
> 
> 2013/2/14 Hendrik Ebbers <hendrik.ebbers at me.com>
> 
>> Hi,
>> maybe DataFX (http://www.javafxdata.org/) can help.
>> 
>> 
>> 
>> Am 14.02.2013 um 19:10 schrieb Sebastian Gutierrez <scgm11 at gmail.com>:
>> 
>>> Hello list,
>>> 
>>> I'm migrating a silverlight app to javafx, but I'm running into this
>> issue:
>>> 
>>> I used a lot async calls to REST Webservices on siverlight like this:
>>> 
>>> WebClient test = new WebClient();
>>> test.UploadStringCompleted += new
>> UploadStringCompletedEventHandler(test_UploadStringCompleted);
>>> test.UploadStringAsync(URL, POST DATA);
>>> 
>>> and the callback method:
>>> 
>>> 
>>> void test_UploadStringCompleted(object sender,
>> UploadStringCompletedEventArgs e)
>>>       {
>>>     String result =    e.Response();
>>> 
>>>           //here I have the response of the web service
>>> 
>>>       }
>>> 
>>> 
>>> 
>>> 
>>> 
>>> now Im using this on JAVAFX:
>>> 
>>> 
>>> public static String ExecPOSTRESTWebService(String resource, String data)
>>>   {
>>>       try {
>>> 
>>> 
>>> 
>>> 
>>>     String rest = //URL for the rest WS;
>>> 
>>>     URL url = new URL(rest);
>>>     URLConnection conn = url.openConnection();
>>>     conn.setDoOutput(true);
>>>           BufferedReader rd;
>>>           String buffer;
>>>           try (OutputStreamWriter wr = new
>> OutputStreamWriter(conn.getOutputStream())) {
>>>               wr.write(data);
>>>               wr.flush();
>>>               rd = new BufferedReader(new
>> InputStreamReader(conn.getInputStream()));
>>>               String line;
>>>               buffer = "";
>>>               while ((line = rd.readLine()) != null) {
>>>                   buffer = buffer + line;
>>>               }
>>>           }
>>>     rd.close();
>>> 
>>>     return buffer;
>>> 
>>>       } catch (Exception ex) {
>>>           Logger.getLogger(Utils.class.getName()).log(Level.SEVERE,
>> ex.toString());
>>>           return "";
>>>       }
>>> 
>>>   }
>>> 
>>> 
>>> the problem is that this is sync and not async so I block the UI, I know
>> I can do some threading and Platform.runlater… and those… but for many
>> calls the code will get hard to read and difficult
>>> is there any component around that does the async calls with a callback
>> method?? any library?
>>> 
>>> 
>>> Thanks!
>>> 
>>> 
>>> 
>> 


More information about the openjfx-dev mailing list