From d22de197a117fda78ebc0a5abcfc824832d74fc3 Mon Sep 17 00:00:00 2001 From: madhawap Date: Fri, 6 Jan 2017 19:07:49 +0530 Subject: [PATCH] fix to WebappPublisherConfig --- .../publisher/config/WebappPublisherConfig.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/config/WebappPublisherConfig.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/config/WebappPublisherConfig.java index faf94c81918..a54d370e5cf 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/config/WebappPublisherConfig.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/config/WebappPublisherConfig.java @@ -42,6 +42,7 @@ public class WebappPublisherConfig { private boolean isPublished; private boolean isEnabledUpdateApi; private Profiles profiles; + private static boolean isInitialized = false; private static WebappPublisherConfig config; @@ -52,9 +53,13 @@ public class WebappPublisherConfig { } public static WebappPublisherConfig getInstance() { - if (config == null) { - throw new InvalidConfigurationStateException("Webapp Authenticator Configuration is not " + - "initialized properly"); + if (!isInitialized) { + try { + init(); + } catch (WebappPublisherConfigurationFailedException e) { + throw new InvalidConfigurationStateException("Webapp Authenticator Configuration is not " + + "initialized properly"); + } } return config; } @@ -95,7 +100,10 @@ public class WebappPublisherConfig { this.profiles = profiles; } - public static void init() throws WebappPublisherConfigurationFailedException { + public synchronized static void init() throws WebappPublisherConfigurationFailedException { + if (isInitialized) { + return; + } try { File emailSenderConfig = new File(WEBAPP_PUBLISHER_CONFIG_PATH); Document doc = WebappPublisherUtil.convertToDocument(emailSenderConfig); @@ -105,6 +113,7 @@ public class WebappPublisherConfig { Unmarshaller unmarshaller = ctx.createUnmarshaller(); //unmarshaller.setSchema(getSchema()); config = (WebappPublisherConfig) unmarshaller.unmarshal(doc); + isInitialized = true; } catch (JAXBException e) { throw new WebappPublisherConfigurationFailedException("Error occurred while un-marshalling Webapp " + "Publisher Config", e);