Re: Pluggable WSIFServiceFactories
Paul Russell <[email protected]>
| Newsgroups | gmane.comp.apache.webservices.wsif.devel |
|---|---|
| Message-ID | <[email protected]> |
Nirmal, Thanks for your reply. Attached is a patch for this. I'm quite new to WSIF, so I'm not clear how you deal with patches (I know that other projects use Jira or similar). I couldn't find anywhere other than this mailing lists to put this patch, so I've attached it here; apologies if this isn't the right forum! Couple of things to bear in mind about this: * I've made minor modifications (mainly around logging etc) since I made the initial change. I'm working on this from home (can't get to CVS to do a diff at work), and the only place I can test this properly is at work. I'll make sure this happens tomorrow, and will e-mail to confirm this passed okay. Probably best not to commit the change until this is complete. * I tried to run the automated unit tests, but they failed to compile. Is this expected, or have I broken something? * I noticed while I was making this change that the WSIFProperties class caches the Properties instance once it has been built. While I can totally see why this a good thing from a performance point of view, I can see this causing problems if you try and use WSIF in an environment where there are multiple context class loaders, all of which could potentially want to call WSIF. I think this may apply to the work I'm doing, although I'm not far enough down the line to be sure yet. I'll let you know if this turns out to be a problem. If it does turn out to be a problem, I can't see any reason why we can't cache the properties instance in a Map keyed against the context classloader instance. Thanks, let me know if the patch is any use or not... Paul On 27 Jan 2004, at 15:23, Nirmal Mukhi wrote: > > Hi, > > Introduction of custom service factories was taken out for efficiency > reasons at one point, but I support it as being a good thing, since I > think the use far outweighs the reduction in performance. Why don't > you submit the patch so the committers can vote on it? Hopefully it > will pass that vote and if so I'll commit it to the codebase. > > Thanks, > Nirmal. > -- Paul Russell [email protected]
WSIFServiceFactorySupport.diff
(application/octet-stream, 4 KB)
Index: java/src/org/apache/wsif/WSIFServiceFactory.java
===================================================================
RCS file: /home/cvspublic/ws-wsif/java/src/org/apache/wsif/WSIFServiceFactory.java,v
retrieving revision 1.12
diff -u -r1.12 WSIFServiceFactory.java
--- java/src/org/apache/wsif/WSIFServiceFactory.java 6 Mar 2003 15:54:40 -0000 1.12
+++ java/src/org/apache/wsif/WSIFServiceFactory.java 27 Jan 2004 22:56:57 -0000
@@ -63,7 +63,9 @@
import javax.wsdl.Service;
import org.apache.wsif.base.WSIFServiceFactoryImpl;
+import org.apache.wsif.logging.MessageLogger;
import org.apache.wsif.logging.Trc;
+import org.apache.wsif.util.WSIFProperties;
import org.apache.wsif.util.WSIFUtils;
/**
@@ -75,6 +77,8 @@
*/
public abstract class WSIFServiceFactory {
+ private static final String SERVICE_FACTORY_PROPERTY = "wsif.servicefactory";
+
/**
* Creates a new instance of an implementation the abstract
* WSIFServiceFactory class.
@@ -82,7 +86,28 @@
public static WSIFServiceFactory newInstance() {
Trc.entry(null);
- WSIFServiceFactoryImpl wsf = new WSIFServiceFactoryImpl();
+ WSIFServiceFactory wsf;
+
+ String serviceFactoryName = WSIFProperties.getProperty(SERVICE_FACTORY_PROPERTY);
+ if ( serviceFactoryName == null ) {
+ wsf = new WSIFServiceFactoryImpl();
+ } else {
+ try {
+ wsf = (WSIFServiceFactory)Thread.currentThread().getContextClassLoader().loadClass(serviceFactoryName).newInstance();
+ } catch (InstantiationException e) {
+ Trc.exception(e);
+ MessageLogger.log("WSIF.0012W",new String[] {serviceFactoryName,e.getClass().getName(),e.getMessage()});
+ wsf = new WSIFServiceFactoryImpl();
+ } catch (IllegalAccessException e) {
+ Trc.exception(e);
+ MessageLogger.log("WSIF.0012W",new String[] {serviceFactoryName,e.getClass().getName(),e.getMessage()});
+ wsf = new WSIFServiceFactoryImpl();
+ } catch (ClassNotFoundException e) {
+ Trc.exception(e);
+ MessageLogger.log("WSIF.0012W",new String[] {serviceFactoryName,e.getClass().getName(),e.getMessage()});
+ wsf = new WSIFServiceFactoryImpl();
+ }
+ }
// Create the simple types map for use by other WSIF classes
WSIFUtils.createSimpleTypesMap();
Index: java/src/org/apache/wsif/catalog/Messages.properties
===================================================================
RCS file: /home/cvspublic/ws-wsif/java/src/org/apache/wsif/catalog/Messages.properties,v
retrieving revision 1.7
diff -u -r1.7 Messages.properties
--- java/src/org/apache/wsif/catalog/Messages.properties 7 Dec 2002 12:33:57 -0000 1.7
+++ java/src/org/apache/wsif/catalog/Messages.properties 27 Jan 2004 22:56:58 -0000
@@ -63,3 +63,13 @@
# Parameter(s): {0} the user's preferred port
# Description: The preferred port set by the user on org.apache.wsif.WSIFService is not available
# User Action: None unless this message appears for long periods of time in which case the user might want to pick a different port as their preferred port
+
+WSIF.0012W=WSIF0012W: Could not create instance of custom WSIFServiceFactory ''{0}'', using default instead. This was due to a ''{1}'': ''{2}''
+# Parameter(s): {0} the class name of the custom factory.
+# {1} the class name of the exception causing the failure.
+# {2} the text of the message from the exception.
+# Description: Failed to instantiate the custom WSIFServiceFactory for some reason.
+# User Action: This could indicate the the class was not found, or not accessible. The user should check that
+# the class name is correct, that the class is available from the calling thread's context classloader
+# and that the class is publicly accessible. Additionally, the class must have a default (no argument)
+# constructor, which must also be publicly accessible.