Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Web components are web applications (WARs) with additional SCA artifacts that allow Servlets and JSPs to be wired to services in a domain.

To define a web component, create a WAR contribution with a composite that has an implementation.web component defined in itWeb components do not need to be explicitly defined - a WAR is sufficient for Fabric3 to deploy it as a web app. However, if you need to specify configuration such as the URL path, you must create a composite with an implementation.web:

Code Block
xml
xml
<component name="calculator">
   <implementation.web/>

  <reference name="calculatorService" target="CalculatorService"/>
 </component>

WAR contribution composites are typically placed under /WEB-INF although the may be located anywhere in the contribution archive. When deployed, the web application context for the above component will be <runtime ip>:<port>/calcultorcalculator.

In the previous example, a reference to the CalculatorService was made available to the web application for injection onto servlets and JSPs. To inject the reference on a Servlet, use the @Reference annotation:

Code Block
java
java
public class CalculatorServlet extends HttpServlet {

   @Reference
   protected CalculatorService calculatorService;

   protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      // ...
   }
}
Info

Note that references configured on a web component are available to all artifacts in the web application. A reference defined in the composite may be injected into multiple Servlets and JSPS.

About componentType and web applications

SCA defines a concept of a componentType, which is metadata about a component implementation, e.g. its references, services, etc. This metadata is abstract in the sense that it has a uniform aspect across implementations types such as Java, BPEL, C++, a web component, etc. The componentType is then configured by a <component> entry in a composite. For example, its references are wired, properties set, and services bound.

When a contribution is installed, Fabric3 scans the implementations and calculates the componentTypes for all implementations. In Java, it does this by introspecting annotations on Java classes. The web implementations works a bit differently. When a web contribution is installed, Servlet and Filter classes specified in web.xml are scanned for annotations such as @Reference and added to the componentType. In case of eg. Spring MVC @Controllers (and others such as JSPs, Wicket or Vaadin components etc that access references), there are no known annotations to scan. For these cases, a specific web.componentType side-file in WEB-INF needs to be created. It should look like this:

...

<?xml version="1.0" encoding="UTF-8"?>
<componentType xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912">
	<reference name="calculatorService">
		<interface.java
			interface="org.fabric3.samples.web.calculator.CalculatorService" />
	</reference>
</componentType>
Note

There is a JIRA issue created about expanding the annotation scanning to classes other than just Servlet and Filter.

Alternative Methods for Accessing Services

Services can also be accessed from a web application by looking them up in the Servlet context or by using the SCA taglib. Due to threading constrains, stateless services are accessed differently than conversational services. We discuss those differences in the next two sections.

Accessing Stateless and Composite Scoped Services

Stateless services and services backed by composite-scoped components can be looked up by their reference name from the Servlet context. The following version of the CalculatorServlet uses the servlet context to obtain a reference to the CalculatorService:

...

public class CalculatorServlet extends HttpServlet {

   protected CalculatorService calculatorService;

   public void init(ServletConfig config) throws ServletException {
      super.init(config);
      servletContext = config.getServletContext();
      calculatorService = (CalculatorService) servletContext.getAttribute("calculatorService);
   }

   protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      // ...
   }
}

The SCA Tag Library

Fabric3 includes support for the OSOA-defined SCA TagLib. This taglib is separately downloaded from the Fabric3 web site and contains support for adding <reference> and <property> tags in JSPs.

 

Configuring the Web Context Path

The web context URL is calculated by using the component URI. For example, a web component named "WebComponent" will be available from http://<server address>/WebComponent. It is good practice to specify a relative context path that differs from the component name. To do this, use the implementation.web/@uri attribute:

...

In the above example, the web context URL will be http://<server address>/webapp

 

Info

Note that references configured on a web component are available to all artifacts in the web application. A reference defined in the composite may be injected into multiple Servlets and JSPS.

Integrating Web UI Frameworks

XXXXXXXX

Enabling Web Component Support

Web component support is enabled by installing the web profile in any of the Fabric3 runtimes.