Hawaiʻi's Technology Community

HOWTO: Consume a Groovy Web Service with Flex

Recently, I've been faced with the fact that Flex is quite popular as a web presentation layer. Given my Java background, at first I was quite reluctant to recognize this, until new projects paved the way to learn more about this RIA technology. Since I already have a considerable amount of server-side code in Java, I was wondering if it is possible to connect Java and Flex to get the best of both worlds. Hence this article gives a walk through on how to consume a Groovy Web Service with Flex. Let's start with a simple Groovy service class, which might look something like this

Then, let's create a Groovy Web Service

Running WSPublisher will start up an instance of Jetty and publish your newly created web service. To check that everything is running smoothly, try accessing WSDL
You should get back an XML document. Now, once your simple web service is running, let's create a simple Flex consumer. Assuming you already have a Flex project setup, let's start by declaring a web service

Notice WSDL url parameter and operation 'name' tag, which point to Java 'getMsg' method. The rest of attributes define web service id and respective callback functions, declared like this

Last step is to create a simple button that would trigger the call

Now, run your Flex project and you should see a single button on the screen.

If you've done everything correctly, pressing the button will fetch "Hello World from Flex/Java communication!" string and display it in a pop up window

That is it! Now you can use your existing Java server code and still have a slick Flex based user interface. Here is a JavaWorld article that goes further into Java EE/Flex combination. Hope you find this post useful. Happy Flexing!
Ikayzo - Design • Build • Localize | Web • Desktop • Mobile

Views: 298


You need to be a member of TechHui to add comments!

Join TechHui


web design, web development, localization

© 2023   Created by Daniel Leuck.   Powered by

Badges  |  Report an Issue  |  Terms of Service