incubator-yoko-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dmidd...@apache.org
Subject svn commit: r522882 - in /incubator/yoko/trunk/bindings/src: main/java/org/apache/yoko/bindings/corba/CorbaDestination.java test/java/org/apache/yoko/bindings/corba/CorbaObjectReferenceTest.java
Date Tue, 27 Mar 2007 12:11:48 GMT
Author: dmiddlem
Date: Tue Mar 27 05:11:47 2007
New Revision: 522882

URL: http://svn.apache.org/viewvc?view=rev&rev=522882
Log:
Commit for YOKO-270:
* Small fix for issues when shutting down the binding.
* Re-committing the test for object reference support.

Added:
    incubator/yoko/trunk/bindings/src/test/java/org/apache/yoko/bindings/corba/CorbaObjectReferenceTest.java
  (with props)
Modified:
    incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaDestination.java

Modified: incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaDestination.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaDestination.java?view=diff&rev=522882&r1=522881&r2=522882
==============================================================================
--- incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaDestination.java
(original)
+++ incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaDestination.java
Tue Mar 27 05:11:47 2007
@@ -192,11 +192,18 @@
                 // Try add the key to the boot manager.  This is required for a corbaloc
                 int keyIndex = location.indexOf('/');
                 String key = location.substring(keyIndex + 1);
-                org.apache.yoko.orb.OB.BootManager bootManager = 
-                    org.apache.yoko.orb.OB.BootManagerHelper.narrow(
+                try {
+                    org.apache.yoko.orb.OB.BootManager bootManager = 
+                        org.apache.yoko.orb.OB.BootManagerHelper.narrow(
                             orb.resolve_initial_references("BootManager"));
-                bootManager.add_binding(key.getBytes(), obj);
-                LOG.info("Added key " + key + " to bootmanager");
+                    bootManager.add_binding(key.getBytes(), obj);
+                    LOG.info("Added key " + key + " to bootmanager");
+                } catch (org.apache.yoko.orb.OB.BootManagerPackage.AlreadyExists ex) {
+                    // REVISIT: This can happen when the binding is being shutdown.  We need
to find
+                    // out why we are trying to initialize a servant when we are shutting
down the
+                    // binding.
+                    LOG.info("Key " + key + " already added to boot manager");
+                }
             } else {
                 String ior = orb.object_to_string(obj);
                 address.setLocation(ior);

Added: incubator/yoko/trunk/bindings/src/test/java/org/apache/yoko/bindings/corba/CorbaObjectReferenceTest.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/test/java/org/apache/yoko/bindings/corba/CorbaObjectReferenceTest.java?view=auto&rev=522882
==============================================================================
--- incubator/yoko/trunk/bindings/src/test/java/org/apache/yoko/bindings/corba/CorbaObjectReferenceTest.java
(added)
+++ incubator/yoko/trunk/bindings/src/test/java/org/apache/yoko/bindings/corba/CorbaObjectReferenceTest.java
Tue Mar 27 05:11:47 2007
@@ -0,0 +1,379 @@
+/**
+ * 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.yoko.bindings.corba;
+
+import java.io.File;
+import java.net.URL;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.jws.WebService;
+import javax.xml.namespace.QName;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.Endpoint;
+import javax.xml.ws.Service;
+
+import org.apache.cxf.jaxb.JAXBUtils;
+import org.apache.cxf.ws.addressing.EndpointReferenceType;
+import org.apache.cxf.wsdl.EndpointReferenceUtils;
+import org.apache.cxf.wsdl.WSDLManager;
+import org.apache.cxf.wsdl11.WSDLManagerImpl;
+
+import org.apache.schemas.yoko.idl.objectref.TestInterface;
+import org.apache.schemas.yoko.idl.objectref.TestInterfaceCORBAService;
+import org.apache.schemas.yoko.idl.objectref.TestObject;
+import org.apache.schemas.yoko.idl.objectref.TestObjectCORBAService;
+
+import junit.framework.TestCase;
+
+public class CorbaObjectReferenceTest extends TestCase {
+
+    private final QName OBJECT_PORT_NAME = 
+        new QName("http://schemas.apache.org/yoko/idl/ObjectRef", "TestObjectCORBAPort");

+    
+    private final QName OBJECT_PORT_TYPE = 
+        new QName("http://schemas.apache.org/yoko/idl/ObjectRef", "TestObject"); 
+    
+    private final QName OBJECT_SERVICE_NAME = 
+        new QName("http://schemas.apache.org/yoko/idl/ObjectRef", "TestObjectCORBAService");

+    
+    private final QName INTERFACE_PORT_NAME = 
+        new QName("http://schemas.apache.org/yoko/idl/ObjectRef", "TestInterfaceCORBAPort");

+    
+    private final QName INTERFACE_SERVICE_NAME = 
+        new QName("http://schemas.apache.org/yoko/idl/ObjectRef", "TestInterfaceCORBAService");

+    
+    private final static String WSDL_LOCATION = "/wsdl/ObjectRef.wsdl";
+    private final static int MAX_WAIT_COUNT = 15;
+    
+    private static TestServer server;
+    private static boolean testServerReady;
+    private TestInterface client;
+    private URL wsdlUrl;
+
+    public CorbaObjectReferenceTest(String arg0) {
+        super(arg0);
+    }
+    
+    public static void main(String[] args) {
+        junit.textui.TestRunner.run(CorbaObjectReferenceTest.class);
+    }
+    
+    protected void setUp() throws Exception {
+        super.setUp();
+       
+        if (server == null) {
+            System.out.println("Initializing object reference support test...");
+            server = new TestServer();
+            server.start();
+        }
+
+        int waitCount = 0;
+        // Wait for the server to start if it hasn't already
+        while (waitCount < MAX_WAIT_COUNT && !server.isReady()) {
+            try {
+                Thread.sleep(1000);
+                waitCount++;
+            } catch (Exception ex) {
+                // Consume
+            }
+        }
+
+        if (!server.isReady()) {
+            throw new Exception("Server failed to start in a timely fashion");
+        }
+
+        // Now initialize the client-side
+        try {
+            wsdlUrl = TestInterface.class.getResource(WSDL_LOCATION);
+        } catch (Exception ex) {
+            throw new Exception("Unable to resolve WSDL location");
+        }
+        
+        TestInterfaceCORBAService service = 
+            new TestInterfaceCORBAService(wsdlUrl, INTERFACE_SERVICE_NAME);
+        client = service.getPort(INTERFACE_PORT_NAME, TestInterface.class);
+
+        if (client == null) {
+            throw new Exception("Unable to create client");
+        }
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+
+        server.interrupt();
+
+        try {
+            // Sleep for 3 seconds waiting for the server to shut down
+            Thread.sleep(3000);
+        } catch (Exception ex) {
+            // Move on to check if the server is down
+        }
+
+        if (server.isAlive()) {
+            throw new Exception("Did not terminate test server!");
+        }
+    }
+
+    public void testCustomObjectParam() {
+        System.out.println("Testing custom object reference as a parameter...");
+        EndpointReferenceType ref = null;
+        ref = createEndpointReferenceType("CustomObjectParam", false);
+
+        boolean result = client.testCustomObjectParam(ref);
+        assertTrue(result);
+    }
+
+    public void testDefaultObjectParam() {
+        System.out.println("Testing default object reference as a parameter...");
+        EndpointReferenceType ref = null;
+        ref = createEndpointReferenceType("DefaultObjectParam", false);
+
+        boolean result = client.testDefaultObjectParam(ref);
+        assertTrue(result);
+    }
+
+    public void testCustomObjectReturn() throws Exception {
+        System.out.println("Testing custom object reference as a return value...");
+        EndpointReferenceType ref = client.testCustomObjectReturn();
+        TestObject testObj = createObjectFromEndpointReferenceType(ref);
+
+        int updateVal = 789;
+
+        int startVal = testObj.testObjectValue();
+
+        // We keep on having to set the request context with the endpoints address.  This
+        // was not the case before and should be looked at further
+        Map<String, Object> requestContext = ((BindingProvider)testObj).getRequestContext();
+        requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, ref.getAddress().getValue());
+        testObj.testObjectValueUpdate(updateVal);
+
+        requestContext = ((BindingProvider)testObj).getRequestContext();
+        requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, ref.getAddress().getValue());
+        int endVal = testObj.testObjectValue();
+
+        assertTrue(endVal == updateVal);
+    }
+
+    public void testDefaultObjectReturn() throws Exception {
+        System.out.println("Testing default object reference as a return value...");
+        EndpointReferenceType ref = client.testDefaultObjectReturn();
+        TestObject testObj = createObjectFromEndpointReferenceType(ref);
+
+        int updateVal = 246;
+
+        int startVal = testObj.testObjectValue();
+
+        // We keep on having to set the request context with the endpoints address.  This
+        // was not the case before and should be looked at further
+        Map<String, Object> requestContext = ((BindingProvider)testObj).getRequestContext();
+        requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, ref.getAddress().getValue());
+        testObj.testObjectValueUpdate(updateVal);
+
+        requestContext = ((BindingProvider)testObj).getRequestContext();
+        requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, ref.getAddress().getValue());
+        int endVal = testObj.testObjectValue();
+
+        assertTrue(endVal == updateVal);
+    }
+ 
+    // Helper methods that can be used throughout the test
+    public EndpointReferenceType createEndpointReferenceType(String name, boolean serverSide)
{
+        String corbaAddress = null;
+        // The server and client bindings need to be on two different ORBs since they can't
+        // share.  So we need to make sure that the port numbers are different.
+        if (serverSide) {
+            corbaAddress = "corbaloc::localhost:54321/Server" + name;
+        } else {
+            corbaAddress = "corbaloc::localhost:54322/Client" + name;
+        }
+
+        Object testObj = new TestObjectImpl();
+        Endpoint.publish(corbaAddress, testObj);
+
+        EndpointReferenceType ref =
+            EndpointReferenceUtils.getEndpointReference(wsdlUrl,
+                                                        OBJECT_SERVICE_NAME,
+                                                        OBJECT_PORT_NAME.getLocalPart());
+        EndpointReferenceUtils.setInterfaceName(ref, OBJECT_PORT_TYPE);
+        EndpointReferenceUtils.setAddress(ref, corbaAddress);
+
+        return ref;
+    }
+
+    public TestObject createObjectFromEndpointReferenceType(EndpointReferenceType epr) throws
Exception {
+            WSDLManager manager = null;
+            manager = new WSDLManagerImpl();
+
+            QName interfaceName = EndpointReferenceUtils.getInterfaceName(epr);
+            String wsdlLocation = EndpointReferenceUtils.getWSDLLocation(epr);
+            QName serviceName = EndpointReferenceUtils.getServiceName(epr);
+            String portName = EndpointReferenceUtils.getPortName(epr);
+
+            QName port = new QName(serviceName.getNamespaceURI(), portName);
+
+            StringBuffer seiName = new StringBuffer();
+            seiName.append("org.apache.schemas.yoko.idl.objectref.");
+            seiName.append(JAXBUtils.nameToIdentifier(interfaceName.getLocalPart(),
+                           JAXBUtils.IdentifierType.INTERFACE));
+
+            Class<?> sei = null;
+            sei = Class.forName(seiName.toString(), true, manager.getClass().getClassLoader());
+
+            Service service = Service.create(wsdlUrl, serviceName);
+            TestObject testObj = (TestObject)service.getPort(port, sei);
+
+            Map<String, Object> requestContext = ((BindingProvider)testObj).getRequestContext();
+            requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, epr.getAddress().getValue());
+
+            return testObj;
+    }
+
+    
+    
+    // A small test server for the test case to interact with
+    public class TestServer extends Thread {
+        private boolean serverReady;
+
+        public TestServer() {
+            serverReady = false;
+        }
+
+        public void run() {
+            Object implementor = new TestInterfaceImpl();
+            String address = "corbaloc::localhost:54321/ObjectRefTest";
+            Endpoint.publish(address, implementor);
+
+            serverReady = true;
+        }
+
+        public boolean isReady() {
+            return serverReady;
+        }
+    }
+
+
+    
+    // A minimal TestInterface implementation to test object references
+    @WebService(portName = "TestInterfaceCORBAPort",
+                          serviceName = "TestInterfaceCORBAService",
+                          targetNamespace = "http://schemas.apache.org/yoko/idl/ObjectRef",
+                          endpointInterface = "org.apache.schemas.yoko.idl.objectref.TestInterface")
+    public class TestInterfaceImpl implements TestInterface {
+
+        public boolean testCustomObjectParam(EndpointReferenceType param) {
+            TestObject testObj = null;
+            try {
+                testObj = createObjectFromEndpointReferenceType(param);
+            } catch (Exception ex) {
+                return false;
+            }
+
+            if (testObj == null) {
+                return false;
+            }
+
+            try {
+                int updateVal = 123;
+                int startVal = testObj.testObjectValue();
+
+                // We keep on having to set the request context with the endpoints address.
 This
+                // was not the case before and should be looked at further
+                Map<String, Object> requestContext = ((BindingProvider)testObj).getRequestContext();
+                requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, param.getAddress().getValue());
+                testObj.testObjectValueUpdate(updateVal);
+
+                requestContext = ((BindingProvider)testObj).getRequestContext();
+                requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, param.getAddress().getValue());
+                int endVal = testObj.testObjectValue();
+
+                return (endVal == updateVal);
+            } catch(Exception ex) {
+                return false;
+            }
+        }
+
+        public boolean testDefaultObjectParam(EndpointReferenceType param) {
+            TestObject testObj = null;
+            try {
+                testObj = createObjectFromEndpointReferenceType(param);
+            } catch (Exception ex) {
+                return false;
+            }
+
+            if (testObj == null) {
+                return false;
+            }
+
+            try {
+                int updateVal = 456;
+                int startVal = testObj.testObjectValue();
+
+                // We keep on having to set the request context with the endpoints address.
 This
+                // was not the case before and should be looked at further
+                Map<String, Object> requestContext = ((BindingProvider)testObj).getRequestContext();
+                requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, param.getAddress().getValue());
+                testObj.testObjectValueUpdate(updateVal);
+
+                requestContext = ((BindingProvider)testObj).getRequestContext();
+                requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, param.getAddress().getValue());
+                int endVal = testObj.testObjectValue();
+
+                return (endVal == updateVal);
+            } catch(Exception ex) {
+                return false;
+            }
+        }
+
+        public EndpointReferenceType testCustomObjectReturn() {
+            EndpointReferenceType ref = null;
+            ref = createEndpointReferenceType("CustomObjectReturn", true);
+
+            return ref;
+        }
+
+        public EndpointReferenceType testDefaultObjectReturn() {
+            EndpointReferenceType ref = null;
+            ref = createEndpointReferenceType("DefaultObjectReturn", true);
+
+            return ref;
+        }
+    }
+
+
+    
+    // A minimal TestInterface implementation to test object references
+    @javax.jws.WebService(portName = "TestObjectCORBAPort",
+                          serviceName = "TestObjectCORBAService",
+                          targetNamespace = "http://schemas.apache.org/yoko/idl/ObjectRef",
+                          endpointInterface = "org.apache.schemas.yoko.idl.objectref.TestObject")
+    public class TestObjectImpl implements TestObject {
+
+        private int val;
+
+        public int testObjectValue() {
+            return val;
+        }
+
+        public void testObjectValueUpdate(int value) {
+            val = value;
+        }
+    }
+}

Propchange: incubator/yoko/trunk/bindings/src/test/java/org/apache/yoko/bindings/corba/CorbaObjectReferenceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/yoko/trunk/bindings/src/test/java/org/apache/yoko/bindings/corba/CorbaObjectReferenceTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message