Title: [929] trunk/servicemix-jsr181: Improve jsr181 component :
Revision
929
Author
gnt
Date
2005-11-24 17:37:55 -0500 (Thu, 24 Nov 2005)

Log Message

Improve jsr181 component : 
  * annotations / type-mapping is now configured per endpoint
  * use xbean syntax for the xml config file
  * inject the component context so that components can send messages
  * can give an existing spring bean or a class name for the pojo

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/servicemix-jsr181/maven.xml (928 => 929)

--- trunk/servicemix-jsr181/maven.xml	2005-11-24 15:04:45 UTC (rev 928)
+++ trunk/servicemix-jsr181/maven.xml	2005-11-24 22:37:55 UTC (rev 929)
@@ -7,4 +7,25 @@
 
   <goal name="nightly" prereqs="clean, jbi:install, jbi:deploy"/>
 
+  <postGoal name="java:compile">
+    <attainGoal name="xbean:generate" />
+  </postGoal>
+
+  <goal name="xbean:generate" description="Generates the XBean XSD, documentation and META-INF/services files.">
+    <path id="test.classpath">
+      <pathelement path="${maven.build.dest}" />
+      <pathelement path="${basedir}/target/classes" />
+      <pathelement path="${basedir}/target/test-classes" />
+      <path refid="maven.dependency.classpath" />
+    </path>
+
+    <taskdef name="xsdGenerate" classname="org.xbean.spring.generator.MappingGeneratorTask">
+      <classpath refid="test.classpath" />
+    </taskdef>
+    <xsdGenerate destFile="${basedir}/target/servicemix-jsr181-${pom.currentVersion}.xsd" namespace="http://servicemix.org/jsr181/1.0"
+    		classpathref="test.classpath" srcdir="${basedir}/src/main/java"  metaInfDir="${basedir}/target/generated/"/>
+  	<copy file="${basedir}/target/servicemix-jsr181-${pom.currentVersion}.xsd" todir="${basedir}/target/generated/"/>
+  	<copy file="${basedir}/target/servicemix-jsr181-${pom.currentVersion}.xsd" todir="${basedir}/../xdocs"/>    
+    <copy file="${basedir}/target/servicemix-jsr181-${pom.currentVersion}.xsd.html" todir="${basedir}/../xdocs"/>
+  </goal>
 </project>

Modified: trunk/servicemix-jsr181/project.xml (928 => 929)

--- trunk/servicemix-jsr181/project.xml	2005-11-24 15:04:45 UTC (rev 928)
+++ trunk/servicemix-jsr181/project.xml	2005-11-24 22:37:55 UTC (rev 929)
@@ -256,6 +256,41 @@
         <version>${log4j_version}</version>
       </dependency>
 
+      <dependency>
+        <groupId>annogen</groupId>
+        <artifactId>annogen</artifactId>
+        <version>${annogen_version}</version>
+        <properties>
+          <scope>compile</scope>
+        </properties>
+      </dependency>
+      <dependency>
+        <groupId>qdox</groupId>
+        <artifactId>qdox</artifactId>
+        <version>${qdox_version}</version>
+        <properties>
+          <scope>compile</scope>
+        </properties>
+      </dependency>
     </dependencies>  
 
+    <build>
+        <resources>
+            <resource>
+                <directory>src/main/resources</directory>
+                <includes>
+                    <include>**/*.properties</include>
+                    <include>**/*.xml</include>
+                    <include>**/*</include>
+                </includes>
+            </resource>
+            <resource>
+                <directory>target/generated</directory>
+                <includes>
+                    <include>**/*</include>
+                </includes>
+                <filtering>false</filtering>
+            </resource>
+        </resources>
+    </build>
 </project>

Modified: trunk/servicemix-jsr181/src/main/java/org/servicemix/jsr181/Jsr181Bootstrap.java (928 => 929)

--- trunk/servicemix-jsr181/src/main/java/org/servicemix/jsr181/Jsr181Bootstrap.java	2005-11-24 15:04:45 UTC (rev 928)
+++ trunk/servicemix-jsr181/src/main/java/org/servicemix/jsr181/Jsr181Bootstrap.java	2005-11-24 22:37:55 UTC (rev 929)
@@ -21,34 +21,4 @@
 
 public class Jsr181Bootstrap extends BaseBootstrap {
 
-    private Jsr181Configuration configuration;
-    
-    public Jsr181Bootstrap() {
-        configuration = new Jsr181Configuration();
-    }
-    
-    /* (non-Javadoc)
-     * @see org.servicemix.common.BaseBootstrap#getExtensionMBean()
-     */
-    protected Object getExtensionMBean() throws Exception {
-        return configuration;
-    }
-
-    /* (non-Javadoc)
-     * @see org.servicemix.common.BaseBootstrap#doInit()
-     */
-    protected void doInit() throws Exception {
-        super.doInit();
-        configuration.setRootDir(this.context.getContext().getWorkspaceRoot());
-        configuration.load();
-     }
-
-    /* (non-Javadoc)
-     * @see org.servicemix.common.BaseBootstrap#doOnInstall()
-     */
-    protected void doOnInstall() throws Exception {
-        super.doOnInstall();
-        configuration.save();
-    }
-
 }

Deleted: trunk/servicemix-jsr181/src/main/java/org/servicemix/jsr181/Jsr181Configuration.java (928 => 929)

--- trunk/servicemix-jsr181/src/main/java/org/servicemix/jsr181/Jsr181Configuration.java	2005-11-24 15:04:45 UTC (rev 928)
+++ trunk/servicemix-jsr181/src/main/java/org/servicemix/jsr181/Jsr181Configuration.java	2005-11-24 22:37:55 UTC (rev 929)
@@ -1,63 +0,0 @@
-/** 
- * 
- * Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
- * 
- * 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.servicemix.jsr181;
-
-import org.servicemix.common.PersistentConfiguration;
-
-
-public class Jsr181Configuration extends PersistentConfiguration implements Jsr181ConfigurationMBean {
-
-    public static final String WEBANNOTATIONSCLASS_PROPERTY = "webAnnotationsClass";
-    public static final String WEBANNOTATIONSCLASS_DEFAULT = "org.codehaus.xfire.annotations.jsr181.Jsr181WebAnnotations";
-    public static final String TYPEMAPPINGREGISTRYCLASS_PROPERTY = "typeMappingRegistryClass";
-    public static final String TYPEMAPPINGREGISTRYCLASS_DEFAULT = "org.codehaus.xfire.jaxb2.JaxbTypeRegistry";
-    
-    public Jsr181Configuration() {
-    }
-
-    /* (non-Javadoc)
-     * @see org.servicemix.jsr181.Jsr181ConfigurationMBean#getTypeMappingRegistryClass()
-     */
-    public String getTypeMappingRegistryClass() {
-        return properties.getProperty(TYPEMAPPINGREGISTRYCLASS_PROPERTY, TYPEMAPPINGREGISTRYCLASS_DEFAULT);
-    }
-
-    /* (non-Javadoc)
-     * @see org.servicemix.jsr181.Jsr181ConfigurationMBean#setTypeMappingRegistryClass(java.lang.String)
-     */
-    public void setTypeMappingRegistryClass(String typeMappingRegistryClass) {
-        this.properties.put(TYPEMAPPINGREGISTRYCLASS_PROPERTY, typeMappingRegistryClass);
-        save();
-    }
-
-    /* (non-Javadoc)
-     * @see org.servicemix.jsr181.Jsr181ConfigurationMBean#getWebAnnotationsClass()
-     */
-    public String getWebAnnotationsClass() {
-        return properties.getProperty(WEBANNOTATIONSCLASS_PROPERTY, WEBANNOTATIONSCLASS_DEFAULT);
-    }
-
-    /* (non-Javadoc)
-     * @see org.servicemix.jsr181.Jsr181ConfigurationMBean#setWebAnnotationsClass(java.lang.String)
-     */
-    public void setWebAnnotationsClass(String webAnnotationsClass) {
-        this.properties.put(WEBANNOTATIONSCLASS_PROPERTY, webAnnotationsClass);
-        save();
-    }
-    
-}

Deleted: trunk/servicemix-jsr181/src/main/java/org/servicemix/jsr181/Jsr181ConfigurationMBean.java (928 => 929)

--- trunk/servicemix-jsr181/src/main/java/org/servicemix/jsr181/Jsr181ConfigurationMBean.java	2005-11-24 15:04:45 UTC (rev 928)
+++ trunk/servicemix-jsr181/src/main/java/org/servicemix/jsr181/Jsr181ConfigurationMBean.java	2005-11-24 22:37:55 UTC (rev 929)
@@ -1,41 +0,0 @@
-/** 
- * 
- * Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
- * 
- * 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.servicemix.jsr181;
-
-public interface Jsr181ConfigurationMBean {
-
-    /**
-     * @return Returns the typeMappingRegistryClass.
-     */
-    String getTypeMappingRegistryClass();
-
-    /**
-     * @param typeMappingRegistryClass The typeMappingRegistryClass to set.
-     */
-    void setTypeMappingRegistryClass(String typeMappingRegistryClass);
-
-    /**
-     * @return Returns the webAnnotationsClass.
-     */
-    String getWebAnnotationsClass();
-
-    /**
-     * @param webAnnotationsClass The webAnnotationsClass to set.
-     */
-    void setWebAnnotationsClass(String webAnnotationsClass);
-}

Modified: trunk/servicemix-jsr181/src/main/java/org/servicemix/jsr181/Jsr181Endpoint.java (928 => 929)

--- trunk/servicemix-jsr181/src/main/java/org/servicemix/jsr181/Jsr181Endpoint.java	2005-11-24 15:04:45 UTC (rev 928)
+++ trunk/servicemix-jsr181/src/main/java/org/servicemix/jsr181/Jsr181Endpoint.java	2005-11-24 22:37:55 UTC (rev 929)
@@ -17,37 +17,77 @@
  **/
 package org.servicemix.jsr181;
 
-import org.apache.commons.logging.Log;
-import org.codehaus.xfire.XFire;
-import org.codehaus.xfire.service.Service;
-import org.codehaus.xfire.service.ServiceFactory;
-import org.codehaus.xfire.transport.Transport;
-import org.servicemix.common.Endpoint;
-import org.servicemix.jsr181.xfire.JbiTransport;
-import org.w3c.dom.Document;
-import org.xml.sax.SAXException;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
 
 import javax.jbi.component.ComponentContext;
 import javax.jbi.messaging.MessageExchange.Role;
 import javax.jbi.servicedesc.ServiceEndpoint;
 import javax.wsdl.Definition;
 import javax.wsdl.Port;
-import javax.wsdl.WSDLException;
 import javax.wsdl.factory.WSDLFactory;
 import javax.xml.namespace.QName;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
+import org.codehaus.xfire.XFire;
+import org.codehaus.xfire.aegis.AegisBindingProvider;
+import org.codehaus.xfire.aegis.type.DefaultTypeMappingRegistry;
+import org.codehaus.xfire.aegis.type.TypeMappingRegistry;
+import org.codehaus.xfire.annotations.AnnotationServiceFactory;
+import org.codehaus.xfire.annotations.WebAnnotations;
+import org.codehaus.xfire.annotations.backport175.Backport175WebAnnotations;
+import org.codehaus.xfire.annotations.commons.CommonsWebAttributes;
+import org.codehaus.xfire.annotations.jsr181.Jsr181WebAnnotations;
+import org.codehaus.xfire.jaxb2.JaxbTypeRegistry;
+import org.codehaus.xfire.service.Service;
+import org.codehaus.xfire.service.ServiceFactory;
+import org.codehaus.xfire.service.binding.BeanInvoker;
+import org.codehaus.xfire.service.binding.ObjectServiceFactory;
+import org.codehaus.xfire.transport.Transport;
+import org.codehaus.xfire.xmlbeans.XmlBeansTypeRegistry;
+import org.servicemix.common.Endpoint;
+import org.servicemix.jsr181.xfire.JbiTransport;
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
 
+/**
+ * 
+ * @author gnodet
+ * @version $Revision: 908 $
+ * @org.xbean.XBean element="endpoint"
+ *                  description="A jsr181 endpoint"
+ * 
+ */
 public class Jsr181Endpoint extends Endpoint {
 
+    private static final Map knownTypeMappings;
+    private static final Map knownAnnotations;
+    
+    static {
+        knownTypeMappings = new HashMap();
+        knownTypeMappings.put("default", new DefaultTypeMappingRegistry(true));
+        knownTypeMappings.put("jaxb2", new JaxbTypeRegistry());
+        knownTypeMappings.put("xmlbeans", new XmlBeansTypeRegistry());
+        
+        knownAnnotations = new HashMap();
+        knownAnnotations.put("backport", new Backport175WebAnnotations());
+        knownAnnotations.put("commons", new CommonsWebAttributes());
+        knownAnnotations.put("java5", new Jsr181WebAnnotations());
+    }
+    
     protected Object pojo;
+    protected String pojoClass;
+    protected String annotations;
+    protected String typeMapping;
+    
     protected ServiceEndpoint activated;
     protected Service xfireService;
-    protected Log logger;
     
     /**
      * @return Returns the pojo.
@@ -72,6 +112,7 @@
 
     /* (non-Javadoc)
      * @see org.servicemix.common.Endpoint#getRole()
+     * @org.xbean.XBean hide="true"
      */
     public Role getRole() {
         return Role.PROVIDER;
@@ -84,7 +125,7 @@
         logger = this.serviceUnit.getComponent().getLogger();
         ComponentContext ctx = this.serviceUnit.getComponent().getComponentContext();
         activated = ctx.activateEndpoint(service, endpoint);
-        
+        injectContext(ctx);
     }
 
     /* (non-Javadoc)
@@ -95,13 +136,68 @@
         activated = null;
         ComponentContext ctx = this.serviceUnit.getComponent().getComponentContext();
         ctx.deactivateEndpoint(ep);
+        injectContext(null);
     }
 
+    protected void injectContext(ComponentContext context) {
+        try {
+            Method mth = pojo.getClass().getMethod("setContext", new Class[] { ComponentContext.class });
+            mth.invoke(pojo, new Object[] { context });
+        } catch (Exception e) {
+            logger.debug("Unable to inject ComponentContext", e);
+        }
+    }
 
-    public void registerService() throws SAXException, IOException, ParserConfigurationException, WSDLException {
+    public void registerService() throws Exception {
+        if (pojo == null) {
+            Class cl = Class.forName(pojoClass);
+            pojo = cl.newInstance();
+        }
+        // Determine annotations
+        WebAnnotations wa = null;
+        if (annotations != null) {
+            if (!annotations.equals("none")) {
+                wa = (WebAnnotations) knownAnnotations.get(annotations);
+                if (wa == null) {
+                    throw new Exception("Unrecognized annotations: " + annotations);
+                }
+            }
+        } else {
+            for (Iterator it = knownAnnotations.values().iterator(); it.hasNext();) {
+                WebAnnotations w = (WebAnnotations) it.next();
+                if (w.hasWebServiceAnnotation(pojo.getClass())) {
+                    wa = w;
+                    break;
+                }
+            }
+        }
+        // Determine TypeMappingRegistry
+        TypeMappingRegistry tm = null;
+        if (typeMapping == null) {
+            if (wa == null) {
+                tm = (TypeMappingRegistry) knownTypeMappings.get("default");
+            } else {
+                tm = (TypeMappingRegistry) knownTypeMappings.get("jaxb2");
+            }
+        } else {
+            tm = (TypeMappingRegistry) knownTypeMappings.get(typeMapping);
+            if (tm == null) {
+                throw new Exception("Unrecognized typeMapping: " + typeMapping);
+            }
+        }
+        // Create factory
         XFire xfire = getXFire();
-        ServiceFactory factory = getServiceFactory();
+        ServiceFactory factory = null;
+        if (wa == null) {
+            factory = new ObjectServiceFactory(xfire.getTransportManager(),
+                                               new AegisBindingProvider(tm));
+        } else {
+            factory = new AnnotationServiceFactory(wa, 
+                                                   xfire.getTransportManager(), 
+                                                   new AegisBindingProvider(tm));
+        }
         xfireService = factory.create(getPojo().getClass());
+        xfireService.setInvoker(new BeanInvoker(getPojo()));
         xfire.getServiceRegistry().register(xfireService);
         xfire.getTransportManager().disableAll(xfireService.getName());
         Transport jbiT = xfire.getTransportManager().getTransport(JbiTransport.JBI_BINDING);
@@ -153,10 +249,38 @@
         return xfire;
     }
     
-    protected ServiceFactory getServiceFactory() {
-        Jsr181LifeCycle jsr181LifeCycle = (Jsr181LifeCycle) this.serviceUnit.getComponent().getLifeCycle();
-        ServiceFactory factory = jsr181LifeCycle.getFactory();
-        return factory;
+    public String getPojoClass() {
+        return pojoClass;
     }
 
+    /**
+     * 
+     * @param pojoClass
+     * @org.xbean.Property alias="pojo-class"
+     */
+    public void setPojoClass(String pojoClass) {
+        this.pojoClass = pojoClass;
+    }
+
+    public String getAnnotations() {
+        return annotations;
+    }
+
+    public void setAnnotations(String annotations) {
+        this.annotations = annotations;
+    }
+
+    public String getTypeMapping() {
+        return typeMapping;
+    }
+
+    /**
+     * 
+     * @param pojoClass
+     * @org.xbean.Property alias="type-mapping"
+     */
+    public void setTypeMapping(String typeMapping) {
+        this.typeMapping = typeMapping;
+    }
+
 }

Modified: trunk/servicemix-jsr181/src/main/java/org/servicemix/jsr181/Jsr181LifeCycle.java (928 => 929)

--- trunk/servicemix-jsr181/src/main/java/org/servicemix/jsr181/Jsr181LifeCycle.java	2005-11-24 15:04:45 UTC (rev 928)
+++ trunk/servicemix-jsr181/src/main/java/org/servicemix/jsr181/Jsr181LifeCycle.java	2005-11-24 22:37:55 UTC (rev 929)
@@ -17,22 +17,8 @@
  **/
 package org.servicemix.jsr181;
 
-import org.codehaus.xfire.MessageContext;
-import org.codehaus.xfire.XFire;
-import org.codehaus.xfire.XFireFactory;
-import org.codehaus.xfire.aegis.AegisBindingProvider;
-import org.codehaus.xfire.aegis.type.TypeMappingRegistry;
-import org.codehaus.xfire.annotations.AnnotationServiceFactory;
-import org.codehaus.xfire.annotations.WebAnnotations;
-import org.codehaus.xfire.exchange.InMessage;
-import org.codehaus.xfire.service.Service;
-import org.codehaus.xfire.service.ServiceFactory;
-import org.codehaus.xfire.transport.Channel;
-import org.codehaus.xfire.transport.Transport;
-import org.servicemix.common.BaseLifeCycle;
-import org.servicemix.common.Endpoint;
-import org.servicemix.jbi.jaxp.BytesSource;
-import org.servicemix.jsr181.xfire.JbiTransport;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 
 import javax.jbi.messaging.ExchangeStatus;
 import javax.jbi.messaging.Fault;
@@ -48,49 +34,34 @@
 import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.stream.StreamResult;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
+import org.codehaus.xfire.MessageContext;
+import org.codehaus.xfire.XFire;
+import org.codehaus.xfire.XFireFactory;
+import org.codehaus.xfire.exchange.InMessage;
+import org.codehaus.xfire.service.Service;
+import org.codehaus.xfire.transport.Channel;
+import org.codehaus.xfire.transport.Transport;
+import org.servicemix.common.BaseLifeCycle;
+import org.servicemix.common.Endpoint;
+import org.servicemix.jbi.jaxp.BytesSource;
+import org.servicemix.jsr181.xfire.JbiTransport;
 
 public class Jsr181LifeCycle extends BaseLifeCycle {
 
-    protected Jsr181Configuration configuration;
     protected XFire xfire;
-    protected ServiceFactory factory;
     
     public Jsr181LifeCycle(Jsr181Component component) {
         super(component);
-        configuration = new Jsr181Configuration();
     }
 
     /**
-     * @return Returns the factory.
-     */
-    public ServiceFactory getFactory() {
-        return factory;
-    }
-
-    /**
      * @return Returns the xfire.
      */
     public XFire getXFire() {
         return xfire;
     }
 
-    /**
-     * @return Returns the configuration.
-     */
-    public Jsr181Configuration getConfiguration() {
-        return configuration;
-    }
-
     /* (non-Javadoc)
-     * @see org.servicemix.common.BaseBootstrap#getExtensionMBean()
-     */
-    protected Object getExtensionMBean() throws Exception {
-        return configuration;
-    }
-
-    /* (non-Javadoc)
      * @see org.servicemix.common.BaseLifeCycle#processProviderExchange(org.servicemix.common.Endpoint, javax.jbi.messaging.MessageExchange)
      */
     protected void processProviderExchange(Endpoint ep, MessageExchange exchange) throws Exception {
@@ -136,23 +107,14 @@
      */
     protected void doInit() throws Exception {
         super.doInit();
-        configuration.setRootDir(this.context.getWorkspaceRoot());
-        configuration.load();
         xfire = XFireFactory.newInstance().getXFire();
+        Object[] transports = xfire.getTransportManager().getTransports().toArray();
+        for (int i = 0; i < transports.length; i++) {
+            xfire.getTransportManager().unregister((Transport) transports[i]);
+        }
         xfire.getTransportManager().register(new JbiTransport());
-        WebAnnotations webAnnotations = (WebAnnotations) createInstance(configuration.getWebAnnotationsClass());
-        TypeMappingRegistry tmRegistry = (TypeMappingRegistry) createInstance(configuration.getTypeMappingRegistryClass());
-        factory = new AnnotationServiceFactory(
-                        webAnnotations, 
-                        xfire.getTransportManager(), 
-                        new AegisBindingProvider(tmRegistry));
     }
     
-    protected Object createInstance(String className) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
-        Class cl = Class.forName(className);
-        return cl.newInstance();
-    }
-    
     protected XMLStreamReader getXMLStreamReader(Source source) throws TransformerException, XMLStreamException {
         try {
             return XMLInputFactory.newInstance().createXMLStreamReader(source);

Modified: trunk/servicemix-jsr181/src/main/java/org/servicemix/jsr181/Jsr181XBeanDeployer.java (928 => 929)

--- trunk/servicemix-jsr181/src/main/java/org/servicemix/jsr181/Jsr181XBeanDeployer.java	2005-11-24 15:04:45 UTC (rev 928)
+++ trunk/servicemix-jsr181/src/main/java/org/servicemix/jsr181/Jsr181XBeanDeployer.java	2005-11-24 22:37:55 UTC (rev 929)
@@ -33,8 +33,8 @@
             throw failure("deploy", "Endpoint should be a Jsr181 endpoint", null);
         }
         Jsr181Endpoint ep = (Jsr181Endpoint) endpoint;
-        if (ep.getPojo() == null) {
-            throw failure("deploy", "Endpoint must have a non-null pojo", null);
+        if (ep.getPojo() == null && ep.getPojoClass() == null) {
+            throw failure("deploy", "Endpoint must have a non-null pojo or a pojoClass", null);
         }
         try {
             ep.registerService();

Modified: trunk/servicemix-jsr181/src/main/java/org/servicemix/jsr181/xfire/JbiChannel.java (928 => 929)

--- trunk/servicemix-jsr181/src/main/java/org/servicemix/jsr181/xfire/JbiChannel.java	2005-11-24 15:04:45 UTC (rev 928)
+++ trunk/servicemix-jsr181/src/main/java/org/servicemix/jsr181/xfire/JbiChannel.java	2005-11-24 22:37:55 UTC (rev 929)
@@ -17,6 +17,11 @@
  **/
 package org.servicemix.jsr181.xfire;
 
+import java.io.OutputStream;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
 import org.codehaus.xfire.MessageContext;
 import org.codehaus.xfire.XFireException;
 import org.codehaus.xfire.exchange.OutMessage;
@@ -24,11 +29,6 @@
 import org.codehaus.xfire.transport.Channel;
 import org.codehaus.xfire.util.STAXUtils;
 
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
-
-import java.io.OutputStream;
-
 /**
  * Jbi channel, only support local invocations. 
  */

Modified: trunk/servicemix-jsr181/src/main/java/org/servicemix/jsr181/xfire/JbiTransport.java (928 => 929)

--- trunk/servicemix-jsr181/src/main/java/org/servicemix/jsr181/xfire/JbiTransport.java	2005-11-24 15:04:45 UTC (rev 928)
+++ trunk/servicemix-jsr181/src/main/java/org/servicemix/jsr181/xfire/JbiTransport.java	2005-11-24 22:37:55 UTC (rev 929)
@@ -19,7 +19,10 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.codehaus.xfire.handler.LocateBindingHandler;
 import org.codehaus.xfire.service.Service;
+import org.codehaus.xfire.soap.SoapTransport;
+import org.codehaus.xfire.soap.handler.SoapBindingHandler;
 import org.codehaus.xfire.transport.AbstractTransport;
 import org.codehaus.xfire.transport.Channel;
 import org.codehaus.xfire.transport.DefaultEndpoint;
@@ -30,7 +33,7 @@
  * but without soap encoding. 
  * 
  */
-public class JbiTransport extends AbstractTransport implements WSDL11Transport {
+public class JbiTransport extends AbstractTransport implements WSDL11Transport, SoapTransport {
 
     private static final Log log = LogFactory.getLog(JbiTransport.class);
     
@@ -42,10 +45,11 @@
 
     public JbiTransport() {
         addInHandler(new PrepareHandler());
+        addInHandler(new LocateBindingHandler());
+        addInHandler(new SoapBindingHandler());
     }
     
-    public String getName()
-    {
+    public String getName() {
         return "JBI";
     }
     

Modified: trunk/servicemix-jsr181/src/test/java/org/servicemix/jsr181/Jsr181ComponentTest.java (928 => 929)

--- trunk/servicemix-jsr181/src/test/java/org/servicemix/jsr181/Jsr181ComponentTest.java	2005-11-24 15:04:45 UTC (rev 928)
+++ trunk/servicemix-jsr181/src/test/java/org/servicemix/jsr181/Jsr181ComponentTest.java	2005-11-24 22:37:55 UTC (rev 929)
@@ -1,23 +1,44 @@
+/** 
+ * 
+ * Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
+ * 
+ * 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.servicemix.jsr181;
 
-import org.codehaus.xfire.annotations.commons.CommonsWebAttributes;
-import org.codehaus.xfire.xmlbeans.XmlBeansTypeRegistry;
-import org.servicemix.client.DefaultServiceMixClient;
-import org.servicemix.jbi.container.JBIContainer;
-import org.servicemix.jbi.jaxp.SourceTransformer;
-import org.servicemix.jbi.jaxp.StringSource;
+import java.io.File;
+import java.net.URL;
 
 import javax.jbi.messaging.InOut;
 import javax.naming.InitialContext;
 import javax.xml.namespace.QName;
 
-import java.io.File;
-import java.net.URL;
-
 import junit.framework.TestCase;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.servicemix.client.DefaultServiceMixClient;
+import org.servicemix.jbi.container.JBIContainer;
+import org.servicemix.jbi.jaxp.SourceTransformer;
+import org.servicemix.jbi.jaxp.StringSource;
+
+import test.EchoService;
+
 public class Jsr181ComponentTest extends TestCase {
 
+    private static Log logger =  LogFactory.getLog(Jsr181ComponentTest.class);
+    
     protected JBIContainer container;
     
     protected void setUp() throws Exception {
@@ -37,23 +58,19 @@
     
     public void testCommonsAnnotations() throws Exception {
         Jsr181Component component = new Jsr181Component();
-        Jsr181LifeCycle lifecycle = (Jsr181LifeCycle) component.getLifeCycle();
-        lifecycle.getConfiguration().setTypeMappingRegistryClass(XmlBeansTypeRegistry.class.getName());
-        lifecycle.getConfiguration().setWebAnnotationsClass(CommonsWebAttributes.class.getName());
         container.activateComponent(component, "JSR181Component");
 
         // Start container
         container.start();
         
         // Deploy SU
-        URL url = ""
-        File path = new File(url.getFile());
-        path = path.getParentFile();
-        System.err.println(path.getAbsolutePath());
-        component.getServiceUnitManager().deploy("su", path.getAbsolutePath());
-        component.getServiceUnitManager().init("su", path.getAbsolutePath());
+        component.getServiceUnitManager().deploy("su", getServiceUnitPath("good1"));
+        component.getServiceUnitManager().init("su", getServiceUnitPath("good1"));
         component.getServiceUnitManager().start("su");
         
+        assertNotNull(EchoService.instance);
+        assertNotNull(EchoService.instance.getContext());
+        
         // Call it
         DefaultServiceMixClient client = new DefaultServiceMixClient(container);
         InOut me = client.createInOutExchange();
@@ -61,11 +78,94 @@
         me.getInMessage().setContent(new StringSource("<echo xmlns='http://test'><in0>world</in0></echo>"));
         client.sendSync(me);
         if (me.getFault() != null) {
-            System.err.println("!!! FAULT !!!!");
-            System.err.println(new SourceTransformer().toString(me.getFault().getContent()));
+            logger.info("!!! FAULT !!!!");
+            logger.info(new SourceTransformer().toString(me.getFault().getContent()));
         }
-        System.err.println(new SourceTransformer().toString(me.getOutMessage().getContent()));
+        logger.info(new SourceTransformer().toString(me.getOutMessage().getContent()));
+    }
+    
+    
+    public void testWithoutAnnotations() throws Exception {
+        Jsr181Component component = new Jsr181Component();
+        container.activateComponent(component, "JSR181Component");
+
+        // Start container
+        container.start();
         
+        // Deploy SU
+        component.getServiceUnitManager().deploy("good2", getServiceUnitPath("good2"));
+        component.getServiceUnitManager().init("good2", getServiceUnitPath("good2"));
+        component.getServiceUnitManager().start("good2");
+        
+        assertNotNull(EchoService.instance);
+        assertNotNull(EchoService.instance.getContext());
+        
+        // Call it
+        DefaultServiceMixClient client = new DefaultServiceMixClient(container);
+        InOut me = client.createInOutExchange();
+        me.setInterfaceName(new QName("http://test", "EchoService2PortType"));
+        me.getInMessage().setContent(new StringSource("<echo xmlns='http://test'><in0>world</in0></echo>"));
+        client.sendSync(me);
+        if (me.getFault() != null) {
+            logger.info("!!! FAULT !!!!");
+            logger.info(new SourceTransformer().toString(me.getFault().getContent()));
+        }
+        logger.info(new SourceTransformer().toString(me.getOutMessage().getContent()));
     }
     
+    public void testDeployUndeploy() throws Exception {
+        Jsr181Component component = new Jsr181Component();
+        container.activateComponent(component, "JSR181Component");
+        component.getServiceUnitManager().deploy("d/u", getServiceUnitPath("good1"));
+        component.getServiceUnitManager().shutDown("d/u");
+        component.getServiceUnitManager().undeploy("d/u", getServiceUnitPath("good1"));
+        component.getServiceUnitManager().deploy("d/u", getServiceUnitPath("good1"));
+        component.getServiceUnitManager().start("d/u");
+        component.getServiceUnitManager().stop("d/u");
+        component.getServiceUnitManager().shutDown("d/u");
+    }
+    
+    public void testNoPojoNoClass() throws Exception {
+        Jsr181Component component = new Jsr181Component();
+        container.activateComponent(component, "JSR181Component");
+        try {
+            component.getServiceUnitManager().deploy("bad1", getServiceUnitPath("bad1"));
+            fail("Expected an exception");
+        } catch (Exception e) {
+            // ok
+            logger.info(e.getMessage());
+        }
+    }
+    
+    public void testNoEndpoints() throws Exception {
+        Jsr181Component component = new Jsr181Component();
+        container.activateComponent(component, "JSR181Component");
+        try {
+            component.getServiceUnitManager().deploy("bad2", getServiceUnitPath("bad2"));
+            fail("Expected an exception");
+        } catch (Exception e) {
+            // ok
+            logger.info(e.getMessage());
+        }
+    }
+    
+    public void testDuplicates() throws Exception {
+        Jsr181Component component = new Jsr181Component();
+        container.activateComponent(component, "JSR181Component");
+        try {
+            component.getServiceUnitManager().deploy("bad3", getServiceUnitPath("bad3"));
+            fail("Expected an exception");
+        } catch (Exception e) {
+            // ok
+            logger.info(e.getMessage());
+        }
+    }
+    
+    protected String getServiceUnitPath(String name) {
+        URL url = "" + "/xbean.xml");
+        File path = new File(url.getFile());
+        path = path.getParentFile();
+        return path.getAbsolutePath();
+    }
+    
 }

Modified: trunk/servicemix-jsr181/src/test/java/test/EchoService.java (928 => 929)

--- trunk/servicemix-jsr181/src/test/java/test/EchoService.java	2005-11-24 15:04:45 UTC (rev 928)
+++ trunk/servicemix-jsr181/src/test/java/test/EchoService.java	2005-11-24 22:37:55 UTC (rev 929)
@@ -1,17 +1,52 @@
+/** 
+ * 
+ * Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
+ * 
+ * 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 test;
 
+import javax.jbi.component.ComponentContext;
 
+
 /**
  * @@org.codehaus.xfire.annotations.commons.WebService(name = "EchoService")
  * @@org.codehaus.xfire.annotations.commons.soap.SOAPBinding(style = 0)
  */
 public class EchoService {
+    
+    public static EchoService instance;
+    
+    private ComponentContext context;
 
+    public EchoService() {
+        instance = this;
+    }
+    
     /**
      * @@org.codehaus.xfire.annotations.commons.WebMethod(operationName = "echo")
      */
     public String echo(String input) {
         return input;
     }
+
+    public ComponentContext getContext() {
+        return context;
+    }
+
+    public void setContext(ComponentContext context) {
+        this.context = context;
+    }
     
 }

Added: trunk/servicemix-jsr181/src/test/java/test/EchoService2.java (928 => 929)

--- trunk/servicemix-jsr181/src/test/java/test/EchoService2.java	2005-11-24 15:04:45 UTC (rev 928)
+++ trunk/servicemix-jsr181/src/test/java/test/EchoService2.java	2005-11-24 22:37:55 UTC (rev 929)
@@ -0,0 +1,29 @@
+/** 
+ * 
+ * Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
+ * 
+ * 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 test;
+
+public class EchoService2 {
+    
+    public EchoService2() {
+    }
+    
+    public String echo(String input) {
+        return input;
+    }
+
+}

Added: trunk/servicemix-jsr181/src/test/resources/bad1/xbean.xml (928 => 929)

--- trunk/servicemix-jsr181/src/test/resources/bad1/xbean.xml	2005-11-24 15:04:45 UTC (rev 928)
+++ trunk/servicemix-jsr181/src/test/resources/bad1/xbean.xml	2005-11-24 22:37:55 UTC (rev 929)
@@ -0,0 +1,6 @@
+<?xml version="1.0"?>
+<beans xmlns:jsr181="http://servicemix.org/jsr181/1.0">
+
+  <jsr181:endpoint endpoint="endpoint1" />
+  				   
+</beans>

Added: trunk/servicemix-jsr181/src/test/resources/bad2/xbean.xml (928 => 929)

--- trunk/servicemix-jsr181/src/test/resources/bad2/xbean.xml	2005-11-24 15:04:45 UTC (rev 928)
+++ trunk/servicemix-jsr181/src/test/resources/bad2/xbean.xml	2005-11-24 22:37:55 UTC (rev 929)
@@ -0,0 +1,6 @@
+<?xml version="1.0"?>
+<beans>
+
+  <bean class="test.EchoService"/>
+  				   
+</beans>

Added: trunk/servicemix-jsr181/src/test/resources/bad3/xbean.xml (928 => 929)

--- trunk/servicemix-jsr181/src/test/resources/bad3/xbean.xml	2005-11-24 15:04:45 UTC (rev 928)
+++ trunk/servicemix-jsr181/src/test/resources/bad3/xbean.xml	2005-11-24 22:37:55 UTC (rev 929)
@@ -0,0 +1,10 @@
+<?xml version="1.0"?>
+<beans xmlns:jsr181="http://servicemix.org/jsr181/1.0">
+
+  <jsr181:endpoint type-mapping="xmlbeans"
+  				   pojo-class="test.EchoService" />
+  				   
+  <jsr181:endpoint type-mapping="xmlbeans"
+  				   pojo-class="test.EchoService" />
+  				   
+</beans>

Added: trunk/servicemix-jsr181/src/test/resources/good2/xbean.xml (928 => 929)

--- trunk/servicemix-jsr181/src/test/resources/good2/xbean.xml	2005-11-24 15:04:45 UTC (rev 928)
+++ trunk/servicemix-jsr181/src/test/resources/good2/xbean.xml	2005-11-24 22:37:55 UTC (rev 929)
@@ -0,0 +1,14 @@
+<?xml version="1.0"?>
+<beans xmlns:jsr181="http://servicemix.org/jsr181/1.0">
+
+  <jsr181:endpoint endpoint="endpoint1"
+  				   type-mapping="xmlbeans">
+    <jsr181:pojo>
+      <bean class="test.EchoService" />
+    </jsr181:pojo>
+  </jsr181:endpoint>
+
+  <jsr181:endpoint pojo-class="test.EchoService2"
+  				   annotations="none" />
+  				   
+</beans>

Modified: trunk/servicemix-jsr181/src/test/resources/log4j.properties (928 => 929)

--- trunk/servicemix-jsr181/src/test/resources/log4j.properties	2005-11-24 15:04:45 UTC (rev 928)
+++ trunk/servicemix-jsr181/src/test/resources/log4j.properties	2005-11-24 22:37:55 UTC (rev 929)
@@ -1,7 +1,7 @@
 #
 # The logging properties used during tests..
 #
-log4j.rootLogger=INFO, stdout
+log4j.rootLogger=DEBUG, stdout
 log4j.logger.org.servicemix.jsr181=DEBUG
 
 log4j.logger.org.activemq=WARN

Reply via email to