Author: rmannibucau
Date: Thu Jan 3 09:17:25 2013
New Revision: 1428228
URL: http://svn.apache.org/viewvc?rev=1428228&view=rev
Log:
TOMEE-694 TOMEE-695 jaxrs configuration review (app level + compatibility)
Modified:
openejb/trunk/openejb/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRSService.java
openejb/trunk/openejb/server/openejb-cxf-transport/src/main/java/org/apache/openejb/server/cxf/transport/util/CxfUtil.java
openejb/trunk/openejb/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java
Modified:
openejb/trunk/openejb/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRSService.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRSService.java?rev=1428228&r1=1428227&r2=1428228&view=diff
==============================================================================
---
openejb/trunk/openejb/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRSService.java
(original)
+++
openejb/trunk/openejb/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRSService.java
Thu Jan 3 09:17:25 2013
@@ -61,6 +61,19 @@ public class CxfRSService extends RESTSe
}
@Override
+ protected boolean containsJaxRsConfiguration(final Properties properties) {
+ return properties.containsKey(CxfRsHttpListener.PROVIDERS_KEY)
+ || properties.containsKey(CxfRsHttpListener.CXF_JAXRS_PREFIX +
CxfUtil.IN_FAULT_INTERCEPTORS)
+ || properties.containsKey(CxfRsHttpListener.CXF_JAXRS_PREFIX +
CxfUtil.IN_INTERCEPTORS)
+ || properties.containsKey(CxfRsHttpListener.CXF_JAXRS_PREFIX +
CxfUtil.OUT_FAULT_INTERCEPTORS)
+ || properties.containsKey(CxfRsHttpListener.CXF_JAXRS_PREFIX +
CxfUtil.OUT_INTERCEPTORS)
+ || properties.containsKey(CxfRsHttpListener.CXF_JAXRS_PREFIX +
CxfUtil.DATABINDING)
+ || properties.containsKey(CxfRsHttpListener.CXF_JAXRS_PREFIX +
CxfUtil.FEATURES)
+ || properties.containsKey(CxfRsHttpListener.CXF_JAXRS_PREFIX +
CxfUtil.ADDRESS)
+ || properties.containsKey(CxfRsHttpListener.CXF_JAXRS_PREFIX +
CxfUtil.ENDPOINT_PROPERTIES);
+ }
+
+ @Override
protected RsHttpListener createHttpListener() {
return new CxfRsHttpListener(httpTransportFactory);
}
Modified:
openejb/trunk/openejb/server/openejb-cxf-transport/src/main/java/org/apache/openejb/server/cxf/transport/util/CxfUtil.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/server/openejb-cxf-transport/src/main/java/org/apache/openejb/server/cxf/transport/util/CxfUtil.java?rev=1428228&r1=1428227&r2=1428228&view=diff
==============================================================================
---
openejb/trunk/openejb/server/openejb-cxf-transport/src/main/java/org/apache/openejb/server/cxf/transport/util/CxfUtil.java
(original)
+++
openejb/trunk/openejb/server/openejb-cxf-transport/src/main/java/org/apache/openejb/server/cxf/transport/util/CxfUtil.java
Thu Jan 3 09:17:25 2013
@@ -23,7 +23,6 @@ import org.apache.cxf.bus.extension.Exte
import org.apache.cxf.databinding.DataBinding;
import org.apache.cxf.endpoint.AbstractEndpointFactory;
import org.apache.cxf.feature.AbstractFeature;
-import org.apache.cxf.feature.Feature;
import org.apache.cxf.interceptor.AbstractBasicInterceptorProvider;
import org.apache.cxf.interceptor.Interceptor;
import org.apache.cxf.message.Message;
@@ -93,7 +92,9 @@ public final class CxfUtil {
if (properties != null) {
svrFactory.setProperties(PropertiesHelper.map(properties));
}
- if (SystemInstance.get().getOptions().get(prefix + DEBUG, false)) {
+
+ final String debugKey = prefix + DEBUG;
+ if ("true".equalsIgnoreCase(beanConfig.getProperty(debugKey,
SystemInstance.get().getOptions().get(debugKey, "false")))) {
svrFactory.getProperties(true).put("faultStackTraceEnabled",
"true");
}
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=1428228&r1=1428227&r2=1428228&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
Thu Jan 3 09:17:25 2013
@@ -20,7 +20,13 @@ package org.apache.openejb.server.rest;
import org.apache.openejb.BeanContext;
import org.apache.openejb.BeanType;
import org.apache.openejb.Injection;
-import org.apache.openejb.assembler.classic.*;
+import org.apache.openejb.assembler.classic.AppInfo;
+import org.apache.openejb.assembler.classic.Assembler;
+import org.apache.openejb.assembler.classic.EjbJarInfo;
+import org.apache.openejb.assembler.classic.EnterpriseBeanInfo;
+import org.apache.openejb.assembler.classic.IdPropertiesInfo;
+import org.apache.openejb.assembler.classic.ServiceInfo;
+import org.apache.openejb.assembler.classic.WebAppInfo;
import
org.apache.openejb.assembler.classic.event.AssemblerAfterApplicationCreated;
import
org.apache.openejb.assembler.classic.event.AssemblerBeforeApplicationDestroyed;
import org.apache.openejb.assembler.classic.util.PojoUtil;
@@ -50,13 +56,25 @@ import javax.ws.rs.ext.Provider;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.net.*;
-import java.util.*;
+import java.net.MalformedURLException;
+import java.net.Socket;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
public abstract class RESTService implements ServerService, SelfManaging {
public static final Logger LOGGER =
Logger.getInstance(LogCategory.OPENEJB_RS, RESTService.class);
private static final boolean OLD_WEBSERVICE_DEPLOYMENT =
SystemInstance.get().getOptions().get("openejb.webservice.old-deployment",
false);
- private static final boolean APPLICATION_DEPLOYMENT =
SystemInstance.get().getOptions().get("openejb.jaxrs.application", true);
+ public static final String OPENEJB_USE_APPLICATION_PROPERTY =
"openejb.jaxrs.application";
+ private static final String APPLICATION_DEPLOYMENT =
SystemInstance.get().getOptions().get(OPENEJB_USE_APPLICATION_PROPERTY, "true");
public static final String OPENEJB_JAXRS_PROVIDERS_AUTO_PROP =
"openejb.jaxrs.providers.auto";
private static final String IP = "n/a";
@@ -116,13 +134,14 @@ public abstract class RESTService implem
Collection<IdPropertiesInfo> pojoConfigurations = null; // done lazily
try {
- if (APPLICATION_DEPLOYMENT) {
+ boolean deploymentWithApplication =
"true".equalsIgnoreCase(appInfo.properties.getProperty(OPENEJB_USE_APPLICATION_PROPERTY,
APPLICATION_DEPLOYMENT));
+ if (deploymentWithApplication) {
Application application = null;
String prefix = "/";
+ Class<?> appClazz = null;
if (webApp.restApplications.size() == 1) {
final String app =
webApp.restApplications.iterator().next();
- final Class<?> appClazz;
try {
appClazz = classLoader.loadClass(app);
application =
Application.class.cast(appClazz.newInstance());
@@ -130,60 +149,91 @@ public abstract class RESTService implem
throw new OpenEJBRestRuntimeException("can't create
class " + app, e);
}
- final String path = appPrefix(appClazz);
- if (path != null) {
- prefix += path + wildcard;
- } else {
- prefix += wildcard;
- }
-
final Set<Class<?>> classes = application.getClasses();
final Set<Object> singletons = application.getSingletons();
+
if (classes.size() + singletons.size() == 0) {
application = null; // use discovered services
} else {
for (Class<?> clazz : classes) {
if (isProvider(clazz)) {
additionalProviders.add(clazz);
+ } else if (!hasEjbAndIsNotAManagedBean(restEjbs,
clazz.getName())) {
+ pojoConfigurations =
PojoUtil.findPojoConfig(pojoConfigurations, appInfo, webApp);
+ if
(PojoUtil.findConfiguration(pojoConfigurations, clazz.getName()) != null) {
+ deploymentWithApplication = false;
+ logOldDeploymentUsage(clazz.getName());
+ break;
+ }
}
}
- for (Object o : singletons) {
- if (isProvider(o.getClass())) {
- additionalProviders.add(o);
+
+ if (deploymentWithApplication) {
+ for (Object o : singletons) {
+ final Class<?> clazz = o.getClass();
+ if (isProvider(clazz)) {
+ additionalProviders.add(o);
+ } else if
(!hasEjbAndIsNotAManagedBean(restEjbs, clazz.getName())) {
+ pojoConfigurations =
PojoUtil.findPojoConfig(pojoConfigurations, appInfo, webApp);
+ if
(PojoUtil.findConfiguration(pojoConfigurations, clazz.getName()) != null) {
+ deploymentWithApplication = false;
+ logOldDeploymentUsage(clazz.getName());
+ break;
+ }
+ }
}
}
}
+
+ final String path = appPrefix(appClazz);
+ if (path != null) {
+ prefix += path + wildcard;
+ } else {
+ prefix += wildcard;
+ }
}
- if (application == null) {
- application = new InternalApplication();
+ if (deploymentWithApplication) {
+ if (application == null) {
+ application = new InternalApplication();
- for (String clazz : webApp.restClass) {
- try {
- final Class<?> loaded =
classLoader.loadClass(clazz);
- if (!isProvider(loaded)) {
- application.getClasses().add(loaded);
- } else {
- additionalProviders.add(loaded);
+ for (String clazz : webApp.restClass) {
+ try {
+ final Class<?> loaded =
classLoader.loadClass(clazz);
+ if (!isProvider(loaded)) {
+ pojoConfigurations =
PojoUtil.findPojoConfig(pojoConfigurations, appInfo, webApp);
+ if
(PojoUtil.findConfiguration(pojoConfigurations, loaded.getName()) != null) {
+ deploymentWithApplication = false;
+
logOldDeploymentUsage(loaded.getName());
+ break;
+ }
+ application.getClasses().add(loaded);
+ } else {
+ additionalProviders.add(loaded);
+ }
+ } catch (Exception e) {
+ throw new OpenEJBRestRuntimeException("can't
load class " + clazz, e);
+ }
+ }
+ if (deploymentWithApplication) {
+ for (Map.Entry<String, EJBRestServiceInfo> ejb :
restEjbs.entrySet()) {
+
application.getClasses().add(ejb.getValue().context.getBeanClass());
+ }
+ if (!prefix.endsWith(wildcard)) {
+ prefix += wildcard;
}
- } catch (Exception e) {
- throw new OpenEJBRestRuntimeException("can't load
class " + clazz, e);
}
}
- for (Map.Entry<String, EJBRestServiceInfo> ejb :
restEjbs.entrySet()) {
-
application.getClasses().add(ejb.getValue().context.getBeanClass());
- }
- if (!prefix.endsWith(wildcard)) {
- prefix += wildcard;
+
+ if (!application.getClasses().isEmpty() ||
!application.getSingletons().isEmpty()) {
+ pojoConfigurations =
PojoUtil.findPojoConfig(pojoConfigurations, appInfo, webApp);
+ deployApplication(appInfo, webApp.contextRoot,
restEjbs, classLoader, injections, owbCtx, context, additionalProviders,
pojoConfigurations, application, prefix);
}
}
- if (!application.getClasses().isEmpty() ||
!application.getSingletons().isEmpty()) {
- pojoConfigurations =
PojoUtil.findPojoConfig(pojoConfigurations, appInfo, webApp);
- deployApplication(appInfo, webApp.contextRoot, restEjbs,
classLoader, injections, owbCtx, context, additionalProviders,
pojoConfigurations, application, prefix);
- }
+ }
- } else {
+ if (!deploymentWithApplication) {
// The spec says:
//
// "The resources and providers that make up a JAX-RS
application are configured via an application-supplied
@@ -302,6 +352,10 @@ public abstract class RESTService implem
}
}
+ protected static void logOldDeploymentUsage(final String clazz) {
+ LOGGER.info("Using deployment by endpoint instead of by application
for JAXRS deployment because an old configuration (by class/ejb) was found on "
+ clazz);
+ }
+
private void deployApplication(AppInfo appInfo, String contextRoot,
Map<String, EJBRestServiceInfo> restEjbs, ClassLoader classLoader,
Collection<Injection> injections, WebBeansContext owbCtx, Context context,
Collection<Object> additionalProviders, Collection<IdPropertiesInfo>
pojoConfigurations, Application application, String prefix) {
// get configuration
Properties configuration =
PojoUtil.findConfiguration(pojoConfigurations,
application.getClass().getName());
@@ -376,6 +430,9 @@ public abstract class RESTService implem
if (!enabled) return;
final AppInfo appInfo = event.getApp();
+
+ quickCheckIfOldDeploymentShouldBeUsedFromEjbConfig(appInfo);
+
if (deployedApplications.add(appInfo)) {
if (appInfo.webApps.size() == 0) {
final Map<String, EJBRestServiceInfo> restEjbs =
getRestEjbs(appInfo);
@@ -390,13 +447,14 @@ public abstract class RESTService implem
providers = new ArrayList<Object>();
}
- if (APPLICATION_DEPLOYMENT) {
+ if
("true".equalsIgnoreCase(appInfo.properties.getProperty(OPENEJB_USE_APPLICATION_PROPERTY,
APPLICATION_DEPLOYMENT))) {
final Application application = new InternalApplication();
for (Map.Entry<String, EJBRestServiceInfo> ejb :
restEjbs.entrySet()) {
application.getClasses().add(ejb.getValue().context.getBeanClass());
}
- List<IdPropertiesInfo> pojoConfigurations = new
ArrayList<IdPropertiesInfo>();
+ // merge configurations at app level since a single
deployment is available
+ final List<IdPropertiesInfo> pojoConfigurations = new
ArrayList<IdPropertiesInfo>();
BeanContext comp = null;
for (EjbJarInfo ejbJar : appInfo.ejbJars) {
for (EnterpriseBeanInfo bean : ejbJar.enterpriseBeans)
{
@@ -445,6 +503,28 @@ public abstract class RESTService implem
}
}
+ private void quickCheckIfOldDeploymentShouldBeUsedFromEjbConfig(final
AppInfo appInfo) {
+ // if forced don't update anything
+ if (appInfo.properties.getProperty(OPENEJB_USE_APPLICATION_PROPERTY)
!= null) {
+ return;
+ }
+
+ for (EjbJarInfo ejbJar : appInfo.ejbJars) {
+ for (EnterpriseBeanInfo bean : ejbJar.enterpriseBeans) {
+ if (bean.restService) {
+ final BeanContext beanContext =
containerSystem.getBeanContext(bean.ejbDeploymentId);
+ if
(containsJaxRsConfiguration(beanContext.getProperties())) {
+
appInfo.properties.setProperty(OPENEJB_USE_APPLICATION_PROPERTY, "true");
+ logOldDeploymentUsage(bean.ejbClass);
+ return; // no need to look further
+ }
+ }
+ }
+ }
+ }
+
+ protected abstract boolean containsJaxRsConfiguration(final Properties
properties);
+
protected Map<String, EJBRestServiceInfo> getRestEjbs(AppInfo appInfo) {
Map<String, BeanContext> beanContexts = new HashMap<String,
BeanContext>();
for (EjbJarInfo ejbJar : appInfo.ejbJars) {
@@ -740,7 +820,7 @@ public abstract class RESTService implem
}
@Override
- public void init(Properties props) throws Exception {
+ public void init(final Properties props) throws Exception {
virtualHost = props.getProperty("virtualHost");
enabled = ServiceManager.isEnabled(props);
}