Title: [933] trunk/servicemix-jsr181: Allow use of jsr181 component on jdk 1.4
Revision
933
Author
gnt
Date
2005-11-25 04:20:27 -0500 (Fri, 25 Nov 2005)

Log Message

Allow use of jsr181 component on jdk 1.4
Clean up the xfire jbi transport
Add more tests

Modified Paths

Added Paths

Removed Paths

Property Changed

  • trunk/servicemix-jsr181/

Diff

Property changes: trunk/servicemix-jsr181

Name: svn:ignore
   - .classpath
.project
target
   + .classpath
.project
target
*.ser

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

--- trunk/servicemix-jsr181/src/main/java/org/servicemix/jsr181/Jsr181Endpoint.java	2005-11-25 09:16:52 UTC (rev 932)
+++ trunk/servicemix-jsr181/src/main/java/org/servicemix/jsr181/Jsr181Endpoint.java	2005-11-25 09:20:27 UTC (rev 933)
@@ -43,8 +43,6 @@
 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;
@@ -72,13 +70,25 @@
     static {
         knownTypeMappings = new HashMap();
         knownTypeMappings.put("default", new DefaultTypeMappingRegistry(true));
-        knownTypeMappings.put("jaxb2", new JaxbTypeRegistry());
         knownTypeMappings.put("xmlbeans", new XmlBeansTypeRegistry());
+        try {
+            Class cl = Class.forName("org.codehaus.xfire.jaxb2.JaxbTypeRegistry");
+            Object tr = cl.newInstance();
+            knownTypeMappings.put("jaxb2", tr);
+        } catch (Throwable e) {
+            // we are in jdk 1.4, do nothing
+        }
         
         knownAnnotations = new HashMap();
         knownAnnotations.put("backport", new Backport175WebAnnotations());
         knownAnnotations.put("commons", new CommonsWebAttributes());
-        knownAnnotations.put("java5", new Jsr181WebAnnotations());
+        try {
+            Class cl = Class.forName("org.codehaus.xfire.annotations.jsr181.Jsr181WebAnnotations");
+            Object wa = cl.newInstance();
+            knownAnnotations.put("java5", wa);
+        } catch (Throwable e) {
+            // we are in jdk 1.4, do nothing
+        }
     }
     
     protected Object pojo;

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

--- trunk/servicemix-jsr181/src/main/java/org/servicemix/jsr181/xfire/JbiTransport.java	2005-11-25 09:16:52 UTC (rev 932)
+++ trunk/servicemix-jsr181/src/main/java/org/servicemix/jsr181/xfire/JbiTransport.java	2005-11-25 09:20:27 UTC (rev 933)
@@ -37,14 +37,11 @@
 
     private static final Log log = LogFactory.getLog(JbiTransport.class);
     
-    public final static String JBI_TRANSPORT_NS = "http://java.sun.com/xml/ns/jbi/binding/service+engine";
-    
     public final static String JBI_BINDING = "http://java.sun.com/xml/ns/jbi/binding/service+engine";
     
     private final static String URI_PREFIX = "urn:xfire:transport:jbi:";
 
     public JbiTransport() {
-        addInHandler(new PrepareHandler());
         addInHandler(new LocateBindingHandler());
         addInHandler(new SoapBindingHandler());
     }
@@ -57,10 +54,6 @@
         return "jbi://" + service.getName();
     }
 
-    public String getTransportURI(Service service) {
-        return JBI_TRANSPORT_NS;
-    }
-
     protected Channel createNewChannel(String uri) {
         log.debug("Creating new channel for uri: " + uri);
         JbiChannel c = new JbiChannel(uri, this);

Deleted: trunk/servicemix-jsr181/src/main/java/org/servicemix/jsr181/xfire/PrepareHandler.java (932 => 933)

--- trunk/servicemix-jsr181/src/main/java/org/servicemix/jsr181/xfire/PrepareHandler.java	2005-11-25 09:16:52 UTC (rev 932)
+++ trunk/servicemix-jsr181/src/main/java/org/servicemix/jsr181/xfire/PrepareHandler.java	2005-11-25 09:20:27 UTC (rev 933)
@@ -1,57 +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.xfire;
-
-import org.codehaus.xfire.MessageContext;
-import org.codehaus.xfire.exchange.InMessage;
-import org.codehaus.xfire.handler.AbstractHandler;
-import org.codehaus.xfire.handler.Phase;
-
-import javax.xml.stream.XMLStreamReader;
-
-/**
- * Handler to start document parsing. 
- */
-public class PrepareHandler extends AbstractHandler {
-
-    public String getPhase() {
-        return Phase.PARSE;
-    }
-
-    public void invoke(MessageContext context) throws Exception {
-        InMessage message = context.getInMessage();
-        XMLStreamReader reader = message.getXMLStreamReader();
-        while (reader.hasNext()) {
-            int event = reader.next();
-            switch (event)
-            {
-                case XMLStreamReader.START_DOCUMENT:
-                    String encoding = reader.getCharacterEncodingScheme();
-                    message.setEncoding(encoding);
-                    break;
-                case XMLStreamReader.END_DOCUMENT:
-                    return;
-                case XMLStreamReader.START_ELEMENT:
-                    return;
-                default:
-                    break;
-            }
-        }
-    }
-    
-}
\ No newline at end of file

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

--- trunk/servicemix-jsr181/src/test/java/org/servicemix/jsr181/Jsr181ComponentTest.java	2005-11-25 09:16:52 UTC (rev 932)
+++ trunk/servicemix-jsr181/src/test/java/org/servicemix/jsr181/Jsr181ComponentTest.java	2005-11-25 09:20:27 UTC (rev 933)
@@ -43,10 +43,11 @@
     
     protected void setUp() throws Exception {
         container = new JBIContainer();
-        container.setUseMBeanServer(true);
-        container.setCreateMBeanServer(true);
+        container.setUseMBeanServer(false);
+        container.setCreateMBeanServer(false);
         container.setMonitorInstallationDirectory(false);
         container.setNamingContext(new InitialContext());
+        container.setEmbedded(true);
         container.init();
     }
     
@@ -161,6 +162,42 @@
         }
     }
     
+    public void testNotJsr181Endpoint() throws Exception {
+        Jsr181Component component = new Jsr181Component();
+        container.activateComponent(component, "JSR181Component");
+        try {
+            component.getServiceUnitManager().deploy("bad4", getServiceUnitPath("bad4"));
+            fail("Expected an exception");
+        } catch (Exception e) {
+            // ok
+            logger.info(e.getMessage());
+        }
+    }
+    
+    public void testUnrecognizedTypeMapping() throws Exception {
+        Jsr181Component component = new Jsr181Component();
+        container.activateComponent(component, "JSR181Component");
+        try {
+            component.getServiceUnitManager().deploy("bad5", getServiceUnitPath("bad5"));
+            fail("Expected an exception");
+        } catch (Exception e) {
+            // ok
+            logger.info(e.getMessage());
+        }
+    }
+    
+    public void testUnrecognizedAnnotations() throws Exception {
+        Jsr181Component component = new Jsr181Component();
+        container.activateComponent(component, "JSR181Component");
+        try {
+            component.getServiceUnitManager().deploy("bad6", getServiceUnitPath("bad6"));
+            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());

Added: trunk/servicemix-jsr181/src/test/java/test/TestEndpoint.java (932 => 933)

--- trunk/servicemix-jsr181/src/test/java/test/TestEndpoint.java	2005-11-25 09:16:52 UTC (rev 932)
+++ trunk/servicemix-jsr181/src/test/java/test/TestEndpoint.java	2005-11-25 09:20:27 UTC (rev 933)
@@ -0,0 +1,24 @@
+package test;
+
+import javax.jbi.messaging.MessageExchange.Role;
+
+import org.servicemix.common.Endpoint;
+
+public class TestEndpoint extends Endpoint {
+
+    public Role getRole() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public void activate() throws Exception {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void deactivate() throws Exception {
+        // TODO Auto-generated method stub
+
+    }
+
+}

Added: trunk/servicemix-jsr181/src/test/resources/bad4/xbean.xml (932 => 933)

--- trunk/servicemix-jsr181/src/test/resources/bad4/xbean.xml	2005-11-25 09:16:52 UTC (rev 932)
+++ trunk/servicemix-jsr181/src/test/resources/bad4/xbean.xml	2005-11-25 09:20:27 UTC (rev 933)
@@ -0,0 +1,7 @@
+<?xml version="1.0"?>
+<beans xmlns:jsr181="http://servicemix.org/jsr181/1.0">
+
+  <bean class="test.TestEndpoint">
+  </bean>
+  				   
+</beans>

Added: trunk/servicemix-jsr181/src/test/resources/bad5/xbean.xml (932 => 933)

--- trunk/servicemix-jsr181/src/test/resources/bad5/xbean.xml	2005-11-25 09:16:52 UTC (rev 932)
+++ trunk/servicemix-jsr181/src/test/resources/bad5/xbean.xml	2005-11-25 09:20:27 UTC (rev 933)
@@ -0,0 +1,7 @@
+<?xml version="1.0"?>
+<beans xmlns:jsr181="http://servicemix.org/jsr181/1.0">
+
+  <jsr181:endpoint type-mapping="---"
+  				   pojo-class="test.EchoService" />
+  				   
+</beans>

Added: trunk/servicemix-jsr181/src/test/resources/bad6/xbean.xml (932 => 933)

--- trunk/servicemix-jsr181/src/test/resources/bad6/xbean.xml	2005-11-25 09:16:52 UTC (rev 932)
+++ trunk/servicemix-jsr181/src/test/resources/bad6/xbean.xml	2005-11-25 09:20:27 UTC (rev 933)
@@ -0,0 +1,7 @@
+<?xml version="1.0"?>
+<beans xmlns:jsr181="http://servicemix.org/jsr181/1.0">
+
+  <jsr181:endpoint annotations="---"
+  				   pojo-class="test.EchoService" />
+  				   
+</beans>

Reply via email to