[java-shib-shared] branch main updated: IDP-2088 AbstractIdPModule.BasicModuleResource may orphan a ClassicHttpResponse
Rod Widdowson
rdw at steadingsoftware.com
Sat Apr 8 10:51:06 UTC 2023
This is an automated email from the git hooks/post-receive script.
rdw pushed a commit to branch main
in repository java-shib-shared.
View the commit online:
http://git.shibboleth.net/view/?p=java-shib-shared.git;a=commit;h=b87ae7d237aa363912c5ea23011ef347c5027525
The following commit(s) were added to refs/heads/main by this push:
new b87ae7d2 IDP-2088 AbstractIdPModule.BasicModuleResource may orphan a ClassicHttpResponse
b87ae7d2 is described below
commit b87ae7d237aa363912c5ea23011ef347c5027525
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Sat Apr 8 11:50:36 2023 +0100
IDP-2088 AbstractIdPModule.BasicModuleResource may orphan a ClassicHttpResponse
https://shibboleth.atlassian.net/browse/IDP-2088
Exbed ConnectionClosingInputStream for use elsewhere
---
.../resource/ConnectionClosingInputStream.java | 107 +++++++++++++++++++++
.../spring/httpclient/resource/HTTPResource.java | 91 ++----------------
2 files changed, 116 insertions(+), 82 deletions(-)
diff --git a/shib-networking-spring/src/main/java/net/shibboleth/shared/spring/httpclient/resource/ConnectionClosingInputStream.java b/shib-networking-spring/src/main/java/net/shibboleth/shared/spring/httpclient/resource/ConnectionClosingInputStream.java
new file mode 100644
index 00000000..1fb27406
--- /dev/null
+++ b/shib-networking-spring/src/main/java/net/shibboleth/shared/spring/httpclient/resource/ConnectionClosingInputStream.java
@@ -0,0 +1,107 @@
+/*
+ * 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.shared.spring.httpclient.resource;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.annotation.Nonnull;
+
+import org.apache.hc.core5.http.ClassicHttpResponse;
+import org.apache.hc.core5.http.HttpResponse;
+
+/**
+ * A wrapper around the entity content {@link InputStream} represented by an {@link HttpResponse}
+ * that closes the stream and the HttpResponse when {@link #close()} is invoked.
+ */
+ public class ConnectionClosingInputStream extends InputStream {
+
+ /** HTTP response that is being wrapped. */
+ @Nonnull private final ClassicHttpResponse response;
+
+ /** Stream owned by the given HTTP response. */
+ @Nonnull private final InputStream stream;
+
+ /**
+ * Constructor.
+ *
+ * @param httpResponse HTTP method that was invoked
+ * @throws IOException if there is a problem getting the entity content input stream from the response
+ */
+ public ConnectionClosingInputStream(@Nonnull final ClassicHttpResponse httpResponse) throws IOException {
+ response = httpResponse;
+ final InputStream str = response.getEntity().getContent();
+ assert str!=null;
+ stream = str;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public int available() throws IOException {
+ return stream.available();
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void close() throws IOException {
+ stream.close();
+ response.close();
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public synchronized void mark(final int readLimit) {
+ stream.mark(readLimit);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public boolean markSupported() {
+ return stream.markSupported();
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public int read() throws IOException {
+ return stream.read();
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public int read(final byte[] b) throws IOException {
+ return stream.read(b);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public int read(final byte[] b, final int off, final int len) throws IOException {
+ return stream.read(b, off, len);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public synchronized void reset() throws IOException {
+ stream.reset();
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public long skip(final long n) throws IOException {
+ return stream.skip(n);
+ }
+}
\ No newline at end of file
diff --git a/shib-networking-spring/src/main/java/net/shibboleth/shared/spring/httpclient/resource/HTTPResource.java b/shib-networking-spring/src/main/java/net/shibboleth/shared/spring/httpclient/resource/HTTPResource.java
index 5aedf091..5726a7d6 100644
--- a/shib-networking-spring/src/main/java/net/shibboleth/shared/spring/httpclient/resource/HTTPResource.java
+++ b/shib-networking-spring/src/main/java/net/shibboleth/shared/spring/httpclient/resource/HTTPResource.java
@@ -123,7 +123,9 @@ public class HTTPResource extends AbstractIdentifiedInitializableComponent imple
* @return a new instance of {@link HttpCacheContext}
*/
@Nonnull protected HttpCacheContext buildHttpClientContext() {
- return HttpCacheContext.create();
+ final HttpCacheContext result = HttpCacheContext.create();
+ assert result != null;
+ return result;
}
/**
@@ -234,7 +236,9 @@ public class HTTPResource extends AbstractIdentifiedInitializableComponent imple
/** {@inheritDoc} */
@Override @Nonnull public URI getURI() throws IOException {
try {
- return resourceURL.toURI();
+ final URI result = resourceURL.toURI();
+ assert result != null;
+ return result;
} catch (final URISyntaxException ex) {
throw new IOException("Invalid URI [" + resourceURL + "]", ex);
}
@@ -379,7 +383,9 @@ public class HTTPResource extends AbstractIdentifiedInitializableComponent imple
/** {@inheritDoc} */
@Override @Nonnull public String getDescription() {
final StringBuilder builder = new StringBuilder("HTTPResource [").append(resourceURL.toString()).append(']');
- return builder.toString();
+ final String result = builder.toString();
+ assert result != null;
+ return result;
}
@@ -397,84 +403,5 @@ public class HTTPResource extends AbstractIdentifiedInitializableComponent imple
log.error("Error closing HTTP response from '{}'", resourceURL.toExternalForm(), e);
}
}
-
- /**
- * A wrapper around the entity content {@link InputStream} represented by an {@link HttpResponse}
- * that closes the stream and the HttpResponse when {@link #close()} is invoked.
- */
- private static class ConnectionClosingInputStream extends InputStream {
-
- /** HTTP response that is being wrapped. */
- @Nonnull private final ClassicHttpResponse response;
-
- /** Stream owned by the given HTTP response. */
- @Nonnull private final InputStream stream;
-
- /**
- * Constructor.
- *
- * @param httpResponse HTTP method that was invoked
- * @throws IOException if there is a problem getting the entity content input stream from the response
- */
- public ConnectionClosingInputStream(@Nonnull final ClassicHttpResponse httpResponse) throws IOException {
- response = httpResponse;
- stream = response.getEntity().getContent();
- }
-
- /** {@inheritDoc} */
- @Override
- public int available() throws IOException {
- return stream.available();
- }
-
- /** {@inheritDoc} */
- @Override
- public void close() throws IOException {
- stream.close();
- response.close();
- }
-
- /** {@inheritDoc} */
- @Override
- public synchronized void mark(final int readLimit) {
- stream.mark(readLimit);
- }
-
- /** {@inheritDoc} */
- @Override
- public boolean markSupported() {
- return stream.markSupported();
- }
-
- /** {@inheritDoc} */
- @Override
- public int read() throws IOException {
- return stream.read();
- }
-
- /** {@inheritDoc} */
- @Override
- public int read(final byte[] b) throws IOException {
- return stream.read(b);
- }
-
- /** {@inheritDoc} */
- @Override
- public int read(final byte[] b, final int off, final int len) throws IOException {
- return stream.read(b, off, len);
- }
-
- /** {@inheritDoc} */
- @Override
- public synchronized void reset() throws IOException {
- stream.reset();
- }
-
- /** {@inheritDoc} */
- @Override
- public long skip(final long n) throws IOException {
- return stream.skip(n);
- }
- }
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list