[
https://issues.apache.org/jira/browse/WICKET-7153?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17944076#comment-17944076
]
ASF GitHub Bot commented on WICKET-7153:
----------------------------------------
martin-g commented on code in PR #1146:
URL: https://github.com/apache/wicket/pull/1146#discussion_r2041446230
##########
wicket-core/src/main/java/org/apache/wicket/core/request/mapper/HashBasedResourceReferenceMapper.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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.wicket.core.request.mapper;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Supplier;
+import org.apache.wicket.WicketRuntimeException;
+import org.apache.wicket.request.mapper.ParentPathReferenceRewriter;
+import org.apache.wicket.request.mapper.parameter.IPageParametersEncoder;
+import org.apache.wicket.request.resource.caching.IResourceCachingStrategy;
+
+/**
+ * <p>
+ * Resource reference {@link org.apache.wicket.request.IRequestMapper} that
encodes class names as hash codes.
+ * This allows hiding the class name from resource references. i.e., instead
of <em>/wicket/resource/org.xxx.yyy.ZPanel/a.js</em> the
+ * URL will display <em>/wicket/resource/ddd/a.js</em>, where ddd =
hash(org.xxx.yyy.ZPanel). This allows globally hiding
+ * class structure of your application (not displaying it via URLs).
+ * </p>
+ *
+ * <p>
+ * Caveat: we don't take into account has collisions. I.e. to to different
class names having the same hash code.
+ * </p>
+ * <p>
+ * Note: if you want to hide the "wicket" part of URL for "xxx" you can do:
+ * <code>
+ * protected IMapperContext newMapperContext() {
+ * return new DefaultMapperContext(this) {
+ * public String getNamespace() {
+ * return "xxx";
+ * }
+ * };
+ * }
+ * </code>
+ * on your Application class.
+ * </p>
+ */
+public class HashBasedResourceReferenceMapper extends
ParentPathReferenceRewriter
Review Comment:
This class needs unit tests!
##########
wicket-core/src/main/java/org/apache/wicket/core/request/mapper/HashBasedResourceReferenceMapper.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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.wicket.core.request.mapper;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Supplier;
+import org.apache.wicket.WicketRuntimeException;
+import org.apache.wicket.request.mapper.ParentPathReferenceRewriter;
+import org.apache.wicket.request.mapper.parameter.IPageParametersEncoder;
+import org.apache.wicket.request.resource.caching.IResourceCachingStrategy;
+
+/**
+ * <p>
+ * Resource reference {@link org.apache.wicket.request.IRequestMapper} that
encodes class names as hash codes.
+ * This allows hiding the class name from resource references. i.e., instead
of <em>/wicket/resource/org.xxx.yyy.ZPanel/a.js</em> the
+ * URL will display <em>/wicket/resource/ddd/a.js</em>, where ddd =
hash(org.xxx.yyy.ZPanel). This allows globally hiding
+ * class structure of your application (not displaying it via URLs).
+ * </p>
+ *
+ * <p>
+ * Caveat: we don't take into account has collisions. I.e. to to different
class names having the same hash code.
+ * </p>
+ * <p>
+ * Note: if you want to hide the "wicket" part of URL for "xxx" you can do:
+ * <code>
+ * protected IMapperContext newMapperContext() {
+ * return new DefaultMapperContext(this) {
+ * public String getNamespace() {
+ * return "xxx";
+ * }
+ * };
+ * }
+ * </code>
+ * on your Application class.
+ * </p>
+ */
+public class HashBasedResourceReferenceMapper extends
ParentPathReferenceRewriter
+{
+
+ private static class HashBasedBasicResourceReferenceMapper extends
BasicResourceReferenceMapper
+ {
+
+ private final Map<Long, String> hashMap = new
ConcurrentHashMap<>();
+
+ private final boolean checkHashCollision;
+
+ /**
+ * Construct.
+ *
+ * @param pageParametersEncoder {@link IPageParametersEncoder}
+ * @param cachingStrategy {@link
Supplier<IResourceCachingStrategy>}
+ */
+ public
HashBasedBasicResourceReferenceMapper(IPageParametersEncoder
pageParametersEncoder, Supplier<? extends IResourceCachingStrategy>
cachingStrategy, boolean checkHashCollision)
+ {
+ super(pageParametersEncoder, cachingStrategy);
+ this.checkHashCollision = checkHashCollision;
+ }
+
+ @Override
+ protected Class<?> resolveClass(String name)
+ {
+ try
+ {
+ long hash = Long.parseLong(name);
+ String className = hashMap.get(hash);
+ if (className == null)
+ {
+ return super.getPageClass(name);
+ }
+ return super.resolveClass(className);
+ }
+ catch (NumberFormatException e)
+ {
+ return super.getPageClass(name);
+ }
+ }
+
+ @Override
+ protected String getClassName(Class<?> scope)
+ {
+ String name = super.getClassName(scope);
+ long hash = scope.hashCode();
Review Comment:
The class javadoc says `that encodes class names as hash codes`, i.e.
`String.hashCode()`, but it is actualy `Class.hashCode()`
Probably you want:
```suggestion
long hash = name.hashCode();
```
?!
##########
wicket-core/src/main/java/org/apache/wicket/core/request/mapper/HashBasedResourceReferenceMapper.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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.wicket.core.request.mapper;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Supplier;
+import org.apache.wicket.WicketRuntimeException;
+import org.apache.wicket.request.mapper.ParentPathReferenceRewriter;
+import org.apache.wicket.request.mapper.parameter.IPageParametersEncoder;
+import org.apache.wicket.request.resource.caching.IResourceCachingStrategy;
+
+/**
+ * <p>
+ * Resource reference {@link org.apache.wicket.request.IRequestMapper} that
encodes class names as hash codes.
+ * This allows hiding the class name from resource references. i.e., instead
of <em>/wicket/resource/org.xxx.yyy.ZPanel/a.js</em> the
+ * URL will display <em>/wicket/resource/ddd/a.js</em>, where ddd =
hash(org.xxx.yyy.ZPanel). This allows globally hiding
+ * class structure of your application (not displaying it via URLs).
+ * </p>
+ *
+ * <p>
+ * Caveat: we don't take into account has collisions. I.e. to to different
class names having the same hash code.
Review Comment:
`I.e. to to different class` sounds wrong. Please re-phrase it.
##########
wicket-core/src/main/java/org/apache/wicket/core/request/mapper/HashBasedResourceReferenceMapper.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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.wicket.core.request.mapper;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Supplier;
+import org.apache.wicket.WicketRuntimeException;
+import org.apache.wicket.request.mapper.ParentPathReferenceRewriter;
+import org.apache.wicket.request.mapper.parameter.IPageParametersEncoder;
+import org.apache.wicket.request.resource.caching.IResourceCachingStrategy;
+
+/**
+ * <p>
+ * Resource reference {@link org.apache.wicket.request.IRequestMapper} that
encodes class names as hash codes.
+ * This allows hiding the class name from resource references. i.e., instead
of <em>/wicket/resource/org.xxx.yyy.ZPanel/a.js</em> the
+ * URL will display <em>/wicket/resource/ddd/a.js</em>, where ddd =
hash(org.xxx.yyy.ZPanel). This allows globally hiding
+ * class structure of your application (not displaying it via URLs).
+ * </p>
+ *
+ * <p>
+ * Caveat: we don't take into account has collisions. I.e. to to different
class names having the same hash code.
Review Comment:
```suggestion
* Caveat: we don't take into account hash collisions. I.e. to to
different class names having the same hash code.
```
> [Resources] modify RootMapper in order to allow to define a refferent
> ResourceReferenceMapper
> ---------------------------------------------------------------------------------------------
>
> Key: WICKET-7153
> URL: https://issues.apache.org/jira/browse/WICKET-7153
> Project: Wicket
> Issue Type: Improvement
> Components: wicket
> Affects Versions: 10.4.0, 9.20.0
> Reporter: Ernesto Reinaldo Barreiro
> Assignee: Ernesto Reinaldo Barreiro
> Priority: Major
> Fix For: 10.5.0, 9.21.0
>
>
> In our application we would like to hide as much as possible the fact that we
> are using wicket. We are using a lot of third party libraries and if you
> inspect headers headers you will see things like, e.g.:
> "./wicket/resource/org.xxx.yyy.APanel/a.js"
>
> we want to replace this with
>
> "appres/resource/\{some_stable_number_depending_on_package_class}/a.js"
>
> The way I found to solve this requires copy/pasting/modifying SystemMapper.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)