You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2012/03/27 18:37:35 UTC

svn commit: r1305895 - in /cxf/trunk: parent/ services/wsn/wsn-api/ services/wsn/wsn-api/src/main/java/org/apache/cxf/wsn/client/ services/wsn/wsn-api/src/main/java/org/apache/cxf/wsn/util/ services/wsn/wsn-core/ services/wsn/wsn-core/src/main/java/org...

Author: dkulp
Date: Tue Mar 27 16:37:34 2012
New Revision: 1305895

URL: http://svn.apache.org/viewvc?rev=1305895&view=rev
Log:
[CXF-4210] Add support for extra types to be handled by the ws-n api's

Added:
    cxf/trunk/services/wsn/wsn-api/src/main/java/org/apache/cxf/wsn/util/CXFWSNHelper.java   (with props)
    cxf/trunk/services/wsn/wsn-core/src/test/java/org/apache/cxf/wsn/types/
    cxf/trunk/services/wsn/wsn-core/src/test/java/org/apache/cxf/wsn/types/CustomType.java   (with props)
Modified:
    cxf/trunk/parent/pom.xml
    cxf/trunk/services/wsn/wsn-api/pom.xml
    cxf/trunk/services/wsn/wsn-api/src/main/java/org/apache/cxf/wsn/client/Consumer.java
    cxf/trunk/services/wsn/wsn-api/src/main/java/org/apache/cxf/wsn/client/CreatePullPoint.java
    cxf/trunk/services/wsn/wsn-api/src/main/java/org/apache/cxf/wsn/client/NotificationBroker.java
    cxf/trunk/services/wsn/wsn-api/src/main/java/org/apache/cxf/wsn/client/PullPoint.java
    cxf/trunk/services/wsn/wsn-api/src/main/java/org/apache/cxf/wsn/client/Registration.java
    cxf/trunk/services/wsn/wsn-api/src/main/java/org/apache/cxf/wsn/client/Subscription.java
    cxf/trunk/services/wsn/wsn-api/src/main/java/org/apache/cxf/wsn/util/WSNHelper.java
    cxf/trunk/services/wsn/wsn-core/pom.xml
    cxf/trunk/services/wsn/wsn-core/src/main/java/org/apache/cxf/wsn/AbstractNotificationBroker.java
    cxf/trunk/services/wsn/wsn-core/src/main/java/org/apache/cxf/wsn/services/JaxwsEndpointManager.java
    cxf/trunk/services/wsn/wsn-core/src/main/java/org/apache/cxf/wsn/services/JaxwsPublisher.java
    cxf/trunk/services/wsn/wsn-core/src/main/java/org/apache/cxf/wsn/services/JaxwsSubscription.java
    cxf/trunk/services/wsn/wsn-core/src/test/java/org/apache/cxf/wsn/RiTest.java
    cxf/trunk/services/wsn/wsn-core/src/test/java/org/apache/cxf/wsn/WsnBrokerTest.java

Modified: cxf/trunk/parent/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/parent/pom.xml?rev=1305895&r1=1305894&r2=1305895&view=diff
==============================================================================
--- cxf/trunk/parent/pom.xml (original)
+++ cxf/trunk/parent/pom.xml Tue Mar 27 16:37:34 2012
@@ -40,6 +40,7 @@
         <cxf.surefire.parallel.mode />
         <cxf.surefire.fork.vmargs>-ea</cxf.surefire.fork.vmargs>
         <cxf.server.launcher.vmargs>-ea</cxf.server.launcher.vmargs>
+        <cxf.surefire.enable.assertions>true</cxf.surefire.enable.assertions>
         <cxf.compile.flags>-Xlint:unchecked,deprecation,fallthrough,finally</cxf.compile.flags>
         <cxf.compile.show.deprecation>true</cxf.compile.show.deprecation>
         <cxf.codegenplugin.forkmode>once</cxf.codegenplugin.forkmode>
@@ -371,6 +372,7 @@
                         <forkMode>${cxf.surefire.fork.mode}</forkMode>
                         <childDelegation>false</childDelegation>
                         <argLine>${cxf.surefire.fork.vmargs}</argLine>
+                        <enableAssertions>${cxf.surefire.enable.assertions}</enableAssertions>
                         <parallel>${cxf.surefire.parallel.mode}</parallel>
                         <systemPropertyVariables>
                             <cxf.useRandomFirstPort>true</cxf.useRandomFirstPort>

Modified: cxf/trunk/services/wsn/wsn-api/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/services/wsn/wsn-api/pom.xml?rev=1305895&r1=1305894&r2=1305895&view=diff
==============================================================================
--- cxf/trunk/services/wsn/wsn-api/pom.xml (original)
+++ cxf/trunk/services/wsn/wsn-api/pom.xml Tue Mar 27 16:37:34 2012
@@ -39,6 +39,12 @@
             <artifactId>cxf-api</artifactId>
             <version>${project.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-rt-frontend-jaxws</artifactId>
+            <version>${project.version}</version>
+            <optional>true</optional>
+        </dependency>
     </dependencies>
 	
 	<build>

Modified: cxf/trunk/services/wsn/wsn-api/src/main/java/org/apache/cxf/wsn/client/Consumer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/services/wsn/wsn-api/src/main/java/org/apache/cxf/wsn/client/Consumer.java?rev=1305895&r1=1305894&r2=1305895&view=diff
==============================================================================
--- cxf/trunk/services/wsn/wsn-api/src/main/java/org/apache/cxf/wsn/client/Consumer.java (original)
+++ cxf/trunk/services/wsn/wsn-api/src/main/java/org/apache/cxf/wsn/client/Consumer.java Tue Mar 27 16:37:34 2012
@@ -18,11 +18,17 @@
  */
 package org.apache.cxf.wsn.client;
 
+
 import javax.jws.WebParam;
 import javax.jws.WebService;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
 import javax.xml.ws.Endpoint;
 import javax.xml.ws.wsaddressing.W3CEndpointReference;
 
+import org.w3c.dom.Element;
+
+import org.apache.cxf.wsn.util.WSNHelper;
 import org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType;
 import org.oasis_open.docs.wsn.b_2.Notify;
 import org.oasis_open.docs.wsn.bw_2.NotificationConsumer;
@@ -36,11 +42,26 @@ public class Consumer implements Notific
 
     private final Callback callback;
     private final Endpoint endpoint;
+    private final JAXBContext context;
 
-    public Consumer(Callback callback, String address) {
+    public Consumer(Callback callback, String address, Class<?> ... extraClasses) {
         this.callback = callback;
-        this.endpoint = Endpoint.create(this);
-        this.endpoint.publish(address);
+        WSNHelper helper = WSNHelper.getInstance();
+        if (helper.supportsExtraClasses()) {
+            this.endpoint = helper.publish(address, this, extraClasses);
+            this.context = null;
+        } else {
+            this.endpoint = helper.publish(address, this);
+            if (extraClasses != null && extraClasses.length > 0) {
+                try {
+                    this.context = JAXBContext.newInstance(extraClasses);
+                } catch (JAXBException e) {
+                    throw new RuntimeException(e);
+                }
+            } else {
+                this.context = null;
+            }
+        }
     }
 
     public void stop() {
@@ -56,6 +77,17 @@ public class Consumer implements Notific
                   name = "Notify", 
                   targetNamespace = "http://docs.oasis-open.org/wsn/b-2") Notify notify) {
         for (NotificationMessageHolderType message : notify.getNotificationMessage()) {
+            if (context != null) {
+                Object o = message.getMessage().getAny();
+                if (o instanceof Element) {
+                    try {
+                        o = context.createUnmarshaller().unmarshal((Element)o);
+                        message.getMessage().setAny(o);
+                    } catch (JAXBException e) {
+                        //ignore, leave as a DOM
+                    }
+                }
+            }
             this.callback.notify(message);
         }
     }

Modified: cxf/trunk/services/wsn/wsn-api/src/main/java/org/apache/cxf/wsn/client/CreatePullPoint.java
URL: http://svn.apache.org/viewvc/cxf/trunk/services/wsn/wsn-api/src/main/java/org/apache/cxf/wsn/client/CreatePullPoint.java?rev=1305895&r1=1305894&r2=1305895&view=diff
==============================================================================
--- cxf/trunk/services/wsn/wsn-api/src/main/java/org/apache/cxf/wsn/client/CreatePullPoint.java (original)
+++ cxf/trunk/services/wsn/wsn-api/src/main/java/org/apache/cxf/wsn/client/CreatePullPoint.java Tue Mar 27 16:37:34 2012
@@ -30,11 +30,13 @@ public class CreatePullPoint implements 
     private final W3CEndpointReference epr;
 
     public CreatePullPoint(String address) {
-        this(WSNHelper.createWSA(address));
+        this(WSNHelper.getInstance().createWSA(address));
     }
 
     public CreatePullPoint(W3CEndpointReference epr) {
-        this.createPullPoint = WSNHelper.getPort(epr, org.oasis_open.docs.wsn.bw_2.CreatePullPoint.class);
+        this.createPullPoint 
+            = WSNHelper.getInstance().getPort(epr, 
+                                              org.oasis_open.docs.wsn.bw_2.CreatePullPoint.class);
         this.epr = epr;
     }
 

Modified: cxf/trunk/services/wsn/wsn-api/src/main/java/org/apache/cxf/wsn/client/NotificationBroker.java
URL: http://svn.apache.org/viewvc/cxf/trunk/services/wsn/wsn-api/src/main/java/org/apache/cxf/wsn/client/NotificationBroker.java?rev=1305895&r1=1305894&r2=1305895&view=diff
==============================================================================
--- cxf/trunk/services/wsn/wsn-api/src/main/java/org/apache/cxf/wsn/client/NotificationBroker.java (original)
+++ cxf/trunk/services/wsn/wsn-api/src/main/java/org/apache/cxf/wsn/client/NotificationBroker.java Tue Mar 27 16:37:34 2012
@@ -20,10 +20,16 @@ package org.apache.cxf.wsn.client;
 
 import java.util.Collections;
 import java.util.List;
+
+import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBElement;
+import javax.xml.bind.JAXBException;
 import javax.xml.namespace.QName;
+import javax.xml.transform.dom.DOMResult;
 import javax.xml.ws.wsaddressing.W3CEndpointReference;
 
+import org.w3c.dom.Document;
+
 import org.apache.cxf.wsn.util.WSNHelper;
 import org.oasis_open.docs.wsn.b_2.FilterType;
 import org.oasis_open.docs.wsn.b_2.GetCurrentMessage;
@@ -64,19 +70,44 @@ public class NotificationBroker implemen
     public static final QName QNAME_MESSAGE_CONTENT = new QName(WSN_URI, "MessageContent");
 
     
-    private final org.oasis_open.docs.wsn.brw_2.NotificationBroker broker;
+    private org.oasis_open.docs.wsn.brw_2.NotificationBroker broker;
     private final W3CEndpointReference epr;
+    private Class<?> extraClasses[];
+    private JAXBContext context;
 
     public NotificationBroker(String address) {
-        this(WSNHelper.createWSA(address));
+        this(WSNHelper.getInstance().createWSA(address));
     }
 
     public NotificationBroker(W3CEndpointReference epr) {
-        this.broker = WSNHelper.getPort(epr, org.oasis_open.docs.wsn.brw_2.NotificationBroker.class);
         this.epr = epr;
     }
 
-    public org.oasis_open.docs.wsn.brw_2.NotificationBroker getBroker() {
+    public void setExtraClasses(Class<?> ... c) {
+        extraClasses = c;
+    }
+    
+    public synchronized org.oasis_open.docs.wsn.brw_2.NotificationBroker getBroker() {
+        if (broker == null) {
+            WSNHelper helper = WSNHelper.getInstance();
+            if (helper.supportsExtraClasses()) {
+                this.broker = WSNHelper.getInstance()
+                    .getPort(epr, 
+                         org.oasis_open.docs.wsn.brw_2.NotificationBroker.class,
+                         extraClasses);
+            } else {
+                this.broker = WSNHelper.getInstance()
+                    .getPort(epr, 
+                         org.oasis_open.docs.wsn.brw_2.NotificationBroker.class);
+                if (extraClasses != null && extraClasses.length > 0) {
+                    try {
+                        this.context = JAXBContext.newInstance(extraClasses);
+                    } catch (JAXBException e) {
+                        throw new RuntimeException(e);
+                    }
+                }
+            }
+        }
         return broker;
     }
 
@@ -89,6 +120,20 @@ public class NotificationBroker implemen
     }
 
     public void notify(Referencable publisher, String topic, Object msg) {
+        getBroker();
+        if (this.context != null) {
+            try {
+                DOMResult result = new DOMResult();
+                context.createMarshaller().marshal(msg, result);
+                msg = result.getNode();
+                if (msg instanceof Document) {
+                    msg = ((Document)msg).getDocumentElement();
+                } 
+            } catch (JAXBException e) {
+                //ignore, we'll try and let the runtime handle it as is
+            }
+        }
+        
         Notify notify = new Notify();
         NotificationMessageHolderType holder = new NotificationMessageHolderType();
         if (publisher != null) {
@@ -102,7 +147,7 @@ public class NotificationBroker implemen
         holder.setMessage(new NotificationMessageHolderType.Message());
         holder.getMessage().setAny(msg);
         notify.getNotificationMessage().add(holder);
-        broker.notify(notify);
+        getBroker().notify(notify);
     }
 
     public Subscription subscribe(Referencable consumer, String topic) 
@@ -160,7 +205,7 @@ public class NotificationBroker implemen
             subscribeRequest.setSubscriptionPolicy(new Subscribe.SubscriptionPolicy());
             subscribeRequest.getSubscriptionPolicy().getAny().add(new UseRaw());
         }
-        SubscribeResponse response = broker.subscribe(subscribeRequest);
+        SubscribeResponse response = getBroker().subscribe(subscribeRequest);
         return new Subscription(response.getSubscriptionReference());
     }
 
@@ -175,7 +220,7 @@ public class NotificationBroker implemen
             topicExp.getContent().add(topic);
             getCurrentMessageRequest.setTopic(topicExp);
         }
-        GetCurrentMessageResponse response = broker.getCurrentMessage(getCurrentMessageRequest);
+        GetCurrentMessageResponse response = getBroker().getCurrentMessage(getCurrentMessageRequest);
         return response.getAny();
     }
 
@@ -214,7 +259,7 @@ public class NotificationBroker implemen
             }
         }
         registerPublisherRequest.setDemand(demand);
-        RegisterPublisherResponse response = broker.registerPublisher(registerPublisherRequest);
+        RegisterPublisherResponse response = getBroker().registerPublisher(registerPublisherRequest);
         return new Registration(response.getPublisherRegistrationReference());
     }
 

Modified: cxf/trunk/services/wsn/wsn-api/src/main/java/org/apache/cxf/wsn/client/PullPoint.java
URL: http://svn.apache.org/viewvc/cxf/trunk/services/wsn/wsn-api/src/main/java/org/apache/cxf/wsn/client/PullPoint.java?rev=1305895&r1=1305894&r2=1305895&view=diff
==============================================================================
--- cxf/trunk/services/wsn/wsn-api/src/main/java/org/apache/cxf/wsn/client/PullPoint.java (original)
+++ cxf/trunk/services/wsn/wsn-api/src/main/java/org/apache/cxf/wsn/client/PullPoint.java Tue Mar 27 16:37:34 2012
@@ -37,11 +37,11 @@ public class PullPoint implements Refere
     private final W3CEndpointReference epr;
 
     public PullPoint(String address) {
-        this(WSNHelper.createWSA(address));
+        this(WSNHelper.getInstance().createWSA(address));
     }
 
     public PullPoint(W3CEndpointReference epr) {
-        this.pullPoint = WSNHelper.getPort(epr, org.oasis_open.docs.wsn.bw_2.PullPoint.class);
+        this.pullPoint = WSNHelper.getInstance().getPort(epr, org.oasis_open.docs.wsn.bw_2.PullPoint.class);
         this.epr = epr;
     }
 

Modified: cxf/trunk/services/wsn/wsn-api/src/main/java/org/apache/cxf/wsn/client/Registration.java
URL: http://svn.apache.org/viewvc/cxf/trunk/services/wsn/wsn-api/src/main/java/org/apache/cxf/wsn/client/Registration.java?rev=1305895&r1=1305894&r2=1305895&view=diff
==============================================================================
--- cxf/trunk/services/wsn/wsn-api/src/main/java/org/apache/cxf/wsn/client/Registration.java (original)
+++ cxf/trunk/services/wsn/wsn-api/src/main/java/org/apache/cxf/wsn/client/Registration.java Tue Mar 27 16:37:34 2012
@@ -32,11 +32,11 @@ public class Registration implements Ref
     private final W3CEndpointReference epr;
 
     public Registration(String address) {
-        this(WSNHelper.createWSA(address));
+        this(WSNHelper.getInstance().createWSA(address));
     }
 
     public Registration(W3CEndpointReference epr) {
-        this.registration = WSNHelper.getPort(epr, PublisherRegistrationManager.class);
+        this.registration = WSNHelper.getInstance().getPort(epr, PublisherRegistrationManager.class);
         this.epr = epr;
     }
 

Modified: cxf/trunk/services/wsn/wsn-api/src/main/java/org/apache/cxf/wsn/client/Subscription.java
URL: http://svn.apache.org/viewvc/cxf/trunk/services/wsn/wsn-api/src/main/java/org/apache/cxf/wsn/client/Subscription.java?rev=1305895&r1=1305894&r2=1305895&view=diff
==============================================================================
--- cxf/trunk/services/wsn/wsn-api/src/main/java/org/apache/cxf/wsn/client/Subscription.java (original)
+++ cxf/trunk/services/wsn/wsn-api/src/main/java/org/apache/cxf/wsn/client/Subscription.java Tue Mar 27 16:37:34 2012
@@ -38,11 +38,11 @@ public class Subscription implements Ref
     private final W3CEndpointReference epr;
 
     public Subscription(String address) {
-        this(WSNHelper.createWSA(address));
+        this(WSNHelper.getInstance().createWSA(address));
     }
 
     public Subscription(W3CEndpointReference epr) {
-        this.subscription = WSNHelper.getPort(epr, PausableSubscriptionManager.class);
+        this.subscription = WSNHelper.getInstance().getPort(epr, PausableSubscriptionManager.class);
         this.epr = epr;
     }
 

Added: cxf/trunk/services/wsn/wsn-api/src/main/java/org/apache/cxf/wsn/util/CXFWSNHelper.java
URL: http://svn.apache.org/viewvc/cxf/trunk/services/wsn/wsn-api/src/main/java/org/apache/cxf/wsn/util/CXFWSNHelper.java?rev=1305895&view=auto
==============================================================================
--- cxf/trunk/services/wsn/wsn-api/src/main/java/org/apache/cxf/wsn/util/CXFWSNHelper.java (added)
+++ cxf/trunk/services/wsn/wsn-api/src/main/java/org/apache/cxf/wsn/util/CXFWSNHelper.java Tue Mar 27 16:37:34 2012
@@ -0,0 +1,77 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.cxf.wsn.util;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.Endpoint;
+
+import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
+import org.apache.cxf.wsn.wsdl.WSNWSDLLocator;
+
+/**
+ * 
+ */
+public class CXFWSNHelper extends WSNHelper {
+
+    public boolean supportsExtraClasses() {
+        return true;
+    }
+
+    @Override
+    public <T> T getPort(String address,
+                         Class<T> serviceInterface,
+                         Class<?>... extraClasses) {
+        
+        ClassLoader cl = Thread.currentThread().getContextClassLoader();
+        try {
+            if (setClassLoader) {
+                Thread.currentThread().setContextClassLoader(WSNHelper.class.getClassLoader());
+            }
+            
+            JaxWsProxyFactoryBean jwfb = new JaxWsProxyFactoryBean();
+            jwfb.getClientFactoryBean().setWsdlURL(WSNWSDLLocator.getWSDLUrl().toExternalForm());
+            jwfb.setServiceName(new QName("http://cxf.apache.org/wsn/jaxws", 
+                                          serviceInterface.getSimpleName() + "Service"));
+            jwfb.setEndpointName(new QName("http://cxf.apache.org/wsn/jaxws", "Soap"));
+            jwfb.setAddress(address);
+            if (extraClasses != null && extraClasses.length > 0) {
+                Map<String, Object> props = new HashMap<String, Object>();
+                props.put("jaxb.additionalContextClasses", extraClasses);
+                jwfb.getClientFactoryBean().getServiceFactory().setProperties(props);
+            }
+            return jwfb.create(serviceInterface); 
+        } finally {
+            Thread.currentThread().setContextClassLoader(cl);
+        }
+    }
+    public Endpoint publish(String address, Object o, Class<?> ... extraClasses) {
+        Endpoint endpoint = Endpoint.create(o);
+        if (extraClasses != null && extraClasses.length > 0) {
+            Map<String, Object> props = new HashMap<String, Object>();
+            props.put("jaxb.additionalContextClasses", extraClasses);
+            endpoint.setProperties(props);
+        }
+        endpoint.publish(address);
+        return endpoint;
+    }
+}

Propchange: cxf/trunk/services/wsn/wsn-api/src/main/java/org/apache/cxf/wsn/util/CXFWSNHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/services/wsn/wsn-api/src/main/java/org/apache/cxf/wsn/util/CXFWSNHelper.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/trunk/services/wsn/wsn-api/src/main/java/org/apache/cxf/wsn/util/WSNHelper.java
URL: http://svn.apache.org/viewvc/cxf/trunk/services/wsn/wsn-api/src/main/java/org/apache/cxf/wsn/util/WSNHelper.java?rev=1305895&r1=1305894&r2=1305895&view=diff
==============================================================================
--- cxf/trunk/services/wsn/wsn-api/src/main/java/org/apache/cxf/wsn/util/WSNHelper.java (original)
+++ cxf/trunk/services/wsn/wsn-api/src/main/java/org/apache/cxf/wsn/util/WSNHelper.java Tue Mar 27 16:37:34 2012
@@ -20,8 +20,10 @@ package org.apache.cxf.wsn.util;
 
 import javax.xml.namespace.QName;
 import javax.xml.transform.dom.DOMResult;
+import javax.xml.ws.Endpoint;
 import javax.xml.ws.EndpointReference;
 import javax.xml.ws.Service;
+import javax.xml.ws.spi.Provider;
 import javax.xml.ws.wsaddressing.W3CEndpointReference;
 import javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder;
 
@@ -31,26 +33,72 @@ import org.w3c.dom.NodeList;
 import org.apache.cxf.helpers.DOMUtils;
 import org.apache.cxf.wsn.wsdl.WSNWSDLLocator;
 
-public abstract class WSNHelper {
-    private static boolean setClassLoader = true;
-    public static boolean setClassLoader() {
+public class WSNHelper {
+    private static volatile WSNHelper instance;
+    protected boolean setClassLoader = true;
+
+    
+    public static WSNHelper getInstance() {
+        if (instance == null) {
+            createInstance();
+        }
+        return instance;
+    }
+    public static void clearInstance() {
+        instance = null;
+    }
+    
+    private static synchronized void createInstance() {
+        if (instance != null) {
+            return;
+        }
+        Provider p = Provider.provider();
+        if (p.getClass().getName().contains("apache.cxf")) {
+            instance = new CXFWSNHelper();
+        } else {
+            instance = new WSNHelper();
+        }
+    }
+    
+    public boolean setClassLoader() {
         return setClassLoader;
     }
-    public static void setClassLoader(boolean cl) {
+    public void setClassLoader(boolean cl) {
         setClassLoader = cl;
     }
     
-    public static <T> T getPort(EndpointReference ref, Class<T> serviceInterface) {
+    public boolean supportsExtraClasses() {
+        return false;
+    }
+    
+    public Endpoint publish(String address, Object o, Class<?> ... extraClasses) {
+        if (extraClasses != null && extraClasses.length > 0) {
+            throw new UnsupportedOperationException("Pure JAX-WS does not support the extraClasses");
+        }
+        Endpoint endpoint = Endpoint.create(o);
+        endpoint.publish(address);
+        return endpoint;
+    }
+    
+    public <T> T getPort(EndpointReference ref, 
+                         Class<T> serviceInterface,
+                         Class<?> ... extraClasses) {
         if (!(ref instanceof W3CEndpointReference)) {
             throw new IllegalArgumentException("Unsupported endpoint reference: " 
                 + (ref != null ? ref.toString() : "null"));
         }
         W3CEndpointReference w3cEpr = (W3CEndpointReference) ref;
         String address = getWSAAddress(w3cEpr);
-        return getPort(address, serviceInterface);
+        return getPort(address, serviceInterface, extraClasses);
     }
 
-    public static <T> T getPort(String address, Class<T> serviceInterface) {
+    public <T> T getPort(String address, 
+                         Class<T> serviceInterface,
+                         Class<?> ... extraClasses) {
+        if (extraClasses != null && extraClasses.length > 0) {
+            throw new UnsupportedOperationException("Pure JAX-WS does not support the extraClasses");
+        }
+        
         ClassLoader cl = Thread.currentThread().getContextClassLoader();
         try {
             if (setClassLoader) {
@@ -66,7 +114,7 @@ public abstract class WSNHelper {
         }
     }
 
-    public static W3CEndpointReference createWSA(String address) {
+    public W3CEndpointReference createWSA(String address) {
         ClassLoader cl = Thread.currentThread().getContextClassLoader();
         try {
             if (setClassLoader) {
@@ -79,7 +127,7 @@ public abstract class WSNHelper {
         }
     }
 
-    public static String getWSAAddress(W3CEndpointReference ref) {
+    public String getWSAAddress(W3CEndpointReference ref) {
         Element element = DOMUtils.createDocument().createElement("elem");
         ref.writeTo(new DOMResult(element));
         NodeList nl = element.getElementsByTagNameNS("http://www.w3.org/2005/08/addressing", "Address");
@@ -89,6 +137,4 @@ public abstract class WSNHelper {
         }
         return null;
     }
-
-
 }

Modified: cxf/trunk/services/wsn/wsn-core/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/services/wsn/wsn-core/pom.xml?rev=1305895&r1=1305894&r2=1305895&view=diff
==============================================================================
--- cxf/trunk/services/wsn/wsn-core/pom.xml (original)
+++ cxf/trunk/services/wsn/wsn-core/pom.xml Tue Mar 27 16:37:34 2012
@@ -33,6 +33,14 @@
         <relativePath>../../../parent/pom.xml</relativePath>
     </parent>
 
+    <properties>
+        <!-- bug in jaxb is causing an assertion error if -ea is turned on -->
+        <cxf.surefire.fork.vmargs></cxf.surefire.fork.vmargs>
+        <cxf.server.launcher.vmargs></cxf.server.launcher.vmargs>
+        <cxf.surefire.enable.assertions>false</cxf.surefire.enable.assertions>
+    </properties>
+
+
 	<dependencies>
         <dependency>
             <groupId>org.apache.geronimo.specs</groupId>
@@ -89,7 +97,6 @@
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
-            <version>4.8.2</version>
             <scope>test</scope>
         </dependency>
         <dependency>
@@ -127,6 +134,12 @@
             </exclusions>
         </dependency>
         <dependency>
+            <groupId>xalan</groupId>
+            <artifactId>xalan</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
             <groupId>com.sun.net.httpserver</groupId>
             <artifactId>http</artifactId>
             <version>20070405</version>

Modified: cxf/trunk/services/wsn/wsn-core/src/main/java/org/apache/cxf/wsn/AbstractNotificationBroker.java
URL: http://svn.apache.org/viewvc/cxf/trunk/services/wsn/wsn-core/src/main/java/org/apache/cxf/wsn/AbstractNotificationBroker.java?rev=1305895&r1=1305894&r2=1305895&view=diff
==============================================================================
--- cxf/trunk/services/wsn/wsn-core/src/main/java/org/apache/cxf/wsn/AbstractNotificationBroker.java (original)
+++ cxf/trunk/services/wsn/wsn-core/src/main/java/org/apache/cxf/wsn/AbstractNotificationBroker.java Tue Mar 27 16:37:34 2012
@@ -176,7 +176,7 @@ public abstract class AbstractNotificati
     protected AbstractPublisher getPublisher(W3CEndpointReference producerReference) {
         AbstractPublisher publisher = null;
         if (producerReference != null) {
-            String address = WSNHelper.getWSAAddress(producerReference);
+            String address = WSNHelper.getInstance().getWSAAddress(producerReference);
             publisher = publishers.get(address);
         }
         if (publisher == null) {
@@ -337,7 +337,9 @@ public abstract class AbstractNotificati
             RegisterPublisherResponse response = new RegisterPublisherResponse();
             response.setPublisherRegistrationReference(publisher.getEpr());
             if (publisher.getPublisherReference() != null) {
-                publishers.put(WSNHelper.getWSAAddress(publisher.getPublisherReference()), publisher);
+                publishers.put(WSNHelper.getInstance()
+                                   .getWSAAddress(publisher.getPublisherReference()),
+                               publisher);
             } else {
                 nonContactPublishers.add(publisher);
             }

Modified: cxf/trunk/services/wsn/wsn-core/src/main/java/org/apache/cxf/wsn/services/JaxwsEndpointManager.java
URL: http://svn.apache.org/viewvc/cxf/trunk/services/wsn/wsn-core/src/main/java/org/apache/cxf/wsn/services/JaxwsEndpointManager.java?rev=1305895&r1=1305894&r2=1305895&view=diff
==============================================================================
--- cxf/trunk/services/wsn/wsn-core/src/main/java/org/apache/cxf/wsn/services/JaxwsEndpointManager.java (original)
+++ cxf/trunk/services/wsn/wsn-core/src/main/java/org/apache/cxf/wsn/services/JaxwsEndpointManager.java Tue Mar 27 16:37:34 2012
@@ -43,7 +43,7 @@ public class JaxwsEndpointManager implem
     public Endpoint register(String address, Object service) throws EndpointRegistrationException {
         ClassLoader cl = Thread.currentThread().getContextClassLoader();
         try {
-            if (WSNHelper.setClassLoader()) {
+            if (WSNHelper.getInstance().setClassLoader()) {
                 Thread.currentThread().setContextClassLoader(JaxwsEndpointManager.class.getClassLoader());
             }
             String bindingId = SOAPBinding.SOAP11HTTP_BINDING;

Modified: cxf/trunk/services/wsn/wsn-core/src/main/java/org/apache/cxf/wsn/services/JaxwsPublisher.java
URL: http://svn.apache.org/viewvc/cxf/trunk/services/wsn/wsn-core/src/main/java/org/apache/cxf/wsn/services/JaxwsPublisher.java?rev=1305895&r1=1305894&r2=1305895&view=diff
==============================================================================
--- cxf/trunk/services/wsn/wsn-core/src/main/java/org/apache/cxf/wsn/services/JaxwsPublisher.java (original)
+++ cxf/trunk/services/wsn/wsn-core/src/main/java/org/apache/cxf/wsn/services/JaxwsPublisher.java Tue Mar 27 16:37:34 2012
@@ -59,7 +59,8 @@ public class JaxwsPublisher extends JmsP
     protected void start() throws PublisherRegistrationFailedFault {
         super.start();
         if (demand) {
-            notificationProducer = WSNHelper.getPort(publisherReference, NotificationProducer.class);
+            notificationProducer = WSNHelper.getInstance()
+                .getPort(publisherReference, NotificationProducer.class);
         }
     }
 
@@ -73,7 +74,8 @@ public class JaxwsPublisher extends JmsP
                     new JAXBElement<TopicExpressionType>(AbstractSubscription.QNAME_TOPIC_EXPRESSION,
                             TopicExpressionType.class, topic));
             SubscribeResponse response = notificationProducer.subscribe(subscribeRequest);
-            return WSNHelper.getPort(response.getSubscriptionReference(), SubscriptionManager.class);
+            return WSNHelper.getInstance()
+                .getPort(response.getSubscriptionReference(), SubscriptionManager.class);
         } catch (Exception e) {
             LOGGER.log(Level.INFO, "Error while subscribing on-demand publisher", e);
             return null;

Modified: cxf/trunk/services/wsn/wsn-core/src/main/java/org/apache/cxf/wsn/services/JaxwsSubscription.java
URL: http://svn.apache.org/viewvc/cxf/trunk/services/wsn/wsn-core/src/main/java/org/apache/cxf/wsn/services/JaxwsSubscription.java?rev=1305895&r1=1305894&r2=1305895&view=diff
==============================================================================
--- cxf/trunk/services/wsn/wsn-core/src/main/java/org/apache/cxf/wsn/services/JaxwsSubscription.java (original)
+++ cxf/trunk/services/wsn/wsn-core/src/main/java/org/apache/cxf/wsn/services/JaxwsSubscription.java Tue Mar 27 16:37:34 2012
@@ -62,7 +62,8 @@ public class JaxwsSubscription extends J
             throw new SubscribeCreationFailedFault("Raw notifications are not supported", fault);
         }
         try {
-            consumer = WSNHelper.getPort(subscribeRequest.getConsumerReference(), NotificationConsumer.class);
+            consumer = WSNHelper.getInstance().getPort(subscribeRequest.getConsumerReference(), 
+                                                       NotificationConsumer.class);
         } catch (Exception e) {
             SubscribeCreationFailedFaultType fault = new SubscribeCreationFailedFaultType();
             throw new SubscribeCreationFailedFault("Unable to resolve consumer reference endpoint", fault, e);

Modified: cxf/trunk/services/wsn/wsn-core/src/test/java/org/apache/cxf/wsn/RiTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/services/wsn/wsn-core/src/test/java/org/apache/cxf/wsn/RiTest.java?rev=1305895&r1=1305894&r2=1305895&view=diff
==============================================================================
--- cxf/trunk/services/wsn/wsn-core/src/test/java/org/apache/cxf/wsn/RiTest.java (original)
+++ cxf/trunk/services/wsn/wsn-core/src/test/java/org/apache/cxf/wsn/RiTest.java Tue Mar 27 16:37:34 2012
@@ -18,9 +18,23 @@
  */
 package org.apache.cxf.wsn;
 
+import org.junit.Test;
+
 public class RiTest extends WsnBrokerTest {
 
     protected String getProviderImpl() {
         return "com.sun.xml.ws.spi.ProviderImpl";
     }
+    
+    @Test
+    public void testPublisherCustomType() throws Exception {
+        try {
+            assert false;
+        } catch (AssertionError e) {
+            //Bug in jaxb prevents this test from passing if assertions are on.
+            //We'll just return;
+            return;
+        }
+        super.testPublisherCustomType();
+    }
 }

Modified: cxf/trunk/services/wsn/wsn-core/src/test/java/org/apache/cxf/wsn/WsnBrokerTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/services/wsn/wsn-core/src/test/java/org/apache/cxf/wsn/WsnBrokerTest.java?rev=1305895&r1=1305894&r2=1305895&view=diff
==============================================================================
--- cxf/trunk/services/wsn/wsn-core/src/test/java/org/apache/cxf/wsn/WsnBrokerTest.java (original)
+++ cxf/trunk/services/wsn/wsn-core/src/test/java/org/apache/cxf/wsn/WsnBrokerTest.java Tue Mar 27 16:37:34 2012
@@ -34,7 +34,6 @@ import java.util.concurrent.TimeUnit;
 import javax.xml.bind.JAXBElement;
 import javax.xml.namespace.QName;
 
-import junit.framework.TestCase;
 import org.apache.activemq.ActiveMQConnectionFactory;
 import org.apache.cxf.wsn.client.Consumer;
 import org.apache.cxf.wsn.client.CreatePullPoint;
@@ -45,11 +44,19 @@ import org.apache.cxf.wsn.client.Registr
 import org.apache.cxf.wsn.client.Subscription;
 import org.apache.cxf.wsn.services.JaxwsCreatePullPoint;
 import org.apache.cxf.wsn.services.JaxwsNotificationBroker;
+import org.apache.cxf.wsn.types.CustomType;
 import org.apache.cxf.wsn.util.WSNHelper;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
 import org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType;
 import org.oasis_open.docs.wsn.b_2.TopicExpressionType;
 
-public abstract class WsnBrokerTest extends TestCase {
+
+public abstract class WsnBrokerTest extends Assert {
     private boolean useExternal;
     
     
@@ -66,21 +73,22 @@ public abstract class WsnBrokerTest exte
     protected abstract String getProviderImpl();
     
 
-    @Override
+    @Before
     public void setUp() throws Exception {
         loader = Thread.currentThread().getContextClassLoader();
         String impl = getProviderImpl();
         Thread.currentThread()
             .setContextClassLoader(new FakeClassLoader(impl));
-        WSNHelper.setClassLoader(false);
+        WSNHelper.getInstance().setClassLoader(false);
     
         System.setProperty("javax.xml.ws.spi.Provider", impl);
 
         port2 = getFreePort();
         if (!useExternal) {
             port1 = getFreePort();
-            
-            activemq = new ActiveMQConnectionFactory("vm:(broker:(tcp://localhost:6000)?persistent=false)");
+            int brokerPort = getFreePort();
+            activemq = new ActiveMQConnectionFactory("vm:(broker:(tcp://localhost:" + brokerPort 
+                                                     + ")?persistent=false)");
 
             notificationBrokerServer = new JaxwsNotificationBroker("WSNotificationBroker", activemq);
             notificationBrokerServer.setAddress("http://localhost:" + port1 + "/wsn/NotificationBroker");
@@ -103,7 +111,7 @@ public abstract class WsnBrokerTest exte
         return port;
     }
 
-    @Override
+    @After
     public void tearDown() throws Exception {
         if (!useExternal) {
             notificationBrokerServer.destroy();
@@ -112,8 +120,10 @@ public abstract class WsnBrokerTest exte
         System.clearProperty("javax.xml.ws.spi.Provider");
         Thread.currentThread()
             .setContextClassLoader(loader);
+        WSNHelper.clearInstance();
     }
 
+    @Test
     public void testBroker() throws Exception {
         TestConsumer callback = new TestConsumer();
         Consumer consumer = new Consumer(callback, "http://localhost:" + port2 + "/test/consumer");
@@ -128,13 +138,14 @@ public abstract class WsnBrokerTest exte
         }
         assertEquals(1, callback.notifications.size());
         NotificationMessageHolderType message = callback.notifications.get(0);
-        assertEquals(WSNHelper.getWSAAddress(subscription.getEpr()), 
-                     WSNHelper.getWSAAddress(message.getSubscriptionReference()));
+        assertEquals(WSNHelper.getInstance().getWSAAddress(subscription.getEpr()), 
+                     WSNHelper.getInstance().getWSAAddress(message.getSubscriptionReference()));
 
         subscription.unsubscribe();
         consumer.stop();
     }
 
+    @Test
     public void testPullPoint() throws Exception {
         PullPoint pullPoint = createPullPoint.create();
         Subscription subscription = notificationBroker.subscribe(pullPoint, "myTopic");
@@ -157,6 +168,7 @@ public abstract class WsnBrokerTest exte
         pullPoint.destroy();
     }
 
+    @Test
     public void testPublisher() throws Exception {
         TestConsumer consumerCallback = new TestConsumer();
         Consumer consumer = new Consumer(consumerCallback, "http://localhost:" + port2 + "/test/consumer");
@@ -176,16 +188,17 @@ public abstract class WsnBrokerTest exte
         }
         assertEquals(1, consumerCallback.notifications.size());
         NotificationMessageHolderType message = consumerCallback.notifications.get(0);
-        assertEquals(WSNHelper.getWSAAddress(subscription.getEpr()),
-                     WSNHelper.getWSAAddress(message.getSubscriptionReference()));
-        assertEquals(WSNHelper.getWSAAddress(publisher.getEpr()),
-                     WSNHelper.getWSAAddress(message.getProducerReference()));
+        assertEquals(WSNHelper.getInstance().getWSAAddress(subscription.getEpr()),
+                     WSNHelper.getInstance().getWSAAddress(message.getSubscriptionReference()));
+        assertEquals(WSNHelper.getInstance().getWSAAddress(publisher.getEpr()),
+                     WSNHelper.getInstance().getWSAAddress(message.getProducerReference()));
 
         subscription.unsubscribe();
         registration.destroy();
         publisher.stop();
         consumer.stop();
     }
+    @Test
     public void testNullPublisherReference() throws Exception {
         TestConsumer consumerCallback = new TestConsumer();
         Consumer consumer = new Consumer(consumerCallback, "http://localhost:" + port2 + "/test/consumer");
@@ -203,14 +216,15 @@ public abstract class WsnBrokerTest exte
         }
         assertEquals(1, consumerCallback.notifications.size());
         NotificationMessageHolderType message = consumerCallback.notifications.get(0);
-        assertEquals(WSNHelper.getWSAAddress(subscription.getEpr()),
-                     WSNHelper.getWSAAddress(message.getSubscriptionReference()));
+        assertEquals(WSNHelper.getInstance().getWSAAddress(subscription.getEpr()),
+                     WSNHelper.getInstance().getWSAAddress(message.getSubscriptionReference()));
 
         subscription.unsubscribe();
         registration.destroy();
         publisher.stop();
         consumer.stop();
     }
+    @Test
     public void testPublisherOnDemand() throws Exception {
         TestConsumer consumerCallback = new TestConsumer();
         Consumer consumer = new Consumer(consumerCallback, "http://localhost:" + port2 + "/test/consumer");
@@ -240,6 +254,40 @@ public abstract class WsnBrokerTest exte
         publisher.stop();
         consumer.stop();
     }
+    
+    @Test
+    public void testPublisherCustomType() throws Exception {
+        notificationBroker.setExtraClasses(CustomType.class);
+        
+        TestConsumer consumerCallback = new TestConsumer();
+        Consumer consumer = new Consumer(consumerCallback,
+                                         "http://localhost:" + port2 + "/test/consumer",
+                                         CustomType.class);
+        
+        Subscription subscription = notificationBroker.subscribe(consumer, "myTopic");
+
+        PublisherCallback publisherCallback = new PublisherCallback();
+        Publisher publisher = new Publisher(publisherCallback, "http://localhost:" + port2 
+                                            + "/test/publisher");
+        Registration registration = notificationBroker.registerPublisher(publisher, "myTopic");
+
+        synchronized (consumerCallback.notifications) {
+            notificationBroker.notify(publisher, "myTopic", new CustomType(1, 2));
+            consumerCallback.notifications.wait(1000000);
+        }
+        assertEquals(1, consumerCallback.notifications.size());
+        NotificationMessageHolderType message = consumerCallback.notifications.get(0);
+        assertEquals(WSNHelper.getInstance().getWSAAddress(subscription.getEpr()),
+                     WSNHelper.getInstance().getWSAAddress(message.getSubscriptionReference()));
+        assertEquals(WSNHelper.getInstance().getWSAAddress(publisher.getEpr()),
+                     WSNHelper.getInstance().getWSAAddress(message.getProducerReference()));
+        assertTrue(message.getMessage().getAny() instanceof CustomType);
+
+        subscription.unsubscribe();
+        registration.destroy();
+        publisher.stop();
+        consumer.stop();
+    }
 
     public static class TestConsumer implements Consumer.Callback {
 

Added: cxf/trunk/services/wsn/wsn-core/src/test/java/org/apache/cxf/wsn/types/CustomType.java
URL: http://svn.apache.org/viewvc/cxf/trunk/services/wsn/wsn-core/src/test/java/org/apache/cxf/wsn/types/CustomType.java?rev=1305895&view=auto
==============================================================================
--- cxf/trunk/services/wsn/wsn-core/src/test/java/org/apache/cxf/wsn/types/CustomType.java (added)
+++ cxf/trunk/services/wsn/wsn-core/src/test/java/org/apache/cxf/wsn/types/CustomType.java Tue Mar 27 16:37:34 2012
@@ -0,0 +1,85 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.cxf.wsn.types;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+/**
+ * 
+ */
+@XmlRootElement(name = "customType", namespace = "http://example/")
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "customType", namespace = "http://example/", 
+    propOrder = { "arg0", "arg1" })
+public class CustomType {
+    @XmlElement(name = "arg0", namespace = "")
+    private int arg0;
+    @XmlElement(name = "arg1", namespace = "")
+    private int arg1;
+
+    public CustomType() {
+    }
+    
+    public CustomType(int a, int b) {
+        arg0 = a;
+        arg1 = b;
+    }
+    
+    /**
+     * 
+     * @return
+     *     returns int
+     */
+    public int getArg0() {
+        return this.arg0;
+    }
+
+    /**
+     * 
+     * @param arg0
+     *     the value for the arg0 property
+     */
+    public void setArg0(int arg0) {
+        this.arg0 = arg0;
+    }
+
+    /**
+     * 
+     * @return
+     *     returns int
+     */
+    public int getArg1() {
+        return this.arg1;
+    }
+
+    /**
+     * 
+     * @param arg1
+     *     the value for the arg1 property
+     */
+    public void setArg1(int arg1) {
+        this.arg1 = arg1;
+    }
+
+}
\ No newline at end of file

Propchange: cxf/trunk/services/wsn/wsn-core/src/test/java/org/apache/cxf/wsn/types/CustomType.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/services/wsn/wsn-core/src/test/java/org/apache/cxf/wsn/types/CustomType.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date