cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dkazimirc...@apache.org
Subject [6/9] cayenne git commit: Clean up old Hessian servlet implementation.
Date Tue, 01 Mar 2016 14:50:44 GMT
Clean up old Hessian servlet implementation.


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/1d9c26b1
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/1d9c26b1
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/1d9c26b1

Branch: refs/heads/master
Commit: 1d9c26b1204adc8179ee4586979ab9772e4631ec
Parents: fadd1d1
Author: Dzmitry Kazimirchyk <dkazimirchyk@gmail.com>
Authored: Mon Jan 25 18:27:02 2016 +0300
Committer: Dzmitry Kazimirchyk <dkazimirchyk@gmail.com>
Committed: Tue Mar 1 14:10:20 2016 +0300

----------------------------------------------------------------------
 .../remote/hessian/HessianConnection.java       | 308 -------------------
 .../hessian/HessianURLConnectionFactory.java    |  51 ---
 .../remote/hessian/service/HessianUtil.java     |  11 +-
 .../org/apache/cayenne/rop/ROPConnector.java    |  15 +
 .../remote/hessian/HessianConnectionTest.java   |  81 -----
 .../rop/server/ROPHessianServlet.java           | 127 --------
 .../cayenne/configuration/web/WebUtil.java      |   3 +-
 .../rop/server/ROPHessianServletTest.java       | 183 -----------
 .../rop/server/ROPServletTest.java              | 179 +++++++++++
 9 files changed, 201 insertions(+), 757 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/1d9c26b1/cayenne-client/src/main/java/org/apache/cayenne/remote/hessian/HessianConnection.java
----------------------------------------------------------------------
diff --git a/cayenne-client/src/main/java/org/apache/cayenne/remote/hessian/HessianConnection.java
b/cayenne-client/src/main/java/org/apache/cayenne/remote/hessian/HessianConnection.java
deleted file mode 100644
index 372cfc7..0000000
--- a/cayenne-client/src/main/java/org/apache/cayenne/remote/hessian/HessianConnection.java
+++ /dev/null
@@ -1,308 +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
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- ****************************************************************/
-
-package org.apache.cayenne.remote.hessian;
-
-import com.caucho.hessian.client.HessianProxyFactory;
-import com.caucho.hessian.client.HessianRuntimeException;
-import com.caucho.hessian.io.HessianProtocolException;
-import com.caucho.hessian.io.SerializerFactory;
-import org.apache.cayenne.CayenneRuntimeException;
-import org.apache.cayenne.event.EventBridge;
-import org.apache.cayenne.event.EventBridgeFactory;
-import org.apache.cayenne.remote.BaseConnection;
-import org.apache.cayenne.remote.ClientMessage;
-import org.apache.cayenne.remote.RemoteService;
-import org.apache.cayenne.remote.RemoteSession;
-import org.apache.cayenne.util.Util;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * An ClientConnection that passes messages to a remotely deployed HessianService. It
- * supports HTTP BASIC authentication. HessianConnection serializes messages using Hessian
- * binary web service protocol over HTTP. For more info on Hessian see Caucho site at <a
- * href="http://www.caucho.com/resin-3.0/protocols/hessian.xtp">http://www.caucho.com/resin-3.0/protocols/hessian.xtp</a>.
- * HessianConnection supports logging of message traffic via Jakarta commons-logging API.
- *
- * @since 1.2
- */
-public class HessianConnection extends BaseConnection {
-
-    private static Log logger = LogFactory.getLog(HessianConnection.class);
-
-    public static final String[] CLIENT_SERIALIZER_FACTORIES = new String[] {
-            ClientSerializerFactory.class.getName()
-    };
-
-    protected String url;
-    protected String userName;
-    protected String password;
-    protected String sharedSessionName;
-
-    protected RemoteSession session;
-    protected RemoteService service;
-    protected SerializerFactory serializerFactory;
-
-    /**
-     * Creates HessianConnection that will establish dedicated session and will not use
-     * HTTP basic authentication.
-     */
-    public HessianConnection(String url) {
-        this(url, null, null, null);
-    }
-
-    /**
-     * Creates a HessianConnection. This constructor can optionally setup basic
-     * authentication credentials and configure shared session. <code>url</code>
is the
-     * only required parameter.
-     */
-    public HessianConnection(String url, String userName, String password,
-            String sharedSessionName) {
-        if (url == null) {
-            throw new IllegalArgumentException("URL of Cayenne service is null.");
-        }
-
-        this.url = url;
-        this.userName = userName;
-        this.password = password;
-        this.sharedSessionName = sharedSessionName;
-    }
-
-    /**
-     * Returns a URL of Cayenne service used by this connector.
-     */
-    public String getUrl() {
-        return url;
-    }
-
-    /**
-     * Returns user name that is used for basic authentication when connecting to the
-     * cayenne server.
-     */
-    public String getUserName() {
-        return userName;
-    }
-
-    /**
-     * Returns password that is used for basic authentication when connecting to the
-     * cayenne server.
-     */
-    public String getPassword() {
-        return password;
-    }
-
-    public String getSharedSessionName() {
-        return sharedSessionName;
-    }
-
-    @Override
-    public EventBridge getServerEventBridge() throws CayenneRuntimeException {
-        if (session == null) {
-            connect();
-        }
-
-        return createServerEventBridge(session);
-    }
-
-    /**
-     * Creates an EventBridge that will listen for server events. Returns null if server
-     * events support is not configured in the descriptor.
-     *
-     * @throws CayenneRuntimeException if EventBridge startup fails for any reason.
-     */
-    protected EventBridge createServerEventBridge(RemoteSession session) throws CayenneRuntimeException
{
-
-        if (!session.isServerEventsEnabled()) {
-            return null;
-        }
-
-        try {
-            EventBridgeFactory factory = (EventBridgeFactory) Class.forName(session.getEventBridgeFactory())
-                    .newInstance();
-
-            // must use "name", not the sessionId as an external subject for the
-            // event bridge
-            return factory.createEventBridge(RemoteSession.getSubjects(), session.getName(),
-                    session.getEventBridgeParameters());
-        } catch (Exception ex) {
-            throw new CayenneRuntimeException("Error creating EventBridge.", ex);
-        }
-    }
-
-    /**
-     * Returns internal RemoteSession instance.
-     */
-    public RemoteSession getSession() {
-        return session;
-    }
-
-    /**
-     * Establishes server session if needed.
-     */
-    @Override
-    protected void beforeSendMessage(ClientMessage message)
-            throws CayenneRuntimeException {
-        // for now only support session-based communications...
-        if (session == null) {
-            connect();
-        }
-    }
-
-    /**
-     * Sends a message to remote Cayenne Hessian service.
-     */
-    @Override
-    protected Object doSendMessage(ClientMessage message) throws CayenneRuntimeException
{
-        try {
-            return service.processMessage(message);
-        }
-        catch (CayenneRuntimeException e) {
-            throw e;
-        }
-        catch (Throwable th) {
-            th = unwindThrowable(th);
-            String errorMessage = buildExceptionMessage("Remote error", th);
-            throw new CayenneRuntimeException(errorMessage, th);
-        }
-    }
-
-    /**
-     * Establishes a session with remote service.
-     */
-    protected synchronized void connect() throws CayenneRuntimeException {
-        if (session != null) {
-            return;
-        }
-
-        long t0 = 0;
-        if (logger.isInfoEnabled()) {
-            t0 = System.currentTimeMillis();
-            StringBuilder log = new StringBuilder("Connecting to [");
-            if (userName != null) {
-                log.append(userName);
-
-                if (password != null) {
-                    log.append(":*******");
-                }
-
-                log.append("@");
-            }
-
-            log.append(url);
-            log.append("]");
-
-            if (sharedSessionName != null) {
-                log.append(" - shared session '").append(sharedSessionName).append("'");
-            }
-            else {
-                log.append(" - dedicated session.");
-            }
-
-            logger.info(log.toString());
-        }
-
-        // init service proxy...
-        HessianProxyFactory factory = new HessianProxyFactory();
-        factory.setSerializerFactory(HessianConfig.createFactory(
-                CLIENT_SERIALIZER_FACTORIES,
-                null));
-        factory.setConnectionFactory(new HessianURLConnectionFactory(this));
-        factory.setUser(userName);
-        factory.setPassword(password);
-
-        this.serializerFactory = factory.getSerializerFactory();
-
-        try {
-            this.service = (RemoteService) factory.create(RemoteService.class, url);
-        }
-        catch (Throwable th) {
-            th = unwindThrowable(th);
-            String message = buildExceptionMessage("URL error", th);
-            throw new CayenneRuntimeException(message, th);
-        }
-
-        // create server session...
-        try {
-            session = (sharedSessionName != null) ? service
-                    .establishSharedSession(sharedSessionName) : service
-                    .establishSession();
-
-            if (logger.isInfoEnabled()) {
-                long time = System.currentTimeMillis() - t0;
-                logger.info("=== Connected, session: "
-                        + session
-                        + " - took "
-                        + time
-                        + " ms.");
-            }
-        }
-        catch (Throwable th) {
-            th = unwindThrowable(th);
-            String message = buildExceptionMessage(
-                    "Error establishing remote session",
-                    th);
-            logger.info(message, th);
-            throw new CayenneRuntimeException(message, th);
-        }
-
-        // TODO: send a connect event...
-    }
-
-    String buildExceptionMessage(String message, Throwable th) {
-
-        StringBuilder buffer = new StringBuilder(message);
-        buffer.append(". URL - ").append(url);
-
-        String thMessage = th.getMessage();
-        if (!Util.isEmptyString(thMessage)) {
-            buffer.append("; CAUSE - ").append(thMessage);
-        }
-
-        return buffer.toString();
-    }
-
-    /**
-     * Utility method to get exception cause. Implements special handling of Hessian
-     * exceptions.
-     */
-    Throwable unwindThrowable(Throwable th) {
-        if (th instanceof HessianProtocolException) {
-            Throwable cause = ((HessianProtocolException) th).getRootCause();
-
-            if (cause != null) {
-                return unwindThrowable(cause);
-            }
-        }
-        else if (th instanceof HessianRuntimeException) {
-            Throwable cause = ((HessianRuntimeException) th).getRootCause();
-
-            if (cause != null) {
-                return unwindThrowable(cause);
-            }
-        }
-
-        return Util.unwindException(th);
-    }
-
-    public SerializerFactory getSerializerFactory() {
-        return serializerFactory;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/1d9c26b1/cayenne-client/src/main/java/org/apache/cayenne/remote/hessian/HessianURLConnectionFactory.java
----------------------------------------------------------------------
diff --git a/cayenne-client/src/main/java/org/apache/cayenne/remote/hessian/HessianURLConnectionFactory.java
b/cayenne-client/src/main/java/org/apache/cayenne/remote/hessian/HessianURLConnectionFactory.java
deleted file mode 100644
index d5a441f..0000000
--- a/cayenne-client/src/main/java/org/apache/cayenne/remote/hessian/HessianURLConnectionFactory.java
+++ /dev/null
@@ -1,51 +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
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- ****************************************************************/
-
-package org.apache.cayenne.remote.hessian;
-
-import org.apache.cayenne.remote.RemoteSession;
-
-import java.io.IOException;
-import java.net.URL;
-
-public class HessianURLConnectionFactory extends com.caucho.hessian.client.HessianURLConnectionFactory
{
-
-    static final String SESSION_COOKIE_NAME = "JSESSIONID";
-
-    private HessianConnection clientConnection;
-
-    HessianURLConnectionFactory(HessianConnection clientConnection) {
-        this.clientConnection = clientConnection;
-    }
-
-    @Override
-    public com.caucho.hessian.client.HessianConnection open(URL url) throws IOException {
-        com.caucho.hessian.client.HessianConnection hessianConnection = super.open(url);
-
-        // add session cookie
-        RemoteSession session = clientConnection.getSession();
-        if (session != null && session.getSessionId() != null) {
-            hessianConnection.addHeader("Cookie", SESSION_COOKIE_NAME
-                    + "="
-                    + session.getSessionId());
-        }
-
-        return hessianConnection;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cayenne/blob/1d9c26b1/cayenne-client/src/main/java/org/apache/cayenne/remote/hessian/service/HessianUtil.java
----------------------------------------------------------------------
diff --git a/cayenne-client/src/main/java/org/apache/cayenne/remote/hessian/service/HessianUtil.java
b/cayenne-client/src/main/java/org/apache/cayenne/remote/hessian/service/HessianUtil.java
index 7c0f15c..88a938b 100644
--- a/cayenne-client/src/main/java/org/apache/cayenne/remote/hessian/service/HessianUtil.java
+++ b/cayenne-client/src/main/java/org/apache/cayenne/remote/hessian/service/HessianUtil.java
@@ -25,10 +25,11 @@ import java.io.Serializable;
 
 import org.apache.cayenne.map.EntityResolver;
 import org.apache.cayenne.remote.hessian.HessianConfig;
-import org.apache.cayenne.remote.hessian.HessianConnection;
 
 import com.caucho.hessian.io.HessianInput;
 import com.caucho.hessian.io.HessianOutput;
+import org.apache.cayenne.rop.ServerHessianSerializationServiceProvider;
+import org.apache.cayenne.rop.http.ClientHessianSerializationServiceProvider;
 
 /**
  * Hessian related utilities.
@@ -47,7 +48,7 @@ public class HessianUtil {
         ByteArrayOutputStream bytes = new ByteArrayOutputStream();
         HessianOutput out = new HessianOutput(bytes);
         out.setSerializerFactory(HessianConfig.createFactory(
-                HessianConnection.CLIENT_SERIALIZER_FACTORIES,
+                ClientHessianSerializationServiceProvider.CLIENT_SERIALIZER_FACTORIES,
                 null));
         out.writeObject(object);
 
@@ -55,7 +56,7 @@ public class HessianUtil {
 
         HessianInput in = new HessianInput(new ByteArrayInputStream(data));
         in.setSerializerFactory(HessianConfig.createFactory(
-                HessianService.SERVER_SERIALIZER_FACTORIES,
+                ServerHessianSerializationServiceProvider.SERVER_SERIALIZER_FACTORIES,
                 serverResolver));
 
         return in.readObject();
@@ -67,7 +68,7 @@ public class HessianUtil {
         ByteArrayOutputStream bytes = new ByteArrayOutputStream();
         HessianOutput out = new HessianOutput(bytes);
         out.setSerializerFactory(HessianConfig.createFactory(
-                HessianService.SERVER_SERIALIZER_FACTORIES,
+				ServerHessianSerializationServiceProvider.SERVER_SERIALIZER_FACTORIES,
                 serverResolver));
         out.writeObject(object);
 
@@ -75,7 +76,7 @@ public class HessianUtil {
 
         HessianInput in = new HessianInput(new ByteArrayInputStream(data));
         in.setSerializerFactory(HessianConfig.createFactory(
-                HessianConnection.CLIENT_SERIALIZER_FACTORIES,
+                ClientHessianSerializationServiceProvider.CLIENT_SERIALIZER_FACTORIES,
                 null));
         return in.readObject();
     }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/1d9c26b1/cayenne-client/src/main/java/org/apache/cayenne/rop/ROPConnector.java
----------------------------------------------------------------------
diff --git a/cayenne-client/src/main/java/org/apache/cayenne/rop/ROPConnector.java b/cayenne-client/src/main/java/org/apache/cayenne/rop/ROPConnector.java
index 4976d80..5855cf8 100644
--- a/cayenne-client/src/main/java/org/apache/cayenne/rop/ROPConnector.java
+++ b/cayenne-client/src/main/java/org/apache/cayenne/rop/ROPConnector.java
@@ -21,12 +21,27 @@ package org.apache.cayenne.rop;
 import java.io.IOException;
 import java.io.InputStream;
 
+/**
+ * ROP network connectivity interface.
+ * 
+ * @since 4.0
+ */
 public interface ROPConnector {
 
+	/**
+	 * Establishes a dedicated session with Cayenne DataChannel, returning session id.
+	 */
     InputStream establishSession() throws IOException;
 
+	/**
+	 * Creates a new session with the specified or joins an existing one. This method is
+	 * used to bootstrap collaborating clients of a single "group chat".
+	 */
     InputStream establishSharedSession(String name) throws IOException;
 
+	/**
+	 * Processes message on a remote server, returning the result of such processing.
+	 */
     InputStream sendMessage(byte[] message) throws IOException;
     
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/1d9c26b1/cayenne-client/src/test/java/org/apache/cayenne/remote/hessian/HessianConnectionTest.java
----------------------------------------------------------------------
diff --git a/cayenne-client/src/test/java/org/apache/cayenne/remote/hessian/HessianConnectionTest.java
b/cayenne-client/src/test/java/org/apache/cayenne/remote/hessian/HessianConnectionTest.java
deleted file mode 100644
index e3808ed..0000000
--- a/cayenne-client/src/test/java/org/apache/cayenne/remote/hessian/HessianConnectionTest.java
+++ /dev/null
@@ -1,81 +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
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- ****************************************************************/
-
-package org.apache.cayenne.remote.hessian;
-
-import org.apache.cayenne.CayenneRuntimeException;
-import org.apache.cayenne.remote.ClientMessage;
-import org.apache.cayenne.remote.RemoteService;
-import org.apache.cayenne.remote.RemoteSession;
-import org.apache.cayenne.remote.service.MissingSessionException;
-import org.junit.Test;
-
-import java.rmi.RemoteException;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-public class HessianConnectionTest {
-
-    @Test
-    public void testConstructor1Arg() {
-        HessianConnection c = new HessianConnection("a");
-        assertEquals("a", c.getUrl());
-        assertNull(c.getUserName());
-        assertNull(c.getPassword());
-    }
-
-    @Test
-    public void testConstructor3Arg() {
-        HessianConnection c = new HessianConnection("a", "b", "c", "d");
-        assertEquals("a", c.getUrl());
-        assertEquals("b", c.getUserName());
-        assertEquals("c", c.getPassword());
-        assertEquals("d", c.getSharedSessionName());
-    }
-
-    @Test
-    public void testMissingSessionException() {
-        // Set up the test objects.  We want to mock out RemoteService.
-        HessianConnection c = new HessianConnection("a");
-        c.service = new RemoteService() {
-            public RemoteSession establishSession() throws RemoteException {
-                return null;
-            }
-
-            public RemoteSession establishSharedSession(String name) throws RemoteException
{
-                return null;
-            }
-
-            public Object processMessage(ClientMessage message) throws RemoteException, Throwable
{
-                throw new MissingSessionException();
-            }
-        };
-
-
-        try {
-            c.doSendMessage(null);
-        }
-        catch (CayenneRuntimeException e) {
-            // Verify that CayenneRuntimeExceptions are not wrapped in another CayenneRuntimeException.
-            assertTrue(e instanceof MissingSessionException);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/1d9c26b1/cayenne-server/src/main/java/org/apache/cayenne/configuration/rop/server/ROPHessianServlet.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/configuration/rop/server/ROPHessianServlet.java
b/cayenne-server/src/main/java/org/apache/cayenne/configuration/rop/server/ROPHessianServlet.java
deleted file mode 100644
index 3059a5b..0000000
--- a/cayenne-server/src/main/java/org/apache/cayenne/configuration/rop/server/ROPHessianServlet.java
+++ /dev/null
@@ -1,127 +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
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- ****************************************************************/
-package org.apache.cayenne.configuration.rop.server;
-
-import java.util.Collection;
-import java.util.Map;
-
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
-
-import org.apache.cayenne.DataChannel;
-import org.apache.cayenne.configuration.CayenneRuntime;
-import org.apache.cayenne.configuration.server.ServerRuntime;
-import org.apache.cayenne.configuration.web.RequestHandler;
-import org.apache.cayenne.configuration.web.WebConfiguration;
-import org.apache.cayenne.configuration.web.WebUtil;
-import org.apache.cayenne.di.Module;
-import org.apache.cayenne.event.EventBridge;
-import org.apache.cayenne.remote.RemoteService;
-import org.apache.cayenne.remote.hessian.HessianConfig;
-import org.apache.cayenne.remote.hessian.service.HessianService;
-
-import com.caucho.hessian.io.SerializerFactory;
-import com.caucho.hessian.server.HessianServlet;
-
-/**
- * A servlet that bootstraps a Hessian-based ROP server. Servlet initialization
- * parameters:
- * <ul>
- * <li>configuration-location (optional) - a name of Cayenne configuration XML file
that
- * will be used to load Cayenne stack. If missing, the servlet name will be used to derive
- * the location. ".xml" extension will be appended to the servlet name to get the
- * location, so a servlet 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>
- * All other parameters passed to the servlet are considered to be related to the
- * {@link EventBridge} initialization.
- * 
- * @since 3.1
- */
-public class ROPHessianServlet extends HessianServlet {
-
-    protected ServletContext servletContext;
-
-    /**
-     * Installs {@link HessianService} to respond to {@link RemoteService} requests.
-     */
-    @Override
-    public void init(ServletConfig configuration) throws ServletException {
-        
-        checkAlreadyConfigured(configuration.getServletContext());
-
-        this.servletContext = configuration.getServletContext();
-
-        WebConfiguration configAdapter = new WebConfiguration(configuration);
-
-        String configurationLocation = configAdapter.getConfigurationLocation();
-        Map<String, String> eventBridgeParameters = configAdapter.getOtherParameters();
-
-        Collection<Module> modules = configAdapter.createModules(new ROPServerModule(
-                eventBridgeParameters));
-
-        ServerRuntime runtime = new ServerRuntime(configurationLocation, modules
-                .toArray(new Module[modules.size()]));
-
-        DataChannel channel = runtime.getChannel();
-
-        RemoteService service = runtime.getInjector().getInstance(RemoteService.class);
-
-        SerializerFactory serializerFactory = HessianConfig.createFactory(
-                HessianService.SERVER_SERIALIZER_FACTORIES,
-                channel.getEntityResolver());
-
-        setAPIClass(RemoteService.class);
-        setSerializerFactory(serializerFactory);
-        setService(service);
-
-        // Even though runtime instance is not accessed by Hessian service directly (it
-        // uses DataChannel injection instead), expose it in a manner consistent with
-        // CayenneFilter. Servlets other than ROP may decide to use it...
-
-        // TODO: andrus 04/14/2010: if CayenneFilter and ROPHessianServlet are used
-        // together in the same webapp, maybe a good idea to ensure they are using the
-        // same stack...Merging CayenneRuntime's modules might be tough though.
-
-        WebUtil.setCayenneRuntime(servletContext, runtime);
-        super.init(configuration);
-    }
-    
-    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() {
-        super.destroy();
-
-        CayenneRuntime runtime = WebUtil.getCayenneRuntime(servletContext);
-        if (runtime != null) {
-            runtime.shutdown();
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/1d9c26b1/cayenne-server/src/main/java/org/apache/cayenne/configuration/web/WebUtil.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/configuration/web/WebUtil.java
b/cayenne-server/src/main/java/org/apache/cayenne/configuration/web/WebUtil.java
index 244d5c3..dfeb3c4 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/configuration/web/WebUtil.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/configuration/web/WebUtil.java
@@ -21,12 +21,11 @@ package org.apache.cayenne.configuration.web;
 import javax.servlet.ServletContext;
 
 import org.apache.cayenne.configuration.CayenneRuntime;
-import org.apache.cayenne.configuration.rop.server.ROPHessianServlet;
 
 /**
  * A helper class to retrieve and store {@link CayenneRuntime} in the
  * {@link ServletContext}. All Cayenne web configuration objects, such as
- * {@link CayenneFilter} and {@link ROPHessianServlet}, are using this class to access
+ * {@link CayenneFilter} and {@link org.apache.cayenne.rop.ROPServlet}, are using this class
to access
  * runtime.
  * 
  * @since 3.1

http://git-wip-us.apache.org/repos/asf/cayenne/blob/1d9c26b1/cayenne-server/src/test/java/org/apache/cayenne/configuration/rop/server/ROPHessianServletTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/configuration/rop/server/ROPHessianServletTest.java
b/cayenne-server/src/test/java/org/apache/cayenne/configuration/rop/server/ROPHessianServletTest.java
deleted file mode 100644
index cf4bc52..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/configuration/rop/server/ROPHessianServletTest.java
+++ /dev/null
@@ -1,183 +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
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- ****************************************************************/
-package org.apache.cayenne.configuration.rop.server;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-
-import org.apache.cayenne.configuration.CayenneRuntime;
-import org.apache.cayenne.configuration.Constants;
-import org.apache.cayenne.configuration.ModuleCollection;
-import org.apache.cayenne.configuration.server.ServerModule;
-import org.apache.cayenne.configuration.web.MockModule1;
-import org.apache.cayenne.configuration.web.MockModule2;
-import org.apache.cayenne.configuration.web.MockRequestHandler;
-import org.apache.cayenne.configuration.web.RequestHandler;
-import org.apache.cayenne.configuration.web.WebUtil;
-import org.apache.cayenne.di.Key;
-import org.apache.cayenne.di.Module;
-import org.apache.cayenne.remote.RemoteService;
-import org.junit.Test;
-
-import com.mockrunner.mock.web.MockServletConfig;
-import com.mockrunner.mock.web.MockServletContext;
-
-public class ROPHessianServletTest {
-
-	@Test
-	public void testInitWithServletName() throws Exception {
-
-		MockServletConfig config = new MockServletConfig();
-		config.setServletName("cayenne-org.apache.cayenne.configuration.rop.server.test-config");
-
-		MockServletContext context = new MockServletContext();
-		config.setServletContext(context);
-
-		ROPHessianServlet servlet = new ROPHessianServlet();
-
-		assertNull(WebUtil.getCayenneRuntime(context));
-		servlet.init(config);
-
-		CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
-		assertNotNull(runtime);
-
-		List<?> locations = runtime.getInjector().getInstance(
-				Key.get(List.class, Constants.SERVER_PROJECT_LOCATIONS_LIST));
-		assertEquals(Arrays.asList("cayenne-org.apache.cayenne.configuration.rop.server.test-config.xml"),
locations);
-	}
-
-	@Test
-	public void testInitWithLocation() throws Exception {
-
-		String location = "cayenne-org.apache.cayenne.configuration.rop.server.test-config.xml";
-		MockServletConfig config = new MockServletConfig();
-		config.setServletName("abc");
-		config.setInitParameter("configuration-location", location);
-
-		MockServletContext context = new MockServletContext();
-		config.setServletContext(context);
-
-		ROPHessianServlet servlet = new ROPHessianServlet();
-		servlet.init(config);
-
-		CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
-		assertNotNull(runtime);
-		List<?> locations = runtime.getInjector().getInstance(
-				Key.get(List.class, Constants.SERVER_PROJECT_LOCATIONS_LIST));
-
-		assertEquals(Arrays.asList(location), locations);
-	}
-
-	@Test
-	public void testInitWithStandardModules() throws Exception {
-
-		String name = "cayenne-org.apache.cayenne.configuration.rop.server.test-config";
-
-		MockServletConfig config = new MockServletConfig();
-		config.setServletName(name);
-
-		MockServletContext context = new MockServletContext();
-		config.setServletContext(context);
-
-		ROPHessianServlet servlet = new ROPHessianServlet();
-		servlet.init(config);
-
-		CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
-		assertNotNull(runtime);
-
-		List<?> locations = runtime.getInjector().getInstance(
-				Key.get(List.class, Constants.SERVER_PROJECT_LOCATIONS_LIST));
-
-		assertEquals(Arrays.asList(name + ".xml"), locations);
-		
-		Collection<Module> modules = ((ModuleCollection) runtime.getModule()).getModules();
-		assertEquals(2, modules.size());
-		Object[] marray = modules.toArray();
-
-		assertTrue(marray[0] instanceof ServerModule);
-		assertTrue(marray[1] instanceof ROPServerModule);
-
-		assertTrue(RemoteService.class.equals(servlet.getAPIClass()));
-	}
-
-	@Test
-	public void testInitWithExtraModules() throws Exception {
-
-		String name = "cayenne-org.apache.cayenne.configuration.rop.server.test-config";
-
-		MockServletConfig config = new MockServletConfig();
-		config.setServletName(name);
-		config.setInitParameter("extra-modules", MockModule1.class.getName() + "," + MockModule2.class.getName());
-
-		MockServletContext context = new MockServletContext();
-		config.setServletContext(context);
-
-		ROPHessianServlet servlet = new ROPHessianServlet();
-		servlet.init(config);
-
-		CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
-		assertNotNull(runtime);
-
-		Collection<Module> modules = ((ModuleCollection) runtime.getModule()).getModules();
-		assertEquals(4, modules.size());
-
-		Object[] marray = modules.toArray();
-
-		assertTrue(marray[0] instanceof ServerModule);
-		assertTrue(marray[1] instanceof ROPServerModule);
-		assertTrue(marray[2] instanceof MockModule1);
-		assertTrue(marray[3] instanceof MockModule2);
-
-		RequestHandler handler = runtime.getInjector().getInstance(RequestHandler.class);
-		assertTrue(handler instanceof MockRequestHandler);
-	}
-
-	@Test
-	public void testInitHessianService() throws Exception {
-
-		MockServletConfig config = new MockServletConfig();
-		config.setServletName("abc");
-
-		MockServletContext context = new MockServletContext();
-		config.setServletContext(context);
-		config.setInitParameter("extra-modules", ROPHessianServlet_ConfigModule.class.getName());
-
-		ROPHessianServlet servlet = new ROPHessianServlet();
-
-		servlet.init(config);
-		CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
-		Collection<Module> modules = ((ModuleCollection) runtime.getModule()).getModules();
-		assertEquals(3, modules.size());
-
-		Object[] marray = modules.toArray();
-
-		assertTrue(marray[2] instanceof ROPHessianServlet_ConfigModule);
-
-		assertTrue(RemoteService.class.equals(servlet.getAPIClass()));
-
-		// TODO: mock servlet request to check that the right service instance
-		// is invoked
-	}
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/1d9c26b1/cayenne-server/src/test/java/org/apache/cayenne/configuration/rop/server/ROPServletTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/configuration/rop/server/ROPServletTest.java
b/cayenne-server/src/test/java/org/apache/cayenne/configuration/rop/server/ROPServletTest.java
new file mode 100644
index 0000000..569d703
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/configuration/rop/server/ROPServletTest.java
@@ -0,0 +1,179 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.configuration.rop.server;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.cayenne.configuration.CayenneRuntime;
+import org.apache.cayenne.configuration.Constants;
+import org.apache.cayenne.configuration.ModuleCollection;
+import org.apache.cayenne.configuration.server.ServerModule;
+import org.apache.cayenne.configuration.web.MockModule1;
+import org.apache.cayenne.configuration.web.MockModule2;
+import org.apache.cayenne.configuration.web.MockRequestHandler;
+import org.apache.cayenne.configuration.web.RequestHandler;
+import org.apache.cayenne.configuration.web.WebUtil;
+import org.apache.cayenne.di.Key;
+import org.apache.cayenne.di.Module;
+import org.apache.cayenne.rop.ROPServlet;
+import org.junit.Test;
+
+import com.mockrunner.mock.web.MockServletConfig;
+import com.mockrunner.mock.web.MockServletContext;
+
+public class ROPServletTest {
+
+	@Test
+	public void testInitWithServletName() throws Exception {
+
+		MockServletConfig config = new MockServletConfig();
+		config.setServletName("cayenne-org.apache.cayenne.configuration.rop.server.test-config");
+
+		MockServletContext context = new MockServletContext();
+		config.setServletContext(context);
+
+		ROPServlet servlet = new ROPServlet();
+
+		assertNull(WebUtil.getCayenneRuntime(context));
+		servlet.init(config);
+
+		CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
+		assertNotNull(runtime);
+
+		List<?> locations = runtime.getInjector().getInstance(
+				Key.get(List.class, Constants.SERVER_PROJECT_LOCATIONS_LIST));
+		assertEquals(Arrays.asList("cayenne-org.apache.cayenne.configuration.rop.server.test-config.xml"),
locations);
+	}
+
+	@Test
+	public void testInitWithLocation() throws Exception {
+
+		String location = "cayenne-org.apache.cayenne.configuration.rop.server.test-config.xml";
+		MockServletConfig config = new MockServletConfig();
+		config.setServletName("abc");
+		config.setInitParameter("configuration-location", location);
+
+		MockServletContext context = new MockServletContext();
+		config.setServletContext(context);
+
+		ROPServlet servlet = new ROPServlet();
+		servlet.init(config);
+
+		CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
+		assertNotNull(runtime);
+		List<?> locations = runtime.getInjector().getInstance(
+				Key.get(List.class, Constants.SERVER_PROJECT_LOCATIONS_LIST));
+
+		assertEquals(Arrays.asList(location), locations);
+	}
+
+	@Test
+	public void testInitWithStandardModules() throws Exception {
+
+		String name = "cayenne-org.apache.cayenne.configuration.rop.server.test-config";
+
+		MockServletConfig config = new MockServletConfig();
+		config.setServletName(name);
+
+		MockServletContext context = new MockServletContext();
+		config.setServletContext(context);
+
+		ROPServlet servlet = new ROPServlet();
+		servlet.init(config);
+
+		CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
+		assertNotNull(runtime);
+
+		List<?> locations = runtime.getInjector().getInstance(
+				Key.get(List.class, Constants.SERVER_PROJECT_LOCATIONS_LIST));
+
+		assertEquals(Arrays.asList(name + ".xml"), locations);
+		
+		Collection<Module> modules = ((ModuleCollection) runtime.getModule()).getModules();
+		assertEquals(2, modules.size());
+		Object[] marray = modules.toArray();
+
+		assertTrue(marray[0] instanceof ServerModule);
+		assertTrue(marray[1] instanceof ROPServerModule);
+	}
+
+	@Test
+	public void testInitWithExtraModules() throws Exception {
+
+		String name = "cayenne-org.apache.cayenne.configuration.rop.server.test-config";
+
+		MockServletConfig config = new MockServletConfig();
+		config.setServletName(name);
+		config.setInitParameter("extra-modules", MockModule1.class.getName() + "," + MockModule2.class.getName());
+
+		MockServletContext context = new MockServletContext();
+		config.setServletContext(context);
+
+		ROPServlet servlet = new ROPServlet();
+		servlet.init(config);
+
+		CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
+		assertNotNull(runtime);
+
+		Collection<Module> modules = ((ModuleCollection) runtime.getModule()).getModules();
+		assertEquals(4, modules.size());
+
+		Object[] marray = modules.toArray();
+
+		assertTrue(marray[0] instanceof ServerModule);
+		assertTrue(marray[1] instanceof ROPServerModule);
+		assertTrue(marray[2] instanceof MockModule1);
+		assertTrue(marray[3] instanceof MockModule2);
+
+		RequestHandler handler = runtime.getInjector().getInstance(RequestHandler.class);
+		assertTrue(handler instanceof MockRequestHandler);
+	}
+
+	@Test
+	public void testInitHessianService() throws Exception {
+
+		MockServletConfig config = new MockServletConfig();
+		config.setServletName("abc");
+
+		MockServletContext context = new MockServletContext();
+		config.setServletContext(context);
+		config.setInitParameter("extra-modules", ROPHessianServlet_ConfigModule.class.getName());
+
+		ROPServlet servlet = new ROPServlet();
+
+		servlet.init(config);
+		CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
+		Collection<Module> modules = ((ModuleCollection) runtime.getModule()).getModules();
+		assertEquals(3, modules.size());
+
+		Object[] marray = modules.toArray();
+
+		assertTrue(marray[2] instanceof ROPHessianServlet_ConfigModule);
+
+		// TODO: mock servlet request to check that the right service instance
+		// is invoked
+	}
+}


Mime
View raw message