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 sc...@apache.org on 2005/08/02 18:41:44 UTC
svn commit: r227035 [10/12] - in /webservices/pubscribe/trunk: ./
src/java/org/apache/ws/eventing/ src/java/org/apache/ws/eventing/porttype/
src/java/org/apache/ws/eventing/porttype/impl/
src/java/org/apache/ws/eventing/pubsub/ src/java/org/apache/ws/e...
Modified: webservices/pubscribe/trunk/src/java/org/apache/ws/pubsub/emitter/file/FileEmitterTask.java
URL: http://svn.apache.org/viewcvs/webservices/pubscribe/trunk/src/java/org/apache/ws/pubsub/emitter/file/FileEmitterTask.java?rev=227035&r1=227034&r2=227035&view=diff
==============================================================================
--- webservices/pubscribe/trunk/src/java/org/apache/ws/pubsub/emitter/file/FileEmitterTask.java (original)
+++ webservices/pubscribe/trunk/src/java/org/apache/ws/pubsub/emitter/file/FileEmitterTask.java Tue Aug 2 09:41:00 2005
@@ -1,127 +1,126 @@
-/*=============================================================================*
- * 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.EmitterException;
-import org.apache.ws.pubsub.emitter.EmitterTask;
-import org.apache.ws.pubsub.i18n.Keys;
-import org.apache.ws.pubsub.i18n.MessagesImpl;
-import org.apache.ws.util.i18n.Messages;
-
-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 FileEmitterTask
- extends EmitterTask
-{
- /** 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( FileEmitterTask.class );
-
- /**
- * Creates a new {@link FileEmitterTask} object.
- *
- * @see EmitterTask(SOAPMessage, URL)
- */
- public FileEmitterTask( SOAPMessage notif,
- URL url)
- {
- super( notif, url );
- }
-
- /**
- * 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 EmitterTask#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 );
- }
+/*=============================================================================*
+ * 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.EmitterException;
+import org.apache.ws.pubsub.emitter.EmitterTask;
+import org.apache.ws.pubsub.i18n.Keys;
+import org.apache.ws.pubsub.i18n.MessagesImpl;
+import org.apache.ws.util.i18n.Messages;
+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 FileEmitterTask
+ extends EmitterTask
+{
+ /** 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( FileEmitterTask.class );
+
+ /**
+ * Creates a new {@link FileEmitterTask} object.
+ *
+ * @see EmitterTask(SOAPMessage, URL)
+ */
+ public FileEmitterTask( SOAPMessage notif,
+ URL url )
+ {
+ super( notif, url );
+ }
+
+ /**
+ * 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 EmitterTask#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 );
+ }
}
Modified: webservices/pubscribe/trunk/src/java/org/apache/ws/pubsub/emitter/http/HttpEmitterTask.java
URL: http://svn.apache.org/viewcvs/webservices/pubscribe/trunk/src/java/org/apache/ws/pubsub/emitter/http/HttpEmitterTask.java?rev=227035&r1=227034&r2=227035&view=diff
==============================================================================
--- webservices/pubscribe/trunk/src/java/org/apache/ws/pubsub/emitter/http/HttpEmitterTask.java (original)
+++ webservices/pubscribe/trunk/src/java/org/apache/ws/pubsub/emitter/http/HttpEmitterTask.java Tue Aug 2 09:41:00 2005
@@ -1,90 +1,88 @@
-/*=============================================================================*
- * 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.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.ws.pubsub.emitter.EmitterException;
-import org.apache.ws.pubsub.emitter.EmitterTask;
-import org.apache.ws.pubsub.i18n.Keys;
-import org.apache.ws.pubsub.i18n.MessagesImpl;
-import org.apache.ws.util.i18n.Messages;
-
-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 HttpEmitterTask
- extends EmitterTask
-{
- /** 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( HttpEmitterTask.class );
-
- /**
- * Creates a new {@link HttpEmitterTask} object.
- *
- * @see EmitterTask(SOAPMessage, URL)
- */
- public HttpEmitterTask( SOAPMessage notif,
- URL url )
- {
- super( notif, url );
- }
-
- /**
- * Sends the notification to the destination via HTTP.
- *
- * @see EmitterTask#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( ) );
- if (LOG.isDebugEnabled())
- {
- if(response != null)
- {
- 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 );
- }
- }
+/*=============================================================================*
+ * 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.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ws.pubsub.emitter.EmitterException;
+import org.apache.ws.pubsub.emitter.EmitterTask;
+import org.apache.ws.pubsub.i18n.Keys;
+import org.apache.ws.pubsub.i18n.MessagesImpl;
+import org.apache.ws.util.i18n.Messages;
+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 HttpEmitterTask
+ extends EmitterTask
+{
+ /** 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( HttpEmitterTask.class );
+
+ /**
+ * Creates a new {@link HttpEmitterTask} object.
+ *
+ * @see EmitterTask(SOAPMessage, URL)
+ */
+ public HttpEmitterTask( SOAPMessage notif,
+ URL url )
+ {
+ super( notif, url );
+ }
+
+ /**
+ * Sends the notification to the destination via HTTP.
+ *
+ * @see EmitterTask#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( ) );
+ if ( LOG.isDebugEnabled( ) )
+ {
+ if ( response != null )
+ {
+ 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 );
+ }
+ }
}
Modified: webservices/pubscribe/trunk/src/java/org/apache/ws/pubsub/i18n/Keys.java
URL: http://svn.apache.org/viewcvs/webservices/pubscribe/trunk/src/java/org/apache/ws/pubsub/i18n/Keys.java?rev=227035&r1=227034&r2=227035&view=diff
==============================================================================
--- webservices/pubscribe/trunk/src/java/org/apache/ws/pubsub/i18n/Keys.java (original)
+++ webservices/pubscribe/trunk/src/java/org/apache/ws/pubsub/i18n/Keys.java Tue Aug 2 09:41:00 2005
@@ -1,103 +1,103 @@
-/*=============================================================================*
- * 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.i18n;
-
-
-/**
- * i18n message keys for the <code>org.apache.ws.notification</code> package.
- */
-public interface Keys
-{
- /** DOCUMENT_ME */
- String CREATE_SUB_TABLE = "CREATE_SUB_TABLE";
-
- /** DOCUMENT_ME */
- String CREATING_SUB_TABLE_MGR = "CREATING_SUB_TABLE_MGR";
-
- /** DOCUMENT_ME */
- String EMITTING_MESSAGE = "EMITTING_MESSAGE";
-
- /** DOCUMENT_ME */
- String INVALID_SUBMGR_TABLE_TYPE = "INVALID_SUBMGR_TABLE_TYPE";
-
- /** DOCUMENT_ME */
- String MESSAGE_NOT_AVAILABLE_FOR_TOPIC = "MESSAGE_NOT_AVAILABLE_FOR_TOPIC";
-
- /** DOCUMENT_ME */
- String NULL_PROP_QNAME = "NULL_PROP_QNAME";
-
- /** DOCUMENT_ME */
- String NULL_SUBID_NOT_ALLOWED = "NULL_SUBID_NOT_ALLOWED";
-
- /** DOCUMENT_ME */
- String TOPIC_NOT_AVAILABLE_FOR_SUBSCRIPTION = "TOPIC_NOT_AVAILABLE_FOR_SUBSCRIPTION";
-
- /** CREATING_NOTIF_EMITTER=Creating a notification emitter to destination=[{0}] */
- String CREATING_NOTIF_EMITTER = "CREATING_NOTIF_EMITTER";
-
- /** NOTIF_EMITTER_CREATION_FAILURE=Failed to create a notification emitter for destination [{0}]. Cause: {1} */
- String NOTIF_EMITTER_CREATION_FAILURE = "NOTIF_EMITTER_CREATION_FAILURE";
-
- /** UNSUPPORTED_PROTOCOL=Destination requires an unsupported protocol [{0}]; it will not receive notification [{1}] */
- String UNSUPPORTED_PROTOCOL = "UNSUPPORTED_PROTOCOL";
-
- /** BAD_TASK_CLASS_IS_ABSTRACT=Bad task class [{0}]; it must not be abstract. Cause: {1} */
- String BAD_TASK_CLASS_IS_ABSTRACT = "BAD_TASK_CLASS_IS_ABSTRACT";
-
- /** BAD_TASK_CLASS_ACCESS_DENIED=Bad task class [{0}]; access to the constructor was denied. Cause: {1} */
- String BAD_TASK_CLASS_ACCESS_DENIED = "BAD_TASK_CLASS_ACCESS_DENIED";
-
- /** TASK_CON_EXCEPTION=Task [{0}] constructor threw an exception: {1} */
- String TASK_CON_EXCEPTION = "TASK_CON_EXCEPTION";
-
- /** BAD_TASK_CLASS_NO_CON=Bad task class [{0}], missing required constructor. Cause: {1} */
- String BAD_TASK_CLASS_NO_CON = "BAD_TASK_CLASS_NO_CON";
-
- /** EMITTING_NOTIFICATION=Emitting notification: destination=[{0}], notification=[{1}] */
- String EMITTING_NOTIFICATION = "EMITTING_NOTIFICATION";
-
- /**
- * @msg SOAP Response to emitted notification: [{0}]
- **/
- String RESPONSE_TO_EMIT = "RESPONSE_TO_EMIT";
-
- /** EMISSION_FAILURE={0} failed to emit notification [{1}]. Cause: {2} */
- String EMISSION_FAILURE = "EMISSION_FAILURE";
-
- /** EX_NO_NOTIFICATIONS=No Notifications to emit! */
- String EX_NO_NOTIFICATIONS = "EX_NO_NOTIFICATIONS";
-
- /** EMITTING_TO_FILE=Emitting notification to file [{0}] */
- String EMITTING_TO_FILE = "EMITTING_TO_FILE";
-
- /** EX_FAILED_TO_STORE_NOTIFICATION_TO_FILE_BAD_URL=Failed to store notification to file, bad destination URL: [{0}] */
- String EX_FAILED_TO_STORE_NOTIFICATION_TO_FILE_BAD_URL = "EX_FAILED_TO_STORE_NOTIFICATION_TO_FILE_BAD_URL";
-
- /** EX_FAILED_TO_STORE_NOTIFICATION_TO_FILE=Failed to store notification to file: [{0}] */
- String EX_FAILED_TO_STORE_NOTIFICATION_TO_FILE = "EX_FAILED_TO_STORE_NOTIFICATION_TO_FILE";
-
- /** EMITTING_TO_HTTP_DEST=Emitting notification to HTTP destination [{0}] */
- String EMITTING_TO_HTTP_DEST = "EMITTING_TO_HTTP_DEST";
-
- /** EX_FAILED_TO_SEND_HTTP_NOTIFICATION_BAD_URL=Failed to send HTTP notification, bad destination URL: [{0}] */
- String EX_FAILED_TO_SEND_HTTP_NOTIFICATION_BAD_URL = "EX_FAILED_TO_SEND_HTTP_NOTIFICATION_BAD_URL";
-
- /** EX_FAILED_TO_SEND_HTTP_NOTIFICATION=Failed to send notification via HTTP: [{0}] */
- String EX_FAILED_TO_SEND_HTTP_NOTIFICATION = "EX_FAILED_TO_SEND_HTTP_NOTIFICATION";
-
- /** GETTING_SUBSCRIBERS=Getting subscribers on topic [{0}] */
- String GETTING_SUBSCRIBERS = "GETTING_SUBSCRIBERS";
+/*=============================================================================*
+ * 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.i18n;
+
+
+/**
+ * i18n message keys for the <code>org.apache.ws.notification</code> package.
+ */
+public interface Keys
+{
+ /** DOCUMENT_ME */
+ String CREATE_SUB_TABLE = "CREATE_SUB_TABLE";
+
+ /** DOCUMENT_ME */
+ String CREATING_SUB_TABLE_MGR = "CREATING_SUB_TABLE_MGR";
+
+ /** DOCUMENT_ME */
+ String EMITTING_MESSAGE = "EMITTING_MESSAGE";
+
+ /** DOCUMENT_ME */
+ String INVALID_SUBMGR_TABLE_TYPE = "INVALID_SUBMGR_TABLE_TYPE";
+
+ /** DOCUMENT_ME */
+ String MESSAGE_NOT_AVAILABLE_FOR_TOPIC = "MESSAGE_NOT_AVAILABLE_FOR_TOPIC";
+
+ /** DOCUMENT_ME */
+ String NULL_PROP_QNAME = "NULL_PROP_QNAME";
+
+ /** DOCUMENT_ME */
+ String NULL_SUBID_NOT_ALLOWED = "NULL_SUBID_NOT_ALLOWED";
+
+ /** DOCUMENT_ME */
+ String TOPIC_NOT_AVAILABLE_FOR_SUBSCRIPTION = "TOPIC_NOT_AVAILABLE_FOR_SUBSCRIPTION";
+
+ /** CREATING_NOTIF_EMITTER=Creating a notification emitter to destination=[{0}] */
+ String CREATING_NOTIF_EMITTER = "CREATING_NOTIF_EMITTER";
+
+ /** NOTIF_EMITTER_CREATION_FAILURE=Failed to create a notification emitter for destination [{0}]. Cause: {1} */
+ String NOTIF_EMITTER_CREATION_FAILURE = "NOTIF_EMITTER_CREATION_FAILURE";
+
+ /** UNSUPPORTED_PROTOCOL=Destination requires an unsupported protocol [{0}]; it will not receive notification [{1}] */
+ String UNSUPPORTED_PROTOCOL = "UNSUPPORTED_PROTOCOL";
+
+ /** BAD_TASK_CLASS_IS_ABSTRACT=Bad task class [{0}]; it must not be abstract. Cause: {1} */
+ String BAD_TASK_CLASS_IS_ABSTRACT = "BAD_TASK_CLASS_IS_ABSTRACT";
+
+ /** BAD_TASK_CLASS_ACCESS_DENIED=Bad task class [{0}]; access to the constructor was denied. Cause: {1} */
+ String BAD_TASK_CLASS_ACCESS_DENIED = "BAD_TASK_CLASS_ACCESS_DENIED";
+
+ /** TASK_CON_EXCEPTION=Task [{0}] constructor threw an exception: {1} */
+ String TASK_CON_EXCEPTION = "TASK_CON_EXCEPTION";
+
+ /** BAD_TASK_CLASS_NO_CON=Bad task class [{0}], missing required constructor. Cause: {1} */
+ String BAD_TASK_CLASS_NO_CON = "BAD_TASK_CLASS_NO_CON";
+
+ /** EMITTING_NOTIFICATION=Emitting notification: destination=[{0}], notification=[{1}] */
+ String EMITTING_NOTIFICATION = "EMITTING_NOTIFICATION";
+
+ /**
+ * @msg SOAP Response to emitted notification: [{0}]
+ **/
+ String RESPONSE_TO_EMIT = "RESPONSE_TO_EMIT";
+
+ /** EMISSION_FAILURE={0} failed to emit notification [{1}]. Cause: {2} */
+ String EMISSION_FAILURE = "EMISSION_FAILURE";
+
+ /** EX_NO_NOTIFICATIONS=No Notifications to emit! */
+ String EX_NO_NOTIFICATIONS = "EX_NO_NOTIFICATIONS";
+
+ /** EMITTING_TO_FILE=Emitting notification to file [{0}] */
+ String EMITTING_TO_FILE = "EMITTING_TO_FILE";
+
+ /** EX_FAILED_TO_STORE_NOTIFICATION_TO_FILE_BAD_URL=Failed to store notification to file, bad destination URL: [{0}] */
+ String EX_FAILED_TO_STORE_NOTIFICATION_TO_FILE_BAD_URL = "EX_FAILED_TO_STORE_NOTIFICATION_TO_FILE_BAD_URL";
+
+ /** EX_FAILED_TO_STORE_NOTIFICATION_TO_FILE=Failed to store notification to file: [{0}] */
+ String EX_FAILED_TO_STORE_NOTIFICATION_TO_FILE = "EX_FAILED_TO_STORE_NOTIFICATION_TO_FILE";
+
+ /** EMITTING_TO_HTTP_DEST=Emitting notification to HTTP destination [{0}] */
+ String EMITTING_TO_HTTP_DEST = "EMITTING_TO_HTTP_DEST";
+
+ /** EX_FAILED_TO_SEND_HTTP_NOTIFICATION_BAD_URL=Failed to send HTTP notification, bad destination URL: [{0}] */
+ String EX_FAILED_TO_SEND_HTTP_NOTIFICATION_BAD_URL = "EX_FAILED_TO_SEND_HTTP_NOTIFICATION_BAD_URL";
+
+ /** EX_FAILED_TO_SEND_HTTP_NOTIFICATION=Failed to send notification via HTTP: [{0}] */
+ String EX_FAILED_TO_SEND_HTTP_NOTIFICATION = "EX_FAILED_TO_SEND_HTTP_NOTIFICATION";
+
+ /** GETTING_SUBSCRIBERS=Getting subscribers on topic [{0}] */
+ String GETTING_SUBSCRIBERS = "GETTING_SUBSCRIBERS";
}
Modified: webservices/pubscribe/trunk/src/java/org/apache/ws/pubsub/i18n/MessagesImpl.java
URL: http://svn.apache.org/viewcvs/webservices/pubscribe/trunk/src/java/org/apache/ws/pubsub/i18n/MessagesImpl.java?rev=227035&r1=227034&r2=227035&view=diff
==============================================================================
--- webservices/pubscribe/trunk/src/java/org/apache/ws/pubsub/i18n/MessagesImpl.java (original)
+++ webservices/pubscribe/trunk/src/java/org/apache/ws/pubsub/i18n/MessagesImpl.java Tue Aug 2 09:41:00 2005
@@ -1,66 +1,66 @@
-/*=============================================================================*
- * 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.i18n;
-
-import org.apache.ws.util.i18n.AbstractMessages;
-import org.apache.ws.util.i18n.Messages;
-
-/**
- * Singleton used by all classes below the {@link org.apache.ws.pubsub} package
- * for retrieving i18n messages.
- *
- * @author Ian P. Springer
- */
-public class MessagesImpl
- extends AbstractMessages
-{
- /** the package name of the project */
- public static final String PROJECT_PACKAGE_NAME = "org.apache.ws.pubsub";
-
- /** package where the i18n stuff can be found */
- public static final String RESOURCE_PACKAGE_NAME = "org.apache.ws.pubsub.i18n";
- private static Messages s_ourInstance = new MessagesImpl( );
-
- /**
- * Returns this singleton.
- *
- * @return the singleton
- */
- public static Messages getInstance( )
- {
- return s_ourInstance;
- }
-
- /**
- * Returns the project's package name.
- *
- * @return project package name
- */
- protected String getProjectPackageName( )
- {
- return PROJECT_PACKAGE_NAME;
- }
-
- /**
- * Returns the package name where the i18n stuff can be found.
- *
- * @return resource package name
- */
- protected String getResourcePackageName( )
- {
- return RESOURCE_PACKAGE_NAME;
- }
+/*=============================================================================*
+ * 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.i18n;
+
+import org.apache.ws.util.i18n.AbstractMessages;
+import org.apache.ws.util.i18n.Messages;
+
+/**
+ * Singleton used by all classes below the {@link org.apache.ws.pubsub} package
+ * for retrieving i18n messages.
+ *
+ * @author Ian P. Springer
+ */
+public class MessagesImpl
+ extends AbstractMessages
+{
+ /** the package name of the project */
+ public static final String PROJECT_PACKAGE_NAME = "org.apache.ws.pubsub";
+
+ /** package where the i18n stuff can be found */
+ public static final String RESOURCE_PACKAGE_NAME = "org.apache.ws.pubsub.i18n";
+ private static Messages s_ourInstance = new MessagesImpl( );
+
+ /**
+ * Returns this singleton.
+ *
+ * @return the singleton
+ */
+ public static Messages getInstance( )
+ {
+ return s_ourInstance;
+ }
+
+ /**
+ * Returns the project's package name.
+ *
+ * @return project package name
+ */
+ protected String getProjectPackageName( )
+ {
+ return PROJECT_PACKAGE_NAME;
+ }
+
+ /**
+ * Returns the package name where the i18n stuff can be found.
+ *
+ * @return resource package name
+ */
+ protected String getResourcePackageName( )
+ {
+ return RESOURCE_PACKAGE_NAME;
+ }
}
Modified: webservices/pubscribe/trunk/src/java/org/apache/ws/pubsub/wsaSOAPConnection.java
URL: http://svn.apache.org/viewcvs/webservices/pubscribe/trunk/src/java/org/apache/ws/pubsub/wsaSOAPConnection.java?rev=227035&r1=227034&r2=227035&view=diff
==============================================================================
--- webservices/pubscribe/trunk/src/java/org/apache/ws/pubsub/wsaSOAPConnection.java (original)
+++ webservices/pubscribe/trunk/src/java/org/apache/ws/pubsub/wsaSOAPConnection.java Tue Aug 2 09:41:00 2005
@@ -1,61 +1,103 @@
-/*
- * Copyright 2001-2004 The Apache Software Foundation.
+/*=============================================================================*
+ * 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
+ * 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.
- */
+ * 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;
+
/**
*
* @author Stefan Lischke
*/
import org.apache.ws.addressing.EndpointReference;
-import javax.xml.soap.*;
-import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlCursor;
+import org.apache.xmlbeans.XmlObject;
import javax.xml.namespace.QName;
+import javax.xml.soap.*;
+
+/**
+ * DOCUMENT_ME
+ *
+ * @version $Revision: 1.8 $
+ * @author $author$
+ */
+public class wsaSOAPConnection
+{
+ /** Creates a new instance of wsaSOAPConnection */
+ public wsaSOAPConnection( )
+ {
+ }
+
+ /**
+ * @return The unique instance of this class.
+ */
+ public static wsaSOAPConnection newInstance( )
+ {
+ return new wsaSOAPConnection( );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param request DOCUMENT_ME
+ * @param url DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ *
+ * @throws SOAPException DOCUMENT_ME
+ */
+ public SOAPMessage call( SOAPMessage request,
+ String url )
+ throws SOAPException
+ {
+ SOAPConnectionFactory sconF = SOAPConnectionFactory.newInstance( );
+ SOAPConnection scon = sconF.createConnection( );
+ return ( scon.call( request, url ) );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param request DOCUMENT_ME
+ * @param epr DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ *
+ * @throws SOAPException DOCUMENT_ME
+ */
+ public SOAPMessage call( SOAPMessage request,
+ EndpointReference epr )
+ throws SOAPException
+ {
+ SOAPHeader sH = request.getSOAPHeader( );
+
+ //if epr contains ReferenceProperty add WSA header
+ XmlObject[] refprops = (XmlObject[]) epr.getReferenceProperties( );
+ if ( refprops != null )
+ {
+ for ( int i = 0; i < refprops.length; i++ )
+ {
+ XmlCursor xc = refprops[i].newCursor( );
+ QName propname = xc.getName( );
+ sH.addChildElement( propname.getLocalPart( ),
+ propname.getPrefix( ),
+ propname.getNamespaceURI( ) ).addTextNode( xc.getTextValue( ) );
+ xc.dispose( );
+ }
+ }
-public class wsaSOAPConnection {
-
- /** Creates a new instance of wsaSOAPConnection */
- public wsaSOAPConnection() {
- }
-
- /**
- * @return The unique instance of this class.
- */
-
- static public wsaSOAPConnection newInstance() {
- return new wsaSOAPConnection();
- }
-
- public SOAPMessage call(SOAPMessage request, String url ) throws SOAPException{
- SOAPConnectionFactory sconF= SOAPConnectionFactory.newInstance();
- SOAPConnection scon = sconF.createConnection();
- return(scon.call(request, url));
- }
- public SOAPMessage call(SOAPMessage request,EndpointReference epr) throws SOAPException{
- SOAPHeader sH = request.getSOAPHeader();
- //if epr contains ReferenceProperty add WSA header
- XmlObject[] refprops = (XmlObject[])epr.getReferenceProperties();
- if(refprops!=null){
- for(int i=0;i<refprops.length;i++){
- XmlCursor xc = refprops[i].newCursor();
- QName propname = xc.getName();
- sH.addChildElement(propname.getLocalPart(),propname.getPrefix(),propname.getNamespaceURI()).addTextNode(xc.getTextValue());
- xc.dispose();
- }
- }
- return(call(request,epr.getAddress()));
- }
-}
+ return ( call( request,
+ epr.getAddress( ) ) );
+ }
+}
\ No newline at end of file
Modified: webservices/pubscribe/trunk/src/java/org/apache/ws/util/test/PortListen.java
URL: http://svn.apache.org/viewcvs/webservices/pubscribe/trunk/src/java/org/apache/ws/util/test/PortListen.java?rev=227035&r1=227034&r2=227035&view=diff
==============================================================================
--- webservices/pubscribe/trunk/src/java/org/apache/ws/util/test/PortListen.java (original)
+++ webservices/pubscribe/trunk/src/java/org/apache/ws/util/test/PortListen.java Tue Aug 2 09:41:00 2005
@@ -1,292 +1,312 @@
-package org.apache.ws.util.test;
-
-/*=============================================================================*
- * 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.
- *=============================================================================*/
-
-import java.io.BufferedOutputStream;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.InterruptedIOException;
-import java.net.ServerSocket;
-import java.net.Socket;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Locale;
-import java.util.TimeZone;
-
-/**
- * Single-message HTTP listener. When this object is instantiated, it will spawn
- * a thread and listen for a message on the specified port. Call
- * {@link #waitForIncomingMessage()} to block, waiting for the message.
- *
- * @author mazz
- * @author ips
- */
-public class PortListen
-{
-
- private static final DateFormat HTTP_DATE_FORMAT = new SimpleDateFormat(
- "EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US );
-
- static
- {
- HTTP_DATE_FORMAT.setTimeZone( TimeZone.getTimeZone( "GMT" ) );
- }
-
- /**
- * the buffer to store the incoming message
- */
- private StringBuffer m_incomingMessage;
-
- /**
- * Instantiates the object and immediately begins listening for a message.
- *
- * @param port the port to listen to; a value of <code>0</code> creates a socket on any free port
- * @param timeout the time (in milliseconds) the socket accept() will wait for an incoming connection;
- * a value of <code>0</code> indicates accept() should wait infinitely
- */
- public PortListen( int port,
- int timeout )
- {
- m_incomingMessage = new StringBuffer();
- // spawn the thread
- getIncomingMessage( port, timeout, m_incomingMessage );
- }
-
- /**
- * Waits for the incoming message.
- * <p/>
- * This method will block waiting for the incoming message to come in or for an error to occur.
- *
- * @return the incoming message as a string
- */
- public String waitForIncomingMessage()
- {
- synchronized ( m_incomingMessage )
- {
- while ( m_incomingMessage.length() == 0 )
- {
- try
- {
- m_incomingMessage.wait( 1000 );
- }
- catch ( InterruptedException ignored )
- {
- }
- }
- }
-
- return m_incomingMessage.toString();
- }
-
- /**
- * Listens for an incoming TCP/IP message. When an incoming message is received, it is stored in the
- * <code>retIncomingMessage</code> string buffer and <code>notify</code> on that string buffer will be called to let
- * the caller know that it is ready.
- * <p/>
- * The incoming message string buffer must be non-<code>null</code> and must be empty.
- * <p/>
- * If an error occurs, the string buffer will be filled with the string "ERROR:" followed by the exception message.
- * Even on an error, <code>notify</code> will be called to let the caller know that something happened.
- * <p/>
- * Note that this method does not block - it spawns a thread to perform the listening and returns immediately.
- * <p/>
- * This will return an HTTP server-like response back to the client.
- *
- * @param port the port to listen to
- * @param timeout the time (in milliseconds) the socket accept() will wait for an incoming connection
- * @param retIncomingMessage the incoming message to be returned to the caller - this buffer will be filled in and
- * <code>notify</code> will be called on it to let the caller know that it is ready
- *
- * @throws IllegalArgumentException if the given buffer was <code>null</code> or not empty
- */
- protected void getIncomingMessage( final int port,
- final int timeout,
- final StringBuffer retIncomingMessage )
- throws IllegalArgumentException
- {
- if ( retIncomingMessage == null || retIncomingMessage.length() > 0 )
- {
- throw new IllegalArgumentException( "Must provide a non-null string buffer that is empty" );
- }
-
- // use as a monitor lock to determine when the thread has started
- // this must be final to allow for the inner Runnable class to access it
- final Object listenerStarted = new Object();
-
- Thread listener =
- new Thread( new Runnable()
- {
- private static final String HTTP_SERVER_NAME = "WS-NotificationConsumer/1.0";
- private static final String HTTP_VERSION = "1.0";
- private static final String HTTP_STATUS = "202 Accepted";
-
- public void run()
- {
- ServerSocket server = null;
-
- try
- {
- server = new ServerSocket( port );
- server.setSoTimeout( timeout );
-
- // let the outer method know that we have started and just about to block on the accept
- synchronized ( listenerStarted )
- {
- listenerStarted.notify();
- }
-
- Socket sock = server.accept();
- sock.setSoTimeout( 500 );
- BufferedReader bufIn = new BufferedReader(
- new InputStreamReader( sock.getInputStream() ) );
- BufferedOutputStream bufOut = new BufferedOutputStream( sock.getOutputStream() );
-
- byte[] responseBytes = buildResponse().toString().getBytes();
-
- try
- {
- synchronized ( retIncomingMessage )
- {
- while ( !bufIn.readLine().equals( "" ) ) // skip empty lines
- {
- }
- char[] buffer = new char[10240];
- int length = -1;
- while ( ( length = bufIn.read( buffer, 0, buffer.length ) ) != -1 )
- {
- retIncomingMessage.append( buffer, 0, length );
- }
- }
- }
- catch ( InterruptedIOException ignored )
- {
- }
- bufOut.write( responseBytes, 0, responseBytes.length );
- bufOut.flush();
- bufIn.close();
- bufOut.close();
- }
- catch ( Throwable t )
- {
- synchronized ( retIncomingMessage )
- {
- retIncomingMessage.delete( 0,
- retIncomingMessage.length() );
- retIncomingMessage.append( "ERROR: " );
- retIncomingMessage.append( t );
- }
- }
- finally
- {
- synchronized ( retIncomingMessage )
- {
- // make sure something goes in the message, even if nothing was received
- if ( retIncomingMessage.length() == 0 )
- {
- retIncomingMessage.append( "ERROR: incoming message was empty" );
- }
-
- retIncomingMessage.notify();
- }
-
- if ( server != null )
- {
- try
- {
- server.close();
- }
- catch ( IOException ignored )
- {
- }
- }
-
- // do this as a fail safe
- synchronized ( listenerStarted )
- {
- listenerStarted.notify();
- }
- }
-
- }
-
- /**
- * Build a one-way HTTP response message that complies to the WS-I Basic Profile 1.0, section 5.6.10
- * - see http://www.ws-i.org/Profiles/BasicProfile-1.0-2004-04-16.html#refinement16651160
- *
- * @return a WS-I-compliant Notify response message
- */
- private String buildResponse()
- {
- Date timeNow = new Date();
- Date sameTimeTomorrow = new Date( timeNow.getTime() + ( 24 * 60 * 60 * 1000 ) );
- StringBuffer responseBuf = new StringBuffer( "HTTP/" );
- responseBuf.append( HTTP_VERSION );
- responseBuf.append( " " );
- responseBuf.append( HTTP_STATUS );
- responseBuf.append( "\r\n" );
-
- responseBuf.append( "Date: " );
- responseBuf.append( HTTP_DATE_FORMAT.format( timeNow ) );
- responseBuf.append( "\r\n" );
-
- responseBuf.append( "Server: " );
- responseBuf.append( HTTP_SERVER_NAME );
- responseBuf.append( "\r\n" );
-
- responseBuf.append( "Cache-Control: " );
- responseBuf.append( "max-age=86400" );
- responseBuf.append( "\r\n" );
-
- responseBuf.append( "Expires: " );
- responseBuf.append( HTTP_DATE_FORMAT.format( sameTimeTomorrow ) );
- responseBuf.append( "\r\n" );
-
- return responseBuf.toString();
- }
- } );
-
- // start listening and then return when the thread has officially gone live
- // and the socket is ready to be accepted
- synchronized ( listenerStarted )
- {
- listener.start();
-
- try
- {
- listenerStarted.wait();
- }
- catch ( InterruptedException ignored )
- {
- }
- }
- }
-
- public static void main( String[] args )
- {
- int port = args.length >= 1 ? Integer.valueOf( args[0] ).intValue() : 0;
- int timeout = args.length >= 2 ? Integer.valueOf( args[1] ).intValue() : 0;
- PortListen portListen = new PortListen( port, timeout );
- System.out.println( "Listening for notification on port " + port + "..." );
- String msg = portListen.waitForIncomingMessage();
- System.out.println( "Received notification! SOAP message follows..." );
- System.out.println( msg );
- System.out.println( "Listener stopped." );
- }
-
-}
+/*=============================================================================*
+ * 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.util.test;
+
+
+/*=============================================================================*
+ * 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.
+ *=============================================================================*/
+import java.io.BufferedOutputStream;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.InterruptedIOException;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+import java.util.TimeZone;
+
+/**
+ * Single-message HTTP listener. When this object is instantiated, it will spawn
+ * a thread and listen for a message on the specified port. Call
+ * {@link #waitForIncomingMessage()} to block, waiting for the message.
+ *
+ * @author mazz
+ * @author ips
+ */
+public class PortListen
+{
+ private static final DateFormat HTTP_DATE_FORMAT =
+ new SimpleDateFormat( "EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US );
+
+ static
+ {
+ HTTP_DATE_FORMAT.setTimeZone( TimeZone.getTimeZone( "GMT" ) );
+ }
+
+ /**
+ * the buffer to store the incoming message
+ */
+ private StringBuffer m_incomingMessage;
+
+ /**
+ * Instantiates the object and immediately begins listening for a message.
+ *
+ * @param port the port to listen to; a value of <code>0</code> creates a socket on any free port
+ * @param timeout the time (in milliseconds) the socket accept() will wait for an incoming connection;
+ * a value of <code>0</code> indicates accept() should wait infinitely
+ */
+ public PortListen( int port,
+ int timeout )
+ {
+ m_incomingMessage = new StringBuffer( );
+
+ // spawn the thread
+ getIncomingMessage( port, timeout, m_incomingMessage );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param args DOCUMENT_ME
+ */
+ public static void main( String[] args )
+ {
+ int port = ( args.length >= 1 ) ? Integer.valueOf( args[0] ).intValue( ) : 0;
+ int timeout = ( args.length >= 2 ) ? Integer.valueOf( args[1] ).intValue( ) : 0;
+ PortListen portListen = new PortListen( port, timeout );
+ System.out.println( "Listening for notification on port " + port + "..." );
+ String msg = portListen.waitForIncomingMessage( );
+ System.out.println( "Received notification! SOAP message follows..." );
+ System.out.println( msg );
+ System.out.println( "Listener stopped." );
+ }
+
+ /**
+ * Waits for the incoming message.
+ * <p/>
+ * This method will block waiting for the incoming message to come in or for an error to occur.
+ *
+ * @return the incoming message as a string
+ */
+ public String waitForIncomingMessage( )
+ {
+ synchronized ( m_incomingMessage )
+ {
+ while ( m_incomingMessage.length( ) == 0 )
+ {
+ try
+ {
+ m_incomingMessage.wait( 1000 );
+ }
+ catch ( InterruptedException ignored )
+ {
+ }
+ }
+ }
+
+ return m_incomingMessage.toString( );
+ }
+
+ /**
+ * Listens for an incoming TCP/IP message. When an incoming message is received, it is stored in the
+ * <code>retIncomingMessage</code> string buffer and <code>notify</code> on that string buffer will be called to let
+ * the caller know that it is ready.
+ * <p/>
+ * The incoming message string buffer must be non-<code>null</code> and must be empty.
+ * <p/>
+ * If an error occurs, the string buffer will be filled with the string "ERROR:" followed by the exception message.
+ * Even on an error, <code>notify</code> will be called to let the caller know that something happened.
+ * <p/>
+ * Note that this method does not block - it spawns a thread to perform the listening and returns immediately.
+ * <p/>
+ * This will return an HTTP server-like response back to the client.
+ *
+ * @param port the port to listen to
+ * @param timeout the time (in milliseconds) the socket accept() will wait for an incoming connection
+ * @param retIncomingMessage the incoming message to be returned to the caller - this buffer will be filled in and
+ * <code>notify</code> will be called on it to let the caller know that it is ready
+ *
+ * @throws IllegalArgumentException if the given buffer was <code>null</code> or not empty
+ */
+ protected void getIncomingMessage( final int port,
+ final int timeout,
+ final StringBuffer retIncomingMessage )
+ throws IllegalArgumentException
+ {
+ if ( ( retIncomingMessage == null ) || ( retIncomingMessage.length( ) > 0 ) )
+ {
+ throw new IllegalArgumentException( "Must provide a non-null string buffer that is empty" );
+ }
+
+ // use as a monitor lock to determine when the thread has started
+ // this must be final to allow for the inner Runnable class to access it
+ final Object listenerStarted = new Object( );
+
+ Thread listener =
+ new Thread( new Runnable( )
+ {
+ private static final String HTTP_SERVER_NAME = "WS-NotificationConsumer/1.0";
+ private static final String HTTP_VERSION = "1.0";
+ private static final String HTTP_STATUS = "202 Accepted";
+
+ public void run( )
+ {
+ ServerSocket server = null;
+
+ try
+ {
+ server = new ServerSocket( port );
+ server.setSoTimeout( timeout );
+
+ // let the outer method know that we have started and just about to block on the accept
+ synchronized ( listenerStarted )
+ {
+ listenerStarted.notify( );
+ }
+
+ Socket sock = server.accept( );
+ sock.setSoTimeout( 500 );
+ BufferedReader bufIn =
+ new BufferedReader( new InputStreamReader( sock.getInputStream( ) ) );
+ BufferedOutputStream bufOut = new BufferedOutputStream( sock.getOutputStream( ) );
+
+ byte[] responseBytes = buildResponse( ).toString( ).getBytes( );
+
+ try
+ {
+ synchronized ( retIncomingMessage )
+ {
+ while ( !bufIn.readLine( ).equals( "" ) ) // skip empty lines
+ {
+ }
+
+ char[] buffer = new char[10240];
+ int length = -1;
+ while ( ( length = bufIn.read( buffer, 0, buffer.length ) ) != -1 )
+ {
+ retIncomingMessage.append( buffer, 0, length );
+ }
+ }
+ }
+ catch ( InterruptedIOException ignored )
+ {
+ }
+
+ bufOut.write( responseBytes, 0, responseBytes.length );
+ bufOut.flush( );
+ bufIn.close( );
+ bufOut.close( );
+ }
+ catch ( Throwable t )
+ {
+ synchronized ( retIncomingMessage )
+ {
+ retIncomingMessage.delete( 0,
+ retIncomingMessage.length( ) );
+ retIncomingMessage.append( "ERROR: " );
+ retIncomingMessage.append( t );
+ }
+ }
+ finally
+ {
+ synchronized ( retIncomingMessage )
+ {
+ // make sure something goes in the message, even if nothing was received
+ if ( retIncomingMessage.length( ) == 0 )
+ {
+ retIncomingMessage.append( "ERROR: incoming message was empty" );
+ }
+
+ retIncomingMessage.notify( );
+ }
+
+ if ( server != null )
+ {
+ try
+ {
+ server.close( );
+ }
+ catch ( IOException ignored )
+ {
+ }
+ }
+
+ // do this as a fail safe
+ synchronized ( listenerStarted )
+ {
+ listenerStarted.notify( );
+ }
+ }
+ }
+
+ /**
+ * Build a one-way HTTP response message that complies to the WS-I Basic Profile 1.0, section 5.6.10
+ * - see http://www.ws-i.org/Profiles/BasicProfile-1.0-2004-04-16.html#refinement16651160
+ *
+ * @return a WS-I-compliant Notify response message
+ */
+ private String buildResponse( )
+ {
+ Date timeNow = new Date( );
+ Date sameTimeTomorrow = new Date( timeNow.getTime( ) + ( 24 * 60 * 60 * 1000 ) );
+ StringBuffer responseBuf = new StringBuffer( "HTTP/" );
+ responseBuf.append( HTTP_VERSION );
+ responseBuf.append( " " );
+ responseBuf.append( HTTP_STATUS );
+ responseBuf.append( "\r\n" );
+
+ responseBuf.append( "Date: " );
+ responseBuf.append( HTTP_DATE_FORMAT.format( timeNow ) );
+ responseBuf.append( "\r\n" );
+
+ responseBuf.append( "Server: " );
+ responseBuf.append( HTTP_SERVER_NAME );
+ responseBuf.append( "\r\n" );
+
+ responseBuf.append( "Cache-Control: " );
+ responseBuf.append( "max-age=86400" );
+ responseBuf.append( "\r\n" );
+
+ responseBuf.append( "Expires: " );
+ responseBuf.append( HTTP_DATE_FORMAT.format( sameTimeTomorrow ) );
+ responseBuf.append( "\r\n" );
+
+ return responseBuf.toString( );
+ }
+ } );
+
+ // start listening and then return when the thread has officially gone live
+ // and the socket is ready to be accepted
+ synchronized ( listenerStarted )
+ {
+ listener.start( );
+
+ try
+ {
+ listenerStarted.wait( );
+ }
+ catch ( InterruptedException ignored )
+ {
+ }
+ }
+ }
+}
\ No newline at end of file
Modified: webservices/pubscribe/trunk/src/java/org/apache/ws/util/thread/NamedThread.java
URL: http://svn.apache.org/viewcvs/webservices/pubscribe/trunk/src/java/org/apache/ws/util/thread/NamedThread.java?rev=227035&r1=227034&r2=227035&view=diff
==============================================================================
--- webservices/pubscribe/trunk/src/java/org/apache/ws/util/thread/NamedThread.java (original)
+++ webservices/pubscribe/trunk/src/java/org/apache/ws/util/thread/NamedThread.java Tue Aug 2 09:41:00 2005
@@ -1,250 +1,250 @@
-/*=============================================================================*
- * 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.util.thread;
-
-import EDU.oswego.cs.dl.util.concurrent.ThreadFactory;
-
-/**
- * Subclass of {@link java.lang.Thread} that provides commonly named threads for
- * use inside a particular software application.
- * <p/>
- * The main purpose of this class is to provide all threads
- * running in the software with a consistent naming convention. When instantiating
- * a <code>NamedThread</code>, if a name is provided, that name will be used as the
- * base name for the thread. The base name will be decorated with additional information
- * to make the thread name unique.
- */
-public class NamedThread
- extends Thread
-{
- /** all thread names will have this string as a prefix */
- public static final String THREAD_NAME_PREFIX = "pubscribe.thread.";
-
- /** number of named threads that have been created */
- private static long s_threadCount = 0L;
-
- /** base name used to create this thread; or <code>null</code> if no name was specified */
- private final String m_baseName;
-
- /**
- * Creates the thread with an empty base name.
- *
- * @see java.lang.Thread#Thread(java.lang.String)
- */
- public NamedThread( )
- {
- super( createThreadName( null ) );
- m_baseName = null;
- }
-
- /**
- * Creates the thread with an empty base name.
- *
- * @see java.lang.Thread#Thread(java.lang.Runnable)
- */
- public NamedThread( Runnable target )
- {
- super( target,
- createThreadName( null ) );
- m_baseName = null;
- }
-
- /**
- * Creates the thread with an empty base name.
- *
- * @see java.lang.Thread#Thread(java.lang.ThreadGroup, java.lang.Runnable)
- */
- public NamedThread( ThreadGroup group,
- Runnable target )
- {
- super( group, target,
- createThreadName( null ) );
- m_baseName = null;
- }
-
- /**
- * Creates the thread with the given name to be used as the base name.
- *
- * @see java.lang.Thread#Thread(java.lang.String)
- */
- public NamedThread( String name )
- {
- super( createThreadName( name ) );
- m_baseName = name;
- }
-
- /**
- * Creates the thread with the given name to be used as the base name.
- *
- * @see java.lang.Thread#Thread(java.lang.ThreadGroup, java.lang.String)
- */
- public NamedThread( ThreadGroup group,
- String name )
- {
- super( group,
- createThreadName( name ) );
- m_baseName = name;
- }
-
- /**
- * Creates the thread with the given name to be used as the base name.
- *
- * @see java.lang.Thread#Thread(java.lang.Runnable, java.lang.String)
- */
- public NamedThread( Runnable target,
- String name )
- {
- super( target,
- createThreadName( name ) );
- m_baseName = name;
- }
-
- /**
- * Creates the thread with the given name to be used as the base name.
- *
- * @see java.lang.Thread#Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String)
- */
- public NamedThread( ThreadGroup group,
- Runnable target,
- String name )
- {
- super( group, target,
- createThreadName( name ) );
- m_baseName = name;
- }
-
- /**
- * Returns the base name used to create the thread. To get the actual name
- * of the thread, use {@link java.lang.Thread#getName()}. If no name was
- * passed into a constructor, or if null was passed, then null is returned.
- *
- * @return base name of the thread (the name passed into the constructor)
- */
- public String getBaseName( )
- {
- return m_baseName;
- }
-
- /**
- * Builds a thread name that is unique to the JVM.
- * The base name provided will be used as part of the thread
- * name to further describe the thread's purpose. If the base name is
- * null, it will not be used.
- *
- * @param baseName thread's base name
- *
- * @return String a String that can be used as a thread name
- */
- protected static String createThreadName( String baseName )
- {
- String name;
- long thread_num;
-
- synchronized ( THREAD_NAME_PREFIX )
- { // really we want to synchronize on m_threadCount, but its a primitive
-
- // so just use THREAD_NAME_PREFIX as a monitor lock
- thread_num = s_threadCount++;
- }
-
- name = THREAD_NAME_PREFIX + thread_num;
-
- if ( baseName != null )
- {
- name += ( "." + baseName );
- }
-
- return name;
- }
-
- /**
- * A thread factory for use with the Concurrent API. This factory creates threads
- * of type {@link NamedThread} and provides the ability to name the threads via the
- * base name facility of {@link NamedThread}. Threads created by this
- * factory may be daemon threads if desired
- * (see {@link ConcurrentThreadFactory#ConcurrentThreadFactory(String, boolean)}).
- */
- public static class ConcurrentThreadFactory
- implements ThreadFactory
- {
- /** the base name this factory will use for all of its threads */
- private String m_factoryBaseName;
-
- /** determines if all threads created by this factory are daemon threads or not */
- private boolean m_isDaemon;
-
- /**
- * Creates a factory that does not define a base name for the user threads it will create.
- */
- public ConcurrentThreadFactory( )
- {
- this( null, false );
- }
-
- /**
- * Creates a factory that defines a base name for the user threads it will create.
- *
- * @param baseName the base name used for all threads created by this factory (may be <code>null</code>)
- *
- * @see NamedThread#getBaseName()
- */
- public ConcurrentThreadFactory( String baseName )
- {
- this( baseName, false );
- }
-
- /**
- * Creates a factory that does not define a base name for the threads it will create but explicitly
- * defines whether or not the threads will be daemon or user threads.
- *
- * @param isDaemon if <code>true</code> then all threads created by this factory will be daemon threads.
- */
- public ConcurrentThreadFactory( boolean isDaemon )
- {
- this( null, isDaemon );
- }
-
- /**
- * Creates a factory that defines the new threads' base names and whether or not the threads to be
- * created will be daemon or user threads.
- *
- * @param baseName the base name used for all threads created by this factory (may be <code>null</code>)
- * @param isDaemon if <code>true</code> then all threads created by this factory will be daemon threads.
- */
- public ConcurrentThreadFactory( String baseName,
- boolean isDaemon )
- {
- m_factoryBaseName = baseName;
- m_isDaemon = isDaemon;
- }
-
- /**
- * Creates a {@link NamedThread} using this factory's base name as the new thread's base name.
- *
- * @see ThreadFactory#newThread(java.lang.Runnable)
- * @see NamedThread#NamedThread(Runnable, String)
- * @see NamedThread#getBaseName()
- */
- public Thread newThread( Runnable command )
- {
- NamedThread retNewThread = new NamedThread( command, m_factoryBaseName );
-
- retNewThread.setDaemon( m_isDaemon );
-
- return retNewThread;
- }
- }
-}
+/*=============================================================================*
+ * 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.util.thread;
+
+import EDU.oswego.cs.dl.util.concurrent.ThreadFactory;
+
+/**
+ * Subclass of {@link java.lang.Thread} that provides commonly named threads for
+ * use inside a particular software application.
+ * <p/>
+ * The main purpose of this class is to provide all threads
+ * running in the software with a consistent naming convention. When instantiating
+ * a <code>NamedThread</code>, if a name is provided, that name will be used as the
+ * base name for the thread. The base name will be decorated with additional information
+ * to make the thread name unique.
+ */
+public class NamedThread
+ extends Thread
+{
+ /** all thread names will have this string as a prefix */
+ public static final String THREAD_NAME_PREFIX = "pubscribe.thread.";
+
+ /** number of named threads that have been created */
+ private static long s_threadCount = 0L;
+
+ /** base name used to create this thread; or <code>null</code> if no name was specified */
+ private final String m_baseName;
+
+ /**
+ * Creates the thread with an empty base name.
+ *
+ * @see java.lang.Thread#Thread(java.lang.String)
+ */
+ public NamedThread( )
+ {
+ super( createThreadName( null ) );
+ m_baseName = null;
+ }
+
+ /**
+ * Creates the thread with an empty base name.
+ *
+ * @see java.lang.Thread#Thread(java.lang.Runnable)
+ */
+ public NamedThread( Runnable target )
+ {
+ super( target,
+ createThreadName( null ) );
+ m_baseName = null;
+ }
+
+ /**
+ * Creates the thread with an empty base name.
+ *
+ * @see java.lang.Thread#Thread(java.lang.ThreadGroup, java.lang.Runnable)
+ */
+ public NamedThread( ThreadGroup group,
+ Runnable target )
+ {
+ super( group, target,
+ createThreadName( null ) );
+ m_baseName = null;
+ }
+
+ /**
+ * Creates the thread with the given name to be used as the base name.
+ *
+ * @see java.lang.Thread#Thread(java.lang.String)
+ */
+ public NamedThread( String name )
+ {
+ super( createThreadName( name ) );
+ m_baseName = name;
+ }
+
+ /**
+ * Creates the thread with the given name to be used as the base name.
+ *
+ * @see java.lang.Thread#Thread(java.lang.ThreadGroup, java.lang.String)
+ */
+ public NamedThread( ThreadGroup group,
+ String name )
+ {
+ super( group,
+ createThreadName( name ) );
+ m_baseName = name;
+ }
+
+ /**
+ * Creates the thread with the given name to be used as the base name.
+ *
+ * @see java.lang.Thread#Thread(java.lang.Runnable, java.lang.String)
+ */
+ public NamedThread( Runnable target,
+ String name )
+ {
+ super( target,
+ createThreadName( name ) );
+ m_baseName = name;
+ }
+
+ /**
+ * Creates the thread with the given name to be used as the base name.
+ *
+ * @see java.lang.Thread#Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String)
+ */
+ public NamedThread( ThreadGroup group,
+ Runnable target,
+ String name )
+ {
+ super( group, target,
+ createThreadName( name ) );
+ m_baseName = name;
+ }
+
+ /**
+ * Returns the base name used to create the thread. To get the actual name
+ * of the thread, use {@link java.lang.Thread#getName()}. If no name was
+ * passed into a constructor, or if null was passed, then null is returned.
+ *
+ * @return base name of the thread (the name passed into the constructor)
+ */
+ public String getBaseName( )
+ {
+ return m_baseName;
+ }
+
+ /**
+ * Builds a thread name that is unique to the JVM.
+ * The base name provided will be used as part of the thread
+ * name to further describe the thread's purpose. If the base name is
+ * null, it will not be used.
+ *
+ * @param baseName thread's base name
+ *
+ * @return String a String that can be used as a thread name
+ */
+ protected static String createThreadName( String baseName )
+ {
+ String name;
+ long thread_num;
+
+ synchronized ( THREAD_NAME_PREFIX )
+ { // really we want to synchronize on m_threadCount, but its a primitive
+
+ // so just use THREAD_NAME_PREFIX as a monitor lock
+ thread_num = s_threadCount++;
+ }
+
+ name = THREAD_NAME_PREFIX + thread_num;
+
+ if ( baseName != null )
+ {
+ name += ( "." + baseName );
+ }
+
+ return name;
+ }
+
+ /**
+ * A thread factory for use with the Concurrent API. This factory creates threads
+ * of type {@link NamedThread} and provides the ability to name the threads via the
+ * base name facility of {@link NamedThread}. Threads created by this
+ * factory may be daemon threads if desired
+ * (see {@link ConcurrentThreadFactory#ConcurrentThreadFactory(String, boolean)}).
+ */
+ public static class ConcurrentThreadFactory
+ implements ThreadFactory
+ {
+ /** the base name this factory will use for all of its threads */
+ private String m_factoryBaseName;
+
+ /** determines if all threads created by this factory are daemon threads or not */
+ private boolean m_isDaemon;
+
+ /**
+ * Creates a factory that does not define a base name for the user threads it will create.
+ */
+ public ConcurrentThreadFactory( )
+ {
+ this( null, false );
+ }
+
+ /**
+ * Creates a factory that defines a base name for the user threads it will create.
+ *
+ * @param baseName the base name used for all threads created by this factory (may be <code>null</code>)
+ *
+ * @see NamedThread#getBaseName()
+ */
+ public ConcurrentThreadFactory( String baseName )
+ {
+ this( baseName, false );
+ }
+
+ /**
+ * Creates a factory that does not define a base name for the threads it will create but explicitly
+ * defines whether or not the threads will be daemon or user threads.
+ *
+ * @param isDaemon if <code>true</code> then all threads created by this factory will be daemon threads.
+ */
+ public ConcurrentThreadFactory( boolean isDaemon )
+ {
+ this( null, isDaemon );
+ }
+
+ /**
+ * Creates a factory that defines the new threads' base names and whether or not the threads to be
+ * created will be daemon or user threads.
+ *
+ * @param baseName the base name used for all threads created by this factory (may be <code>null</code>)
+ * @param isDaemon if <code>true</code> then all threads created by this factory will be daemon threads.
+ */
+ public ConcurrentThreadFactory( String baseName,
+ boolean isDaemon )
+ {
+ m_factoryBaseName = baseName;
+ m_isDaemon = isDaemon;
+ }
+
+ /**
+ * Creates a {@link NamedThread} using this factory's base name as the new thread's base name.
+ *
+ * @see ThreadFactory#newThread(java.lang.Runnable)
+ * @see NamedThread#NamedThread(Runnable, String)
+ * @see NamedThread#getBaseName()
+ */
+ public Thread newThread( Runnable command )
+ {
+ NamedThread retNewThread = new NamedThread( command, m_factoryBaseName );
+
+ retNewThread.setDaemon( m_isDaemon );
+
+ return retNewThread;
+ }
+ }
+}
\ No newline at end of file