ezolnbl-dpc commented on code in PR #2693:
URL: https://github.com/apache/fineract/pull/2693#discussion_r1003706464


##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/idempotency/IdempotencyKeyFilter.java:
##########
@@ -0,0 +1,63 @@
+/**
+ * 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.fineract.infrastructure.idempotency;
+
+import java.io.IOException;
+import javax.servlet.FilterChain;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
+import org.apache.fineract.useradministration.domain.AppUser;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.http.HttpMethod;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.context.SecurityContext;
+import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.stereotype.Component;
+import org.springframework.web.filter.GenericFilterBean;
+
+@Component
+public class IdempotencyKeyFilter extends GenericFilterBean {

Review Comment:
   There is no performance or any other problem with this approach (under the 
hood RequestContextHolder also uses ThreadLocal), however I added a remove 
command for safety after the pass of the value. Beside me 4 other developers 
used the ThreadLocalContextUtil for their job and the reason why I also 
implemented this way is because to see every Fineract specific headers at 1 
place for more readable and understandable code instead of just "hiding" the 
logic deep in the PortfolioCommandSourceWritePlatformServiceImpl class without 
any trace.
   
   The 2 solution is basically equivalent, the cost of +1 filter calling is 
just almost equal to zero however RequestContextHolder is not used anywhere in 
the codebase yet.
   
   If you insist to implement it with your solution, I will change it gladly.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to