This chapter provides instructions for deploying Coherence REST to an embedded HTTP server, WebLogic server, and GlassFish server. Generic servlet container instructions are also provided.
The following sections are included in this chapter:
Coherence provides two embedded HTTP servers that can be used to host RESTful Web services: com.tangosol.coherence.rest.server.DefaultHttpServer (backed by Oracle's lightweight HTTP server) and com.tangosol.coherence.rest.server.GrizzlyHttpServer (backed by Grizzly). See "Changing the Embedded HTTP Server" for details on changing the default HTTP server.
The HTTP server must be enabled on a Coherence proxy server. To enable the HTTP server, edit the proxy's cache configuration file and add an <http-acceptor> element, within the <proxy-scheme> element, and include the host and port for the HTTP server.
The following example configures the HTTP server to accept requests on localhost 127.0.0.1 and port 8080.
<proxy-scheme>
<service-name>ExtendHttpProxyService</service-name>
<acceptor-config>
<http-acceptor>
<class-name>
com.tangosol.coherence.rest.server.DefaultHttpServer</class-name>
<local-address>
<address>127.0.0.1</address>
<port>8080</port>
</local-address>
<resource-config>
<instance>
<class-name>
com.tangosol.coherence.rest.server.DefaultResourceConfig
</class-name>
</instance>
</resource-config>
</http-acceptor>
</acceptor-config>
<autostart>true</autostart>
</proxy-scheme>
The above configuration explicitly defines the HTTP server class and Jersey resource configuration class. However; these are default values and need not be included. See Oracle Coherence Developer's Guide for a detailed reference of all <http-acceptor> subelements.
This section provides instructions for deploying Coherence Rest to a Java EE environment:
The following topics are included in this section:
To package a Coherence REST application:
Create a basic Web application directory structure as follows:
/ /WEB-INF /WEB-INF/classes /WEB-INF/lib
Copy the following JARs from the COHERENCE_HOME/lib directory to the /WEB-INF/lib directory:
coherence.jar
coherence-rest.jar
jackson-all-1.8.1.jar
jersey-core-1.7.jar
jersey-json-1.7.jar
jersey-server-1.7.jar
Create a Web application deployment descriptor (web.xml) and include the following servlet definition:
<web-app>
<servlet>
<servlet-name>Coherence REST</servlet-name>
<servlet-class>
com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>
com.sun.jersey.config.property.resourceConfigClass</param-name>
<param-value>
com.tangosol.coherence.rest.server.DefaultResourceConfig
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
...
</web-app>
Save the web.xml file to the /WEB-INF/ directory.
Copy the coherence-rest-config.xml file to the /WEB-INF/classes directory.
Copy your coherence-cache-config.xml file and tangosol-coherence-override.xml file to the WEB-INF/classes directory.
Create a Web ARchive file (WAR) using the jar utility. For example, issue the following command from a command prompt at the root of the Web application directory:
jar -cvf coherence_rest.war *
The archive should contain the following files
/WEB-INF/web.xml /WEB-INF/classes/coherence-rest-config.xml /WEB-INF/classes/tangosol-coherence-override.xml /WEB-INF/classes/coherence-cache-config.xml /WEB-INF/lib/coherence.jar /WEB-INF/lib/coherence-rest.jar /WEB-INF/lib/jackson-all-1.8.1.jar /WEB-INF/lib/jersey-core-1.7.jar /WEB-INF/lib/jersey-json-1.7.jar /WEB-INF/lib/jersey-json-1.7.jar
To deploy Coherence REST to WebLogic server:
Package Coherence REST as a WAR file as described in "Packaging Coherence REST for Deployment". To ensure the correct version of Coherence is used, add the following WebLogic-specific deployment descriptor to the /WEB-INF directory:
<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app
xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd
http://xmlns.oracle.com/weblogic/weblogic-web-app
http://xmlns.oracle.com/weblogic/weblogic-web-app/1.0/weblogic-web-app.xsd">
<wls:container-descriptor>
<wls:prefer-web-inf-classes>true</wls:prefer-web-inf-classes>
</wls:container-descriptor>
</wls:weblogic-web-app>
Deploy the WAR using the WebLogic administration console (http://localhost:7001/console).
From a browser, access the data in a Coherence cache by navigating to http://localhost:7001/{cacheName}.
To deploy Coherence REST to GlassFish server:
From GlassFish administration console, click Configuration->JVM Settings. switch to the JVM Options tab and add the following option:
Click the JVM Options tab and add the following option:
-Dcom.sun.enterprise.overrideablejavaxpackages=javax.ws.rs,javax.ws.rs.core,javax.ws.rs.ext
Package Coherence REST as a WAR file as described in "Packaging Coherence REST for Deployment". In addition, override the version of Jersey distributed in GlassFish with the version of Jersey distributed with Coherence REST by setting the class loader delegation to false in WEB-INF/sun-web.xml or WEB-INF/glassfish-web.xml. For example:
<sun-web-app error-url=""> <class-loader delegate="false"/> </sun-web-app>
Deploy the WAR using the GlassFish administration console. (http://localhost:4848/).
From a browser, access the data in Coherence caches by navigating to http://localhost:8080/{cacheName}.
Coherence REST can be deployed to any servlet container by packaging Coherence REST as a WAR file. See "Packaging Coherence REST for Deployment" for details. Refer to your vendors documentation for details on deploying WAR files. In addition, See the Jersey user guide for additional servlet container deployment options:
http://jersey.java.net/nonav/documentation/latest/user-guide.html#d4e194