Author: rmannibucau
Date: Tue Jul  9 09:52:40 2013
New Revision: 1501172

URL: http://svn.apache.org/r1501172
Log:
TOMEE-1000 openejb-hessian module - cdi integration + client through an 
HessianInitialContext

Added:
    
tomee/tomee/trunk/server/openejb-hessian/src/main/java/org/apache/openejb/cdi/
    
tomee/tomee/trunk/server/openejb-hessian/src/main/java/org/apache/openejb/cdi/api/
    
tomee/tomee/trunk/server/openejb-hessian/src/main/java/org/apache/openejb/cdi/api/Hessian.java
    
tomee/tomee/trunk/server/openejb-hessian/src/main/java/org/apache/openejb/cdi/internal/
    
tomee/tomee/trunk/server/openejb-hessian/src/main/java/org/apache/openejb/cdi/internal/HessianExtension.java
    
tomee/tomee/trunk/server/openejb-hessian/src/main/java/org/apache/openejb/client/
    
tomee/tomee/trunk/server/openejb-hessian/src/main/java/org/apache/openejb/client/hessian/
    
tomee/tomee/trunk/server/openejb-hessian/src/main/java/org/apache/openejb/client/hessian/HessianInitialContextFactory.java
    
tomee/tomee/trunk/server/openejb-hessian/src/main/resources/META-INF/services/
    
tomee/tomee/trunk/server/openejb-hessian/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
    
tomee/tomee/trunk/server/openejb-hessian/src/test/java/org/apache/openejb/server/hessian/HessianCdiTest.java
      - copied, changed from r1500981, 
tomee/tomee/trunk/server/openejb-hessian/src/test/java/org/apache/openejb/server/hessian/HessianServiceTest.java
    
tomee/tomee/trunk/server/openejb-hessian/src/test/java/org/apache/openejb/server/hessian/HessianInitialContextTest.java
      - copied, changed from r1500981, 
tomee/tomee/trunk/server/openejb-hessian/src/test/java/org/apache/openejb/server/hessian/HessianServiceTest.java
Modified:
    
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/cdi/OpenEJBLifecycle.java
    
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/WebContext.java
    
tomee/tomee/trunk/server/openejb-hessian/src/main/java/org/apache/openejb/server/hessian/HessianServer.java
    
tomee/tomee/trunk/server/openejb-hessian/src/main/java/org/apache/openejb/server/hessian/HessianService.java
    
tomee/tomee/trunk/server/openejb-hessian/src/test/java/org/apache/openejb/server/hessian/HessianServiceTest.java

Modified: 
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/cdi/OpenEJBLifecycle.java
URL: 
http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/cdi/OpenEJBLifecycle.java?rev=1501172&r1=1501171&r2=1501172&view=diff
==============================================================================
--- 
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/cdi/OpenEJBLifecycle.java
 (original)
+++ 
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/cdi/OpenEJBLifecycle.java
 Tue Jul  9 09:52:40 2013
@@ -19,6 +19,7 @@ package org.apache.openejb.cdi;
 import org.apache.openejb.AppContext;
 import org.apache.openejb.BeanContext;
 import org.apache.openejb.OpenEJBRuntimeException;
+import org.apache.openejb.assembler.classic.AppInfo;
 import org.apache.openejb.assembler.classic.Assembler;
 import org.apache.openejb.loader.SystemInstance;
 import org.apache.openejb.util.LogCategory;
@@ -56,6 +57,7 @@ import java.util.concurrent.TimeUnit;
  * @version $Rev:$ $Date:$
  */
 public class OpenEJBLifecycle implements ContainerLifecycle {
+    public static final ThreadLocal<AppInfo> CURRENT_APP_INFO = new 
ThreadLocal<AppInfo>();
 
     //Logger instance
     private static final Logger logger = 
Logger.getInstance(LogCategory.OPENEJB_CDI, OpenEJBLifecycle.class);
@@ -178,11 +180,16 @@ public class OpenEJBLifecycle implements
                 //Scan
                 this.scannerService.scan();
 
+                // just to let us write custom CDI Extension using our 
internals easily
+                
CURRENT_APP_INFO.set(StartupObject.class.cast(startupObject).getAppInfo());
+
                 //Deploy bean from XML. Also configures deployments, 
interceptors, decorators.
                 deployer.deploy(scannerService);
             } catch (Exception e1) {
                 Assembler.logger.error("CDI Beans module deployment failed", 
e1);
                 throw new OpenEJBRuntimeException(e1);
+            } finally {
+                CURRENT_APP_INFO.remove();
             }
 
             for (final BeanContext bc : stuff.getBeanContexts()) {

Modified: 
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/WebContext.java
URL: 
http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/WebContext.java?rev=1501172&r1=1501171&r2=1501172&view=diff
==============================================================================
--- 
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/WebContext.java
 (original)
+++ 
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/WebContext.java
 Tue Jul  9 09:52:40 2013
@@ -187,7 +187,7 @@ public class WebContext {
                 || 
ServletRequestAttributeListener.class.isAssignableFrom(beanClass);
     }
 
-    private WebBeansContext getWebBeansContext() {
+    public WebBeansContext getWebBeansContext() {
         if (webbeansContext == null) {
             return getAppContext().getWebBeansContext();
         }

Added: 
tomee/tomee/trunk/server/openejb-hessian/src/main/java/org/apache/openejb/cdi/api/Hessian.java
URL: 
http://svn.apache.org/viewvc/tomee/tomee/trunk/server/openejb-hessian/src/main/java/org/apache/openejb/cdi/api/Hessian.java?rev=1501172&view=auto
==============================================================================
--- 
tomee/tomee/trunk/server/openejb-hessian/src/main/java/org/apache/openejb/cdi/api/Hessian.java
 (added)
+++ 
tomee/tomee/trunk/server/openejb-hessian/src/main/java/org/apache/openejb/cdi/api/Hessian.java
 Tue Jul  9 09:52:40 2013
@@ -0,0 +1,32 @@
+/*
+ *     Licensed to the Apache Software Foundation (ASF) under one or more
+ *     contributor license agreements.  See the NOTICE file distributed with
+ *     this work for additional information regarding copyright ownership.
+ *     The ASF licenses this file to You under the Apache License, Version 2.0
+ *     (the "License"); you may not use this file except in compliance with
+ *     the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *     Unless required by applicable law or agreed to in writing, software
+ *     distributed under the License is distributed on an "AS IS" BASIS,
+ *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *     See the License for the specific language governing permissions and
+ *     limitations under the License.
+ */
+package org.apache.openejb.cdi.api;
+
+import com.caucho.hessian.io.SerializerFactory;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Hessian {
+    String path() default "";
+    boolean sendCollectionType() default true;
+    Class<? extends SerializerFactory> serializerFactory() default 
SerializerFactory.class;
+}

Added: 
tomee/tomee/trunk/server/openejb-hessian/src/main/java/org/apache/openejb/cdi/internal/HessianExtension.java
URL: 
http://svn.apache.org/viewvc/tomee/tomee/trunk/server/openejb-hessian/src/main/java/org/apache/openejb/cdi/internal/HessianExtension.java?rev=1501172&view=auto
==============================================================================
--- 
tomee/tomee/trunk/server/openejb-hessian/src/main/java/org/apache/openejb/cdi/internal/HessianExtension.java
 (added)
+++ 
tomee/tomee/trunk/server/openejb-hessian/src/main/java/org/apache/openejb/cdi/internal/HessianExtension.java
 Tue Jul  9 09:52:40 2013
@@ -0,0 +1,179 @@
+/*
+ *     Licensed to the Apache Software Foundation (ASF) under one or more
+ *     contributor license agreements.  See the NOTICE file distributed with
+ *     this work for additional information regarding copyright ownership.
+ *     The ASF licenses this file to You under the Apache License, Version 2.0
+ *     (the "License"); you may not use this file except in compliance with
+ *     the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *     Unless required by applicable law or agreed to in writing, software
+ *     distributed under the License is distributed on an "AS IS" BASIS,
+ *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *     See the License for the specific language governing permissions and
+ *     limitations under the License.
+ */
+package org.apache.openejb.cdi.internal;
+
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.openejb.AppContext;
+import org.apache.openejb.OpenEJBRuntimeException;
+import org.apache.openejb.assembler.classic.AppInfo;
+import org.apache.openejb.cdi.OpenEJBLifecycle;
+import org.apache.openejb.cdi.api.Hessian;
+import org.apache.openejb.core.WebContext;
+import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.server.hessian.HessianRegistry;
+import org.apache.openejb.server.hessian.HessianServer;
+import org.apache.openejb.server.hessian.HessianService;
+import org.apache.openejb.spi.ContainerSystem;
+import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.container.BeanManagerImpl;
+import org.apache.webbeans.container.InjectableBeanManager;
+
+import javax.enterprise.context.Dependent;
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.AfterDeploymentValidation;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.BeforeShutdown;
+import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.inject.spi.ProcessBean;
+import javax.enterprise.inject.spi.ProcessSessionBean;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.logging.Logger;
+
+public class HessianExtension implements Extension {
+    private static final Logger LOGGER = 
Logger.getLogger(HessianExtension.class.getName());
+
+    private final Collection<Pair<Class<?>, Bean<?>>> toDeploy = new 
ArrayList<Pair<Class<?>, Bean<?>>>();
+    private final Collection<DeployedEndpoint> deployed = new 
ArrayList<DeployedEndpoint>();
+
+    protected <X> void findHessianWebServices(final @Observes ProcessBean<X> 
processBean) {
+        if (ProcessSessionBean.class.isInstance(processBean)) {
+            return;
+        }
+
+        final Bean<X> bean = processBean.getBean();
+        for (final Class<?> itf : bean.getBeanClass().getInterfaces()) {
+            final Hessian hessian = itf.getAnnotation(Hessian.class);
+            if (hessian != null) {
+                toDeploy.add(new ImmutablePair<Class<?>, Bean<?>>(itf, bean));
+            }
+        }
+    }
+
+    protected void deploy(final @Observes AfterDeploymentValidation 
afterDeploymentValidation, final BeanManager bm) {
+        final HessianService service = 
SystemInstance.get().getComponent(HessianService.class);
+        if (service == null) {
+            LOGGER.severe("HessianService not yet started, no hessian CDI 
webservices will be deployed");
+            return;
+        }
+
+        final HessianRegistry registry = service.getRegistry();
+
+        for (final Pair<Class<?>, Bean<?>> pair : toDeploy) {
+            final Class<?> itf = pair.getKey();
+            final Hessian hessian = itf.getAnnotation(Hessian.class);
+            final Bean<?> bean = pair.getValue();
+            final HessianServer server = new 
HessianServer(bean.getBeanClass().getClassLoader());
+            try {
+                if 
(!hessian.serializerFactory().isInstance(server.getSerializerFactory())) {
+                    
server.serializerFactory(hessian.serializerFactory().newInstance());
+                }
+            } catch (final Exception e) {
+                throw new OpenEJBRuntimeException(e);
+            }
+            server.sendCollectionType(hessian.sendCollectionType());
+            if (Dependent.class.equals(bean.getScope())) {
+                LOGGER.warning("@Dependent can lead to memory leaks ATM");
+            }
+            server.createSkeleton(bm.getReference(bean, itf, null), itf);
+
+            final String name = getName(itf);
+            final String appName = findAppName(bm);
+            try {
+                LOGGER.info("Hessian(url=" + 
registry.deploy(itf.getClassLoader(), server,
+                        service.getVirtualHost(), appName,
+                        service.getAuthMethod(), 
service.getTransportGuarantee(),
+                        service.getRealmName(), name) + ", interface=" + name 
+ ")");
+                deployed.add(new DeployedEndpoint(appName, name));
+            } catch (final URISyntaxException e) {
+                throw new OpenEJBRuntimeException(e);
+            }
+        }
+        toDeploy.clear();
+    }
+
+    private static String findAppName(final BeanManager bm) {
+        final AppInfo currentApp = OpenEJBLifecycle.CURRENT_APP_INFO.get();
+        if (currentApp == null) {
+            throw new IllegalStateException("Without OpenEJBLifecycle this 
Extension can't work correctly");
+        }
+
+        if (currentApp.webAppAlone) {
+            return currentApp.webApps.iterator().next().contextRoot;
+        }
+
+        for (final AppContext app : 
SystemInstance.get().getComponent(ContainerSystem.class).getAppContexts()) {
+            for (final WebContext webContext : app.getWebContexts()) {
+                if (isSameContext(bm, webContext.getWebBeansContext())) {
+                    String contextRoot = webContext.getContextRoot();
+                    if (contextRoot != null) {
+                        if (contextRoot.startsWith("/")) {
+                            return contextRoot.substring(1);
+                        }
+                        return contextRoot;
+                    }
+                    return webContext.getId();
+                }
+            }
+            if (isSameContext(bm, app.getWebBeansContext())) {
+                return app.getId();
+            }
+        }
+        throw new IllegalArgumentException("Can't find application matching 
bean manager " + bm);
+    }
+
+    private static boolean isSameContext(final BeanManager bm, WebBeansContext 
app) {
+        return InjectableBeanManager.class.isInstance(bm) && app == 
InjectableBeanManager.class.cast(bm).getWebBeansContext()
+                || BeanManagerImpl.class.isInstance(bm) && app == 
BeanManagerImpl.class.cast(bm).getWebBeansContext();
+    }
+
+    protected void shutdown(final @Observes BeforeShutdown unused) {
+        final HessianService service = 
SystemInstance.get().getComponent(HessianService.class);
+        if (service == null) {
+            return;
+        }
+
+        final HessianRegistry registry = service.getRegistry();
+        for (final DeployedEndpoint pair : deployed) {
+            registry.undeploy(service.getVirtualHost(), pair.app, pair.name);
+            LOGGER.info("Undeployed CDI hessian service " + pair.name);
+        }
+        deployed.clear();
+    }
+
+    private static String getName(final Class<?> itf) {
+        final Hessian hessian = itf.getAnnotation(Hessian.class);
+        final String name = hessian.path();
+        if (name.isEmpty()) {
+            return itf.getName();
+        }
+        return name;
+    }
+
+    protected static class DeployedEndpoint {
+        private final String app;
+        private final String name;
+
+        protected DeployedEndpoint(final String app, final String name) {
+            this.app = app;
+            this.name = name;
+        }
+    }
+}

Added: 
tomee/tomee/trunk/server/openejb-hessian/src/main/java/org/apache/openejb/client/hessian/HessianInitialContextFactory.java
URL: 
http://svn.apache.org/viewvc/tomee/tomee/trunk/server/openejb-hessian/src/main/java/org/apache/openejb/client/hessian/HessianInitialContextFactory.java?rev=1501172&view=auto
==============================================================================
--- 
tomee/tomee/trunk/server/openejb-hessian/src/main/java/org/apache/openejb/client/hessian/HessianInitialContextFactory.java
 (added)
+++ 
tomee/tomee/trunk/server/openejb-hessian/src/main/java/org/apache/openejb/client/hessian/HessianInitialContextFactory.java
 Tue Jul  9 09:52:40 2013
@@ -0,0 +1,123 @@
+/*
+ *     Licensed to the Apache Software Foundation (ASF) under one or more
+ *     contributor license agreements.  See the NOTICE file distributed with
+ *     this work for additional information regarding copyright ownership.
+ *     The ASF licenses this file to You under the Apache License, Version 2.0
+ *     (the "License"); you may not use this file except in compliance with
+ *     the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *     Unless required by applicable law or agreed to in writing, software
+ *     distributed under the License is distributed on an "AS IS" BASIS,
+ *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *     See the License for the specific language governing permissions and
+ *     limitations under the License.
+ */
+package org.apache.openejb.client.hessian;
+
+import com.caucho.hessian.client.HessianProxyFactory;
+import com.caucho.hessian.io.SerializerFactory;
+import org.apache.openejb.OpenEJBRuntimeException;
+import org.apache.openejb.core.ivm.naming.ContextWrapper;
+
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.NamingException;
+import javax.naming.spi.InitialContextFactory;
+import java.util.Hashtable;
+
+public class HessianInitialContextFactory implements InitialContextFactory {
+    public static final String API = "openejb.hessian.client.api";
+    public static final String FORCE_SERIALIZABLE = 
"openejb.hessian.client.force-serializable";
+    public static final String CHUNKED = "openejb.hessian.client.chunked";
+    public static final String DEBUG = "openejb.hessian.client.debug";
+    public static final String READ_TIMEOUT = 
"openejb.hessian.client.read-timeout";
+    public static final String CONNECT_TIMEOUT = 
"openejb.hessian.client.connect-timeout";
+
+    @Override
+    public Context getInitialContext(final Hashtable<?, ?> environment) throws 
NamingException {
+        return new HessianContext(environment);
+    }
+
+    private static class HessianContext extends ContextWrapper {
+        private final Hashtable<?, ?> environment;
+        private final ClassLoader loader;
+        private final String url;
+        private final Class<?> api;
+        private final boolean allowNonSerializable;
+        private final String user;
+        private final String password;
+        private final boolean chunked;
+        private final boolean debug;
+        private final int readTimeout;
+        private final int connectTimeout;
+
+        public HessianContext(final Hashtable<?, ?> environment) {
+            super(null); // will lead to NPE if used but shouldn't be used in 
practise
+            this.environment = environment;
+
+            String baseUrl = 
String.class.cast(environment.get(Context.PROVIDER_URL));
+            if (baseUrl == null) {
+                throw new IllegalArgumentException("provider url should be 
set");
+            }
+            if (!baseUrl.endsWith("/")) {
+                baseUrl += '/';
+            }
+
+            this.url = baseUrl;
+
+            this.loader = Thread.currentThread().getContextClassLoader();
+            this.user = 
String.class.cast(environment.get(Context.SECURITY_PRINCIPAL));
+            this.password = 
String.class.cast(environment.get(Context.SECURITY_CREDENTIALS));
+            this.allowNonSerializable = environment.get(FORCE_SERIALIZABLE) == 
null || !"true".equals(String.class.cast(environment.get(FORCE_SERIALIZABLE)));
+            this.chunked = environment.get(CHUNKED) == null || 
"true".equals(String.class.cast(environment.get(CHUNKED)));
+            this.debug = 
"true".equals(String.class.cast(environment.get(DEBUG)));
+            this.readTimeout = environment.get(READ_TIMEOUT) == null ? -1 : 
Integer.parseInt(String.class.cast(environment.get(READ_TIMEOUT)));
+            this.connectTimeout = environment.get(CONNECT_TIMEOUT) == null ? 
-1 : Integer.parseInt(String.class.cast(environment.get(CONNECT_TIMEOUT)));
+
+            final String apiClassname = 
String.class.cast(environment.get(API));
+            if (apiClassname != null) {
+                try {
+                    api = loader.loadClass(apiClassname);
+                } catch (final ClassNotFoundException e) {
+                    throw new OpenEJBRuntimeException(e);
+                }
+            } else {
+                api = null;
+            }
+        }
+
+        @Override
+        public Object lookup(final Name name) throws NamingException {
+            return lookup(name.toString());
+        }
+
+        @Override
+        public Object lookup(final String name) throws NamingException {
+            final HessianProxyFactory clientFactory = new 
HessianProxyFactory(loader);
+            final SerializerFactory factory = new SerializerFactory(loader);
+            factory.setAllowNonSerializable(allowNonSerializable);
+            clientFactory.setSerializerFactory(factory);
+            if (user != null) {
+                clientFactory.setUser(user);
+                clientFactory.setPassword(password);
+            }
+            clientFactory.setChunkedPost(chunked);
+            clientFactory.setDebug(debug);
+            clientFactory.setReadTimeout(readTimeout);
+            clientFactory.setConnectTimeout(connectTimeout);
+
+            final String completeUrl = url + name;
+            try {
+                if (api != null) { // just use it
+                    return clientFactory.create(api, completeUrl, loader);
+                }
+
+                return clientFactory.create(completeUrl); // will do a remote 
call to get the api
+            } catch (final Exception e) {
+                throw new NamingException(e.getMessage());
+            }
+        }
+    }
+}

Modified: 
tomee/tomee/trunk/server/openejb-hessian/src/main/java/org/apache/openejb/server/hessian/HessianServer.java
URL: 
http://svn.apache.org/viewvc/tomee/tomee/trunk/server/openejb-hessian/src/main/java/org/apache/openejb/server/hessian/HessianServer.java?rev=1501172&r1=1501171&r2=1501172&view=diff
==============================================================================
--- 
tomee/tomee/trunk/server/openejb-hessian/src/main/java/org/apache/openejb/server/hessian/HessianServer.java
 (original)
+++ 
tomee/tomee/trunk/server/openejb-hessian/src/main/java/org/apache/openejb/server/hessian/HessianServer.java
 Tue Jul  9 09:52:40 2013
@@ -71,6 +71,10 @@ public class HessianServer {
         return this;
     }
 
+    public SerializerFactory getSerializerFactory() {
+        return serializerFactory;
+    }
+
     public void invoke(final InputStream inputStream, final OutputStream 
outputStream) throws Throwable {
         InputStream isToUse = inputStream;
         OutputStream osToUse = outputStream;

Modified: 
tomee/tomee/trunk/server/openejb-hessian/src/main/java/org/apache/openejb/server/hessian/HessianService.java
URL: 
http://svn.apache.org/viewvc/tomee/tomee/trunk/server/openejb-hessian/src/main/java/org/apache/openejb/server/hessian/HessianService.java?rev=1501172&r1=1501171&r2=1501172&view=diff
==============================================================================
--- 
tomee/tomee/trunk/server/openejb-hessian/src/main/java/org/apache/openejb/server/hessian/HessianService.java
 (original)
+++ 
tomee/tomee/trunk/server/openejb-hessian/src/main/java/org/apache/openejb/server/hessian/HessianService.java
 Tue Jul  9 09:52:40 2013
@@ -70,11 +70,11 @@ public class HessianService implements S
                 continue;
             }
 
-            final HessianServer server = new 
HessianServer(beanContext.getClassLoader())
-                        .debug(debug)
-                        .sendCollectionType(sendCollectionType);
+            final HessianServer server = new 
HessianServer(beanContext.getClassLoader()).debug(debug);
             if (serializerFactory != null) {
-                server.serializerFactory(serializerFactory);
+                
server.serializerFactory(serializerFactory).sendCollectionType(sendCollectionType);
+            } else {
+                server.sendCollectionType(sendCollectionType);
             }
             server.createSkeleton(ProxyEJB.simpleProxy(beanContext, new 
Class<?>[]{ remoteItf }), remoteItf);
 
@@ -89,7 +89,19 @@ public class HessianService implements S
     @Override
     public void start() throws ServiceException {
         SystemInstance.get().addObserver(this);
-        registry = SystemInstance.get().getComponent(HessianRegistry.class);
+        SystemInstance.get().setComponent(HessianService.class, this);
+        registry = setRegistry();
+
+        final Assembler assembler = 
SystemInstance.get().getComponent(Assembler.class);
+        if (assembler != null) {
+            for (final AppInfo appInfo : assembler.getDeployedApplications()) {
+                afterApplicationCreated(new 
AssemblerAfterApplicationCreated(appInfo, 
SystemInstance.get().getComponent(ContainerSystem.class).getAppContext(appInfo.appId).getBeanContexts()));
+            }
+        }
+    }
+
+    private HessianRegistry setRegistry() {
+        HessianRegistry registry = 
SystemInstance.get().getComponent(HessianRegistry.class);
         if (registry == null) {
             try { // if tomcat
                 
HessianService.class.getClassLoader().loadClass("org.apache.catalina.Context");
@@ -103,13 +115,11 @@ public class HessianService implements S
             }
             SystemInstance.get().setComponent(HessianRegistry.class, registry);
         }
+        return registry;
+    }
 
-        final Assembler assembler = 
SystemInstance.get().getComponent(Assembler.class);
-        if (assembler != null) {
-            for (final AppInfo appInfo : assembler.getDeployedApplications()) {
-                afterApplicationCreated(new 
AssemblerAfterApplicationCreated(appInfo, 
SystemInstance.get().getComponent(ContainerSystem.class).getAppContext(appInfo.appId).getBeanContexts()));
-            }
-        }
+    public HessianRegistry getRegistry() {
+        return registry;
     }
 
     @Override
@@ -153,7 +163,7 @@ public class HessianService implements S
         }
     }
 
-    private static String appName(final AppInfo app, final BeanContext 
beanContext) {
+    public static String appName(final AppInfo app, final BeanContext 
beanContext) {
         if (!app.webApps.isEmpty()) {
             for (final EjbJarInfo ejbJar : app.ejbJars) {
                 for (final EnterpriseBeanInfo bean : ejbJar.enterpriseBeans) {
@@ -183,6 +193,62 @@ public class HessianService implements S
         return -1;
     }
 
+    public boolean isDisabled() {
+        return disabled;
+    }
+
+    public void setDisabled(final boolean disabled) {
+        this.disabled = disabled;
+    }
+
+    public boolean isDebug() {
+        return debug;
+    }
+
+    public void setDebug(final boolean debug) {
+        this.debug = debug;
+    }
+
+    public boolean isSendCollectionType() {
+        return sendCollectionType;
+    }
+
+    public void setSendCollectionType(final boolean sendCollectionType) {
+        this.sendCollectionType = sendCollectionType;
+    }
+
+    public String getRealmName() {
+        return realmName;
+    }
+
+    public void setRealmName(final String realmName) {
+        this.realmName = realmName;
+    }
+
+    public String getVirtualHost() {
+        return virtualHost;
+    }
+
+    public void setVirtualHost(final String virtualHost) {
+        this.virtualHost = virtualHost;
+    }
+
+    public String getTransportGuarantee() {
+        return transportGuarantee;
+    }
+
+    public void setTransportGuarantee(final String transportGuarantee) {
+        this.transportGuarantee = transportGuarantee;
+    }
+
+    public String getAuthMethod() {
+        return authMethod;
+    }
+
+    public void setAuthMethod(final String authMethod) {
+        this.authMethod = authMethod;
+    }
+
     @Override
     public void init(final Properties props) throws Exception {
         disabled = Boolean.parseBoolean(props.getProperty("disabled", 
"false"));

Added: 
tomee/tomee/trunk/server/openejb-hessian/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
URL: 
http://svn.apache.org/viewvc/tomee/tomee/trunk/server/openejb-hessian/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension?rev=1501172&view=auto
==============================================================================
--- 
tomee/tomee/trunk/server/openejb-hessian/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
 (added)
+++ 
tomee/tomee/trunk/server/openejb-hessian/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
 Tue Jul  9 09:52:40 2013
@@ -0,0 +1 @@
+org.apache.openejb.cdi.internal.HessianExtension

Copied: 
tomee/tomee/trunk/server/openejb-hessian/src/test/java/org/apache/openejb/server/hessian/HessianCdiTest.java
 (from r1500981, 
tomee/tomee/trunk/server/openejb-hessian/src/test/java/org/apache/openejb/server/hessian/HessianServiceTest.java)
URL: 
http://svn.apache.org/viewvc/tomee/tomee/trunk/server/openejb-hessian/src/test/java/org/apache/openejb/server/hessian/HessianCdiTest.java?p2=tomee/tomee/trunk/server/openejb-hessian/src/test/java/org/apache/openejb/server/hessian/HessianCdiTest.java&p1=tomee/tomee/trunk/server/openejb-hessian/src/test/java/org/apache/openejb/server/hessian/HessianServiceTest.java&r1=1500981&r2=1501172&rev=1501172&view=diff
==============================================================================
--- 
tomee/tomee/trunk/server/openejb-hessian/src/test/java/org/apache/openejb/server/hessian/HessianServiceTest.java
 (original)
+++ 
tomee/tomee/trunk/server/openejb-hessian/src/test/java/org/apache/openejb/server/hessian/HessianCdiTest.java
 Tue Jul  9 09:52:40 2013
@@ -1,27 +1,49 @@
+/*
+ *     Licensed to the Apache Software Foundation (ASF) under one or more
+ *     contributor license agreements.  See the NOTICE file distributed with
+ *     this work for additional information regarding copyright ownership.
+ *     The ASF licenses this file to You under the Apache License, Version 2.0
+ *     (the "License"); you may not use this file except in compliance with
+ *     the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *     Unless required by applicable law or agreed to in writing, software
+ *     distributed under the License is distributed on an "AS IS" BASIS,
+ *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *     See the License for the specific language governing permissions and
+ *     limitations under the License.
+ */
 package org.apache.openejb.server.hessian;
 
 import com.caucho.hessian.client.HessianProxyFactory;
 import com.caucho.hessian.io.SerializerFactory;
+import org.apache.openejb.cdi.api.Hessian;
+import org.apache.openejb.jee.WebApp;
 import org.apache.openejb.junit.ApplicationComposer;
+import org.apache.openejb.testing.Classes;
 import org.apache.openejb.testing.EnableServices;
 import org.apache.openejb.testing.Module;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
-import javax.ejb.Remote;
-import javax.ejb.Singleton;
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import java.beans.Beans;
 import java.net.MalformedURLException;
 
 import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertThat;
 
 @EnableServices({ "hessian", "httpejbd" })
 @RunWith(ApplicationComposer.class)
-public class HessianServiceTest {
+public class HessianCdiTest {
     @Module
-    public Class<?>[] classes() {
-        return new Class<?>[] { MyHessianWebService.class };
+    @Classes(cdi = true, value = { MyCdiHessianService.class, CdiBean.class })
+    public WebApp webApp() {
+        return new WebApp().contextRoot("web");
     }
 
     @Test
@@ -31,22 +53,26 @@ public class HessianServiceTest {
         final SerializerFactory factory = new SerializerFactory(loader);
         factory.setAllowNonSerializable(true);
         clientFactory.setSerializerFactory(factory);
-        final HessianWebService client = 
HessianWebService.class.cast(clientFactory.create(HessianWebService.class, 
"http://127.0.0.1:4204/HessianServiceTest/hessian/"; + 
MyHessianWebService.class.getSimpleName()));
+        final CdiService client = 
CdiService.class.cast(clientFactory.create(CdiService.class, 
"http://127.0.0.1:4204/web/hessian/service";));
 
         final Out out = client.call(new In("test"));
         assertThat(out, instanceOf(Out.class));
         assertEquals("test", out.value);
     }
 
-    @Remote
-    public static interface HessianWebService {
-        Out call(In  in);
+    @Hessian(path = "service")
+    public static interface CdiService {
+        Out call(In in);
     }
 
-    @Singleton
-    public static class MyHessianWebService implements HessianWebService {
+    @ApplicationScoped
+    public static class MyCdiHessianService implements CdiService {
+        @Inject
+        private CdiBean bean;
+
         @Override
         public Out call(final In in) {
+            assertNotNull(bean);
             return new Out(in.value);
         }
     }
@@ -66,4 +92,8 @@ public class HessianServiceTest {
             this.value = value;
         }
     }
+
+    public static class CdiBean {
+
+    }
 }

Copied: 
tomee/tomee/trunk/server/openejb-hessian/src/test/java/org/apache/openejb/server/hessian/HessianInitialContextTest.java
 (from r1500981, 
tomee/tomee/trunk/server/openejb-hessian/src/test/java/org/apache/openejb/server/hessian/HessianServiceTest.java)
URL: 
http://svn.apache.org/viewvc/tomee/tomee/trunk/server/openejb-hessian/src/test/java/org/apache/openejb/server/hessian/HessianInitialContextTest.java?p2=tomee/tomee/trunk/server/openejb-hessian/src/test/java/org/apache/openejb/server/hessian/HessianInitialContextTest.java&p1=tomee/tomee/trunk/server/openejb-hessian/src/test/java/org/apache/openejb/server/hessian/HessianServiceTest.java&r1=1500981&r2=1501172&rev=1501172&view=diff
==============================================================================
--- 
tomee/tomee/trunk/server/openejb-hessian/src/test/java/org/apache/openejb/server/hessian/HessianServiceTest.java
 (original)
+++ 
tomee/tomee/trunk/server/openejb-hessian/src/test/java/org/apache/openejb/server/hessian/HessianInitialContextTest.java
 Tue Jul  9 09:52:40 2013
@@ -1,16 +1,33 @@
+/*
+ *     Licensed to the Apache Software Foundation (ASF) under one or more
+ *     contributor license agreements.  See the NOTICE file distributed with
+ *     this work for additional information regarding copyright ownership.
+ *     The ASF licenses this file to You under the Apache License, Version 2.0
+ *     (the "License"); you may not use this file except in compliance with
+ *     the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *     Unless required by applicable law or agreed to in writing, software
+ *     distributed under the License is distributed on an "AS IS" BASIS,
+ *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *     See the License for the specific language governing permissions and
+ *     limitations under the License.
+ */
 package org.apache.openejb.server.hessian;
 
-import com.caucho.hessian.client.HessianProxyFactory;
-import com.caucho.hessian.io.SerializerFactory;
+import org.apache.openejb.client.hessian.HessianInitialContextFactory;
 import org.apache.openejb.junit.ApplicationComposer;
 import org.apache.openejb.testing.EnableServices;
 import org.apache.openejb.testing.Module;
+import org.apache.openejb.testng.PropertiesBuilder;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
 import javax.ejb.Remote;
 import javax.ejb.Singleton;
-import java.net.MalformedURLException;
+import javax.naming.Context;
+import javax.naming.InitialContext;
 
 import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.junit.Assert.assertEquals;
@@ -18,20 +35,20 @@ import static org.junit.Assert.assertTha
 
 @EnableServices({ "hessian", "httpejbd" })
 @RunWith(ApplicationComposer.class)
-public class HessianServiceTest {
+public class HessianInitialContextTest {
     @Module
     public Class<?>[] classes() {
-        return new Class<?>[] { MyHessianWebService.class };
+        return new Class<?>[] { Server.class };
     }
 
     @Test
-    public void client() throws MalformedURLException {
-        final ClassLoader loader = 
Thread.currentThread().getContextClassLoader();
-        final HessianProxyFactory clientFactory = new 
HessianProxyFactory(loader);
-        final SerializerFactory factory = new SerializerFactory(loader);
-        factory.setAllowNonSerializable(true);
-        clientFactory.setSerializerFactory(factory);
-        final HessianWebService client = 
HessianWebService.class.cast(clientFactory.create(HessianWebService.class, 
"http://127.0.0.1:4204/HessianServiceTest/hessian/"; + 
MyHessianWebService.class.getSimpleName()));
+    public void client() throws Exception {
+        final MyApi client = MyApi.class.cast(
+                new InitialContext(new PropertiesBuilder()
+                        .p(Context.INITIAL_CONTEXT_FACTORY, 
HessianInitialContextFactory.class.getName())
+                        .p(Context.PROVIDER_URL, 
"http://127.0.0.1:4204/HessianInitialContextTest/hessian/";)
+                        .build())
+                    .lookup("Server"));
 
         final Out out = client.call(new In("test"));
         assertThat(out, instanceOf(Out.class));
@@ -39,12 +56,12 @@ public class HessianServiceTest {
     }
 
     @Remote
-    public static interface HessianWebService {
-        Out call(In  in);
+    public static interface MyApi {
+        Out call(In in);
     }
 
     @Singleton
-    public static class MyHessianWebService implements HessianWebService {
+    public static class Server implements MyApi {
         @Override
         public Out call(final In in) {
             return new Out(in.value);
@@ -54,7 +71,7 @@ public class HessianServiceTest {
     public static class In {
         private String value;
 
-        public In(String value) {
+        public In(final String value) {
             this.value = value;
         }
     }
@@ -62,7 +79,7 @@ public class HessianServiceTest {
     public static class Out {
         private String value;
 
-        public Out(String value) {
+        public Out(final String value) {
             this.value = value;
         }
     }

Modified: 
tomee/tomee/trunk/server/openejb-hessian/src/test/java/org/apache/openejb/server/hessian/HessianServiceTest.java
URL: 
http://svn.apache.org/viewvc/tomee/tomee/trunk/server/openejb-hessian/src/test/java/org/apache/openejb/server/hessian/HessianServiceTest.java?rev=1501172&r1=1501171&r2=1501172&view=diff
==============================================================================
--- 
tomee/tomee/trunk/server/openejb-hessian/src/test/java/org/apache/openejb/server/hessian/HessianServiceTest.java
 (original)
+++ 
tomee/tomee/trunk/server/openejb-hessian/src/test/java/org/apache/openejb/server/hessian/HessianServiceTest.java
 Tue Jul  9 09:52:40 2013
@@ -1,3 +1,19 @@
+/*
+ *     Licensed to the Apache Software Foundation (ASF) under one or more
+ *     contributor license agreements.  See the NOTICE file distributed with
+ *     this work for additional information regarding copyright ownership.
+ *     The ASF licenses this file to You under the Apache License, Version 2.0
+ *     (the "License"); you may not use this file except in compliance with
+ *     the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *     Unless required by applicable law or agreed to in writing, software
+ *     distributed under the License is distributed on an "AS IS" BASIS,
+ *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *     See the License for the specific language governing permissions and
+ *     limitations under the License.
+ */
 package org.apache.openejb.server.hessian;
 
 import com.caucho.hessian.client.HessianProxyFactory;


Reply via email to