Author: scamp
Date: Wed Feb  2 08:54:48 2005
New Revision: 149535

URL: http://svn.apache.org/viewcvs?view=rev&rev=149535
Log:
renamed as per Stefan

Added:
    
incubator/hermes/trunk/src/java/org/apache/ws/pubsub/emitter/EmitterTask.java
    
incubator/hermes/trunk/src/java/org/apache/ws/pubsub/emitter/file/FileEmitterTask.java
    
incubator/hermes/trunk/src/java/org/apache/ws/pubsub/emitter/http/HttpEmitterTask.java
Removed:
    
incubator/hermes/trunk/src/java/org/apache/ws/pubsub/emitter/NotificationEmitterTask.java
    
incubator/hermes/trunk/src/java/org/apache/ws/pubsub/emitter/file/FileNotificationEmitterTask.java
    
incubator/hermes/trunk/src/java/org/apache/ws/pubsub/emitter/http/HttpNotificationEmitterTask.java

Added: 
incubator/hermes/trunk/src/java/org/apache/ws/pubsub/emitter/EmitterTask.java
URL: 
http://svn.apache.org/viewcvs/incubator/hermes/trunk/src/java/org/apache/ws/pubsub/emitter/EmitterTask.java?view=auto&rev=149535
==============================================================================
--- 
incubator/hermes/trunk/src/java/org/apache/ws/pubsub/emitter/EmitterTask.java 
(added)
+++ 
incubator/hermes/trunk/src/java/org/apache/ws/pubsub/emitter/EmitterTask.java 
Wed Feb  2 08:54:48 2005
@@ -0,0 +1,253 @@
+/*=============================================================================*
+ *  Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed 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 org.apache.ws.pubsub.emitter;
+
+import org.apache.ws.pubsub.emitter.file.FileNotificationEmitterTask;
+import org.apache.ws.pubsub.emitter.http.HttpNotificationEmitterTask;
+import org.apache.ws.pubsub.i18n.MessagesImpl;
+import org.apache.ws.pubsub.i18n.Keys;
+import org.apache.ws.util.i18n.Messages;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.xml.sax.SAXException;
+import org.xmlsoap.schemas.ws.x2003.x03.addressing.EndpointReferenceType;
+import javax.xml.soap.SOAPMessage;
+import java.lang.reflect.InvocationTargetException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.HashMap;
+
+/**
+ * This task is to be used to send notifications to client subscriber 
destinations.  This class contains
+ * a factory method, [EMAIL PROTECTED] #createEmitterTask(SOAPMessage, 
EndpointReferenceType)}, that creates a task specific to the
+ * protocol for the given destination; this factory method must be used to 
create emitter tasks.
+ * All subclasses to this class will be responsible for sending notifications 
over particular protocol
+ * transports.  Each subclass must have a constructor that takes a XML string 
(the notification message itself),
+ * a destination URL and a destination EPR as a
+ * [EMAIL PROTECTED] 
org.xmlsoap.schemas.ws.x2003.x03.addressing.EndpointReferenceType}; these 
constructors are called by this class' factory method.
+ */
+public abstract class NotificationEmitterTask
+   implements Runnable
+{
+   /** object used to obtain I18N messages */
+   private static final Messages MSG = MessagesImpl.getInstance(  );
+
+   /** object used to log messages */
+   private static final Log LOG = LogFactory.getLog( 
NotificationEmitterTask.class );
+
+   /**
+    * Protocol emitter map: key is protocol name, value is corresponding 
[EMAIL PROTECTED] NotificationEmitterTask} class.
+    */
+   private static final HashMap PROTOCOL_EMITTER_MAP;
+
+   static
+   {
+      PROTOCOL_EMITTER_MAP = new HashMap(  );
+      PROTOCOL_EMITTER_MAP.put( FileNotificationEmitterTask.PROTOCOL, 
FileNotificationEmitterTask.class );
+      PROTOCOL_EMITTER_MAP.put( HttpNotificationEmitterTask.PROTOCOL, 
HttpNotificationEmitterTask.class );
+
+      //PROTOCOL_EMITTER_MAP.put( HttpsNotificationEmitterTask.PROTOCOL, 
HttpsNotificationEmitterTask.class );
+      //PROTOCOL_EMITTER_MAP.put( FtpNotificationEmitterTask.PROTOCOL, 
FtpNotificationEmitterTask.class );
+      //PROTOCOL_EMITTER_MAP.put( MailtoNotificationEmitterTask.PROTOCOL, 
MailtoNotificationEmitterTask.class );
+      //PROTOCOL_EMITTER_MAP.put( JdbcNotificationEmitterTask.PROTOCOL, 
JdbcNotificationEmitterTask.class );
+   }
+
+   /** The notification to send */
+   private final SOAPMessage m_notification;
+
+   /** The destination URL where the notification will be sent */
+   private final URL m_destinationUrl;
+
+   /** The destination EPR of the notification consumer */
+   private final EndpointReferenceType m_destinationEpr;
+
+   /**
+    * Constructor to build the task.  This is protected to enforce that fact 
that only
+    * [EMAIL PROTECTED] #createEmitterTask(javax.xml.soap.SOAPMessage, 
org.xmlsoap.schemas.ws.x2003.x03.addressing.EndpointReferenceType)}
+    * should be used by clients to create these task objects.
+    *
+    * @param notif notification to send
+    * @param url endpoint URL of notification consumer
+    * @param destination endpoint reference of the notification consumer
+    */
+   protected NotificationEmitterTask( SOAPMessage           notif,
+                                      URL                   url,
+                                      EndpointReferenceType destination )
+   {
+      m_notification      = notif;
+      m_destinationUrl    = url;
+      m_destinationEpr    = destination;
+   }
+
+   /**
+    * Factory method that creates the appropriate emitter task based on the
+    * protocol required to send the notification.
+    *
+    * @param notif notification to send
+    * @param destination notification is to be sent to this destination 
endpoint
+    *
+    * @return the task to be used to send the notification
+    *
+    * @throws EmitterException if failed to create the task
+    */
+   public static NotificationEmitterTask createEmitterTask( SOAPMessage        
   notif,
+                                                            
EndpointReferenceType destination )
+   throws EmitterException
+   {
+      NotificationEmitterTask task;
+      Class                   task_class = null;
+
+      LOG.debug( MSG.getMessage( Keys.CREATING_NOTIF_EMITTER, destination ) );
+
+      try
+      {
+         URL url;
+
+         try
+         {
+            url = new URL( destination.getAddress(  ).getStringValue(  ) );
+         }
+         catch ( MalformedURLException murle )
+         {
+            LOG.error( MSG.getMessage( Keys.NOTIF_EMITTER_CREATION_FAILURE, 
destination, murle ) );
+            throw new EmitterException( murle );
+         }
+
+         task_class = (Class) PROTOCOL_EMITTER_MAP.get( url.getProtocol(  ) );
+
+         if ( task_class != null )
+         {
+            Class[] sig = new Class[]
+                          {
+                             SOAPMessage.class,
+                             URL.class,
+                             EndpointReferenceType.class
+                          };
+            Object[] params = new Object[]
+                              {
+                                 notif,
+                                 url,
+                                 destination
+                              };
+
+            task = (NotificationEmitterTask) task_class.getConstructor( sig 
).newInstance( params );
+         }
+         else
+         {
+            String err = MSG.getMessage( Keys.UNSUPPORTED_PROTOCOL, 
destination, notif );
+            LOG.error( err );
+            throw new EmitterException( err );
+         }
+      }
+      catch ( InstantiationException ie )
+      {
+         LOG.error( MSG.getMessage( Keys.BAD_TASK_CLASS_IS_ABSTRACT,
+                                    task_class.getName(  ),
+                                    ie ) );
+         throw new EmitterException( ie );
+      }
+      catch ( IllegalAccessException iae )
+      {
+         LOG.error( MSG.getMessage( Keys.BAD_TASK_CLASS_ACCESS_DENIED,
+                                    task_class.getName(  ),
+                                    iae ) );
+         throw new EmitterException( iae );
+      }
+      catch ( InvocationTargetException ite )
+      {
+         LOG.error( MSG.getMessage( Keys.TASK_CON_EXCEPTION,
+                                    task_class.getName(  ),
+                                    ite ) );
+         throw new EmitterException( ite );
+      }
+      catch ( NoSuchMethodException nsme )
+      {
+         LOG.error( MSG.getMessage( Keys.BAD_TASK_CLASS_NO_CON,
+                                    task_class.getName(  ),
+                                    nsme ) );
+         throw new EmitterException( nsme );
+      }
+
+      return task;
+   }
+
+   /**
+    * This template method runs the task's thread and will call the appropriate
+    * emitter task's [EMAIL PROTECTED] #emit()} method to send the 
notification.
+    *
+    * @see java.lang.Runnable#run()
+    */
+   public void run(  )
+   {
+      LOG.debug( MSG.getMessage( Keys.EMITTING_NOTIFICATION, m_destinationEpr, 
m_notification ) );
+      try
+      {
+         emit(  );
+      }
+      catch ( Throwable t )
+      {
+         if ( !( t.getCause(  ) instanceof SAXException ) )
+         {
+            LOG.error( MSG.getMessage( Keys.EMISSION_FAILURE,
+                                       this.getClass(  ),
+                                       m_notification,
+                                       t.getCause(  ) ) );
+         }
+         else
+         {
+            // Axis throws a SAXException if the notification consumer returns 
a response with an invalid HTTP body,
+            // which we can basically ignore.
+            LOG.trace( MSG.getMessage( Keys.EMISSION_FAILURE,
+                                       this.getClass(  ),
+                                       m_notification,
+                                       t.getCause(  ) ) );
+         }
+      }
+   }
+
+   /**
+    * @return the notification consumer's EPR
+    */
+   protected EndpointReferenceType getDestinationEpr(  )
+   {
+      return m_destinationEpr;
+   }
+
+   /**
+    * @return the destination URL where the notification will be sent
+    */
+   protected URL getDestinationUrl(  )
+   {
+      return m_destinationUrl;
+   }
+
+   /**
+    * @return the actual notification object that is to be emitted.
+    */
+   protected SOAPMessage getNotification(  )
+   {
+      return m_notification;
+   }
+
+   /**
+    * Method that will actually send the notification to the destination via
+    * the appropriate protocol transport.
+    *
+    * @throws EmitterException on error attempting to send notification
+    */
+   protected abstract void emit(  )
+   throws EmitterException;
+}
\ No newline at end of file

Added: 
incubator/hermes/trunk/src/java/org/apache/ws/pubsub/emitter/file/FileEmitterTask.java
URL: 
http://svn.apache.org/viewcvs/incubator/hermes/trunk/src/java/org/apache/ws/pubsub/emitter/file/FileEmitterTask.java?view=auto&rev=149535
==============================================================================
--- 
incubator/hermes/trunk/src/java/org/apache/ws/pubsub/emitter/file/FileEmitterTask.java
 (added)
+++ 
incubator/hermes/trunk/src/java/org/apache/ws/pubsub/emitter/file/FileEmitterTask.java
 Wed Feb  2 08:54:48 2005
@@ -0,0 +1,128 @@
+/*=============================================================================*
+ *  Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed 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 org.apache.ws.pubsub.emitter.file;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ws.pubsub.emitter.NotificationEmitterTask;
+import org.apache.ws.pubsub.emitter.EmitterException;
+import org.apache.ws.pubsub.i18n.MessagesImpl;
+import org.apache.ws.pubsub.i18n.Keys;
+import org.apache.ws.util.i18n.Messages;
+import org.xmlsoap.schemas.ws.x2003.x03.addressing.EndpointReferenceType;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPMessage;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+/**
+ * An emitter task that stores a notification to a file specified in the FILE 
protocol URL.
+ * If the file already exists, the new notification data will be appended to 
the end.
+ * If the file is actually a directory, the notification filename will be 
generated.
+ */
+public class FileNotificationEmitterTask
+   extends NotificationEmitterTask
+{
+   /** This emitter's protocol */
+   public static final String PROTOCOL = "file";
+
+   /** object used to obtain I18N messages */
+   private static final Messages MSG = MessagesImpl.getInstance(  );
+
+   /** object used to log messages */
+   private static final Log LOG = LogFactory.getLog( 
FileNotificationEmitterTask.class );
+
+   /**
+    * Creates a new [EMAIL PROTECTED] FileNotificationEmitterTask} object.
+    *
+    * @see NotificationEmitterTask#NotificationEmitterTask(SOAPMessage, URL, 
EndpointReferenceType)
+    */
+   public FileNotificationEmitterTask( SOAPMessage           notif,
+                                       URL                   url,
+                                       EndpointReferenceType epr )
+   {
+      super( notif, url, epr );
+   }
+
+   /**
+    * Stores the notification in a file specified by the destination URL.  No 
attempt to
+    * lock the file or otherwise force synchronous writes to the file is made;
+    * it is up to the subscriber to provide a file URI that will be suitable 
for
+    * writing.  If the file is a directory, a file will be created in that 
directory.
+    *
+    * @see NotificationEmitterTask#emit()
+    */
+   protected void emit(  )
+   throws EmitterException
+   {
+      LOG.debug( MSG.getMessage( Keys.EMITTING_TO_FILE,
+                                 getDestinationUrl(  ) ) );
+
+      try
+      {
+         File destFile = new File( getDestinationUrl(  ).getPath(  ) );
+
+         if ( destFile.isDirectory(  ) )
+         {
+            destFile = getDefaultDestinationFile( destFile );
+         }
+         else
+         {
+            destFile.getParentFile(  ).mkdirs(  );
+         }
+
+         FileOutputStream fos          = new FileOutputStream( destFile, true 
);
+         SOAPMessage      notification = getNotification(  );
+         notification.writeTo( fos );
+         fos.close(  );
+      }
+      catch ( MalformedURLException murle )
+      {
+         throw new EmitterException( MSG.getMessage( 
Keys.EX_FAILED_TO_STORE_NOTIFICATION_TO_FILE_BAD_URL,
+                                                     getDestinationUrl(  ) ), 
murle );
+      }
+      catch ( IOException ioe )
+      {
+         throw new EmitterException( MSG.getMessage( 
Keys.EX_FAILED_TO_STORE_NOTIFICATION_TO_FILE,
+                                                     getDestinationUrl(  ) ), 
ioe );
+      }
+      catch ( SOAPException e )
+      {
+         throw new EmitterException( MSG.getMessage( 
Keys.EX_FAILED_TO_STORE_NOTIFICATION_TO_FILE,
+                                                     getDestinationUrl(  ) ), 
e );
+      }
+
+      return;
+   }
+
+   /**
+    * Determines a default file to use when writing the notification to the 
directory.  The file will be created
+    * when this method returns.
+    *
+    * @param dir the directory
+    *
+    * @return the file where the notification will be stored
+    * @throws IOException if failed to create the temp file
+    */
+   private File getDefaultDestinationFile( File dir )
+   throws IOException
+   {
+      return File.createTempFile( "notification-", ".txt", dir );
+   }
+}
\ No newline at end of file

Added: 
incubator/hermes/trunk/src/java/org/apache/ws/pubsub/emitter/http/HttpEmitterTask.java
URL: 
http://svn.apache.org/viewcvs/incubator/hermes/trunk/src/java/org/apache/ws/pubsub/emitter/http/HttpEmitterTask.java?view=auto&rev=149535
==============================================================================
--- 
incubator/hermes/trunk/src/java/org/apache/ws/pubsub/emitter/http/HttpEmitterTask.java
 (added)
+++ 
incubator/hermes/trunk/src/java/org/apache/ws/pubsub/emitter/http/HttpEmitterTask.java
 Wed Feb  2 08:54:48 2005
@@ -0,0 +1,84 @@
+/*=============================================================================*
+ *  Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed 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 org.apache.ws.pubsub.emitter.http;
+
+import org.apache.ws.pubsub.emitter.NotificationEmitterTask;
+import org.apache.ws.pubsub.emitter.EmitterException;
+import org.apache.ws.pubsub.i18n.MessagesImpl;
+import org.apache.ws.pubsub.i18n.Keys;
+import org.apache.ws.util.i18n.Messages;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.xmlsoap.schemas.ws.x2003.x03.addressing.EndpointReferenceType;
+import javax.xml.soap.SOAPConnection;
+import javax.xml.soap.SOAPConnectionFactory;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPMessage;
+import java.net.URL;
+
+/**
+ * An emitter task that sends a notification via the HTTP protocol.
+ */
+public class HttpNotificationEmitterTask
+   extends NotificationEmitterTask
+{
+   /** This emitter's protocol */
+   public static final String PROTOCOL = "http";
+
+   /** object used to obtain I18N messages */
+   private static final Messages MSG = MessagesImpl.getInstance(  );
+
+   /** object used to log messages */
+   private static final Log LOG = LogFactory.getLog( 
HttpNotificationEmitterTask.class );
+
+   /**
+    * Creates a new [EMAIL PROTECTED] HttpNotificationEmitterTask} object.
+    *
+    * @see NotificationEmitterTask#NotificationEmitterTask(SOAPMessage, URL, 
EndpointReferenceType)
+    */
+   public HttpNotificationEmitterTask( SOAPMessage           notif,
+                                       URL                   url,
+                                       EndpointReferenceType destination )
+   {
+      super( notif, url, destination );
+   }
+
+   /**
+    * Sends the notification to the destination via HTTP.
+    *
+    * @see NotificationEmitterTask#emit()
+    */
+   protected void emit(  )
+   throws EmitterException
+   {
+      LOG.debug( MSG.getMessage( Keys.EMITTING_TO_HTTP_DEST,
+                                 getDestinationUrl(  ) ) );
+
+      try
+      {
+         SOAPConnection soapConn = SOAPConnectionFactory.newInstance(  
).createConnection(  );
+         SOAPMessage    response = soapConn.call( getNotification(  ),
+                                                  getDestinationUrl(  
).toString(  ) );
+         LOG.debug( MSG.getMessage( Keys.RESPONSE_TO_EMIT,
+                                    response.toString(  ) ) );
+      }
+      catch ( SOAPException e )
+      {
+         throw new EmitterException( MSG.getMessage( 
Keys.EX_FAILED_TO_SEND_HTTP_NOTIFICATION,
+                                                     getDestinationUrl(  ) ), 
e );
+      }
+   }
+}
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to