Remote Method Invocation (RMI)
As explained earlier, Spring simplifies the RMI model by providing appropriate proxy factory bean called as RmiProxyFactoryBean that enables you to wire RMI services into your Spring application. Spring also provides a remote exporter that makes converting your Spring-managed beans into RMI services.
Spring also provides an easier way to publish these RMI services. Instead of conventionally writing RMI-specific classes with methods that throw RemoteException, you simply write a POJO that performs the functionality of your service and the rest is handle automatically by Spring.
Spring’s own HttpInvoker
Spring provides a special remoting strategy which allows Java serialization via HTTP protocol. This is a very vital feature, particularly when the method arguments you want to pass to the service are complex type objects as compared to simple text messages. This is achieved by using support classes namely HttpInvokerProxyFactoryBean and HttpInvokerServiceExporter.
HTTP invoker is dedicated clearly to perform powerful and seamless Java-to-Java remoting. One of the disadvantages associated with this type of emoting is that, in this both server and client applications be based on the Spring framework.
Hessian is a lightweight binary RPC protocol developed at Caucho Technology. Hessian is a small binary protocol. It uses a custom serialization technique to send the Java objects over the network. In addition to Java, Hessian includes implementations for other languages such as PHP, Python, C++, C# etc.
Hessian serializes objects using a proprietary (very compact) binary format. Hessian remote objects are just ordinary Java objects that implement some interfaces. They don’t require special proxy, home, or remote classes. Hessian protocol fully leverages the host environment’s Web container capabilities. Hessian serialization is very efficient, and the produced binary serialized objects are very compact.
Burlap is a lightweight XML-RPC protocol. Similar to Hessian, it also uses a proprietary serialization mechanism for serializing the Java objects over the network. Burlap serializes objects over the Web using XML.
Similar to Hessian, Burlap’s remote object are ordinary Java objects implementing some interfaces and doesn’t require proxy, home or remote classes. The serialization is very efficient and produced XML’s are very compact.
Spring provides remoting support for web services via JAX-RPC (Java APIs for XML-based Remote Procedure Call). JAX-RPC fully embraces the diverse nature of Web services; it allows a JAX-RPC client to talk to another Web service deployed on a different platform and coded in a different language, it also allows clients on other platforms and coded in different languages to talk to a JAX-RPC service. JAX-RPC also defines the mapping between WSDL (Web Service Description Language) service descriptions and Java interfaces. It can be seen as Java RMIs over Web services.
Spring provides remoting support for web services via JAX-WS (Java API for XML Web Services). JAX-RPC 2.0 was renamed as JAX-WS 2.0 in Java EE 5 and Java 6. The name change reflected the move away from RPC-style and toward document-style web services in the Java world. JAX-RPC 1.0 is deprecated with Java EE 6. JAX-WS uses annotations extensively to simplify the development and deployment of web service clients and endpoints.
JMS is one of the robust and widely used application integration styles. Spring provides remoting support using JMS as the underlying protocol. This is achieved by using support classes namely JmsInvokerProxyFactoryBean and JmsInvokerServiceExporter.
In your Spring config file on the client you create a factory bean of JmsInvokerProxyFactoryBean, you give this bean the service interface, the well named queue and connection factory to the JMS Server. Spring creates a dynamic proxy which translates your code into JMS messages with reply-to and temp queues created properly.
On the server side you create a JmsInvokerServiceExporter bean which has a reference to your bean which actually implements the service interface. You then set up a message listener container which has a reference to the JmsInvokerServiceExporter. The service exporter handles converting the message into an API call on your interface and responding back to the caller on the reply-to queue. This approach is really beneficial because the code you write never interacts with the actual JMS API.
Files are storage mechanism, built into any enterprise operating system and available from any enterprise language universally. In this integration style, your application produces files of shared data for others to consume and consume files that others have produced. Appropriate integrators take the responsibility of producing files in different formats which the business can use which suits their requirement as and when required.
The advantages of this style are that, it is interoperable, much simpler and fast (even though this is purely a relative term). This integration style has its own disadvantages. This style is generally considered to be unsafe with concurrency issues, minimal security considerations and non-transactional in nature. Other disadvantage being that it is platform dependent and not event-driven in nature.
Figure 6-6. File transfer Integration style
Spring framework provides extensive support for this integration style. The support by Spring for this integration style is as below:
- Resource API
- Spring Batch
- Spring Integration
These will be explained to some extent in the following sections.
Spring has rich set of API’s which helps to simplify the common I/O (Input/Output) operations in this integration style. There are several ways by which this integration style can be realized in your application, but three of the most common are using a shared mount or folder, using a FTP server, and for more secure exchanges, using SSH (or SFTP).
SFTP – SSH File Transfer Protocol or Secret File Transfer Protocol or Secure FTP
Spring Batch is a lightweight, comprehensive batch framework designed to enable the development of robust batch applications vital for the daily operations of enterprise systems. Spring Batch builds upon the productivity, POJO-based development approach, and general ease of use.
Spring Batch provides reusable functions that are essential in processing large volumes of records, including logging/tracing, transaction management, job processing statistics, job restart, skip, and resource management. It also provides more advanced technical services and features that will enable extremely high-volume and high performance batch jobs through optimization and partitioning techniques. Simple as well as complex, high-volume batch jobs can leverage the framework in a highly scalable manner to process significant volumes of information.
Various API’s in Spring batch allows to parse CSV and XML files easily. It also helps in streaming of large files in and out of the application with ease.
Spring Batch and its capabilities will be covered in detail in Chapter 19.
Even though Spring has always provided first-class support for messaging and remote procedure calls, many might be surprised at the many robust options available for file transfer integration style which is realized by the Spring Integration project. As explained earlier, among the common three ways of achieving this integration style (shared folder, FTP and SFTP), Spring Integration project has extensive support for all of them.
Spring Integration and its importance in enterprise application will be covered in detail in Chapter 20.
In this Chapter you would have got a clear idea of the various integration styles and its various advantages and disadvantages. More importantly you would have got a clear picture of the support that the Spring framework provides you to achieve this integration style in your application. Even though I have brought about various topics like Spring Batch, Spring Integration, Spring Web Services etc. in this Chapter, I have not given exhaustive explanation in this chapter as we have dedicated chapters later in this book which covers these topics in detail. Still I wanted to bring those topics here in this Chapter so that you have a clear linkage of the reasons we are covering these in detail later on in this book.
After reading this chapter you would have got a clear picture of the various integration styles available along with its pros and cons and more importantly the support provided by the Spring framework.
Page Visitors: 2214