cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abulat...@apache.org
Subject [cayenne] 01/03: CAY-2562 Make ROPServerModule autoloaded
Date Fri, 26 Apr 2019 10:19:07 GMT
This is an automated email from the ASF dual-hosted git repository.

abulatski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cayenne.git

commit c0c909c6c6ce1939b78260dbd5cc91bb1e893b2d
Author: Arseni Bulatski <ancarseni@gmail.com>
AuthorDate: Wed Apr 10 16:38:48 2019 +0300

    CAY-2562 Make ROPServerModule autoloaded
---
 RELEASE-NOTES.txt                                  |  1 +
 .../ProtostuffServerModuleProvider.java            |  6 ++--
 .../configuration/rop/server/ROPServerModule.java  | 12 --------
 .../rop/server/ROPServerModuleProvider.java        | 21 +++++++-------
 .../java/org/apache/cayenne/rop/ROPServlet.java    | 25 ++++++++--------
 ...onfiguration.server.CayenneServerModuleProvider | 20 +++++++++++++
 .../rop/server/ROPServerModuleProviderTest.java    | 33 ++++++----------------
 .../configuration/rop/server/ROPServletTest.java   | 19 +++++++------
 .../apache/cayenne/tutorial/Http2ROPServlet.java   | 18 ++++++------
 9 files changed, 74 insertions(+), 81 deletions(-)

diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt
index df5df34..7463f2b 100644
--- a/RELEASE-NOTES.txt
+++ b/RELEASE-NOTES.txt
@@ -27,6 +27,7 @@ CAY-2542 Modeler: redesign ObjRelationship editor dialog
 CAY-2543 Move ResultSetMapping generation from metadata to translator
 CAY-2549 Modeler: Redesign ObjAttribute editor dialog
 CAY-2555 Use explicit ArcId in GraphChangeHandler methods
+CAY-2562 Make ROPServerModule autoloaded
 
 Bug Fixes:
 
diff --git a/cayenne-protostuff/src/main/java/org/apache/cayenne/configuration/ProtostuffServerModuleProvider.java
b/cayenne-protostuff/src/main/java/org/apache/cayenne/configuration/ProtostuffServerModuleProvider.java
index e256ae6..51e1f84 100644
--- a/cayenne-protostuff/src/main/java/org/apache/cayenne/configuration/ProtostuffServerModuleProvider.java
+++ b/cayenne-protostuff/src/main/java/org/apache/cayenne/configuration/ProtostuffServerModuleProvider.java
@@ -23,8 +23,8 @@ import java.util.Collection;
 import java.util.Collections;
 
 import org.apache.cayenne.configuration.rop.client.ProtostuffModule;
+import org.apache.cayenne.configuration.rop.server.ROPServerModule;
 import org.apache.cayenne.configuration.server.CayenneServerModuleProvider;
-import org.apache.cayenne.configuration.server.ServerModule;
 import org.apache.cayenne.di.Module;
 
 /**
@@ -42,10 +42,8 @@ public class ProtostuffServerModuleProvider implements CayenneServerModuleProvid
         return ProtostuffModule.class;
     }
 
-    @SuppressWarnings("unchecked")
     @Override
     public Collection<Class<? extends Module>> overrides() {
-        Collection modules = Collections.singletonList(ServerModule.class);
-        return modules;
+        return Collections.singletonList(ROPServerModule.class);
     }
 }
diff --git a/cayenne-rop-server/src/main/java/org/apache/cayenne/configuration/rop/server/ROPServerModule.java
b/cayenne-rop-server/src/main/java/org/apache/cayenne/configuration/rop/server/ROPServerModule.java
index ad93183..f6a5dea 100644
--- a/cayenne-rop-server/src/main/java/org/apache/cayenne/configuration/rop/server/ROPServerModule.java
+++ b/cayenne-rop-server/src/main/java/org/apache/cayenne/configuration/rop/server/ROPServerModule.java
@@ -27,8 +27,6 @@ import org.apache.cayenne.rop.ROPSerializationService;
 import org.apache.cayenne.rop.ServerHessianSerializationServiceProvider;
 import org.apache.cayenne.rop.ServerHttpRemoteService;
 
-import java.util.Map;
-
 /**
  * A DI module that defines services for the server-side of an ROP application based on
  * Caucho Hessian.
@@ -37,8 +35,6 @@ import java.util.Map;
  */
 public class ROPServerModule implements Module {
 
-    protected Map<String, String> eventBridgeProperties;
-
     /**
      * @since 4.0
      */
@@ -46,15 +42,7 @@ public class ROPServerModule implements Module {
         return binder.bindMap(String.class, Constants.SERVER_ROP_EVENT_BRIDGE_PROPERTIES_MAP);
     }
 
-    public ROPServerModule(Map<String, String> eventBridgeProperties) {
-        this.eventBridgeProperties = eventBridgeProperties;
-    }
-
     public void configure(Binder binder) {
-
-        MapBuilder<String> mapBuilder = contributeROPBridgeProperties(binder);
-        mapBuilder.putAll(eventBridgeProperties);
-
         binder.bind(RemoteService.class).to(ServerHttpRemoteService.class);
 		binder.bind(ROPSerializationService.class).toProvider(ServerHessianSerializationServiceProvider.class);
     }
diff --git a/cayenne-protostuff/src/main/java/org/apache/cayenne/configuration/ProtostuffServerModuleProvider.java
b/cayenne-rop-server/src/main/java/org/apache/cayenne/configuration/rop/server/ROPServerModuleProvider.java
similarity index 74%
copy from cayenne-protostuff/src/main/java/org/apache/cayenne/configuration/ProtostuffServerModuleProvider.java
copy to cayenne-rop-server/src/main/java/org/apache/cayenne/configuration/rop/server/ROPServerModuleProvider.java
index e256ae6..d844e17 100644
--- a/cayenne-protostuff/src/main/java/org/apache/cayenne/configuration/ProtostuffServerModuleProvider.java
+++ b/cayenne-rop-server/src/main/java/org/apache/cayenne/configuration/rop/server/ROPServerModuleProvider.java
@@ -16,36 +16,37 @@
  *  specific language governing permissions and limitations
  *  under the License.
  ****************************************************************/
+package org.apache.cayenne.configuration.rop.server;
 
-package org.apache.cayenne.configuration;
-
+import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
+import java.util.List;
 
-import org.apache.cayenne.configuration.rop.client.ProtostuffModule;
 import org.apache.cayenne.configuration.server.CayenneServerModuleProvider;
 import org.apache.cayenne.configuration.server.ServerModule;
+import org.apache.cayenne.configuration.web.WebModule;
 import org.apache.cayenne.di.Module;
 
 /**
- * @since 4.0
+ * @since 4.2
  */
-public class ProtostuffServerModuleProvider implements CayenneServerModuleProvider {
+public class ROPServerModuleProvider implements CayenneServerModuleProvider {
 
     @Override
     public Module module() {
-        return new ProtostuffModule();
+        return new ROPServerModule();
     }
 
     @Override
     public Class<? extends Module> moduleType() {
-        return ProtostuffModule.class;
+        return ROPServerModule.class;
     }
 
-    @SuppressWarnings("unchecked")
     @Override
     public Collection<Class<? extends Module>> overrides() {
-        Collection modules = Collections.singletonList(ServerModule.class);
+        List<Class<? extends Module>> modules = new ArrayList<>();
+        modules.add(ServerModule.class);
+        modules.add(WebModule.class);
         return modules;
     }
 }
diff --git a/cayenne-rop-server/src/main/java/org/apache/cayenne/rop/ROPServlet.java b/cayenne-rop-server/src/main/java/org/apache/cayenne/rop/ROPServlet.java
index e7a0001..e93e13c 100644
--- a/cayenne-rop-server/src/main/java/org/apache/cayenne/rop/ROPServlet.java
+++ b/cayenne-rop-server/src/main/java/org/apache/cayenne/rop/ROPServlet.java
@@ -18,16 +18,6 @@
  ****************************************************************/
 package org.apache.cayenne.rop;
 
-import org.apache.cayenne.configuration.CayenneRuntime;
-import org.apache.cayenne.configuration.rop.server.ROPServerModule;
-import org.apache.cayenne.configuration.server.ServerRuntime;
-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.ClientMessage;
-import org.apache.cayenne.remote.RemoteService;
-import org.apache.cayenne.remote.RemoteSession;
-
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletContext;
 import javax.servlet.ServletException;
@@ -38,6 +28,16 @@ import java.io.IOException;
 import java.util.Collection;
 import java.util.Map;
 
+import org.apache.cayenne.configuration.CayenneRuntime;
+import org.apache.cayenne.configuration.rop.server.ROPServerModule;
+import org.apache.cayenne.configuration.server.ServerRuntime;
+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.ClientMessage;
+import org.apache.cayenne.remote.RemoteService;
+import org.apache.cayenne.remote.RemoteSession;
+
 public class ROPServlet extends HttpServlet {
 
     protected ServletContext servletContext;
@@ -56,12 +56,13 @@ public class ROPServlet extends HttpServlet {
         String configurationLocation = configAdapter.getConfigurationLocation();
         Map<String, String> eventBridgeParameters = configAdapter.getOtherParameters();
 
-        Collection<Module> modules = configAdapter.createModules(new ROPServerModule(
-                eventBridgeParameters));
+        Collection<Module> modules = configAdapter.createModules();
 
         ServerRuntime runtime = ServerRuntime.builder()
                 .addConfig(configurationLocation)
                 .addModules(modules)
+                .addModule(binder ->
+                        ROPServerModule.contributeROPBridgeProperties(binder).putAll(eventBridgeParameters))
                 .build();
 
         this.remoteService = runtime.getInjector().getInstance(RemoteService.class);
diff --git a/cayenne-rop-server/src/main/resources/META-INF/services/org.apache.cayenne.configuration.server.CayenneServerModuleProvider
b/cayenne-rop-server/src/main/resources/META-INF/services/org.apache.cayenne.configuration.server.CayenneServerModuleProvider
new file mode 100644
index 0000000..4ea71cd
--- /dev/null
+++ b/cayenne-rop-server/src/main/resources/META-INF/services/org.apache.cayenne.configuration.server.CayenneServerModuleProvider
@@ -0,0 +1,20 @@
+##################################################################
+#   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.
+##################################################################
+
+org.apache.cayenne.configuration.rop.server.ROPServerModuleProvider
\ No newline at end of file
diff --git a/cayenne-protostuff/src/main/java/org/apache/cayenne/configuration/ProtostuffServerModuleProvider.java
b/cayenne-rop-server/src/test/java/org/apache/cayenne/configuration/rop/server/ROPServerModuleProviderTest.java
similarity index 57%
copy from cayenne-protostuff/src/main/java/org/apache/cayenne/configuration/ProtostuffServerModuleProvider.java
copy to cayenne-rop-server/src/test/java/org/apache/cayenne/configuration/rop/server/ROPServerModuleProviderTest.java
index e256ae6..f3b96a6 100644
--- a/cayenne-protostuff/src/main/java/org/apache/cayenne/configuration/ProtostuffServerModuleProvider.java
+++ b/cayenne-rop-server/src/test/java/org/apache/cayenne/configuration/rop/server/ROPServerModuleProviderTest.java
@@ -16,36 +16,19 @@
  *  specific language governing permissions and limitations
  *  under the License.
  ****************************************************************/
+package org.apache.cayenne.configuration.rop.server;
 
-package org.apache.cayenne.configuration;
-
-import java.util.Collection;
-import java.util.Collections;
-
-import org.apache.cayenne.configuration.rop.client.ProtostuffModule;
 import org.apache.cayenne.configuration.server.CayenneServerModuleProvider;
-import org.apache.cayenne.configuration.server.ServerModule;
-import org.apache.cayenne.di.Module;
+import org.apache.cayenne.unit.util.ModuleProviderChecker;
+import org.junit.Test;
 
 /**
- * @since 4.0
+ * @since 4.2
  */
-public class ProtostuffServerModuleProvider implements CayenneServerModuleProvider {
-
-    @Override
-    public Module module() {
-        return new ProtostuffModule();
-    }
-
-    @Override
-    public Class<? extends Module> moduleType() {
-        return ProtostuffModule.class;
-    }
+public class ROPServerModuleProviderTest {
 
-    @SuppressWarnings("unchecked")
-    @Override
-    public Collection<Class<? extends Module>> overrides() {
-        Collection modules = Collections.singletonList(ServerModule.class);
-        return modules;
+    @Test
+    public void testAutoLoadable() {
+        ModuleProviderChecker.testProviderPresent(ROPServerModuleProvider.class, CayenneServerModuleProvider.class);
     }
 }
diff --git a/cayenne-rop-server/src/test/java/org/apache/cayenne/configuration/rop/server/ROPServletTest.java
b/cayenne-rop-server/src/test/java/org/apache/cayenne/configuration/rop/server/ROPServletTest.java
index 43d52fb..e23607d 100644
--- a/cayenne-rop-server/src/test/java/org/apache/cayenne/configuration/rop/server/ROPServletTest.java
+++ b/cayenne-rop-server/src/test/java/org/apache/cayenne/configuration/rop/server/ROPServletTest.java
@@ -18,6 +18,10 @@
  ****************************************************************/
 package org.apache.cayenne.configuration.rop.server;
 
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
 import com.mockrunner.mock.web.MockServletConfig;
 import com.mockrunner.mock.web.MockServletContext;
 import org.apache.cayenne.configuration.CayenneRuntime;
@@ -32,11 +36,10 @@ import org.apache.cayenne.rop.ROPServlet;
 import org.junit.After;
 import org.junit.Test;
 
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-
-import static org.junit.Assert.*;
+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 ROPServletTest {
 
@@ -116,7 +119,7 @@ public class ROPServletTest {
 		assertEquals(Arrays.asList(name + ".xml"), locations);
 
 		Collection<Module> modules = runtime.getModules();
-		assertEquals(4, modules.size());
+		assertEquals(5, modules.size());
 		Object[] marray = modules.toArray();
 
 		if(marray[0] instanceof ServerModule){
@@ -147,7 +150,7 @@ public class ROPServletTest {
 		assertNotNull(runtime);
 
 		Collection<Module> modules = runtime.getModules();
-		assertEquals(6, modules.size());
+		assertEquals(7, modules.size());
 
 		Object[] marray = modules.toArray();
 		if(marray[0] instanceof ServerModule){
@@ -179,7 +182,7 @@ public class ROPServletTest {
 		servlet.init(config);
 		runtime = WebUtil.getCayenneRuntime(context);
 		Collection<Module> modules = runtime.getModules();
-		assertEquals(5, modules.size());
+		assertEquals(6, modules.size());
 
 		Object[] marray = modules.toArray();
 
diff --git a/tutorials/tutorial-rop-server-http2/src/main/java/org/apache/cayenne/tutorial/Http2ROPServlet.java
b/tutorials/tutorial-rop-server-http2/src/main/java/org/apache/cayenne/tutorial/Http2ROPServlet.java
index e9c6df5..7a348a9 100644
--- a/tutorials/tutorial-rop-server-http2/src/main/java/org/apache/cayenne/tutorial/Http2ROPServlet.java
+++ b/tutorials/tutorial-rop-server-http2/src/main/java/org/apache/cayenne/tutorial/Http2ROPServlet.java
@@ -19,7 +19,11 @@
 
 package org.apache.cayenne.tutorial;
 
-import org.apache.cayenne.configuration.rop.client.ProtostuffModule;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import java.util.Collection;
+import java.util.Map;
+
 import org.apache.cayenne.configuration.rop.server.ROPServerModule;
 import org.apache.cayenne.configuration.server.ServerRuntime;
 import org.apache.cayenne.configuration.web.WebConfiguration;
@@ -29,12 +33,6 @@ import org.apache.cayenne.remote.RemoteService;
 import org.apache.cayenne.rop.ROPSerializationService;
 import org.apache.cayenne.rop.ROPServlet;
 
-
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
-import java.util.Collection;
-import java.util.Map;
-
 public class Http2ROPServlet extends ROPServlet {
 
     @Override
@@ -49,13 +47,13 @@ public class Http2ROPServlet extends ROPServlet {
         String configurationLocation = configAdapter.getConfigurationLocation();
         Map<String, String> eventBridgeParameters = configAdapter.getOtherParameters();
 
-        Collection<Module> modules = configAdapter.createModules(
-                new ROPServerModule(eventBridgeParameters),
-                new ProtostuffModule());
+        Collection<Module> modules = configAdapter.createModules();
 
         ServerRuntime runtime = ServerRuntime
                 .builder()
                 .addConfig(configurationLocation)
+                .addModule(binder ->
+                        ROPServerModule.contributeROPBridgeProperties(binder).putAll(eventBridgeParameters))
                 .addModules(modules)
                 .build();
 


Mime
View raw message