1

I am trying to integrate Flex application to access Rest services (using Jersey) through BlazeDS. I'm able to get Rest + Jersey working (pretty straight forward I guess) and I was able to configure Flex + BlazeDS. I'm looking for help to invoke rest services (different methods) from Flex UI based on the annotations specified such as @Path in my rest service class.

Can someone provide some pointers/examples to configure Flex -BlazeDS to invoke the rest services?

Thanks,
RJ

RJ.
  • 313
  • 2
  • 5
  • 14

1 Answers1

0

First off if you're using BlazeDS and only going to have Flex clients, you should setup BlazeDS remote objects instead of REST service. You can use amf channels and send objects instead of xml/json/text.

That being said, What version of flex are you using? I have only done this with Flex 4 (and actionscript 3) using URLRequest and URLLoader (or with HTTPRequest)
Example:

var dataRequest:URLRequest;
var dataLoader:URLLoader;

dataRequest = new URLRequest("http://localhost:8080/Path/to/webservice");
//using post in this case, you can also acess GET  
dataRequest.method = URLRequestMethod.POST;
var variables:URLVariables = new URLVariables();

variables.xmlCoords = xml;

dataRequest.data = variables;
dataRequest.contentType = "application/xml";
dataRequest.requestHeaders.push(new URLRequestHeader("accept", "application/xml"));

dataLoader.load(dataRequest);

Is it feasible to create a REST client with Flex? this topic has been discussed here with some good pointers and I think you should check it out.

Hopefully this can help you out some / point you in the right direction.

Community
  • 1
  • 1
Mike
  • 8,137
  • 6
  • 28
  • 46
  • Thanks Mike. One important point to mention is that the rest services would need to be called both from the flex UI as well as outside (ie the services need to be called in a Restful and non rest way). What is the recommended approach for this? Blaze Ds calling rest (from UI) and have a service exposed to be called from outside? Any comments/suggestions? I'm still trying to get a hang of the rest paradigm and need some inputs. Thanks, RJ – RJ. Feb 16 '11 at 11:25
  • Are you the one creating the flex client code, or are you just responsible for the webservice? I am fairly new to both as well, but what I ended up doing here is just a REST webservice with the dataLoader and dataRequest since I also need it to be available to clients not using flex. It may be best to just stick with REST everywhere and do a bit more work on the flex side to connect to the rest service. If you really wanted you could setup both a rest service and a blazeDS connection with remote objects. The latter approach would probably be a lot of duplicate code is the only issue. – Mike Feb 16 '11 at 14:08
  • I am responsible for both Flex as well as Rest services. I will need to create the rest services such that it can be connected from UI as well as outside. – RJ. Feb 17 '11 at 08:31
  • Okay then just sticking with a REST service is a good call. You should look into the DataRequest and DataLoader from flex or [HTTPService](http://fxtidbits.blogspot.com/2010/02/making-restful-web-service-call.html) to call the REST service from flex. You may have to change a few things (ie setting headers / request type) depending on whether you are using POST or GET and what you are using as data transfer (application/xml, text, json, etc) – Mike Feb 17 '11 at 14:11