summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Campo2008-01-17 08:14:59 (EST)
committerChristian Campo2008-01-17 08:14:59 (EST)
commit9e02b51b96b4800ef7544e2c438d5cd6a456790f (patch)
tree686414cb53b9601a0e57b7634ff8a8332fa70e08
parent1d86ae74f59bfc320d7455fbac68f59bc3b679fb (diff)
downloadorg.eclipse.riena-9e02b51b96b4800ef7544e2c438d5cd6a456790f.zip
org.eclipse.riena-9e02b51b96b4800ef7544e2c438d5cd6a456790f.tar.gz
org.eclipse.riena-9e02b51b96b4800ef7544e2c438d5cd6a456790f.tar.bz2
initial checkin
-rw-r--r--org.eclipse.riena.communication.factory.hessian/.classpath7
-rw-r--r--org.eclipse.riena.communication.factory.hessian/.project28
-rw-r--r--org.eclipse.riena.communication.factory.hessian/.settings/org.eclipse.pde.core.prefs4
-rw-r--r--org.eclipse.riena.communication.factory.hessian/META-INF/MANIFEST.MF10
-rw-r--r--org.eclipse.riena.communication.factory.hessian/build.properties4
-rw-r--r--org.eclipse.riena.communication.factory.hessian/src/org/eclipse/riena/internal/communication/factory/hessian/Activator.java66
-rw-r--r--org.eclipse.riena.communication.factory.hessian/src/org/eclipse/riena/internal/communication/factory/hessian/MyHessianProxyFactory.java88
-rw-r--r--org.eclipse.riena.communication.factory.hessian/src/org/eclipse/riena/internal/communication/factory/hessian/RemoteServiceFactoryHessian.java140
8 files changed, 347 insertions, 0 deletions
diff --git a/org.eclipse.riena.communication.factory.hessian/.classpath b/org.eclipse.riena.communication.factory.hessian/.classpath
new file mode 100644
index 0000000..751c8f2
--- /dev/null
+++ b/org.eclipse.riena.communication.factory.hessian/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/org.eclipse.riena.communication.factory.hessian/.project b/org.eclipse.riena.communication.factory.hessian/.project
new file mode 100644
index 0000000..d15d314
--- /dev/null
+++ b/org.eclipse.riena.communication.factory.hessian/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.riena.communication.factory.hessian</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/org.eclipse.riena.communication.factory.hessian/.settings/org.eclipse.pde.core.prefs b/org.eclipse.riena.communication.factory.hessian/.settings/org.eclipse.pde.core.prefs
new file mode 100644
index 0000000..893147b
--- /dev/null
+++ b/org.eclipse.riena.communication.factory.hessian/.settings/org.eclipse.pde.core.prefs
@@ -0,0 +1,4 @@
+#Wed Apr 04 16:45:39 CEST 2007
+eclipse.preferences.version=1
+pluginProject.extensions=false
+resolve.requirebundle=false
diff --git a/org.eclipse.riena.communication.factory.hessian/META-INF/MANIFEST.MF b/org.eclipse.riena.communication.factory.hessian/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..5a645e6
--- /dev/null
+++ b/org.eclipse.riena.communication.factory.hessian/META-INF/MANIFEST.MF
@@ -0,0 +1,10 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Riena Communication Factory Hessian (Incubation)
+Bundle-SymbolicName: org.eclipse.riena.communication.factory.hessian
+Bundle-Version: 0.0.1
+Bundle-Activator: org.eclipse.riena.internal.communication.factory.hessian.Activator
+Import-Package: com.caucho.hessian.client,
+ org.osgi.framework;version="1.4.0"
+Require-Bundle: org.eclipse.riena.communication.core,
+ org.eclipse.osgi.services
diff --git a/org.eclipse.riena.communication.factory.hessian/build.properties b/org.eclipse.riena.communication.factory.hessian/build.properties
new file mode 100644
index 0000000..34d2e4d
--- /dev/null
+++ b/org.eclipse.riena.communication.factory.hessian/build.properties
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
diff --git a/org.eclipse.riena.communication.factory.hessian/src/org/eclipse/riena/internal/communication/factory/hessian/Activator.java b/org.eclipse.riena.communication.factory.hessian/src/org/eclipse/riena/internal/communication/factory/hessian/Activator.java
new file mode 100644
index 0000000..8b6aa20
--- /dev/null
+++ b/org.eclipse.riena.communication.factory.hessian/src/org/eclipse/riena/internal/communication/factory/hessian/Activator.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG 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:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.internal.communication.factory.hessian;
+
+import java.util.Hashtable;
+
+import org.eclipse.riena.communication.core.factory.IRemoteServiceFactory;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+
+public class Activator implements BundleActivator {
+
+ private ServiceRegistration regFactory;
+ private RemoteServiceFactoryHessian factory;
+
+ private static BundleContext CONTEXT;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ CONTEXT = context;
+ System.out.println("start hessian support on client");
+ factory = new RemoteServiceFactoryHessian();
+ Hashtable<String, Object> properties = new Hashtable<String, Object>(1);
+ properties.put(IRemoteServiceFactory.PROP_PROTOCOL, factory.getProtocol());
+
+ regFactory = context.registerService(IRemoteServiceFactory.ID, factory, properties);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ regFactory.unregister();
+ regFactory = null;
+
+ factory.dispose();
+ CONTEXT = null;
+ System.out.println("stop hessian support on client");
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static BundleContext getContext() {
+ return CONTEXT;
+ }
+
+}
diff --git a/org.eclipse.riena.communication.factory.hessian/src/org/eclipse/riena/internal/communication/factory/hessian/MyHessianProxyFactory.java b/org.eclipse.riena.communication.factory.hessian/src/org/eclipse/riena/internal/communication/factory/hessian/MyHessianProxyFactory.java
new file mode 100644
index 0000000..5d1a074
--- /dev/null
+++ b/org.eclipse.riena.communication.factory.hessian/src/org/eclipse/riena/internal/communication/factory/hessian/MyHessianProxyFactory.java
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG 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:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.internal.communication.factory.hessian;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.Dictionary;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.riena.communication.core.hooks.ICallMessageContext;
+import org.eclipse.riena.communication.core.hooks.ICallMessageContextAccessor;
+import org.eclipse.riena.communication.core.publisher.RSDPublisherProperties;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.cm.ManagedService;
+
+import com.caucho.hessian.client.HessianProxyFactory;
+
+public class MyHessianProxyFactory extends HessianProxyFactory implements ManagedService {
+
+ private ICallMessageContextAccessor mca;
+ private static ThreadLocal<HttpURLConnection> connections = new ThreadLocal<HttpURLConnection>();
+ private URL url;
+
+ public MyHessianProxyFactory() {
+ super();
+ }
+
+ @Override
+ protected URLConnection openConnection(URL url) throws IOException {
+ URLConnection connection;
+ if (this.url != null) {
+ connection = super.openConnection(this.url);
+ } else {
+ connection = super.openConnection(url);
+ }
+ ICallMessageContext mc = mca.getMessageContext();
+ Map<String, List<String>> headers = mc.listRequestHeaders();
+ if (headers != null) {
+ for (String hName : headers.keySet()) {
+ // System.out.println("size:" + headers.get(hName).size());
+ for (String hValue : headers.get(hName)) {
+ connection.addRequestProperty(hName, hValue);
+ // System.out.println(">>>" + hName + ":" + hValue);
+ }
+ }
+ }
+ connections.set((HttpURLConnection) connection);
+ return connection;
+ }
+
+ public void setCallMessageContextAccessor(ICallMessageContextAccessor mca) {
+ this.mca = mca;
+ }
+
+ public static HttpURLConnection getHttpURLConnection() {
+ return connections.get();
+ }
+
+ @SuppressWarnings("unchecked")
+ public void updated(Dictionary properties) throws ConfigurationException {
+ if (properties == null) {
+ return;
+ }
+ String urlStr = (String) properties.get(RSDPublisherProperties.PROP_REMOTE_PATH);
+ if (urlStr != null) {
+ try {
+ URL tmpUrl = new URL(urlStr);
+ this.url = tmpUrl;
+ } catch (MalformedURLException e) {
+ System.out.println("invalid url " + urlStr + e);
+ }
+ }
+
+ }
+
+}
diff --git a/org.eclipse.riena.communication.factory.hessian/src/org/eclipse/riena/internal/communication/factory/hessian/RemoteServiceFactoryHessian.java b/org.eclipse.riena.communication.factory.hessian/src/org/eclipse/riena/internal/communication/factory/hessian/RemoteServiceFactoryHessian.java
new file mode 100644
index 0000000..8b5dd73
--- /dev/null
+++ b/org.eclipse.riena.communication.factory.hessian/src/org/eclipse/riena/internal/communication/factory/hessian/RemoteServiceFactoryHessian.java
@@ -0,0 +1,140 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG 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:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.internal.communication.factory.hessian;
+
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.riena.communication.core.RemoteServiceDescription;
+import org.eclipse.riena.communication.core.factory.IRemoteServiceFactory;
+import org.eclipse.riena.communication.core.factory.RemoteServiceReference;
+import org.eclipse.riena.communication.core.hooks.ICallMessageContext;
+import org.eclipse.riena.communication.core.hooks.ICallMessageContextAccessor;
+
+/**
+ * This is a Hessian based implementation of {@link IRemoteServiceFactory}.
+ * Creates RemoteServiceReferences for service end points based on Hessian
+ * protocol.
+ * <p>
+ * RemoteServiceFactoryHessian becomes registered as OSGi Service with name
+ * {@link IRemoteServiceFactory#ID}. The OSGi Service set the property
+ * "riena.protocol=hessian".
+ *
+ * @author Alexander Ziegler
+ * @author Christian Campo
+ *
+ */
+public class RemoteServiceFactoryHessian implements IRemoteServiceFactory {
+ private final static String PROTOCOL = "hessian";
+ private ICallMessageContextAccessor mca = new CallMsgCtxAcc();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see xeval.rsd.core.IRemoteServiceFactory#create(xeval.rsd.core.RemoteServiceDescription)
+ */
+ public RemoteServiceReference createProxy(RemoteServiceDescription endpoint) {
+ String uri = endpoint.getURL();
+ if (uri == null) {
+ uri = "http://localhost/" + PROTOCOL + endpoint.getPath();
+ }
+ try {
+ MyHessianProxyFactory mhpf = new MyHessianProxyFactory();
+
+ mhpf.setCallMessageContextAccessor(mca);
+ Object proxy = mhpf.create(endpoint.getServiceInterfaceClass(), uri);
+ Object service = proxy;
+ RemoteServiceReference serviceReference = new RemoteServiceReference(endpoint);
+ // set the create proxy as service instance
+ serviceReference.setServiceInstance(service);
+ // the hessian proxy factory also implements ManagedService
+ if (endpoint.getConfigid() != null) {
+ serviceReference.setConfigServiceInstance(mhpf);
+ serviceReference.setConfigServicePID(endpoint.getConfigid());
+ }
+ return serviceReference;
+ } catch (MalformedURLException e) {
+ throw new RuntimeException("MalformedURLException", e);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see xeval.rsd.core.IRemoteServiceFactory#protocol()
+ */
+ public String getProtocol() {
+ return PROTOCOL;
+ }
+
+ public void dispose() {
+ }
+
+ public ICallMessageContextAccessor getMessageContextAccessor() {
+ return mca;
+ }
+
+ class CallMsgCtxAcc implements ICallMessageContextAccessor {
+
+ private ThreadLocal<ICallMessageContext> contexts = new ThreadLocal<ICallMessageContext>();
+
+ public ICallMessageContext createMessageContext(Object proxy) {
+ ICallMessageContext mc = new MsgCtx();
+ contexts.set(mc);
+ return mc;
+ }
+
+ public ICallMessageContext getMessageContext() {
+ return contexts.get();
+ }
+
+ class MsgCtx implements ICallMessageContext {
+
+ private HashMap<String, List<String>> customRequestHeader;
+
+ public List<String> getResponseHeaderValues(String name) {
+ Map<String, List<String>> headers = listResponseHeaders();
+ if (headers == null) {
+ return null;
+ }
+ return headers.get(name);
+ }
+
+ public Map<String, List<String>> listRequestHeaders() {
+ return customRequestHeader;
+ }
+
+ public Map<String, List<String>> listResponseHeaders() {
+ HttpURLConnection httpUrlConnection = MyHessianProxyFactory.getHttpURLConnection();
+ if (httpUrlConnection == null) {
+ return null;
+ }
+ return httpUrlConnection.getHeaderFields();
+ }
+
+ public void addRequestHeader(String name, String value) {
+ if (customRequestHeader == null) {
+ customRequestHeader = new HashMap<String, List<String>>();
+ }
+ List<String> hValues = customRequestHeader.get(name);
+ if (hValues == null) {
+ hValues = new ArrayList<String>();
+ customRequestHeader.put(name, hValues);
+ }
+ hValues.add(value);
+ }
+ }
+ }
+}