This chapter will explain how to set up Remoting over HTTP. RRiBbit HTTP Remoting supports connections that run over SSL, but cannot actually set up such a connection. The reason for this is that setting up an SSL connection is usually not handled by the application, but by the Servlet Container (such as Tomcat) or even higher up the chain, for example the Apache HTTP Server.
RRiBbit uses Apache HTTP Client for initiating the connection from the Client side and Commons Codec to convert the Requests and Responses to a Base64 String, to be sent over HTTP. The exact JAR files and versions thereof that RRiBbit needs are listed in the pom.xml. They are marked as optional, so Maven will not automatically include them in your war file, you have to do that yourselves. Please note that some of these libraries may have transitive dependencies to Commons Logging. If you wish to use SLF4J with the Commons Logging bridge instead, please make sure that the Commons Logging libraries are excluded from your Maven Configuration.
On the server side, RRiBbit provides the HttpRequestProcessorServlet, which is a simple Servlet that receives the Requests from the Client, decodes them and processes them. Like all RequestProcessors, this class needs a ListenerObjectRetriever and a ListenerObjectExecutor. Since it's a Servlet, you cannot pass these in via the constructor. Therefore, two abstract methods have to be implemented to provide them.
If you use Spring, then you can use SpringHttpRequestProcessorServlet, which is an extension of HttpRequestProcessorServlet that implements those abstract methods by getting the Spring WebApplicationContext from the ServletContext and searching for a ListenerObjectRetriever and a ListenerObjectExecutor in that WebApplicationContext. All you have to do is wire up a ListenerObjectRetriever, a ListenerObjectCreator and a ListenerObjectExecutor in your Spring Configuration and then declare the SpringHttpRequestProcessorServlet in your web.xml.
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"> <bean class="fully.qualified.name.of.YourClass" /> <bean id="listenerObjectCreator" class="org.rribbit.creation.SpringBeanClassBasedListenerObjectCreator"> <property name="classNames"> <list> <value>fully.qualified.name.of.YourClassInterface</value> </list> </property> </bean> <bean class="org.rribbit.retrieval.CachedListenerObjectRetriever"> <property name="listenerObjectCreator" ref="listenerObjectCreator" /> </bean> <bean class="org.rribbit.execution.MultiThreadedListenerObjectExecutor" /> </beans>
Then load your Spring WebApplicationContext in the web.xml, along with the SpringHttpRequestProcessorServlet:
<?xml version="1.0" encoding="ISO-8859-1"?> <web-app xmlns="http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/javaee/web-app.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/javaee/web-app.xsd http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/javaee/web-app_2_5.xsd"> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext.xml</param-value> </context-param> <servlet> <servlet-name>RRiBbit</servlet-name> <servlet-class>org.rribbit.processing.SpringHttpRequestProcessorServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>RRiBbit</servlet-name> <url-pattern>/rribbit</url-pattern> </servlet-mapping> </web-app>
So, no Java code is required at all! Just a few lines of Spring xml and web.xml and the server side is ready to go.
On the Client side, RRiBbit provides the HttpRequestDispatcher. This one is very simple. Just provide it with the URL of the Servlet above and hook it up to your RequestResponseBus. The URL is a standard URL, like 'http://host:port/path' and can also start with 'https://'. In case you're wondering, RRiBbit HTTP Remoting uses POST only, no other HTTP methods are invoked.
Whenever you see an error while using RRiBbit HTTP Remoting, it could be caused by a number of things. Below are the two most common Exceptions that you could see on the Client side and their most likely causes:
StreamCorruptedException: Indicates that the client does not understand the response from the server. This may mean that the client gets a 404 page back, which it cannot decode. Please see the client's org.apache.http logs to see the response that the client got from the server. Please also check the URL that you have given the client.
EOFException: Indicates that the client does not get a response from the server. Please check the server logs to see what's wrong.
And that's all about RRiBbit Remoting over HTTP! For other RRiBbit Remoting implementations, please see this page. And before you actually start using RRiBbit, make sure that you check the FAQ!