From e142b189e0fbf978bd99c1ec41e8ea3f4cd5b94b Mon Sep 17 00:00:00 2001 From: Chinthaka Jayatilake <37581983+ChinthakaJ98@users.noreply.github.com> Date: Thu, 30 Nov 2023 10:17:52 +0530 Subject: [PATCH 1/3] Adding support to read from env variables --- .../synapse/config/xml/ProxyServiceFactory.java | 8 ++++++-- .../xml/endpoints/TemplateEndpointFactory.java | 4 +++- .../config/xml/endpoints/WSDLEndpointFactory.java | 14 ++++++++------ 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/modules/core/src/main/java/org/apache/synapse/config/xml/ProxyServiceFactory.java b/modules/core/src/main/java/org/apache/synapse/config/xml/ProxyServiceFactory.java index bb996ffaf2..cc61e4e7e6 100644 --- a/modules/core/src/main/java/org/apache/synapse/config/xml/ProxyServiceFactory.java +++ b/modules/core/src/main/java/org/apache/synapse/config/xml/ProxyServiceFactory.java @@ -237,9 +237,13 @@ public static ProxyService createProxy(OMElement elem, Properties properties) { proxy.setPreservePolicy(preservePolicy.getAttributeValue()); } if (wsdlEndpoint != null) { - proxy.setPublishWSDLEndpoint(wsdlEndpoint.getAttributeValue()); + String resolvedWsdlEndpoint = ResolverFactory.getInstance() + .getResolver(wsdlEndpoint.getAttributeValue()).resolve(); + proxy.setPublishWSDLEndpoint(resolvedWsdlEndpoint); } else if (wsdlKey != null) { - proxy.setWSDLKey(wsdlKey.getAttributeValue()); + String resolvedWsdlKey = ResolverFactory.getInstance() + .getResolver(wsdlKey.getAttributeValue()).resolve(); + proxy.setWSDLKey(resolvedWsdlKey); } else { OMAttribute wsdlURI = wsdl.getAttribute( new QName(XMLConfigConstants.NULL_NAMESPACE, "uri")); diff --git a/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/TemplateEndpointFactory.java b/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/TemplateEndpointFactory.java index 88c83e1502..e42abf9c71 100644 --- a/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/TemplateEndpointFactory.java +++ b/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/TemplateEndpointFactory.java @@ -59,7 +59,9 @@ public Endpoint createEndpoint(OMElement endpointElement, boolean a, Properties OMAttribute endpointTemplateAttribute = endpointElement.getAttribute( new QName(XMLConfigConstants.NULL_NAMESPACE, "template")); if (endpointTemplateAttribute != null) { - templateEndpoint.setTemplate(endpointTemplateAttribute.getAttributeValue()); + String resolvedTemplate = ResolverFactory.getInstance() + .getResolver(endpointTemplateAttribute.getAttributeValue()).resolve(); + templateEndpoint.setTemplate(resolvedTemplate); } else { handleException("Error loading the configuration from endpoint group, " + templateEndpoint.getName() + diff --git a/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/WSDLEndpointFactory.java b/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/WSDLEndpointFactory.java index 7cd5967605..f0d0529b68 100644 --- a/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/WSDLEndpointFactory.java +++ b/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/WSDLEndpointFactory.java @@ -114,14 +114,16 @@ protected Endpoint createEndpoint(OMElement epConfig, boolean anonymousEndpoint, // get the service name and port name. at this point we should not worry about // the presence of those parameters. they are handled by corresponding WSDL builders. - String serviceName = wsdlElement.getAttributeValue(new QName("service")); - String portName = wsdlElement.getAttributeValue(new QName("port")); + String resolvedServiceName = ResolverFactory.getInstance() + .getResolver(wsdlElement.getAttributeValue(new QName("service"))).resolve();; + String resolvedPortName = ResolverFactory.getInstance() + .getResolver(wsdlElement.getAttributeValue(new QName("port"))).resolve(); // check if wsdl is supplied as a URI String wsdlURI = wsdlElement.getAttributeValue(new QName("uri")); // set serviceName and portName in the endpoint. it does not matter if these are // null at this point. we are setting them only for serialization purpose. - wsdlEndpoint.setServiceName(serviceName); - wsdlEndpoint.setPortName(portName); + wsdlEndpoint.setServiceName(resolvedServiceName); + wsdlEndpoint.setPortName(resolvedPortName); String noParsing = properties.getProperty(SKIP_WSDL_PARSING); @@ -142,7 +144,7 @@ protected Endpoint createEndpoint(OMElement epConfig, boolean anonymousEndpoint, new WSDL11EndpointBuilder(). populateEndpointDefinitionFromWSDL(endpoint, - wsdlURI.trim(), omElement, serviceName, portName); + wsdlURI.trim(), omElement, resolvedServiceName, resolvedPortName); } else if (WSDL2Constants.WSDL_NAMESPACE.equals(nsUri)) { //endpoint = new WSDL20EndpointBuilder(). @@ -181,7 +183,7 @@ protected Endpoint createEndpoint(OMElement epConfig, boolean anonymousEndpoint, baseUri = baseUri + File.separator; } new WSDL11EndpointBuilder().populateEndpointDefinitionFromWSDL(endpoint, - baseUri, definitionElement, serviceName, portName); + baseUri, definitionElement, resolvedServiceName, resolvedPortName); } else { endpoint = new EndpointDefinition(); } From 17b5cce23334bfedd88ce2e48052e5c556040b88 Mon Sep 17 00:00:00 2001 From: Chinthaka Jayatilake <37581983+ChinthakaJ98@users.noreply.github.com> Date: Thu, 30 Nov 2023 14:24:49 +0530 Subject: [PATCH 2/3] Adding support to read from env variables --- .../synapse/config/xml/AbstractDBMediatorFactory.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractDBMediatorFactory.java b/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractDBMediatorFactory.java index 740b220abf..5e1bf797da 100644 --- a/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractDBMediatorFactory.java +++ b/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractDBMediatorFactory.java @@ -136,13 +136,15 @@ protected void buildDataSource(OMElement elem, AbstractDBMediator mediator) { } private void readLookupConfig(AbstractDBMediator mediator, OMElement pool) { - String dataSourceName = getValue(pool, DSNAME_Q); - mediator.setDataSourceName(dataSourceName); + String resolvedDataSourceName = ResolverFactory.getInstance().getResolver(getValue(pool, DSNAME_Q)).resolve(); + mediator.setDataSourceName(resolvedDataSourceName); saveElementConfig(pool, DSNAME_Q, mediator); if (pool.getFirstChildWithName(ICCLASS_Q) != null) { + String resolvedInitialContextClass = ResolverFactory.getInstance() + .getResolver(getValue(pool, ICCLASS_Q)).resolve(); Properties props = new Properties(); - props.put(Context.INITIAL_CONTEXT_FACTORY, getValue(pool, ICCLASS_Q)); + props.put(Context.INITIAL_CONTEXT_FACTORY, resolvedInitialContextClass); props.put(Context.PROVIDER_URL, getValue(pool, URL_Q)); props.put(Context.SECURITY_PRINCIPAL, getValue(pool, USER_Q)); props.put(Context.SECURITY_CREDENTIALS, getValue(pool, PASS_Q)); From 4f9884fc2d502e44d9a3c86abc1df37731da14a0 Mon Sep 17 00:00:00 2001 From: Chinthaka Jayatilake <37581983+ChinthakaJ98@users.noreply.github.com> Date: Thu, 30 Nov 2023 22:37:34 +0530 Subject: [PATCH 3/3] Add env support for properties in scheduled tasks --- .../java/org/apache/synapse/task/TaskDescriptionFactory.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/tasks/src/main/java/org/apache/synapse/task/TaskDescriptionFactory.java b/modules/tasks/src/main/java/org/apache/synapse/task/TaskDescriptionFactory.java index a058969b5a..0188ae7cfe 100644 --- a/modules/tasks/src/main/java/org/apache/synapse/task/TaskDescriptionFactory.java +++ b/modules/tasks/src/main/java/org/apache/synapse/task/TaskDescriptionFactory.java @@ -115,6 +115,11 @@ public static TaskDescription createTaskDescription(OMElement el, OMNamespace ta while (it.hasNext()) { OMElement prop = (OMElement) it.next(); if (PropertyHelper.isStaticProperty(prop)) { + String value = prop.getAttributeValue(new QName("value")); + if (value != null) { + String resolvedValue = ResolverFactory.getInstance().getResolver(value).resolve(); + prop.getAttribute(new QName("value")).setAttributeValue(resolvedValue); + } taskDescription.setXmlProperty(prop); } else { handleException("Tasks does not support dynamic properties");