You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by va...@apache.org on 2008/12/03 15:33:04 UTC

svn commit: r722903 - in /geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main: java/sample/HelloworldServletRequestListener.java webapp/WEB-INF/web.composite webapp/WEB-INF/web.xml webapp/hello.jsp

Author: vamsic007
Date: Wed Dec  3 06:33:02 2008
New Revision: 722903

URL: http://svn.apache.org/viewvc?rev=722903&view=rev
Log:
Added a ServletRequestListener.

Added:
    geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/java/sample/HelloworldServletRequestListener.java   (with props)
Modified:
    geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/webapp/WEB-INF/web.composite
    geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/webapp/WEB-INF/web.xml
    geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/webapp/hello.jsp

Added: geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/java/sample/HelloworldServletRequestListener.java
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/java/sample/HelloworldServletRequestListener.java?rev=722903&view=auto
==============================================================================
--- geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/java/sample/HelloworldServletRequestListener.java (added)
+++ geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/java/sample/HelloworldServletRequestListener.java Wed Dec  3 06:33:02 2008
@@ -0,0 +1,149 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package sample;
+
+import javax.servlet.ServletRequestEvent;
+import javax.servlet.ServletRequestListener;
+
+import org.osoa.sca.ComponentContext;
+import org.osoa.sca.annotations.ComponentName;
+import org.osoa.sca.annotations.Context;
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Reference;
+
+/**
+ * A ServletRequestListener that invokes SCA Helloworld services through injected references.
+ * 
+ * @version $Rev$ $Date$
+ */
+public class HelloworldServletRequestListener implements ServletRequestListener {
+    public static final String HELLO_TXT = "hellotxt";
+    @Reference
+    protected Helloworld rlservice;
+    
+    // Reference name specified in the annotation
+    @Reference(name="rlservice2")
+    protected Helloworld ser2;
+    
+    // Reference annotation on setter method
+    private Helloworld ser3;
+    @Reference
+    public void setRlservice3(Helloworld service3) {
+        this.ser3 = service3;
+    }
+    
+    /* Test for required */
+    @Reference(required=false)
+    protected Helloworld rlservice4;
+    
+    @Reference(required=false)
+    protected Helloworld rlservice5;
+    
+    @Reference(required=true)
+    protected Helloworld rlservice6;
+
+    @Property
+    protected String rlproperty1;
+    
+    // Property name specified in the annotation
+    @Property(name="rlproperty2")
+    protected int prop2;
+    
+    // Property annotation on setter method
+    private double prop3;
+    @Property
+    public void setRlproperty3(double property3) {
+        this.prop3 = property3;
+    }
+    
+    /* Test for required */
+    @Property(required=false)
+    protected String rlproperty4;
+
+    @Property(required=false)
+    protected String rlproperty5;
+
+    @Property(required=true)
+    protected String rlproperty6;
+    
+    @ComponentName
+    protected String scaComponentName;
+
+    // Annotation on setter method
+    private String scaComponentName1;
+    @ComponentName
+    public void setScaComponentName1(String scaComponentName1) {
+        this.scaComponentName1 = scaComponentName1;
+    }
+    
+    @Context
+    protected ComponentContext componentContext;
+
+    // Annotation on setter method
+    private ComponentContext componentContext1;
+    @Context
+    public void setCompContext(ComponentContext ctx) {
+        componentContext1 = ctx;
+    }
+
+    public void requestInitialized(ServletRequestEvent event) {
+        event.getServletRequest().setAttribute(HELLO_TXT, prepareMessage("James"));
+    }
+
+    public void requestDestroyed(ServletRequestEvent event) {
+    }
+
+    private String prepareMessage(String name) {
+        StringBuffer sb = new StringBuffer();
+        String greeting = rlservice.sayHello(name);
+        String greeting2 = ser2.sayHello(name);
+        String greeting3 = ser3.sayHello(name);
+        
+        sb.append("<h2>Apache Tuscany Helloworld ServletRequestListener</h2>");
+        sb.append("<h3>@Reference</h3>");
+        sb.append("<br>Injected into field. <br><strong>Result: </strong>" + greeting);
+        sb.append("<br><br>Injected into field with reference name specified in the annotation. <br><strong>Result: </strong>" + greeting2);
+        sb.append("<br><br>Injected using setter method. <br><strong>Result: </strong>" + greeting3);
+        sb.append("<br><br>Required is false. Reference is not specified. "+rlservice4);
+        sb.append("<br><br>Required is false. Reference is specified. "+rlservice5);
+        sb.append("<br><br>Required is true. Reference is specified. "+rlservice6);
+        sb.append("<hr>");
+        
+        sb.append("<h3>@Property</h3>");
+        sb.append("<br>Injected into field: property1 = "+rlproperty1);
+        sb.append("<br>Injected into field with property name specified in the annotation: property2 = "+prop2);
+        sb.append("<br>Injected using setter method: Property3 = "+prop3);
+        sb.append("<br>Required is false. Property is not specified. "+rlproperty4);
+        sb.append("<br>Required is false. Property is specified. "+rlproperty5);
+        sb.append("<br>Required is true. Property is specified. "+rlproperty6);
+        sb.append("<hr>");
+        
+        sb.append("<h3>@ComponentName</h3>");
+        sb.append("<br>Injected into annotated field: "+scaComponentName);
+        sb.append("<br>Injected using annotated method: "+scaComponentName1);
+        sb.append("<hr>");
+
+        sb.append("<h3>@Context</h3>");
+        sb.append("<br>Injected into annotated field: "+componentContext);
+        sb.append("<br>Injected using annotated method: "+componentContext1);
+        sb.append("<hr>");
+
+        return sb.toString();
+    }
+}

Propchange: geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/java/sample/HelloworldServletRequestListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/java/sample/HelloworldServletRequestListener.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/java/sample/HelloworldServletRequestListener.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/webapp/WEB-INF/web.composite
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/webapp/WEB-INF/web.composite?rev=722903&r1=722902&r2=722903&view=diff
==============================================================================
--- geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/webapp/WEB-INF/web.composite (original)
+++ geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/webapp/WEB-INF/web.composite Wed Dec  3 06:33:02 2008
@@ -54,5 +54,19 @@
         <!-- <property name="calproperty4" type="xsd:string">CalProp4</property> -->
         <property name="calproperty5" type="xsd:string">CalProp5</property>
         <property name="calproperty6" type="xsd:string">CalProp6</property>
+
+        <reference name="rlservice" target="HelloworldComponent"/>
+        <reference name="rlservice2" target="HelloworldTeluguComponent"/>
+        <reference name="Rlservice3" target="HelloworldFrenchComponent"/>
+        <!-- <reference name="rlservice4" target="HelloworldComponent"/> -->
+        <reference name="rlservice5" target="HelloworldComponent"/>
+        <reference name="rlservice6" target="HelloworldComponent"/>
+        
+        <property name="rlproperty1" type="xsd:string">RlProp1</property>
+        <property name="rlproperty2" type="xsd:int">700</property>
+        <property name="Rlproperty3" type="xsd:double">0.007</property>
+        <!-- <property name="rlproperty4" type="xsd:string">RlProp4</property> -->
+        <property name="rlproperty5" type="xsd:string">RlProp5</property>
+        <property name="rlproperty6" type="xsd:string">RlProp6</property>
     </component>
 </composite>

Modified: geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/webapp/WEB-INF/web.xml?rev=722903&r1=722902&r2=722903&view=diff
==============================================================================
--- geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/webapp/WEB-INF/web.xml (original)
+++ geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/webapp/WEB-INF/web.xml Wed Dec  3 06:33:02 2008
@@ -32,6 +32,9 @@
   <listener>
       <listener-class>sample.HelloworldServletContextAttributeListener</listener-class>
   </listener>
+  <listener>
+      <listener-class>sample.HelloworldServletRequestListener</listener-class>
+  </listener>
 
   <welcome-file-list id="WelcomeFileList">
     <welcome-file>hello.jsp</welcome-file>

Modified: geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/webapp/hello.jsp
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/webapp/hello.jsp?rev=722903&r1=722902&r2=722903&view=diff
==============================================================================
--- geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/webapp/hello.jsp (original)
+++ geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/webapp/hello.jsp Wed Dec  3 06:33:02 2008
@@ -21,11 +21,14 @@
 
 <%@ page contentType="text/html;charset=UTF-8" language="java" %>
 <%@ page import="sample.HelloworldServletContextListener"%>
+<%@ page import="sample.HelloworldServletRequestListener"%>
 <html>
   <head><title>Helloworld Event Listener sample</title></head>
   <body>
     <h1>Helloworld Event Listener sample</h1>
 
     <%=getServletContext().getAttribute(HelloworldServletContextListener.HELLO_TXT)%>
+
+    <%=request.getAttribute(HelloworldServletRequestListener.HELLO_TXT) %>
   </body>
 </html>