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
}
