Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly release resources #4020

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
Expand Down Expand Up @@ -76,18 +77,27 @@ public class RegistryConfigurationProcessor {
*
* @param in an InputStream containing XML data, or null.
* @param registryContext the RegistryContext to populate
*
* @throws RegistryException if there's a problem
*/
public static void populateRegistryConfig(InputStream in, RegistryContext registryContext)
throws RegistryException {

if (in == null) {
in = Thread.currentThread().getContextClassLoader().getResourceAsStream(
"org/wso2/carbon/registry/core/servlet/registry.xml");
if (in == null) {
return;
try (InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(
"org/wso2/carbon/registry/core/servlet/registry.xml")) {
if (inputStream != null) {
populateConfig(inputStream, registryContext);
}
} catch (IOException e) {
log.error("Error reading registry.xml from classpath", e);
}
} else {
populateConfig(in, registryContext);
}
}

private static void populateConfig(InputStream in, RegistryContext registryContext)
throws RegistryException {

try {
StAXOMBuilder builder = new StAXOMBuilder(
Expand Down Expand Up @@ -218,42 +228,42 @@ public static void populateRegistryConfig(InputStream in, RegistryContext regist
dataBaseConfiguration.setMaxWait(maxWait.getText());
}

OMElement testWhileIdle = dbConfig
.getFirstChildWithName(new QName(
"testWhileIdle"));
if (testWhileIdle != null) {
dataBaseConfiguration
.setTestWhileIdle(testWhileIdle
.getText());
}
OMElement timeBetweenEvictionRunsMillis = dbConfig
.getFirstChildWithName(new QName(
"timeBetweenEvictionRunsMillis"));
if (timeBetweenEvictionRunsMillis != null) {
dataBaseConfiguration
.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis
.getText());
}
OMElement minEvictableIdleTimeMillis = dbConfig
.getFirstChildWithName(new QName(
"minEvictableIdleTimeMillis"));
if (minEvictableIdleTimeMillis != null) {
dataBaseConfiguration
.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis
.getText());
}
OMElement numTestsPerEvictionRun = dbConfig
.getFirstChildWithName(new QName(
"numTestsPerEvictionRun"));
if (numTestsPerEvictionRun != null) {
dataBaseConfiguration
.setNumTestsPerEvictionRun(numTestsPerEvictionRun
.getText());
}
OMElement testWhileIdle = dbConfig
.getFirstChildWithName(new QName(
"testWhileIdle"));
if (testWhileIdle != null) {
dataBaseConfiguration
.setTestWhileIdle(testWhileIdle
.getText());
}

OMElement timeBetweenEvictionRunsMillis = dbConfig
.getFirstChildWithName(new QName(
"timeBetweenEvictionRunsMillis"));
if (timeBetweenEvictionRunsMillis != null) {
dataBaseConfiguration
.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis
.getText());
}

OMElement minEvictableIdleTimeMillis = dbConfig
.getFirstChildWithName(new QName(
"minEvictableIdleTimeMillis"));
if (minEvictableIdleTimeMillis != null) {
dataBaseConfiguration
.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis
.getText());
}

OMElement numTestsPerEvictionRun = dbConfig
.getFirstChildWithName(new QName(
"numTestsPerEvictionRun"));
if (numTestsPerEvictionRun != null) {
dataBaseConfiguration
.setNumTestsPerEvictionRun(numTestsPerEvictionRun
.getText());
}

OMElement maxActive =
dbConfig.getFirstChildWithName(new QName("maxActive"));
if (maxActive != null) {
Expand Down Expand Up @@ -373,7 +383,8 @@ public static void populateRegistryConfig(InputStream in, RegistryContext regist
if (versionConfig != null && "true".equals(versionConfig.getText())) {
registryContext.setVersionOnChange(true);
} else {
registryContext.setVersionOnChange(false); }
registryContext.setVersionOnChange(false);
}
initializeHandlers(configElement, registryContext);

// process query processor config
Expand Down