summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntje Fuhrmann2012-10-30 05:36:52 (EDT)
committerSven Rottstock2012-10-30 05:36:52 (EDT)
commitda5e379408187d58a889a52b9ff6b436f06447aa (patch)
tree8918e7e6eb0adfd784ac11f19e39229f3f4ca97b
parent36b6f33b64cb7e78876e0a296a38a51235fbc656 (diff)
downloadorg.eclipse.stardust.engine-da5e379408187d58a889a52b9ff6b436f06447aa.zip
org.eclipse.stardust.engine-da5e379408187d58a889a52b9ff6b436f06447aa.tar.gz
org.eclipse.stardust.engine-da5e379408187d58a889a52b9ff6b436f06447aa.tar.bz2
Jira-ID: CRNT-26329
Client cannot connect to engine in EJB stateless setup with tunneling service configuration git-svn-id: http://emeafrazerg/svn/ipp/product/trunk/stardust/engine@60394 8100b5e0-4d52-466c-ae9c-bdeccbdeaf6b
-rw-r--r--stardust-engine-core/src/main/java/org/eclipse/stardust/engine/api/ejb2/TunnelingSessionFactory.java172
1 files changed, 172 insertions, 0 deletions
diff --git a/stardust-engine-core/src/main/java/org/eclipse/stardust/engine/api/ejb2/TunnelingSessionFactory.java b/stardust-engine-core/src/main/java/org/eclipse/stardust/engine/api/ejb2/TunnelingSessionFactory.java
new file mode 100644
index 0000000..e662269
--- /dev/null
+++ b/stardust-engine-core/src/main/java/org/eclipse/stardust/engine/api/ejb2/TunnelingSessionFactory.java
@@ -0,0 +1,172 @@
+/*******************************************************************************
+ * Copyright (c) 2012 SunGard CSA LLC 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:
+ * SunGard CSA LLC - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+package org.eclipse.stardust.engine.api.ejb2;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.rmi.RemoteException;
+import java.util.Map;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+
+import org.eclipse.stardust.common.Pair;
+import org.eclipse.stardust.common.error.ApplicationException;
+import org.eclipse.stardust.common.error.InternalException;
+import org.eclipse.stardust.common.error.PublicException;
+import org.eclipse.stardust.common.log.LogUtils;
+import org.eclipse.stardust.common.utils.ejb.EJBUtils;
+import org.eclipse.stardust.engine.api.ejb2.SecureSessionFactory;
+import org.eclipse.stardust.engine.api.ejb2.TunnelingAwareSecureSessionFactory;
+import org.eclipse.stardust.engine.api.ejb2.WorkflowException;
+import org.eclipse.stardust.engine.api.ejb2.tunneling.TunneledContext;
+import org.eclipse.stardust.engine.api.ejb2.tunneling.TunnelingService;
+import org.eclipse.stardust.engine.api.ejb2.tunneling.TunnelingUtils;
+import org.eclipse.stardust.engine.api.runtime.ServiceNotAvailableException;
+import org.eclipse.stardust.engine.core.runtime.beans.removethis.SecurityProperties;
+
+/**
+ * @author Florin.Herinean
+ */
+public class TunnelingSessionFactory
+ implements SecureSessionFactory, TunnelingAwareSecureSessionFactory
+{
+
+ public Object get(String jndiName, @SuppressWarnings("rawtypes") Class homeClass,
+ @SuppressWarnings("rawtypes") Class remoteClass,
+ @SuppressWarnings("rawtypes") Class[] creationArgTypes,
+ final Object[] creationArgs, @SuppressWarnings("rawtypes") Map credentials,
+ @SuppressWarnings("rawtypes") Map properties)
+ {
+ SecureSession result = getSecureSession(jndiName, homeClass, remoteClass,
+ creationArgTypes, creationArgs, credentials, properties);
+
+ if (null != result.tunneledContext)
+ {
+ // no way to propagate tunneled context via old contract
+ throw new ServiceNotAvailableException(
+ "Service is only available for tunneling invocations, but service factory does not seem to be aware.");
+ }
+
+ return result.endpoint;
+ }
+
+ public SecureSession getSecureSession(String jndiName,
+ @SuppressWarnings("rawtypes") Class homeClass,
+ @SuppressWarnings("rawtypes") Class remoteClass,
+ @SuppressWarnings("rawtypes") Class[] creationArgTypes, Object[] creationArgs,
+ @SuppressWarnings("rawtypes") Map credentials,
+ @SuppressWarnings("rawtypes") Map properties)
+ throws ServiceNotAvailableException
+ {
+ Object endpoint = null;
+
+ TunneledContext tunneledContext = null;
+
+ // first obtain the service.
+ try
+ {
+ Context context = EJBUtils.getInitialContext(false, false);
+ Object rawHome = context.lookup(jndiName);
+ LogUtils.traceObject(rawHome, false);
+
+ @SuppressWarnings("unchecked")
+ Pair<Class< ? >, Object> tunnelingHome = TunnelingUtils
+ .castToTunnelingRemoteServiceHome(rawHome, homeClass);
+ if (tunnelingHome != null)
+ {
+ homeClass = tunnelingHome.getFirst();
+ Object home = tunnelingHome.getSecond();
+ LogUtils.traceObject(homeClass, false);
+ @SuppressWarnings("unchecked")
+ Method creationMethod = homeClass.getMethod("create", creationArgTypes);
+ endpoint = creationMethod.invoke(home, creationArgs);
+ LogUtils.traceObject(endpoint, false);
+ }
+ else
+ {
+ // tunneling could not be enabled
+ throw new ClassCastException("Could not cast " + rawHome.getClass() + " to "
+ + homeClass);
+ }
+ }
+ catch (InvocationTargetException e)
+ {
+ ApplicationException ex = getRootException(e.getTargetException());
+ throw new ServiceNotAvailableException(ex.getMessage(), ex);
+ }
+ catch (NamingException e)
+ {
+ throw new ServiceNotAvailableException(e.getMessage(), e);
+ }
+ catch (Exception e)
+ {
+ throw new InternalException("Failed to create session bean.", e);
+ }
+
+ // now attempt to login
+ try
+ {
+ if (endpoint instanceof TunnelingService)
+ {
+ tunneledContext = TunnelingUtils.performTunnelingLogin(
+ (TunnelingService) endpoint,
+ (String) credentials.get(SecurityProperties.CRED_USER),
+ (String) credentials.get(SecurityProperties.CRED_PASSWORD), properties);
+ }
+ else
+ {
+ Method loginMethod = endpoint.getClass().getMethod("login",
+ new Class[] {String.class, String.class, Map.class});
+ loginMethod.invoke(
+ endpoint,
+ new Object[] {
+ credentials.get(SecurityProperties.CRED_USER),
+ credentials.get(SecurityProperties.CRED_PASSWORD), properties});
+ }
+ }
+ catch (InvocationTargetException e)
+ {
+ throw getRootException(e.getTargetException());
+ }
+ catch (Exception e)
+ {
+ throw new InternalException("Failed to create session bean.", e);
+ }
+
+ return new SecureSession(endpoint, tunneledContext);
+ }
+
+ private ApplicationException getRootException(Throwable source)
+ {
+ while (source instanceof RemoteException)
+ {
+ if (((RemoteException) source).detail == null)
+ {
+ return new InternalException(source);
+ }
+ source = ((RemoteException) source).detail;
+ }
+ if (source instanceof WorkflowException)
+ {
+ source = ((WorkflowException) source).getCause();
+ if (source instanceof PublicException)
+ {
+ throw (PublicException) source;
+ }
+ }
+ if (source instanceof ApplicationException)
+ {
+ return (ApplicationException) source;
+ }
+ throw new InternalException(source.getMessage(), source);
+ }
+} \ No newline at end of file