summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Campo2008-01-17 09:30:59 (EST)
committerChristian Campo2008-01-17 09:30:59 (EST)
commit2a2e069a19022ee182a2537571093e2b80497ab4 (patch)
tree0f16001f63a9f1018f7875697914b4f2565b8f48
parenta458efa1e7d92b22abf48de635ab899ac2a6f9f5 (diff)
downloadorg.eclipse.riena-2a2e069a19022ee182a2537571093e2b80497ab4.zip
org.eclipse.riena-2a2e069a19022ee182a2537571093e2b80497ab4.tar.gz
org.eclipse.riena-2a2e069a19022ee182a2537571093e2b80497ab4.tar.bz2
initial checkin
-rw-r--r--org.eclipse.riena.communication.publisher.hessian/.classpath7
-rw-r--r--org.eclipse.riena.communication.publisher.hessian/.project28
-rw-r--r--org.eclipse.riena.communication.publisher.hessian/META-INF/MANIFEST.MF15
-rw-r--r--org.eclipse.riena.communication.publisher.hessian/build.properties5
-rw-r--r--org.eclipse.riena.communication.publisher.hessian/plugin.xml13
-rw-r--r--org.eclipse.riena.communication.publisher.hessian/src/org/eclipse/riena/communication/publisher/hessian/HessianRienaDispatcherServlet.java149
-rw-r--r--org.eclipse.riena.communication.publisher.hessian/src/org/eclipse/riena/internal/communication/publisher/hessian/Activator.java75
-rw-r--r--org.eclipse.riena.communication.publisher.hessian/src/org/eclipse/riena/internal/communication/publisher/hessian/HessianRemoteServicePublisher.java109
-rw-r--r--org.eclipse.riena.communication.publisher.hessian/src/org/eclipse/riena/internal/communication/publisher/hessian/MessageContext.java64
-rw-r--r--org.eclipse.riena.communication.publisher.hessian/src/org/eclipse/riena/internal/communication/publisher/hessian/MessageContextAccessor.java29
10 files changed, 494 insertions, 0 deletions
diff --git a/org.eclipse.riena.communication.publisher.hessian/.classpath b/org.eclipse.riena.communication.publisher.hessian/.classpath
new file mode 100644
index 0000000..751c8f2
--- /dev/null
+++ b/org.eclipse.riena.communication.publisher.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.publisher.hessian/.project b/org.eclipse.riena.communication.publisher.hessian/.project
new file mode 100644
index 0000000..9257500
--- /dev/null
+++ b/org.eclipse.riena.communication.publisher.hessian/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.riena.communication.publisher.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.publisher.hessian/META-INF/MANIFEST.MF b/org.eclipse.riena.communication.publisher.hessian/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..4feb499
--- /dev/null
+++ b/org.eclipse.riena.communication.publisher.hessian/META-INF/MANIFEST.MF
@@ -0,0 +1,15 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Riena Communication Publisher Hessian (Incubation)
+Bundle-SymbolicName: org.eclipse.riena.communication.publisher.hessian;singleton:=true
+Bundle-Version: 0.0.1
+Bundle-Activator: org.eclipse.riena.internal.communication.publisher.hessian.Activator
+Require-Bundle: org.eclipse.equinox.http.registry,
+ org.eclipse.equinox.http.servlet,
+ org.eclipse.riena.communication.core
+Import-Package: com.caucho.hessian.io,
+ com.caucho.hessian.server,
+ javax.servlet;version="2.4.0",
+ javax.servlet.http;version="2.4.0",
+ org.osgi.framework;version="1.4.0"
+Eclipse-BuddyPolicy: registered
diff --git a/org.eclipse.riena.communication.publisher.hessian/build.properties b/org.eclipse.riena.communication.publisher.hessian/build.properties
new file mode 100644
index 0000000..a935307
--- /dev/null
+++ b/org.eclipse.riena.communication.publisher.hessian/build.properties
@@ -0,0 +1,5 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ plugin.xml,\
+ .
diff --git a/org.eclipse.riena.communication.publisher.hessian/plugin.xml b/org.eclipse.riena.communication.publisher.hessian/plugin.xml
new file mode 100644
index 0000000..bac5ea0
--- /dev/null
+++ b/org.eclipse.riena.communication.publisher.hessian/plugin.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.2"?>
+<plugin>
+ <extension
+ point="org.eclipse.equinox.http.registry.servlets">
+ <servlet
+ alias="/hessian"
+ class="org.eclipse.riena.communication.publisher.hessian.HessianRienaDispatcherServlet"
+ load-on-startup="true">
+ </servlet>
+ </extension>
+
+</plugin>
diff --git a/org.eclipse.riena.communication.publisher.hessian/src/org/eclipse/riena/communication/publisher/hessian/HessianRienaDispatcherServlet.java b/org.eclipse.riena.communication.publisher.hessian/src/org/eclipse/riena/communication/publisher/hessian/HessianRienaDispatcherServlet.java
new file mode 100644
index 0000000..ae1cf53
--- /dev/null
+++ b/org.eclipse.riena.communication.publisher.hessian/src/org/eclipse/riena/communication/publisher/hessian/HessianRienaDispatcherServlet.java
@@ -0,0 +1,149 @@
+/*******************************************************************************
+ * 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.communication.publisher.hessian;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.GenericServlet;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.eclipse.riena.communication.core.RemoteServiceDescription;
+import org.eclipse.riena.internal.communication.publisher.hessian.Activator;
+import org.eclipse.riena.internal.communication.publisher.hessian.HessianRemoteServicePublisher;
+import org.eclipse.riena.internal.communication.publisher.hessian.MessageContext;
+import org.eclipse.riena.internal.communication.publisher.hessian.MessageContextAccessor;
+
+import com.caucho.hessian.io.AbstractHessianOutput;
+import com.caucho.hessian.io.Hessian2Input;
+import com.caucho.hessian.io.Hessian2Output;
+import com.caucho.hessian.io.HessianOutput;
+import com.caucho.hessian.io.SerializerFactory;
+import com.caucho.hessian.server.HessianSkeleton;
+
+/**
+ * @author Christian Campo
+ *
+ */
+@SuppressWarnings("serial")
+public class HessianRienaDispatcherServlet extends GenericServlet {
+
+ private SerializerFactory serializerFactory = new SerializerFactory();
+
+ @Override
+ public void init(ServletConfig config) throws ServletException {
+ super.init(config);
+ log("HessianRienaDispatcherServlet:: DEBUG initialized");
+ }
+
+ @Override
+ public void log(String message) {
+ System.out.println(message);
+ }
+
+ public void log(String message, Exception e) {
+ System.out.println(message + "(" + e.getMessage() + ")");
+ }
+
+ @Override
+ public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
+
+ HttpServletRequest httpReq = (HttpServletRequest) req;
+ HttpServletResponse httpRes = (HttpServletResponse) res;
+
+ // set the message context
+ MessageContextAccessor.setMessageContext(new MessageContext(httpReq, httpRes));
+
+ HessianRemoteServicePublisher publisher = getPublisher();
+ if (publisher == null) {
+ if (httpReq.getMethod().equals("GET")) {
+ if (httpReq.getRemoteHost().equals("127.0.0.1")) {
+ PrintWriter pw = new PrintWriter(res.getOutputStream());
+ pw.write(new String("no webservices available"));
+ pw.flush();
+ return;
+ } else {
+ httpRes.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "Hessian requires POST");
+ return;
+ }
+ } else {
+ httpRes.sendError(HttpServletResponse.SC_NOT_FOUND, "webservice not found");
+ return;
+ }
+ }
+ String requestURI = httpReq.getRequestURI();
+ String contextPath = httpReq.getContextPath();
+ if (contextPath.length()>1) {
+ requestURI = requestURI.substring(contextPath.length());
+ }
+ RemoteServiceDescription rsd = publisher.findService(requestURI);
+ log("call " + rsd);
+ if (httpReq.getMethod().equals("GET")) {
+ if (httpReq.getRemoteHost().equals("127.0.0.1")) {
+ PrintWriter pw = new PrintWriter(res.getOutputStream());
+ if (rsd == null) {
+ pw.write("call received from browser, no remote service registered with this URL");
+ } else {
+ pw.write(new String("calls ") + rsd);
+ }
+ pw.flush();
+ return;
+ } else {
+ httpRes.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "Hessian requires POST");
+ return;
+ }
+ }
+ if (rsd==null) {
+ httpRes.sendError(HttpServletResponse.SC_NOT_FOUND,"unknown url :"+httpReq.getRequestURI());
+ return;
+ }
+ Object instance = rsd.getService();
+ HessianSkeleton sk = new HessianSkeleton(instance, rsd.getServiceInterfaceClass());
+ Hessian2Input inp = new Hessian2Input(httpReq.getInputStream());
+ AbstractHessianOutput out;
+ inp.setSerializerFactory(serializerFactory);
+
+ int code = inp.read();
+ if (code != 'c') {
+ throw new IOException("expected 'c' in hessian input at " + code);
+ }
+ int major = inp.read();
+ // int minor = inp.read();
+ inp.read(); // TODO obsolete?? (replaced line above)
+ if (major >= 2) {
+ out = new Hessian2Output(httpRes.getOutputStream());
+ } else {
+ out = new HessianOutput(httpRes.getOutputStream());
+ }
+
+ out.setSerializerFactory(serializerFactory);
+
+ try {
+ sk.invoke(inp, out);
+ } catch (Throwable t) {
+ throw new ServletException(t);
+ }
+ }
+
+ /**
+ *
+ * @return the publisher
+ */
+ protected HessianRemoteServicePublisher getPublisher() {
+ return Activator.getPublisher();
+ }
+
+}
diff --git a/org.eclipse.riena.communication.publisher.hessian/src/org/eclipse/riena/internal/communication/publisher/hessian/Activator.java b/org.eclipse.riena.communication.publisher.hessian/src/org/eclipse/riena/internal/communication/publisher/hessian/Activator.java
new file mode 100644
index 0000000..e42be20
--- /dev/null
+++ b/org.eclipse.riena.communication.publisher.hessian/src/org/eclipse/riena/internal/communication/publisher/hessian/Activator.java
@@ -0,0 +1,75 @@
+/*******************************************************************************
+ * 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.publisher.hessian;
+
+import java.util.Hashtable;
+
+import org.eclipse.riena.communication.core.publisher.IServicePublisher;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator implements BundleActivator {
+ private static BundleContext CONTEXT;
+ private ServiceRegistration publisherReg;
+ private static HessianRemoteServicePublisher publisher;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ CONTEXT = context;
+ System.out.println("start hessian support on server");
+
+ publisher = new HessianRemoteServicePublisher();
+ Hashtable<String, Object> properties = new Hashtable<String, Object>(1);
+ properties.put(IServicePublisher.PROP_PROTOCOL, publisher.getProtocol());
+ publisherReg = context.registerService(IServicePublisher.ID, publisher, properties);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ publisherReg.unregister();
+ publisherReg = null;
+ publisher = null;
+
+ CONTEXT = null;
+ System.out.println("stop hessian support on server");
+ }
+
+ public static BundleContext getContext() {
+ return CONTEXT;
+ }
+
+ /**
+ *
+ * @return the publisher or null if the bundle is stopped
+ */
+ public static HessianRemoteServicePublisher getPublisher() {
+ return publisher;
+ }
+}
diff --git a/org.eclipse.riena.communication.publisher.hessian/src/org/eclipse/riena/internal/communication/publisher/hessian/HessianRemoteServicePublisher.java b/org.eclipse.riena.communication.publisher.hessian/src/org/eclipse/riena/internal/communication/publisher/hessian/HessianRemoteServicePublisher.java
new file mode 100644
index 0000000..bfd3b9f
--- /dev/null
+++ b/org.eclipse.riena.communication.publisher.hessian/src/org/eclipse/riena/internal/communication/publisher/hessian/HessianRemoteServicePublisher.java
@@ -0,0 +1,109 @@
+/*******************************************************************************
+ * 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.publisher.hessian;
+
+import java.net.Inet4Address;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+
+import org.eclipse.riena.communication.core.RemoteServiceDescription;
+import org.eclipse.riena.communication.core.hooks.IServiceMessageContext;
+import org.eclipse.riena.communication.core.hooks.IServiceMessageContextAccessor;
+import org.eclipse.riena.communication.core.publisher.IServicePublisher;
+
+/**
+ * This is a Hessian based implementation of {@link IServicePublisher}. it publish or unpublish OSGi Services as
+ * service end points for Hessian protocol.
+ * <p>
+ * HessianRemoteServicePublisher becomes registered as OSGi Service with name {@link IServicePublisher#ID}. The OSGi
+ * Service set the property "riena.protocol=hessian".
+ *
+ * @author Alexander Ziegler
+ * @author Christian Campo
+ *
+ */
+public class HessianRemoteServicePublisher implements IServicePublisher {
+ private final static String PROTOCOL = "hessian";
+ private final static String SERVLET_PATH = "/hessian";
+ private IServiceMessageContextAccessor mca = new MsgCxtAcc();
+
+ private HashMap<String, RemoteServiceDescription> webServiceDescriptions;
+
+ public HessianRemoteServicePublisher() {
+ webServiceDescriptions = new HashMap<String, RemoteServiceDescription>();
+ }
+
+ public void log(String message) {
+ System.out.println(message);
+ }
+
+ public void log(String message, Exception e) {
+ System.out.println(message + "(" + e.getMessage() + ")");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see xeval.rcplabs.hessianx.server.IWebServicePublisher#publishService(RemoteServiceDescription rsd )
+ */
+ public synchronized String publishService(RemoteServiceDescription rsd) {
+ String localhost = "localhost";
+ try {
+ localhost = Inet4Address.getLocalHost().getHostAddress();
+ } catch (UnknownHostException e) {
+ }
+ String url = "http://" + localhost + SERVLET_PATH + rsd.getPath();
+ rsd.setURL(url);
+ webServiceDescriptions.put(SERVLET_PATH + rsd.getPath(), rsd);
+ log("Riena:Communication::HessianRemoteServicePublisher:: DEBUG: published web service. " + rsd);
+ log("Riena:Communication::HessianRemoteServicePublisher:: DEBUG: web service count: " + webServiceDescriptions.size());
+ return url;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see xeval.rcplabs.hessianx.server.IWebServicePublisher#unpublishService(java.lang.String)
+ */
+ public synchronized void unpublishService(String path) {
+ RemoteServiceDescription rsd = webServiceDescriptions.remove(SERVLET_PATH + path);
+ log("Riena:communication::HessianRemoteServicePublisher:: DEBUG: unpublished web service. " + rsd);
+ log("Riena:communication::HessianRemoteServicePublisher:: DEBUG: web service count: " + webServiceDescriptions.size());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.riena.communication.core.IRemoteServiceProtocol#getProtocol()
+ */
+ public String getProtocol() {
+ return PROTOCOL;
+ }
+
+ public synchronized RemoteServiceDescription findService(String requestURI) {
+ RemoteServiceDescription rsd = webServiceDescriptions.get(requestURI);
+ return rsd;
+ }
+
+ public IServiceMessageContextAccessor getMessageContextAccessor() {
+ return mca;
+ }
+
+ class MsgCxtAcc implements IServiceMessageContextAccessor {
+ MsgCxtAcc() {
+ super();
+ }
+
+ public IServiceMessageContext getMessageContext() {
+ return MessageContextAccessor.getMessageContext();
+ }
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.riena.communication.publisher.hessian/src/org/eclipse/riena/internal/communication/publisher/hessian/MessageContext.java b/org.eclipse.riena.communication.publisher.hessian/src/org/eclipse/riena/internal/communication/publisher/hessian/MessageContext.java
new file mode 100644
index 0000000..e1a1d1a
--- /dev/null
+++ b/org.eclipse.riena.communication.publisher.hessian/src/org/eclipse/riena/internal/communication/publisher/hessian/MessageContext.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * 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.publisher.hessian;
+
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.eclipse.riena.communication.core.hooks.IServiceMessageContext;
+
+public class MessageContext implements IServiceMessageContext {
+
+ private HttpServletRequest httpReq;
+ private HttpServletResponse httpRes;
+
+ public MessageContext(HttpServletRequest httpReq, HttpServletResponse httpRes) {
+ this.httpReq = httpReq;
+ this.httpRes = httpRes;
+ }
+
+ public List<String> getRequestHeaderValue(String name) {
+ Enumeration<String> enumeration = httpReq.getHeaders(name);
+ ArrayList<String> hValues = new ArrayList<String>();
+ while (enumeration.hasMoreElements()) {
+ String value = enumeration.nextElement();
+ hValues.add(value);
+ }
+ return hValues;
+ }
+
+ public Map<String, List<String>> listRequestHeaders() {
+ Map<String, List<String>> headers = new HashMap<String, List<String>>();
+ Enumeration<String> enumHeaders = httpReq.getHeaderNames();
+ while (enumHeaders.hasMoreElements()) {
+ String name = enumHeaders.nextElement();
+ Enumeration<String> enumeration = httpReq.getHeaders(name);
+ ArrayList<String> hValues = new ArrayList<String>();
+ headers.put(name, hValues);
+ while (enumeration.hasMoreElements()) {
+ String value = enumeration.nextElement();
+ hValues.add(value);
+ }
+ }
+ return headers;
+ }
+
+ public void addResponseHeader(String name, String value) {
+ httpRes.addHeader(name, value);
+ }
+
+}
diff --git a/org.eclipse.riena.communication.publisher.hessian/src/org/eclipse/riena/internal/communication/publisher/hessian/MessageContextAccessor.java b/org.eclipse.riena.communication.publisher.hessian/src/org/eclipse/riena/internal/communication/publisher/hessian/MessageContextAccessor.java
new file mode 100644
index 0000000..3f3823e
--- /dev/null
+++ b/org.eclipse.riena.communication.publisher.hessian/src/org/eclipse/riena/internal/communication/publisher/hessian/MessageContextAccessor.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * 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.publisher.hessian;
+
+/**
+ * @author [user:firstname] [user:lastname]
+ *
+ */
+public class MessageContextAccessor {
+
+ private static ThreadLocal<MessageContext> messageContexts = new ThreadLocal<MessageContext>();
+
+ public static MessageContext getMessageContext() {
+ return messageContexts.get();
+ }
+
+ public static void setMessageContext(MessageContext msgCtx) {
+ messageContexts.set(msgCtx);
+ }
+
+}