Fabric3 supports wiring services to Servlets and JSPs in a web application by treating web applications as components. In this chapter, we cover how to implement a web component and wire it to other services in a domain.
See the Starter Applications for an example calculator web application.
Implementing Web Components
Web components are web applications (WARs) with additional SCA artifacts that allow Servlets and JSPs to be wired to services in a domain.
Web 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:
<component name="calculator"> <implementation.web/> </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>/calculator.
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:
public class CalculatorServlet extends HttpServlet { @Reference protected CalculatorService calculatorService; protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // ... } }
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:
<component name="WebComponent"> <implementation.web uri="webapp"/> </component>
In the above example, the web context URL will be http://<server address>/webapp
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.