Caucho Resin Java EE 6 Web Profile App Server PDF
Caucho Resin Java EE 6 Web Profile App Server PDF
Caucho Resin Java EE 6 Web Profile App Server PDF
Visit refcardz.com to browse and download the entire DZone Refcardz collection
brought to you by...
#88
Get More Refcardz! Visit refcardz.com
CONTENTS INCLUDE:
n
About Resin
Downloading Resin
Getting Started with
Caucho Resin
n
n
Installing Resin
n
Resin Directory Layout
n
Starting Resin
n
Configuring Resin and more...
By Emil Ong
are provided in the distribution. Ubuntu Linux users can use
ABOUT RESIN Caucho’s Ubuntu repository to install Resin as a .deb.
Caucho Technology’s Resin® is a Java Application Server with Resin 4.0 now requires Java SE 6. This latest version
a reputation for being lightweight and fast, yet reliable and Hot of Java introduces a number of API improvements and
scalable enough to power the most demanding enterprise Tip Caucho’s internal testing shows performance benefits as
well. Make sure to get the JDK, not just the JRE.
sites. Beginning as a Servlet and JSP engine in 1998, Resin
has since evolved to support the Java EE 6 Web Profile within Unix and Mac OS X installation
highly integrated implementations of Servlet 3.0, CDI, and EJB To install Resin on Unix and Mac OS X, you’ll need to compile
3.1 Lite. In addition to the Web Profile standards, Resin also the JNI code for Resin. Before you compile, you’ll need an
includes a high performance JTA transaction manager, a JMS environment capable of compiling C code (gcc, etc.). You’ll
provider, clustering, connection pooling, and a management probably also want OpenSSL, though this isn’t strictly required.
console. Once you’ve unpacked Resin, it should create a directory with
the full Resin version name (e.g. resin-pro-4.0.4). Change to
Resin is available in two flavors: Resin Open Source and
this directory and run the following commands:
Resin Professional. Resin Open Source is licensed under the
GPL and has all the features necessary for Java EE 6 Web $ ./configure
$ make
Profile development. Resin Professional builds on Resin Open $ sudo make install
Source and offers advanced features such as clustering (both
You’ll need to run the last command (make install) as root so
traditional and cloud), fast native I/O, proxy caching, and
www.dzone.com
you can install Resin system wide. By default, this installs Resin
OpenSSL integration.
in /usr/local/resin-<version>, but you can change this behavior
by passing the --prefix= to the configure command. For more
DOWNLOADING RESIN options, pass -- help to the configure command.
Web App Deploy Contains applications (.war files webapps/ (Subdirectory of root
Directory and exploded applications) directory)
Log Directory Contains server and access log files log/ (Subdirectory of root directory)
STARTING RESIN
Similarly, you can have Resin open a JMX port using the –jmx- Configuring the Resin Server
port option: Resin’s server configuration is XML-based and contained largely
$ java -jar $RESIN_HOME/lib/resin.jar -jmx-port 9000 console within one file called resin.xml. The default resin.xml should
work fine for most users with single-server deployments or
To have Resin run in the background with its log output placed
developers. For more advanced configurations however, you’ll
in the log directory, run:
want to understand and modify the resin.xml file.
$ java -jar $RESIN_HOME/lib/resin.jar start
Structure of resin.xml
You may also want to set the root directory of Resin and a The XML structure of the resin.xml file models the organization
specific configuration file on the command line as well: of Resin. At the top level there is the full Resin deployment,
For more Maven options, see http://wiki.caucho.com/Maven2 Resin includes its own powerful HTTP server which features
For the related Ant plugin, see http://wiki.caucho.com/Ant comparable performance to C-based servers such as Apache
or nginx without the overhead of requiring multiple processes.
CONNECTING DATABASES Using the Resin HTTP server is recommended. In addition to
its solid performance, the Resin HTTP server also has a number
Resin features a built-in database pool which allows multiple
of convenient features for configuring SSL, rewriting requests,
database servers, load balancing, and connection checking.
and managing virtual hosts.
Resin’s database pools are integrated with Resin’s CanDI (CDI
implementation) so that developers can use annotations to OpenSSL
inject the database easily into their code. One of Resin Professional’s most useful features is OpenSSL
integration which offers far faster SSL performance than pure
The following code shows a sample database pool Java solutions. To configure OpenSSL, add an <http> tag with
configuration that you might include in your resin-web.xml for a an <openssl> tag to your server configuration:
pool of up to 150 simultaneous connections:
<resin xmlns=”http://caucho.com/ns/resin”
xmlns:resin=”urn:java:com.caucho.resin”>
<web-app xmlns=”http://caucho.com/ns/resin”>
<cluster id=”app-tier”>
<database jndi-name=”jdbc/myDb”>
<server id=”” address=”192.168.0.10” port=”6800”>
<driver type=”org.postgresql.Driver”>
<http port=”443”>
<url>jdbc:postgresql://localhost/test</url>
<openssl>
<user>myUser</user>
<certificate-file>example.crt</certificate-file>
<password>myPassword</password>
<certificate-key-file>example.key</certificate-key-file>
</driver>
<password>my-password</password>
<max-connections>150</max-connections>
</openssl>
</database>
</http>
</web-app>
</server>
</cluster>
Once you’ve configured the pool in your resin-web.xml, you …
</resin>
can either use JNDI to access the DataSource or use CDI
annotations as in the following class: Rewrite Dispatch
public class MyBusinessLogic { Resin offers a URL rewriting mechanism similar to Apache’s
@javax.inject.Inject mod_rewrite in its HTTP server. Rules for rewriting URLs can be
DataSource myDatabase;
… configured on an application, host, server, or cluster level. For
}
example, you may want to allow all requests for specific static
resources (such as images, CSS, JavaScript, etc.) to be served
LOGGING as usual, but redirect all other requests to a central controller
Servlet. You could achieve that within your resin-web.xml with
Resin uses standard java.util.logging facilities for all its the following configuration:
internal logging and implements several custom log handlers <web-app xmlns=”http://caucho.com/ns/resin”
to manage log output and log rotation. The default logging xmlns:resin=”urn:java:com.caucho.resin”>
<resin:Dispatch regexp=”\.(php|js|gif|png|css|html)$”/>
configuration in the resin.xml file provides INFO-level logging <resin:Dispatch regexp=”^” target=”/controller”/>
</web-app>
for all Resin output. The XML for this configuration is:
<log-handler name=”” level=”all” path=”stdout:”
The <resin:Dispatch> tag here is an internal redirection (i.e. the
timestamp=”[%y-%m-%d %H:%M:%S.%s] {%{thread}} “/> request is passed within the server without an HTTP redirect).
<logger name=”com.caucho” level=”info”/>
You can use tags for HTTP forwarding, FastCGI integration,
You can configure additional loggers for your classes simply load balancing, and more:
by adding another <logger> tag either to resin.xml or your Tag Behavior
application’s resin-web.xml. The default log-handler will <resin:Dispatch> Redirect a request internally
output all log messages to the log directory (or standard <resin:Redirect> Send an HTTP redirect
output, if running in console mode). You can also configure
<resin:Forbidden> Send an HTTP forbidden response
additional log-handlers to deal specifically with your classes’
<resin:Forward> Send an HTTP forward
log messages. For example, if all of your packages started with
<resin:FastCgiProxy> Redirect requests to a backend FastCGI process
“com.example”, you could configure a logger and log-handler:
<resin:HttpProxy> Redirect requests to a backend HTTP service As an example, you may want to allow all accesses to an “/
<resin:LoadBalance> Redirect the request to a backend cluster for processing
admin” application only if the user is in the proper “admin” role:
<web-app xmlns=”http://caucho.com/ns/resin”
Virtual Hosts xmlns:resin=”urn:java:com.caucho.resin”>
<resin:Forbidden regexp=”^/admin”>
For many deployments, you may not need to use specialized <resin:Not>
virtual hosts (e.g. you only use example.com and www.example. <resin:IfUserInRole role=”admin”/>
</resin:Not>
com). In these cases, you can deploy to the standard web </resin:Forbidden>
app deploy directory and Resin will serve all your applications <resin:Dispatch regexp=”^/admin”>
regardless of the virtual host specified by the client. <resin:IfUserInRole role=”admin”/>
<resin:AddHeader name=”Cache-Control” value=”no-cache”/>
</resin:Dispatch>
If you have a deployment with more virtual hosts however </web-app>
(store.example.com, blog.example.com, etc.), you’ll need to
organize your applications in the appropriate virtual hosts. Notice that we also changed the caching behavior of the
Virtual hosts are a native concept to Resin and you can create response to indicate that browsers should not cache this
them two different ways: secure content.
• Use Resin’s host deploy directory
• Create an explicit host with the <host> tag in resin.xml DEVELOPING WITH RESIN
The host deploy directory allows you to create a directory
structure such as: Eclipse Integration
Resin features a development plugin for Eclipse based on the
/var/www/hosts/store.example.com/webapps
WTP framework. With this plugin, developers have all of the
Then any applications deployed in this webapps directory will facilities of the WTP environment with the ability to deploy to
be served from Resin as store.example.com. Resin using a variety of file system and remote deployment
options.
You may prefer to use an explicit <host> tag in your resin.xml.
This approach allows you to create a custom directory structure
and make your hosts explicit in configuration.
SECURITY
In this case, you would run this command from the machine
CLUSTERING RESIN with the network interface assigned the IP 192.168.0.10, as per
the configuration above.
Resin provides clustering capabilities for both traditional
clusters and cloud deployments. This functionality includes: Load Balancing
• Smart load balancing Once you’ve got a backend cluster set up as we did above,
• Distributed session replication you’ll probably want to add load balancing. In the same
• Distributed object caching resin.xml as the app-tier cluster, add the following cluster
• Dynamic server addition and removal
configuration for a web-tier:
• Distributed application deployment
<resin xmlns=”http://caucho.com/ns/resin”
To get started with Resin clustering, you can add <server> xmlns:resin=”urn:java:com.caucho.resin”>
configurations to a <cluster>: <cluster id=”app-tier”>
…
</cluster>
<resin xmlns=”http://caucho.com/ns/resin”
xmlns:resin=”urn:java:com.caucho.resin”> <cluster id=”web-tier” root-directory=”web-tier”>
<cluster id=”app-tier”> <server id=”web-a” address=”123.45.67.89” port=”6800”>
<server id=”app-a” address=”192.168.0.10” port=”6800”/> <http address=”*” port=”80”/>
<server id=”app-b” address=”192.168.0.11” port=”6800”/> </server>
...
</cluster> <host id=””>
<web-app id=”/”>
<resin:LoadBalance regexp=”” cluster=”app-tier”/>
The default resin.xml file has distributed sessions already </web-app>
enabled, so by adding these servers you’ve already got a </host>
</cluster>
cluster that can share data. </resin>
The start up procedure for Resin changes a bit when you have This configures a third Resin instance that will load balance
a cluster. When you have multiple servers configured in your requests from the outside world back to the app-tier servers.
resin.xml, you need to specify which of the servers you will use: Because the <resin:LoadBalance> tag is part of the Rewrite
Dispatch architecture, you can route load balanced requests
$ java -jar $RESIN_HOME/lib/resin.jar -server app-a start
with custom dispatch rules.
#82
CONTENTS INCLUDE:
■
About Cloud Computing
Usage Scenarios Getting Started with
n
Aldo
■
Cloud#64Computing
■
Underlying Concepts
Cost
by...
■
Upcoming Refcardz
youTechnologies ®
Data
■
t toTier
brough Comply.
borate.
Platform Management and more...
■
Chan
ge. Colla By Daniel Rubio
tion:
dz. com
tegra ternvasll
ABOUT CLOUD COMPUTING one time events. TEN TS
INC ■
HTML LUD E:
us Ind Anti-PPaat
Basics
Automated growthHTM
ref car
nuorn
■
Valid
ation one time events, cloud ML
connected to what is now deemed the ‘cloud’. Having the capability to support
ul M.
computing platforms alsoulfacilitate
4 Open the gradual growth curves
n an
Page Source
o
■
s
Vis it
C
faced by web applications. Tools
Core
By Key ■
Elem
atte
has changed substantially in recent years, especially with Structur
E: al Elem ents
INC LUD gration
NTS
P the entrance of service providers like Amazon, Google and Large scale growth scenarios involvingents
specialized
and mor equipment
rdz !
HTML
CO NTE Microsoft. es e... away by
(e.g. load balancers and clusters) are all but abstracted
Continu at Every e chang
m
About ns to isolat
relying on a cloud computing platform’s technology.
Software i-patter
space
Adobe Catalyst
rdz .co
■
n
Re fca
e Work
Build
riptio
and Ant These companies
Desc have a Privat
are in long deployed trol repos
itory web applicationsge HTM
L BAS
■
to mana
Patterns Control
■
that adaptDeve
lop softw
and scale to
n-con
large user
a versio bases,ng and making them In addition, several cloud computing ICSplatforms support data
les to ize mergi
ment
rn
Version e... Patte it all fi minim le
tier technologiesHTM
Manage s and mor e Work knowledgeable in amany
ine to
mainl aspects related tos multip
cloud computing. that Lexceed the precedent set by Relational
space Comm and XHT
■
ref ca
Build
re
OUS
Flash Builder 4
chang
ding code Level
as the desc
the ima alt attribute ribes whe
www.dzone.com
a Task
ive data pt. Server-s
ce
NTINU of buil tr what it is a cloud computing es as platform can offer your ut web output e in clien ment.
T CO cess ion con it chang e witho likew ide lang t-sid e ge is describe re the ima
ise use mec hanism. fromAND
e name CLOUD COMPUTING PLATFORMS
the pro ject’s vers applications. and subm sourc
ABOU (CI) is
with uniqu are from web
The eme pages and uages like Nested
unavaila s alte ge file
rd z!
Maven 3
reposit ed via particul tions that e Pay only what you consume
tagge or Amazon’s cloud you cho platform
computing
the curr isome
heavily basedmoron fine. b></ ed insid
anti e imp a></
For each (e.g. WAR
ent stan ose to writ
lain the t
es more e
not lega each othe
and x” solu b> is
be exp text) to “fi duc Web application deployment ge until
nden a few years
t librari agonmen was similar app ortant,
ns are to pro packa t enviro industry standard
that will softwaredardand virtualization
e HTM technology.
Mo re
DZone, Inc.
ISBN-13: 978-1-934238-68-4
140 Preston Executive Dr. ISBN-10: 1-934238-68-6
Suite 100
50795
Cary, NC 27513