This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch v4
in repository https://gitbox.apache.org/repos/asf/causeway.git
The following commit(s) were added to refs/heads/v4 by this push:
new ab1228beeb7 CAUSEWAY-2297: factors out _LoggingJavaSerializer for
debugging use (Wicket Viewer)
ab1228beeb7 is described below
commit ab1228beeb71052dfa036eb94da99761844329bd
Author: Andi Huber <[email protected]>
AuthorDate: Thu Oct 9 09:26:34 2025 +0200
CAUSEWAY-2297: factors out _LoggingJavaSerializer for debugging use
(Wicket Viewer)
---
.../wicketapp/CausewayWicketApplication.java | 56 -------------
.../viewer/wicketapp/_LoggingJavaSerializer.java | 93 ++++++++++++++++++++++
2 files changed, 93 insertions(+), 56 deletions(-)
diff --git
a/viewers/wicket/viewer/src/main/java/org/apache/causeway/viewer/wicket/viewer/wicketapp/CausewayWicketApplication.java
b/viewers/wicket/viewer/src/main/java/org/apache/causeway/viewer/wicket/viewer/wicketapp/CausewayWicketApplication.java
index 9fc75fe4f30..6dbfe9c7d07 100644
---
a/viewers/wicket/viewer/src/main/java/org/apache/causeway/viewer/wicket/viewer/wicketapp/CausewayWicketApplication.java
+++
b/viewers/wicket/viewer/src/main/java/org/apache/causeway/viewer/wicket/viewer/wicketapp/CausewayWicketApplication.java
@@ -18,9 +18,6 @@
*/
package org.apache.causeway.viewer.wicket.viewer.wicketapp;
-import java.io.IOException;
-import java.io.ObjectOutputStream;
-import java.io.OutputStream;
import java.time.Duration;
import java.util.Collections;
import java.util.List;
@@ -47,7 +44,6 @@
import org.apache.wicket.request.cycle.IRequestCycleListener;
import org.apache.wicket.request.cycle.PageRequestHandlerTracker;
import org.apache.wicket.request.resource.CssResourceReference;
-import org.apache.wicket.serialize.java.JavaSerializer;
import org.apache.wicket.settings.RequestCycleSettings;
import org.apache.wicket.spring.injection.annot.SpringComponentInjector;
@@ -56,7 +52,6 @@
import org.apache.causeway.applib.services.inject.ServiceInjector;
import org.apache.causeway.commons.internal.concurrent._ConcurrentContext;
import org.apache.causeway.commons.internal.concurrent._ConcurrentTaskList;
-import org.apache.causeway.commons.internal.reflection._Reflect;
import org.apache.causeway.core.config.CausewayConfiguration;
import org.apache.causeway.core.config.environment.CausewaySystemEnvironment;
import org.apache.causeway.core.metamodel.context.MetaModelContext;
@@ -76,7 +71,6 @@
import
org.apache.causeway.viewer.wicket.viewer.integration.WebRequestCycleForCauseway;
import lombok.Getter;
-import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
/**
@@ -168,35 +162,6 @@ static class ServiceInjectorHolder {
@Inject ServiceInjector serviceInjector;
}
- static class MyObjectOutputStream extends ObjectOutputStream {
-
- MyObjectOutputStream(final OutputStream outputStream) throws
IOException {
- super(outputStream);
- //enableOverride(true);
- }
-
- @Override
- protected final void writeObjectOverride(final Object obj) throws
java.io.IOException {
- if(obj instanceof String str) {
- System.err.printf(">> \"%s\"%n", str);
- } else {
- System.err.printf(">> %s(%s)%n",
obj.getClass().getSimpleName(),
Integer.toHexString(System.identityHashCode(obj)));
- }
- superWriteObject0(obj, false);
- }
-
- // requires --add-opens java.base/java.io=ALL-UNNAMED
- @SneakyThrows
- private void enableOverride(final boolean ena) {
-
_Reflect.setFieldOn(ObjectOutputStream.class.getDeclaredField("enableOverride"),
this, ena);
- }
- @SneakyThrows
- private void superWriteObject0(final Object... args) {
-
_Reflect.invokeMethodOn(ObjectOutputStream.class.getDeclaredMethod("writeObject0",
new Class[] {Object.class, boolean.class}), this, args);
- }
-
- }
-
/**
* Initializes the application; in particular, bootstrapping the Causeway
* backend, and initializing the {@link ComponentFactoryRegistry} to be
used
@@ -237,27 +202,6 @@ protected void init() {
.submit(_ConcurrentContext.sequential())
.await();
- getFrameworkSettings().setSerializer(new
JavaSerializer(getApplicationKey()) {
- @Override
- public byte[] serialize(final Object object) {
-// var watch = _Timing.now();
-// var bytes = super.serialize(object);
-// watch.stop();
-// System.err.printf("> %s (%d kB %s)%n",
object.getClass().getSimpleName(), bytes.length/1000, watch);
- return new byte[0];
- }
- @Override
- public Object deserialize(final byte[] data) {
- var obj = super.deserialize(data);
- System.err.printf("< %s%n",
obj.getClass().getSimpleName());
- return obj;
- }
- @Override
- protected final java.io.ObjectOutputStream
newObjectOutputStream(final java.io.OutputStream out) throws
java.io.IOException {
- return new MyObjectOutputStream(out);
- }
- });
-
getRequestCycleSettings().setRenderStrategy(RequestCycleSettings.RenderStrategy.REDIRECT_TO_RENDER);
getResourceSettings().setParentFolderPlaceholder("$up$");
diff --git
a/viewers/wicket/viewer/src/main/java/org/apache/causeway/viewer/wicket/viewer/wicketapp/_LoggingJavaSerializer.java
b/viewers/wicket/viewer/src/main/java/org/apache/causeway/viewer/wicket/viewer/wicketapp/_LoggingJavaSerializer.java
new file mode 100644
index 00000000000..8a09a36179f
--- /dev/null
+++
b/viewers/wicket/viewer/src/main/java/org/apache/causeway/viewer/wicket/viewer/wicketapp/_LoggingJavaSerializer.java
@@ -0,0 +1,93 @@
+/*
+ * 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.causeway.viewer.wicket.viewer.wicketapp;
+
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+
+import org.apache.wicket.serialize.java.JavaSerializer;
+
+import org.apache.causeway.commons.internal.base._Timing;
+import org.apache.causeway.commons.internal.reflection._Reflect;
+
+import lombok.SneakyThrows;
+
+/**
+ * For debugging page serialization.
+ *
+ * <p>requires
+ * <pre>--add-opens java.base/java.io=ALL-UNNAMED<pre>
+ *
+ * <p>usage within init() ...
+ * <pre>getFrameworkSettings().setSerializer(new
_LoggingJavaSerializer(getApplicationKey()));
+ */
+class _LoggingJavaSerializer extends JavaSerializer {
+
+ public _LoggingJavaSerializer(final String applicationKey) {
+ super(applicationKey);
+ }
+
+ // ObjectOutputStream variant, that reflectively calls writeObject0
private to the super class, for logging purposes.
+ static class MyObjectOutputStream extends ObjectOutputStream {
+ MyObjectOutputStream(final OutputStream outputStream) throws
IOException {
+ super(outputStream);
+ }
+ @Override
+ protected final void writeObjectOverride(final Object obj) throws
java.io.IOException {
+ if(obj instanceof String str) {
+ System.err.printf(">> \"%s\"%n", str);
+ } else {
+ System.err.printf(">> %s(%s)%n",
obj.getClass().getSimpleName(),
Integer.toHexString(System.identityHashCode(obj)));
+ }
+ superWriteObject0(obj, false);
+ }
+
+ @SneakyThrows
+ private void enableOverride(final boolean ena) {
+
_Reflect.setFieldOn(ObjectOutputStream.class.getDeclaredField("enableOverride"),
this, ena);
+ }
+ @SneakyThrows
+ private void superWriteObject0(final Object... args) {
+
_Reflect.invokeMethodOn(ObjectOutputStream.class.getDeclaredMethod("writeObject0",
new Class[] {Object.class, boolean.class}), this, args);
+ }
+ }
+
+ @Override
+ public byte[] serialize(final Object object) {
+ var watch = _Timing.now();
+ var bytes = super.serialize(object);
+ watch.stop();
+ System.err.printf("> %s (%d kB %s)%n",
object.getClass().getSimpleName(), bytes.length/1000, watch);
+ return new byte[0];
+ }
+
+ @Override
+ public Object deserialize(final byte[] data) {
+ var obj = super.deserialize(data);
+ System.err.printf("< %s%n", obj.getClass().getSimpleName());
+ return obj;
+ }
+
+ @Override
+ protected final java.io.ObjectOutputStream newObjectOutputStream(final
java.io.OutputStream out) throws java.io.IOException {
+ return new MyObjectOutputStream(out);
+ }
+
+}