Using SCA annotations with Web modules

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="http://www.osoa.org/sca/sca_jsp.tld" prefix="sca" %>
<sca:reference name="service" type="test.MyService"  />
<% service.sayHello(); %>

Procedure

  1. 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.
  2. 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="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.




In this information ...


Related reference

IBM Redbooks, demos, education, and more

(Index)

Use IBM Suggests to retrieve related content from ibm.com and beyond, identified for your convenience.

This feature requires Internet access.

Task topic Task topic    

Terms and conditions for information centers | Feedback

Last updatedLast updated: Jan 16, 2013 3:37:33 AM CST
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=v700osgijpa&product=was-nd-mp&topic=tsca_scaannotforwebmodules
File name: tsca_scaannotforwebmodules.html