[java-support] 01/02: IDP-1793 Use Suppliers for HttpRequest/Response
Rod Widdowson
rdw at steadingsoftware.com
Sat Aug 6 15:24:29 UTC 2022
This is an automated email from the git hooks/post-receive script.
rdw pushed a commit to branch main
in repository java-support.
View the commit online:
http://git.shibboleth.net/view/?p=java-support.git;a=commit;h=857a7d991cdc653282a9cf77cef5358780940b4f
commit 857a7d991cdc653282a9cf77cef5358780940b4f
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Thu Jul 28 19:36:59 2022 +0100
IDP-1793 Use Suppliers for HttpRequest/Response
https://shibboleth.atlassian.net/browse/IDP-1793
Two new classes to implement Supplier<HttpServletResponse> and
Supplier<HttpServletRequest>, looking up Thread Local Storage
in the same way that the Proxy implementations do.
---
.../net/ThreadLocalHttpServletRequestProxy.java | 1 -
.../net/ThreadLocalHttpServletRequestSupplier.java | 41 ++++++++++++++++++++++
.../net/ThreadLocalHttpServletResponseProxy.java | 1 -
.../ThreadLocalHttpServletResponseSupplier.java | 41 ++++++++++++++++++++++
4 files changed, 82 insertions(+), 2 deletions(-)
diff --git a/src/main/java/net/shibboleth/utilities/java/support/net/ThreadLocalHttpServletRequestProxy.java b/src/main/java/net/shibboleth/utilities/java/support/net/ThreadLocalHttpServletRequestProxy.java
index 175f4b7..d4bb41d 100644
--- a/src/main/java/net/shibboleth/utilities/java/support/net/ThreadLocalHttpServletRequestProxy.java
+++ b/src/main/java/net/shibboleth/utilities/java/support/net/ThreadLocalHttpServletRequestProxy.java
@@ -404,5 +404,4 @@ public class ThreadLocalHttpServletRequestProxy implements HttpServletRequest {
return Constraint.isNotNull(HttpServletRequestResponseContext.getRequest(),
"Current HttpServletRequest has not been loaded via HttpServletRequestResponseContext");
}
-
}
diff --git a/src/main/java/net/shibboleth/utilities/java/support/net/ThreadLocalHttpServletRequestSupplier.java b/src/main/java/net/shibboleth/utilities/java/support/net/ThreadLocalHttpServletRequestSupplier.java
new file mode 100644
index 0000000..6493a68
--- /dev/null
+++ b/src/main/java/net/shibboleth/utilities/java/support/net/ThreadLocalHttpServletRequestSupplier.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements. See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID 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 net.shibboleth.utilities.java.support.net;
+
+import java.util.function.Supplier;
+
+import jakarta.servlet.http.HttpServletRequest;
+import net.shibboleth.utilities.java.support.logic.Constraint;
+
+/**
+ * An implementation of {@link Supplier<HttpServletRequest>} which looks up the current thread-local
+ * servlet request obtained from {@link HttpServletRequestResponseContext}.
+ */
+public class ThreadLocalHttpServletRequestSupplier implements Supplier<HttpServletRequest> {
+
+ /**
+ * {@inheritDoc}
+ * Get the current HttpServletRequest from ThreadLocal storage.
+ *
+ * @return the current request
+ */
+ public HttpServletRequest get() {
+ return Constraint.isNotNull(HttpServletRequestResponseContext.getRequest(),
+ "Current HttpServletRequest has not been loaded via HttpServletRequestResponseContext");
+ }
+}
diff --git a/src/main/java/net/shibboleth/utilities/java/support/net/ThreadLocalHttpServletResponseProxy.java b/src/main/java/net/shibboleth/utilities/java/support/net/ThreadLocalHttpServletResponseProxy.java
index 4a336a8..68ddeb8 100644
--- a/src/main/java/net/shibboleth/utilities/java/support/net/ThreadLocalHttpServletResponseProxy.java
+++ b/src/main/java/net/shibboleth/utilities/java/support/net/ThreadLocalHttpServletResponseProxy.java
@@ -230,5 +230,4 @@ public class ThreadLocalHttpServletResponseProxy implements HttpServletResponse
return Constraint.isNotNull(HttpServletRequestResponseContext.getResponse(),
"Current HttpServletResponse has not been loaded via HttpServletRequestResponseContext");
}
-
}
diff --git a/src/main/java/net/shibboleth/utilities/java/support/net/ThreadLocalHttpServletResponseSupplier.java b/src/main/java/net/shibboleth/utilities/java/support/net/ThreadLocalHttpServletResponseSupplier.java
new file mode 100644
index 0000000..7180f8d
--- /dev/null
+++ b/src/main/java/net/shibboleth/utilities/java/support/net/ThreadLocalHttpServletResponseSupplier.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements. See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID 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 net.shibboleth.utilities.java.support.net;
+
+import java.util.function.Supplier;
+
+import jakarta.servlet.http.HttpServletResponse;
+import net.shibboleth.utilities.java.support.logic.Constraint;
+
+/**
+ * An implementation of {@link Supplier<HttpServletResponse>} which looks up the current thread-local
+ * servlet response obtained from {@link HttpServletRequestResponseContext}.
+ */
+public class ThreadLocalHttpServletResponseSupplier implements Supplier<HttpServletResponse> {
+
+ /**
+ * {@inheritDoc}
+ * Get the current HttpServletResponse from ThreadLocal storage.
+ *
+ * @return the current response
+ */
+ public HttpServletResponse get() {
+ return Constraint.isNotNull(HttpServletRequestResponseContext.getResponse(),
+ "Current HttpServletResponse has not been loaded via HttpServletRequestResponseContext");
+ }
+}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list