Skip to content

Commit c470fbd

Browse files
committed
Web-Client SNAPSHOT bump
Cleanup resources property
1 parent e3d46ca commit c470fbd

File tree

5 files changed

+38
-14
lines changed

5 files changed

+38
-14
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,13 @@
140140
<dependency>
141141
<groupId>${project.groupId}</groupId>
142142
<artifactId>client</artifactId>
143-
<version>4.2.4</version>
143+
<version>4.2.5-SNAPSHOT</version>
144144
<classifier>classes</classifier>
145145
</dependency>
146146
<dependency>
147147
<groupId>${project.groupId}</groupId>
148148
<artifactId>client</artifactId>
149-
<version>4.2.4</version>
149+
<version>4.2.5-SNAPSHOT</version>
150150
<type>war</type>
151151
</dependency>
152152
<!-- required by jsonld-java - version same as Jersey's HTTP Client -->

src/main/java/com/atomgraph/linkeddatahub/Application.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@
192192
import jakarta.ws.rs.client.Client;
193193
import jakarta.ws.rs.client.ClientBuilder;
194194
import jakarta.ws.rs.client.ClientRequestFilter;
195+
import java.util.concurrent.ConcurrentHashMap;
195196
import javax.xml.transform.TransformerException;
196197
import javax.xml.transform.stream.StreamSource;
197198
import net.jodah.expiringmap.ExpiringMap;
@@ -280,7 +281,7 @@ public class Application extends ResourceConfig
280281
private final List<Locale> supportedLanguages;
281282
private final ExpiringMap<URI, Model> webIDmodelCache = ExpiringMap.builder().expiration(1, TimeUnit.DAYS).build(); // TO-DO: config for the expiration period?
282283
private final ExpiringMap<String, Model> oidcModelCache = ExpiringMap.builder().variableExpiration().build();
283-
private final Map<URI, XsltExecutable> xsltExecutableCache = new HashMap<>();
284+
private final Map<URI, XsltExecutable> xsltExecutableCache = new ConcurrentHashMap<>();
284285
private final MessageDigest messageDigest;
285286
private final boolean enableWebIDSignUp;
286287
private final String oidcRefreshTokensPropertiesPath;
@@ -636,10 +637,16 @@ public Application(final ServletConfig servletConfig, final MediaTypes mediaType
636637
try
637638
{
638639
keyStore = KeyStore.getInstance("PKCS12");
639-
keyStore.load(new FileInputStream(new java.io.File(new URI(clientKeyStoreURIString))), clientKeyStorePassword.toCharArray());
640+
try (FileInputStream keyStoreInputStream = new FileInputStream(new java.io.File(new URI(clientKeyStoreURIString))))
641+
{
642+
keyStore.load(keyStoreInputStream, clientKeyStorePassword.toCharArray());
643+
}
640644

641645
trustStore = KeyStore.getInstance("JKS");
642-
trustStore.load(new FileInputStream(new java.io.File(new URI(clientTrustStoreURIString))), clientTrustStorePassword.toCharArray());
646+
try (FileInputStream trustStoreInputStream = new FileInputStream(new java.io.File(new URI(clientTrustStoreURIString))))
647+
{
648+
trustStore.load(trustStoreInputStream, clientTrustStorePassword.toCharArray());
649+
}
643650

644651
client = getClient(keyStore, clientKeyStorePassword, trustStore, maxConnPerRoute, maxTotalConn, null, false);
645652
externalClient = getClient(keyStore, clientKeyStorePassword, trustStore, maxConnPerRoute, maxTotalConn, null, false);

src/main/java/com/atomgraph/linkeddatahub/resource/Generate.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,13 @@ public Response post(Model model, @QueryParam("default") @DefaultValue("false")
145145
service)));
146146
new Skolemizer(containerGraphURI.toString()).apply(containerModel);
147147

148-
Response containerResponse = super.post(containerModel, false, containerGraphURI);
149-
if (containerResponse.getStatus() != Response.Status.CREATED.getStatusCode())
148+
try (Response containerResponse = super.post(containerModel, false, containerGraphURI))
150149
{
151-
if (log.isErrorEnabled()) log.error("Cannot create container");
152-
throw new InternalServerErrorException("Cannot create container");
150+
if (containerResponse.getStatus() != Response.Status.CREATED.getStatusCode())
151+
{
152+
if (log.isErrorEnabled()) log.error("Cannot create container");
153+
throw new InternalServerErrorException("Cannot create container");
154+
}
153155
}
154156
}
155157
}

src/main/java/com/atomgraph/linkeddatahub/resource/Graph.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -686,8 +686,11 @@ public File writeFile(Resource resource, FormDataBodyPart bodyPart)
686686
{
687687
dis.getMessageDigest().reset();
688688
File tempFile = File.createTempFile("tmp", null);
689-
FileChannel destination = new FileOutputStream(tempFile).getChannel();
690-
destination.transferFrom(Channels.newChannel(dis), 0, 104857600);
689+
try (FileOutputStream fos = new FileOutputStream(tempFile);
690+
FileChannel destination = fos.getChannel())
691+
{
692+
destination.transferFrom(Channels.newChannel(dis), 0, 104857600);
693+
}
691694
String sha1Hash = Hex.encodeHexString(dis.getMessageDigest().digest()); // BigInteger seems to have an issue when the leading hex digit is 0
692695
if (log.isDebugEnabled()) log.debug("Wrote file: {} with SHA1 hash: {}", tempFile, sha1Hash);
693696

@@ -699,7 +702,10 @@ public File writeFile(Resource resource, FormDataBodyPart bodyPart)
699702
if (log.isDebugEnabled()) log.debug("Renaming resource: {} to SHA1 based URI: {}", resource, sha1Uri);
700703
ResourceUtils.renameResource(resource, sha1Uri.toString());
701704

702-
return writeFile(sha1Uri, getUriInfo().getBaseUri(), new FileInputStream(tempFile));
705+
try (FileInputStream fis = new FileInputStream(tempFile))
706+
{
707+
return writeFile(sha1Uri, getUriInfo().getBaseUri(), fis);
708+
}
703709
}
704710
catch (IOException ex)
705711
{

src/main/java/com/atomgraph/linkeddatahub/writer/function/SendHTTPRequest.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,11 @@ public XdmValue call(XdmValue[] arguments) throws SaxonApiException
114114
if (log.isDebugEnabled()) log.debug("Could not execute ldh:send-request function. href: '{}' method: '{}'", href, method);
115115
throw new IOException("Could not execute ldh:send-request function. href: '" + href + "' method: '" + method + "'");
116116
}
117-
if (cr.hasEntity()) return getProcessor().newDocumentBuilder().build(new StreamSource(cr.readEntity(InputStream.class)));
117+
if (cr.hasEntity())
118+
try (InputStream is = cr.readEntity(InputStream.class))
119+
{
120+
return getProcessor().newDocumentBuilder().build(new StreamSource(is));
121+
}
118122
}
119123
else
120124
{
@@ -127,7 +131,12 @@ public XdmValue call(XdmValue[] arguments) throws SaxonApiException
127131
if (log.isDebugEnabled()) log.debug("Could not execute ldh:send-request function. href: '{}' method: '{}'", href, method);
128132
throw new IOException("Could not execute ldh:send-request function. href: '" + href + "' method: '" + method + "'");
129133
}
130-
if (cr.hasEntity()) return getProcessor().newDocumentBuilder().build(new StreamSource(cr.readEntity(InputStream.class)));
134+
135+
if (cr.hasEntity())
136+
try (InputStream is = cr.readEntity(InputStream.class))
137+
{
138+
return getProcessor().newDocumentBuilder().build(new StreamSource(is));
139+
}
131140
}
132141
}
133142

0 commit comments

Comments
 (0)