[jboss-cvs] JBossAS SVN: r86173 - in projects/ejb3/trunk/remoting2: src/main/java/org/jboss/ejb3/remoting/endpoint and 9 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sat Mar 21 08:04:35 EDT 2009
Author: wolfc
Date: 2009-03-21 08:04:35 -0400 (Sat, 21 Mar 2009)
New Revision: 86173
Added:
projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/endpoint/MethodHelper.java
projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/endpoint/client/RemoteContextData.java
projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/clientinterceptor/
projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/clientinterceptor/Current.java
projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/clientinterceptor/InterceptedMockRemotable.java
projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/clientinterceptor/Interceptor.java
projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/clientinterceptor/InterceptorInvocationHandler.java
projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/clientinterceptor/NoopInterceptor.java
projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/clientinterceptor/SimpleInterceptorClientSide.java
projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/clientinterceptor/SimpleInterceptorServerSide.java
projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/clientinterceptor/unit/
projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/clientinterceptor/unit/ClientInterceptorTestCase.java
projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/common/AbstractRemotingTestCaseSetup.java
projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/common/RemoteKernelController.java
projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/common/RemoteKernelControllerImpl.java
Modified:
projects/ejb3/trunk/remoting2/.classpath
projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/endpoint/RemotableEndpoint.java
projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/endpoint/client/RemoteInvocationHandlerInvocationHandler.java
projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/spi/Remotable.java
projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting2/EJB3ServerInvocationHandler.java
projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/common/MockRemotable.java
projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/simple/unit/SimpleRemotingTestCase.java
projects/ejb3/trunk/remoting2/src/test/resources/META-INF/jboss-beans.xml
Log:
EJBTHREE-1779: removed the businessInterface argument from RemotableEndpoint (it's in SerializableMethod) and made a proof of concept for client side interceptors
Modified: projects/ejb3/trunk/remoting2/.classpath
===================================================================
--- projects/ejb3/trunk/remoting2/.classpath 2009-03-21 11:51:33 UTC (rev 86172)
+++ projects/ejb3/trunk/remoting2/.classpath 2009-03-21 12:04:35 UTC (rev 86173)
@@ -1,8 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="src" path="src/main/java"/>
- <classpathentry kind="src" path="src/test/java" output="eclipse-target/tests-classes"/>
- <classpathentry kind="src" path="src/test/resources" output="eclipse-target/tests-classes" excluding="**/*.java"/>
- <classpathentry kind="output" path="eclipse-target/classes"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
- <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
-</classpath>
\ No newline at end of file
+ <classpathentry kind="src" path="src/main/java"/>
+ <classpathentry kind="src" output="eclipse-target/tests-classes" path="src/test/java"/>
+ <classpathentry excluding="**/*.java" kind="src" output="eclipse-target/tests-classes" path="src/test/resources"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.5.0_15"/>
+ <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+ <classpathentry kind="output" path="eclipse-target/classes"/>
+</classpath>
Added: projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/endpoint/MethodHelper.java
===================================================================
--- projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/endpoint/MethodHelper.java (rev 0)
+++ projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/endpoint/MethodHelper.java 2009-03-21 12:04:35 UTC (rev 86173)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.remoting.endpoint;
+
+import java.lang.reflect.Method;
+
+/**
+ * Unexposed MethodHelper
+ *
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+class MethodHelper
+{
+ static Method getMethod(Class<?> cls, String methodName, Class<?>... parameterTypes)
+ {
+ try
+ {
+ return cls.getDeclaredMethod(methodName, parameterTypes);
+ }
+ catch (SecurityException e)
+ {
+ throw new RuntimeException(e);
+ }
+ catch (NoSuchMethodException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+}
Modified: projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/endpoint/RemotableEndpoint.java
===================================================================
--- projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/endpoint/RemotableEndpoint.java 2009-03-21 11:51:33 UTC (rev 86172)
+++ projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/endpoint/RemotableEndpoint.java 2009-03-21 12:04:35 UTC (rev 86173)
@@ -22,17 +22,31 @@
package org.jboss.ejb3.remoting.endpoint;
import java.io.Serializable;
+import java.lang.reflect.Method;
import java.util.Map;
import org.jboss.ejb3.common.lang.SerializableMethod;
/**
- * An endpoint that only takes serializable parameters.
+ * An endpoint that only takes serializable parameters. This is one level higher that a Remotable,
+ * because now we know the target implements RemotableEndpoint.
*
* @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
* @version $Revision: $
*/
public interface RemotableEndpoint
{
- Object invoke(Serializable session, Map<?, ?> context, Class<?> invokedBusinessInterface, SerializableMethod method, Object args[]) throws Throwable;
+ Method INVOKE_METHOD = MethodHelper.getMethod(RemotableEndpoint.class, "invoke", Serializable.class, Map.class, SerializableMethod.class, Object[].class);
+
+ /**
+ * The invokedBusinessInterface is method.actualClass
+ *
+ * @param session
+ * @param contextData
+ * @param method
+ * @param args
+ * @return
+ * @throws Throwable
+ */
+ Object invoke(Serializable session, Map<String, Object> contextData, SerializableMethod method, Object args[]) throws Throwable;
}
Added: projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/endpoint/client/RemoteContextData.java
===================================================================
--- projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/endpoint/client/RemoteContextData.java (rev 0)
+++ projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/endpoint/client/RemoteContextData.java 2009-03-21 12:04:35 UTC (rev 86173)
@@ -0,0 +1,59 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.remoting.endpoint.client;
+
+import java.util.Map;
+
+/**
+ * TODO: This doesn't belong here, because it's a contract with InterceptorInvocationHandler.
+ *
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class RemoteContextData
+{
+ private static ThreadLocal<Map<String, Object>> contextData = new ThreadLocal<Map<String, Object>>();
+
+ public static void cleanContextData()
+ {
+ Map<String, Object> current = contextData.get();
+ if(current == null)
+ throw new IllegalStateException("no context data found");
+ contextData.remove();
+ }
+
+ public static Map<String, Object> getContextData()
+ {
+ Map<String, Object> current = contextData.get();
+ if(current == null)
+ throw new IllegalStateException("no context data found");
+ return current;
+ }
+
+ public static void setContextData(Map<String, Object> value)
+ {
+ Map<String, Object> previous = contextData.get();
+ if(previous != null)
+ throw new IllegalStateException("found previous context data " + previous);
+ contextData.set(value);
+ }
+}
Modified: projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/endpoint/client/RemoteInvocationHandlerInvocationHandler.java
===================================================================
--- projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/endpoint/client/RemoteInvocationHandlerInvocationHandler.java 2009-03-21 11:51:33 UTC (rev 86172)
+++ projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/endpoint/client/RemoteInvocationHandlerInvocationHandler.java 2009-03-21 12:04:35 UTC (rev 86173)
@@ -30,6 +30,12 @@
import org.jboss.ejb3.remoting.endpoint.RemotableEndpoint;
/**
+ * An invocation handler which delegates to an invocation handler that handles invocations
+ * on a RemotableEndpoint.
+ *
+ * In theory you the delegate should be an RemotableEndpoint. In practice this is usually an
+ * InvocationHandler, so this class skips through immediately to that handler.
+ *
* @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
* @version $Revision: $
*/
@@ -48,11 +54,10 @@
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
{
- // FIXME: associate the necessary thread locals to the invocation
- Map<?, ?> context = null;
- Method invokeMethod = RemotableEndpoint.class.getDeclaredMethod("invoke", Serializable.class, Map.class, Class.class, SerializableMethod.class, Object[].class);
- SerializableMethod businessMethod = new SerializableMethod(method);
- Object invokeArgs[] = { session, context, invokedBusinessInterface, businessMethod, args };
+ Map<String, Object> contextData = RemoteContextData.getContextData();
+ Method invokeMethod = RemotableEndpoint.INVOKE_METHOD;
+ SerializableMethod businessMethod = new SerializableMethod(method, invokedBusinessInterface);
+ Object invokeArgs[] = { session, contextData, businessMethod, args };
return delegate.invoke(proxy, invokeMethod, invokeArgs);
}
}
Modified: projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/spi/Remotable.java
===================================================================
--- projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/spi/Remotable.java 2009-03-21 11:51:33 UTC (rev 86172)
+++ projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting/spi/Remotable.java 2009-03-21 12:04:35 UTC (rev 86173)
@@ -24,14 +24,25 @@
import java.io.Serializable;
/**
+ * Defines a wrapper for making an object remotable.
+ *
* @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
* @version $Revision: $
*/
public interface Remotable
{
+ /**
+ * The class loader with which target must be called.
+ */
ClassLoader getClassLoader();
+ /**
+ * Uniquely identifies a remotable.
+ */
Serializable getId();
+ /**
+ * The target onto which the remote invocation must take place.
+ */
Object getTarget();
}
Modified: projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting2/EJB3ServerInvocationHandler.java
===================================================================
--- projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting2/EJB3ServerInvocationHandler.java 2009-03-21 11:51:33 UTC (rev 86172)
+++ projects/ejb3/trunk/remoting2/src/main/java/org/jboss/ejb3/remoting2/EJB3ServerInvocationHandler.java 2009-03-21 12:04:35 UTC (rev 86173)
@@ -24,6 +24,7 @@
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.Arrays;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -58,9 +59,7 @@
*/
public void addListener(InvokerCallbackHandler callbackHandler)
{
- // TODO Auto-generated method stub
- //
- throw new RuntimeException("NYI");
+ // no-op
}
public void addRemotable(Remotable remotable)
@@ -77,6 +76,8 @@
{
Serializable key = (Serializable) invocation.getRequestPayload().get(OID);
Remotable remotable = remotables.get(key);
+ if(remotable == null)
+ throw new IllegalArgumentException("Can't find remotable " + key + " in " + remotables);
Object parameters[] = (Object[]) invocation.getParameter();
SerializableMethod method = (SerializableMethod) parameters[0];
@@ -89,6 +90,10 @@
Thread.currentThread().setContextClassLoader(loader);
return realMethod.invoke(remotable.getTarget(), args);
}
+ catch(IllegalArgumentException e)
+ {
+ throw new IllegalArgumentException("unable to invoke " + realMethod + " on " + remotable.getTarget() + " with " + Arrays.toString(args), e);
+ }
catch(InvocationTargetException e)
{
throw e.getCause();
@@ -104,9 +109,7 @@
*/
public void removeListener(InvokerCallbackHandler callbackHandler)
{
- // TODO Auto-generated method stub
- //
- throw new RuntimeException("NYI");
+ // no-op
}
public void removeRemotable(Remotable remotable)
Added: projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/clientinterceptor/Current.java
===================================================================
--- projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/clientinterceptor/Current.java (rev 0)
+++ projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/clientinterceptor/Current.java 2009-03-21 12:04:35 UTC (rev 86173)
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.remoting2.test.clientinterceptor;
+
+import java.io.Serializable;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class Current
+{
+ private static ThreadLocal<Serializable> state = new ThreadLocal<Serializable>();
+
+ public static Serializable getState()
+ {
+ return state.get();
+ }
+
+ public static void setState(Serializable value)
+ {
+ Current.state.set(value);
+ }
+}
Added: projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/clientinterceptor/InterceptedMockRemotable.java
===================================================================
--- projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/clientinterceptor/InterceptedMockRemotable.java (rev 0)
+++ projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/clientinterceptor/InterceptedMockRemotable.java 2009-03-21 12:04:35 UTC (rev 86173)
@@ -0,0 +1,108 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.remoting2.test.clientinterceptor;
+
+import java.io.Serializable;
+import java.lang.reflect.Method;
+import java.util.Map;
+
+import javax.interceptor.InvocationContext;
+
+import org.jboss.ejb3.common.lang.SerializableMethod;
+import org.jboss.ejb3.remoting2.test.common.MockRemotable;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+//@Interceptors(SimpleInterceptorServerSide.class)
+public class InterceptedMockRemotable extends MockRemotable
+{
+ private Interceptor interceptor = new SimpleInterceptorServerSide();
+
+ @Override
+ public Serializable getId()
+ {
+ return "InterceptedMockRemotable";
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.ejb3.remoting2.test.common.MockRemotable#invoke(java.io.Serializable, java.util.Map, org.jboss.ejb3.common.lang.SerializableMethod, java.lang.Object[])
+ */
+ @Override
+ public Object invoke(final Serializable session, final Map<String, Object> contextData, SerializableMethod method, final Object[] args)
+ throws Throwable
+ {
+ final Method realMethod = method.toMethod(getClassLoader());
+ // emulate an interception
+ InvocationContext context = new InvocationContext() {
+
+ public Map<String, Object> getContextData()
+ {
+ return contextData;
+ }
+
+ public Method getMethod()
+ {
+ return realMethod;
+ }
+
+ public Object[] getParameters()
+ {
+ return args;
+ }
+
+ public Object getTarget()
+ {
+ // TODO: for real?
+ return session;
+ }
+
+ public Object proceed() throws Exception
+ {
+ try
+ {
+ return realMethod.invoke(InterceptedMockRemotable.this, args);
+ }
+ catch(IllegalArgumentException e)
+ {
+ throw new IllegalArgumentException("can't invoke " + realMethod + " on " + this, e);
+ }
+ }
+
+ public void setParameters(Object[] params)
+ {
+ throw new RuntimeException("NYI");
+ }
+ };
+ return interceptor.invoke(context);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.ejb3.remoting2.test.common.MockRemotable#sayHi(java.lang.String)
+ */
+ @Override
+ public String sayHi(String name)
+ {
+ return "Hi " + name + " " + Current.getState();
+ }
+}
Added: projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/clientinterceptor/Interceptor.java
===================================================================
--- projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/clientinterceptor/Interceptor.java (rev 0)
+++ projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/clientinterceptor/Interceptor.java 2009-03-21 12:04:35 UTC (rev 86173)
@@ -0,0 +1,33 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.remoting2.test.clientinterceptor;
+
+import javax.interceptor.InvocationContext;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface Interceptor
+{
+ Object invoke(InvocationContext context) throws Exception;
+}
Added: projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/clientinterceptor/InterceptorInvocationHandler.java
===================================================================
--- projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/clientinterceptor/InterceptorInvocationHandler.java (rev 0)
+++ projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/clientinterceptor/InterceptorInvocationHandler.java 2009-03-21 12:04:35 UTC (rev 86173)
@@ -0,0 +1,117 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.remoting2.test.clientinterceptor;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.interceptor.InvocationContext;
+
+import org.jboss.ejb3.remoting.endpoint.client.RemoteContextData;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class InterceptorInvocationHandler implements InvocationHandler
+{
+ private InvocationHandler handler;
+ private Interceptor interceptor;
+
+ public InterceptorInvocationHandler(InvocationHandler handler, Interceptor interceptor)
+ {
+ this.handler = handler;
+ this.interceptor = interceptor;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])
+ */
+ public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable
+ {
+ final Map<String, Object> contextData = new HashMap<String, Object>();
+ InvocationContext context = new InvocationContext() {
+ private Object[] parameters = args;
+
+ public Map<String, Object> getContextData()
+ {
+ return contextData;
+ }
+
+ public Method getMethod()
+ {
+ return method;
+ }
+
+ public Object[] getParameters()
+ {
+ return args;
+ }
+
+ public Object getTarget()
+ {
+ return proxy;
+ }
+
+ public Object proceed() throws Exception
+ {
+ try
+ {
+ return handler.invoke(proxy, method, parameters);
+ }
+ catch(Error e)
+ {
+ throw e;
+ }
+ catch(RuntimeException e)
+ {
+ throw e;
+ }
+ catch(Exception e)
+ {
+ throw e;
+ }
+ catch(Throwable t)
+ {
+ // should not happen
+ throw new RuntimeException(t);
+ }
+ }
+
+ public void setParameters(Object[] params)
+ {
+ this.parameters = params;
+ }
+ };
+ RemoteContextData.setContextData(contextData);
+ try
+ {
+ return interceptor.invoke(context);
+ }
+ finally
+ {
+ RemoteContextData.cleanContextData();
+ }
+ }
+}
Added: projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/clientinterceptor/NoopInterceptor.java
===================================================================
--- projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/clientinterceptor/NoopInterceptor.java (rev 0)
+++ projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/clientinterceptor/NoopInterceptor.java 2009-03-21 12:04:35 UTC (rev 86173)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.remoting2.test.clientinterceptor;
+
+import javax.interceptor.InvocationContext;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class NoopInterceptor implements Interceptor
+{
+ public Object invoke(InvocationContext context) throws Exception
+ {
+ return context.proceed();
+ }
+}
Added: projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/clientinterceptor/SimpleInterceptorClientSide.java
===================================================================
--- projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/clientinterceptor/SimpleInterceptorClientSide.java (rev 0)
+++ projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/clientinterceptor/SimpleInterceptorClientSide.java 2009-03-21 12:04:35 UTC (rev 86173)
@@ -0,0 +1,48 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.remoting2.test.clientinterceptor;
+
+import java.io.Serializable;
+
+import javax.interceptor.InvocationContext;
+
+import org.jboss.logging.Logger;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class SimpleInterceptorClientSide implements Interceptor
+{
+ private static final Logger log = Logger.getLogger(SimpleInterceptorClientSide.class);
+
+ public static final String STATE = SimpleInterceptorClientSide.class.getName() + ".STATE";
+
+ //@AroundInvoke
+ public Object invoke(InvocationContext context) throws Exception
+ {
+ Serializable state = Current.getState();
+ log.info("setting state " + state);
+ context.getContextData().put(SimpleInterceptorClientSide.STATE, Current.getState());
+ return context.proceed();
+ }
+}
Added: projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/clientinterceptor/SimpleInterceptorServerSide.java
===================================================================
--- projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/clientinterceptor/SimpleInterceptorServerSide.java (rev 0)
+++ projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/clientinterceptor/SimpleInterceptorServerSide.java 2009-03-21 12:04:35 UTC (rev 86173)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.remoting2.test.clientinterceptor;
+
+import java.io.Serializable;
+
+import javax.interceptor.InvocationContext;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class SimpleInterceptorServerSide implements Interceptor
+{
+ //@AroundInvoke
+ public Object invoke(InvocationContext context) throws Exception
+ {
+ Current.setState((Serializable) context.getContextData().get(SimpleInterceptorClientSide.STATE));
+ return context.proceed();
+ }
+}
Added: projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/clientinterceptor/unit/ClientInterceptorTestCase.java
===================================================================
--- projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/clientinterceptor/unit/ClientInterceptorTestCase.java (rev 0)
+++ projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/clientinterceptor/unit/ClientInterceptorTestCase.java 2009-03-21 12:04:35 UTC (rev 86173)
@@ -0,0 +1,94 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.remoting2.test.clientinterceptor.unit;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.Serializable;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Proxy;
+
+import org.jboss.ejb3.remoting.endpoint.client.RemoteInvocationHandlerInvocationHandler;
+import org.jboss.ejb3.remoting2.client.RemoteInvocationHandler;
+import org.jboss.ejb3.remoting2.test.clientinterceptor.Current;
+import org.jboss.ejb3.remoting2.test.clientinterceptor.InterceptedMockRemotable;
+import org.jboss.ejb3.remoting2.test.clientinterceptor.Interceptor;
+import org.jboss.ejb3.remoting2.test.clientinterceptor.InterceptorInvocationHandler;
+import org.jboss.ejb3.remoting2.test.clientinterceptor.SimpleInterceptorClientSide;
+import org.jboss.ejb3.remoting2.test.common.AbstractRemotingTestCaseSetup;
+import org.jboss.ejb3.remoting2.test.common.MockInterface;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.InvokerLocator;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class ClientInterceptorTestCase extends AbstractRemotingTestCaseSetup
+{
+ @BeforeClass
+ public static void beforeClass() throws Throwable
+ {
+ AbstractRemotingTestCaseSetup.beforeClass();
+
+ install(InterceptedMockRemotable.class);
+ }
+
+ private <T> T createRemoteProxy(Client client, Serializable oid, Class<T> businessInterface, Interceptor interceptor)
+ {
+ RemoteInvocationHandler delegate = new RemoteInvocationHandler(client, oid);
+
+ // assume we're talking to a singleton
+ Serializable session = null;
+ InvocationHandler handler = new RemoteInvocationHandlerInvocationHandler(delegate, session, businessInterface);
+
+ handler = new InterceptorInvocationHandler(handler, interceptor);
+
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ Class<?> interfaces[] = { businessInterface };
+ return businessInterface.cast(Proxy.newProxyInstance(loader, interfaces, handler));
+ }
+
+ @Test
+ public void test1() throws Throwable
+ {
+ Interceptor interceptor = new SimpleInterceptorClientSide();
+
+ InvokerLocator locator = new InvokerLocator("socket://localhost:5783");
+ String subsystem = "EJB3_R2D2";
+
+ Client client = new Client(locator, subsystem);
+ client.setDisconnectTimeout(1);
+ client.connect();
+
+ String oid = InterceptedMockRemotable.class.getSimpleName();
+ MockInterface bean = createRemoteProxy(client, oid, MockInterface.class, interceptor);
+
+ Current.setState("something");
+
+ String result = bean.sayHi("me");
+
+ assertEquals("Hi me something", result);
+ }
+}
Added: projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/common/AbstractRemotingTestCaseSetup.java
===================================================================
--- projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/common/AbstractRemotingTestCaseSetup.java (rev 0)
+++ projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/common/AbstractRemotingTestCaseSetup.java 2009-03-21 12:04:35 UTC (rev 86173)
@@ -0,0 +1,296 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.remoting2.test.common;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Proxy;
+import java.net.ConnectException;
+import java.net.Socket;
+import java.net.UnknownHostException;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
+import org.jboss.ejb3.remoting.endpoint.client.RemoteInvocationHandlerInvocationHandler;
+import org.jboss.ejb3.remoting2.client.RemoteInvocationHandler;
+import org.jboss.ejb3.remoting2.test.clientinterceptor.InterceptedMockRemotable;
+import org.jboss.ejb3.remoting2.test.clientinterceptor.InterceptorInvocationHandler;
+import org.jboss.ejb3.remoting2.test.clientinterceptor.NoopInterceptor;
+import org.jboss.logging.Logger;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.InvokerLocator;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+import com.sun.jdi.Bootstrap;
+import com.sun.jdi.VirtualMachine;
+import com.sun.jdi.VirtualMachineManager;
+import com.sun.jdi.connect.LaunchingConnector;
+import com.sun.jdi.connect.Connector.Argument;
+import com.sun.jdi.event.EventSet;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class AbstractRemotingTestCaseSetup
+{
+ private static final Logger log = Logger.getLogger(AbstractRemotingTestCaseSetup.class);
+
+ private static VirtualMachine vm;
+ private static RemoteKernelController controller;
+
+ @AfterClass
+ public static void afterClass()
+ {
+ try
+ {
+ saveCobertura();
+ }
+ catch(Throwable t)
+ {
+ log.error("failed to save Cobertura", t);
+ }
+ vm.exit(0);
+ }
+
+ @BeforeClass
+ public static void beforeClass() throws Throwable
+ {
+ VirtualMachineManager manager = Bootstrap.virtualMachineManager();
+ LaunchingConnector connector = manager.defaultConnector();
+ Map<String, ? extends Argument> args = connector.defaultArguments();
+ for(Argument arg : args.values())
+ {
+ System.out.println(" " + arg);
+ }
+ //String cobertura = " -Dnet.sourceforge.cobertura.datafile=target/cobertura/cobertura-server.ser";
+ String cobertura = "";
+ args.get("options").setValue("-classpath " + getClassPath() + cobertura);
+ args.get("main").setValue("org.jboss.kernel.plugins.bootstrap.standalone.StandaloneBootstrap");
+ log.info(args);
+ vm = connector.launch(args);
+
+ Process p = vm.process();
+ final InputStream in = p.getInputStream();
+ Thread inputStreamReader = new Thread()
+ {
+ @Override
+ public void run()
+ {
+ try
+ {
+ int b;
+ while((b = in.read()) != -1)
+ System.out.write(b);
+ }
+ catch(IOException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ };
+ inputStreamReader.setDaemon(true);
+ inputStreamReader.start();
+
+ final InputStream err = p.getErrorStream();
+ Thread errorStreamReader = new Thread()
+ {
+ @Override
+ public void run()
+ {
+ try
+ {
+ int b;
+ while((b = err.read()) != -1)
+ System.err.write(b);
+ }
+ catch(IOException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ };
+ errorStreamReader.setDaemon(true);
+ errorStreamReader.start();
+
+ vm.resume();
+
+ // This causes an EOFException, which can be ignored.
+ waitForSocket(5783, 10, TimeUnit.SECONDS);
+
+ initRemoteKernelController();
+ }
+
+ private static String getClassPath()
+ {
+ String sureFireTestClassPath = System.getProperty("surefire.test.class.path");
+ log.debug("sureFireTestClassPath = " + sureFireTestClassPath);
+ String javaClassPath = System.getProperty("java.class.path");
+ log.debug("javaClassPath = " + javaClassPath);
+ // make sure we can run under surefire
+ String classPath = sureFireTestClassPath;
+ if(classPath == null)
+ classPath = javaClassPath;
+ log.debug("classPath = " + classPath);
+ return classPath;
+ }
+
+ private static void initRemoteKernelController() throws Exception
+ {
+ InvokerLocator locator = new InvokerLocator("socket://localhost:5783");
+ String subsystem = "EJB3_R2D2";
+
+ Client client = new Client(locator, subsystem);
+ client.setDisconnectTimeout(1);
+ client.connect();
+
+ Class<?> businessInterface = RemoteKernelController.class;
+ RemoteInvocationHandler delegate = new RemoteInvocationHandler(client, businessInterface.getName());
+
+ // RemoteKernelController is a singleton, so no session
+ Serializable session = null;
+ InvocationHandler handler = new RemoteInvocationHandlerInvocationHandler(delegate, session, businessInterface);
+
+ handler = new InterceptorInvocationHandler(handler, new NoopInterceptor());
+
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ Class<?> interfaces[] = { businessInterface };
+ controller = (RemoteKernelController) Proxy.newProxyInstance(loader, interfaces, handler);
+ }
+
+ /**
+ * Install a bean in the server.
+ * @param cls
+ */
+ protected static void install(Class<?> cls) throws Throwable
+ {
+ AbstractBeanMetaData beanMetaData = new AbstractBeanMetaData(InterceptedMockRemotable.class.getName(), InterceptedMockRemotable.class.getName());
+ controller.install(beanMetaData);
+ }
+
+ private static void waitForSocket(int port, long duration, TimeUnit unit)
+ {
+ long end = System.currentTimeMillis() + TimeUnit.MILLISECONDS.convert(duration, unit);
+ while(System.currentTimeMillis() < end)
+ {
+ try
+ {
+ Socket socket = new Socket("localhost", port);
+ socket.close();
+ return;
+ }
+ catch(ConnectException e)
+ {
+ // ignore
+ }
+ catch (UnknownHostException e)
+ {
+ throw new RuntimeException(e);
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ try
+ {
+ Thread.sleep(1000);
+ }
+ catch (InterruptedException e)
+ {
+ return;
+ }
+ }
+ }
+
+ private static void saveCobertura() throws InterruptedException
+ {
+ controller.dumpCobertura();
+ /*
+ String className = "net.sourceforge.cobertura.coveragedata.ProjectData";
+ String methodName = "saveGlobalProjectData";
+
+ vm.eventQueue().remove(1);
+ vm.setDebugTraceMode(VirtualMachine.TRACE_ALL);
+
+ List<ThreadReference> threads = vm.allThreads();
+ System.out.println(threads);
+ ThreadReference thread = threads.get(2);
+ System.out.println(thread);
+ //thread.suspend();
+ vm.suspend();
+ StepRequest stepRequest = vm.eventRequestManager().createStepRequest(thread, StepRequest.STEP_LINE, StepRequest.STEP_OVER);
+ stepRequest.addCountFilter(1);
+ //stepRequest.addClassFilter("*");
+ //stepRequest.setSuspendPolicy(StepRequest.SUSPEND_EVENT_THREAD);
+ stepRequest.enable();
+
+ System.out.println(vm.eventRequestManager().stepRequests());
+ vm.resume();
+ thread.interrupt();
+
+ waitForEvent();
+ //thread.suspend();
+
+ List<ReferenceType> classes = vm.classesByName(className);
+ if(classes.size() == 0)
+ {
+ log.info("Cobertura was not found");
+ return;
+ }
+ ClassType cls = (ClassType) classes.get(0);
+ List<Method> methods = cls.methodsByName(methodName);
+ Method method = methods.get(0);
+ List<? extends Value> arguments = new ArrayList<Value>();
+ int options = 0;
+ try {
+ cls.invokeMethod(thread, method, arguments, options);
+ log.info("Cobertura data successfully saved");
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+ */
+ }
+
+ private static void waitForEvent()
+ {
+ long end = System.currentTimeMillis() + 5000;
+ while(System.currentTimeMillis() < end)
+ {
+ EventSet events;
+ try
+ {
+ events = vm.eventQueue().remove(end - System.currentTimeMillis());
+ }
+ catch(InterruptedException e)
+ {
+ log.info("interrupted");
+ return;
+ }
+ System.out.println(events);
+ }
+ throw new IllegalStateException();
+ }
+}
Modified: projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/common/MockRemotable.java
===================================================================
--- projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/common/MockRemotable.java 2009-03-21 11:51:33 UTC (rev 86172)
+++ projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/common/MockRemotable.java 2009-03-21 12:04:35 UTC (rev 86173)
@@ -56,10 +56,7 @@
return "Hi " + name;
}
- /* (non-Javadoc)
- * @see org.jboss.ejb3.endpoint.Endpoint#invoke(java.io.Serializable, java.lang.Class, java.lang.reflect.Method, java.lang.Object[])
- */
- public Object invoke(Serializable session, Map<?, ?> context, Class<?> invokedBusinessInterface, SerializableMethod method, Object[] args)
+ public Object invoke(Serializable session, Map<String, Object> contextData, SerializableMethod method, Object[] args)
throws Throwable
{
Method realMethod = method.toMethod(getClassLoader());
Added: projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/common/RemoteKernelController.java
===================================================================
--- projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/common/RemoteKernelController.java (rev 0)
+++ projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/common/RemoteKernelController.java 2009-03-21 12:04:35 UTC (rev 86173)
@@ -0,0 +1,37 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.remoting2.test.common;
+
+import org.jboss.beans.metadata.spi.BeanMetaData;
+
+/**
+ * Don't ever do this on the App Server!
+ *
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface RemoteKernelController
+{
+ void dumpCobertura();
+
+ String install(BeanMetaData beanMetaData) throws Throwable;
+}
Added: projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/common/RemoteKernelControllerImpl.java
===================================================================
--- projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/common/RemoteKernelControllerImpl.java (rev 0)
+++ projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/common/RemoteKernelControllerImpl.java 2009-03-21 12:04:35 UTC (rev 86173)
@@ -0,0 +1,130 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.remoting2.test.common;
+
+import java.io.Serializable;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Map;
+
+import org.jboss.beans.metadata.api.annotations.Inject;
+import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.ejb3.common.lang.SerializableMethod;
+import org.jboss.ejb3.remoting.endpoint.RemotableEndpoint;
+import org.jboss.ejb3.remoting.spi.Remotable;
+import org.jboss.kernel.Kernel;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.logging.Logger;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class RemoteKernelControllerImpl implements RemoteKernelController, Remotable, RemotableEndpoint
+{
+ private static final Logger log = Logger.getLogger(RemoteKernelControllerImpl.class);
+
+ // make sure ProjectData is a loaded class in the server
+ static {
+ String className = "net.sourceforge.cobertura.coveragedata.ProjectData";
+ try
+ {
+ Class.forName(className);
+ log.info("Loaded Cobertura");
+ }
+ catch(ClassNotFoundException e)
+ {
+ log.info("Could not find Cobertura");
+ }
+ }
+
+ private Kernel kernel;
+
+ public void dumpCobertura()
+ {
+ try
+ {
+ String className = "net.sourceforge.cobertura.coveragedata.ProjectData";
+ String methodName = "saveGlobalProjectData";
+ Class<?> saveClass = Class.forName(className);
+ java.lang.reflect.Method saveMethod = saveClass.getDeclaredMethod(methodName, new Class[0]);
+ saveMethod.invoke(null, new Object[0]);
+ }
+ catch (Throwable t)
+ {
+ t.printStackTrace();
+ }
+ }
+
+ public String install(BeanMetaData beanMetaData) throws Throwable
+ {
+ KernelControllerContext context = kernel.getController().install(beanMetaData);
+ return (String) context.getName();
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.ejb3.remoting.spi.Remotable#getClassLoader()
+ */
+ public ClassLoader getClassLoader()
+ {
+ return RemoteKernelControllerImpl.class.getClassLoader();
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.ejb3.remoting.spi.Remotable#getId()
+ */
+ public Serializable getId()
+ {
+ return RemoteKernelController.class.getName();
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.ejb3.remoting.spi.Remotable#getTarget()
+ */
+ public Object getTarget()
+ {
+ return this;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.ejb3.remoting.endpoint.RemotableEndpoint#invoke(java.io.Serializable, java.util.Map, org.jboss.ejb3.common.lang.SerializableMethod, java.lang.Object[])
+ */
+ public Object invoke(Serializable session, Map<String, Object> contextData, SerializableMethod method, Object[] args)
+ throws Throwable
+ {
+ Method realMethod = method.toMethod(getClassLoader());
+ try
+ {
+ return realMethod.invoke(this, args);
+ }
+ catch(InvocationTargetException e)
+ {
+ throw e.getCause();
+ }
+ }
+
+ @Inject(bean="jboss.kernel:service=Kernel")
+ public void setKernel(Kernel kernel)
+ {
+ this.kernel = kernel;
+ }
+}
Modified: projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/simple/unit/SimpleRemotingTestCase.java
===================================================================
--- projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/simple/unit/SimpleRemotingTestCase.java 2009-03-21 11:51:33 UTC (rev 86172)
+++ projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/simple/unit/SimpleRemotingTestCase.java 2009-03-21 12:04:35 UTC (rev 86173)
@@ -23,132 +23,35 @@
import static org.junit.Assert.assertEquals;
-import java.io.IOException;
-import java.io.InputStream;
import java.io.Serializable;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
-import java.net.ConnectException;
-import java.net.Socket;
-import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;
-import java.util.concurrent.TimeUnit;
import org.jboss.ejb3.common.lang.SerializableMethod;
import org.jboss.ejb3.remoting.endpoint.RemotableEndpoint;
import org.jboss.ejb3.remoting.endpoint.client.RemoteInvocationHandlerInvocationHandler;
import org.jboss.ejb3.remoting2.EJB3ServerInvocationHandler;
import org.jboss.ejb3.remoting2.client.RemoteInvocationHandler;
+import org.jboss.ejb3.remoting2.test.clientinterceptor.InterceptorInvocationHandler;
+import org.jboss.ejb3.remoting2.test.clientinterceptor.NoopInterceptor;
+import org.jboss.ejb3.remoting2.test.common.AbstractRemotingTestCaseSetup;
import org.jboss.ejb3.remoting2.test.common.MockInterface;
import org.jboss.logging.Logger;
import org.jboss.remoting.Client;
import org.jboss.remoting.InvokerLocator;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
import org.junit.Test;
-import com.sun.jdi.Bootstrap;
-import com.sun.jdi.VirtualMachine;
-import com.sun.jdi.VirtualMachineManager;
-import com.sun.jdi.connect.LaunchingConnector;
-import com.sun.jdi.connect.Connector.Argument;
-
/**
* @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
* @version $Revision: $
*/
-public class SimpleRemotingTestCase
+public class SimpleRemotingTestCase extends AbstractRemotingTestCaseSetup
{
private static final Logger log = Logger.getLogger(SimpleRemotingTestCase.class);
- private static VirtualMachine vm;
-
- @AfterClass
- public static void afterClass()
- {
- vm.exit(0);
- }
-
- @BeforeClass
- public static void beforeClass() throws Exception
- {
- VirtualMachineManager manager = Bootstrap.virtualMachineManager();
- LaunchingConnector connector = manager.defaultConnector();
- Map<String, ? extends Argument> args = connector.defaultArguments();
- for(Argument arg : args.values())
- {
- System.out.println(" " + arg);
- }
- args.get("options").setValue("-classpath " + getClassPath());
- args.get("main").setValue("org.jboss.kernel.plugins.bootstrap.standalone.StandaloneBootstrap");
- System.out.println(args);
- vm = connector.launch(args);
-
- Process p = vm.process();
- final InputStream in = p.getInputStream();
- Thread inputStreamReader = new Thread()
- {
- @Override
- public void run()
- {
- try
- {
- int b;
- while((b = in.read()) != -1)
- System.out.write(b);
- }
- catch(IOException e)
- {
- e.printStackTrace();
- }
- }
- };
- inputStreamReader.setDaemon(true);
- inputStreamReader.start();
-
- final InputStream err = p.getErrorStream();
- Thread errorStreamReader = new Thread()
- {
- @Override
- public void run()
- {
- try
- {
- int b;
- while((b = err.read()) != -1)
- System.err.write(b);
- }
- catch(IOException e)
- {
- e.printStackTrace();
- }
- }
- };
- errorStreamReader.setDaemon(true);
- errorStreamReader.start();
-
- vm.resume();
-
- // This causes an EOFException, which can be ignored.
- waitForSocket(5783, 10, TimeUnit.SECONDS);
- }
-
- private static String getClassPath()
- {
- String sureFireTestClassPath = System.getProperty("surefire.test.class.path");
- log.debug("sureFireTestClassPath = " + sureFireTestClassPath);
- String javaClassPath = System.getProperty("java.class.path");
- log.debug("javaClassPath = " + javaClassPath);
- // make sure we can run under surefire
- String classPath = sureFireTestClassPath;
- if(classPath == null)
- classPath = javaClassPath;
- log.debug("classPath = " + classPath);
- return classPath;
- }
-
@Test
public void testRaw() throws Throwable
{
@@ -164,13 +67,13 @@
metadata.put(EJB3ServerInvocationHandler.OID, "MockRemotableID");
// the target of MockRemotable is RemotableEndpoint
- Method realMethod = RemotableEndpoint.class.getDeclaredMethod("invoke", Serializable.class, Map.class, Class.class, SerializableMethod.class, Object[].class);
- SerializableMethod method = new SerializableMethod(realMethod);
+ Method realMethod = RemotableEndpoint.INVOKE_METHOD;
+ SerializableMethod method = new SerializableMethod(realMethod, RemotableEndpoint.class);
Serializable session = null;
- Map<?, ?> context = null;
+ Map<String, Object> contextData = null;
// the remotable endpoint delegates to a MockInterface endpoint
- SerializableMethod businessMethod = new SerializableMethod(MockInterface.class.getDeclaredMethod("sayHi", String.class));
- Object args[] = { session, context, null, businessMethod, new Object[] { "y" } };
+ SerializableMethod businessMethod = new SerializableMethod(MockInterface.class.getDeclaredMethod("sayHi", String.class), MockInterface.class);
+ Object args[] = { session, contextData, businessMethod, new Object[] { "y" } };
Object param = new Object[] { method, args };
String result = (String) client.invoke(param, metadata);
client.disconnect();
@@ -194,6 +97,8 @@
Class<?> businessInterface = MockInterface.class;
InvocationHandler handler = new RemoteInvocationHandlerInvocationHandler(delegate, session, businessInterface);
+ handler = new InterceptorInvocationHandler(handler, new NoopInterceptor());
+
ClassLoader loader = Thread.currentThread().getContextClassLoader();
Class<?> interfaces[] = { businessInterface };
MockInterface proxy = (MockInterface) Proxy.newProxyInstance(loader, interfaces, handler);
@@ -217,45 +122,12 @@
RemotableEndpoint endpoint = (RemotableEndpoint) Proxy.newProxyInstance(loader, interfaces, handler);
Serializable session = null;
- Map<?, ?> context = null;
+ Map<String, Object> contextData = null;
// the remotable endpoint delegates to a MockInterface endpoint
- SerializableMethod businessMethod = new SerializableMethod(MockInterface.class.getDeclaredMethod("sayHi", String.class));
+ SerializableMethod businessMethod = new SerializableMethod(MockInterface.class.getDeclaredMethod("sayHi", String.class), MockInterface.class);
Object args[] = { "me" };
- String result = (String) endpoint.invoke(session, context, null, businessMethod, args);
+ String result = (String) endpoint.invoke(session, contextData, businessMethod, args);
assertEquals("Hi me", result);
}
- private static void waitForSocket(int port, long duration, TimeUnit unit)
- {
- long end = System.currentTimeMillis() + TimeUnit.MILLISECONDS.convert(duration, unit);
- while(System.currentTimeMillis() < end)
- {
- try
- {
- Socket socket = new Socket("localhost", port);
- socket.close();
- return;
- }
- catch(ConnectException e)
- {
- // ignore
- }
- catch (UnknownHostException e)
- {
- throw new RuntimeException(e);
- }
- catch (IOException e)
- {
- throw new RuntimeException(e);
- }
- try
- {
- Thread.sleep(1000);
- }
- catch (InterruptedException e)
- {
- return;
- }
- }
- }
}
Modified: projects/ejb3/trunk/remoting2/src/test/resources/META-INF/jboss-beans.xml
===================================================================
--- projects/ejb3/trunk/remoting2/src/test/resources/META-INF/jboss-beans.xml 2009-03-21 11:51:33 UTC (rev 86172)
+++ projects/ejb3/trunk/remoting2/src/test/resources/META-INF/jboss-beans.xml 2009-03-21 12:04:35 UTC (rev 86173)
@@ -21,5 +21,8 @@
<property name="serverConfiguration"><inject bean="EJB3ServerConfiguration"/></property>
</bean>
+ <!-- Don't ever do this on the App Server! -->
+ <bean name="RemoteKernelController" class="org.jboss.ejb3.remoting2.test.common.RemoteKernelControllerImpl"/>
+
<bean name="MockRemotable" class="org.jboss.ejb3.remoting2.test.common.MockRemotable"/>
</deployment>
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list