<document>
<deftable>
Interface for the logging service.
The main service implementation.
Configures the environment
Client JSP
</deftable>

The HelloService implementation is just a Java class that implements the HelloService API. This service responds by placing the results of the request on a JMS queue.

package example; public interface LogService { public void log(String message); public String getLog(); } package example; public class LogServiceImpl implements LogService { private int _sequenceNumber = 1; private StringBuilder _log = new StringBuilder(); public void log(String message) { _log.append(_sequenceNumber + ": " + message + "\n"); _sequenceNumber++; } public String getLog() { return _log.toString(); } }

The configuration for this example is the following:

<web-app xmlns="http://caucho.com/ns/resin"> <resource var="logService" jndi-name="example/LogService" type="example.LogServiceImpl" /> <resource var="serviceQueue" jndi-name="jms/ServiceQueue" type="com.caucho.jms.memory.MemoryQueue" /> <resource var="jmsFactory" jndi-name="jms/ConnectionFactory" type="com.caucho.jms.ConnectionFactoryImpl" /> <resource type="com.caucho.hessian.server.HessianListener"> <init> <connection-factory>${jmsFactory}</connection-factory> <destination>${serviceQueue}</destination> <service>${logService}</service> </init> </resource> </web-app>

Finally, the service is called from a JSP page:

<%@ page import="javax.naming.Context" %> <%@ page import="javax.naming.InitialContext" %> <%@ page import="com.caucho.hessian.client.HessianProxyFactory" %> <%@ page import="example.LogService" %> <% // Check the log Context context = (Context) new InitialContext().lookup("java:comp/env"); LogService logService = (LogService) context.lookup("example/LogService"); out.println("Refresh
"); out.println("Logged messages:<br/>"); out.println("<pre>"); out.println(logService.getLog()); out.println("</pre>"); // Make a request HessianProxyFactory factory = new HessianProxyFactory(); String url = "jms:jms/ServiceQueue"; LogService log = (LogService) factory.create(LogService.class, url); log.log("Hello, World"); %>

Try the example

</document>