You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by co...@apache.org on 2016/10/25 09:20:51 UTC
svn commit: r1766488 - in
/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security:
keys/storage/implementations/CertsInFilesystemDirectoryResolver.java
utils/resolver/implementations/ResolverDirectHTTP.java
Author: coheigea
Date: Tue Oct 25 09:20:51 2016
New Revision: 1766488
URL: http://svn.apache.org/viewvc?rev=1766488&view=rev
Log:
Finished try-with-resources work
Modified:
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/keys/storage/implementations/CertsInFilesystemDirectoryResolver.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/utils/resolver/implementations/ResolverDirectHTTP.java
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/keys/storage/implementations/CertsInFilesystemDirectoryResolver.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/keys/storage/implementations/CertsInFilesystemDirectoryResolver.java?rev=1766488&r1=1766487&r2=1766488&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/keys/storage/implementations/CertsInFilesystemDirectoryResolver.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/keys/storage/implementations/CertsInFilesystemDirectoryResolver.java Tue Oct 25 09:20:51 2016
@@ -100,9 +100,7 @@ public class CertsInFilesystemDirectoryR
boolean added = false;
String dn = null;
- FileInputStream fis = null;
- try {
- fis = new FileInputStream(file);
+ try (FileInputStream fis = new FileInputStream(file)) {
X509Certificate cert =
(X509Certificate) cf.generateCertificate(fis);
@@ -128,15 +126,9 @@ public class CertsInFilesystemDirectoryR
if (log.isDebugEnabled()) {
log.debug("Could not add certificate from file " + filename, ex);
}
- } finally {
- try {
- if (fis != null) {
- fis.close();
- }
- } catch (IOException ex) {
- if (log.isDebugEnabled()) {
- log.debug("Could not add certificate from file " + filename, ex);
- }
+ } catch (IOException ex) {
+ if (log.isDebugEnabled()) {
+ log.debug("Could not add certificate from file " + filename, ex);
}
}
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/utils/resolver/implementations/ResolverDirectHTTP.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/utils/resolver/implementations/ResolverDirectHTTP.java?rev=1766488&r1=1766487&r2=1766488&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/utils/resolver/implementations/ResolverDirectHTTP.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/utils/resolver/implementations/ResolverDirectHTTP.java Tue Oct 25 09:20:51 2016
@@ -96,14 +96,12 @@ public class ResolverDirectHTTP extends
@Override
public XMLSignatureInput engineResolveURI(ResourceResolverContext context)
throws ResourceResolverException {
- InputStream inputStream = null;
+
try {
-
// calculate new URI
URI uriNew = getNewURI(context.uriToResolve, context.baseUri);
URL url = uriNew.toURL();
- URLConnection urlConnection;
- urlConnection = openConnection(url);
+ URLConnection urlConnection = openConnection(url);
// check if Basic authentication is required
String auth = urlConnection.getHeaderField("WWW-Authenticate");
@@ -128,8 +126,8 @@ public class ResolverDirectHTTP extends
}
String mimeType = urlConnection.getHeaderField("Content-Type");
- inputStream = urlConnection.getInputStream();
- try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
+ try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ InputStream inputStream = urlConnection.getInputStream()) {
byte[] buf = new byte[4096];
int read = 0;
int summarized = 0;
@@ -160,16 +158,6 @@ public class ResolverDirectHTTP extends
throw new ResourceResolverException(ex, context.uriToResolve, context.baseUri, "generic.EmptyMessage");
} catch (IllegalArgumentException e) {
throw new ResourceResolverException(e, context.uriToResolve, context.baseUri, "generic.EmptyMessage");
- } finally {
- if (inputStream != null) {
- try {
- inputStream.close();
- } catch (IOException e) {
- if (log.isDebugEnabled()) {
- log.debug(e.getMessage(), e);
- }
- }
- }
}
}