Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2014-05-13 00:23:32 +0000
committerslewis2014-05-13 00:23:32 +0000
commit4ecfece657179242082eafb91c2b2fa6e4a90f21 (patch)
tree48af539fa77cacaf71023a92fcf0697bd9d8d386
parent36c5e5215a1998c5e5f598a6c2e23cfe58786225 (diff)
downloadorg.eclipse.ecf-4ecfece657179242082eafb91c2b2fa6e4a90f21.tar.gz
org.eclipse.ecf-4ecfece657179242082eafb91c2b2fa6e4a90f21.tar.xz
org.eclipse.ecf-4ecfece657179242082eafb91c2b2fa6e4a90f21.zip
Added SSL tests and server keystore.
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/security/SSLGeneric.java21
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/security/SSLGenericLocalRemoteServiceTest.java30
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/security/SSLRemoteServiceProxyTest.java173
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/security/SSLRemoteServiceTest.java116
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/security/SSLRemoteServiceTrackerTest.java172
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/security/SSLSimpleConcatClient.java84
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/security/SSLSimpleConcatServer.java61
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/security/SSLSimpleTest.java155
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/security/readme.txt12
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/security/server.ksbin0 -> 2233 bytes
10 files changed, 824 insertions, 0 deletions
diff --git a/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/security/SSLGeneric.java b/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/security/SSLGeneric.java
new file mode 100644
index 000000000..3c0599a1d
--- /dev/null
+++ b/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/security/SSLGeneric.java
@@ -0,0 +1,21 @@
+/****************************************************************************
+ * Copyright (c) 2013 Composent, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Composent, Inc. - initial API and implementation
+ *****************************************************************************/
+
+package org.eclipse.ecf.tests.remoteservice.generic;
+
+/**
+ *
+ */
+public interface SSLGeneric {
+ public static final String CONSUMER_CONTAINER_TYPE = "ecf.generic.ssl.client";
+ public static final String HOST_CONTAINER_TYPE = "ecf.generic.ssl.server";
+ public static final String HOST_CONTAINER_ENDPOINT_ID = "ecfssl://localhost:{0}/secureserver";
+}
diff --git a/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/security/SSLGenericLocalRemoteServiceTest.java b/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/security/SSLGenericLocalRemoteServiceTest.java
new file mode 100644
index 000000000..09c1b8b8f
--- /dev/null
+++ b/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/security/SSLGenericLocalRemoteServiceTest.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+* Copyright (c) 2010 Composent, Inc. and others. All rights reserved. This
+* program and the accompanying materials are made available under the terms of
+* the Eclipse Public License v1.0 which accompanies this distribution, and is
+* available at http://www.eclipse.org/legal/epl-v10.html
+*
+* Contributors:
+* Composent, Inc. - initial API and implementation
+******************************************************************************/
+package org.eclipse.ecf.tests.remoteservice.generic;
+
+import org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter;
+import org.eclipse.ecf.tests.remoteservice.AbstractLocalRemoteServiceTest;
+
+public class SSLGenericLocalRemoteServiceTest extends
+ AbstractLocalRemoteServiceTest {
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ container = getContainerFactory().createContainer(SSLGeneric.CONSUMER_CONTAINER_TYPE);
+ containerAdapter = (IRemoteServiceContainerAdapter) container.getAdapter(IRemoteServiceContainerAdapter.class);
+ }
+
+ protected void tearDown() throws Exception {
+ container.disconnect();
+ container.dispose();
+ getContainerManager().removeAllContainers();
+ super.tearDown();
+ }
+}
diff --git a/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/security/SSLRemoteServiceProxyTest.java b/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/security/SSLRemoteServiceProxyTest.java
new file mode 100644
index 000000000..a732c178a
--- /dev/null
+++ b/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/security/SSLRemoteServiceProxyTest.java
@@ -0,0 +1,173 @@
+/****************************************************************************
+ * Copyright (c) 2008 Composent, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Composent, Inc. - initial API and implementation
+ *****************************************************************************/
+
+package org.eclipse.ecf.tests.remoteservice.generic;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.eclipse.ecf.remoteservice.IRemoteService;
+import org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter;
+import org.eclipse.ecf.remoteservice.IRemoteServiceListener;
+import org.eclipse.ecf.remoteservice.IRemoteServiceProxy;
+import org.eclipse.ecf.remoteservice.IRemoteServiceReference;
+import org.eclipse.ecf.remoteservice.RemoteServiceHelper;
+import org.eclipse.ecf.remoteservice.events.IRemoteServiceEvent;
+import org.eclipse.ecf.remoteservice.events.IRemoteServiceRegisteredEvent;
+import org.eclipse.ecf.remoteservice.util.tracker.RemoteServiceTracker;
+import org.eclipse.ecf.tests.remoteservice.AbstractRemoteServiceTest;
+import org.eclipse.ecf.tests.remoteservice.IConcatService;
+import org.eclipse.equinox.concurrent.future.IFuture;
+import org.eclipse.osgi.util.NLS;
+
+/**
+ *
+ */
+public class SSLRemoteServiceProxyTest extends AbstractRemoteServiceTest {
+
+ RemoteServiceTracker remoteServiceTracker;
+
+ protected String getClientContainerName() {
+ return SSLGeneric.CONSUMER_CONTAINER_TYPE;
+ }
+
+ protected String getServerIdentity() {
+ return NLS.bind(SSLGeneric.HOST_CONTAINER_ENDPOINT_ID, new Integer(genericServerPort));
+ }
+
+ protected String getServerContainerName() {
+ return SSLGeneric.HOST_CONTAINER_TYPE;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ setClientCount(2);
+ createServerAndClients();
+ setupRemoteServiceAdapters();
+ connectClients();
+ addRemoteServiceListeners();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ cleanUpServerAndClients();
+ if (remoteServiceTracker != null) {
+ remoteServiceTracker.close();
+ }
+ super.tearDown();
+ }
+
+ protected IRemoteService getRemoteService(IRemoteServiceContainerAdapter adapter, String clazz, String filter) {
+ remoteServiceTracker = new RemoteServiceTracker(adapter, null, clazz, null);
+ assertNotNull(remoteServiceTracker);
+ remoteServiceTracker.open();
+ return remoteServiceTracker.getRemoteService();
+ }
+
+
+ public void testRemoteServiceProxy() throws Exception {
+ final IRemoteServiceContainerAdapter[] adapters = getRemoteServiceAdapters();
+ // client [0]/adapter[0] is the service 'server'
+ // client [1]/adapter[1] is the service target (client)
+ final Dictionary props = new Hashtable();
+ // Register
+ adapters[0].registerRemoteService(new String[] {IConcatService.class.getName()}, createService(), props);
+ // Give some time for propagation
+ sleep(3000);
+
+ final RemoteServiceTracker st = new RemoteServiceTracker(adapters[1], null, IConcatService.class.getName(), null);
+ assertNotNull(st);
+ st.open();
+ IRemoteService rs = st.getRemoteService();
+ final IConcatService concatService = (IConcatService) rs.getProxy();
+ assertNotNull(concatService);
+ // test for proxy implementing IRemoteServiceProxy
+ if (concatService instanceof IRemoteServiceProxy) {
+ IRemoteService remoteService = ((IRemoteServiceProxy) concatService).getRemoteService();
+ assertNotNull(remoteService);
+ IRemoteServiceReference remoteServiceReference = ((IRemoteServiceProxy) concatService).getRemoteServiceReference();
+ assertNotNull(remoteServiceReference);
+ System.out.println("remote service reference found from proxy="+remoteServiceReference);
+ System.out.println("remoteserviceproxy call start");
+ Object result = RemoteServiceHelper.syncExec(remoteService, "concat" , new Object[] { "IRemoteServiceProxy ","is very cool" }, 20000);
+ System.out.println("remoteserviceproxy call end. result=" + result);
+ } else {
+ System.out.println("proxy call start");
+ final String result = concatService.concat("OSGi ", "is cool");
+ System.out.println("proxy call end. result=" + result);
+ }
+ sleep(3000);
+ st.close();
+ sleep(3000);
+ }
+
+ IRemoteService remoteService;
+ boolean done;
+
+ public void testServiceListener() throws Exception {
+ final IRemoteServiceContainerAdapter[] adapters = getRemoteServiceAdapters();
+ done = false;
+ final Object lock = new Object();
+ adapters[1].addRemoteServiceListener(new IRemoteServiceListener() {
+ public void handleServiceEvent(IRemoteServiceEvent event) {
+ if (event instanceof IRemoteServiceRegisteredEvent) {
+ IRemoteServiceRegisteredEvent e = (IRemoteServiceRegisteredEvent) event;
+ IRemoteServiceReference ref = e.getReference();
+ remoteService = adapters[1].getRemoteService(ref);
+ assertNotNull(remoteService);
+ synchronized (lock) {
+ done = true;
+ lock.notify();
+ }
+ }
+ }
+ });
+
+ // Now register service on server (adapters[0]). This should result in notification on client (adapters[1])
+ // in above handleServiceEvent
+ adapters[0].registerRemoteService(new String[] { IConcatService.class.getName() }, createService(),
+ customizeProperties(null));
+
+ // wait until block above called asynchronously
+ int count = 0;
+ synchronized (lock) {
+ while (!done && count++ < 10) {
+ try {
+ lock.wait(1000);
+ } catch (InterruptedException e) {
+ fail();
+ }
+ }
+ }
+
+ assertTrue(done);
+
+ if (remoteService == null) return;
+ // We've got the remote service, so we're good to go
+ assertTrue(remoteService != null);
+ traceCallStart("callAsynchResult");
+ final IFuture result = remoteService
+ .callAsync(createRemoteConcat("ECF AsynchResults ", "are cool"));
+ traceCallEnd("callAsynch");
+ assertNotNull(result);
+ Thread.sleep(SLEEPTIME);
+ }
+
+}
diff --git a/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/security/SSLRemoteServiceTest.java b/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/security/SSLRemoteServiceTest.java
new file mode 100644
index 000000000..1dbd84695
--- /dev/null
+++ b/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/security/SSLRemoteServiceTest.java
@@ -0,0 +1,116 @@
+/****************************************************************************
+ * Copyright (c) 2004 Composent, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Composent, Inc. - initial API and implementation
+ *****************************************************************************/
+
+package org.eclipse.ecf.tests.remoteservice.generic;
+
+import org.eclipse.ecf.remoteservice.IRemoteService;
+import org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter;
+import org.eclipse.ecf.remoteservice.IRemoteServiceListener;
+import org.eclipse.ecf.remoteservice.IRemoteServiceReference;
+import org.eclipse.ecf.remoteservice.events.IRemoteServiceEvent;
+import org.eclipse.ecf.remoteservice.events.IRemoteServiceRegisteredEvent;
+import org.eclipse.ecf.tests.remoteservice.AbstractRemoteServiceTest;
+import org.eclipse.ecf.tests.remoteservice.IConcatService;
+import org.eclipse.equinox.concurrent.future.IFuture;
+import org.eclipse.osgi.util.NLS;
+
+public class SSLRemoteServiceTest extends AbstractRemoteServiceTest {
+
+ protected String getClientContainerName() {
+ return SSLGeneric.CONSUMER_CONTAINER_TYPE;
+ }
+
+ protected String getServerIdentity() {
+ return NLS.bind(SSLGeneric.HOST_CONTAINER_ENDPOINT_ID, new Integer(genericServerPort));
+ }
+
+ protected String getServerContainerName() {
+ return SSLGeneric.HOST_CONTAINER_TYPE;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ setClientCount(2);
+ createServerAndClients();
+ setupRemoteServiceAdapters();
+ connectClients();
+ addRemoteServiceListeners();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ cleanUpServerAndClients();
+ super.tearDown();
+ }
+
+ IRemoteService remoteService;
+ boolean done;
+
+ public void testServiceListener() throws Exception {
+ final IRemoteServiceContainerAdapter[] adapters = getRemoteServiceAdapters();
+ done = false;
+ final Object lock = new Object();
+ adapters[1].addRemoteServiceListener(new IRemoteServiceListener() {
+ public void handleServiceEvent(IRemoteServiceEvent event) {
+ if (event instanceof IRemoteServiceRegisteredEvent) {
+ IRemoteServiceRegisteredEvent e = (IRemoteServiceRegisteredEvent) event;
+ IRemoteServiceReference ref = e.getReference();
+ remoteService = adapters[1].getRemoteService(ref);
+ assertNotNull(remoteService);
+ synchronized (lock) {
+ done = true;
+ lock.notify();
+ }
+ }
+ }
+ });
+
+ // Now register service on server (adapters[0]). This should result in notification on client (adapters[1])
+ // in above handleServiceEvent
+ adapters[0].registerRemoteService(new String[] { IConcatService.class.getName() }, createService(),
+ customizeProperties(null));
+
+ // wait until block above called asynchronously
+ int count = 0;
+ synchronized (lock) {
+ while (!done && count++ < 10) {
+ try {
+ lock.wait(1000);
+ } catch (InterruptedException e) {
+ fail();
+ }
+ }
+ }
+
+ assertTrue(done);
+
+ if (remoteService == null) return;
+ // We've got the remote service, so we're good to go
+ assertTrue(remoteService != null);
+ traceCallStart("callAsynchResult");
+ final IFuture result = remoteService
+ .callAsync(createRemoteConcat("ECF AsynchResults ", "are cool"));
+ traceCallEnd("callAsynch");
+ assertNotNull(result);
+ Thread.sleep(SLEEPTIME);
+ }
+
+
+}
diff --git a/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/security/SSLRemoteServiceTrackerTest.java b/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/security/SSLRemoteServiceTrackerTest.java
new file mode 100644
index 000000000..2e6d223d5
--- /dev/null
+++ b/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/security/SSLRemoteServiceTrackerTest.java
@@ -0,0 +1,172 @@
+/****************************************************************************
+ * Copyright (c) 2008 Composent, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Composent, Inc. - initial API and implementation
+ *****************************************************************************/
+
+package org.eclipse.ecf.tests.remoteservice.generic;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.eclipse.ecf.remoteservice.IRemoteService;
+import org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter;
+import org.eclipse.ecf.remoteservice.IRemoteServiceListener;
+import org.eclipse.ecf.remoteservice.IRemoteServiceReference;
+import org.eclipse.ecf.remoteservice.events.IRemoteServiceEvent;
+import org.eclipse.ecf.remoteservice.events.IRemoteServiceRegisteredEvent;
+import org.eclipse.ecf.remoteservice.util.tracker.RemoteServiceTracker;
+import org.eclipse.ecf.tests.remoteservice.AbstractRemoteServiceTest;
+import org.eclipse.ecf.tests.remoteservice.IConcatService;
+import org.eclipse.equinox.concurrent.future.IFuture;
+import org.eclipse.osgi.util.NLS;
+
+/**
+ *
+ */
+public class SSLRemoteServiceTrackerTest extends AbstractRemoteServiceTest {
+
+ RemoteServiceTracker remoteServiceTracker;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ecf.tests.remoteservice.AbstractRemoteServiceTest#
+ * getClientContainerName()
+ */
+ protected String getClientContainerName() {
+ return SSLGeneric.CONSUMER_CONTAINER_TYPE;
+ }
+
+ protected String getServerIdentity() {
+ return NLS.bind(SSLGeneric.HOST_CONTAINER_ENDPOINT_ID, new Integer(genericServerPort));
+ }
+
+ protected String getServerContainerName() {
+ return SSLGeneric.HOST_CONTAINER_TYPE;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ setClientCount(2);
+ createServerAndClients();
+ setupRemoteServiceAdapters();
+ connectClients();
+ addRemoteServiceListeners();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ cleanUpServerAndClients();
+ if (remoteServiceTracker != null) {
+ remoteServiceTracker.close();
+ }
+ super.tearDown();
+ }
+
+ protected IRemoteService getRemoteService(
+ IRemoteServiceContainerAdapter adapter, String clazz, String filter) {
+ remoteServiceTracker = new RemoteServiceTracker(adapter, null, clazz,
+ null);
+ assertNotNull(remoteServiceTracker);
+ remoteServiceTracker.open();
+ return remoteServiceTracker.getRemoteService();
+ }
+
+ public void testRemoteServiceTracker() throws Exception {
+ final IRemoteServiceContainerAdapter[] adapters = getRemoteServiceAdapters();
+ // client [0]/adapter[0] is the service 'server'
+ // client [1]/adapter[1] is the service target (client)
+ final Dictionary props = new Hashtable();
+ // Register
+ adapters[0].registerRemoteService(
+ new String[] { IConcatService.class.getName() },
+ createService(), props);
+ // Give some time for propagation
+ sleep(3000);
+
+ final RemoteServiceTracker st = new RemoteServiceTracker(adapters[1],
+ null, IConcatService.class.getName(), null);
+ assertNotNull(st);
+ st.open();
+ IRemoteService rs = st.getRemoteService();
+ final IConcatService concatService = (IConcatService) rs.getProxy();
+ assertNotNull(concatService);
+ System.out.println("proxy call start");
+ final String result = concatService.concat("OSGi ", "is cool");
+ System.out.println("proxy call end. result=" + result);
+ sleep(3000);
+ st.close();
+ sleep(3000);
+ }
+
+ IRemoteService remoteService;
+ boolean done;
+
+ public void testServiceListener() throws Exception {
+ final IRemoteServiceContainerAdapter[] adapters = getRemoteServiceAdapters();
+ done = false;
+ final Object lock = new Object();
+ adapters[1].addRemoteServiceListener(new IRemoteServiceListener() {
+ public void handleServiceEvent(IRemoteServiceEvent event) {
+ if (event instanceof IRemoteServiceRegisteredEvent) {
+ IRemoteServiceRegisteredEvent e = (IRemoteServiceRegisteredEvent) event;
+ IRemoteServiceReference ref = e.getReference();
+ remoteService = adapters[1].getRemoteService(ref);
+ assertNotNull(remoteService);
+ synchronized (lock) {
+ done = true;
+ lock.notify();
+ }
+ }
+ }
+ });
+
+ // Now register service on server (adapters[0]). This should result in
+ // notification on client (adapters[1])
+ // in above handleServiceEvent
+ adapters[0].registerRemoteService(
+ new String[] { IConcatService.class.getName() },
+ createService(), customizeProperties(null));
+
+ // wait until block above called asynchronously
+ int count = 0;
+ synchronized (lock) {
+ while (!done && count++ < 10) {
+ try {
+ lock.wait(1000);
+ } catch (InterruptedException e) {
+ fail();
+ }
+ }
+ }
+
+ assertTrue(done);
+
+ if (remoteService == null)
+ return;
+ // We've got the remote service, so we're good to go
+ assertTrue(remoteService != null);
+ traceCallStart("callAsynchResult");
+ final IFuture result = remoteService.callAsync(createRemoteConcat(
+ "ECF AsynchResults ", "are cool"));
+ traceCallEnd("callAsynch");
+ assertNotNull(result);
+ Thread.sleep(SLEEPTIME);
+ }
+
+}
diff --git a/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/security/SSLSimpleConcatClient.java b/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/security/SSLSimpleConcatClient.java
new file mode 100644
index 000000000..bc6ea6821
--- /dev/null
+++ b/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/security/SSLSimpleConcatClient.java
@@ -0,0 +1,84 @@
+/*******************************************************************************
+* Copyright (c) 2009 EclipseSource and others. All rights reserved. This
+* program and the accompanying materials are made available under the terms of
+* the Eclipse Public License v1.0 which accompanies this distribution, and is
+* available at http://www.eclipse.org/legal/epl-v10.html
+*
+* Contributors:
+* EclipseSource - initial API and implementation
+******************************************************************************/
+package org.eclipse.ecf.tests.remoteservice.generic;
+
+import org.eclipse.ecf.core.ContainerFactory;
+import org.eclipse.ecf.core.IContainer;
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.core.identity.IDFactory;
+import org.eclipse.ecf.remoteservice.IRemoteService;
+import org.eclipse.ecf.remoteservice.IRemoteServiceContainer;
+import org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter;
+import org.eclipse.ecf.remoteservice.IRemoteServiceReference;
+import org.eclipse.ecf.remoteservice.RemoteServiceContainer;
+import org.eclipse.ecf.tests.remoteservice.IConcatService;
+import org.eclipse.osgi.util.NLS;
+
+public class SSLSimpleConcatClient {
+
+ public static final String CLIENT_TYPE = "ecf.generic.ssl.client";
+
+ private IRemoteServiceContainer rsContainer;
+
+ protected String SERVER_ID = "ecfssl://localhost:{0}"+SSLSimpleConcatServer.PATH;
+
+ private IRemoteServiceReference rsReference;
+ private IRemoteService remoteService;
+
+ public synchronized IRemoteService getRemoteService() {
+ if (remoteService == null) {
+ remoteService = rsContainer.getContainerAdapter().getRemoteService(rsReference);
+ }
+ return remoteService;
+ }
+
+ public void start(int port) throws Exception {
+ IContainer client = ContainerFactory.getDefault().createContainer(
+ CLIENT_TYPE);
+ // Get adapter for accessing remote services
+ IRemoteServiceContainerAdapter adapter = (IRemoteServiceContainerAdapter) client
+ .getAdapter(IRemoteServiceContainerAdapter.class);
+
+ rsContainer = new RemoteServiceContainer(client,adapter);
+
+ System.out.println("Client created with ID=" + client.getID());
+
+ ID connectTargetID = IDFactory.getDefault().createStringID(
+ NLS.bind(SERVER_ID, new Integer(port)));
+
+ System.out.println("Attempting connect to id="+connectTargetID);
+ client.connect(connectTargetID, null);
+ System.out.println("Client connected to connectTargetID="
+ + connectTargetID);
+
+ Thread.sleep(1000);
+
+
+ // Get remote service reference
+ IRemoteServiceReference[] refs = adapter.getRemoteServiceReferences(
+ (ID[]) null, IConcatService.class.getName(), null);
+
+ rsReference = refs[0];
+
+ System.out.println("Remote service with ref=" + refs[0]);
+ }
+
+ public void stop() {
+ if (rsContainer != null) {
+ rsContainer.getContainerAdapter().ungetRemoteService(rsReference);
+ remoteService = null;
+ rsReference = null;
+ rsContainer.getContainer().disconnect();
+ rsContainer = null;
+ }
+
+ }
+
+}
diff --git a/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/security/SSLSimpleConcatServer.java b/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/security/SSLSimpleConcatServer.java
new file mode 100644
index 000000000..6b3a31c84
--- /dev/null
+++ b/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/security/SSLSimpleConcatServer.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+* Copyright (c) 2013 EclipseSource and others. All rights reserved. This
+* program and the accompanying materials are made available under the terms of
+* the Eclipse Public License v1.0 which accompanies this distribution, and is
+* available at http://www.eclipse.org/legal/epl-v10.html
+*
+* Contributors:
+* EclipseSource - initial API and implementation
+******************************************************************************/
+package org.eclipse.ecf.tests.remoteservice.generic;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter;
+import org.eclipse.ecf.remoteservice.IRemoteServiceRegistration;
+import org.eclipse.ecf.server.generic.SSLGenericServerContainer;
+import org.eclipse.ecf.server.generic.SSLSimpleGenericServer;
+import org.eclipse.ecf.tests.remoteservice.IConcatService;
+
+public class SSLSimpleConcatServer {
+
+ public static final String PATH = "/sslserver";
+ public static final String HOST = "localhost";
+ public static final int KEEPALIVE = 30000;
+
+ private IRemoteServiceRegistration registration = null;
+ private SSLSimpleGenericServer server;
+
+ public class ConcatService implements IConcatService {
+
+ public String concat(String string1, String string2) {
+ System.out.println("server.concat("+string1+","+string2+")");
+ return string1+string2;
+ }
+
+ }
+ public void start(int port) throws Exception {
+ // Start server
+ server = new SSLSimpleGenericServer(HOST,port);
+ server.start(PATH, KEEPALIVE);
+
+ SSLGenericServerContainer serverContainer = server.getServerContainer(0);
+ IRemoteServiceContainerAdapter adapter = (IRemoteServiceContainerAdapter) serverContainer.getAdapter(IRemoteServiceContainerAdapter.class);
+ Assert.isNotNull(adapter);
+ registration = adapter.registerRemoteService(new String[] { IConcatService.class.getName() }, new ConcatService(), null);
+ Assert.isNotNull(registration);
+ System.out.println("generic server started with id="+serverContainer.getID());
+ }
+
+ public IRemoteServiceRegistration getConcatServiceRegistration() {
+ return registration;
+ }
+
+ public void stop() {
+ if (registration != null) {
+ registration.unregister();
+ registration = null;
+ }
+ server.stop();
+ server = null;
+ }
+}
diff --git a/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/security/SSLSimpleTest.java b/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/security/SSLSimpleTest.java
new file mode 100644
index 000000000..801dbdd6f
--- /dev/null
+++ b/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/security/SSLSimpleTest.java
@@ -0,0 +1,155 @@
+/*******************************************************************************
+* Copyright (c) 2009 EclipseSource and others. All rights reserved. This
+* program and the accompanying materials are made available under the terms of
+* the Eclipse Public License v1.0 which accompanies this distribution, and is
+* available at http://www.eclipse.org/legal/epl-v10.html
+*
+* Contributors:
+* EclipseSource - initial API and implementation
+******************************************************************************/
+package org.eclipse.ecf.tests.remoteservice.generic;
+
+import java.io.IOException;
+import java.net.ServerSocket;
+
+import org.eclipse.ecf.remoteservice.IRemoteCall;
+import org.eclipse.ecf.remoteservice.IRemoteCallListener;
+import org.eclipse.ecf.remoteservice.IRemoteService;
+import org.eclipse.ecf.remoteservice.events.IRemoteCallCompleteEvent;
+import org.eclipse.ecf.remoteservice.events.IRemoteCallEvent;
+import org.eclipse.ecf.tests.remoteservice.IConcatService;
+import org.eclipse.equinox.concurrent.future.IFuture;
+
+import junit.framework.TestCase;
+
+public class SSLSimpleTest extends TestCase {
+
+ public static final String TEST_STRING_1 = "foo";
+ public static final String TEST_STRING_2 = "bar";
+
+ SSLSimpleConcatServer server;
+ SSLSimpleConcatClient client;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ int freePort = getFreePort();
+ if (freePort == -1) throw new Exception("could not run test because could not find open port for server");
+ server = new SSLSimpleConcatServer();
+ server.start(freePort);
+ client = new SSLSimpleConcatClient();
+ client.start(freePort);
+ }
+
+ private int getFreePort() {
+ int port = -1;
+ try {
+ ServerSocket ss = new ServerSocket(0);
+ port = ss.getLocalPort();
+ ss.close();
+ } catch (IOException e) {
+ return -1;
+ }
+ return port;
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ client.stop();
+ client = null;
+ server.stop();
+ server = null;
+ }
+
+ public void testSimpleClientAndServerWithProxy() throws Exception {
+
+ IRemoteService remoteService = client.getRemoteService();
+ assertNotNull(remoteService);
+ // Use proxy
+ String result = ((IConcatService) remoteService.getProxy()).concat(TEST_STRING_1,TEST_STRING_2);
+ assertTrue(result != null && result.equals(TEST_STRING_1+TEST_STRING_2));
+
+ }
+
+ private IRemoteCall getRemoteConcatCall(final String first, final String second) {
+ return new IRemoteCall() {
+
+ public String getMethod() {
+ return "concat";
+ }
+
+ public Object[] getParameters() {
+ return new String[] { first, second };
+ }
+
+ public long getTimeout() {
+ return 3000;
+ }};
+ }
+
+ public void testSimpleClientAndServerWithCallSync() throws Exception {
+
+ IRemoteService remoteService = client.getRemoteService();
+ assertNotNull(remoteService);
+ // Use callSync
+ String result = (String) remoteService.callSync(getRemoteConcatCall(TEST_STRING_2, TEST_STRING_1));
+ assertTrue(result != null && result.equals(TEST_STRING_2+TEST_STRING_1));
+
+ }
+
+ public void testSimpleClientAndServerWithFireAsync() throws Exception {
+
+ IRemoteService remoteService = client.getRemoteService();
+ assertNotNull(remoteService);
+ // Use callSync
+ remoteService.fireAsync(getRemoteConcatCall(TEST_STRING_2, TEST_STRING_1));
+
+ Thread.sleep(1000);
+
+ }
+
+ public void testSimpleClientAndServerWithCallAsync() throws Exception {
+
+ IRemoteService remoteService = client.getRemoteService();
+ assertNotNull(remoteService);
+ // Use callSync
+ remoteService.callAsync(getRemoteConcatCall(TEST_STRING_2, TEST_STRING_1));
+
+ Thread.sleep(1000);
+
+ }
+
+ String result = null;
+
+ public void testSimpleClientAndServerWithCallAsyncListener() throws Exception {
+
+ IRemoteService remoteService = client.getRemoteService();
+ assertNotNull(remoteService);
+ // Use callSync
+ remoteService.callAsync(getRemoteConcatCall(TEST_STRING_2, TEST_STRING_1),new IRemoteCallListener(){
+ public void handleEvent(IRemoteCallEvent event) {
+ if (event instanceof IRemoteCallCompleteEvent) {
+ result = (String) ((IRemoteCallCompleteEvent) event).getResponse();
+ }
+ }
+ });
+
+ Thread.sleep(1000);
+
+ assertNotNull(result);
+ assertTrue(result.equals(TEST_STRING_2+TEST_STRING_1));
+
+ }
+
+ public void testSimpleClientAndServerWithFuture() throws Exception {
+
+ IRemoteService remoteService = client.getRemoteService();
+ assertNotNull(remoteService);
+ // Use callSync
+ IFuture future = remoteService.callAsync(getRemoteConcatCall(TEST_STRING_2, TEST_STRING_1));
+ assertNotNull(future);
+ String result = (String) future.get();
+ assertTrue(result.equals(TEST_STRING_2+TEST_STRING_1));
+ }
+
+
+}
diff --git a/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/security/readme.txt b/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/security/readme.txt
new file mode 100644
index 000000000..70c23e48f
--- /dev/null
+++ b/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/security/readme.txt
@@ -0,0 +1,12 @@
+In this directory is a java keystore file 'server.ks' that has a self-signed certificate.
+The password for accessing this keystore is 'server'. To use with the default
+SSLServerSocketFactory and SSLSocketFactory you may use the following Java System
+Properties
+
+-Djavax.net.ssl.keyStore=security/server.ks
+-Djavax.net.ssl.keyStorePassword=server
+-Djavax.net.ssl.trustStore=security/server.ks
+
+To debug the ssl connection process add this Java System Property
+
+-Djavax.net.debug=all
diff --git a/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/security/server.ks b/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/security/server.ks
new file mode 100644
index 000000000..7f31ada30
--- /dev/null
+++ b/tests/bundles/org.eclipse.ecf.tests.remoteservice.generic/security/server.ks
Binary files differ

Back to the top