You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by nt...@apache.org on 2022/07/11 16:27:21 UTC
[cayenne] 02/02: CAY-2737 Cayenne 4.3: cleanup deprecated code - remove cayenne-web module
This is an automated email from the ASF dual-hosted git repository.
ntimofeev pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cayenne.git
commit 95a4d90ce463a9220e921c376aef7d6521498736
Author: Nikita Timofeev <st...@gmail.com>
AuthorDate: Mon Jul 11 19:19:59 2022 +0300
CAY-2737 Cayenne 4.3: cleanup deprecated code
- remove cayenne-web module
---
assembly/pom.xml | 6 -
.../assemblies/generic/assembly-generic.xml | 1 -
.../main/resources/assemblies/mac/assembly-mac.xml | 1 -
.../assemblies/windows/assembly-windows.xml | 1 -
cayenne-web/pom.xml | 93 -------
.../cayenne/configuration/web/CayenneFilter.java | 133 ----------
.../cayenne/configuration/web/RequestHandler.java | 35 ---
.../web/SessionContextRequestHandler.java | 88 -------
.../web/StatelessContextRequestHandler.java | 73 ------
.../configuration/web/WebConfiguration.java | 205 ---------------
.../cayenne/configuration/web/WebModule.java | 35 ---
.../configuration/web/WebServerModuleProvider.java | 43 ----
.../apache/cayenne/configuration/web/WebUtil.java | 54 ----
...onfiguration.server.CayenneServerModuleProvider | 20 --
.../configuration/web/CayenneFilterTest.java | 227 ----------------
.../web/CayenneFilter_DispatchModule.java | 29 ---
.../web/CayenneFilter_DispatchRequestHandler.java | 45 ----
.../cayenne/configuration/web/MockModule1.java | 30 ---
.../cayenne/configuration/web/MockModule2.java | 31 ---
.../configuration/web/MockRequestHandler.java | 33 ---
.../web/ServletContextHandlerTest.java | 124 ---------
.../configuration/web/WebConfigurationTest.java | 214 ---------------
.../configuration/web/WebModuleProviderTest.java | 30 ---
.../cayenne/configuration/web/WebModuleTest.java | 40 ---
.../cayenne/configuration/web/WebUtilTest.java | 50 ----
.../src/docs/asciidoc/_cayenne-guide/part5.adoc | 2 -
.../asciidoc/_cayenne-guide/part5/cayenneWeb.adoc | 40 ---
.../asciidoc/_getting-started-guide/webapp.adoc | 286 ---------------------
.../src/docs/asciidoc/getting-started-guide.adoc | 2 -
pom.xml | 1 -
tutorials/tutorial/pom.xml | 5 -
tutorials/tutorial/src/main/webapp/WEB-INF/web.xml | 41 ---
tutorials/tutorial/src/main/webapp/detail.jsp | 89 -------
tutorials/tutorial/src/main/webapp/index.jsp | 53 ----
34 files changed, 2160 deletions(-)
diff --git a/assembly/pom.xml b/assembly/pom.xml
index a2d48216d..8432e231b 100644
--- a/assembly/pom.xml
+++ b/assembly/pom.xml
@@ -118,12 +118,6 @@
<version>${project.version}</version>
</dependency>
- <dependency>
- <groupId>org.apache.cayenne</groupId>
- <artifactId>cayenne-web</artifactId>
- <version>${project.version}</version>
- </dependency>
-
<dependency>
<groupId>org.apache.cayenne</groupId>
<artifactId>cayenne-osgi</artifactId>
diff --git a/assembly/src/main/resources/assemblies/generic/assembly-generic.xml b/assembly/src/main/resources/assemblies/generic/assembly-generic.xml
index 126e019a3..000d197d7 100644
--- a/assembly/src/main/resources/assemblies/generic/assembly-generic.xml
+++ b/assembly/src/main/resources/assemblies/generic/assembly-generic.xml
@@ -81,7 +81,6 @@
<include>org.apache.cayenne:cayenne-project-compatibility</include>
<include>org.apache.cayenne:cayenne-server</include>
<include>org.apache.cayenne:cayenne-velocity</include>
- <include>org.apache.cayenne:cayenne-web</include>
</includes>
</dependencySet>
<dependencySet>
diff --git a/assembly/src/main/resources/assemblies/mac/assembly-mac.xml b/assembly/src/main/resources/assemblies/mac/assembly-mac.xml
index 047861d71..519cfbb40 100644
--- a/assembly/src/main/resources/assemblies/mac/assembly-mac.xml
+++ b/assembly/src/main/resources/assemblies/mac/assembly-mac.xml
@@ -79,7 +79,6 @@
<include>org.apache.cayenne:cayenne-project-compatibility</include>
<include>org.apache.cayenne:cayenne-server</include>
<include>org.apache.cayenne:cayenne-velocity</include>
- <include>org.apache.cayenne:cayenne-web</include>
</includes>
</dependencySet>
<dependencySet>
diff --git a/assembly/src/main/resources/assemblies/windows/assembly-windows.xml b/assembly/src/main/resources/assemblies/windows/assembly-windows.xml
index 460ba7500..ea769e6a8 100644
--- a/assembly/src/main/resources/assemblies/windows/assembly-windows.xml
+++ b/assembly/src/main/resources/assemblies/windows/assembly-windows.xml
@@ -79,7 +79,6 @@
<include>org.apache.cayenne:cayenne-project-compatibility</include>
<include>org.apache.cayenne:cayenne-server</include>
<include>org.apache.cayenne:cayenne-velocity</include>
- <include>org.apache.cayenne:cayenne-web</include>
</includes>
</dependencySet>
<dependencySet>
diff --git a/cayenne-web/pom.xml b/cayenne-web/pom.xml
deleted file mode 100644
index 60c9d31cc..000000000
--- a/cayenne-web/pom.xml
+++ /dev/null
@@ -1,93 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- 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
-
- https://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.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <parent>
- <artifactId>cayenne-parent</artifactId>
- <groupId>org.apache.cayenne</groupId>
- <version>4.3.M1-SNAPSHOT</version>
- </parent>
- <modelVersion>4.0.0</modelVersion>
-
- <artifactId>cayenne-web</artifactId>
- <name>cayenne-web: Cayenne Web Extensions</name>
- <packaging>jar</packaging>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.cayenne</groupId>
- <artifactId>cayenne-server</artifactId>
- <version>${project.version}</version>
- <scope>compile</scope>
- </dependency>
-
- <!-- Optional dependencies... things that might have been placed in submodules... -->
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>servlet-api</artifactId>
- <scope>provided</scope>
- <optional>true</optional>
- </dependency>
-
- <!-- Test dependencies -->
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>com.mockrunner</groupId>
- <artifactId>mockrunner-servlet</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-simple</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.cayenne</groupId>
- <artifactId>cayenne-server</artifactId>
- <version>${project.version}</version>
- <type>test-jar</type>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
- <build>
- <plugins>
- <!-- This ensures LICENSE and NOTICE inclusion in all jars -->
- <plugin>
- <artifactId>maven-remote-resources-plugin</artifactId>
- <executions>
- <execution>
- <goals>
- <goal>process</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
-</project>
\ No newline at end of file
diff --git a/cayenne-web/src/main/java/org/apache/cayenne/configuration/web/CayenneFilter.java b/cayenne-web/src/main/java/org/apache/cayenne/configuration/web/CayenneFilter.java
deleted file mode 100644
index 8cf2e6a48..000000000
--- a/cayenne-web/src/main/java/org/apache/cayenne/configuration/web/CayenneFilter.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*****************************************************************
- * 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
- *
- * https://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 org.apache.cayenne.configuration.CayenneRuntime;
-import org.apache.cayenne.configuration.server.ServerModule;
-import org.apache.cayenne.configuration.server.ServerRuntime;
-import org.apache.cayenne.di.Module;
-
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-
-/**
- * A filter that creates a Cayenne server runtime, possibly including custom modules. By
- * default runtime includes {@link ServerModule}. Any custom modules
- * are loaded after the two standard ones to allow custom service overrides. Filter
- * 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 filter name will be used to derive
- * the location. ".xml" extension will be appended to the filter name to get the location,
- * so a filter named "cayenne-foo" will result in location "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>
- * CayenneFilter is a great utility to quickly start a Cayenne application. More advanced
- * apps most likely will not use it, relying on their own configuration mechanism (such as
- * Guice, Spring, etc.)
- *
- * @since 3.1
- */
-public class CayenneFilter implements Filter {
-
- protected ServletContext servletContext;
-
- @Override
- public void init(FilterConfig config) throws ServletException {
-
- checkAlreadyConfigured(config.getServletContext());
-
- this.servletContext = config.getServletContext();
-
- WebConfiguration configAdapter = new WebConfiguration(config);
-
- String configurationLocation = configAdapter.getConfigurationLocation();
- String[] configurationLocations = null;
- if (configurationLocation != null) {
- configurationLocations = configurationLocation.split(",\\s*");
- }
- Collection<Module> modules = configAdapter.createModules();
- modules.addAll(getAdditionalModules());
-
- String dataDomainName = configAdapter.getDataDomainName();
-
- ServerRuntime runtime = ServerRuntime.builder(dataDomainName)
- .addConfigs(configurationLocations)
- .addModules(modules).build();
-
- WebUtil.setCayenneRuntime(config.getServletContext(), runtime);
- }
-
- /**
- * Subclasses may override this to specify additional modules that should be included when creating the CayenneRuntime
- * (in addition to those specified in the web.xml file).
- *
- * @since 4.0
- */
- protected Collection<Module> getAdditionalModules() {
- return new ArrayList<>();
- }
-
- protected void checkAlreadyConfigured(ServletContext context) throws ServletException {
- // sanity check
- if (WebUtil.getCayenneRuntime(context) != null) {
- throw new ServletException(
- "CayenneRuntime is already configured in the servlet environment");
- }
- }
-
- @Override
- public void destroy() {
- CayenneRuntime runtime = WebUtil.getCayenneRuntime(servletContext);
-
- if (runtime != null) {
- runtime.shutdown();
- }
- }
-
- @Override
- public void doFilter(
- ServletRequest request,
- ServletResponse response,
- FilterChain chain) throws IOException, ServletException {
-
- CayenneRuntime runtime = WebUtil.getCayenneRuntime(servletContext);
- RequestHandler handler = runtime.getInjector().getInstance(RequestHandler.class);
-
- handler.requestStart(request, response);
- try {
- chain.doFilter(request, response);
- }
- finally {
- handler.requestEnd(request, response);
- }
- }
-}
diff --git a/cayenne-web/src/main/java/org/apache/cayenne/configuration/web/RequestHandler.java b/cayenne-web/src/main/java/org/apache/cayenne/configuration/web/RequestHandler.java
deleted file mode 100644
index 680abc52d..000000000
--- a/cayenne-web/src/main/java/org/apache/cayenne/configuration/web/RequestHandler.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*****************************************************************
- * 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
- *
- * https://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 javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-
-/**
- * A service invoked by {@link CayenneFilter} that provides a callback mechanism to bind
- * appropriate ObjectContext to the request thread, handle transactions, etc.
- *
- * @since 3.1
- */
-public interface RequestHandler {
-
- void requestStart(ServletRequest request, ServletResponse response);
-
- void requestEnd(ServletRequest request, ServletResponse response);
-}
diff --git a/cayenne-web/src/main/java/org/apache/cayenne/configuration/web/SessionContextRequestHandler.java b/cayenne-web/src/main/java/org/apache/cayenne/configuration/web/SessionContextRequestHandler.java
deleted file mode 100644
index b04cb70c4..000000000
--- a/cayenne-web/src/main/java/org/apache/cayenne/configuration/web/SessionContextRequestHandler.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*****************************************************************
- * 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
- *
- * https://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 javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
-
-import org.apache.cayenne.BaseContext;
-import org.apache.cayenne.ObjectContext;
-import org.apache.cayenne.configuration.CayenneRuntime;
-import org.apache.cayenne.configuration.ObjectContextFactory;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.di.Injector;
-
-/**
- * Default implementation of the {@link RequestHandler} that stores per-user
- * {@link ObjectContext} in a web session and binds it to request thread. Note that using
- * this handler would force {@link HttpSession} creation, that may not be desirable in
- * many cases. Also session-bound context may result in a race condition with two user
- * requests updating the same persistent objects in parallel.
- * <p>
- * User applications in most cases should provide a custom RequestHandler that implements
- * a smarter app-specific strategy for providing ObjectContext.
- * <p>
- * For stateless (per request) context creation use {@link StatelessContextRequestHandler}.
- *
- * @since 3.1
- */
-public class SessionContextRequestHandler implements RequestHandler {
-
- static final String SESSION_CONTEXT_KEY = SessionContextRequestHandler.class
- .getName()
- + ".SESSION_CONTEXT";
-
- // using injector to lookup services instead of injecting them directly for lazy
- // startup and "late binding"
- @Inject
- private Injector injector;
-
- public void requestStart(ServletRequest request, ServletResponse response) {
-
- CayenneRuntime.bindThreadInjector(injector);
-
- if (request instanceof HttpServletRequest) {
-
- // this forces session creation if it does not exist yet
- HttpSession session = ((HttpServletRequest) request).getSession();
-
- ObjectContext context;
- synchronized (session) {
- context = (ObjectContext) session.getAttribute(SESSION_CONTEXT_KEY);
-
- if (context == null) {
- context = injector
- .getInstance(ObjectContextFactory.class)
- .createContext();
- session.setAttribute(SESSION_CONTEXT_KEY, context);
- }
- }
-
- BaseContext.bindThreadObjectContext(context);
- }
- }
-
- public void requestEnd(ServletRequest request, ServletResponse response) {
- CayenneRuntime.bindThreadInjector(null);
- BaseContext.bindThreadObjectContext(null);
- }
-
-}
diff --git a/cayenne-web/src/main/java/org/apache/cayenne/configuration/web/StatelessContextRequestHandler.java b/cayenne-web/src/main/java/org/apache/cayenne/configuration/web/StatelessContextRequestHandler.java
deleted file mode 100644
index 2561ce549..000000000
--- a/cayenne-web/src/main/java/org/apache/cayenne/configuration/web/StatelessContextRequestHandler.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*****************************************************************
- * 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
- *
- * https://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 javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-
-import org.apache.cayenne.BaseContext;
-import org.apache.cayenne.ObjectContext;
-import org.apache.cayenne.configuration.CayenneRuntime;
-import org.apache.cayenne.configuration.ObjectContextFactory;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.di.Injector;
-import org.apache.cayenne.di.Module;
-
-/**
- * <p>Stateless implementation of {@link RequestHandler} that creates a new
- * {@link ObjectContext} for each request and binds it to the request thread.
- * <p>
- * This is an alternative to the session-based request handler
- * {@link SessionContextRequestHandler} which is the default.
- * <p>
- * The request handler can be used by injecting it with a custom @{link Module}, like so:
- *
-<pre><code>
-import org.apache.cayenne.configuration.web.RequestHandler;
-import org.apache.cayenne.configuration.web.StatelessContextRequestHandler;
-import org.apache.cayenne.di.Binder;
-import org.apache.cayenne.di.Module;
-public class AppModule implements Module {
- public void configure(Binder binder) {
- binder.bind(RequestHandler.class).to(StatelessContextRequestHandler.class);
- }
-}
-</code></pre>
- *
- * @since 4.0
- */
-public class StatelessContextRequestHandler implements RequestHandler {
-
- // using injector to lookup services instead of injecting them directly for lazy
- // startup and "late binding"
- @Inject
- private Injector injector;
-
- public void requestStart(ServletRequest request, ServletResponse response) {
- CayenneRuntime.bindThreadInjector(injector);
- ObjectContext context = injector.getInstance(ObjectContextFactory.class).createContext();
- BaseContext.bindThreadObjectContext(context);
- }
-
- public void requestEnd(ServletRequest request, ServletResponse response) {
- CayenneRuntime.bindThreadInjector(null);
- BaseContext.bindThreadObjectContext(null);
- }
-
-}
diff --git a/cayenne-web/src/main/java/org/apache/cayenne/configuration/web/WebConfiguration.java b/cayenne-web/src/main/java/org/apache/cayenne/configuration/web/WebConfiguration.java
deleted file mode 100644
index ad972d8f6..000000000
--- a/cayenne-web/src/main/java/org/apache/cayenne/configuration/web/WebConfiguration.java
+++ /dev/null
@@ -1,205 +0,0 @@
-/*****************************************************************
- * 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
- *
- * https://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 org.apache.cayenne.configuration.server.PropertyDataSourceFactory;
-import org.apache.cayenne.configuration.server.ServerRuntimeBuilder;
-import org.apache.cayenne.di.Module;
-import org.apache.cayenne.util.Util;
-
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
-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;
-
-/**
- * A class that provides access to common Cayenne web configuration parameters retrieved
- * either from a FilterConfig or a ServletConfig configuration.
- *
- * @since 3.1
- */
-public class WebConfiguration {
-
- static final String CONFIGURATION_LOCATION_PARAMETER = "configuration-location";
- static final String EXTRA_MODULES_PARAMETER = "extra-modules";
-
- /**
- * @since 4.1
- */
- static final String DATA_DOMAIN_NAME_PARAMETER = "data-domain-name";
-
- 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 an XML Cayenne configuration, extracted from the
- * filter or servlet configuration parameters.
- */
- public String getConfigurationLocation() {
- String configurationLocation = configuration
- .getInitParameter(CONFIGURATION_LOCATION_PARAMETER);
-
- if (configurationLocation != null) {
- return configurationLocation;
- }
-
- String name = configuration.getFilterName();
-
- if (name == null) {
- return null;
- }
-
- if (!name.endsWith(".xml")) {
- name = name + ".xml";
- }
-
- return name;
- }
-
- /**
- * If you are using multiple configuration files (cayenne-*.xml) this allows you
- * to specify a name for the data domain other than the default name "cayenne"
- * (see {@link ServerRuntimeBuilder}).
- * A specific data domain name is useful if you are setting database connection info
- * using properties via {@link PropertyDataSourceFactory}.
- * @since 4.1
- */
- public String getDataDomainName() {
- return configuration.getInitParameter(DATA_DOMAIN_NAME_PARAMETER);
- }
-
- /**
- * 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<>();
- Collection<Module> modules = new ArrayList<>();
-
- 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 all init parameters from the underlying FilterConfig or
- * ServletConfig object.
- */
- public Map<String, String> getParameters() {
- Enumeration<?> en = configuration.getInitParameterNames();
-
- if (!en.hasMoreElements()) {
- return Collections.emptyMap();
- }
-
- Map<String, String> parameters = new HashMap<>();
- while (en.hasMoreElements()) {
- String key = (String) en.nextElement();
- parameters.put(key, configuration.getInitParameter(key));
- }
-
- return parameters;
- }
-
- /**
- * Returns servlet or filter init parameters, excluding those recognized by
- * WebConfiguration. Namely 'configuration-location' and 'extra-modules' parameters
- * are removed from the returned map.
- */
- public Map<String, String> getOtherParameters() {
-
- Map<String, String> parameters = getParameters();
-
- if (!parameters.isEmpty()) {
- parameters.remove(CONFIGURATION_LOCATION_PARAMETER);
- parameters.remove(EXTRA_MODULES_PARAMETER);
- }
-
- return parameters;
- }
-}
diff --git a/cayenne-web/src/main/java/org/apache/cayenne/configuration/web/WebModule.java b/cayenne-web/src/main/java/org/apache/cayenne/configuration/web/WebModule.java
deleted file mode 100644
index 577feb18e..000000000
--- a/cayenne-web/src/main/java/org/apache/cayenne/configuration/web/WebModule.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*****************************************************************
- * 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
- *
- * https://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 org.apache.cayenne.di.Binder;
-import org.apache.cayenne.di.Module;
-
-/**
- * @since 3.1
- */
-public class WebModule implements Module {
-
- public void configure(Binder binder) {
- binder
- .bind(RequestHandler.class)
- .to(SessionContextRequestHandler.class)
- .withoutScope();
- }
-}
diff --git a/cayenne-web/src/main/java/org/apache/cayenne/configuration/web/WebServerModuleProvider.java b/cayenne-web/src/main/java/org/apache/cayenne/configuration/web/WebServerModuleProvider.java
deleted file mode 100644
index 55e98ebe4..000000000
--- a/cayenne-web/src/main/java/org/apache/cayenne/configuration/web/WebServerModuleProvider.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*****************************************************************
- * 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
- *
- * https://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 org.apache.cayenne.configuration.server.CayenneServerModuleProvider;
-import org.apache.cayenne.di.Module;
-
-import java.util.Collection;
-import java.util.Collections;
-
-public class WebServerModuleProvider implements CayenneServerModuleProvider{
-
- @Override
- public Module module() {
- return new WebModule();
- }
-
- @Override
- public Class<? extends Module> moduleType() {
- return WebModule.class;
- }
-
- @Override
- public Collection<Class<? extends Module>> overrides() {
- return Collections.emptyList();
- }
-}
\ No newline at end of file
diff --git a/cayenne-web/src/main/java/org/apache/cayenne/configuration/web/WebUtil.java b/cayenne-web/src/main/java/org/apache/cayenne/configuration/web/WebUtil.java
deleted file mode 100644
index 11a283f70..000000000
--- a/cayenne-web/src/main/java/org/apache/cayenne/configuration/web/WebUtil.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*****************************************************************
- * 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
- *
- * https://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 javax.servlet.ServletContext;
-
-import org.apache.cayenne.configuration.CayenneRuntime;
-
-/**
- * A helper class to retrieve and store {@link CayenneRuntime} in the
- * {@link ServletContext}. All Cayenne web configuration objects, such as
- * {@link CayenneFilter} and {@link org.apache.cayenne.rop.ROPServlet}, are using this class to access
- * runtime.
- *
- * @since 3.1
- */
-public class WebUtil {
-
- static final String CAYENNE_RUNTIME_KEY = WebUtil.class.getName()
- + ".CAYENNE_RUNTIME";
-
- /**
- * Retrieves CayenneRuntime previously stored in provided context via
- * {@link #setCayenneRuntime(ServletContext, CayenneRuntime)}. May return null if no
- * runtime was stored.
- */
- public static CayenneRuntime getCayenneRuntime(ServletContext context) {
- return (CayenneRuntime) context.getAttribute(CAYENNE_RUNTIME_KEY);
- }
-
- /**
- * Stores {@link CayenneRuntime} in the servlet context. It can be later retrieve via
- * {@link #getCayenneRuntime(ServletContext)}.
- */
- public static void setCayenneRuntime(ServletContext context, CayenneRuntime runtime) {
- context.setAttribute(CAYENNE_RUNTIME_KEY, runtime);
- }
-}
diff --git a/cayenne-web/src/main/resources/META-INF/services/org.apache.cayenne.configuration.server.CayenneServerModuleProvider b/cayenne-web/src/main/resources/META-INF/services/org.apache.cayenne.configuration.server.CayenneServerModuleProvider
deleted file mode 100644
index 21f595930..000000000
--- a/cayenne-web/src/main/resources/META-INF/services/org.apache.cayenne.configuration.server.CayenneServerModuleProvider
+++ /dev/null
@@ -1,20 +0,0 @@
-##################################################################
-# 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
-#
-# https://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.
-##################################################################
-
-org.apache.cayenne.configuration.web.WebServerModuleProvider
\ No newline at end of file
diff --git a/cayenne-web/src/test/java/org/apache/cayenne/configuration/web/CayenneFilterTest.java b/cayenne-web/src/test/java/org/apache/cayenne/configuration/web/CayenneFilterTest.java
deleted file mode 100644
index a1f306339..000000000
--- a/cayenne-web/src/test/java/org/apache/cayenne/configuration/web/CayenneFilterTest.java
+++ /dev/null
@@ -1,227 +0,0 @@
-/*****************************************************************
- * 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
- *
- * https://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 com.mockrunner.mock.web.MockFilterChain;
-import com.mockrunner.mock.web.MockFilterConfig;
-import com.mockrunner.mock.web.MockHttpServletRequest;
-import com.mockrunner.mock.web.MockHttpServletResponse;
-import com.mockrunner.mock.web.MockServletContext;
-import org.apache.cayenne.configuration.CayenneRuntime;
-import org.apache.cayenne.configuration.Constants;
-import org.apache.cayenne.configuration.server.ServerModule;
-import org.apache.cayenne.di.Key;
-import org.apache.cayenne.di.Module;
-import org.junit.Test;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-public class CayenneFilterTest {
-
- @Test
- public void testInitWithFilterName() throws Exception {
-
- MockFilterConfig config = new MockFilterConfig();
- config.setFilterName("abc");
-
- MockServletContext context = new MockServletContext();
- config.setupServletContext(context);
-
- CayenneFilter filter = new CayenneFilter();
-
- assertNull(WebUtil.getCayenneRuntime(context));
- filter.init(config);
-
- CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
- assertNotNull(runtime);
-
- List<String> locations = runtime.getInjector()
- .getInstance(Key.getListOf(String.class, Constants.SERVER_PROJECT_LOCATIONS_LIST));
-
- assertEquals(Collections.singletonList("abc.xml"), locations);
- }
-
- @Test
- public void testInitWithLocation() throws Exception {
-
- MockFilterConfig config = new MockFilterConfig();
- config.setFilterName("abc");
- config.setInitParameter(WebConfiguration.CONFIGURATION_LOCATION_PARAMETER, "xyz");
-
- MockServletContext context = new MockServletContext();
- config.setupServletContext(context);
-
- CayenneFilter filter = new CayenneFilter();
- filter.init(config);
-
- CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
- assertNotNull(runtime);
- List<String> locations = runtime.getInjector()
- .getInstance(Key.getListOf(String.class, Constants.SERVER_PROJECT_LOCATIONS_LIST));
-
- assertEquals(Collections.singletonList("xyz"), locations);
- }
-
- @Test
- public void testInitWithMultipleLocations() throws Exception {
-
- MockFilterConfig config = new MockFilterConfig();
- config.setFilterName("abc");
- config.setInitParameter(WebConfiguration.CONFIGURATION_LOCATION_PARAMETER, "xyz,abc,\tdef, \n ghi");
-
- MockServletContext context = new MockServletContext();
- config.setupServletContext(context);
-
- CayenneFilter filter = new CayenneFilter();
- filter.init(config);
-
- CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
- assertNotNull(runtime);
- List<String> locations = runtime.getInjector()
- .getInstance(Key.getListOf(String.class, Constants.SERVER_PROJECT_LOCATIONS_LIST));
-
- assertEquals(Arrays.asList("xyz", "abc", "def", "ghi"), locations);
- }
-
- @Test
- public void testInitWithCustomDomainName() throws Exception {
- MockFilterConfig config = new MockFilterConfig();
- config.setFilterName("abc");
- config.setInitParameter(WebConfiguration.DATA_DOMAIN_NAME_PARAMETER, "custom");
-
- MockServletContext context = new MockServletContext();
- config.setupServletContext(context);
-
- CayenneFilter filter = new CayenneFilter();
- filter.init(config);
-
- CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
- assertNotNull(runtime);
-
- String domainName = runtime.getInjector()
- .getInstance(Key.getMapOf(String.class, String.class, Constants.PROPERTIES_MAP))
- .get(Constants.SERVER_DOMAIN_NAME_PROPERTY);
- assertEquals("custom", domainName);
- }
-
- @Test
- public void testInitWithStandardModules() throws Exception {
-
- MockFilterConfig config = new MockFilterConfig();
- config.setFilterName("cayenne-abc");
-
- MockServletContext context = new MockServletContext();
- config.setupServletContext(context);
-
- CayenneFilter filter = new CayenneFilter();
-
- assertNull(WebUtil.getCayenneRuntime(context));
- filter.init(config);
-
- CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
- assertNotNull(runtime);
- List<String> locations = runtime.getInjector()
- .getInstance(Key.getListOf(String.class, Constants.SERVER_PROJECT_LOCATIONS_LIST));
-
- assertEquals(Collections.singletonList("cayenne-abc.xml"), locations);
- Collection<Module> modules = runtime.getModules();
- assertEquals(3, modules.size());
-
- Object[] marray = modules.toArray();
-
- if (marray[0] instanceof ServerModule) {
- assertTrue(marray[1] instanceof WebModule);
- } else {
- assertTrue(marray[0] instanceof WebModule);
- }
-
- RequestHandler handler = runtime.getInjector().getInstance(RequestHandler.class);
- assertTrue(handler instanceof SessionContextRequestHandler);
- }
-
- @Test
- public void testInitWithExtraModules() throws Exception {
-
- MockFilterConfig config = new MockFilterConfig();
- config.setFilterName("abc");
- config.setInitParameter(WebConfiguration.EXTRA_MODULES_PARAMETER,
- MockModule1.class.getName() + "," + MockModule2.class.getName());
-
- MockServletContext context = new MockServletContext();
- config.setupServletContext(context);
-
- CayenneFilter filter = new CayenneFilter();
- filter.init(config);
-
- CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
- assertNotNull(runtime);
-
- Collection<Module> modules = runtime.getModules();
- assertEquals(5, modules.size());
-
-
- Object[] marray = modules.toArray();
- if (marray[0] instanceof ServerModule) {
- assertTrue(marray[1] instanceof WebModule);
- } else {
- assertTrue(marray[0] instanceof WebModule);
- }
- assertTrue(marray[2] instanceof MockModule1);
- assertTrue(marray[3] instanceof MockModule2);
-
- RequestHandler handler = runtime.getInjector().getInstance(RequestHandler.class);
- assertTrue(handler instanceof MockRequestHandler);
- }
-
- @Test
- public void testDoFilter() throws Exception {
- MockFilterConfig config = new MockFilterConfig();
- config.setFilterName("abc");
- config.setInitParameter(WebConfiguration.EXTRA_MODULES_PARAMETER, CayenneFilter_DispatchModule.class.getName());
-
- MockServletContext context = new MockServletContext();
- config.setupServletContext(context);
-
- CayenneFilter filter = new CayenneFilter();
- filter.init(config);
-
- CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
- CayenneFilter_DispatchRequestHandler handler = (CayenneFilter_DispatchRequestHandler) runtime.getInjector()
- .getInstance(RequestHandler.class);
-
- assertEquals(0, handler.getStarted());
- assertEquals(0, handler.getEnded());
-
- filter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(), new MockFilterChain());
- assertEquals(1, handler.getStarted());
- assertEquals(1, handler.getEnded());
-
- filter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(), new MockFilterChain());
- assertEquals(2, handler.getStarted());
- assertEquals(2, handler.getEnded());
- }
-}
diff --git a/cayenne-web/src/test/java/org/apache/cayenne/configuration/web/CayenneFilter_DispatchModule.java b/cayenne-web/src/test/java/org/apache/cayenne/configuration/web/CayenneFilter_DispatchModule.java
deleted file mode 100644
index 67d440c66..000000000
--- a/cayenne-web/src/test/java/org/apache/cayenne/configuration/web/CayenneFilter_DispatchModule.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*****************************************************************
- * 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
- *
- * https://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 org.apache.cayenne.di.Binder;
-import org.apache.cayenne.di.Module;
-
-public class CayenneFilter_DispatchModule implements Module {
-
- public void configure(Binder binder) {
- binder.bind(RequestHandler.class).to(CayenneFilter_DispatchRequestHandler.class);
- }
-}
diff --git a/cayenne-web/src/test/java/org/apache/cayenne/configuration/web/CayenneFilter_DispatchRequestHandler.java b/cayenne-web/src/test/java/org/apache/cayenne/configuration/web/CayenneFilter_DispatchRequestHandler.java
deleted file mode 100644
index 3ca021ff4..000000000
--- a/cayenne-web/src/test/java/org/apache/cayenne/configuration/web/CayenneFilter_DispatchRequestHandler.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*****************************************************************
- * 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
- *
- * https://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 javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-
-public class CayenneFilter_DispatchRequestHandler implements RequestHandler {
-
- private int started;
- private int ended;
-
- public void requestEnd(ServletRequest request, ServletResponse response) {
- ended++;
- }
-
- public void requestStart(ServletRequest request, ServletResponse response) {
- started++;
- }
-
- public int getStarted() {
- return started;
- }
-
- public int getEnded() {
- return ended;
- }
-
-}
diff --git a/cayenne-web/src/test/java/org/apache/cayenne/configuration/web/MockModule1.java b/cayenne-web/src/test/java/org/apache/cayenne/configuration/web/MockModule1.java
deleted file mode 100644
index e3c99403c..000000000
--- a/cayenne-web/src/test/java/org/apache/cayenne/configuration/web/MockModule1.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*****************************************************************
- * 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
- *
- * https://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 org.apache.cayenne.di.Binder;
-import org.apache.cayenne.di.Module;
-
-
-public class MockModule1 implements Module {
-
- public void configure(Binder binder) {
- }
-
-}
diff --git a/cayenne-web/src/test/java/org/apache/cayenne/configuration/web/MockModule2.java b/cayenne-web/src/test/java/org/apache/cayenne/configuration/web/MockModule2.java
deleted file mode 100644
index 1bd3e5e85..000000000
--- a/cayenne-web/src/test/java/org/apache/cayenne/configuration/web/MockModule2.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*****************************************************************
- * 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
- *
- * https://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 org.apache.cayenne.di.Binder;
-import org.apache.cayenne.di.Module;
-
-public class MockModule2 implements Module {
-
- public void configure(Binder binder) {
- binder.bind(RequestHandler.class).to(MockRequestHandler.class);
- }
-
-}
diff --git a/cayenne-web/src/test/java/org/apache/cayenne/configuration/web/MockRequestHandler.java b/cayenne-web/src/test/java/org/apache/cayenne/configuration/web/MockRequestHandler.java
deleted file mode 100644
index 37a652eb1..000000000
--- a/cayenne-web/src/test/java/org/apache/cayenne/configuration/web/MockRequestHandler.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*****************************************************************
- * 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
- *
- * https://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 javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-
-
-public class MockRequestHandler implements RequestHandler {
-
- public void requestEnd(ServletRequest request, ServletResponse response) {
- }
-
- public void requestStart(ServletRequest request, ServletResponse response) {
- }
-
-}
diff --git a/cayenne-web/src/test/java/org/apache/cayenne/configuration/web/ServletContextHandlerTest.java b/cayenne-web/src/test/java/org/apache/cayenne/configuration/web/ServletContextHandlerTest.java
deleted file mode 100644
index 706f645b9..000000000
--- a/cayenne-web/src/test/java/org/apache/cayenne/configuration/web/ServletContextHandlerTest.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*****************************************************************
- * 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
- *
- * https://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 com.mockrunner.mock.web.MockHttpServletRequest;
-import com.mockrunner.mock.web.MockHttpServletResponse;
-import com.mockrunner.mock.web.MockHttpSession;
-import org.apache.cayenne.BaseContext;
-import org.apache.cayenne.DataChannel;
-import org.apache.cayenne.MockDataChannel;
-import org.apache.cayenne.ObjectContext;
-import org.apache.cayenne.configuration.ObjectContextFactory;
-import org.apache.cayenne.di.DIBootstrap;
-import org.apache.cayenne.di.Injector;
-import org.apache.cayenne.di.Module;
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.mock;
-
-public class ServletContextHandlerTest {
-
- @Test
- public void testRequestStart_bindContext() {
-
- Module module = binder -> {
-
- binder.bind(DataChannel.class).to(MockDataChannel.class);
- binder.bind(ObjectContextFactory.class).toInstance(
- new ObjectContextFactory() {
-
- public ObjectContext createContext(DataChannel parent) {
- return mock(ObjectContext.class);
- }
-
- public ObjectContext createContext() {
- return mock(ObjectContext.class);
- }
- });
- };
- Injector injector = DIBootstrap.createInjector(module);
- SessionContextRequestHandler handler = new SessionContextRequestHandler();
- injector.injectMembers(handler);
-
- MockHttpSession session = new MockHttpSession();
-
- BaseContext.bindThreadObjectContext(null);
-
- try {
-
- MockHttpServletRequest request1 = new MockHttpServletRequest();
- MockHttpServletResponse response1 = new MockHttpServletResponse();
- request1.setSession(session);
- handler.requestStart(request1, response1);
-
- ObjectContext c1 = BaseContext.getThreadObjectContext();
- assertNotNull(c1);
-
- handler.requestEnd(request1, response1);
-
- try {
- BaseContext.getThreadObjectContext();
- fail("thread context not null");
- }
- catch (IllegalStateException e) {
- // expected
- }
-
- MockHttpServletRequest request2 = new MockHttpServletRequest();
- MockHttpServletResponse response2 = new MockHttpServletResponse();
- request2.setSession(session);
- handler.requestStart(request2, response2);
-
- ObjectContext c2 = BaseContext.getThreadObjectContext();
- assertSame(c1, c2);
-
- handler.requestEnd(request2, response2);
- try {
- BaseContext.getThreadObjectContext();
- fail("thread context not null");
- }
- catch (IllegalStateException e) {
- // expected
- }
-
- MockHttpServletRequest request3 = new MockHttpServletRequest();
- MockHttpServletResponse response3 = new MockHttpServletResponse();
- request3.setSession(new MockHttpSession());
- handler.requestStart(request3, response3);
-
- ObjectContext c3 = BaseContext.getThreadObjectContext();
- assertNotNull(c3);
- assertNotSame(c1, c3);
-
- handler.requestEnd(request3, response3);
- try {
- BaseContext.getThreadObjectContext();
- fail("thread context not null");
- }
- catch (IllegalStateException e) {
- // expected
- }
- }
- finally {
- BaseContext.bindThreadObjectContext(null);
- }
- }
-}
diff --git a/cayenne-web/src/test/java/org/apache/cayenne/configuration/web/WebConfigurationTest.java b/cayenne-web/src/test/java/org/apache/cayenne/configuration/web/WebConfigurationTest.java
deleted file mode 100644
index 71cac8ca9..000000000
--- a/cayenne-web/src/test/java/org/apache/cayenne/configuration/web/WebConfigurationTest.java
+++ /dev/null
@@ -1,214 +0,0 @@
-/*****************************************************************
- * 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
- *
- * https://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 com.mockrunner.mock.web.MockFilterConfig;
-import com.mockrunner.mock.web.MockServletConfig;
-import org.apache.cayenne.di.Module;
-import org.junit.Test;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Map;
-
-import static org.junit.Assert.*;
-
-public class WebConfigurationTest {
-
- @Test
- public void testFilterCreateModules_Standard() throws Exception {
-
- MockFilterConfig config = new MockFilterConfig();
- WebConfiguration configuration = new WebConfiguration(config);
-
- Module m1 = binder -> {
- };
-
- Module m2 = binder -> {
- };
-
- Collection<Module> modules = configuration.createModules(m1, m2);
- assertEquals(2, modules.size());
-
- Iterator<Module> it = modules.iterator();
- assertSame(m1, it.next());
- assertSame(m2, it.next());
- }
-
- @Test
- public void testFilterCreateModules_Extra() throws Exception {
-
- MockFilterConfig config = new MockFilterConfig();
- String exra = String.format(
- "%s, \n%s",
- MockModule1.class.getName(),
- MockModule2.class.getName());
- config.setInitParameter(WebConfiguration.EXTRA_MODULES_PARAMETER, exra);
-
- WebConfiguration configuration = new WebConfiguration(config);
-
- Module m1 = binder -> {
- };
-
- Module m2 = binder -> {
- };
-
- Collection<Module> modules = configuration.createModules(m1, m2);
- assertEquals(4, modules.size());
-
- Iterator<Module> it = modules.iterator();
- assertSame(m1, it.next());
- assertSame(m2, it.next());
- assertTrue(it.next() instanceof MockModule1);
- assertTrue(it.next() instanceof MockModule2);
- }
-
- @Test
- public void testServletCreateModules_Extra() throws Exception {
-
- MockServletConfig config = new MockServletConfig();
- String exra = String.format(
- "%s, \n%s",
- MockModule1.class.getName(),
- MockModule2.class.getName());
- config.setInitParameter(WebConfiguration.EXTRA_MODULES_PARAMETER, exra);
-
- WebConfiguration configuration = new WebConfiguration(config);
-
- Module m1 = binder -> {
- };
-
- Module m2 = binder -> {
- };
-
- Collection<Module> modules = configuration.createModules(m1, m2);
- assertEquals(4, modules.size());
-
- Iterator<Module> it = modules.iterator();
- assertSame(m1, it.next());
- assertSame(m2, it.next());
- assertTrue(it.next() instanceof MockModule1);
- assertTrue(it.next() instanceof MockModule2);
- }
-
- @Test
- public void testFilterConfigurationLocation_Name() {
- MockFilterConfig config1 = new MockFilterConfig();
- config1.setFilterName("cayenne-x");
-
- WebConfiguration configuration1 = new WebConfiguration(config1);
- assertEquals("cayenne-x.xml", configuration1.getConfigurationLocation());
-
- MockFilterConfig config2 = new MockFilterConfig();
- config2.setFilterName("cayenne-y.xml");
-
- WebConfiguration configuration2 = new WebConfiguration(config2);
- assertEquals("cayenne-y.xml", configuration2.getConfigurationLocation());
-
- MockFilterConfig config3 = new MockFilterConfig();
- config3.setFilterName("a/b/c/cayenne-z.xml");
-
- WebConfiguration configuration3 = new WebConfiguration(config3);
- assertEquals("a/b/c/cayenne-z.xml", configuration3.getConfigurationLocation());
- }
-
- @Test
- public void testServletConfigurationLocation_Name() {
- MockServletConfig config1 = new MockServletConfig();
- config1.setServletName("cayenne-x");
-
- WebConfiguration configuration1 = new WebConfiguration(config1);
- assertEquals("cayenne-x.xml", configuration1.getConfigurationLocation());
-
- MockServletConfig config2 = new MockServletConfig();
- config2.setServletName("cayenne-y.xml");
-
- WebConfiguration configuration2 = new WebConfiguration(config2);
- assertEquals("cayenne-y.xml", configuration2.getConfigurationLocation());
-
- MockServletConfig config3 = new MockServletConfig();
- config3.setServletName("a/b/c/cayenne-z.xml");
-
- WebConfiguration configuration3 = new WebConfiguration(config3);
- assertEquals("a/b/c/cayenne-z.xml", configuration3.getConfigurationLocation());
- }
-
- @Test
- public void testFilterConfigurationLocation_Parameter() {
- MockFilterConfig config1 = new MockFilterConfig();
- config1.setFilterName("cayenne-x");
- config1.setInitParameter(
- WebConfiguration.CONFIGURATION_LOCATION_PARAMETER,
- "cayenne-y.xml");
-
- WebConfiguration configuration1 = new WebConfiguration(config1);
- assertEquals("cayenne-y.xml", configuration1.getConfigurationLocation());
- }
-
- @Test
- public void testServletConfigurationLocation_Parameter() {
- MockServletConfig config1 = new MockServletConfig();
- config1.setServletName("cayenne-x");
- config1.setInitParameter(
- WebConfiguration.CONFIGURATION_LOCATION_PARAMETER,
- "cayenne-y.xml");
-
- WebConfiguration configuration1 = new WebConfiguration(config1);
- assertEquals("cayenne-y.xml", configuration1.getConfigurationLocation());
- }
-
- @Test
- public void testFilterParameters() {
- MockFilterConfig config1 = new MockFilterConfig();
- config1.setFilterName("cayenne-x");
- config1.setInitParameter(
- WebConfiguration.CONFIGURATION_LOCATION_PARAMETER,
- "cayenne-y.xml");
- config1.setInitParameter("test", "xxx");
-
- WebConfiguration configuration1 = new WebConfiguration(config1);
- Map<String, String> parameters = configuration1.getParameters();
- assertNotSame(parameters, configuration1.getParameters());
- assertEquals(parameters, configuration1.getParameters());
-
- assertEquals(2, parameters.size());
- assertEquals("cayenne-y.xml", parameters
- .get(WebConfiguration.CONFIGURATION_LOCATION_PARAMETER));
- assertEquals("xxx", parameters.get("test"));
- }
-
- @Test
- public void testFilterOtherParameters() {
- MockFilterConfig config1 = new MockFilterConfig();
- config1.setFilterName("cayenne-x");
- config1.setInitParameter(
- WebConfiguration.CONFIGURATION_LOCATION_PARAMETER,
- "cayenne-y.xml");
- config1.setInitParameter(WebConfiguration.EXTRA_MODULES_PARAMETER, "M1,M2");
- config1.setInitParameter("test", "xxx");
-
- WebConfiguration configuration1 = new WebConfiguration(config1);
- Map<String, String> parameters = configuration1.getOtherParameters();
- assertNotSame(parameters, configuration1.getOtherParameters());
- assertEquals(parameters, configuration1.getOtherParameters());
-
- assertEquals(1, parameters.size());
- assertEquals("xxx", parameters.get("test"));
- }
-}
diff --git a/cayenne-web/src/test/java/org/apache/cayenne/configuration/web/WebModuleProviderTest.java b/cayenne-web/src/test/java/org/apache/cayenne/configuration/web/WebModuleProviderTest.java
deleted file mode 100644
index a4a392d47..000000000
--- a/cayenne-web/src/test/java/org/apache/cayenne/configuration/web/WebModuleProviderTest.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * 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
- *
- * https://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 org.apache.cayenne.configuration.server.CayenneServerModuleProvider;
-import org.apache.cayenne.unit.util.ModuleProviderChecker;
-import org.junit.Test;
-
-public class WebModuleProviderTest {
- @Test
- public void testProviderPresent() {
- ModuleProviderChecker.testProviderPresent(WebServerModuleProvider.class, CayenneServerModuleProvider.class);
- }
-}
\ No newline at end of file
diff --git a/cayenne-web/src/test/java/org/apache/cayenne/configuration/web/WebModuleTest.java b/cayenne-web/src/test/java/org/apache/cayenne/configuration/web/WebModuleTest.java
deleted file mode 100644
index 27ee168a3..000000000
--- a/cayenne-web/src/test/java/org/apache/cayenne/configuration/web/WebModuleTest.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*****************************************************************
- * 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
- *
- * https://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 org.apache.cayenne.di.Injector;
-import org.apache.cayenne.di.spi.DefaultInjector;
-import org.junit.Test;
-
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertTrue;
-
-public class WebModuleTest {
-
- @Test
- public void testBind_Scopes() {
-
- Injector injector = new DefaultInjector(new WebModule());
- RequestHandler handler = injector.getInstance(RequestHandler.class);
- assertTrue(handler instanceof SessionContextRequestHandler);
-
- RequestHandler handler1 = injector.getInstance(RequestHandler.class);
- assertNotSame("Incorrect singleton scope for request handler", handler, handler1);
- }
-}
diff --git a/cayenne-web/src/test/java/org/apache/cayenne/configuration/web/WebUtilTest.java b/cayenne-web/src/test/java/org/apache/cayenne/configuration/web/WebUtilTest.java
deleted file mode 100644
index 336f24924..000000000
--- a/cayenne-web/src/test/java/org/apache/cayenne/configuration/web/WebUtilTest.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*****************************************************************
- * 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
- *
- * https://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 com.mockrunner.mock.web.MockServletContext;
-import org.apache.cayenne.configuration.CayenneRuntime;
-import org.junit.Test;
-
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.mockito.Mockito.mock;
-
-public class WebUtilTest {
-
- @Test
- public void testGetCayenneRuntime() {
- MockServletContext context = new MockServletContext();
-
- assertNull(WebUtil.getCayenneRuntime(context));
-
- CayenneRuntime runtime = mock(CayenneRuntime.class);
-
- WebUtil.setCayenneRuntime(context, runtime);
- assertSame(runtime, WebUtil.getCayenneRuntime(context));
-
- CayenneRuntime runtime1 = mock(CayenneRuntime.class);
-
- WebUtil.setCayenneRuntime(context, runtime1);
- assertSame(runtime1, WebUtil.getCayenneRuntime(context));
-
- WebUtil.setCayenneRuntime(context, null);
- assertNull(WebUtil.getCayenneRuntime(context));
- }
-}
diff --git a/docs/asciidoc/cayenne-guide/src/docs/asciidoc/_cayenne-guide/part5.adoc b/docs/asciidoc/cayenne-guide/src/docs/asciidoc/_cayenne-guide/part5.adoc
index da902e9e5..c0cb192c9 100644
--- a/docs/asciidoc/cayenne-guide/src/docs/asciidoc/_cayenne-guide/part5.adoc
+++ b/docs/asciidoc/cayenne-guide/src/docs/asciidoc/_cayenne-guide/part5.adoc
@@ -26,6 +26,4 @@ include::part5/projectCompatibility.adoc[]
include::part5/apacheVelocity.adoc[]
-include::part5/cayenneWeb.adoc[]
-
include::part5/cayenneOsgi.adoc[]
diff --git a/docs/asciidoc/cayenne-guide/src/docs/asciidoc/_cayenne-guide/part5/cayenneWeb.adoc b/docs/asciidoc/cayenne-guide/src/docs/asciidoc/_cayenne-guide/part5/cayenneWeb.adoc
deleted file mode 100644
index d1a2c8ad9..000000000
--- a/docs/asciidoc/cayenne-guide/src/docs/asciidoc/_cayenne-guide/part5/cayenneWeb.adoc
+++ /dev/null
@@ -1,40 +0,0 @@
-// 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
-//
-// https://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.
-
-include::../var.adoc[]
-
-[#ext-web]
-=== Cayenne Web Extension
-
-Provides basic utilities to bootstrap Cayenne service inside web application.
-
-==== Maven
-
-[source, XML,subs="verbatim,attributes"]
-----
-<dependency>
- <groupId>org.apache.cayenne</groupId>
- <artifactId>cayenne-web</artifactId>
- <version>{version}</version>
-</dependency>
-----
-
-==== Gradle
-
-[source, Groovy,subs="verbatim,attributes"]
-----
-compile 'org.apache.cayenne:cayenne-web:{version}'
-----
-
-
diff --git a/docs/asciidoc/getting-started-guide/src/docs/asciidoc/_getting-started-guide/webapp.adoc b/docs/asciidoc/getting-started-guide/src/docs/asciidoc/_getting-started-guide/webapp.adoc
deleted file mode 100644
index 5b1013eb8..000000000
--- a/docs/asciidoc/getting-started-guide/src/docs/asciidoc/_getting-started-guide/webapp.adoc
+++ /dev/null
@@ -1,286 +0,0 @@
-// 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
-//
-// https://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.
-== Converting to Web Application
-This chapter shows how to work with Cayenne in a web application.
-
-=== Converting Tutorial to a Web Application
-The web part of the web application tutorial is done in JSP, which is the least common
-denominator of the Java web technologies, and is intentionally simplistic from the UI
-perspective, to concentrate on Cayenne integration aspect, rather than the interface. A
-typical Cayenne web application works like this:
-
-- Cayenne configuration is loaded when an application context is started, using a special servlet filter.
-- User requests are intercepted by the filter, and the DataContext is bound to
-the request thread, so the application can access it easily from anywhere.
-- The same DataContext instance is reused within a single user session;
-different sessions use different DataContexts (and therefore different sets of
-objects). _The context can be scoped differently
-depending on the app specifics. For the tutorial we'll be using a
-session-scoped context._
-
-So let's convert the tutorial that we created to a web application:
-
-- In IDEA under "tutorial" project folder create a new folder `src/main/webapp/WEB-INF`.
-- Under `WEB-INF` create a new file `web.xml` (a standard web app descriptor):
-
-.web.xml
-[source,xml]
-----
-<?xml version="1.0" encoding="utf-8"?>
-<!DOCTYPE web-app
- PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
- "http://java.sun.com/dtd/web-app_2_3.dtd">
-<web-app>
- <display-name>Cayenne Tutorial</display-name>
-
- <!-- This filter bootstraps ServerRuntime and then provides each request thread
- with a session-bound DataContext. Note that the name of the filter is important,
- as it points it to the right named configuration file.
- -->
- <filter>
- <filter-name>cayenne-project</filter-name>
- <filter-class>org.apache.cayenne.configuration.web.CayenneFilter</filter-class>
- </filter>
- <filter-mapping>
- <filter-name>cayenne-project</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
- <welcome-file-list>
- <welcome-file>index.jsp</welcome-file>
- </welcome-file-list>
-</web-app>
-----
-
-- Create the artist browser page `src/main/webapp/index.jsp` file with the following contents:
-
-.webapp/index.jsp
-[source,jsp]
-----
-<%@ page language="java" contentType="text/html" %>
-<%@ page import="org.example.cayenne.persistent.*" %>
-<%@ page import="org.apache.cayenne.*" %>
-<%@ page import="org.apache.cayenne.query.*" %>
-<%@ page import="org.apache.cayenne.exp.*" %>
-<%@ page import="java.util.*" %>
-
-<%
- ObjectContext context = BaseContext.getThreadObjectContext();
- List<Artist> artists = ObjectSelect.query(Artist.class)
- .orderBy(Artist.NAME.asc())
- .select(context);
-%>
-
-<html>
- <head>
- <title>Main</title>
- </head>
- <body>
- <h2>Artists:</h2>
-
- <% if(artists.isEmpty()) {%>
- <p>No artists found</p>
- <% } else {
- for(Artist a : artists) {
- %>
- <p><a href="detail.jsp?id=<%=Cayenne.intPKForObject(a)%>"> <%=a.getName()%> </a></p>
- <%
- }
- } %>
- <hr>
- <p><a href="detail.jsp">Create new artist...</a></p>
- </body>
-</html>
-----
-
-- Create the artist editor page `src/main/webapp/detail.jsp` with the following content:
-
-.webapp/detail.jsp
-[source,jsp]
-----
-<%@ page language="java" contentType="text/html" %>
-<%@ page import="org.example.cayenne.persistent.*" %>
-<%@ page import="org.apache.cayenne.*" %>
-<%@ page import="org.apache.cayenne.query.*" %>
-<%@ page import="java.util.*" %>
-<%@ page import="java.text.*" %>
-<%@ page import="java.time.format.DateTimeFormatter" %>
-
-<%
- ObjectContext context = BaseContext.getThreadObjectContext();
- String id = request.getParameter("id");
-
- // find artist for id
- Artist artist = null;
- if(id != null && id.trim().length() > 0) {
- artist = SelectById.query(Artist.class, Integer.parseInt(id)).selectOne(context);
- }
-
- if("POST".equals(request.getMethod())) {
- // if no id is saved in the hidden field, we are dealing with
- // create new artist request
- if(artist == null) {
- artist = context.newObject(Artist.class);
- }
-
- // note that in a real application we would so dome validation ...
- // here we just hope the input is correct
- artist.setName(request.getParameter("name"));
- artist.setDateOfBirthString(request.getParameter("dateOfBirth"));
-
- context.commitChanges();
-
- response.sendRedirect("index.jsp");
- }
-
- if(artist == null) {
- // create transient artist for the form response rendering
- artist = new Artist();
- }
-
- String name = artist.getName() == null ? "" : artist.getName();
-
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
- String dob = artist.getDateOfBirth() == null
- ? "" :artist.getDateOfBirth().format(formatter);
-%>
-<html>
- <head>
- <title>Artist Details</title>
- </head>
- <body>
- <h2>Artists Details</h2>
- <form name="EditArtist" action="detail.jsp" method="POST">
- <input type="hidden" name="id" value="<%= id != null ? id : "" %>" />
- <table border="0">
- <tr>
- <td>Name:</td>
- <td><input type="text" name="name" value="<%= name %>"/></td>
- </tr>
- <tr>
- <td>Date of Birth (yyyyMMdd):</td>
- <td><input type="text" name="dateOfBirth" value="<%= dob %>"/></td>
- </tr>
- <tr>
- <td></td>
- <td align="right"><input type="submit" value="Save" /></td>
- </tr>
- </table>
- </form>
- </body>
-</html>
-----
-
-==== Running Web Application
-
-We need to add cayenne-web module and javax servlet-api for our application.
-
-.pom.xml
-[source,xml]
-----
-<dependency>
- <groupId>org.apache.cayenne</groupId>
- <artifactId>cayenne-web</artifactId>
- <version>${cayenne.version}</version>
-</dependency>
-<dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>javax.servlet-api</artifactId>
- <version>3.1.0</version>
- <scope>provided</scope>
-</dependency>
-----
-
-Also to run the web application we'll use "maven-jetty-plugin". To activate it,
-let's add the following piece of code to the `pom.xml` file, following the "dependencies"
-section and save the POM:
-
-.pom.xml
-[source,xml]
-----
-<build>
- <plugins>
- <plugin>
- <groupId>org.eclipse.jetty</groupId>
- <artifactId>jetty-maven-plugin</artifactId>
- <version>9.4.8.v20171121</version>
- </plugin>
- </plugins>
-</build>
-----
-
-- Go to "Select Run/Debug Configuration" menu, and then "Edit Configuration..."
-
-image::idea-edit-configurations.png[align="center"]
-
-
-- Click `+` button and select "Maven". Enter "Name" and "Command line" as shown on screenshot:
-
-image:idea-run-configuration.png[]
-
-- Click "Apply" and "Run". On the first execution it may take a few minutes for
-Jetty plugin to download all dependencies, but eventually you'll see the logs
-like this:
-
- [INFO] ------------------------------------------------------------------------
- [INFO] Building tutorial 0.0.1-SNAPSHOT
- [INFO] ------------------------------------------------------------------------
- ...
- [INFO] Configuring Jetty for project: tutorial
- [INFO] webAppSourceDirectory not set. Trying src/main/webapp
- [INFO] Reload Mechanic: automatic
- [INFO] Classes = /.../tutorial/target/classes
- [INFO] Logging initialized @1617ms
- [INFO] Context path = /
- [INFO] Tmp directory = /.../tutorial/target/tmp
- [INFO] Web defaults = org/eclipse/jetty/webapp/webdefault.xml
- [INFO] Web overrides = none
- [INFO] web.xml file = file:/.../tutorial/src/main/webapp/WEB-INF/web.xml
- [INFO] Webapp directory = /.../tutorial/src/main/webapp
- [INFO] jetty-9.3.0.v20150612
- [INFO] Started o.e.j.m.p.JettyWebAppContext@6872f9c8{/,file:/.../tutorial/src/main/webapp/,AVAILABLE}{file:/.../tutorial/src/main/webapp/}
- [INFO] Started ServerConnector@723875bc{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
- [INFO] Started @2367ms
- [INFO] Started Jetty Server</screen>
-
-- So the Jetty container just started.
-
-- Now go to http://localhost:8080/ URL. You should see "No artists found message" in the web browser and
-the following output in the IDEA console:
-
- INFO: Loading XML configuration resource from file:/.../tutorial/target/classes/cayenne-project.xml
- INFO: loading user name and password.
- INFO: Connecting to 'jdbc:derby:memory:testdb;create=true' as 'null'
- INFO: +++ Connecting: SUCCESS.
- INFO: setting DataNode 'datanode' as default, used by all unlinked DataMaps
- INFO: Detected and installed adapter: org.apache.cayenne.dba.derby.DerbyAdapter
- INFO: --- transaction started.
- INFO: No schema detected, will create mapped tables
- INFO: CREATE TABLE GALLERY (ID INTEGER NOT NULL, NAME VARCHAR (200), PRIMARY KEY (ID))
- INFO: CREATE TABLE ARTIST (DATE_OF_BIRTH DATE, ID INTEGER NOT NULL, NAME VARCHAR (200), PRIMARY KEY (ID))
- INFO: CREATE TABLE PAINTING (ARTIST_ID INTEGER, GALLERY_ID INTEGER, ID INTEGER NOT NULL,
- NAME VARCHAR (200), PRIMARY KEY (ID))
- INFO: ALTER TABLE PAINTING ADD FOREIGN KEY (ARTIST_ID) REFERENCES ARTIST (ID)
- INFO: ALTER TABLE PAINTING ADD FOREIGN KEY (GALLERY_ID) REFERENCES GALLERY (ID)
- INFO: CREATE TABLE AUTO_PK_SUPPORT (
- TABLE_NAME CHAR(100) NOT NULL, NEXT_ID BIGINT NOT NULL, PRIMARY KEY(TABLE_NAME))
- ...
- INFO: SELECT t0.DATE_OF_BIRTH, t0.NAME, t0.ID FROM ARTIST t0 ORDER BY t0.NAME
- INFO: === returned 0 rows. - took 17 ms.
- INFO: +++ transaction committed.</screen>
-
-- You can click on "Create new artist" link to create artists. Existing artists can be edited by clicking on their name:
-
-image::chrome-webapp.png[align="center"]
-
-You are done with the tutorial!
\ No newline at end of file
diff --git a/docs/asciidoc/getting-started-guide/src/docs/asciidoc/getting-started-guide.adoc b/docs/asciidoc/getting-started-guide/src/docs/asciidoc/getting-started-guide.adoc
index 87a401ff3..5725bd762 100644
--- a/docs/asciidoc/getting-started-guide/src/docs/asciidoc/getting-started-guide.adoc
+++ b/docs/asciidoc/getting-started-guide/src/docs/asciidoc/getting-started-guide.adoc
@@ -42,5 +42,3 @@ include::_getting-started-guide/setup.adoc[]
include::_getting-started-guide/part2.adoc[]
include::_getting-started-guide/part3.adoc[]
-
-include::_getting-started-guide/webapp.adoc[]
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 25671b772..9d60a361c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -66,7 +66,6 @@
<module>cayenne-project-compatibility</module>
<module>cayenne-server</module>
<module>cayenne-velocity</module>
- <module>cayenne-web</module>
<module>cayenne-osgi</module>
<module>maven-plugins</module>
<module>modeler</module>
diff --git a/tutorials/tutorial/pom.xml b/tutorials/tutorial/pom.xml
index 89b6c2dc3..f865dbb57 100644
--- a/tutorials/tutorial/pom.xml
+++ b/tutorials/tutorial/pom.xml
@@ -37,11 +37,6 @@
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
- <dependency>
- <groupId>org.apache.cayenne</groupId>
- <artifactId>cayenne-web</artifactId>
- <version>${project.version}</version>
- </dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
diff --git a/tutorials/tutorial/src/main/webapp/WEB-INF/web.xml b/tutorials/tutorial/src/main/webapp/WEB-INF/web.xml
deleted file mode 100644
index 40a668f2c..000000000
--- a/tutorials/tutorial/src/main/webapp/WEB-INF/web.xml
+++ /dev/null
@@ -1,41 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
- <!DOCTYPE web-app
- PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
- "http://java.sun.com/dtd/web-app_2_3.dtd">
-<!--
- 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
-
- https://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.
--->
-<web-app>
- <display-name>Cayenne Tutorial</display-name>
-
- <!--
- This filter provides each request thread with a session-bound
- DataContext
- -->
- <filter>
- <filter-name>cayenne-project</filter-name>
- <filter-class>org.apache.cayenne.configuration.web.CayenneFilter</filter-class>
- </filter>
- <filter-mapping>
- <filter-name>cayenne-project</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
- <welcome-file-list>
- <welcome-file>index.jsp</welcome-file>
- </welcome-file-list>
-</web-app>
\ No newline at end of file
diff --git a/tutorials/tutorial/src/main/webapp/detail.jsp b/tutorials/tutorial/src/main/webapp/detail.jsp
deleted file mode 100644
index 1f9f890f2..000000000
--- a/tutorials/tutorial/src/main/webapp/detail.jsp
+++ /dev/null
@@ -1,89 +0,0 @@
-<!--
-/*****************************************************************
- * 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
- *
- * https://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.
- ****************************************************************/
- -->
-<%@ page language="java" contentType="text/html" %>
-<%@ page import="org.apache.cayenne.tutorial.persistent.*" %>
-<%@ page import="org.apache.cayenne.*" %>
-<%@ page import="java.time.format.DateTimeFormatter"%>
-
-// tag::content[]
-<%
- ObjectContext context = BaseContext.getThreadObjectContext();
- String id = request.getParameter("id");
-
- // find artist for id
- Artist artist = null;
- if(id != null && id.trim().length() > 0) {
- artist = Cayenne.objectForPK(context, Artist.class, Integer.parseInt(id));
- }
-
- if("POST".equals(request.getMethod())) {
- // if no id is saved in the hidden field, we are dealing with
- // create new artist request
- if(artist == null) {
- artist = context.newObject(Artist.class);
- }
-
- // note that in a real application we would so dome validation ...
- // here we just hope the input is correct
- artist.setName(request.getParameter("name"));
- artist.setDateOfBirthString(request.getParameter("dateOfBirth"));
-
- context.commitChanges();
-
- response.sendRedirect("index.jsp");
- }
-
- if(artist == null) {
- // create transient artist for the form response rendering
- artist = new Artist();
- }
-
- String name = artist.getName() == null ? "" : artist.getName();
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
- String dob = artist.getDateOfBirth() == null
- ? "" :artist.getDateOfBirth().format(formatter);
-%>
-<html>
- <head>
- <title>Artist Details</title>
- </head>
- <body>
- <h2>Artists Details</h2>
- <form name="EditArtist" action="detail.jsp" method="POST">
- <input type="hidden" name="id" value="<%= id != null ? id : "" %>" />
- <table border="0">
- <tr>
- <td>Name:</td>
- <td><input type="text" name="name" value="<%= name %>"/></td>
- </tr>
- <tr>
- <td>Date of Birth (yyyyMMdd):</td>
- <td><input type="text" name="dateOfBirth" value="<%= dob %>"/></td>
- </tr>
- <tr>
- <td></td>
- <td align="right"><input type="submit" value="Save" /></td>
- </tr>
- </table>
- </form>
- </body>
-</html>
-// end::content[]
\ No newline at end of file
diff --git a/tutorials/tutorial/src/main/webapp/index.jsp b/tutorials/tutorial/src/main/webapp/index.jsp
deleted file mode 100644
index 64090cc89..000000000
--- a/tutorials/tutorial/src/main/webapp/index.jsp
+++ /dev/null
@@ -1,53 +0,0 @@
-<!--
-/*****************************************************************
- * 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
- *
- * https://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.
- ****************************************************************/
- -->
-<%@ page contentType="text/html" %>
-<%@ page import="org.apache.cayenne.tutorial.persistent.*" %>
-<%@ page import="org.apache.cayenne.*" %>
-<%@ page import="org.apache.cayenne.query.*" %>
-<%@ page import="java.util.*" %>
-// tag::content[]
-<%
- ObjectContext context = BaseContext.getThreadObjectContext();
- List<Artist> artists = ObjectSelect.query(Artist.class)
- .orderBy(Artist.NAME.asc())
- .select(context);
-%>
-<html>
- <head>
- <title>Main</title>
- </head>
- <body>
- <h2>Artists:</h2>
-
- <% if(artists.isEmpty()) {%>
- <p>No artists found</p>
- <% } else {
- for(Artist a : artists) {
- %>
- <p><a href="detail.jsp?id=<%=Cayenne.intPKForObject(a)%>"> <%=a.getName()%> </a></p>
- <%
- }
- } %>
- <hr>
- <p><a href="detail.jsp">Create new artist...</a></p>
- </body>
-</html>
-// end::content[]
\ No newline at end of file