Author: rmannibucau
Date: Mon Dec  3 22:10:57 2012
New Revision: 1416698

URL: http://svn.apache.org/viewvc?rev=1416698&view=rev
Log:
TOMEE-624 finally appprefix (false context) is useless

Modified:
    
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentsResolver.java
    
openejb/trunk/openejb/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java
    
openejb/trunk/openejb/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RsRegistry.java
    
openejb/trunk/openejb/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RsRegistryImpl.java
    
openejb/trunk/openejb/tomee/tomee-jaxrs/src/main/java/org/apache/tomee/webservices/TomcatRsRegistry.java

Modified: 
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentsResolver.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentsResolver.java?rev=1416698&r1=1416697&r2=1416698&view=diff
==============================================================================
--- 
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentsResolver.java
 (original)
+++ 
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentsResolver.java
 Mon Dec  3 22:10:57 2012
@@ -17,7 +17,6 @@
 package org.apache.openejb.config;
 
 import org.apache.openejb.config.sys.Deployments;
-import org.apache.openejb.config.sys.JaxbOpenejb;
 import org.apache.openejb.loader.FileUtils;
 import org.apache.openejb.loader.Files;
 import org.apache.openejb.loader.Options;
@@ -32,12 +31,10 @@ import org.apache.xbean.finder.filter.In
 
 import java.io.File;
 import java.io.IOException;
-import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.EnumSet;
-import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;

Modified: 
openejb/trunk/openejb/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java?rev=1416698&r1=1416697&r2=1416698&view=diff
==============================================================================
--- 
openejb/trunk/openejb/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java
 (original)
+++ 
openejb/trunk/openejb/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java
 Mon Dec  3 22:10:57 2012
@@ -193,10 +193,10 @@ public abstract class RESTService implem
 
                     if (hasEjbAndIsNotAManagedBean(restEjbs, 
o.getClass().getName())) {
                         // no more a singleton if the ejb is not a 
singleton...but it is a weird case
-                        deployEJB(appPrefix, 
restEjbs.get(o.getClass().getName()).context, additionalProviders, 
appInfo.services);
+                        deployEJB(webApp.contextRoot, appPrefix, 
restEjbs.get(o.getClass().getName()).context, additionalProviders, 
appInfo.services);
                     } else {
                         pojoConfigurations = 
PojoUtil.findPojoConfig(pojoConfigurations, appInfo, webApp);
-                        deploySingleton(appPrefix, o, appInstance, 
classLoader, additionalProviders,
+                        deploySingleton(webApp.contextRoot, appPrefix, o, 
appInstance, classLoader, additionalProviders,
                                 new 
ServiceConfiguration(PojoUtil.findConfiguration(pojoConfigurations, 
o.getClass().getName()), appInfo.services));
                     }
                 }
@@ -207,10 +207,10 @@ public abstract class RESTService implem
                     }
 
                     if (hasEjbAndIsNotAManagedBean(restEjbs, clazz.getName())) 
{
-                        deployEJB(appPrefix, 
restEjbs.get(clazz.getName()).context, additionalProviders, appInfo.services);
+                        deployEJB(webApp.contextRoot, appPrefix, 
restEjbs.get(clazz.getName()).context, additionalProviders, appInfo.services);
                     } else {
                         pojoConfigurations = 
PojoUtil.findPojoConfig(pojoConfigurations, appInfo, webApp);
-                        deployPojo(appPrefix, clazz, appInstance, classLoader, 
injections, context, owbCtx, additionalProviders,
+                        deployPojo(webApp.contextRoot, appPrefix, clazz, 
appInstance, classLoader, injections, context, owbCtx, additionalProviders,
                                 new 
ServiceConfiguration(PojoUtil.findConfiguration(pojoConfigurations, 
clazz.getName()), appInfo.services));
                     }
                 }
@@ -220,6 +220,8 @@ public abstract class RESTService implem
             }
 
             if (!useApp) {
+                appPrefix = webApp.contextRoot;
+
                 final Set<String> restClasses = new 
HashSet<String>(webApp.restClass);
                 restClasses.addAll(webApp.ejbRestServices);
 
@@ -227,16 +229,16 @@ public abstract class RESTService implem
                     if (restEjbs.containsKey(clazz)) {
                         final BeanContext ctx = restEjbs.get(clazz).context;
                         if (hasEjbAndIsNotAManagedBean(restEjbs, clazz)) {
-                            deployEJB(appPrefix, restEjbs.get(clazz).context, 
additionalProviders, appInfo.services);
+                            deployEJB(webApp.contextRoot, appPrefix, 
restEjbs.get(clazz).context, additionalProviders, appInfo.services);
                         } else {
-                            deployPojo(appPrefix, ctx.getBeanClass(), null, 
ctx.getClassLoader(), ctx.getInjections(), context,
+                            deployPojo(webApp.contextRoot, appPrefix, 
ctx.getBeanClass(), null, ctx.getClassLoader(), ctx.getInjections(), context,
                                     owbCtx, additionalProviders, new 
ServiceConfiguration(ctx.getProperties(), appInfo.services));
                         }
                     } else {
                         try {
                             Class<?> loadedClazz = 
classLoader.loadClass(clazz);
                             pojoConfigurations = 
PojoUtil.findPojoConfig(pojoConfigurations, appInfo, webApp);
-                            deployPojo(appPrefix, loadedClazz, null, 
classLoader, injections, context, owbCtx,
+                            deployPojo(webApp.contextRoot, appPrefix, 
loadedClazz, null, classLoader, injections, context, owbCtx,
                                     additionalProviders,
                                     new 
ServiceConfiguration(PojoUtil.findConfiguration(pojoConfigurations, 
loadedClazz.getName()), appInfo.services));
                         } catch (ClassNotFoundException e) {
@@ -293,12 +295,12 @@ public abstract class RESTService implem
                 for (Map.Entry<String, EJBRestServiceInfo> ejb : 
restEjbs.entrySet()) {
                     final BeanContext ctx = ejb.getValue().context;
                     if (BeanType.MANAGED.equals(ctx.getComponentType())) {
-                        deployPojo(ejb.getValue().path, ctx.getBeanClass(), 
null, ctx.getClassLoader(), ctx.getInjections(),
+                        deployPojo("", ejb.getValue().path, 
ctx.getBeanClass(), null, ctx.getClassLoader(), ctx.getInjections(),
                                 ctx.getJndiContext(),
                                 
containerSystem.getAppContext(appInfo.appId).getWebBeansContext(),
                                 providers, new 
ServiceConfiguration(ctx.getProperties(), appInfo.services));
                     } else {
-                        deployEJB(ejb.getValue().path, ctx, providers, 
appInfo.services);
+                        deployEJB("", ejb.getValue().path, ctx, providers, 
appInfo.services);
                     }
                 }
                 restEjbs.clear();
@@ -351,19 +353,19 @@ public abstract class RESTService implem
         return restEjbs;
     }
 
-    private void deploySingleton(String contextRoot, Object o, Application 
appInstance, ClassLoader classLoader,
+    private void deploySingleton(String web, String contextRoot, Object o, 
Application appInstance, ClassLoader classLoader,
                                  Collection<Object> additionalProviders, 
ServiceConfiguration configuration) {
         final String nopath = getAddress(contextRoot, o.getClass());
         final RsHttpListener listener = createHttpListener();
-        final RsRegistry.AddressInfo address = 
rsRegistry.createRsHttpListener(contextRoot, listener, classLoader, 
nopath.substring(NOPATH_PREFIX.length() - 1), virtualHost);
+        final RsRegistry.AddressInfo address = 
rsRegistry.createRsHttpListener(web, listener, classLoader, 
nopath.substring(NOPATH_PREFIX.length() - 1), virtualHost);
 
-        services.add(new DeployedService(address.complete, contextRoot, 
o.getClass().getName()));
+        services.add(new DeployedService(address.complete, web, 
o.getClass().getName()));
         listener.deploySingleton(getFullContext(address.base, contextRoot), o, 
appInstance, additionalProviders, configuration);
 
         LOGGER.info("deployed REST singleton: " + o);
     }
 
-    private void deployPojo(String contextRoot, Class<?> loadedClazz, 
Application app, ClassLoader classLoader, Collection<Injection> injections,
+    private void deployPojo(String web, String contextRoot, Class<?> 
loadedClazz, Application app, ClassLoader classLoader, Collection<Injection> 
injections,
                             Context context, WebBeansContext owbCtx, 
Collection<Object> additionalProviders, ServiceConfiguration config) {
         if (loadedClazz.isInterface()) {
             return;
@@ -371,7 +373,7 @@ public abstract class RESTService implem
 
         final String nopath = getAddress(contextRoot, loadedClazz);
         final RsHttpListener listener = createHttpListener();
-        final RsRegistry.AddressInfo address = 
rsRegistry.createRsHttpListener(contextRoot, listener, classLoader, 
nopath.substring(NOPATH_PREFIX.length() - 1), virtualHost);
+        final RsRegistry.AddressInfo address = 
rsRegistry.createRsHttpListener(web, listener, classLoader, 
nopath.substring(NOPATH_PREFIX.length() - 1), virtualHost);
 
         services.add(new DeployedService(address.complete, contextRoot, 
loadedClazz.getName()));
         listener.deployPojo(getFullContext(address.base, contextRoot), 
loadedClazz, app, injections, context, owbCtx,
@@ -380,10 +382,10 @@ public abstract class RESTService implem
         LOGGER.info("REST Service: " + address.complete + "  -> Pojo " + 
loadedClazz.getName());
     }
 
-    private void deployEJB(String context, BeanContext beanContext, 
Collection<Object> additionalProviders, Collection<ServiceInfo> serviceInfos) {
+    private void deployEJB(String web, String context, BeanContext 
beanContext, Collection<Object> additionalProviders, Collection<ServiceInfo> 
serviceInfos) {
         final String nopath = getAddress(context, beanContext.getBeanClass());
         final RsHttpListener listener = createHttpListener();
-        final RsRegistry.AddressInfo address = 
rsRegistry.createRsHttpListener(context, listener, 
beanContext.getClassLoader(), nopath.substring(NOPATH_PREFIX.length() - 1), 
virtualHost);
+        final RsRegistry.AddressInfo address = 
rsRegistry.createRsHttpListener(web, listener, beanContext.getClassLoader(), 
nopath.substring(NOPATH_PREFIX.length() - 1), virtualHost);
 
         services.add(new DeployedService(address.complete, context, 
beanContext.getBeanClass().getName()));
         listener.deployEJB(getFullContext(address.base, context), beanContext,

Modified: 
openejb/trunk/openejb/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RsRegistry.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RsRegistry.java?rev=1416698&r1=1416697&r2=1416698&view=diff
==============================================================================
--- 
openejb/trunk/openejb/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RsRegistry.java
 (original)
+++ 
openejb/trunk/openejb/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RsRegistry.java
 Mon Dec  3 22:10:57 2012
@@ -22,7 +22,7 @@ import org.apache.openejb.server.httpd.H
 import java.util.List;
 
 public interface RsRegistry {
-    AddressInfo createRsHttpListener(String root, HttpListener listener, 
ClassLoader classLoader, String path, String virtualHost);
+    AddressInfo createRsHttpListener(String webContext, HttpListener listener, 
ClassLoader classLoader, String path, String virtualHost);
     HttpListener removeListener(String context);
 
     public static class AddressInfo {

Modified: 
openejb/trunk/openejb/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RsRegistryImpl.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RsRegistryImpl.java?rev=1416698&r1=1416697&r2=1416698&view=diff
==============================================================================
--- 
openejb/trunk/openejb/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RsRegistryImpl.java
 (original)
+++ 
openejb/trunk/openejb/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RsRegistryImpl.java
 Mon Dec  3 22:10:57 2012
@@ -27,16 +27,14 @@ import java.util.Map;
 public class RsRegistryImpl extends OpenEJBHttpRegistry implements RsRegistry {
     private Map<String, String> addresses = new HashMap<String, String>();
 
-    @Override
-    public AddressInfo createRsHttpListener(String root, HttpListener 
listener, ClassLoader classLoader, String path, String virtualHost) {
+    @Override public AddressInfo createRsHttpListener(String webContext, 
HttpListener listener, ClassLoader classLoader, String path, String 
virtualHost) {
         String address = 
HttpUtil.selectSingleAddress(getResolvedAddresses(path));
         addWrappedHttpListener(listener, classLoader, path);
         addresses.put(address, path);
         return new AddressInfo(address, address);
     }
 
-    @Override
-    public HttpListener removeListener(String context) {
+    @Override public HttpListener removeListener(String context) {
         String regex = addresses.get(context);
         if (regex != null) {
             HttpListener listener = registry.removeHttpListener(regex);

Modified: 
openejb/trunk/openejb/tomee/tomee-jaxrs/src/main/java/org/apache/tomee/webservices/TomcatRsRegistry.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/tomee/tomee-jaxrs/src/main/java/org/apache/tomee/webservices/TomcatRsRegistry.java?rev=1416698&r1=1416697&r2=1416698&view=diff
==============================================================================
--- 
openejb/trunk/openejb/tomee/tomee-jaxrs/src/main/java/org/apache/tomee/webservices/TomcatRsRegistry.java
 (original)
+++ 
openejb/trunk/openejb/tomee/tomee-jaxrs/src/main/java/org/apache/tomee/webservices/TomcatRsRegistry.java
 Mon Dec  3 22:10:57 2012
@@ -57,8 +57,8 @@ public class TomcatRsRegistry implements
     }
 
     @Override
-    public AddressInfo createRsHttpListener(String root, HttpListener 
listener, ClassLoader classLoader, String completePath, String virtualHost) {
-        String path = completePath;
+    public AddressInfo createRsHttpListener(String webContext, HttpListener 
listener, ClassLoader classLoader, String completePath, String virtualHost) {
+        String path = webContext;
         if (path == null) {
             throw new NullPointerException("contextRoot is null");
         }
@@ -66,27 +66,6 @@ public class TomcatRsRegistry implements
             throw new NullPointerException("listener is null");
         }
 
-        // parsing could be optimized a bit...
-        String realRoot = root;
-        if (!root.startsWith("/")) {
-            realRoot = "/" + root;
-        }
-        if (realRoot.length() > 1) {
-            int idx = realRoot.substring(1).indexOf('/');
-            if (idx > 0) {
-                realRoot = realRoot.substring(0, idx + 1);
-            }
-        }
-        if (!path.startsWith("/")) {
-            path = "/" + path;
-        }
-        if (!"/".equals(realRoot)) {
-            path = path.substring(realRoot.length(), path.length());
-        }
-        if (!path.startsWith("/")) {
-            path = "/" + path;
-        }
-
         // find the existing host (we do not auto-create hosts)
         if (virtualHost == null) virtualHost = engine.getDefaultHost();
         Container host = engine.findChild(virtualHost);
@@ -95,14 +74,14 @@ public class TomcatRsRegistry implements
         }
 
         // get the webapp context
-        Context context = (Context) host.findChild(realRoot);
+        Context context = (Context) host.findChild(webContext);
 
-        if (context == null && "/".equals(realRoot)) { // ROOT
+        if (context == null && "/".equals(webContext)) { // ROOT
             context = (Context) host.findChild("");
         }
 
         if (context == null) {
-            throw new IllegalStateException("Invalid context '" + realRoot + 
"'.  Cannot find context in host " + host.getName());
+            throw new IllegalStateException("Invalid context '" + webContext + 
"'.  Cannot find context in host " + host.getName());
         }
 
         Wrapper wrapper = context.createWrapper();
@@ -110,16 +89,15 @@ public class TomcatRsRegistry implements
         wrapper.setName(name);
         wrapper.setServletClass(RsServlet.class.getName());
 
-        final String mapping = path.replace("/.*", "/*");
         context.addChild(wrapper);
-        wrapper.addMapping(mapping);
-        context.addServletMapping(mapping, name);
+        wrapper.addMapping(completePath);
+        context.addServletMapping(completePath, name);
 
         final String listenerId = wrapper.getName() + 
RsServlet.class.getName() + listener.hashCode();
         wrapper.addInitParameter(HttpListener.class.getName(), listenerId);
         context.getServletContext().setAttribute(listenerId, listener);
 
-        path = address(connectors, host.getName(), realRoot);
+        path = address(connectors, host.getName(), webContext);
         final String key = address(connectors, host.getName(), completePath);
         listeners.put(key, listener);
 


Reply via email to