You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2010/05/03 05:27:25 UTC
svn commit: r940353 - in
/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src:
main/java/org/apache/cayenne/configuration/rop/
main/java/org/apache/cayenne/configuration/rop/server/
main/java/org/apache/cayenne/configuration/web/ main/java/org/...
Author: aadamchik
Date: Mon May 3 03:27:24 2010
New Revision: 940353
URL: http://svn.apache.org/viewvc?rev=940353&view=rev
Log:
CAY-1420 Migrate ROP server-side components to DI-based stack
Added:
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/server/
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/server/CayenneROPServerModule.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/server/ROPHessianServlet.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/WebConfiguration.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/rop/
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/rop/server/
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/rop/server/ROPHessianServletTest.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/rop/server/ROPHessianServlet_ConfigModule.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/MockRemoteService.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/cayenne-org.apache.cayenne.configuration.rop.server.test-config.xml
Modified:
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/CayenneFilter.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/WebUtil.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/hessian/service/HessianService.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/hessian/service/HessianServlet.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/service/BaseRemoteService.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/service/HttpRemoteService.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/web/CayenneFilterTest.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/hessian/service/HessianServiceTest.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/service/BaseRemoteServiceTest.java
Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/server/CayenneROPServerModule.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/server/CayenneROPServerModule.java?rev=940353&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/server/CayenneROPServerModule.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/server/CayenneROPServerModule.java Mon May 3 03:27:24 2010
@@ -0,0 +1,52 @@
+/*****************************************************************
+ * 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.cayenne.configuration.rop.server;
+
+import java.util.Map;
+
+import org.apache.cayenne.di.Binder;
+import org.apache.cayenne.di.MapBuilder;
+import org.apache.cayenne.di.Module;
+import org.apache.cayenne.remote.RemoteService;
+import org.apache.cayenne.remote.hessian.service.HessianService;
+
+/**
+ * A DI module that defines services for the server-side of an ROP application based on
+ * Caucho Hessian.
+ *
+ * @since 3.1
+ */
+public class CayenneROPServerModule implements Module {
+
+ protected Map<String, String> eventBridgeProperties;
+
+ public CayenneROPServerModule(Map<String, String> eventBridgeProperties) {
+ this.eventBridgeProperties = eventBridgeProperties;
+ }
+
+ public void configure(Binder binder) {
+
+ MapBuilder<String> mapBuilder = binder
+ .bindMap(HessianService.EVENT_BRIDGE_PROPERTIES_MAP);
+ mapBuilder.putAll(eventBridgeProperties);
+
+ binder.bind(RemoteService.class).to(HessianService.class);
+ }
+
+}
Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/server/ROPHessianServlet.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/server/ROPHessianServlet.java?rev=940353&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/server/ROPHessianServlet.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/server/ROPHessianServlet.java Mon May 3 03:27:24 2010
@@ -0,0 +1,103 @@
+/*****************************************************************
+ * 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.cayenne.configuration.rop.server;
+
+import java.util.Collection;
+import java.util.Map;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+
+import org.apache.cayenne.DataChannel;
+import org.apache.cayenne.configuration.server.CayenneServerModule;
+import org.apache.cayenne.configuration.server.CayenneServerRuntime;
+import org.apache.cayenne.configuration.web.RequestHandler;
+import org.apache.cayenne.configuration.web.WebConfiguration;
+import org.apache.cayenne.configuration.web.WebUtil;
+import org.apache.cayenne.di.Module;
+import org.apache.cayenne.remote.RemoteService;
+import org.apache.cayenne.remote.hessian.HessianConfig;
+import org.apache.cayenne.remote.hessian.service.HessianService;
+
+import com.caucho.hessian.io.SerializerFactory;
+import com.caucho.hessian.server.HessianServlet;
+
+/**
+ * A servlet that bootstraps a Hessian-based ROP server. Servlet initialization
+ * parameters:
+ * <ul>
+ * <li>configuration-location (optional) - a name of Cayenne configuration XML file that
+ * will be used to load Cayenne stack. If missing, the servlet name will be used to derive
+ * the location using the following naming convention: if servlet name is "foo",
+ * configuration file name is name is "cayenne-foo.xml".
+ * <li>extra-modules (optional) - a comma or space-separated list of class names, with
+ * each class implementing {@link Module} interface. These are the custom modules loaded
+ * after the two standard ones that allow users to override any Cayenne runtime aspects,
+ * e.g. {@link RequestHandler}. Each custom module must have a no-arg constructor.
+ * </ul>
+ * <p>
+ *
+ * @since 3.1
+ */
+public class ROPHessianServlet extends HessianServlet {
+
+ /**
+ * Installs {@link HessianService} to respond to {@link RemoteService} requests.
+ */
+ @Override
+ public void init(ServletConfig configuration) throws ServletException {
+
+ WebConfiguration configAdapter = new WebConfiguration(configuration);
+
+ String configurationLocation = configAdapter.getCayenneConfigurationLocation();
+ Map<String, String> eventBridgeParameters = configAdapter
+ .getOtherInitializationParameters();
+
+ Collection<Module> modules = configAdapter
+ .createModules(
+ new CayenneServerModule(configurationLocation),
+ new CayenneROPServerModule(eventBridgeParameters));
+
+ CayenneServerRuntime runtime = new CayenneServerRuntime(
+ configurationLocation,
+ modules);
+
+ DataChannel channel = runtime.getDataChannel();
+
+ RemoteService service = runtime.getInjector().getInstance(RemoteService.class);
+
+ SerializerFactory serializerFactory = HessianConfig.createFactory(
+ HessianService.SERVER_SERIALIZER_FACTORIES,
+ channel.getEntityResolver());
+
+ setAPIClass(RemoteService.class);
+ setSerializerFactory(serializerFactory);
+ setService(service);
+
+ // Even though runtime instance is not accessed by Hessian service directly (it
+ // uses DataChannel injection instead), expose it in a manner consistent with
+ // CayenneFilter. Servlets other than ROP may decide to use it...
+
+ // TODO: andrus 04/14/2010: if CayenneFilter and ROPHessianServlet are used
+ // together in the same webapp, maybe a good idea to ensure they are using the
+ // same stack...Merging CayenneRuntime's modules might be tough though.
+ WebUtil.setCayenneRuntime(configuration.getServletContext(), runtime);
+ super.init(configuration);
+ }
+}
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/CayenneFilter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/CayenneFilter.java?rev=940353&r1=940352&r2=940353&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/CayenneFilter.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/CayenneFilter.java Mon May 3 03:27:24 2010
@@ -19,9 +19,7 @@
package org.apache.cayenne.configuration.web;
import java.io.IOException;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.StringTokenizer;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
@@ -35,7 +33,6 @@ import org.apache.cayenne.configuration.
import org.apache.cayenne.configuration.server.CayenneServerModule;
import org.apache.cayenne.configuration.server.CayenneServerRuntime;
import org.apache.cayenne.di.Module;
-import org.apache.cayenne.util.Util;
/**
* A filter that creates a Cayenne server runtime, possibly including custom modules. By
@@ -61,56 +58,18 @@ import org.apache.cayenne.util.Util;
*/
public class CayenneFilter implements Filter {
- static final String CONFIGURATION_LOCATION_PARAMETER = "configuration-location";
- static final String EXTRA_MODULES_PARAMETER = "extra-modules";
-
protected ServletContext servletContext;
public void init(FilterConfig config) throws ServletException {
this.servletContext = config.getServletContext();
- String configurationLocation = config
- .getInitParameter(CONFIGURATION_LOCATION_PARAMETER);
- if (configurationLocation == null) {
- configurationLocation = "cayenne-" + config.getFilterName() + ".xml";
- }
+ WebConfiguration configAdapter = new WebConfiguration(config);
- if (configurationLocation == null) {
- throw new ServletException(
- "Can't initialize Cayenne runtime. CayenneFilter has no name and no '"
- + CONFIGURATION_LOCATION_PARAMETER
- + "' parameter");
- }
+ String configurationLocation = configAdapter.getCayenneConfigurationLocation();
- Collection<Module> modules = new ArrayList<Module>(5);
- modules.add(new CayenneServerModule(configurationLocation));
- modules.add(new CayenneWebModule());
-
- String extraModules = config.getInitParameter(EXTRA_MODULES_PARAMETER);
- if (extraModules != null) {
-
- StringTokenizer toks = new StringTokenizer(extraModules, ", \n\r");
-
- while (toks.hasMoreTokens()) {
- String moduleName = toks.nextToken();
- Module module;
- try {
- module = (Module) Util.getJavaClass(moduleName).newInstance();
- }
- catch (Exception e) {
- String message = String
- .format(
- "Error instantiating custom DI module '%s' by filter '%s': %s",
- moduleName,
- getClass().getName(),
- e.getMessage());
- throw new ServletException(message, e);
- }
-
- modules.add(module);
- }
- }
+ Collection<Module> modules = configAdapter.createModules(new CayenneServerModule(
+ configurationLocation), new CayenneWebModule());
CayenneServerRuntime runtime = new CayenneServerRuntime(
configurationLocation,
Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/WebConfiguration.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/WebConfiguration.java?rev=940353&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/WebConfiguration.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/WebConfiguration.java Mon May 3 03:27:24 2010
@@ -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.cayenne.configuration.web;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.StringTokenizer;
+
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+
+import org.apache.cayenne.di.Module;
+import org.apache.cayenne.util.Util;
+
+/**
+ * A class that provides access to common Cayenne web configuration parameters retrieved
+ * either from a filter or servlet configuration.
+ *
+ * @since 3.1
+ */
+public class WebConfiguration {
+
+ static final String CONFIGURATION_LOCATION_PARAMETER = "configuration-location";
+ static final String EXTRA_MODULES_PARAMETER = "extra-modules";
+
+ private FilterConfig configuration;
+
+ public WebConfiguration(final ServletConfig servletConfiguration) {
+ this.configuration = new FilterConfig() {
+
+ public ServletContext getServletContext() {
+ return servletConfiguration.getServletContext();
+ }
+
+ @SuppressWarnings("all")
+ public Enumeration getInitParameterNames() {
+ return servletConfiguration.getInitParameterNames();
+ }
+
+ public String getInitParameter(String name) {
+ return servletConfiguration.getInitParameter(name);
+ }
+
+ public String getFilterName() {
+ return servletConfiguration.getServletName();
+ }
+ };
+ }
+
+ public WebConfiguration(FilterConfig filterConfiguration) {
+ this.configuration = filterConfiguration;
+ }
+
+ /**
+ * Returns a non-null location of a Cayenne configuration, extracted from the filter
+ * or servlet configuration parameters.
+ */
+ public String getCayenneConfigurationLocation() {
+ String configurationLocation = configuration
+ .getInitParameter(CONFIGURATION_LOCATION_PARAMETER);
+ return configurationLocation == null ? configurationLocation = "cayenne-"
+ + configuration.getFilterName()
+ + ".xml" : configurationLocation;
+ }
+
+ /**
+ * Creates and returns a collection of modules made of provided standard modules and
+ * extra custom modules specified via an optional "extra-modules" init parameter. The
+ * value of the parameter is expected to be a comma or space-separated list of class
+ * names, with each class implementing {@link Module} interface. Each custom module
+ * must have a no-arg constructor. If a module of this type is already in the modules
+ * collection, such module is skipped.
+ */
+ public Collection<Module> createModules(Module... standardModules)
+ throws ServletException {
+
+ Set<String> existingModules = new HashSet<String>();
+ Collection<Module> modules = new ArrayList<Module>();
+
+ if (standardModules != null) {
+ for (Module module : standardModules) {
+ modules.add(module);
+ existingModules.add(module.getClass().getName());
+ }
+ }
+
+ String extraModules = configuration.getInitParameter(EXTRA_MODULES_PARAMETER);
+ if (extraModules != null) {
+
+ StringTokenizer toks = new StringTokenizer(extraModules, ", \n\r");
+ while (toks.hasMoreTokens()) {
+ String moduleName = toks.nextToken();
+
+ if (!existingModules.add(moduleName)) {
+ continue;
+ }
+
+ Module module;
+ try {
+ module = (Module) Util.getJavaClass(moduleName).newInstance();
+ }
+ catch (Exception e) {
+ String message = String
+ .format(
+ "Error instantiating custom DI module '%s' by filter '%s': %s",
+ moduleName,
+ getClass().getName(),
+ e.getMessage());
+ throw new ServletException(message, e);
+ }
+
+ modules.add(module);
+ }
+ }
+
+ return modules;
+ }
+
+ /**
+ * Returns a map of parameters from the underlying FilterConfig or ServletConfig
+ * object.
+ */
+ public Map<String, String> getInitializationParameters() {
+ Enumeration<?> en = configuration.getInitParameterNames();
+
+ if (!en.hasMoreElements()) {
+ return Collections.EMPTY_MAP;
+ }
+
+ Map<String, String> parameters = new HashMap<String, String>();
+ while (en.hasMoreElements()) {
+ String key = (String) en.nextElement();
+ parameters.put(key, configuration.getInitParameter(key));
+ }
+
+ return parameters;
+ }
+
+ /**
+ * Returns servlet or filter configuration parameters, excluding those recognized by
+ * WebConfiguration. Namely 'configuration-location' and 'extra-modules' parameters
+ * are removed.
+ */
+ public Map<String, String> getOtherInitializationParameters() {
+
+ Map<String, String> parameters = getInitializationParameters();
+
+ if (!parameters.isEmpty()) {
+ parameters.remove(CONFIGURATION_LOCATION_PARAMETER);
+ parameters.remove(EXTRA_MODULES_PARAMETER);
+ }
+
+ return parameters;
+ }
+}
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/WebUtil.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/WebUtil.java?rev=940353&r1=940352&r2=940353&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/WebUtil.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/WebUtil.java Mon May 3 03:27:24 2010
@@ -21,11 +21,13 @@ package org.apache.cayenne.configuration
import javax.servlet.ServletContext;
import org.apache.cayenne.configuration.CayenneRuntime;
+import org.apache.cayenne.configuration.rop.server.ROPHessianServlet;
/**
* A helper class to retrieve and store {@link CayenneRuntime} in the
- * {@link ServletContext}. All Cayenne web configuration objects are relying on this class
- * to access runtime.
+ * {@link ServletContext}. All Cayenne web configuration objects, such as
+ * {@link CayenneFilter} and {@link ROPHessianServlet}, are using this class to access
+ * runtime.
*
* @since 3.1
*/
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/hessian/service/HessianService.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/hessian/service/HessianService.java?rev=940353&r1=940352&r2=940353&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/hessian/service/HessianService.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/hessian/service/HessianService.java Mon May 3 03:27:24 2010
@@ -19,57 +19,36 @@
package org.apache.cayenne.remote.hessian.service;
-import java.util.Enumeration;
-import java.util.HashMap;
import java.util.Map;
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
-import org.apache.cayenne.remote.hessian.HessianConfig;
+import org.apache.cayenne.access.DataDomain;
+import org.apache.cayenne.di.Inject;
import org.apache.cayenne.remote.service.HttpRemoteService;
-import com.caucho.hessian.io.SerializerFactory;
-import com.caucho.services.server.Service;
import com.caucho.services.server.ServiceContext;
/**
- * An implementation of RemoteService using binary Hessian protocol. For more info on
- * Hessian see http://www.caucho.com/resin-3.0/protocols/hessian.xtp.
+ * An implementation of RemoteService for work within Caucho Hessian environment.
*
- * @see org.apache.cayenne.remote.hessian.service.HessianServlet
- * @see org.apache.cayenne.remote.RemoteService
- * @since 1.2
+ * @since 3.1 the service API is reworked to initialize via Cayenne DI.
*/
-public class HessianService extends HttpRemoteService implements Service {
+public class HessianService extends HttpRemoteService {
+
+ public static final String EVENT_BRIDGE_PROPERTIES_MAP = "org.apache.cayenne.remote.hessian.service.HessianService.properties";
public static final String[] SERVER_SERIALIZER_FACTORIES = new String[] {
- ServerSerializerFactory.class.getName()
+ ServerSerializerFactory.class.getName()
};
/**
- * Extracts parameters from ServletConfig and initializes the service.
- */
- public void init(ServletConfig config) throws ServletException {
- Map properties = new HashMap();
-
- Enumeration en = config.getInitParameterNames();
- while (en.hasMoreElements()) {
- String name = (String) en.nextElement();
- properties.put(name, config.getInitParameter(name));
- }
-
- initService(properties);
- }
-
- /**
- * Creates a Hessian SerializerFactory with Cayenne extensions.
+ * @since 3.1
*/
- SerializerFactory createSerializerFactory() {
- return HessianConfig.createFactory(SERVER_SERIALIZER_FACTORIES, getRootChannel()
- .getEntityResolver());
+ public HessianService(@Inject DataDomain domain,
+ @Inject(EVENT_BRIDGE_PROPERTIES_MAP) Map<String, String> eventBridgeProperties) {
+ super(domain, eventBridgeProperties);
}
@Override
@@ -83,8 +62,4 @@ public class HessianService extends Http
return request.getSession(create);
}
-
- public void destroy() {
- destroyService();
- }
}
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/hessian/service/HessianServlet.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/hessian/service/HessianServlet.java?rev=940353&r1=940352&r2=940353&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/hessian/service/HessianServlet.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/hessian/service/HessianServlet.java Mon May 3 03:27:24 2010
@@ -22,117 +22,31 @@ package org.apache.cayenne.remote.hessia
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
-import org.apache.cayenne.remote.RemoteService;
+import org.apache.cayenne.configuration.rop.server.ROPHessianServlet;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
/**
- * An extension of the <code>com.caucho.hessian.server.HessianServlet</code> that
- * installs default Cayenne handlers, simplifying <code>web.xml</code> configuration.
- * Here is a sample configuration:
- *
- * <pre>
- * <servlet>
- * <servlet-name>cayenne</servlet-name>
- * <servlet-class>org.apache.cayenne.remote.hessian.service.HessianServlet</servlet-class>
- * </servlet>
- *
- * <servlet-mapping>
- * <servlet-name>cayenne</servlet-name>
- * <url-pattern>/cayenne</url-pattern>
- * </servlet-mapping>
- * </pre>
- *
- * Custom service class and interface can be specified in a manner compatible with Hessian
- * recommendations, namely via <em>service-class</em> and <em>api-class</em> servlet
- * parameters.
+ * Deprecated since 3.1 in favor of {@link ROPHessianServlet}. Note that if you keep using
+ * this servlet in your web.xml, only default configuration will work, as "api-class" and
+ * "service-class" parameters are no longer supported. ROPHessianServlet supports
+ * "extra-modules" parameter instead to customize ROP service via
+ * {@link HessianServletConfigurator}.
*
+ * @deprecated since 3.1 use {@link ROPHessianServlet}.
* @since 1.2
*/
-public class HessianServlet extends com.caucho.hessian.server.HessianServlet {
+public class HessianServlet extends ROPHessianServlet {
+
+ private Log logger;
- // config parameters compatible with Hessian parameter names
- static final String API_CLASS_PARAMETER = "api-class";
- static final String SERVICE_CLASS_PARAMETER = "service-class";
-
- /**
- * Installs {@link HessianService} to respond to {@link RemoteService} requests.
- */
@Override
public void init(ServletConfig config) throws ServletException {
- Class apiClass = createAPIClass(config);
- if (apiClass == null) {
- throw new ServletException("Can't configure service API class");
- }
-
- setAPIClass(apiClass);
-
- HessianService service = createService(config);
- if (service == null) {
- throw new ServletException("Error configuring service ");
- }
-
- service.init(config);
- setSerializerFactory(service.createSerializerFactory());
- setService(service);
+ logger = LogFactory.getLog(HessianServlet.class);
+ logger.warn("**** HessianServlet is deprecated. Use ROPHessianServlet instead");
- // proceed to super
super.init(config);
}
- protected HessianService createService(ServletConfig config) throws ServletException {
-
- String className = config.getInitParameter(SERVICE_CLASS_PARAMETER);
- if (className == null) {
- return new HessianService();
- }
-
- try {
- Class serviceClass = Class.forName(className, true, Thread
- .currentThread()
- .getContextClassLoader());
-
- if (!HessianService.class.isAssignableFrom(serviceClass)) {
- throw new ServletException(
- "Service class must be a subclass of HessianService: "
- + className);
- }
-
- return (HessianService) serviceClass.newInstance();
- }
- catch (ServletException e) {
- throw e;
- }
- catch (Exception e) {
- throw new ServletException(
- "Error instantiating service class " + className,
- e);
- }
- }
-
- protected Class createAPIClass(ServletConfig config) throws ServletException {
- String interfaceName = config.getInitParameter(API_CLASS_PARAMETER);
- if (interfaceName == null) {
- return RemoteService.class;
- }
- try {
- Class serviceInterface = Class.forName(interfaceName, true, Thread
- .currentThread()
- .getContextClassLoader());
-
- if (!RemoteService.class.isAssignableFrom(serviceInterface)) {
- throw new ServletException(
- "Service interface must be a subinterface of RemoteService: "
- + interfaceName);
- }
-
- return serviceInterface;
- }
- catch (ServletException e) {
- throw e;
- }
- catch (Exception e) {
- throw new ServletException("Error instantiating service interface "
- + interfaceName, e);
- }
- }
}
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/service/BaseRemoteService.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/service/BaseRemoteService.java?rev=940353&r1=940352&r2=940353&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/service/BaseRemoteService.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/service/BaseRemoteService.java Mon May 3 03:27:24 2010
@@ -27,8 +27,6 @@ import org.apache.cayenne.CayenneRuntime
import org.apache.cayenne.DataChannel;
import org.apache.cayenne.access.ClientServerChannel;
import org.apache.cayenne.access.DataDomain;
-import org.apache.cayenne.conf.Configuration;
-import org.apache.cayenne.conf.DefaultConfiguration;
import org.apache.cayenne.remote.ClientMessage;
import org.apache.cayenne.remote.RemoteService;
import org.apache.cayenne.remote.RemoteSession;
@@ -37,8 +35,8 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
- * A generic implementation of an RemoteService. Subclasses can be customized to work with
- * different remoting mechanisms, such as Hessian or JAXRPC.
+ * A generic implementation of an RemoteService. Can be subclassed to work with different
+ * remoting mechanisms, such as Hessian or JAXRPC.
*
* @since 1.2
*/
@@ -46,48 +44,42 @@ public abstract class BaseRemoteService
public static final String EVENT_BRIDGE_FACTORY_PROPERTY = "cayenne.RemoteService.EventBridge.factory";
- // keep logger non-static so that it could be garbage collected with this instance..
- private final Log logObj = LogFactory.getLog(BaseRemoteService.class);
+ // keep logger non-static so that it could be garbage collected with this instance.
+ protected final Log logger;
protected DataDomain domain;
-
protected String eventBridgeFactoryName;
- protected Map eventBridgeParameters;
-
- public String getEventBridgeFactoryName() {
- return eventBridgeFactoryName;
- }
-
- public Map getEventBridgeParameters() {
- return eventBridgeParameters != null ? Collections
- .unmodifiableMap(eventBridgeParameters) : Collections.EMPTY_MAP;
- }
+ protected Map<String, String> eventBridgeParameters;
/**
- * A method that sets up a service, initializing Cayenne stack. Should be invoked by
- * subclasses from their appropriate service lifecycle methods.
+ * @since 3.1
*/
- protected void initService(Map properties) throws CayenneRuntimeException {
+ public BaseRemoteService(DataDomain domain, Map<String, String> eventBridgeProperties) {
+
+ logger = LogFactory.getLog(getClass());
// start Cayenne service
- logObj.debug(this.getClass().getName() + " is starting");
+ logger.debug("ROP service is starting");
- initCayenneStack(properties);
- initEventBridgeParameters(properties);
+ this.domain = domain;
+ initEventBridgeParameters(eventBridgeProperties);
- logObj.debug(getClass().getName() + " started");
+ logger.debug(getClass().getName() + " started");
}
- /**
- * Shuts down this service. Should be invoked by subclasses from their appropriate
- * service lifecycle methods.
- */
- protected void destroyService() {
- logObj.debug(getClass().getName() + " destroyed");
+ public String getEventBridgeFactoryName() {
+ return eventBridgeFactoryName;
+ }
+
+ public Map<String, String> getEventBridgeParameters() {
+ return eventBridgeParameters != null ? Collections
+ .unmodifiableMap(eventBridgeParameters) : Collections.EMPTY_MAP;
}
/**
* Returns a DataChannel that is a parent of all session DataChannels.
+ *
+ * @deprecated unused since 3.1
*/
public DataChannel getRootChannel() {
return domain;
@@ -113,16 +105,16 @@ public abstract class BaseRemoteService
protected abstract ServerSession getServerSession();
public RemoteSession establishSession() {
- logObj.debug("Session requested by client");
+ logger.debug("Session requested by client");
RemoteSession session = createServerSession().getSession();
- logObj.debug("Established client session: " + session);
+ logger.debug("Established client session: " + session);
return session;
}
public RemoteSession establishSharedSession(String name) {
- logObj.debug("Shared session requested by client. Group name: " + name);
+ logger.debug("Shared session requested by client. Group name: " + name);
if (name == null) {
throw new CayenneRuntimeException("Invalid null shared session name");
@@ -143,7 +135,7 @@ public abstract class BaseRemoteService
throw new MissingSessionException("No session associated with request.");
}
- logObj.debug("processMessage, sessionId: " + handler.getSession().getSessionId());
+ logger.debug("processMessage, sessionId: " + handler.getSession().getSessionId());
// intercept and log exceptions
try {
@@ -156,7 +148,7 @@ public abstract class BaseRemoteService
message.getClass().getName()).append(" of type ").append(message);
String wrapperMessageString = wrapperMessage.toString();
- logObj.info(wrapperMessageString, th);
+ logger.info(wrapperMessageString, th);
// This exception will probably be propagated to the client.
// Recast the exception to a serializable form.
@@ -184,44 +176,28 @@ public abstract class BaseRemoteService
/**
* Creates a server-side channel that will handle all client requests. For shared
* sessions the same channel instance is reused for the entire group of clients. For
- * dedicated sessions, one channel per client is created. <p/> This implementation
- * returns {@link ClientServerChannel} instance wrapping a DataContext. Subclasses may
- * override the method to customize channel creation. For instance they may wrap
- * channel in the custom interceptors to handle transactions or security.
+ * dedicated sessions, one channel per client is created.
+ * <p/>
+ * This implementation returns {@link ClientServerChannel} instance wrapping a
+ * DataContext. Subclasses may override the method to customize channel creation. For
+ * instance they may wrap channel in the custom interceptors to handle transactions or
+ * security.
*/
protected DataChannel createChannel() {
return new ClientServerChannel(domain);
}
/**
- * Sets up Cayenne stack.
- */
- protected void initCayenneStack(Map properties) {
- Configuration cayenneConfig = new DefaultConfiguration(
- Configuration.DEFAULT_DOMAIN_FILE);
-
- try {
- cayenneConfig.initialize();
- }
- catch (Exception ex) {
- throw new CayenneRuntimeException("Error starting Cayenne", ex);
- }
-
- // TODO (Andrus 10/15/2005) this assumes that mapping has a single domain...
- // do something about multiple domains
- this.domain = cayenneConfig.getDomain();
- }
-
- /**
* Initializes EventBridge parameters for remote clients peer-to-peer communications.
*/
- protected void initEventBridgeParameters(Map properties) {
- String eventBridgeFactoryName = (String) properties
+ protected void initEventBridgeParameters(Map<String, String> properties) {
+ String eventBridgeFactoryName = properties
.get(BaseRemoteService.EVENT_BRIDGE_FACTORY_PROPERTY);
if (eventBridgeFactoryName != null) {
- Map eventBridgeParameters = new HashMap(properties);
+ Map<String, String> eventBridgeParameters = new HashMap<String, String>(
+ properties);
eventBridgeParameters.remove(BaseRemoteService.EVENT_BRIDGE_FACTORY_PROPERTY);
this.eventBridgeFactoryName = eventBridgeFactoryName;
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/service/HttpRemoteService.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/service/HttpRemoteService.java?rev=940353&r1=940352&r2=940353&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/service/HttpRemoteService.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/service/HttpRemoteService.java Mon May 3 03:27:24 2010
@@ -26,24 +26,29 @@ import java.util.Map;
import javax.servlet.http.HttpSession;
import org.apache.cayenne.DataChannel;
+import org.apache.cayenne.access.DataDomain;
import org.apache.cayenne.remote.RemoteSession;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
/**
- * A {@link org.apache.cayenne.remote.RemoteService} implementation that stores
- * server context information in HTTP sessions.
+ * A {@link org.apache.cayenne.remote.RemoteService} implementation that stores server
+ * context information in HTTP sessions.
*
* @since 1.2
*/
public abstract class HttpRemoteService extends BaseRemoteService {
- static final String SESSION_ATTRIBUTE = "HttpRemoteService.ServerSession";
+ static final String SESSION_ATTRIBUTE = HttpRemoteService.class.getName()
+ + ".ServerSession";
- // keep logger non-static so that it could be garbage collected with this instance..
- private final Log logObj = LogFactory.getLog(HttpRemoteService.class);
+ private Map<String, WeakReference<DataChannel>> sharedChannels;
- private Map<String, WeakReference<DataChannel>> sharedChannels = new HashMap<String, WeakReference<DataChannel>>();
+ /**
+ * @since 3.1
+ */
+ public HttpRemoteService(DataDomain domain, Map<String, String> eventBridgeProperties) {
+ super(domain, eventBridgeProperties);
+ this.sharedChannels = new HashMap<String, WeakReference<DataChannel>>();
+ }
/**
* Returns an HttpSession associated with the current request in progress.
@@ -101,10 +106,10 @@ public abstract class HttpRemoteService
if (channel == null) {
channel = createChannel();
saveSharedChannel(name, channel);
- logObj.debug("Starting a new shared channel: " + name);
+ logger.debug("Starting a new shared channel: " + name);
}
else {
- logObj.debug("Joining existing shared channel: " + name);
+ logger.debug("Joining existing shared channel: " + name);
}
}
Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/rop/server/ROPHessianServletTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/rop/server/ROPHessianServletTest.java?rev=940353&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/rop/server/ROPHessianServletTest.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/rop/server/ROPHessianServletTest.java Mon May 3 03:27:24 2010
@@ -0,0 +1,151 @@
+/*****************************************************************
+ * 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.cayenne.configuration.rop.server;
+
+import junit.framework.TestCase;
+
+import org.apache.cayenne.configuration.CayenneRuntime;
+import org.apache.cayenne.configuration.server.CayenneServerModule;
+import org.apache.cayenne.configuration.web.MockModule1;
+import org.apache.cayenne.configuration.web.MockModule2;
+import org.apache.cayenne.configuration.web.MockRequestHandler;
+import org.apache.cayenne.configuration.web.RequestHandler;
+import org.apache.cayenne.configuration.web.WebUtil;
+import org.apache.cayenne.remote.RemoteService;
+
+import com.mockrunner.mock.web.MockServletConfig;
+import com.mockrunner.mock.web.MockServletContext;
+
+public class ROPHessianServletTest extends TestCase {
+
+ public void testInitWithServletName() throws Exception {
+
+ MockServletConfig config = new MockServletConfig();
+ config.setServletName("org.apache.cayenne.configuration.rop.server.test-config");
+
+ MockServletContext context = new MockServletContext();
+ config.setServletContext(context);
+
+ ROPHessianServlet servlet = new ROPHessianServlet();
+
+ assertNull(WebUtil.getCayenneRuntime(context));
+ servlet.init(config);
+
+ CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
+ assertNotNull(runtime);
+
+ assertEquals(
+ "cayenne-org.apache.cayenne.configuration.rop.server.test-config.xml",
+ runtime.getConfigurationLocation());
+ }
+
+ public void testInitWithLocation() throws Exception {
+
+ String location = "cayenne-org.apache.cayenne.configuration.rop.server.test-config.xml";
+ MockServletConfig config = new MockServletConfig();
+ config.setServletName("abc");
+ config.setInitParameter("configuration-location", location);
+
+ MockServletContext context = new MockServletContext();
+ config.setServletContext(context);
+
+ ROPHessianServlet servlet = new ROPHessianServlet();
+ servlet.init(config);
+
+ CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
+ assertNotNull(runtime);
+
+ assertEquals(location, runtime.getConfigurationLocation());
+ }
+
+ public void testInitWithStandardModules() throws Exception {
+
+ String name = "org.apache.cayenne.configuration.rop.server.test-config";
+
+ MockServletConfig config = new MockServletConfig();
+ config.setServletName(name);
+
+ MockServletContext context = new MockServletContext();
+ config.setServletContext(context);
+
+ ROPHessianServlet servlet = new ROPHessianServlet();
+ servlet.init(config);
+
+ CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
+ assertNotNull(runtime);
+
+ assertEquals("cayenne-" + name + ".xml", runtime.getConfigurationLocation());
+ assertEquals(2, runtime.getModules().length);
+ assertTrue(runtime.getModules()[0] instanceof CayenneServerModule);
+ assertTrue(runtime.getModules()[1] instanceof CayenneROPServerModule);
+
+ assertTrue(RemoteService.class.equals(servlet.getAPIClass()));
+ }
+
+ public void testInitWithExtraModules() throws Exception {
+
+ String name = "org.apache.cayenne.configuration.rop.server.test-config";
+
+ MockServletConfig config = new MockServletConfig();
+ config.setServletName(name);
+ config.setInitParameter("extra-modules", MockModule1.class.getName()
+ + ","
+ + MockModule2.class.getName());
+
+ MockServletContext context = new MockServletContext();
+ config.setServletContext(context);
+
+ ROPHessianServlet servlet = new ROPHessianServlet();
+ servlet.init(config);
+
+ CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
+ assertNotNull(runtime);
+
+ assertEquals(4, runtime.getModules().length);
+
+ assertTrue(runtime.getModules()[0] instanceof CayenneServerModule);
+ assertTrue(runtime.getModules()[1] instanceof CayenneROPServerModule);
+ assertTrue(runtime.getModules()[2] instanceof MockModule1);
+ assertTrue(runtime.getModules()[3] instanceof MockModule2);
+
+ RequestHandler handler = runtime.getInjector().getInstance(RequestHandler.class);
+ assertTrue(handler instanceof MockRequestHandler);
+ }
+
+ public void testInitHessianService() throws Exception {
+
+ MockServletConfig config = new MockServletConfig();
+ config.setServletName("abc");
+
+ MockServletContext context = new MockServletContext();
+ config.setServletContext(context);
+ config.setInitParameter("extra-modules", ROPHessianServlet_ConfigModule.class
+ .getName());
+
+ ROPHessianServlet servlet = new ROPHessianServlet();
+
+ servlet.init(config);
+ CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
+ assertTrue(runtime.getModules()[2] instanceof ROPHessianServlet_ConfigModule);
+
+ assertTrue(RemoteService.class.equals(servlet.getAPIClass()));
+
+ // TODO: mock servlet request to check that the right service instance is invoked
+ }
+}
Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/rop/server/ROPHessianServlet_ConfigModule.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/rop/server/ROPHessianServlet_ConfigModule.java?rev=940353&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/rop/server/ROPHessianServlet_ConfigModule.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/rop/server/ROPHessianServlet_ConfigModule.java Mon May 3 03:27:24 2010
@@ -0,0 +1,38 @@
+/*****************************************************************
+ * 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.cayenne.configuration.rop.server;
+
+import org.apache.cayenne.DataChannel;
+import org.apache.cayenne.access.DataDomain;
+import org.apache.cayenne.di.Binder;
+import org.apache.cayenne.di.Module;
+import org.apache.cayenne.remote.MockRemoteService;
+import org.apache.cayenne.remote.RemoteService;
+
+public class ROPHessianServlet_ConfigModule implements Module {
+
+ public void configure(Binder binder) {
+
+ DataDomain domain = new DataDomain("x");
+ binder.bind(DataChannel.class).toInstance(domain);
+ binder.bind(DataDomain.class).toInstance(domain);
+ binder.bind(RemoteService.class).to(MockRemoteService.class);
+ }
+
+}
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/web/CayenneFilterTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/web/CayenneFilterTest.java?rev=940353&r1=940352&r2=940353&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/web/CayenneFilterTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/web/CayenneFilterTest.java Mon May 3 03:27:24 2010
@@ -50,11 +50,13 @@ public class CayenneFilterTest extends T
assertEquals("cayenne-abc.xml", runtime.getConfigurationLocation());
}
- public void testInitWithRuntimeName() throws Exception {
+ public void testInitWithLocation() throws Exception {
MockFilterConfig config = new MockFilterConfig();
config.setFilterName("abc");
- config.setInitParameter(CayenneFilter.CONFIGURATION_LOCATION_PARAMETER, "xyz");
+ config.setInitParameter(
+ WebConfiguration.CONFIGURATION_LOCATION_PARAMETER,
+ "xyz");
MockServletContext context = new MockServletContext();
config.setupServletContext(context);
@@ -97,10 +99,9 @@ public class CayenneFilterTest extends T
MockFilterConfig config = new MockFilterConfig();
config.setFilterName("abc");
- config.setInitParameter(CayenneFilter.EXTRA_MODULES_PARAMETER, MockModule1.class
- .getName()
- + ","
- + MockModule2.class.getName());
+ config.setInitParameter(
+ WebConfiguration.EXTRA_MODULES_PARAMETER,
+ MockModule1.class.getName() + "," + MockModule2.class.getName());
MockServletContext context = new MockServletContext();
config.setupServletContext(context);
@@ -126,7 +127,7 @@ public class CayenneFilterTest extends T
MockFilterConfig config = new MockFilterConfig();
config.setFilterName("abc");
config.setInitParameter(
- CayenneFilter.EXTRA_MODULES_PARAMETER,
+ WebConfiguration.EXTRA_MODULES_PARAMETER,
CayenneFilter_DispatchModule.class.getName());
MockServletContext context = new MockServletContext();
Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/MockRemoteService.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/MockRemoteService.java?rev=940353&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/MockRemoteService.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/MockRemoteService.java Mon May 3 03:27:24 2010
@@ -0,0 +1,37 @@
+/*****************************************************************
+ * 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.cayenne.remote;
+
+import java.rmi.RemoteException;
+
+public class MockRemoteService implements RemoteService {
+
+ public RemoteSession establishSession() throws RemoteException {
+ return null;
+ }
+
+ public RemoteSession establishSharedSession(String name) throws RemoteException {
+ return null;
+ }
+
+ public Object processMessage(ClientMessage message) throws RemoteException, Throwable {
+ return null;
+ }
+
+}
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/hessian/service/HessianServiceTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/hessian/service/HessianServiceTest.java?rev=940353&r1=940352&r2=940353&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/hessian/service/HessianServiceTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/hessian/service/HessianServiceTest.java Mon May 3 03:27:24 2010
@@ -19,42 +19,46 @@
package org.apache.cayenne.remote.hessian.service;
+import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpSession;
-import junit.framework.TestCase;
-
import org.apache.cayenne.access.DataDomain;
import org.apache.cayenne.event.MockEventBridgeFactory;
-import org.apache.cayenne.remote.hessian.service.HessianService;
+import com.caucho.services.server.ServiceContext;
+import com.mockrunner.mock.web.MockHttpServletRequest;
import com.mockrunner.mock.web.MockHttpSession;
-import com.mockrunner.mock.web.MockServletConfig;
+
+import junit.framework.TestCase;
public class HessianServiceTest extends TestCase {
- public void testInit() throws Exception {
- MockServletConfig config = new MockServletConfig();
- config.setInitParameter(
+ public void testGetSession() throws Exception {
+
+ Map<String, String> map = new HashMap<String, String>();
+ map.put(
HessianService.EVENT_BRIDGE_FACTORY_PROPERTY,
MockEventBridgeFactory.class.getName());
- HessianService handler = new HessianService() {
+ DataDomain domain = new DataDomain("test");
+
+ HessianService service = new HessianService(domain, map);
- @Override
- protected void initCayenneStack(Map properties) {
- this.domain = new DataDomain("test");
- }
-
- @Override
- protected HttpSession getSession(boolean create) {
- return new MockHttpSession();
- }
- };
-
- handler.init(config);
- assertEquals(MockEventBridgeFactory.class.getName(), handler
- .getEventBridgeFactoryName());
+ MockHttpServletRequest request = new MockHttpServletRequest();
+ HttpSession session = new MockHttpSession();
+ request.setSession(session);
+
+ // for some eason need to call this to get session activated in the mock request
+ request.getSession();
+
+ try {
+ ServiceContext.begin(request, null, null);
+ assertSame(session, service.getSession(false));
+ }
+ finally {
+ ServiceContext.end();
+ }
}
}
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/service/BaseRemoteServiceTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/service/BaseRemoteServiceTest.java?rev=940353&r1=940352&r2=940353&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/service/BaseRemoteServiceTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/service/BaseRemoteServiceTest.java Mon May 3 03:27:24 2010
@@ -18,19 +18,59 @@
****************************************************************/
package org.apache.cayenne.remote.service;
+import java.util.HashMap;
+import java.util.Map;
+
import junit.framework.TestCase;
import org.apache.cayenne.CayenneRuntimeException;
+import org.apache.cayenne.access.DataDomain;
+import org.apache.cayenne.event.MockEventBridgeFactory;
import org.apache.cayenne.query.Query;
import org.apache.cayenne.remote.QueryMessage;
import org.apache.cayenne.remote.RemoteSession;
+import org.apache.cayenne.remote.hessian.service.HessianService;
import org.apache.cayenne.util.Util;
public class BaseRemoteServiceTest extends TestCase {
+ public void testConstructor() throws Exception {
+
+ Map<String, String> map = new HashMap<String, String>();
+ map.put(
+ HessianService.EVENT_BRIDGE_FACTORY_PROPERTY,
+ MockEventBridgeFactory.class.getName());
+
+ DataDomain domain = new DataDomain("test");
+ BaseRemoteService service = new BaseRemoteService(domain, map) {
+
+ @Override
+ protected ServerSession createServerSession() {
+ return null;
+ }
+
+ @Override
+ protected ServerSession createServerSession(String name) {
+ return null;
+ }
+
+ @Override
+ protected ServerSession getServerSession() {
+ return null;
+ }
+ };
+ assertEquals(MockEventBridgeFactory.class.getName(), service
+ .getEventBridgeFactoryName());
+ assertSame(domain, service.domain);
+
+ }
+
public void testProcessMessageExceptionSerializability() throws Throwable {
- BaseRemoteService handler = new BaseRemoteService() {
+ Map<String, String> map = new HashMap<String, String>();
+ DataDomain domain = new DataDomain("test");
+
+ BaseRemoteService service = new BaseRemoteService(domain, map) {
@Override
protected ServerSession createServerSession() {
@@ -49,7 +89,7 @@ public class BaseRemoteServiceTest exten
};
try {
- handler.processMessage(new QueryMessage(null) {
+ service.processMessage(new QueryMessage(null) {
@Override
public Query getQuery() {
@@ -65,7 +105,7 @@ public class BaseRemoteServiceTest exten
}
try {
- handler.processMessage(new QueryMessage(null) {
+ service.processMessage(new QueryMessage(null) {
@Override
public Query getQuery() {
Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/cayenne-org.apache.cayenne.configuration.rop.server.test-config.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/cayenne-org.apache.cayenne.configuration.rop.server.test-config.xml?rev=940353&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/cayenne-org.apache.cayenne.configuration.rop.server.test-config.xml (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/cayenne-org.apache.cayenne.configuration.rop.server.test-config.xml Mon May 3 03:27:24 2010
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<domain project-version="6">
+
+</domain>