You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@geode.apache.org by GitBox <gi...@apache.org> on 2020/06/17 00:03:46 UTC

[GitHub] [geode] boglesby commented on a change in pull request #5246: GEODE-8221: Commits session data prior to sending output to browser

boglesby commented on a change in pull request #5246:
URL: https://github.com/apache/geode/pull/5246#discussion_r441207166



##########
File path: extensions/geode-modules/src/main/java/org/apache/geode/modules/session/catalina/AbstractCommitSessionValve.java
##########
@@ -0,0 +1,86 @@
+/*
+ * 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.geode.modules.session.catalina;
+
+import static org.apache.geode.util.internal.UncheckedUtils.uncheckedCast;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+
+import org.apache.catalina.Context;
+import org.apache.catalina.Manager;
+import org.apache.catalina.connector.Request;
+import org.apache.catalina.connector.Response;
+import org.apache.catalina.valves.ValveBase;
+import org.apache.juli.logging.Log;
+import org.apache.juli.logging.LogFactory;
+
+
+public abstract class AbstractCommitSessionValve<SelfT extends AbstractCommitSessionValve<?>>
+    extends ValveBase {
+
+  private static final Log log = LogFactory.getLog(AbstractCommitSessionValve.class);
+
+  protected static final String info =
+      "org.apache.geode.modules.session.catalina.CommitSessionValve/1.0";
+
+  AbstractCommitSessionValve() {
+    log.info("Initialized");
+  }
+
+  @Override
+  public void invoke(final Request request, final Response response)
+      throws IOException, ServletException {
+    // Invoke the next Valve
+    try {
+      getNext().invoke(request, wrapResponse(response));
+    } finally {
+      commitSession(request);
+    }
+  }
+
+  /**
+   * Commit session only if DeltaSessionManager is in place.
+   *
+   * @param request to commit session from.
+   */
+  protected static <SelfT extends AbstractCommitSessionValve<?>> void commitSession(
+      final Request request) {
+    final Context context = request.getContext();
+    final Manager manager = context.getManager();
+    if (manager instanceof DeltaSessionManager) {
+      final DeltaSessionFacade session = (DeltaSessionFacade) request.getSession(false);
+      if (session != null) {
+        final DeltaSessionManager<SelfT> deltaSessionManager = uncheckedCast(manager);
+        final Log contextLogger = context.getLogger();

Review comment:
       Can you change this to use the AbstractCommitSessionValve's Logger (the static log variable) instead of the Context's logger? I'm not sure why its like this, but if we use the AbstractCommitSessionValve's Logger, then only 1 line in logging.properties is necessary to debug this class rather than 2:
   ```
   org.apache.geode.modules.session.level = FINE
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org