geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vamsic...@apache.org
Subject svn commit: r723015 - in /geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main: java/sample/ webapp/ webapp/WEB-INF/
Date Wed, 03 Dec 2008 19:05:57 GMT
Author: vamsic007
Date: Wed Dec  3 11:05:57 2008
New Revision: 723015

URL: http://svn.apache.org/viewvc?rev=723015&view=rev
Log:
Added an HttpSessionListener and an HttpSessionAttributeListener.

Added:
    geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/java/sample/HelloworldHttpSessionAttributeListener.java
  (with props)
    geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/java/sample/HelloworldHttpSessionListener.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/HelloworldHttpSessionAttributeListener.java
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/java/sample/HelloworldHttpSessionAttributeListener.java?rev=723015&view=auto
==============================================================================
--- geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/java/sample/HelloworldHttpSessionAttributeListener.java
(added)
+++ geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/java/sample/HelloworldHttpSessionAttributeListener.java
Wed Dec  3 11:05:57 2008
@@ -0,0 +1,153 @@
+/*
+ * 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.http.HttpSessionAttributeListener;
+import javax.servlet.http.HttpSessionBindingEvent;
+
+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 HttpSessionAttributeListener that invokes SCA Helloworld services through injected references.
+ * 
+ * @version $Rev$ $Date$
+ */
+public class HelloworldHttpSessionAttributeListener implements HttpSessionAttributeListener
{
+    @Reference
+    protected Helloworld hsalservice;
+    
+    // Reference name specified in the annotation
+    @Reference(name="hsalservice2")
+    protected Helloworld ser2;
+    
+    // Reference annotation on setter method
+    private Helloworld ser3;
+    @Reference
+    public void setHsalservice3(Helloworld service3) {
+        this.ser3 = service3;
+    }
+    
+    /* Test for required */
+    @Reference(required=false)
+    protected Helloworld hsalservice4;
+    
+    @Reference(required=false)
+    protected Helloworld hsalservice5;
+    
+    @Reference(required=true)
+    protected Helloworld hsalservice6;
+
+    @Property
+    protected String hsalproperty1;
+    
+    // Property name specified in the annotation
+    @Property(name="hsalproperty2")
+    protected int prop2;
+    
+    // Property annotation on setter method
+    private double prop3;
+    @Property
+    public void setHsalproperty3(double property3) {
+        this.prop3 = property3;
+    }
+    
+    /* Test for required */
+    @Property(required=false)
+    protected String hsalproperty4;
+
+    @Property(required=false)
+    protected String hsalproperty5;
+
+    @Property(required=true)
+    protected String hsalproperty6;
+    
+    @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 attributeAdded(HttpSessionBindingEvent event) {
+        if(event.getName().equals(HelloworldHttpSessionListener.HELLO_TXT)) {
+            event.getSession().setAttribute(event.getName(), event.getValue()+prepareMessage("Jones"));
+        }
+    }
+
+    public void attributeRemoved(HttpSessionBindingEvent event) {
+    }
+
+    public void attributeReplaced(HttpSessionBindingEvent event) {
+    }
+
+    private String prepareMessage(String name) {
+        StringBuffer sb = new StringBuffer();
+        String greeting = hsalservice.sayHello(name);
+        String greeting2 = ser2.sayHello(name);
+        String greeting3 = ser3.sayHello(name);
+        
+        sb.append("<h2>Apache Tuscany Helloworld HttpSessionAttributeListener</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. "+hsalservice4);
+        sb.append("<br><br>Required is false. Reference is specified. "+hsalservice5);
+        sb.append("<br><br>Required is true. Reference is specified. "+hsalservice6);
+        sb.append("<hr>");
+        
+        sb.append("<h3>@Property</h3>");
+        sb.append("<br>Injected into field: property1 = "+hsalproperty1);
+        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. "+hsalproperty4);
+        sb.append("<br>Required is false. Property is specified. "+hsalproperty5);
+        sb.append("<br>Required is true. Property is specified. "+hsalproperty6);
+        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/HelloworldHttpSessionAttributeListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

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

Added: geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/java/sample/HelloworldHttpSessionListener.java
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/java/sample/HelloworldHttpSessionListener.java?rev=723015&view=auto
==============================================================================
--- geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/java/sample/HelloworldHttpSessionListener.java
(added)
+++ geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/java/sample/HelloworldHttpSessionListener.java
Wed Dec  3 11:05:57 2008
@@ -0,0 +1,151 @@
+/*
+ * 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.http.HttpSessionEvent;
+import javax.servlet.http.HttpSessionListener;
+
+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 HttpSessionListener that invokes SCA Helloworld services through injected references
and sets a "hellotxt"
+ * attribute in the session.
+ * 
+ * @version $Rev$ $Date$
+ */
+public class HelloworldHttpSessionListener implements HttpSessionListener {
+    public static final String HELLO_TXT = "hellotxt";
+
+    @Reference
+    protected Helloworld hslservice;
+    
+    // Reference name specified in the annotation
+    @Reference(name="hslservice2")
+    protected Helloworld ser2;
+    
+    // Reference annotation on setter method
+    private Helloworld ser3;
+    @Reference
+    public void setHslservice3(Helloworld service3) {
+        this.ser3 = service3;
+    }
+    
+    /* Test for required */
+    @Reference(required=false)
+    protected Helloworld hslservice4;
+    
+    @Reference(required=false)
+    protected Helloworld hslservice5;
+    
+    @Reference(required=true)
+    protected Helloworld hslservice6;
+
+    @Property
+    protected String hslproperty1;
+    
+    // Property name specified in the annotation
+    @Property(name="hslproperty2")
+    protected int prop2;
+    
+    // Property annotation on setter method
+    private double prop3;
+    @Property
+    public void setHslproperty3(double property3) {
+        this.prop3 = property3;
+    }
+    
+    /* Test for required */
+    @Property(required=false)
+    protected String hslproperty4;
+
+    @Property(required=false)
+    protected String hslproperty5;
+
+    @Property(required=true)
+    protected String hslproperty6;
+    
+    @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 sessionCreated(HttpSessionEvent event) {
+        event.getSession().setAttribute(HELLO_TXT, prepareMessage("Indiana"));
+    }
+
+    public void sessionDestroyed(HttpSessionEvent event) {
+    }
+
+    private String prepareMessage(String name) {
+        StringBuffer sb = new StringBuffer();
+        String greeting = hslservice.sayHello(name);
+        String greeting2 = ser2.sayHello(name);
+        String greeting3 = ser3.sayHello(name);
+        
+        sb.append("<h2>Apache Tuscany Helloworld HttpSessionListener</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. "+hslservice4);
+        sb.append("<br><br>Required is false. Reference is specified. "+hslservice5);
+        sb.append("<br><br>Required is true. Reference is specified. "+hslservice6);
+        sb.append("<hr>");
+        
+        sb.append("<h3>@Property</h3>");
+        sb.append("<br>Injected into field: property1 = "+hslproperty1);
+        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. "+hslproperty4);
+        sb.append("<br>Required is false. Property is specified. "+hslproperty5);
+        sb.append("<br>Required is true. Property is specified. "+hslproperty6);
+        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/HelloworldHttpSessionListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Propchange: geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/java/sample/HelloworldHttpSessionListener.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=723015&r1=723014&r2=723015&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 11:05:57 2008
@@ -82,5 +82,33 @@
         <!-- <property name="rlproperty4" type="xsd:string">RalProp4</property>
-->
         <property name="ralproperty5" type="xsd:string">RalProp5</property>
         <property name="ralproperty6" type="xsd:string">RalProp6</property>
+
+        <reference name="hslservice" target="HelloworldComponent"/>
+        <reference name="hslservice2" target="HelloworldTeluguComponent"/>
+        <reference name="Hslservice3" target="HelloworldFrenchComponent"/>
+        <!-- <reference name="hslservice4" target="HelloworldComponent"/> -->
+        <reference name="hslservice5" target="HelloworldComponent"/>
+        <reference name="hslservice6" target="HelloworldComponent"/>
+        
+        <property name="hslproperty1" type="xsd:string">HslProp1</property>
+        <property name="hslproperty2" type="xsd:int">700</property>
+        <property name="Hslproperty3" type="xsd:double">0.007</property>
+        <!-- <property name="hslproperty4" type="xsd:string">HslProp4</property>
-->
+        <property name="hslproperty5" type="xsd:string">HslProp5</property>
+        <property name="hslproperty6" type="xsd:string">HslProp6</property>
+
+        <reference name="hsalservice" target="HelloworldComponent"/>
+        <reference name="hsalservice2" target="HelloworldTeluguComponent"/>
+        <reference name="Hsalservice3" target="HelloworldFrenchComponent"/>
+        <!-- <reference name="hsalservice4" target="HelloworldComponent"/> -->
+        <reference name="hsalservice5" target="HelloworldComponent"/>
+        <reference name="hsalservice6" target="HelloworldComponent"/>
+        
+        <property name="hsalproperty1" type="xsd:string">HsalProp1</property>
+        <property name="hsalproperty2" type="xsd:int">700</property>
+        <property name="Hsalproperty3" type="xsd:double">0.007</property>
+        <!-- <property name="hsalproperty4" type="xsd:string">HsalProp4</property>
-->
+        <property name="hsalproperty5" type="xsd:string">HsalProp5</property>
+        <property name="hsalproperty6" type="xsd:string">HsalProp6</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=723015&r1=723014&r2=723015&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 11:05:57 2008
@@ -38,6 +38,12 @@
   <listener>
       <listener-class>sample.HelloworldServletRequestAttributeListener</listener-class>
   </listener>
+  <listener>
+      <listener-class>sample.HelloworldHttpSessionListener</listener-class>
+  </listener>
+  <listener>
+      <listener-class>sample.HelloworldHttpSessionAttributeListener</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=723015&r1=723014&r2=723015&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 11:05:57 2008
@@ -22,6 +22,8 @@
 <%@ page contentType="text/html;charset=UTF-8" language="java" %>
 <%@ page import="sample.HelloworldServletContextListener"%>
 <%@ page import="sample.HelloworldServletRequestListener"%>
+<%@ page import="sample.HelloworldHttpSessionListener"%>
+
 <html>
   <head><title>Helloworld Event Listener sample</title></head>
   <body>
@@ -30,5 +32,7 @@
     <%=getServletContext().getAttribute(HelloworldServletContextListener.HELLO_TXT)%>
 
     <%=request.getAttribute(HelloworldServletRequestListener.HELLO_TXT) %>
+
+    <%=session.getAttribute(HelloworldHttpSessionListener.HELLO_TXT) %>
   </body>
 </html>



Mime
View raw message