diff --git a/components/org.wso2.carbon.identity.api.server.rule.metadata/org.wso2.carbon.identity.api.server.rule.metadata.common/src/main/java/org/wso2/carbon/identity/api/server/rule/metadata/common/RuleMetadataServiceHolder.java b/components/org.wso2.carbon.identity.api.server.rule.metadata/org.wso2.carbon.identity.api.server.rule.metadata.common/src/main/java/org/wso2/carbon/identity/api/server/rule/metadata/common/RuleMetadataServiceHolder.java index 58e087c34c..85ebe33919 100644 --- a/components/org.wso2.carbon.identity.api.server.rule.metadata/org.wso2.carbon.identity.api.server.rule.metadata.common/src/main/java/org/wso2/carbon/identity/api/server/rule/metadata/common/RuleMetadataServiceHolder.java +++ b/components/org.wso2.carbon.identity.api.server.rule.metadata/org.wso2.carbon.identity.api.server.rule.metadata.common/src/main/java/org/wso2/carbon/identity/api/server/rule/metadata/common/RuleMetadataServiceHolder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * Copyright (c) 2024-2025, WSO2 LLC. (http://www.wso2.com). * * WSO2 LLC. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except @@ -18,6 +18,7 @@ package org.wso2.carbon.identity.api.server.rule.metadata.common; +import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.identity.rule.metadata.service.RuleMetadataService; /** @@ -25,15 +26,17 @@ */ public class RuleMetadataServiceHolder { - private static RuleMetadataService ruleMetadataService; + public RuleMetadataServiceHolder() {} - public static RuleMetadataService getRuleMetadataService() { + private static class ServerRuleMetadataServiceHolder { - return ruleMetadataService; + static final RuleMetadataService SERVICE = (RuleMetadataService) PrivilegedCarbonContext + .getThreadLocalCarbonContext() + .getOSGiService(RuleMetadataService.class, null); } - public static void setRuleMetadataService(RuleMetadataService ruleMetadataService) { + public static RuleMetadataService getRuleMetadataService() { - RuleMetadataServiceHolder.ruleMetadataService = ruleMetadataService; + return ServerRuleMetadataServiceHolder.SERVICE; } } diff --git a/components/org.wso2.carbon.identity.api.server.rule.metadata/org.wso2.carbon.identity.api.server.rule.metadata.common/src/main/java/org/wso2/carbon/identity/api/server/rule/metadata/common/factory/RuleMetaOSGiServiceFactory.java b/components/org.wso2.carbon.identity.api.server.rule.metadata/org.wso2.carbon.identity.api.server.rule.metadata.common/src/main/java/org/wso2/carbon/identity/api/server/rule/metadata/common/factory/RuleMetaOSGiServiceFactory.java deleted file mode 100644 index 9594c90ebb..0000000000 --- a/components/org.wso2.carbon.identity.api.server.rule.metadata/org.wso2.carbon.identity.api.server.rule.metadata.common/src/main/java/org/wso2/carbon/identity/api/server/rule/metadata/common/factory/RuleMetaOSGiServiceFactory.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). - * - * WSO2 LLC. 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 org.wso2.carbon.identity.api.server.rule.metadata.common.factory; - -import org.springframework.beans.factory.config.AbstractFactoryBean; -import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.identity.rule.metadata.service.RuleMetadataService; - -/** - * Factory bean used to instantiate the RuleMetadataService type of object inside the container. - */ -public class RuleMetaOSGiServiceFactory extends AbstractFactoryBean { - - private RuleMetadataService ruleMetadataService; - - @Override - public Class getObjectType() { - - return Object.class; - } - - @Override - protected RuleMetadataService createInstance() throws Exception { - - if (this.ruleMetadataService == null) { - ruleMetadataService = (RuleMetadataService) PrivilegedCarbonContext. - getThreadLocalCarbonContext().getOSGiService(RuleMetadataService.class, null); - if (ruleMetadataService == null) { - throw new Exception("Rule Metadata Service is not available."); - } - } - return this.ruleMetadataService; - } -} diff --git a/components/org.wso2.carbon.identity.api.server.rule.metadata/org.wso2.carbon.identity.api.server.rule.metadata.v1/src/gen/java/org/wso2/carbon/identity/api/server/rule/metadata/v1/RulesApi.java b/components/org.wso2.carbon.identity.api.server.rule.metadata/org.wso2.carbon.identity.api.server.rule.metadata.v1/src/gen/java/org/wso2/carbon/identity/api/server/rule/metadata/v1/RulesApi.java index d1b14bf807..86c1a2c2bb 100644 --- a/components/org.wso2.carbon.identity.api.server.rule.metadata/org.wso2.carbon.identity.api.server.rule.metadata.v1/src/gen/java/org/wso2/carbon/identity/api/server/rule/metadata/v1/RulesApi.java +++ b/components/org.wso2.carbon.identity.api.server.rule.metadata/org.wso2.carbon.identity.api.server.rule.metadata.v1/src/gen/java/org/wso2/carbon/identity/api/server/rule/metadata/v1/RulesApi.java @@ -18,12 +18,12 @@ package org.wso2.carbon.identity.api.server.rule.metadata.v1; -import org.springframework.beans.factory.annotation.Autowired; import org.apache.cxf.jaxrs.ext.multipart.Attachment; import org.apache.cxf.jaxrs.ext.multipart.Multipart; import java.io.InputStream; import java.util.List; +import org.wso2.carbon.identity.api.server.rule.metadata.v1.factories.RulesApiServiceFactory; import org.wso2.carbon.identity.api.server.rule.metadata.v1.model.Error; import org.wso2.carbon.identity.api.server.rule.metadata.v1.model.FieldDefinition; import org.wso2.carbon.identity.api.server.rule.metadata.v1.RulesApiService; @@ -40,9 +40,12 @@ public class RulesApi { - @Autowired - private RulesApiService delegate; + private final RulesApiService delegate; + public RulesApi() { + + this.delegate = RulesApiServiceFactory.getRulesApi(); + } @Valid @GET @Path("/metadata") diff --git a/components/org.wso2.carbon.identity.api.server.rule.metadata/org.wso2.carbon.identity.api.server.rule.metadata.v1/src/gen/java/org/wso2/carbon/identity/api/server/rule/metadata/v1/factories/RulesApiServiceFactory.java b/components/org.wso2.carbon.identity.api.server.rule.metadata/org.wso2.carbon.identity.api.server.rule.metadata.v1/src/gen/java/org/wso2/carbon/identity/api/server/rule/metadata/v1/factories/RulesApiServiceFactory.java index 8050fa7d72..7915ca14ec 100644 --- a/components/org.wso2.carbon.identity.api.server.rule.metadata/org.wso2.carbon.identity.api.server.rule.metadata.v1/src/gen/java/org/wso2/carbon/identity/api/server/rule/metadata/v1/factories/RulesApiServiceFactory.java +++ b/components/org.wso2.carbon.identity.api.server.rule.metadata/org.wso2.carbon.identity.api.server.rule.metadata.v1/src/gen/java/org/wso2/carbon/identity/api/server/rule/metadata/v1/factories/RulesApiServiceFactory.java @@ -23,10 +23,10 @@ public class RulesApiServiceFactory { - private final static RulesApiService service = new RulesApiServiceImpl(); + private final static RulesApiService SERVICE = new RulesApiServiceImpl(); public static RulesApiService getRulesApi() { - return service; + return SERVICE; } } diff --git a/components/org.wso2.carbon.identity.api.server.rule.metadata/org.wso2.carbon.identity.api.server.rule.metadata.v1/src/main/java/org/wso2/carbon/identity/api/server/rule/metadata/v1/core/ServerRuleMetadataService.java b/components/org.wso2.carbon.identity.api.server.rule.metadata/org.wso2.carbon.identity.api.server.rule.metadata.v1/src/main/java/org/wso2/carbon/identity/api/server/rule/metadata/v1/core/ServerRuleMetadataService.java index 5b09f05f51..fd9cc08e95 100644 --- a/components/org.wso2.carbon.identity.api.server.rule.metadata/org.wso2.carbon.identity.api.server.rule.metadata.v1/src/main/java/org/wso2/carbon/identity/api/server/rule/metadata/v1/core/ServerRuleMetadataService.java +++ b/components/org.wso2.carbon.identity.api.server.rule.metadata/org.wso2.carbon.identity.api.server.rule.metadata.v1/src/main/java/org/wso2/carbon/identity/api/server/rule/metadata/v1/core/ServerRuleMetadataService.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * Copyright (c) 2024-2025, WSO2 LLC. (http://www.wso2.com). * * WSO2 LLC. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except @@ -19,7 +19,6 @@ package org.wso2.carbon.identity.api.server.rule.metadata.v1.core; import org.wso2.carbon.context.CarbonContext; -import org.wso2.carbon.identity.api.server.rule.metadata.common.RuleMetadataServiceHolder; import org.wso2.carbon.identity.api.server.rule.metadata.v1.model.Field; import org.wso2.carbon.identity.api.server.rule.metadata.v1.model.Link; import org.wso2.carbon.identity.api.server.rule.metadata.v1.util.RuleMetadataAPIErrorBuilder; @@ -32,6 +31,7 @@ import org.wso2.carbon.identity.rule.metadata.model.OptionsReferenceValue; import org.wso2.carbon.identity.rule.metadata.model.OptionsValue; import org.wso2.carbon.identity.rule.metadata.model.Value; +import org.wso2.carbon.identity.rule.metadata.service.RuleMetadataService; import java.util.ArrayList; import java.util.List; @@ -41,6 +41,12 @@ */ public class ServerRuleMetadataService { + private final RuleMetadataService ruleMetadataService; + + public ServerRuleMetadataService(RuleMetadataService ruleMetadataService) { + + this.ruleMetadataService = ruleMetadataService; + } /** * Get the expression metadata for the given flow. * @param flow Flow type @@ -52,8 +58,7 @@ public List fieldDefinitions = - RuleMetadataServiceHolder.getRuleMetadataService().getExpressionMeta(flowType, + List fieldDefinitions = ruleMetadataService.getExpressionMeta(flowType, CarbonContext.getThreadLocalCarbonContext().getTenantDomain()); List diff --git a/components/org.wso2.carbon.identity.api.server.rule.metadata/org.wso2.carbon.identity.api.server.rule.metadata.v1/src/main/java/org/wso2/carbon/identity/api/server/rule/metadata/v1/factories/ServerRuleMetadataServiceFactory.java b/components/org.wso2.carbon.identity.api.server.rule.metadata/org.wso2.carbon.identity.api.server.rule.metadata.v1/src/main/java/org/wso2/carbon/identity/api/server/rule/metadata/v1/factories/ServerRuleMetadataServiceFactory.java new file mode 100644 index 0000000000..972ce4059d --- /dev/null +++ b/components/org.wso2.carbon.identity.api.server.rule.metadata/org.wso2.carbon.identity.api.server.rule.metadata.v1/src/main/java/org/wso2/carbon/identity/api/server/rule/metadata/v1/factories/ServerRuleMetadataServiceFactory.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. 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 org.wso2.carbon.identity.api.server.rule.metadata.v1.factories; + +import org.wso2.carbon.identity.api.server.rule.metadata.common.RuleMetadataServiceHolder; +import org.wso2.carbon.identity.api.server.rule.metadata.v1.core.ServerRuleMetadataService; +import org.wso2.carbon.identity.rule.metadata.service.RuleMetadataService; + +public class ServerRuleMetadataServiceFactory { + + private static final ServerRuleMetadataService SERVICE; + + static { + RuleMetadataService ruleMetadataService = RuleMetadataServiceHolder.getRuleMetadataService(); + if (ruleMetadataService == null) { + throw new IllegalStateException("RuleMetadataService not available from OSGI context."); + } + SERVICE = new ServerRuleMetadataService(ruleMetadataService); + } + + public static ServerRuleMetadataService getServerRuleMetadataService() { + + return SERVICE; + } + +} diff --git a/components/org.wso2.carbon.identity.api.server.rule.metadata/org.wso2.carbon.identity.api.server.rule.metadata.v1/src/main/java/org/wso2/carbon/identity/api/server/rule/metadata/v1/impl/RulesApiServiceImpl.java b/components/org.wso2.carbon.identity.api.server.rule.metadata/org.wso2.carbon.identity.api.server.rule.metadata.v1/src/main/java/org/wso2/carbon/identity/api/server/rule/metadata/v1/impl/RulesApiServiceImpl.java index 19cc9fadbd..02ef18eb6d 100644 --- a/components/org.wso2.carbon.identity.api.server.rule.metadata/org.wso2.carbon.identity.api.server.rule.metadata.v1/src/main/java/org/wso2/carbon/identity/api/server/rule/metadata/v1/impl/RulesApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.server.rule.metadata/org.wso2.carbon.identity.api.server.rule.metadata.v1/src/main/java/org/wso2/carbon/identity/api/server/rule/metadata/v1/impl/RulesApiServiceImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * Copyright (c) 2024-2025, WSO2 LLC. (http://www.wso2.com). * * WSO2 LLC. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except @@ -18,9 +18,9 @@ package org.wso2.carbon.identity.api.server.rule.metadata.v1.impl; -import org.springframework.beans.factory.annotation.Autowired; import org.wso2.carbon.identity.api.server.rule.metadata.v1.RulesApiService; import org.wso2.carbon.identity.api.server.rule.metadata.v1.core.ServerRuleMetadataService; +import org.wso2.carbon.identity.api.server.rule.metadata.v1.factories.ServerRuleMetadataServiceFactory; import javax.ws.rs.core.Response; @@ -29,8 +29,16 @@ */ public class RulesApiServiceImpl implements RulesApiService { - @Autowired - private ServerRuleMetadataService serverRuleMetadataService; + private final ServerRuleMetadataService serverRuleMetadataService; + + public RulesApiServiceImpl() { + + try { + this.serverRuleMetadataService = ServerRuleMetadataServiceFactory.getServerRuleMetadataService(); + } catch (IllegalStateException e) { + throw new RuntimeException("Error occurred while initiating serverRuleMetadataService.", e); + } + } @Override public Response getExpressionMeta(String flow) { diff --git a/components/org.wso2.carbon.identity.api.server.rule.metadata/org.wso2.carbon.identity.api.server.rule.metadata.v1/src/main/resources/META-INF/cxf/rule-metadata-server-v1-cxf.xml b/components/org.wso2.carbon.identity.api.server.rule.metadata/org.wso2.carbon.identity.api.server.rule.metadata.v1/src/main/resources/META-INF/cxf/rule-metadata-server-v1-cxf.xml deleted file mode 100644 index cb6f995fcf..0000000000 --- a/components/org.wso2.carbon.identity.api.server.rule.metadata/org.wso2.carbon.identity.api.server.rule.metadata.v1/src/main/resources/META-INF/cxf/rule-metadata-server-v1-cxf.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - - - - - -