Async REST web services calls
Гулько Александр
kirhog at gmail.com
Fri Feb 15 17:15:28 PST 2013
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