SOA Messaging Basics
Appcelerator provides SOA Integration Points for Java, PHP, Ruby, .NET, Python and Perl. SOA Integration Points enable developers to create Appcelerator services that are fully integrated with Appcelerator’s message-oriented architecture.
Appcelerator services are responsible for fulfilling service requests (typically generated by Appcelerator RIAs). Since Appcelerator is message-driven, Appcelerator services must subscribe to a service request message and produce a service response message. Each SOA Integration Point provides a simple mechanism for declaring service message subscription. SOA Integration Points also handle data marshalling on behalf of the service, which greatly simplifies the task of service creation.
The example below shows how to create a service using the Java SOA Integration Point. Please see our Reference and Getting Started Guides for more information on how to use the other SOA Integration Points.
Example Java Service
Creating Java services is easy. You start with a plain Java object (POJO) and simply apply a Service annotation to each method that handles a service request.
@Service(request = "login.request", response = "login.response")
The Java SOA Integration Point also provides a simple way to deal with request and response data. Request data can be accessed via the request Message object like so:
request.getData().getString("foo")
There are also methods for getting other Java data types like boolean and Long.
Adding data to the response is also easy. You can “put” data into the response object like so:
response.getData().put("user",user)
In the example above, we place a Java User object into the response. The Java SOA Integration Point automatically handles the data marshalling for us.
Here’s a full example of a Java service.
import org.appcelerator.annotation.Service;
import org.appcelerator.messaging.Message;
public class LoginService
{
@Service(request = "login.request", response = "login.response")
protected void processLogin (Message request, Message response)
{
// get request data
String username = request.getData().getString("username");
String password = request.getData().getString("password");
User user = userDAO.login(username,password);
// format response
if (user != null)
{
response.getData().put("success",true);
response.getData().put("user",user);
return;
}
response.getData().put("success",false);
}
}