summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/host-corba/src
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2008-06-25 22:39:16 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2008-06-25 22:39:16 +0000
commit2c5b145988ffc9b4ccd334ac287134b015b40b8f (patch)
tree3079b6e8d285cbc68252ceef9425611133f83dd0 /java/sca/modules/host-corba/src
parent8b7992d467853c38106a590cdcdfc0f8efb0ea9d (diff)
Apply the patApply the patch from Wojtek for TUSCANY-2397. Thanks.
I also did some refactoring for the test case to only start the tnameserv once. Another issue I fixed is that the Exceptions for unknown host and port are JDK-specific. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@671675 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/host-corba/src')
-rw-r--r--java/sca/modules/host-corba/src/main/java/org/apache/tuscany/sca/host/corba/CorbaHost.java61
-rw-r--r--java/sca/modules/host-corba/src/main/java/org/apache/tuscany/sca/host/corba/CorbaHostException.java46
-rw-r--r--java/sca/modules/host-corba/src/main/java/org/apache/tuscany/sca/host/corba/CorbaHostExtensionPoint.java50
-rw-r--r--java/sca/modules/host-corba/src/main/java/org/apache/tuscany/sca/host/corba/DefaultCorbaHost.java128
-rw-r--r--java/sca/modules/host-corba/src/main/java/org/apache/tuscany/sca/host/corba/DefaultCorbaHostExtensionPoint.java49
-rw-r--r--java/sca/modules/host-corba/src/main/java/org/apache/tuscany/sca/host/corba/ExtensibleCorbaHost.java56
-rw-r--r--java/sca/modules/host-corba/src/main/resources/META-INF/services/org.apache.tuscany.sca.host.corba.CorbaHostExtensionPoint18
-rw-r--r--java/sca/modules/host-corba/src/test/java/org/apache/tuscany/sca/host/corba/testing/DefaultCorbaHostTestCase.java226
-rw-r--r--java/sca/modules/host-corba/src/test/java/org/apache/tuscany/sca/host/corba/testing/general/TestInterface.java30
-rw-r--r--java/sca/modules/host-corba/src/test/java/org/apache/tuscany/sca/host/corba/testing/general/TestInterfaceHelper.java98
-rw-r--r--java/sca/modules/host-corba/src/test/java/org/apache/tuscany/sca/host/corba/testing/general/TestInterfaceHolder.java51
-rw-r--r--java/sca/modules/host-corba/src/test/java/org/apache/tuscany/sca/host/corba/testing/general/TestInterfaceOperations.java31
-rw-r--r--java/sca/modules/host-corba/src/test/java/org/apache/tuscany/sca/host/corba/testing/general/_TestInterfaceImplBase.java74
-rw-r--r--java/sca/modules/host-corba/src/test/java/org/apache/tuscany/sca/host/corba/testing/general/_TestInterfaceStub.java73
-rw-r--r--java/sca/modules/host-corba/src/test/java/org/apache/tuscany/sca/host/corba/testing/servants/TestInterfaceServant.java35
-rw-r--r--java/sca/modules/host-corba/src/test/resources/general.idl43
16 files changed, 1069 insertions, 0 deletions
diff --git a/java/sca/modules/host-corba/src/main/java/org/apache/tuscany/sca/host/corba/CorbaHost.java b/java/sca/modules/host-corba/src/main/java/org/apache/tuscany/sca/host/corba/CorbaHost.java
new file mode 100644
index 0000000000..7d9a3db587
--- /dev/null
+++ b/java/sca/modules/host-corba/src/main/java/org/apache/tuscany/sca/host/corba/CorbaHost.java
@@ -0,0 +1,61 @@
+/*
+ * 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.tuscany.sca.host.corba;
+
+import org.omg.CORBA.Object;
+
+/**
+ * CORBA Service hosting interface
+ */
+public interface CorbaHost {
+
+ /**
+ * Registers servant in name server.
+ *
+ * @param name binding name
+ * @param host name server host
+ * @param port name server port
+ * @param serviceObject
+ * @throws CorbaHostException
+ */
+ void registerServant(String name, String host, int port, Object serviceObject) throws CorbaHostException;
+
+ /**
+ * Removes servant from name server
+ *
+ * @param name binding name
+ * @param host name server host
+ * @param port name server port
+ * @throws CorbaHostException
+ */
+ void unregisterServant(String name, String host, int port) throws CorbaHostException;
+
+ /**
+ * Gets reference to object
+ *
+ * @param name binding name
+ * @param host name server host
+ * @param port name server port
+ * @return objects reference
+ * @throws CorbaHostException
+ */
+ Object getReference(String name, String host, int port) throws CorbaHostException;
+
+}
diff --git a/java/sca/modules/host-corba/src/main/java/org/apache/tuscany/sca/host/corba/CorbaHostException.java b/java/sca/modules/host-corba/src/main/java/org/apache/tuscany/sca/host/corba/CorbaHostException.java
new file mode 100644
index 0000000000..47037a01fc
--- /dev/null
+++ b/java/sca/modules/host-corba/src/main/java/org/apache/tuscany/sca/host/corba/CorbaHostException.java
@@ -0,0 +1,46 @@
+/*
+ * 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.tuscany.sca.host.corba;
+
+/**
+ * General exception for corba hosts operations
+ */
+public class CorbaHostException extends Exception {
+
+ private static final long serialVersionUID = 1L;
+
+ public static final String BINDING_IN_USE = "Binding name is already in use";
+ public static final String NO_SUCH_OBJECT = "There is no object under given binding name";
+ public static final String NO_SUCH_HOST = "Couldn't find specified host";
+ public static final String NO_SUCH_PORT = "Couldn't connect to specified port";
+ public static final String WRONG_NAME = "Characters used in binding name are illegal";
+
+ public CorbaHostException(String message) {
+ super(message);
+ }
+
+ public CorbaHostException(Exception cause) {
+ super(cause);
+ }
+
+ public CorbaHostException(String message, Exception cause) {
+ super(message, cause);
+ }
+}
diff --git a/java/sca/modules/host-corba/src/main/java/org/apache/tuscany/sca/host/corba/CorbaHostExtensionPoint.java b/java/sca/modules/host-corba/src/main/java/org/apache/tuscany/sca/host/corba/CorbaHostExtensionPoint.java
new file mode 100644
index 0000000000..1488e4f80b
--- /dev/null
+++ b/java/sca/modules/host-corba/src/main/java/org/apache/tuscany/sca/host/corba/CorbaHostExtensionPoint.java
@@ -0,0 +1,50 @@
+/*
+ * 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.tuscany.sca.host.corba;
+
+import java.util.List;
+
+/**
+ * An extension point for CORBA hostst
+ */
+public interface CorbaHostExtensionPoint {
+
+ /**
+ * Removes CORBA host extension
+ *
+ * @param corbaHost
+ */
+ void addCorbaHost(CorbaHost corbaHost);
+
+ /**
+ * Removes CORBA host extension
+ *
+ * @param corbaHost
+ */
+ void removeCorbaHost(CorbaHost corbaHost);
+
+ /**
+ * Gets all CORBA host extensions
+ *
+ * @return
+ */
+ List<CorbaHost> getCorbaHosts();
+
+}
diff --git a/java/sca/modules/host-corba/src/main/java/org/apache/tuscany/sca/host/corba/DefaultCorbaHost.java b/java/sca/modules/host-corba/src/main/java/org/apache/tuscany/sca/host/corba/DefaultCorbaHost.java
new file mode 100644
index 0000000000..c8b485466e
--- /dev/null
+++ b/java/sca/modules/host-corba/src/main/java/org/apache/tuscany/sca/host/corba/DefaultCorbaHost.java
@@ -0,0 +1,128 @@
+/*
+ * 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.tuscany.sca.host.corba;
+
+import org.omg.CORBA.ORB;
+import org.omg.CORBA.Object;
+import org.omg.CosNaming.NameComponent;
+import org.omg.CosNaming.NamingContext;
+import org.omg.CosNaming.NamingContextHelper;
+import org.omg.CosNaming.NamingContextPackage.InvalidName;
+import org.omg.CosNaming.NamingContextPackage.NotFound;
+
+/**
+ * Default implementation of CORBA host
+ */
+public class DefaultCorbaHost implements CorbaHost {
+
+ private void validatePort(int port) throws IllegalArgumentException {
+ if (port < 1) {
+ throw new IllegalArgumentException("Port value should be > 0");
+ }
+ }
+
+ private void validateName(String name) throws IllegalArgumentException {
+ if (name == null || name.length() == 0) {
+ throw new IllegalArgumentException("Object name shouldn't be null");
+ }
+ }
+
+ private String[] getArgs(String host, int port) {
+ String[] args = {"-ORBInitialHost", host, "-ORBInitialPort", "" + port};
+ return args;
+ }
+
+ private NamingContext getNamingContext(String host, int port) throws Exception {
+ ORB orb = ORB.init(getArgs(host, port), null);
+ org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");
+ return NamingContextHelper.narrow(objRef);
+ }
+
+ private void handleException(Exception e) throws CorbaHostException {
+ // The cause of the Exception is JDK specific
+ if (e instanceof NotFound) {
+ throw new CorbaHostException(CorbaHostException.NO_SUCH_OBJECT, e);
+ } else if (e instanceof InvalidName) {
+ throw new CorbaHostException(e);
+ } else {
+ throw new CorbaHostException(e);
+ }
+ }
+
+ public void registerServant(String name, String host, int port, Object servantObject) throws CorbaHostException {
+ validatePort(port);
+ validateName(name);
+ if (host == null || host.length() == 0) {
+ host = "localhost";
+ }
+ try {
+ NamingContext ncRef = getNamingContext(host, port);
+ NameComponent nc = new NameComponent(name, "");
+ NameComponent[] path = {nc};
+ try {
+ ncRef.resolve(path);
+ // no exception means that some object is already registered
+ // under this name, we need to crash here
+ throw new CorbaHostException(CorbaHostException.BINDING_IN_USE);
+ } catch (NotFound e) {
+ ncRef.bind(path, servantObject);
+ }
+ } catch (CorbaHostException e) {
+ throw e;
+ } catch (Exception e) {
+ handleException(e);
+ }
+ }
+
+ public void unregisterServant(String name, String host, int port) throws CorbaHostException {
+ validatePort(port);
+ validateName(name);
+ if (host == null || host.length() == 0) {
+ host = "localhost";
+ }
+ try {
+ NamingContext ncRef = getNamingContext(host, port);
+ NameComponent nc = new NameComponent(name, "");
+ NameComponent[] path = {nc};
+ ncRef.unbind(path);
+ } catch (Exception e) {
+ handleException(e);
+ }
+ }
+
+ public Object getReference(String name, String host, int port) throws CorbaHostException {
+ validatePort(port);
+ validateName(name);
+ if (host == null || host.length() == 0) {
+ host = "localhost";
+ }
+ Object result = null;
+ try {
+ NamingContext ncRef = getNamingContext(host, port);
+ NameComponent nc = new NameComponent(name, "");
+ NameComponent path[] = {nc};
+ result = ncRef.resolve(path);
+ } catch (Exception e) {
+ handleException(e);
+ }
+ return result;
+ }
+
+}
diff --git a/java/sca/modules/host-corba/src/main/java/org/apache/tuscany/sca/host/corba/DefaultCorbaHostExtensionPoint.java b/java/sca/modules/host-corba/src/main/java/org/apache/tuscany/sca/host/corba/DefaultCorbaHostExtensionPoint.java
new file mode 100644
index 0000000000..f9150f137c
--- /dev/null
+++ b/java/sca/modules/host-corba/src/main/java/org/apache/tuscany/sca/host/corba/DefaultCorbaHostExtensionPoint.java
@@ -0,0 +1,49 @@
+/*
+ * 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.tuscany.sca.host.corba;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Default implementation of CorbaHostExtensionPoint
+ */
+public class DefaultCorbaHostExtensionPoint implements CorbaHostExtensionPoint {
+
+ private List<CorbaHost> corbaHosts = new ArrayList<CorbaHost>();
+
+ public DefaultCorbaHostExtensionPoint() {
+ CorbaHost defaultHost = new DefaultCorbaHost();
+ addCorbaHost(defaultHost);
+ }
+
+ public void addCorbaHost(CorbaHost host) {
+ corbaHosts.add(host);
+ }
+
+ public void removeCorbaHost(CorbaHost host) {
+ corbaHosts.remove(host);
+ }
+
+ public List<CorbaHost> getCorbaHosts() {
+ return corbaHosts;
+ }
+
+}
diff --git a/java/sca/modules/host-corba/src/main/java/org/apache/tuscany/sca/host/corba/ExtensibleCorbaHost.java b/java/sca/modules/host-corba/src/main/java/org/apache/tuscany/sca/host/corba/ExtensibleCorbaHost.java
new file mode 100644
index 0000000000..eab7af57a7
--- /dev/null
+++ b/java/sca/modules/host-corba/src/main/java/org/apache/tuscany/sca/host/corba/ExtensibleCorbaHost.java
@@ -0,0 +1,56 @@
+/*
+ * 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.tuscany.sca.host.corba;
+
+import org.omg.CORBA.Object;
+
+/**
+ * Default implementation of extensible CORBA host
+ */
+public class ExtensibleCorbaHost implements CorbaHost {
+
+ private CorbaHostExtensionPoint chep;
+
+ public ExtensibleCorbaHost(CorbaHostExtensionPoint chep) {
+ this.chep = chep;
+ }
+
+ public Object getReference(String name, String host, int port) throws CorbaHostException {
+ if (chep.getCorbaHosts().isEmpty()) {
+ throw new CorbaHostException("No registered CORBA hosts");
+ }
+ return chep.getCorbaHosts().get(0).getReference(name, host, port);
+ }
+
+ public void registerServant(String name, String host, int port, Object serviceObject) throws CorbaHostException {
+ if (chep.getCorbaHosts().isEmpty()) {
+ throw new CorbaHostException("No registered CORBA hosts");
+ }
+ registerServant(name, host, port, serviceObject);
+ }
+
+ public void unregisterServant(String name, String host, int port) throws CorbaHostException {
+ if (chep.getCorbaHosts().isEmpty()) {
+ throw new CorbaHostException("No registered CORBA hosts");
+ }
+ unregisterServant(name, host, port);
+ }
+
+}
diff --git a/java/sca/modules/host-corba/src/main/resources/META-INF/services/org.apache.tuscany.sca.host.corba.CorbaHostExtensionPoint b/java/sca/modules/host-corba/src/main/resources/META-INF/services/org.apache.tuscany.sca.host.corba.CorbaHostExtensionPoint
new file mode 100644
index 0000000000..a72bed4ea8
--- /dev/null
+++ b/java/sca/modules/host-corba/src/main/resources/META-INF/services/org.apache.tuscany.sca.host.corba.CorbaHostExtensionPoint
@@ -0,0 +1,18 @@
+# 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.
+
+org.apache.tuscany.sca.host.corba.DefaultCorbaHostExtensionPoint
diff --git a/java/sca/modules/host-corba/src/test/java/org/apache/tuscany/sca/host/corba/testing/DefaultCorbaHostTestCase.java b/java/sca/modules/host-corba/src/test/java/org/apache/tuscany/sca/host/corba/testing/DefaultCorbaHostTestCase.java
new file mode 100644
index 0000000000..5b9167122f
--- /dev/null
+++ b/java/sca/modules/host-corba/src/test/java/org/apache/tuscany/sca/host/corba/testing/DefaultCorbaHostTestCase.java
@@ -0,0 +1,226 @@
+/*
+ * 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.tuscany.sca.host.corba.testing;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertTrue;
+import static junit.framework.Assert.fail;
+
+import java.io.IOException;
+
+import org.apache.tuscany.sca.host.corba.CorbaHost;
+import org.apache.tuscany.sca.host.corba.CorbaHostException;
+import org.apache.tuscany.sca.host.corba.DefaultCorbaHost;
+import org.apache.tuscany.sca.host.corba.testing.general.TestInterface;
+import org.apache.tuscany.sca.host.corba.testing.general.TestInterfaceHelper;
+import org.apache.tuscany.sca.host.corba.testing.servants.TestInterfaceServant;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.omg.CORBA.ORB;
+
+/**
+ * General tests
+ */
+public class DefaultCorbaHostTestCase {
+
+ private static final String LOCALHOST = "localhost";
+ private static final int DEFAULT_PORT = 11100; //1050;
+ private static final long INTERVAL = 500;
+
+ private static Process tn;
+ private static CorbaHost host;
+
+ /**
+ * Spawn tnameserv under given port
+ *
+ * @param port
+ * @return
+ * @throws IOException
+ */
+ private static Process spawnTnameserv(int port) throws IOException {
+ Process process = Runtime.getRuntime().exec("tnameserv -ORBInitialPort " + port);
+ for (int i = 0; i < 3; i++) {
+ try {
+ // Thread.sleep(SPAWN_TIME);
+ String[] args = {"-ORBInitialHost", LOCALHOST, "-ORBInitialPort", "" + port};
+ ORB orb = ORB.init(args, null);
+ orb.resolve_initial_references("NameService");
+ break;
+ } catch (Throwable e) {
+ try {
+ Thread.sleep(INTERVAL);
+ } catch (InterruptedException e1) {
+ // Ignore
+ }
+ }
+ }
+ return process;
+ }
+
+ /**
+ * Kill previously spawned tnameserv
+ *
+ * @param p
+ */
+ private static void killProcess(Process p) {
+ if (p != null) {
+ p.destroy();
+ }
+ }
+
+ @BeforeClass
+ public static void start() {
+ try {
+ tn = spawnTnameserv(DEFAULT_PORT);
+ host = new DefaultCorbaHost();
+ } catch (Throwable e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ @AfterClass
+ public static void stop() {
+ killProcess(tn);
+ }
+
+ /**
+ * Tests registering, getting and unregistering CORBA object
+ */
+ @Test
+ public void test_registerServant() {
+ try {
+ TestInterface servant = new TestInterfaceServant();
+ host.registerServant("Test", LOCALHOST, DEFAULT_PORT, servant);
+
+ TestInterface ref = TestInterfaceHelper.narrow(host.getReference("Test", null, DEFAULT_PORT));
+ assertEquals(2, ref.getInt(2));
+
+ host.unregisterServant("Test", LOCALHOST, DEFAULT_PORT);
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail();
+ }
+ }
+
+ /**
+ * Tests situation when name is already registered
+ */
+ @Test
+ public void test_nameAlreadyRegistered() {
+ try {
+ TestInterface servant = new TestInterfaceServant();
+ host.registerServant("Test", LOCALHOST, DEFAULT_PORT, servant);
+ host.registerServant("Test", LOCALHOST, DEFAULT_PORT, servant);
+ fail();
+ } catch (CorbaHostException e) {
+ assertTrue(e.getMessage().equals(CorbaHostException.BINDING_IN_USE));
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail();
+ }
+ }
+
+ /**
+ * Tests getting non existing reference
+ */
+ @Test
+ public void test_getNonExistingObject() {
+ try {
+ host.getReference("NonExistingReference", LOCALHOST, DEFAULT_PORT);
+ fail();
+ } catch (CorbaHostException e) {
+ assertTrue(e.getMessage().equals(CorbaHostException.NO_SUCH_OBJECT));
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail();
+ }
+ }
+
+ /**
+ * Tests unregistering non existing reference
+ */
+ @Test
+ public void test_unregisterNonExistentObject() {
+ try {
+ host.unregisterServant("NonExistingReference2", LOCALHOST, DEFAULT_PORT);
+ fail();
+ } catch (CorbaHostException e) {
+ assertTrue(e.getMessage().equals(CorbaHostException.NO_SUCH_OBJECT));
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail();
+ }
+ }
+
+ /**
+ * Tests registering under invalid host
+ */
+ @Test
+ public void test_invalidHost() {
+ try {
+ TestInterface servant = new TestInterfaceServant();
+ host.registerServant("Test", "nosuchhost", DEFAULT_PORT, servant);
+ fail();
+ } catch (CorbaHostException e) {
+ // Expected
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ /**
+ * Tests registering under invalid port
+ */
+ @Test
+ public void test_invalidPort() {
+ try {
+ TestInterface servant = new TestInterfaceServant();
+ host.registerServant("Test", LOCALHOST, 9991, servant);
+ fail();
+ } catch (CorbaHostException e) {
+ // Expected
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ /**
+ * Tests registering under invalid name
+ */
+ @Test
+ @Ignore("SUN JDK 6 is happy with all kind of names")
+ public void test_invalidBindingName() {
+ try {
+ TestInterface servant = new TestInterfaceServant();
+ host.registerServant("---", LOCALHOST, DEFAULT_PORT, servant);
+ fail();
+ } catch (CorbaHostException e) {
+ assertTrue(e.getMessage().equals(CorbaHostException.WRONG_NAME));
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail();
+ }
+ }
+}
diff --git a/java/sca/modules/host-corba/src/test/java/org/apache/tuscany/sca/host/corba/testing/general/TestInterface.java b/java/sca/modules/host-corba/src/test/java/org/apache/tuscany/sca/host/corba/testing/general/TestInterface.java
new file mode 100644
index 0000000000..8d1a9db9e9
--- /dev/null
+++ b/java/sca/modules/host-corba/src/test/java/org/apache/tuscany/sca/host/corba/testing/general/TestInterface.java
@@ -0,0 +1,30 @@
+/*
+ * 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.tuscany.sca.host.corba.testing.general;
+
+/**
+* org/apache/tuscany/sca/host/corba/testing/general/TestInterface.java .
+* Generated by the IDL-to-Java compiler (portable), version "3.2"
+* from general_tests.idl
+* środa, 25 czerwiec 2008 16:19:44 CEST
+*/
+
+public interface TestInterface extends TestInterfaceOperations, org.omg.CORBA.Object, org.omg.CORBA.portable.IDLEntity {
+} // interface TestInterface
diff --git a/java/sca/modules/host-corba/src/test/java/org/apache/tuscany/sca/host/corba/testing/general/TestInterfaceHelper.java b/java/sca/modules/host-corba/src/test/java/org/apache/tuscany/sca/host/corba/testing/general/TestInterfaceHelper.java
new file mode 100644
index 0000000000..fe85dc7743
--- /dev/null
+++ b/java/sca/modules/host-corba/src/test/java/org/apache/tuscany/sca/host/corba/testing/general/TestInterfaceHelper.java
@@ -0,0 +1,98 @@
+/*
+ * 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.tuscany.sca.host.corba.testing.general;
+
+/**
+* org/apache/tuscany/sca/host/corba/testing/general/TestInterfaceHelper.java .
+* Generated by the IDL-to-Java compiler (portable), version "3.2"
+* from general_tests.idl
+* środa, 25 czerwiec 2008 16:19:44 CEST
+*/
+
+abstract public class TestInterfaceHelper {
+ private static String _id = "IDL:org/apache/tuscany/sca/host/corba/testing/general/TestInterface:1.0";
+
+ public static void insert(org.omg.CORBA.Any a, org.apache.tuscany.sca.host.corba.testing.general.TestInterface that) {
+ org.omg.CORBA.portable.OutputStream out = a.create_output_stream();
+ a.type(type());
+ write(out, that);
+ a.read_value(out.create_input_stream(), type());
+ }
+
+ public static org.apache.tuscany.sca.host.corba.testing.general.TestInterface extract(org.omg.CORBA.Any a) {
+ return read(a.create_input_stream());
+ }
+
+ private static org.omg.CORBA.TypeCode __typeCode = null;
+
+ synchronized public static org.omg.CORBA.TypeCode type() {
+ if (__typeCode == null) {
+ __typeCode =
+ org.omg.CORBA.ORB.init()
+ .create_interface_tc(org.apache.tuscany.sca.host.corba.testing.general.TestInterfaceHelper.id(),
+ "TestInterface");
+ }
+ return __typeCode;
+ }
+
+ public static String id() {
+ return _id;
+ }
+
+ public static org.apache.tuscany.sca.host.corba.testing.general.TestInterface read(org.omg.CORBA.portable.InputStream istream) {
+ return narrow(istream.read_Object(_TestInterfaceStub.class));
+ }
+
+ public static void write(org.omg.CORBA.portable.OutputStream ostream,
+ org.apache.tuscany.sca.host.corba.testing.general.TestInterface value) {
+ ostream.write_Object((org.omg.CORBA.Object)value);
+ }
+
+ public static org.apache.tuscany.sca.host.corba.testing.general.TestInterface narrow(org.omg.CORBA.Object obj) {
+ if (obj == null)
+ return null;
+ else if (obj instanceof org.apache.tuscany.sca.host.corba.testing.general.TestInterface)
+ return (org.apache.tuscany.sca.host.corba.testing.general.TestInterface)obj;
+ else if (!obj._is_a(id()))
+ throw new org.omg.CORBA.BAD_PARAM();
+ else {
+ org.omg.CORBA.portable.Delegate delegate = ((org.omg.CORBA.portable.ObjectImpl)obj)._get_delegate();
+ org.apache.tuscany.sca.host.corba.testing.general._TestInterfaceStub stub =
+ new org.apache.tuscany.sca.host.corba.testing.general._TestInterfaceStub();
+ stub._set_delegate(delegate);
+ return stub;
+ }
+ }
+
+ public static org.apache.tuscany.sca.host.corba.testing.general.TestInterface unchecked_narrow(org.omg.CORBA.Object obj) {
+ if (obj == null)
+ return null;
+ else if (obj instanceof org.apache.tuscany.sca.host.corba.testing.general.TestInterface)
+ return (org.apache.tuscany.sca.host.corba.testing.general.TestInterface)obj;
+ else {
+ org.omg.CORBA.portable.Delegate delegate = ((org.omg.CORBA.portable.ObjectImpl)obj)._get_delegate();
+ org.apache.tuscany.sca.host.corba.testing.general._TestInterfaceStub stub =
+ new org.apache.tuscany.sca.host.corba.testing.general._TestInterfaceStub();
+ stub._set_delegate(delegate);
+ return stub;
+ }
+ }
+
+}
diff --git a/java/sca/modules/host-corba/src/test/java/org/apache/tuscany/sca/host/corba/testing/general/TestInterfaceHolder.java b/java/sca/modules/host-corba/src/test/java/org/apache/tuscany/sca/host/corba/testing/general/TestInterfaceHolder.java
new file mode 100644
index 0000000000..305a4d7b97
--- /dev/null
+++ b/java/sca/modules/host-corba/src/test/java/org/apache/tuscany/sca/host/corba/testing/general/TestInterfaceHolder.java
@@ -0,0 +1,51 @@
+/*
+ * 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.tuscany.sca.host.corba.testing.general;
+
+/**
+* org/apache/tuscany/sca/host/corba/testing/general/TestInterfaceHolder.java .
+* Generated by the IDL-to-Java compiler (portable), version "3.2"
+* from general_tests.idl
+* środa, 25 czerwiec 2008 16:19:44 CEST
+*/
+
+public final class TestInterfaceHolder implements org.omg.CORBA.portable.Streamable {
+ public org.apache.tuscany.sca.host.corba.testing.general.TestInterface value = null;
+
+ public TestInterfaceHolder() {
+ }
+
+ public TestInterfaceHolder(org.apache.tuscany.sca.host.corba.testing.general.TestInterface initialValue) {
+ value = initialValue;
+ }
+
+ public void _read(org.omg.CORBA.portable.InputStream i) {
+ value = org.apache.tuscany.sca.host.corba.testing.general.TestInterfaceHelper.read(i);
+ }
+
+ public void _write(org.omg.CORBA.portable.OutputStream o) {
+ org.apache.tuscany.sca.host.corba.testing.general.TestInterfaceHelper.write(o, value);
+ }
+
+ public org.omg.CORBA.TypeCode _type() {
+ return org.apache.tuscany.sca.host.corba.testing.general.TestInterfaceHelper.type();
+ }
+
+}
diff --git a/java/sca/modules/host-corba/src/test/java/org/apache/tuscany/sca/host/corba/testing/general/TestInterfaceOperations.java b/java/sca/modules/host-corba/src/test/java/org/apache/tuscany/sca/host/corba/testing/general/TestInterfaceOperations.java
new file mode 100644
index 0000000000..f557d3e020
--- /dev/null
+++ b/java/sca/modules/host-corba/src/test/java/org/apache/tuscany/sca/host/corba/testing/general/TestInterfaceOperations.java
@@ -0,0 +1,31 @@
+/*
+ * 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.tuscany.sca.host.corba.testing.general;
+
+/**
+* org/apache/tuscany/sca/host/corba/testing/general/TestInterfaceOperations.java .
+* Generated by the IDL-to-Java compiler (portable), version "3.2"
+* from general_tests.idl
+* środa, 25 czerwiec 2008 16:19:44 CEST
+*/
+
+public interface TestInterfaceOperations {
+ int getInt(int arg);
+} // interface TestInterfaceOperations
diff --git a/java/sca/modules/host-corba/src/test/java/org/apache/tuscany/sca/host/corba/testing/general/_TestInterfaceImplBase.java b/java/sca/modules/host-corba/src/test/java/org/apache/tuscany/sca/host/corba/testing/general/_TestInterfaceImplBase.java
new file mode 100644
index 0000000000..f993066dab
--- /dev/null
+++ b/java/sca/modules/host-corba/src/test/java/org/apache/tuscany/sca/host/corba/testing/general/_TestInterfaceImplBase.java
@@ -0,0 +1,74 @@
+/*
+ * 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.tuscany.sca.host.corba.testing.general;
+
+/**
+* org/apache/tuscany/sca/host/corba/testing/general/_TestInterfaceImplBase.java .
+* Generated by the IDL-to-Java compiler (portable), version "3.2"
+* from general_tests.idl
+* środa, 25 czerwiec 2008 16:19:44 CEST
+*/
+
+public abstract class _TestInterfaceImplBase extends org.omg.CORBA.portable.ObjectImpl implements
+ org.apache.tuscany.sca.host.corba.testing.general.TestInterface, org.omg.CORBA.portable.InvokeHandler {
+
+ // Constructors
+ public _TestInterfaceImplBase() {
+ }
+
+ private static java.util.Hashtable _methods = new java.util.Hashtable();
+ static {
+ _methods.put("getInt", new java.lang.Integer(0));
+ }
+
+ public org.omg.CORBA.portable.OutputStream _invoke(String $method,
+ org.omg.CORBA.portable.InputStream in,
+ org.omg.CORBA.portable.ResponseHandler $rh) {
+ org.omg.CORBA.portable.OutputStream out = null;
+ java.lang.Integer __method = (java.lang.Integer)_methods.get($method);
+ if (__method == null)
+ throw new org.omg.CORBA.BAD_OPERATION(0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE);
+
+ switch (__method.intValue()) {
+ case 0: // org/apache/tuscany/sca/host/corba/testing/general/TestInterface/getInt
+ {
+ int arg = in.read_long();
+ int $result = (int)0;
+ $result = this.getInt(arg);
+ out = $rh.createReply();
+ out.write_long($result);
+ break;
+ }
+
+ default:
+ throw new org.omg.CORBA.BAD_OPERATION(0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE);
+ }
+
+ return out;
+ } // _invoke
+
+ // Type-specific CORBA::Object operations
+ private static String[] __ids = {"IDL:org/apache/tuscany/sca/host/corba/testing/general/TestInterface:1.0"};
+
+ public String[] _ids() {
+ return (String[])__ids.clone();
+ }
+
+} // class _TestInterfaceImplBase
diff --git a/java/sca/modules/host-corba/src/test/java/org/apache/tuscany/sca/host/corba/testing/general/_TestInterfaceStub.java b/java/sca/modules/host-corba/src/test/java/org/apache/tuscany/sca/host/corba/testing/general/_TestInterfaceStub.java
new file mode 100644
index 0000000000..30a77deaf5
--- /dev/null
+++ b/java/sca/modules/host-corba/src/test/java/org/apache/tuscany/sca/host/corba/testing/general/_TestInterfaceStub.java
@@ -0,0 +1,73 @@
+/*
+ * 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.tuscany.sca.host.corba.testing.general;
+
+/**
+* org/apache/tuscany/sca/host/corba/testing/general/_TestInterfaceStub.java .
+* Generated by the IDL-to-Java compiler (portable), version "3.2"
+* from general_tests.idl
+* środa, 25 czerwiec 2008 16:19:44 CEST
+*/
+
+public class _TestInterfaceStub extends org.omg.CORBA.portable.ObjectImpl implements
+ org.apache.tuscany.sca.host.corba.testing.general.TestInterface {
+
+ public int getInt(int arg) {
+ org.omg.CORBA.portable.InputStream $in = null;
+ try {
+ org.omg.CORBA.portable.OutputStream $out = _request("getInt", true);
+ $out.write_long(arg);
+ $in = _invoke($out);
+ int $result = $in.read_long();
+ return $result;
+ } catch (org.omg.CORBA.portable.ApplicationException $ex) {
+ $in = $ex.getInputStream();
+ String _id = $ex.getId();
+ throw new org.omg.CORBA.MARSHAL(_id);
+ } catch (org.omg.CORBA.portable.RemarshalException $rm) {
+ return getInt(arg);
+ } finally {
+ _releaseReply($in);
+ }
+ } // getInt
+
+ // Type-specific CORBA::Object operations
+ private static String[] __ids = {"IDL:org/apache/tuscany/sca/host/corba/testing/general/TestInterface:1.0"};
+
+ public String[] _ids() {
+ return (String[])__ids.clone();
+ }
+
+ private void readObject(java.io.ObjectInputStream s) throws java.io.IOException {
+ String str = s.readUTF();
+ String[] args = null;
+ java.util.Properties props = null;
+ org.omg.CORBA.Object obj = org.omg.CORBA.ORB.init(args, props).string_to_object(str);
+ org.omg.CORBA.portable.Delegate delegate = ((org.omg.CORBA.portable.ObjectImpl)obj)._get_delegate();
+ _set_delegate(delegate);
+ }
+
+ private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException {
+ String[] args = null;
+ java.util.Properties props = null;
+ String str = org.omg.CORBA.ORB.init(args, props).object_to_string(this);
+ s.writeUTF(str);
+ }
+} // class _TestInterfaceStub
diff --git a/java/sca/modules/host-corba/src/test/java/org/apache/tuscany/sca/host/corba/testing/servants/TestInterfaceServant.java b/java/sca/modules/host-corba/src/test/java/org/apache/tuscany/sca/host/corba/testing/servants/TestInterfaceServant.java
new file mode 100644
index 0000000000..0ebde8ef0d
--- /dev/null
+++ b/java/sca/modules/host-corba/src/test/java/org/apache/tuscany/sca/host/corba/testing/servants/TestInterfaceServant.java
@@ -0,0 +1,35 @@
+/*
+ * 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.tuscany.sca.host.corba.testing.servants;
+
+import org.apache.tuscany.sca.host.corba.testing.general._TestInterfaceImplBase;
+
+/**
+ * Testing servant
+ */
+public class TestInterfaceServant extends _TestInterfaceImplBase {
+
+ private static final long serialVersionUID = 1L;
+
+ public int getInt(int arg) {
+ return arg;
+ }
+
+}
diff --git a/java/sca/modules/host-corba/src/test/resources/general.idl b/java/sca/modules/host-corba/src/test/resources/general.idl
new file mode 100644
index 0000000000..f67566deb8
--- /dev/null
+++ b/java/sca/modules/host-corba/src/test/resources/general.idl
@@ -0,0 +1,43 @@
+/*
+ * 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.
+ */
+
+/*
+ * compile by
+ * idlj -fall -oldImplBase genera.idl
+ */
+
+module org {
+ module apache {
+ module tuscany {
+ module sca {
+ module host {
+ module corba {
+ module testing {
+ module general {
+ interface TestInterface {
+ long getInt(in long arg);
+ };
+ };
+ };
+ };
+ };
+ };
+ };
+ };
+};