Running liferay behind Apache2 mod_jk and Tomcat6 on Debian

September 14, 2009 · Leave a Comment
Filed under: CMS, Featured, Hibernate, JAVA, JSP, LifeRay 

I cant figure out what i need to do to configure apache2 to talk to tomcat on my Debian linux environment. I have liferay running on Tomcat which i can access via the following URL

1
2http://192.168.0.2:8080/web/guest

I am trying to configure Apache2 using mod_jk to allow me to access liferay using something like http://192.168.0.2/liferay but everything i do just returns the following error

1
2The requested URL /liferay was not found on this server.
3Apache/2.2.9 (Debian) mod_jk/1.2.26 PHP/5.2.6-1+lenny3 with Suhosin-Patch Server at 192.168.0.2 Port 80

Here is my configuration

workers.properties

1
2workers.java_home=/data/resourceRepository/external/bin/SDK/jdk
3ps=/
4worker.list=default
5worker.default.port=8009
6worker.default.host=localhost
7worker.default.type=ajp13
8worker.default.lbfactor=1

/etc/apache2/sites-available/liferay

1
2hpmedia:/etc/apache2/sites-available# cat liferay
3<VirtualHost *:80>
4 ServerAdmin webmaster@localhost
5 JkMount /liferay default
6 DirectoryIndex index.php index.html
7
8 ErrorLog /var/log/apache2/error.log
9
10 # Possible values include: debug, info, notice, warn, error, crit,
11 # alert, emerg.
12 LogLevel warn
13
14</VirtualHost>
15hpmedia:/etc/apache2/sites-available#

There is a symbolik link in sites-enabled that points to the above file.

changes to /etc/apache2/apache2.conf

1
2JkWorkersFile /data/resourceRepository/internal/workarea/liferay/liferay_home/apache-tomcat-6.0.20/conf/workers.properties
3
4JkLogFile /data/resourceRepository/internal/workarea/liferay/liferay_home/apache-tomcat-6.0.20/logs/jk.log
5
6JkLogLevel info
7
8JkLogStampFormat “[%a %b %d %H:%M:%S %Y]”
9
10JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
11
12JkRequestLogFormat “%w %V %T”

/etc/apache2/mods-enabled/jk.load

1
2LoadModule jk_module /usr/lib/apache2/modules/mod_jk.so

My environment is as follows




Debian 5.2
Java5
Tomcat 6
Liferay 5.2.3
Apache2

Is there anything i am doing wrong in the above configuration?

here are my virtual hosts files in /etc/apache2/sites-enabled

1
2<VirtualHost *:80>
3 ServerAdmin webmaster@localhost
4
5 DocumentRoot /data/resourceRepository/internal/workarea/joomla/bravaonline
6 <Directory />
7 Options FollowSymLinks
8 AllowOverride None
9 </Directory>
10 <Directory /data/resourceRepository/internal/workarea/joomal/bravaonline/>
11 Options Indexes FollowSymLinks MultiViews
12 AllowOverride None
13 Order allow,deny
14 allow from all
15 </Directory>
16
17 ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
18 <Directory “/usr/lib/cgi-bin”>
19 AllowOverride None
20 Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
21 Order allow,deny
22 Allow from all
23 </Directory>
24
25 ErrorLog /var/log/apache2/error.log
26
27 # Possible values include: debug, info, notice, warn, error, crit,
28 # alert, emerg.
29 LogLevel warn
30
31 CustomLog /var/log/apache2/access.log combined
32
33 Alias /doc/ “/usr/share/doc/”
34 <Directory “/usr/share/doc/”>
35 Options Indexes MultiViews FollowSymLinks
36 AllowOverride None
37 Order deny,allow
38 Deny from all
39 Allow from 127.0.0.0/255.0.0.0 ::1/128
40 </Directory>
41</VirtualHost>

and the second one which i want to point to the tomcat installation is

1
2<VirtualHost www.brava1.com>
3 ServerAdmin webmaster@localhost
4 ServerName www.brava1.com
5 ServerAlias brava1.com
6
7 JkMount /lifer* default
8 DirectoryIndex index.php index.html
9
10 ErrorLog /var/log/apache2/error.log
11
12 # Possible values include: debug, info, notice, warn, error, crit,
13 # alert, emerg.
14 LogLevel warn
15
16</VirtualHost>

i changed it slightly to try and access it using http://www.brava1.com/liferay but i still get the same problem.

I setup a similar environment using these steps:
http://cmsclarity.com/node/6

Setting up Freemarker + Spring Portlet in Spring MVC – Spring

September 8, 2009 · Leave a Comment
Filed under: Featured, Hibernate, JAVA, JSP, MVC Frameworks, Springs 

I had been searching and searching and to no avail.
Can some one please show me how to set up spring portlet to use Freemarker instead of jsp/jstl in an spring mvc framework please??
Havent had much luck finding it on the web

well specifically want to know whats the portlet equivilant of this
<bean id=”urlMapping”>
<property name=”mappings”>
<value>
/twitter.html=TwitterController
/twitterLogin.html=TwitterController
/twitterUpdate.html=TwitterController
</value>
</property>
<property name=”order” value=”0″/>
</bean>

given that there is no SimpleUrlHandlerMapping in the web.portlet packages in spring.

Okay. That doesn’t have anything to do with JSP / FreeMarker. Just a straightforward “how does Spring MVC map portlet requests to controllers/views?” thing.

Are you using Spring 2.5 or an older version? Reason I ask is, the first choice is whether you are going to use the Annotation-based Controllers or the Interface-based Controllers. Mapping is quite different depending on these. If you are using 2.5, I highly recommend going with the Annotation-based controllers.

Other resources to look at to understand the major differences between servlet requests and portlet requests in Spring:

Chapter 16 of the reference manual:
http://static.springsource.org/sprin…e/portlet.html

The slides and sample code from a seminar I did earlier this year on Spring Portlet MVC:
http://www.ja-sig.org/wiki/x/CACDAQ

Configuring Apache2.2 mod_proxy_ajp with Tomcat

June 4, 2009 · Leave a Comment
Filed under: Featured, JSP, Linux, MySql, MySQL 5.1 

mod_proxy_ajp is an Apache module which can be used to forward a client HTTP request to an internal Tomcat application server using the AJP protocol.  In this example I have used JSPWki as the example application running on a Windows server with Apache2.2 and Tomcat 5.5

Advantages of mod_proxy_ajp rather:

  • You can gain a lot of flexibility (lot of the apache modules/features can be used especially “name-based virtual hosting”)
  • Practical for those who need to support Java applications along with PHP / Perl … (only one apache server is needed)
  • Certificates management is easier in apache configuration (this argument is a lot subjective)
  • It’s not Tomcat’s main objective to serve http static resources (not optimized for that)
  • Load balancing/cluster management is easier with an apache frontend

Tomcat configuration

We just have to create the AJP connector in the conf/server.xml file like that:

<Connector port="8009" enableLookups="false" redirectPort="8443" protocol="AJP/1.3" />

This line will enable AJP connections to the 8009 port of your tomcat server (localhost for example).

Apache2 configuration

One way (useful if this apache is a global front end) is to create a virtual host for this application.

  • ProxyPass and ProxyPassReverse are classic reverse proxy directives used to forward the stream to another location.
  • ajp://… is the AJP connector location (your tomcat’s server host/port)

# JSP Wiki DNS

<VirtualHost 10.1.1.170:80>

ServerName wiki.example.com

ServerAlias wiki

DocumentRoot “D:/Tomcat 5.5/webapps/JSPWiki/”

#DocumentRoot “D:/Apache2.2/htdocs/JSPWiki”

<Proxy *>

AddDefaultCharset Off

Order deny,allow

Allow from all

</Proxy>

ProxyPass / ajp://localhost:8009/

ProxyPassReverse / ajp://localhost:8009/

</VirtualHost>

The following entries were made in server.xml on the Tomcat App Server :

<Host name=”wiki.example.com” debug=”0″

appBase=”D:/Tomcat 5.5/webapps”

unpackWARs=”true” autoDeploy=”true”>

<Alias>wiki</Alias>

<Context path= “” docBase=”D:/Tomcat 5.5/webapps/JSPWiki” debug=”1″/>

<Valve className=”org.apache.catalina.valves.AccessLogValve”

directory=”logs” prefix=”home_access_log.” suffix=”.txt”

pattern=”common” resolveHosts=”false”/>

</Host>

Under JSPWiki/WEB-INF/jspwiki.properties the Base URL was modified as follows :

jspwiki.baseURL=http://wiki/JSPWiki/

Expression Language

June 29, 2008 · Leave a Comment
Filed under: Featured, JAVA, Java el, JSP 

Expression Language

A primary feature of JSP technology version 2.0 is its support for an expression language (EL). An expression language makes it possible to easily access application data stored in JavaBeans components. For example, the JSP expression language allows a page author to access a bean using simple syntax such as ${name} for a simple variable or ${name.foo.bar} for a nested property.

The test attribute of the following conditional tag is supplied with an EL expression that compares the number of items in the session-scoped bean named cart with 0:

<c:if test="${sessionScope.cart.numberOfItems > 0}"> 
  ...
</c:if> 

The JSP expression evaluator is responsible for handling EL expressions, which are enclosed by the ${ } characters and can include literals. Here’s an example:

<c:if test="${bean1.a < 3}" >
  ...
</c:if> 

Any value that does not begin with ${ is treated as a literal and is parsed to the expected type using the PropertyEditor for the type:

<c:if test="true" >
...
</c:if> 

Literal values that contain the ${ characters must be escaped as follows:

<mytags:example attr1="an expression is ${'${'}true}" /> 

Deactivating Expression Evaluation

Because the pattern that identifies EL expressions–${ }–was not reserved in the JSP specifications before JSP 2.0, there may be applications where such a pattern is intended to pass through verbatim. To prevent the pattern from being evaluated, you can deactivate EL evaluation.

To deactivate the evaluation of EL expressions, you specify the isELIgnored attribute of the page directive:

<%@ page isELIgnored ="true|false" %> 

The valid values of this attribute are true and false. If it is true, EL expressions are ignored when they appear in static text or tag attributes. If it is false, EL expressions are evaluated by the container.

The default value varies depending on the version of the web application deployment descriptor. The default mode for JSP pages delivered using a Servlet 2.3 or earlier descriptor is to ignore EL expressions; this provides backward compatibility. The default mode for JSP pages delivered with a Servlet 2.4 descriptor is to evaluate EL expressions; this automatically provides the default that most applications want. You can also deactivate EL expression evaluation for a group of JSP pages (see Deactivating EL Expression Evaluation).

Using Expressions

EL expressions can be used:

  • In static text
  • In any standard or custom tag attribute that can accept an expression

The value of an expression in static text is computed and inserted into the current output. If the static text appears in a tag body, note that an expression will not be evaluated if the body is declared to be tagdependent (see body-content Attribute).

There are three ways to set a tag attribute value:

  • With a single expression construct:

<some:tag value="${expr}"/>

The expression is evaluated and the result is coerced to the attribute’s expected type.

  • With one or more expressions separated or surrounded by text:

<some:tag value="some${expr}${expr}text${expr}"/>

The expressions are evaluated from left to right. Each expression is coerced to a String and then concatenated with any intervening text. The resulting String is then coerced to the attribute’s expected type.

  • With text only:

<some:tag value="sometext"/>

In this case, the attribute’s String value is coerced to the attribute’s expected type.

Expressions used to set attribute values are evaluated in the context of an expected type. If the result of the expression evaluation does not match the expected type exactly, a type conversion will be performed. For example, the expression ${1.2E4} provided as the value of an attribute of type float will result in the following conversion:

Float.valueOf("1.2E4").floatValue()  

See section JSP2.8 of the JSP 2.0 specification for the complete type conversion rules.

Variables

The web container evaluates a variable that appears in an expression by looking up its value according to the behavior of PageContext.findAttribute(String). For example, when evaluating the expression ${product}, the container will look for product in the page, request, session, and application scopes and will return its value. If product is not found, null is returned. A variable that matches one of the implicit objects described in Implicit Objects will return that implicit object instead of the variable’s value.

Properties of variables are accessed using the . operator and can be nested arbitrarily.

The JSP expression language unifies the treatment of the . and [] operators. expr-a.identifier-b is equivalent to expr-a["identifier-b"]; that is, the expression expr-b is used to construct a literal whose value is the identifier, and then the [] operator is used with that value.

To evaluate expr-a[expr-b], evaluate expr-a into value-a and evaluate expr-b into value-b. If either value-a or value-b is null, return null.

  • If value-a is a Map, return value-a.get(value-b). If !value-a.containsKey(value-b), then return null.
  • If value-a is a List or array, coerce value-b to int and re

    turn value-a.get(value-b) or Array.get(value-a, value-b), as appropriate. If the coercion couldn’t be performed, an error is returned. If the get call returns an IndexOutOfBoundsException, null is returned. If the get call returns another exception, an error is returned.

  • If value-a is a JavaBeans object, coerce value-b to String. If value-b is a readable property of value-a, then return the result of a get call. If the get method throws an exception, an error is returned.

Implicit Objects

The JSP expression language defines a set of implicit objects:

In addition, several implicit objects are available that allow easy access to the following objects:

  • param: Maps a request parameter name to a single value
  • paramValues: Maps a request parameter name to an array of values
  • header: Maps a request header name to a single value
  • headerValues: Maps a request header name to an array of values
  • cookie: Maps a cookie name to a single cookie
  • initParam: Maps a context initialization parameter name to a single value

Finally, there are objects that allow access to the various scoped variables described in Using Scope Objects.

  • pageScope: Maps page-scoped variable names to their values
  • requestScope: Maps request-scoped variable names to their values
  • sessionScope: Maps session-scoped variable names to their values
  • applicationScope: Maps application-scoped variable names to their values

When an expression references one of these objects by name, the appropriate object is returned instead of the corresponding attribute. For example, ${pageContext} returns the PageContext object, even if there is an existing pageContext attribute containing some other value.

Literals

The JSP expression language defines the following literals:

  • Boolean: true and false
  • Integer: as in Java
  • Floating point: as in Java
  • String: with single and double quotes; " is escaped as ", ‘ is escaped as ‘, and is escaped as \.
  • Null: null

Operators

In addition to the . and [] operators discussed in Variables, the JSP expression language provides the following operators:

  • Arithmetic: +, - (binary), *, / and div, % and mod, - (unary)
  • Logical: and, &&, or, ||, not, !
  • Relational: ==, eq, !=, ne, <, lt, >, gt, <=, ge, >=, le. Comparisons can be made against other values, or against boolean, string, integer, or floating point literals.
  • Empty: The empty operator is a prefix operation that can be used to determine whether a value is null or empty.
  • Conditional: A ? B : C. Evaluate B or C, depending on the result of the evaluation of A.

The precedence of operators highest to lowest, left to right is as follows:

  • [] .
  • () – Used to change the precedence of operators.
  • - (unary) not ! empty
  • * / div % mod
  • + - (binary)
  • < > <= >= lt gt le ge
  • == != eq ne
  • && and
  • || or
  • ? :

Reserved Words

The following words are reserved for the JSP expression language and should not be used as identifiers.

and   eq   gt   true   instanceof
or    ne   le   false  empty
not   lt   ge   null   div   mod 

Note that many of these words are not in the language now, but they may be in the future, so you should avoid using them.

Examples

Table 12-2 contains example EL expressions and the result of evaluating them.

Table 12-2 Example Expressions 

EL Expression

Result

${1 > (4/2)}

false

${4.0 >= 3}

true

${100.0 == 100}

true

${(10*10) ne 100}

false

${a < b}

true

${hip gt hit}

false

${4 > 3}

true

${1.2E4 + 1.4}

12001.4

${3 div 4}

0.75

${10 mod 4}

2

${empty param.Add}

True if the request parameter named Add is null or an empty string

${pageContext.request.contextPath}

The context path

${sessionScope.cart.numberOfItems}

The value of the numberOfItems property of the session-scoped attribute named cart

${param[mycom.productId]}

The value of the request parameter named mycom.productId

${header["host"]}

The host

${departments[deptName]}

The value of the entry named deptName in the departments map

${requestScope['javax.servlet.
forward.servlet_path']}

The value of the request-scoped attribute named javax.servlet.
forward.servlet_path

Functions

The JSP expression language allows you to define a function that can be invoked in an expression. Functions are defined using the same mechanisms as custom tags (See Using Custom Tags and Chapter 15).

Using Functions

Functions can appear in static text and tag attribute values.

To use a function in a JSP page, you use a taglib directive to import the tag library containing the function. Then you preface the function invocation with the prefix declared in the directive.

For example, the date example page index.jsp imports the /functions library and invokes the function equals in an expression:

<%@ taglib prefix="f" uri="/functions"%>
...
    <c:when
      test="${f:equals(selectedLocaleString,
        localeString)}" > 

Defining Functions

To define a function you program it as a public static method in a public class. The mypkg.MyLocales class in the date example defines a function that tests the equality of two Strings as follows:

package mypkg;
public class MyLocales {
 
  ...
  public static boolean equals( String l1, String l2 ) {
    return l1.equals(l2);
  }
} 

Then you map the function name as used in the EL expression to the defining class and function signature in a TLD. The following functions.tld file in the date example maps the equals function to the class containing the implementation of the function equals and the signature of the function:

<function>
  <name>equals</name>
<


span style='font-size:10pt;'>  <function-class>mypkg.MyLocales</function-class>
  <function-signature>boolean equals( java.lang.String,
    java.lang.String )</function-signature>
</function> 

A tag library can have only one function element that has any given name element.