You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pubscribe-commits@ws.apache.org by jr...@apache.org on 2005/07/29 17:51:37 UTC

svn commit: r226384 - /webservices/pubscribe/trunk/src/site/content/xdocs/dev_guide/consumer.xml

Author: jruzzi
Date: Fri Jul 29 08:51:35 2005
New Revision: 226384

URL: http://svn.apache.org/viewcvs?rev=226384&view=rev
Log:
updated content

Modified:
    webservices/pubscribe/trunk/src/site/content/xdocs/dev_guide/consumer.xml

Modified: webservices/pubscribe/trunk/src/site/content/xdocs/dev_guide/consumer.xml
URL: http://svn.apache.org/viewcvs/webservices/pubscribe/trunk/src/site/content/xdocs/dev_guide/consumer.xml?rev=226384&r1=226383&r2=226384&view=diff
==============================================================================
--- webservices/pubscribe/trunk/src/site/content/xdocs/dev_guide/consumer.xml (original)
+++ webservices/pubscribe/trunk/src/site/content/xdocs/dev_guide/consumer.xml Fri Jul 29 08:51:35 2005
@@ -13,19 +13,22 @@
 			only receives messages for notifications to which it is subscribed.  
 			</p>
 			<p>The Wsdl2Java tool generates the same artifacts for a notification consumer as it does for a notification producer. In particular, the service, resource, and home class are 
-			generated but need to be modified specifically for your consumer. The topics in this section describe how to modify these classes. An example notification consumer for the 
-			filesystem example is provided in the <code>INSTALL_DIR/examples/consumer</code> and discussed below. Initially, you should model your consumer based on the example to 
+			generated but need to be modified specifically for your consumer. The topics in this section describe how to modify these classes. An example notification consumer that works together  
+			with the filesystem example is provided in the <code>INSTALL_DIR/examples/consumer</code> and discussed below. Initially, you should model your consumer based on the example to 
 			ensure that you 	write a valid consumer.
 			</p>
-			<note>Before completing the instructions below, you must create a WSDL that implements the Notify operation from the <code>NotificationConsumer</code> portType and run the 
-			Wsdl2Java tool on the WSDL. If you use the INSTALL_DIR/template/_TEMPLATE_.wsdl to create the WSDL, this operation is included and only needs to be uncommented. A completed 
-			WSDL is provided for the consumer example.</note>
+			<note>A consumer WSDL must implement the <code>Notify</code> operation from the <code>NotificationConsumer</code> portType. If you use the 
+			<code>INSTALL_DIR/template/_TEMPLATE_.wsdl</code> to create the WSDL, this operation is included and only needs to be uncommented. A WSDL is included in the consumer 
+			example. To use this example, run the Wsdl2Java tool on the WSDL.
+			</note>
 		</section>
 		<section>
 			<title>Modify the Service Class</title>
 			<p>An abstract method <code>Notify</code> is generated in the abstractService class an needs to be implemented in your service class. The implementation of the method is dependant 
 			on whatever features you want to include for your consumer. In the consumer example, a property is used to retrieve the last notification message. In 
-			this case, the <code>notify</code> method allows a JSP page to retrieve and display the current notification message. The method is implemented as follows:</p>
+			this case, the <code>notify</code> method will allow a JSP page to retrieve and display the current notification message. Notice that the service class is also used to 
+			setup and initialize the <code>LASTMESSAGE</code> resource property. Therefore, the the resource class will not need to perform these operations. The method is implemented as 
+			follows:</p>
 			<source>
 public void notify(org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.NotifyDocument notifyDocument)
     {
@@ -50,12 +53,13 @@
 		</section>
 		<section>
 			<title>Modify the Resource Class</title>
-			<p>The resource class is used to setup and initialize any resource properties. For the consumer example, a single resource property is defined and called 
-			<code>LastMessage</code>. The resource class <code>init()</code> method is modified to add this property to the <code>ResourcePropertySet</code> This is not required but 
-			demonstrates a possible implementation.
+			<p>The resource class is used to setup and initialize any resource properties. For the consumer example,  the resource class is not used to setup and initialize the 
+			<code>LASTMESSAGE</code> resource property, but instead  the service class is used to perform these operations. If you choose to use the resource class, you should update the 
+			<code>init()</code> method to add your properties to the <code>ResourcePropertySet</code> The following sample code is not required for the consumer example but demonstrates a 
+			possible implementation.
 			</p>
 			<source>
-    public void init()
+   public void init()
     {
         super.init();               
 
@@ -64,45 +68,35 @@
 		 */
 		org.apache.ws.resource.properties.ResourcePropertySet resourcePropertySet = getResourcePropertySet();
 		org.apache.ws.resource.properties.ResourceProperty resourceProperty = null;
+
+
 	try{	
 		// init the {http://ws.apache.org/resource/example/NotifConsumer}LastMessage Resource Property
 		resourceProperty = resourcePropertySet.get(ConsumerPortPropertyQNames.LASTMESSAGE);
+		
 		}
 	catch (Exception e)
 	{
 	   throw new javax.xml.rpc.JAXRPCException("There was a problem in initializing your resource properties.  Please check your init() method. Cause: " + e.getLocalizedMessage());
-	}		
-	        
-    }
-			</source>
+	}       
+}			</source>
 		</section>
 		<section>
 			<title>Modify the Home Class</title>
 			<p>The home class is used to lookup the resource instance. It can act as a factory for creating instances upon request, or build all instances. It is meant to be the entry point for 
-			locating a resource instance. For the consumer example the <code>init()</code> method is modified to get an instance of the consumer resource.</p>
+			locating a resource instance. For the consumer example the <code>init()</code> method is modified to get an instance of the consumer resource. The resource is a singleton 
+			and therfore only requires a single instance. For more information on creating a singleton, see the <a href="ext:single">Creating a Singleton Service</a> in the Apache WSRF 
+         		documentation.
+         		</p>
 			<source>
- private static Resource m_resource = null; 
-
-  public Resource getInstance( ResourceContext resourceContext )
-            throws ResourceException,
-            ResourceContextException,
-            ResourceUnknownException
+ public void init() throws Exception
     {
-        if(m_resource == null)
-	    {
-			//singleton
-	        ConsumerPortResource myresource = new ConsumerPortResource();
-	        myresource.init();
-			//the next line will create an EPR
-			EndpointReference epr = getEndpointReference(resourceContext.getBaseURL(  ) + "/" + getServiceName().getLocalPart() , null, SPEC_NAMESPACE_SET.getAddressingNamespace());
-			myresource.setEndpointReference(epr); //make sure to set the EPR on your new instance
-			m_resource = myresource;
-	    }
-
-        return m_resource;
+        super.init();
+        add( createInstance( null ) );
     }</source>
-			<note>A client for the consumer must use the EPR to access the consumer resource. The EPR is returned by the notification producer when you subscribe to a notification 
-			topic.</note>
+			<note>At runtime, a client for the consumer must use the EPR to access the consumer resource. The EPR is returned by the notification producer when you subscribe to a 
+			notification topic.
+			</note>
 		</section>
 	</body>
 </document>