To know how to specify multiple URL patterns for web context filter in JBoss Seam, in components.xml please visit http://jeenotes.blogspot.com/2008/12/how-to-specify-multiple-url-pattern-for.html
![]() |
09 Dec · Tue 2008
How to specify multiple URL pattern for Seam web:context-filter
27 Nov · Thu 2008
Deploy web application WAR or exploded at root (default) context in Tomcat 6 plus
To deploy a web application [in WAR or exploded format] with root context in Tomcat 6 plus, please follow the below steps.
You can delete the ROOT folder under TOMCAT_HOME/webapps.
Rename your WAR as ROOT.war and place it under webapps folder. If the deployment is in exploded format, assign ROOT as the name for the topmost parent folder.
This is the easiest way to deploy a web application in Tomcat with root context [aka default context].(Other ways involve specifying a Context in any one of the configuration files)
Note: If you dont like the name to be ROOT or ROOT.war, please edit TOMCAT_HOME/conf/server.xml to add the Context as below [assuming the application name is shoppingcart] within <HOST>
<Context path="" docBase="shoppingcart"/>
16 Nov · Sun 2008
WAR or EAR deployment versus exploded folder deployment
When should we go for an archive [war or ear] deployment rather than exploded folder deployment in production environment? Read more on this at http://javalegion.blogspot.com/2008/11/war-or-ear-deployment-versus-exploded.html
NetBeans code templates - expand shortcut auto completion
Learn how to use shortcut keys for auto completion for common code templates like try catch block or System.out.println http://javalegion.blogspot.com/2008/11/netbeans-code-templates-expand-shortcut.html
How to read values from properties file in JBoss Seam in your application
This link provides code snippets explaining how to read values from property files in JBoss Seam
http://javalegion.blogspot.com/2008/11/how-to-read-values-from-properties-file.html
How to find transitive dependency in Maven
Maven packs the transitive dependencies also into the archive files. We can exclude specific transitive dependencies by using <exclusions>
To list transitive dependencies that are packed into the archive file, there is maven-dependency-plugin.
Include the following under plugins and invoke any of the maven life cycle phase like mvn install dependency:tree
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
How to debug in Tomcat 6 plus and JBoss 4.2.x using NetBeans 6.5
To know how to debug in Tomcat the link is http://javalegion.blogspot.com/2008/11/debug-in-tomcat-6-plus-using-netbeans.html
To know how to debug in JBoss the link is http://javalegion.blogspot.com/2008/11/profiling-and-debugging-in-jboss-42x.html
Searching Files in Projects in NetBeans 6.1 plus
To search for files in projects in NetBeans 6.1 and 6.5, we can use Ctrl+O or Alt+Shift+O.
-Use Alt+Shift+O when we wish to search for any file type.
-Use Ctrl+O when we wish to search only Java files. This will provide us the result faster than when using Alt+Shift+O as only Java files are considered.
Maven Beginners please read how to solve Maven java.lang.OutOfMemoryError
This link explains how to solve Maven OutOfMemoryError in Windows.
http://javalegion.blogspot.com/2008/11/maven-javalangoutofmemoryerror.html
Silent mode installation of Java
The below content in a batch file will install JDK in D:\jdk1_6_10 without popping up any GUI. Useful to install without user interaction. The log will be written into setuplog.txt
echo off
start ./sdk/jdk-6u10-windows-i586-p.exe /s INSTALLDIR=D:\jdk1_6_10 /L ./setuplog.txt
How to add entries in MANIFEST.MF of WAR EAR and JAR in Maven
In war files, we can use maven-war-plugin as below. Build number and the computer name will be added along with the default entries.
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<archive>
<manifestEntries>
<Implementation-Build>${buildNumber}</Implementation-Build>
<Build-Machine>${env.COMPUTERNAME}</Build-Machine>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>
In EJB jar files we can use maven-ejb-plugin. For normal jars please use maven-jar-plugin in a similar fashion
<plugin>
<artifactId>maven-ejb-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
<manifestEntries>
<Implementation-Build>${buildNumber}</Implementation-Build>
<Build-Machine>${env.COMPUTERNAME}</Build-Machine>
</manifestEntries>
</archive>
</configuration>
</plugin>
03 Nov · Mon 2008
Seam 2.1.0 released
JBoss Seam 2.1.0 got released around November 23rd, 2008. The inline images in the email template were appearing as attachments in Outlook and Thunderbird and this issue has been fixed in Seam 2.1.0. Will test and post the result soon.
16 Oct · Thu 2008
Assigning a different name to Project Object Model in Maven other than pom.xml
In Maven 2.0 it is not mandatory that we always name the Project Object Model as pom.xml. We can assign a custom name say abc.xml and invoke it using the command mvn -f abc.xml package
Same applies for ANT. Instead of assigning the default name of build.xml, if the file name is def.xml, we can invoke using the command ant -f def.xml
Obtaining JBoss Seam component in CXF JAXWS implementor configured using Spring
This entry explains how to obtain a JBoss Seam component in a CXF JAXWS implementor configured using Spring.
Let us consider the example given in Developing Contract First webservice using CXF where we publish the endpoints using Spring configuration file cxf.xml
If we are using JBoss Seam as the application stack in our project we may want to inject Seam components into the implementation class which in the above example is EmpWorkHoursImpl.java. The easiest way to do it is as below.
Step 1: Configure a Filter in Seam's component.xml for the URL patterns
on which CXF Servlet ( org.apache.cxf.transport.servlet.CXFServlet) is
listening on by entering a line as below.
<web:context-filter url-pattern="/services/*" />Note: You would have noticed the CXF servlet having the URL mapping as below in the example under consideration
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
Step 2: Now in EmpWorkHoursImpl.java we can obtain a Seam component [say AddSeam.java] by following any one of the approach below.
Approach 1:
AddSeam addnum = (AddSeam)org.jboss.seam.Component.getInstance("addnum");
Approch 2:
AddSeam addnum=(AddSeam)org.jboss.seam.Component.getInstance(AddSeam.class);
AddSeam.java contains the following.
package com.ts.action;
import javax.persistence.EntityManager;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.faces.FacesMessages;
import org.jboss.seam.log.Log;
@Name("addnum")
public class AddSeam {
@In
private EntityManager em;
@In
private FacesMessages facesMessages;
@Logger
private Log log;
//Have your other methods and variables here
}
14 Oct · Tue 2008
Restricting Page access based on Role in JBoss Seam
This post shows how to restrict page access based on Role using pages.xml in JBoss Seam.
addquestion.xhtml is the UI to enable user to add questions [say in an exam]. If we are to allow only users having role as admin to access the page, we make the following entry in the pages.xml.
<page view-id="/addquestion.xhtml" login-required="true">
<restrict>#{s:hasRole('admin')}</restrict>
</page>
The role is set in the backing bean which authenticates and logs in the user as below. Here we have two roles admin and student. Only admin users are allowed to access the add question page. Admin and Student are the related JPA entity classes which maps to the related tables where admin credentials and student credentials are stored.
import com.ts.entity.Admin;
import com.ts.entity.Student;
import static org.jboss.seam.ScopeType.SESSION;
import java.util.List;
import javax.persistence.EntityManager;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.security.Identity;
@Name("authenticator")
public class AuthenticatorAction {
@In
EntityManager em;
@Out(required = false, scope = SESSION)
private Admin admin;
@Out(required = false, scope = SESSION)
private Student student;
@In
private Identity identity;
public boolean authenticate() {
List results = em.createQuery("select u from Admin u where u.username=#{identity.username} and u.password=#{identity.password}").getResultList();
if (results.size() != 0) {
admin = (Admin) results.get(0);
identity.addRole("admin");
return true;
}
results = em.createQuery("select u from Student u where u.username=#{identity.username} and u.password=#{identity.password}").getResultList();
if (results.size() != 0) {
student = (Student) results.get(0);
identity.addRole("student");
return true;
}
return false;
}
}
Important:
We must specify an exception in pages.xml as below. Else the AuthorizationException will be swallowed [though we can see the Exception on the log files and in server console] and the user will be allowed to access the page. That is without the below exception entry an user with role as student will be allowed to access add question page.
<exception class="org.jboss.seam.security.AuthorizationException">
<redirect view-id="/main.xhtml">
<message>You don't have permission to do this</message>
</redirect>
</exception>
