You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pubscribe-dev@ws.apache.org by sc...@apache.org on 2005/02/02 17:53:37 UTC
svn commit: r149534 - in
incubator/hermes/trunk/src/java/org/apache/ws/pubsub/emitter:
file/FileNotificationEmitterTask.java http/HttpNotificationEmitterTask.java
Author: scamp
Date: Wed Feb 2 08:53:36 2005
New Revision: 149534
URL: http://svn.apache.org/viewcvs?view=rev&rev=149534
Log:
Added Emitter stuff from Muse
Added:
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/file/FileNotificationEmitterTask.java
URL: http://svn.apache.org/viewcvs/incubator/hermes/trunk/src/java/org/apache/ws/pubsub/emitter/file/FileNotificationEmitterTask.java?view=auto&rev=149534
==============================================================================
--- incubator/hermes/trunk/src/java/org/apache/ws/pubsub/emitter/file/FileNotificationEmitterTask.java (added)
+++ incubator/hermes/trunk/src/java/org/apache/ws/pubsub/emitter/file/FileNotificationEmitterTask.java Wed Feb 2 08:53:36 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 {@link 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/HttpNotificationEmitterTask.java
URL: http://svn.apache.org/viewcvs/incubator/hermes/trunk/src/java/org/apache/ws/pubsub/emitter/http/HttpNotificationEmitterTask.java?view=auto&rev=149534
==============================================================================
--- incubator/hermes/trunk/src/java/org/apache/ws/pubsub/emitter/http/HttpNotificationEmitterTask.java (added)
+++ incubator/hermes/trunk/src/java/org/apache/ws/pubsub/emitter/http/HttpNotificationEmitterTask.java Wed Feb 2 08:53:36 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 {@link 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: hermes-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: hermes-dev-help@ws.apache.org