Use SCA annotations with web modules
Use Java annotations for Service Component Architecture (SCA) to identify existing Java EE components, such as web modules, as SCA components that are a part of an SCA composite.
Identify and obtain the web module that represents your business logic to enable within an SCA environment.
The SCA programming model supports Java EE integration. As a result, we can take advantage of SCA annotations to enable Java EE web components such as servlets, filters, and event listeners to consume SCA services. By using Java annotations that apply to SCA, we can enable existing web modules to be recognized as an SCA component and participate in an SCA composite.
Web modules can participate in SCA assembly as the implementation type of a component that does not offer services, even though we can configure or wire the component to other services. We can configure a web module with annotations to acquire references to services that are wired to the component by the SCA assembly. We can also use annotations when to obtain the value of a property using the @Property annotation, to inject a handle to the SCA component context using the @Context annotation or to obtain the component name using the @ComponentName annotation. For a list of supported annotations for web modules, see the SCA specifications and APIs documentation.
We can also obtain SCA references in JSP (JSP) files by using SCA JSP tag libraries. The following example illustrates how annotations are used within a JSP tag handler:
<%@ taglib uri="http://www.osoa.org/sca/sca_jsp.tld" prefix="sca" %> <sca:reference name="service" type="test.MyService" /> <% service.sayHello(); %>
- Add SCA annotations to the components we want within a web module. Based on the needs, use the supported annotations to inject SCA information into the web module.
- Define a component in the application.composite file in the META-INF directory.
The implementation.web element is used to declare a service component that is implemented by the web component. The component contains information for the annotations. To configure this component implementation, use the following schema:
<implementation.web web-uri="<module name>"/>
For example, we can define a component in the EAR META-INF/application.composite file as follows:
<component name="WebAnnotationTestServletComponent"> <implementation.web web-uri="SCA_JEE_InjectionWeb.war"/> <reference name="getServerDateReference" target="GetServerDateServiceComponent"> <interface.java interface="sca.injection.test.GetServerDateService"/> </reference> </component>The following example illustrates a servlet in the WAR module using SCA annotations:
public class WebAnnotationTestServlet extends HttpServlet { @Reference GetServerDateService getServerDateReference; }The following example illustrates a JSP using SCA annotations by importing the SCA tag library:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ taglib uri="http://www.osoa.org/sca/sca_jsp.tld" prefix="sca" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN " "http://www.w3.org/TR/html4/loose.dtd"> <sca:reference name="getServerDateReference" type="sca.injection.test.GetServerDateService" /> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>TESTING SCA ANNOTATION IN JSP</title> </head> <body> <h2> Reference Annotation in JSP: </h2> GetServerDateService.getString returns : <%=getServerDateReference.getString() %> </body> </html>
Results
You now have SCA-enabled Java EE web modules that take advantage of the SCA programming model.
What to do next
Deploy the components to a business-level application.
Related concepts
Ways to install enterprise applications or modules
Related tasks
Create SCA business-level applications Start business-level applications Use existing Java EE modules and components as SCA implementations
SCA annotations Service Component Architecture specifications and APIs