From ac48ea044c0dae5313ccbee784537b05bff3779c Mon Sep 17 00:00:00 2001 From: Andy Janata Date: Thu, 22 Mar 2018 16:23:41 -0700 Subject: [PATCH] Delete some old stuff that was never fully implemented or needed. --- .../cah/handlers/AdminHandler.java | 61 ------------------- .../cah/handlers/AdminSetVerboseLog.java | 49 --------------- .../net/socialgamer/cah/handlers/Handler.java | 34 +---------- .../socialgamer/cah/handlers/Handlers.java | 1 - .../socialgamer/cah/servlets/AjaxServlet.java | 13 ++-- 5 files changed, 7 insertions(+), 151 deletions(-) delete mode 100644 src/main/java/net/socialgamer/cah/handlers/AdminHandler.java delete mode 100644 src/main/java/net/socialgamer/cah/handlers/AdminSetVerboseLog.java diff --git a/src/main/java/net/socialgamer/cah/handlers/AdminHandler.java b/src/main/java/net/socialgamer/cah/handlers/AdminHandler.java deleted file mode 100644 index e3b6944..0000000 --- a/src/main/java/net/socialgamer/cah/handlers/AdminHandler.java +++ /dev/null @@ -1,61 +0,0 @@ -/** - * Copyright (c) 2012, Andy Janata - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package net.socialgamer.cah.handlers; - -import java.util.Map; - -import javax.servlet.http.HttpSession; - -import net.socialgamer.cah.Constants; -import net.socialgamer.cah.Constants.ErrorCode; -import net.socialgamer.cah.Constants.ReturnableData; -import net.socialgamer.cah.RequestWrapper; - - -/** - * Superclass of handlers for administrative actions. Ensures that the client is allowed to make - * admin requests. - * - * @author Andy Janata (ajanata@socialgamer.net) - */ -public abstract class AdminHandler extends Handler { - - @Override - public Map handle(final RequestWrapper request, final HttpSession session) { - if (!Constants.ADMIN_IP_ADDRESSES.contains(request.getRemoteAddr())) { - return error(ErrorCode.ACCESS_DENIED); - } - - return handle(request); - } - - /** - * Handle a request. - * - * @param request - * Request data from the client. - * @return Response data. - */ - public abstract Map handle(RequestWrapper request); -} diff --git a/src/main/java/net/socialgamer/cah/handlers/AdminSetVerboseLog.java b/src/main/java/net/socialgamer/cah/handlers/AdminSetVerboseLog.java deleted file mode 100644 index 85dd149..0000000 --- a/src/main/java/net/socialgamer/cah/handlers/AdminSetVerboseLog.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * Copyright (c) 2012, Andy Janata - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package net.socialgamer.cah.handlers; - -import java.util.Map; - -import net.socialgamer.cah.Constants.AjaxOperation; -import net.socialgamer.cah.Constants.ReturnableData; -import net.socialgamer.cah.RequestWrapper; - - -/** - * Admin handler for turning verbose logging on and off. This has been temporarily abandoned as - * using this ajax framework for administration purposes would take a while to set up. - * - * @author Andy Janata (ajanata@socialgamer.net) - */ -public class AdminSetVerboseLog extends AdminHandler { - - public static final String OP = AjaxOperation.ADMIN_SET_VERBOSE_LOG.toString(); - - @Override - public Map handle(final RequestWrapper request) { - // TODO Auto-generated method stub - return null; - } - -} diff --git a/src/main/java/net/socialgamer/cah/handlers/Handler.java b/src/main/java/net/socialgamer/cah/handlers/Handler.java index 81a4a96..c371292 100644 --- a/src/main/java/net/socialgamer/cah/handlers/Handler.java +++ b/src/main/java/net/socialgamer/cah/handlers/Handler.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2012, Andy Janata + * Copyright (c) 2012-2018, Andy Janata * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted @@ -80,36 +80,4 @@ public abstract class Handler { data.putAll(extraData); return data; } - - /** - * Clean up after this Handler. Currently, this means using reflection to see if the concrete - * Handler implementation had a field of type Session (Hibernate), and closing it if it does and - * did not already close it. - */ - public final void cleanUp() { - // this actually breaks stuff, I'll have to think it through later. - // for (final Field field : this.getClass().getDeclaredFields()) { - // if (field.getType() == Session.class) { - // try { - // // This Handler had a Hibernate Session. Try to close it if it wasn't already closed. - // // This is extremely dirty but also extremely awesome to not have problems if it is - // // forgotten. - // field.setAccessible(true); - // final Session session = (Session) field.get(this); - // if (session.isOpen()) { - // session.close(); - // logger.log(Level.INFO, "Closing unclosed Hibernate Session in " - // + this.getClass().getName()); - // } - // } catch (final Exception e) { - // // Something prevented us from ignoring access control check, so we can't close the - // // session. Log about it and continue. - // e.printStackTrace(); - // logger.log(Level.SEVERE, "Unable to reflect and get Hibernate Session from " - // + this.getClass().getName()); - // logger.log(Level.SEVERE, e.toString()); - // } - // } - // } - } } diff --git a/src/main/java/net/socialgamer/cah/handlers/Handlers.java b/src/main/java/net/socialgamer/cah/handlers/Handlers.java index f36f7de..527149c 100644 --- a/src/main/java/net/socialgamer/cah/handlers/Handlers.java +++ b/src/main/java/net/socialgamer/cah/handlers/Handlers.java @@ -10,7 +10,6 @@ public class Handlers { static { LIST = new HashMap>(); - LIST.put(AdminSetVerboseLog.OP, AdminSetVerboseLog.class); LIST.put(BanHandler.OP, BanHandler.class); LIST.put(CardcastAddCardsetHandler.OP, CardcastAddCardsetHandler.class); LIST.put(CardcastListCardsetsHandler.OP, CardcastListCardsetsHandler.class); diff --git a/src/main/java/net/socialgamer/cah/servlets/AjaxServlet.java b/src/main/java/net/socialgamer/cah/servlets/AjaxServlet.java index 44c804c..05da78f 100644 --- a/src/main/java/net/socialgamer/cah/servlets/AjaxServlet.java +++ b/src/main/java/net/socialgamer/cah/servlets/AjaxServlet.java @@ -1,16 +1,16 @@ /** - * Copyright (c) 2012, Andy Janata + * Copyright (c) 2012-2018, Andy Janata * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without modification, are permitted * provided that the following conditions are met: - * + * * * Redistributions of source code must retain the above copyright notice, this list of conditions * and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of * conditions and the following disclaimer in the documentation and/or other materials provided * with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR @@ -46,9 +46,9 @@ import net.socialgamer.cah.handlers.Handlers; /** * Servlet implementation class AjaxServlet. - * + * * This servlet is only used for client actions, not for long-polling. - * + * * @author Andy Janata (ajanata@socialgamer.net) */ @WebServlet("/AjaxServlet") @@ -94,7 +94,6 @@ public class AjaxServlet extends CahServlet { return; } final Map data = handler.handle(new RequestWrapper(request), hSession); - handler.cleanUp(); data.put(AjaxResponse.SERIAL, serial); returnData(user, out, data); return;