<document>
<deftable>
resin-web.xml configuration
PHP script acting as the web client
Log service implementation
</deftable>

Using JMS for WebServices is as easy as sending the body of a SOAP message as a JMS message. (TODO: Actually remove SOAP envelope.) Below is a PHP script using the Quercus JMS module that acts as the service client.

<?php $service_queue = new JMSQueue("jms/ServiceQueue"); if (! $service_queue) { exit("Unable to get service queue!"); } $log_service = jndi_lookup("example/LogService"); echo "<a href=\"\">Refresh</a><br/>\n"; echo "Logged messages:<br/>\n"; echo "<pre>\n"; echo $log_service->getLog(); echo "</pre>\n"; $request = "<env:Envelope xmlns:env=\"http://www.w3.org/2003/05/soap-enveloper\">" . "<env:Body>" . "<m:log xmlns:m=\"urn:log\">" . " <s>Hello, World</s>" . "</m:log>" . "</env:Body>" . "</env:Envelope>"; if (! $service_queue->send($request)) { echo "Unable to send request\n"; } ?>

In the configuration below, we create a JMS queue for service requests. The service provider is a JMS MessageListener (implemented by `com.caucho.jms.services.ServicesListener`) which services all requests sent as JMS `TextMessage`s on the serviceQueue. In this example, the actual service implementation is a logging service, shown below.

<web-app xmlns="http://caucho.com/ns/resin"> <servlet servlet-name="resin-php" servlet-class="com.caucho.quercus.servlet.QuercusServlet" /> <servlet-mapping url-pattern="*.php" servlet-name="resin-php" /> <system-property javax.xml.stream.XMLInputFactory="com.caucho.xml.stream.XMLInputFactoryImpl"/> <resource var="logService" jndi-name="example/LogService" type="example.LogService" /> <resource var="serviceQueue" jndi-name="jms/ServiceQueue" type="com.caucho.jms.memory.MemoryQueue"/> <resource var="jmsFactory" type="com.caucho.jms.ConnectionFactoryImpl" jndi-name="jms/ConnectionFactory"/> <resource type="com.caucho.jms.services.ServicesListener"> <init> <connection-factory>${jmsFactory}</connection-factory> <destination>${serviceQueue}</destination> <service>${logService}</service> </init> </resource> </web-app>

The actual service provided here is a logging service. Note the @WebService and @WebMethod annotations.

package example; import javax.jws.WebMethod; import javax.jws.WebService; @WebService public class LogService { private int _sequenceNumber = 1; private StringBuilder _log = new StringBuilder(); @WebMethod public int log(String message) { _log.append(_sequenceNumber + ": " + message + "\n"); return _sequenceNumber++; } @WebMethod(exclude=true) public String getLog() { return _log.toString(); } }
</document>