Use Java™ annotations
for Service Component Architecture (SCA) to identify existing Java
Platform, Enterprise Edition (Java EE) components, such as web modules,
as SCA components that are a part of an SCA composite.
Before you begin
Identify and obtain the web module that represents your
business logic that you want to enable within an SCA environment.
About this task
The SCA programming model supports Java EE integration.
As a result, you 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,
you 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 you can configure or wire the component
to other services. You can configure a web module with annotations
to acquire references to services that are wired to the component
by the SCA assembly. You can also use annotations when you want 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.
You can also obtain SCA references
in JavaServer
Pages (JSP) files by using SCA JSP tag libraries. The following
example illustrates how annotations are used within a JSP tag handler:
<%@ taglib uri="https://www.osoa.org/sca/sca_jsp.tld" prefix="sca" %>
<sca:reference name="service" type="test.MyService" />
<% service.sayHello(); %>
Procedure
- Add SCA annotations to the components that you want within
a web module.
Based on your needs, use the supported annotations
to inject SCA information into your 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, you 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 web application archive (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="https://www.osoa.org/sca/sca_jsp.tld" prefix="sca" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN
" "https://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.