From dcdff4041d25160e4e41c0f31b265f18b7e1b515 Mon Sep 17 00:00:00 2001 From: chathurangaj Date: Thu, 12 Dec 2024 15:51:05 +0530 Subject: [PATCH 01/21] deploy endpoints needed for http connector in local entry deployer --- .../synapse/deployers/LocalEntryDeployer.java | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/modules/core/src/main/java/org/apache/synapse/deployers/LocalEntryDeployer.java b/modules/core/src/main/java/org/apache/synapse/deployers/LocalEntryDeployer.java index 97539f8094..ee8b84219d 100644 --- a/modules/core/src/main/java/org/apache/synapse/deployers/LocalEntryDeployer.java +++ b/modules/core/src/main/java/org/apache/synapse/deployers/LocalEntryDeployer.java @@ -30,6 +30,8 @@ import org.apache.synapse.config.xml.EntryFactory; import org.apache.synapse.config.xml.EntrySerializer; import org.apache.synapse.config.xml.MultiXMLConfigurationBuilder; +import org.apache.synapse.config.xml.endpoints.EndpointFactory; +import org.apache.synapse.endpoints.Endpoint; import org.apache.synapse.transport.dynamicconfigurations.KeyStoreReloaderHolder; import org.apache.synapse.transport.nhttp.config.SslSenderTrustStoreHolder; @@ -48,6 +50,7 @@ import java.util.Properties; import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; /** * Handles the LocalEntry deployment and undeployment tasks @@ -89,6 +92,7 @@ public String deploySynapseArtifact(OMElement artifactConfig, String fileName, log.info("LocalEntry named '" + e.getKey() + "' has been deployed from file : " + fileName); handleSSLSenderCertificates(artifactConfig); + deployEndpointsForHTTPConnection(artifactConfig, fileName, properties); return e.getKey(); } else { handleSynapseArtifactDeploymentError("LocalEntry Deployment Failed. The artifact " + @@ -102,6 +106,73 @@ public String deploySynapseArtifact(OMElement artifactConfig, String fileName, return null; } + private void deployEndpointsForHTTPConnection(OMElement artifactConfig, String fileName, Properties properties) + throws XMLStreamException { + + OMElement httpInitElement = + artifactConfig.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, HTTP_CONNECTION_IDENTIFIER)); + if (httpInitElement != null) { + OMElement documentElement = generateHTTPEndpointOMElement(httpInitElement); + +// String omElementString = "" + +// "" + +// "" + +// "" + +// ""; +// String omElementString = +// "" + +// "" + +// "" + +// "-1" + +// "1" + +// "" + +// "" + +// "0" + +// "" + +// "" + +// ""; +// InputStream inputStream = new ByteArrayInputStream(omElementString.getBytes(StandardCharsets.UTF_8)); +// OMElement documentElement = +// new StAXOMBuilder(StAXUtils.createXMLStreamReader(inputStream)).getDocumentElement(); + try { + Endpoint ep = EndpointFactory.getEndpointFromElement(documentElement, false, properties); + + //Set the car name + ep.setArtifactContainerName(customLogContent); + if (ep != null) { + ep.setFileName((new File(fileName)).getName()); + if (log.isDebugEnabled()) { + log.debug("Endpoint named '" + ep.getName() + + "' has been built from the file " + fileName); + } + ep.init(getSynapseEnvironment()); + if (log.isDebugEnabled()) { + log.debug("Initialized the endpoint : " + ep.getName()); + } + getSynapseConfiguration().addEndpoint(ep.getName(), ep); + if (log.isDebugEnabled()) { + log.debug("Endpoint Deployment from file : " + fileName + " : Completed"); + } + log.info("Endpoint named '" + ep.getName() + + "' has been deployed from file : " + fileName); + } else { + handleSynapseArtifactDeploymentError("Endpoint Deployment Failed. The artifact " + + "described in the file " + fileName + " is not an Endpoint"); + } + } catch (Exception e) { + handleSynapseArtifactDeploymentError("Endpoint Deployment from the file : " + + fileName + " : Failed.", e); + } + } + } + + private OMElement generateHTTPEndpointOMElement(OMElement httpConnectionElement) { + + HTTPConnectionRepresentation httpConnectionRepresentation = + new HTTPConnectionRepresentation(httpConnectionElement); + return httpConnectionRepresentation.generateOMElement(); + } + private void handleSSLSenderCertificates(OMElement element) throws DeploymentException { OMElement httpInitElement = From 84f56938cf0f16016d8fb0b22f94ea00676c4641 Mon Sep 17 00:00:00 2001 From: chathurangaj Date: Thu, 12 Dec 2024 16:15:45 +0530 Subject: [PATCH 02/21] use http connection info to generate endpoint om element --- .../apache/synapse/deployers/Constant.java | 25 ++ .../HTTPConnectionRepresentation.java | 325 ++++++++++++++++++ 2 files changed, 350 insertions(+) create mode 100644 modules/core/src/main/java/org/apache/synapse/deployers/Constant.java create mode 100644 modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java diff --git a/modules/core/src/main/java/org/apache/synapse/deployers/Constant.java b/modules/core/src/main/java/org/apache/synapse/deployers/Constant.java new file mode 100644 index 0000000000..3f4780e6fc --- /dev/null +++ b/modules/core/src/main/java/org/apache/synapse/deployers/Constant.java @@ -0,0 +1,25 @@ +package org.apache.synapse.deployers; + +public class Constant { + + // Constants for the HTTP Endpoint + public static final String ENDPOINT_IDENTIFIER = "ep"; + public static final String BASIC_AUTH = "Basic Auth"; + public static final String OAUTH = "OAuth"; + public static final String OAUTH_GRANT_TYPE_AUTHORIZATION_CODE = "Authorization Code"; + public static final String OAUTH_GRANT_TYPE_CLIENT_CREDENTIALS = "Client Credentials"; + public static final String OAUTH_GRANT_TYPE_PASSWORD = "Password"; + + // Constants for the HTTP Connection + public static final String NAME = "name"; + public static final String BASE_URL = "baseUrl"; + public static final String TIMEOUT_DURATION = "timeoutDuration"; + public static final String TIMEOUT_ACTION = "timeoutAction"; + public static final String SUSPEND_ERROR_CODES = "suspendErrorCodes"; + public static final String SUSPEND_INITIAL_DURATION = "suspendInitialDuration"; + public static final String SUSPEND_MAXIMUM_DURATION = "suspendMaximumDuration"; + public static final String SUSPEND_PROGRESSION_FACTOR = "suspendProgressionFactor"; + public static final String RETRY_ERROR_CODES = "retryErrorCodes"; + public static final String RETRY_COUNT = "retryCount"; + public static final String RETRY_DELAY = "retryDelay"; +} diff --git a/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java b/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java new file mode 100644 index 0000000000..748e3ee0ae --- /dev/null +++ b/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java @@ -0,0 +1,325 @@ +package org.apache.synapse.deployers; + +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.axiom.om.OMNamespace; +import org.apache.axiom.om.impl.llom.factory.OMLinkedListImplFactory; +import org.apache.commons.lang.StringUtils; + +import java.util.Iterator; + +public class HTTPConnectionRepresentation { + + private String name; + private String endpointName; + private String connectionType; + private String baseUrl; + private String certificateType; + private String authType; + private String basicCredentialsUsername; + private String basicCredentialsPassword; + private String oauthAuthorizationMode; + private String oauthGrantType; + + private String oauthRefreshClientId; + private String oauthRefreshClientSecret; + private String oauthRefreshTokenUrl; + private String oauthRefreshRefreshToken; + private String oauthRefreshAdditionalProperties; + + private String oauthClientClientId; + private String oauthClientClientSecret; + private String oauthClientTokenUrl; + + private String oauthPasswordClientId; + private String oauthPasswordClientSecret; + private String oauthPasswordTokenUrl; + private String oauthPasswordUsername; + private String oauthPasswordPassword; + + private int timeoutDuration; + private String timeoutAction; + private String suspendErrorCodes; + private int suspendInitialDuration; + private int suspendMaximumDuration; + private int suspendProgressionFactor; + private String retryErrorCodes; + private int retryCount; + private int retryDelay; + + public HTTPConnectionRepresentation(OMElement inputOMElement) { + // Parse input OMElement and populate the attributes + Iterator children = inputOMElement.getChildElements(); + while (children.hasNext()) { + OMElement child = (OMElement) children.next(); + switch (child.getLocalName()) { + case "connectionType": + this.connectionType = child.getText(); + break; + case "baseUrl": + this.baseUrl = child.getText(); + break; + case "certificateType": + this.certificateType = child.getText(); + break; + case "authType": + this.authType = child.getText(); + break; + case "basicCredentialsUsername": + this.basicCredentialsUsername = child.getText(); + break; + case "basicCredentialsPassword": + this.basicCredentialsPassword = child.getText(); + break; + case "oauthAuthorizationMode": + this.oauthAuthorizationMode = child.getText(); + break; + case "oauthGrantType": + this.oauthGrantType = child.getText(); + break; + case "oauthRefreshClientId": + this.oauthRefreshClientId = child.getText(); + break; + case "oauthRefreshClientSecret": + this.oauthRefreshClientSecret = child.getText(); + break; + case "oauthRefreshTokenUrl": + this.oauthRefreshTokenUrl = child.getText(); + break; + case "oauthRefreshRefreshToken": + this.oauthRefreshRefreshToken = child.getText(); + break; + case "oauthRefreshAdditionalProperties": + this.oauthRefreshAdditionalProperties = child.getText(); + break; + case "oauthClientClientId": + this.oauthClientClientId = child.getText(); + break; + case "oauthClientClientSecret": + this.oauthClientClientSecret = child.getText(); + break; + case "oauthClientTokenUrl": + this.oauthClientTokenUrl = child.getText(); + break; + case "oauthPasswordClientId": + this.oauthPasswordClientId = child.getText(); + break; + case "oauthPasswordClientSecret": + this.oauthPasswordClientSecret = child.getText(); + break; + case "oauthPasswordTokenUrl": + this.oauthPasswordTokenUrl = child.getText(); + break; + case "oauthPasswordUsername": + this.oauthPasswordUsername = child.getText(); + break; + case "oauthPasswordPassword": + this.oauthPasswordPassword = child.getText(); + break; + case "timeoutDuration": + this.timeoutDuration = Integer.parseInt(child.getText()); + break; + case "timeoutAction": + this.timeoutAction = child.getText(); + break; + case "suspendErrorCodes": + this.suspendErrorCodes = child.getText(); + break; + case "suspendInitialDuration": + this.suspendInitialDuration = Integer.parseInt(child.getText()); + break; + case "suspendMaximumDuration": + this.suspendMaximumDuration = Integer.parseInt(child.getText()); + break; + case "suspendProgressionFactor": + this.suspendProgressionFactor = Integer.parseInt(child.getText()); + break; + case "retryErrorCodes": + this.retryErrorCodes = child.getText(); + break; + case "retryCount": + this.retryCount = Integer.parseInt(child.getText()); + break; + case "retryDelay": + this.retryDelay = Integer.parseInt(child.getText()); + break; + case "name": + this.name = child.getText(); + this.endpointName = child.getText() + Constant.ENDPOINT_IDENTIFIER; + break; + default: + // Ignore unknown elements + } + } + } + + public OMElement generateOMElement() { + OMFactory factory = new OMLinkedListImplFactory(); + OMNamespace synapseNS = factory.createOMNamespace("http://ws.apache.org/ns/synapse", ""); + + OMElement endpoint = factory.createOMElement("endpoint", synapseNS); + endpoint.addAttribute("name", endpointName, null); + + OMElement http = factory.createOMElement("http", synapseNS); + http.addAttribute("uri-template", "{uri.var.base}{+uri.var.path}{+uri.var.query}", null); + + if (this.timeoutDuration > 0 || StringUtils.isNotEmpty(this.timeoutAction)) { + OMElement timeout = factory.createOMElement("timeout", synapseNS); + if (this.timeoutDuration > 0) { + OMElement duration = factory.createOMElement("duration", synapseNS); + duration.setText(String.valueOf(this.timeoutDuration)); + timeout.addChild(duration); + } + if (StringUtils.isNotEmpty(this.timeoutAction) && !this.timeoutAction.equalsIgnoreCase("never")) { + OMElement responseAction = factory.createOMElement("responseAction", synapseNS); + responseAction.setText(this.timeoutAction); + timeout.addChild(responseAction); + } + http.addChild(timeout); + } + + if (StringUtils.isNotEmpty(this.suspendErrorCodes) || this.suspendInitialDuration > 0 || this.suspendProgressionFactor > 0 || this.suspendMaximumDuration > 0) { + OMElement suspendOnFailure = factory.createOMElement("suspendOnFailure", synapseNS); + if (StringUtils.isNotEmpty(this.suspendErrorCodes)) { + OMElement errorCodes = factory.createOMElement("errorCodes", synapseNS); + errorCodes.setText(this.suspendErrorCodes); + suspendOnFailure.addChild(errorCodes); + } + if (this.suspendInitialDuration > 0) { + OMElement initialDuration = factory.createOMElement("initialDuration", synapseNS); + initialDuration.setText(String.valueOf(this.suspendInitialDuration)); + suspendOnFailure.addChild(initialDuration); + } + if (this.suspendProgressionFactor > 0) { + OMElement progressionFactor = factory.createOMElement("progressionFactor", synapseNS); + progressionFactor.setText(String.valueOf(this.suspendProgressionFactor)); + suspendOnFailure.addChild(progressionFactor); + } + if (this.suspendMaximumDuration > 0) { + OMElement maximumDuration = factory.createOMElement("maximumDuration", synapseNS); + maximumDuration.setText(String.valueOf(this.suspendMaximumDuration)); + suspendOnFailure.addChild(maximumDuration); + } + http.addChild(suspendOnFailure); + } + + if (StringUtils.isNotEmpty(this.retryErrorCodes) || this.retryCount > 0 || this.retryDelay > 0) { + OMElement markForSuspension = factory.createOMElement("markForSuspension", synapseNS); + OMElement retryErrorCodes = factory.createOMElement("errorCodes", synapseNS); + if (StringUtils.isNotEmpty(this.retryErrorCodes)) { + retryErrorCodes.setText(this.retryErrorCodes); + markForSuspension.addChild(retryErrorCodes); + } + OMElement retriesBeforeSuspension = factory.createOMElement("retriesBeforeSuspension", synapseNS); + if (this.retryCount > 0) { + retriesBeforeSuspension.setText(String.valueOf(this.retryCount)); + markForSuspension.addChild(retriesBeforeSuspension); + } + OMElement retryDelay = factory.createOMElement("retryDelay", synapseNS); + if (this.retryDelay > 0) { + retryDelay.setText(String.valueOf(this.retryDelay)); + markForSuspension.addChild(retryDelay); + } + http.addChild(markForSuspension); + } + + if (authType.equalsIgnoreCase(Constant.BASIC_AUTH)) { + OMElement authentication = factory.createOMElement("authentication", synapseNS); + OMElement basicAuth = factory.createOMElement("basicAuth", synapseNS); + OMElement username = factory.createOMElement("username", synapseNS); + username.setText(this.basicCredentialsUsername); + basicAuth.addChild(username); + OMElement password = factory.createOMElement("password", synapseNS); + password.setText(this.basicCredentialsPassword); + basicAuth.addChild(password); + authentication.addChild(basicAuth); + http.addChild(authentication); + } else if (authType.equalsIgnoreCase(Constant.OAUTH)) { + OMElement authentication = factory.createOMElement("authentication", synapseNS); + OMElement oauth = factory.createOMElement("oauth", synapseNS); + OMElement authMode = factory.createOMElement("authMode", synapseNS); + authMode.setText(this.oauthAuthorizationMode); + if (oauthGrantType.equalsIgnoreCase(Constant.OAUTH_GRANT_TYPE_AUTHORIZATION_CODE)) { + OMElement authorizationCode = factory.createOMElement("authorizationCode", synapseNS); + + OMElement refreshToken = factory.createOMElement("refreshToken", synapseNS); + refreshToken.setText(this.oauthRefreshRefreshToken); + OMElement clientId = factory.createOMElement("clientId", synapseNS); + clientId.setText(this.oauthRefreshClientId); + OMElement clientSecret = factory.createOMElement("clientSecret", synapseNS); + clientSecret.setText(this.oauthRefreshClientSecret); + OMElement tokenUrl = factory.createOMElement("tokenUrl", synapseNS); + tokenUrl.setText(this.oauthRefreshTokenUrl); + + authorizationCode.addChild(refreshToken); + authorizationCode.addChild(clientId); + authorizationCode.addChild(clientSecret); + authorizationCode.addChild(tokenUrl); + authorizationCode.addChild(authMode); + + if (StringUtils.isNotEmpty(this.oauthRefreshAdditionalProperties)) { + OMElement additionalProperties = factory.createOMElement("requestParameters", synapseNS); + for (String additionalProperty : this.oauthRefreshAdditionalProperties.split(",")) { + String[] keyValue = additionalProperty.split(":"); + if (keyValue.length == 2) { + OMElement parameter = factory.createOMElement("parameter", synapseNS); + parameter.addAttribute("name", keyValue[0], null); + parameter.setText(keyValue[1]); + additionalProperties.addChild(parameter); + } + } + authorizationCode.addChild(additionalProperties); + } + + oauth.addChild(authorizationCode); + authentication.addChild(oauth); + http.addChild(authentication); + } else if (oauthGrantType.equalsIgnoreCase(Constant.OAUTH_GRANT_TYPE_CLIENT_CREDENTIALS)) { + OMElement clientCredentials = factory.createOMElement("clientCredentials", synapseNS); + + OMElement clientId = factory.createOMElement("clientId", synapseNS); + clientId.setText(this.oauthClientClientId); + OMElement clientSecret = factory.createOMElement("clientSecret", synapseNS); + clientSecret.setText(this.oauthClientClientSecret); + OMElement tokenUrl = factory.createOMElement("tokenUrl", synapseNS); + tokenUrl.setText(this.oauthClientTokenUrl); + + clientCredentials.addChild(clientId); + clientCredentials.addChild(clientSecret); + clientCredentials.addChild(tokenUrl); + clientCredentials.addChild(authMode); + + oauth.addChild(clientCredentials); + authentication.addChild(oauth); + http.addChild(authentication); + } else if (oauthGrantType.equalsIgnoreCase(Constant.OAUTH_GRANT_TYPE_PASSWORD)) { + OMElement passwordCredentials = factory.createOMElement("passwordCredentials", synapseNS); + + OMElement username = factory.createOMElement("username", synapseNS); + username.setText(this.oauthPasswordUsername); + OMElement password = factory.createOMElement("password", synapseNS); + password.setText(this.oauthPasswordPassword); + OMElement clientId = factory.createOMElement("clientId", synapseNS); + clientId.setText(this.oauthPasswordClientId); + OMElement clientSecret = factory.createOMElement("clientSecret", synapseNS); + clientSecret.setText(this.oauthPasswordClientSecret); + OMElement tokenUrl = factory.createOMElement("tokenUrl", synapseNS); + tokenUrl.setText(this.oauthPasswordTokenUrl); + + passwordCredentials.addChild(username); + passwordCredentials.addChild(password); + passwordCredentials.addChild(clientId); + passwordCredentials.addChild(clientSecret); + passwordCredentials.addChild(tokenUrl); + passwordCredentials.addChild(authMode); + + oauth.addChild(passwordCredentials); + authentication.addChild(oauth); + http.addChild(authentication); + } + } + + endpoint.addChild(http); + return endpoint; + } +} From 612307a6b8f4b47698fb32482843578b1c7d25b4 Mon Sep 17 00:00:00 2001 From: chathurangaj Date: Thu, 12 Dec 2024 16:16:48 +0530 Subject: [PATCH 03/21] add tests for endpoint om element generation from connection info --- .../HTTPConnectionRepresentationTest.java | 391 ++++++++++++++++++ 1 file changed, 391 insertions(+) create mode 100644 modules/core/src/test/java/org/apache/synapse/deployers/HTTPConnectionRepresentationTest.java diff --git a/modules/core/src/test/java/org/apache/synapse/deployers/HTTPConnectionRepresentationTest.java b/modules/core/src/test/java/org/apache/synapse/deployers/HTTPConnectionRepresentationTest.java new file mode 100644 index 0000000000..31b72f8ba2 --- /dev/null +++ b/modules/core/src/test/java/org/apache/synapse/deployers/HTTPConnectionRepresentationTest.java @@ -0,0 +1,391 @@ +package org.apache.synapse.deployers; + +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.impl.builder.StAXOMBuilder; +import org.apache.axiom.om.util.StAXUtils; +import org.junit.Assert; +import org.junit.Test; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; + +import javax.xml.stream.XMLStreamException; + +public class HTTPConnectionRepresentationTest { + + @Test + public void testEndpointOMElementGeneration() throws XMLStreamException { + + String omElementString = + "\n" + + " https\n" + + " balsslconnep\n" + + " File\n" + + " BasicCredentials\n" + + " http://jsonplaceholder.typicode.com/posts\n" + + " resources:certificates/serverpubliccert.crt\n" + + " 403\n" + + " 1\n" + + " 300\n" + + " 3\n" + + " 20\n" + + " Discard\n" + + ""; + String expectedEndpointOMElementString = + "" + + "" + + "" + + "Discard" + + "" + + "" + + "403" + + "1" + + "" + + "" + + "300" + + "3" + + "20" + + "" + + "" + + ""; + InputStream inputStream = new ByteArrayInputStream(omElementString.getBytes(StandardCharsets.UTF_8)); + OMElement documentElement = + new StAXOMBuilder(StAXUtils.createXMLStreamReader(inputStream)).getDocumentElement(); + HTTPConnectionRepresentation httpConnectionRepresentation = new HTTPConnectionRepresentation(documentElement); + OMElement generatedEndpointOMElement = httpConnectionRepresentation.generateOMElement(); + Assert.assertEquals(generatedEndpointOMElement.toString(), expectedEndpointOMElementString); + } + + @Test + public void testEndpointOMElementGenerationWithTimeoutActionNever() throws XMLStreamException { + + String omElementString = + "\n" + + " https\n" + + " balsslconnep\n" + + " File\n" + + " BasicCredentials\n" + + " http://jsonplaceholder.typicode.com/posts\n" + + " resources:certificates/serverpubliccert.crt\n" + + " 403\n" + + " 1\n" + + " 300\n" + + " 3\n" + + " 20\n" + + " Never\n" + + ""; + String expectedEndpointOMElementString = + "" + + "" + + "" + + "" + + "403" + + "1" + + "" + + "" + + "300" + + "3" + + "20" + + "" + + "" + + ""; + InputStream inputStream = new ByteArrayInputStream(omElementString.getBytes(StandardCharsets.UTF_8)); + OMElement documentElement = + new StAXOMBuilder(StAXUtils.createXMLStreamReader(inputStream)).getDocumentElement(); + HTTPConnectionRepresentation httpConnectionRepresentation = new HTTPConnectionRepresentation(documentElement); + OMElement generatedEndpointOMElement = httpConnectionRepresentation.generateOMElement(); + Assert.assertEquals(generatedEndpointOMElement.toString(), expectedEndpointOMElementString); + } + + @Test + public void testEndpointOMElementGenerationWithBasicAuth() throws XMLStreamException { + + String omElementString = + "\n" + + " https\n" + + " balsslconnep\n" + + " File\n" + + " Basic Auth\n" + + " http://jsonplaceholder.typicode.com/posts\n" + + " resources:certificates/serverpubliccert.crt\n" + + " 403\n" + + " 1\n" + + " 300\n" + + " 3\n" + + " 20\n" + + " Discard\n" + + " admin\n" + + " admin\n" + + ""; + String expectedEndpointOMElementString = + "" + + "" + + "" + + "Discard" + + "" + + "" + + "403" + + "1" + + "" + + "" + + "300" + + "3" + + "20" + + "" + + "" + + "" + + "admin" + + "admin" + + "" + + "" + + "" + + ""; + InputStream inputStream = new ByteArrayInputStream(omElementString.getBytes(StandardCharsets.UTF_8)); + OMElement documentElement = + new StAXOMBuilder(StAXUtils.createXMLStreamReader(inputStream)).getDocumentElement(); + HTTPConnectionRepresentation httpConnectionRepresentation = new HTTPConnectionRepresentation(documentElement); + OMElement generatedEndpointOMElement = httpConnectionRepresentation.generateOMElement(); + Assert.assertEquals(generatedEndpointOMElement.toString(), expectedEndpointOMElementString); + } + + @Test + public void testEndpointOMElementGenerationWithOAuthAuthorizationCode() throws XMLStreamException { + + String omElementString = + "\n" + + " https\n" + + " balsslconnep\n" + + " File\n" + + " OAuth\n" + + " Header\n" + + " Authorization Code\n" + + " http://jsonplaceholder.typicode.com/posts\n" + + " resources:certificates/serverpubliccert.crt\n" + + " 403\n" + + " 1\n" + + " 300\n" + + " 3\n" + + " 20\n" + + " Discard\n" + + " admin\n" + + " admin\n" + + " admin\n" + + " admin\n" + + ""; + String expectedEndpointOMElementString = + "" + + "" + + "" + + "Discard" + + "" + + "" + + "403" + + "1" + + "" + + "" + + "300" + + "3" + + "20" + + "" + + "" + + "" + + "" + + "admin" + + "admin" + + "admin" + + "admin" + + "Header" + + "" + + "" + + "" + + "" + + ""; + InputStream inputStream = new ByteArrayInputStream(omElementString.getBytes(StandardCharsets.UTF_8)); + OMElement documentElement = + new StAXOMBuilder(StAXUtils.createXMLStreamReader(inputStream)).getDocumentElement(); + HTTPConnectionRepresentation httpConnectionRepresentation = new HTTPConnectionRepresentation(documentElement); + OMElement generatedEndpointOMElement = httpConnectionRepresentation.generateOMElement(); + Assert.assertEquals(generatedEndpointOMElement.toString(), expectedEndpointOMElementString); + } + + @Test + public void testEndpointOMElementGenerationWithOAuthAuthorizationCodeAndExpressions() throws XMLStreamException { + + String omElementString = + "\n" + + " https\n" + + " balsslconnep\n" + + " File\n" + + " OAuth\n" + + " Header\n" + + " Authorization Code\n" + + " http://jsonplaceholder.typicode.com/posts\n" + + " resources:certificates/serverpubliccert.crt\n" + + " 403\n" + + " 1\n" + + " 300\n" + + " 3\n" + + " 20\n" + + " Discard\n" + + " {$ctx:admin}\n" + + " {$ctx:admin}\n" + + " {$ctx:admin}\n" + + " {$ctx:admin}\n" + + ""; + String expectedEndpointOMElementString = + "" + + "" + + "" + + "Discard" + + "" + + "" + + "403" + + "1" + + "" + + "" + + "300" + + "3" + + "20" + + "" + + "" + + "" + + "" + + "{$ctx:admin}" + + "{$ctx:admin}" + + "{$ctx:admin}" + + "{$ctx:admin}" + + "Header" + + "" + + "" + + "" + + "" + + ""; + InputStream inputStream = new ByteArrayInputStream(omElementString.getBytes(StandardCharsets.UTF_8)); + OMElement documentElement = + new StAXOMBuilder(StAXUtils.createXMLStreamReader(inputStream)).getDocumentElement(); + HTTPConnectionRepresentation httpConnectionRepresentation = new HTTPConnectionRepresentation(documentElement); + OMElement generatedEndpointOMElement = httpConnectionRepresentation.generateOMElement(); + Assert.assertEquals(generatedEndpointOMElement.toString(), expectedEndpointOMElementString); + } + + @Test + public void testEndpointOMElementGenerationWithOAuthClientCredentials() throws XMLStreamException { + + String omElementString = + "\n" + + " https\n" + + " balsslconnep\n" + + " File\n" + + " OAuth\n" + + " Header\n" + + " Client Credentials\n" + + " http://jsonplaceholder.typicode.com/posts\n" + + " resources:certificates/serverpubliccert.crt\n" + + " 403\n" + + " 1\n" + + " 300\n" + + " 3\n" + + " 20\n" + + " Discard\n" + + " admin\n" + + " admin\n" + + " admin\n" + + ""; + String expectedEndpointOMElementString = + "" + + "" + + "" + + "Discard" + + "" + + "" + + "403" + + "1" + + "" + + "" + + "300" + + "3" + + "20" + + "" + + "" + + "" + + "" + + "admin" + + "admin" + + "admin" + + "Header" + + "" + + "" + + "" + + "" + + ""; + InputStream inputStream = new ByteArrayInputStream(omElementString.getBytes(StandardCharsets.UTF_8)); + OMElement documentElement = + new StAXOMBuilder(StAXUtils.createXMLStreamReader(inputStream)).getDocumentElement(); + HTTPConnectionRepresentation httpConnectionRepresentation = new HTTPConnectionRepresentation(documentElement); + OMElement generatedEndpointOMElement = httpConnectionRepresentation.generateOMElement(); + Assert.assertEquals(generatedEndpointOMElement.toString(), expectedEndpointOMElementString); + } + + @Test + public void testEndpointOMElementGenerationWithOAuthPassword() throws XMLStreamException { + + String omElementString = + "\n" + + " https\n" + + " balsslconnep\n" + + " File\n" + + " OAuth\n" + + " Header\n" + + " Password\n" + + " http://jsonplaceholder.typicode.com/posts\n" + + " resources:certificates/serverpubliccert.crt\n" + + " 403\n" + + " 1\n" + + " 300\n" + + " 3\n" + + " 20\n" + + " Discard\n" + + " admin\n" + + " admin\n" + + " admin\n" + + " admin\n" + + " admin\n" + + ""; + String expectedEndpointOMElementString = + "" + + "" + + "" + + "Discard" + + "" + + "" + + "403" + + "1" + + "" + + "" + + "300" + + "3" + + "20" + + "" + + "" + + "" + + "" + + "admin" + + "admin" + + "admin" + + "admin" + + "admin" + + "Header" + + "" + + "" + + "" + + "" + + ""; + InputStream inputStream = new ByteArrayInputStream(omElementString.getBytes(StandardCharsets.UTF_8)); + OMElement documentElement = + new StAXOMBuilder(StAXUtils.createXMLStreamReader(inputStream)).getDocumentElement(); + HTTPConnectionRepresentation httpConnectionRepresentation = new HTTPConnectionRepresentation(documentElement); + OMElement generatedEndpointOMElement = httpConnectionRepresentation.generateOMElement(); + Assert.assertEquals(generatedEndpointOMElement.toString(), expectedEndpointOMElementString); + } +} From ae01607b1763c87baeaad31cc571a778c71571bb Mon Sep 17 00:00:00 2001 From: chathurangaj Date: Thu, 12 Dec 2024 16:58:12 +0530 Subject: [PATCH 04/21] rename oauth refresh to oauth authorization --- .../HTTPConnectionRepresentation.java | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java b/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java index 748e3ee0ae..f1bec2b08f 100644 --- a/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java +++ b/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java @@ -21,11 +21,11 @@ public class HTTPConnectionRepresentation { private String oauthAuthorizationMode; private String oauthGrantType; - private String oauthRefreshClientId; - private String oauthRefreshClientSecret; - private String oauthRefreshTokenUrl; - private String oauthRefreshRefreshToken; - private String oauthRefreshAdditionalProperties; + private String oauthAuthorizationClientId; + private String oauthAuthorizationClientSecret; + private String oauthAuthorizationTokenUrl; + private String oauthAuthorizationRefreshToken; + private String oauthAuthorizationAdditionalProperties; private String oauthClientClientId; private String oauthClientClientSecret; @@ -77,20 +77,20 @@ public HTTPConnectionRepresentation(OMElement inputOMElement) { case "oauthGrantType": this.oauthGrantType = child.getText(); break; - case "oauthRefreshClientId": - this.oauthRefreshClientId = child.getText(); + case "oauthAuthorizationClientId": + this.oauthAuthorizationClientId = child.getText(); break; - case "oauthRefreshClientSecret": - this.oauthRefreshClientSecret = child.getText(); + case "oauthAuthorizationClientSecret": + this.oauthAuthorizationClientSecret = child.getText(); break; - case "oauthRefreshTokenUrl": - this.oauthRefreshTokenUrl = child.getText(); + case "oauthAuthorizationTokenUrl": + this.oauthAuthorizationTokenUrl = child.getText(); break; - case "oauthRefreshRefreshToken": - this.oauthRefreshRefreshToken = child.getText(); + case "oauthAuthorizationRefreshToken": + this.oauthAuthorizationRefreshToken = child.getText(); break; - case "oauthRefreshAdditionalProperties": - this.oauthRefreshAdditionalProperties = child.getText(); + case "oauthAuthorizationAdditionalProperties": + this.oauthAuthorizationAdditionalProperties = child.getText(); break; case "oauthClientClientId": this.oauthClientClientId = child.getText(); @@ -243,13 +243,13 @@ public OMElement generateOMElement() { OMElement authorizationCode = factory.createOMElement("authorizationCode", synapseNS); OMElement refreshToken = factory.createOMElement("refreshToken", synapseNS); - refreshToken.setText(this.oauthRefreshRefreshToken); + refreshToken.setText(this.oauthAuthorizationRefreshToken); OMElement clientId = factory.createOMElement("clientId", synapseNS); - clientId.setText(this.oauthRefreshClientId); + clientId.setText(this.oauthAuthorizationClientId); OMElement clientSecret = factory.createOMElement("clientSecret", synapseNS); - clientSecret.setText(this.oauthRefreshClientSecret); + clientSecret.setText(this.oauthAuthorizationClientSecret); OMElement tokenUrl = factory.createOMElement("tokenUrl", synapseNS); - tokenUrl.setText(this.oauthRefreshTokenUrl); + tokenUrl.setText(this.oauthAuthorizationTokenUrl); authorizationCode.addChild(refreshToken); authorizationCode.addChild(clientId); @@ -257,9 +257,9 @@ public OMElement generateOMElement() { authorizationCode.addChild(tokenUrl); authorizationCode.addChild(authMode); - if (StringUtils.isNotEmpty(this.oauthRefreshAdditionalProperties)) { + if (StringUtils.isNotEmpty(this.oauthAuthorizationAdditionalProperties)) { OMElement additionalProperties = factory.createOMElement("requestParameters", synapseNS); - for (String additionalProperty : this.oauthRefreshAdditionalProperties.split(",")) { + for (String additionalProperty : this.oauthAuthorizationAdditionalProperties.split(",")) { String[] keyValue = additionalProperty.split(":"); if (keyValue.length == 2) { OMElement parameter = factory.createOMElement("parameter", synapseNS); From 1edae2514e58c456d2f3f8b0dfa6bff96ba4fb5b Mon Sep 17 00:00:00 2001 From: chathurangaj Date: Thu, 12 Dec 2024 20:29:36 +0530 Subject: [PATCH 05/21] update tests --- .../HTTPConnectionRepresentationTest.java | 192 +++++++++++++----- 1 file changed, 139 insertions(+), 53 deletions(-) diff --git a/modules/core/src/test/java/org/apache/synapse/deployers/HTTPConnectionRepresentationTest.java b/modules/core/src/test/java/org/apache/synapse/deployers/HTTPConnectionRepresentationTest.java index 31b72f8ba2..d862b47992 100644 --- a/modules/core/src/test/java/org/apache/synapse/deployers/HTTPConnectionRepresentationTest.java +++ b/modules/core/src/test/java/org/apache/synapse/deployers/HTTPConnectionRepresentationTest.java @@ -20,7 +20,7 @@ public void testEndpointOMElementGeneration() throws XMLStreamException { String omElementString = "\n" + " https\n" + - " balsslconnep\n" + + " library\n" + " File\n" + " BasicCredentials\n" + " http://jsonplaceholder.typicode.com/posts\n" + @@ -33,8 +33,8 @@ public void testEndpointOMElementGeneration() throws XMLStreamException { " Discard\n" + ""; String expectedEndpointOMElementString = - "" + - "" + + "" + + "" + "" + "Discard" + "" + @@ -54,7 +54,28 @@ public void testEndpointOMElementGeneration() throws XMLStreamException { new StAXOMBuilder(StAXUtils.createXMLStreamReader(inputStream)).getDocumentElement(); HTTPConnectionRepresentation httpConnectionRepresentation = new HTTPConnectionRepresentation(documentElement); OMElement generatedEndpointOMElement = httpConnectionRepresentation.generateOMElement(); - Assert.assertEquals(generatedEndpointOMElement.toString(), expectedEndpointOMElementString); + Assert.assertEquals(expectedEndpointOMElementString, generatedEndpointOMElement.toString()); + } + + @Test + public void testEndpointOMElementGenerationWithoutErrorHandling() throws XMLStreamException { + + String omElementString = + "\n" + + " http\n" + + " library\n" + + " http://jsonplaceholder.typicode.com/posts\n" + + ""; + String expectedEndpointOMElementString = + "" + + "" + + ""; + InputStream inputStream = new ByteArrayInputStream(omElementString.getBytes(StandardCharsets.UTF_8)); + OMElement documentElement = + new StAXOMBuilder(StAXUtils.createXMLStreamReader(inputStream)).getDocumentElement(); + HTTPConnectionRepresentation httpConnectionRepresentation = new HTTPConnectionRepresentation(documentElement); + OMElement generatedEndpointOMElement = httpConnectionRepresentation.generateOMElement(); + Assert.assertEquals(expectedEndpointOMElementString, generatedEndpointOMElement.toString()); } @Test @@ -63,7 +84,7 @@ public void testEndpointOMElementGenerationWithTimeoutActionNever() throws XMLSt String omElementString = "\n" + " https\n" + - " balsslconnep\n" + + " library\n" + " File\n" + " BasicCredentials\n" + " http://jsonplaceholder.typicode.com/posts\n" + @@ -76,8 +97,8 @@ public void testEndpointOMElementGenerationWithTimeoutActionNever() throws XMLSt " Never\n" + ""; String expectedEndpointOMElementString = - "" + - "" + + "" + + "" + "" + "" + "403" + @@ -95,7 +116,7 @@ public void testEndpointOMElementGenerationWithTimeoutActionNever() throws XMLSt new StAXOMBuilder(StAXUtils.createXMLStreamReader(inputStream)).getDocumentElement(); HTTPConnectionRepresentation httpConnectionRepresentation = new HTTPConnectionRepresentation(documentElement); OMElement generatedEndpointOMElement = httpConnectionRepresentation.generateOMElement(); - Assert.assertEquals(generatedEndpointOMElement.toString(), expectedEndpointOMElementString); + Assert.assertEquals(expectedEndpointOMElementString, generatedEndpointOMElement.toString()); } @Test @@ -104,7 +125,7 @@ public void testEndpointOMElementGenerationWithBasicAuth() throws XMLStreamExcep String omElementString = "\n" + " https\n" + - " balsslconnep\n" + + " library\n" + " File\n" + " Basic Auth\n" + " http://jsonplaceholder.typicode.com/posts\n" + @@ -119,8 +140,8 @@ public void testEndpointOMElementGenerationWithBasicAuth() throws XMLStreamExcep " admin\n" + ""; String expectedEndpointOMElementString = - "" + - "" + + "" + + "" + "" + "Discard" + "" + @@ -146,7 +167,7 @@ public void testEndpointOMElementGenerationWithBasicAuth() throws XMLStreamExcep new StAXOMBuilder(StAXUtils.createXMLStreamReader(inputStream)).getDocumentElement(); HTTPConnectionRepresentation httpConnectionRepresentation = new HTTPConnectionRepresentation(documentElement); OMElement generatedEndpointOMElement = httpConnectionRepresentation.generateOMElement(); - Assert.assertEquals(generatedEndpointOMElement.toString(), expectedEndpointOMElementString); + Assert.assertEquals(expectedEndpointOMElementString, generatedEndpointOMElement.toString()); } @Test @@ -155,7 +176,7 @@ public void testEndpointOMElementGenerationWithOAuthAuthorizationCode() throws X String omElementString = "\n" + " https\n" + - " balsslconnep\n" + + " library\n" + " File\n" + " OAuth\n" + " Header\n" + @@ -168,14 +189,14 @@ public void testEndpointOMElementGenerationWithOAuthAuthorizationCode() throws X " 3\n" + " 20\n" + " Discard\n" + - " admin\n" + - " admin\n" + - " admin\n" + - " admin\n" + + " admin\n" + + " admin\n" + + " admin\n" + + " admin\n" + ""; String expectedEndpointOMElementString = - "" + - "" + + "" + + "" + "" + "Discard" + "" + @@ -206,7 +227,72 @@ public void testEndpointOMElementGenerationWithOAuthAuthorizationCode() throws X new StAXOMBuilder(StAXUtils.createXMLStreamReader(inputStream)).getDocumentElement(); HTTPConnectionRepresentation httpConnectionRepresentation = new HTTPConnectionRepresentation(documentElement); OMElement generatedEndpointOMElement = httpConnectionRepresentation.generateOMElement(); - Assert.assertEquals(generatedEndpointOMElement.toString(), expectedEndpointOMElementString); + Assert.assertEquals(expectedEndpointOMElementString, generatedEndpointOMElement.toString()); + } + + @Test + public void testEndpointOMElementGenerationWithOAuthAuthorizationCodeAdditionalProperties() throws XMLStreamException { + + String omElementString = + "\n" + + " https\n" + + " library\n" + + " File\n" + + " OAuth\n" + + " Header\n" + + " Authorization Code\n" + + " http://jsonplaceholder.typicode.com/posts\n" + + " resources:certificates/serverpubliccert.crt\n" + + " 403\n" + + " 1\n" + + " 300\n" + + " 3\n" + + " 20\n" + + " Discard\n" + + " admin\n" + + " admin\n" + + " admin\n" + + " admin\n" + + " name1:value1, name2:value2\n" + + ""; + String expectedEndpointOMElementString = + "" + + "" + + "" + + "Discard" + + "" + + "" + + "403" + + "1" + + "" + + "" + + "300" + + "3" + + "20" + + "" + + "" + + "" + + "" + + "admin" + + "admin" + + "admin" + + "admin" + + "Header" + + "" + + "value1" + + "value2" + + "" + + "" + + "" + + "" + + "" + + ""; + InputStream inputStream = new ByteArrayInputStream(omElementString.getBytes(StandardCharsets.UTF_8)); + OMElement documentElement = + new StAXOMBuilder(StAXUtils.createXMLStreamReader(inputStream)).getDocumentElement(); + HTTPConnectionRepresentation httpConnectionRepresentation = new HTTPConnectionRepresentation(documentElement); + OMElement generatedEndpointOMElement = httpConnectionRepresentation.generateOMElement(); + Assert.assertEquals(expectedEndpointOMElementString, generatedEndpointOMElement.toString()); } @Test @@ -215,7 +301,7 @@ public void testEndpointOMElementGenerationWithOAuthAuthorizationCodeAndExpressi String omElementString = "\n" + " https\n" + - " balsslconnep\n" + + " library\n" + " File\n" + " OAuth\n" + " Header\n" + @@ -228,45 +314,45 @@ public void testEndpointOMElementGenerationWithOAuthAuthorizationCodeAndExpressi " 3\n" + " 20\n" + " Discard\n" + - " {$ctx:admin}\n" + - " {$ctx:admin}\n" + - " {$ctx:admin}\n" + - " {$ctx:admin}\n" + + " {$ctx:admin}\n" + + " {$ctx:admin}\n" + + " {$ctx:admin}\n" + + " {$ctx:admin}\n" + ""; String expectedEndpointOMElementString = - "" + - "" + + "" + + "" + "" + - "Discard" + + "Discard" + "" + "" + - "403" + - "1" + + "403" + + "1" + "" + "" + - "300" + - "3" + - "20" + + "300" + + "3" + + "20" + "" + "" + - "" + - "" + - "{$ctx:admin}" + - "{$ctx:admin}" + - "{$ctx:admin}" + - "{$ctx:admin}" + - "Header" + - "" + - "" + + "" + + "" + + "{$ctx:admin}" + + "{$ctx:admin}" + + "{$ctx:admin}" + + "{$ctx:admin}" + + "Header" + + "" + + "" + "" + - "" + - ""; + "" + + ""; InputStream inputStream = new ByteArrayInputStream(omElementString.getBytes(StandardCharsets.UTF_8)); OMElement documentElement = new StAXOMBuilder(StAXUtils.createXMLStreamReader(inputStream)).getDocumentElement(); HTTPConnectionRepresentation httpConnectionRepresentation = new HTTPConnectionRepresentation(documentElement); OMElement generatedEndpointOMElement = httpConnectionRepresentation.generateOMElement(); - Assert.assertEquals(generatedEndpointOMElement.toString(), expectedEndpointOMElementString); + Assert.assertEquals(expectedEndpointOMElementString, generatedEndpointOMElement.toString()); } @Test @@ -275,7 +361,7 @@ public void testEndpointOMElementGenerationWithOAuthClientCredentials() throws X String omElementString = "\n" + " https\n" + - " balsslconnep\n" + + " library\n" + " File\n" + " OAuth\n" + " Header\n" + @@ -293,8 +379,8 @@ public void testEndpointOMElementGenerationWithOAuthClientCredentials() throws X " admin\n" + ""; String expectedEndpointOMElementString = - "" + - "" + + "" + + "" + "" + "Discard" + "" + @@ -324,7 +410,7 @@ public void testEndpointOMElementGenerationWithOAuthClientCredentials() throws X new StAXOMBuilder(StAXUtils.createXMLStreamReader(inputStream)).getDocumentElement(); HTTPConnectionRepresentation httpConnectionRepresentation = new HTTPConnectionRepresentation(documentElement); OMElement generatedEndpointOMElement = httpConnectionRepresentation.generateOMElement(); - Assert.assertEquals(generatedEndpointOMElement.toString(), expectedEndpointOMElementString); + Assert.assertEquals(expectedEndpointOMElementString, generatedEndpointOMElement.toString()); } @Test @@ -333,7 +419,7 @@ public void testEndpointOMElementGenerationWithOAuthPassword() throws XMLStreamE String omElementString = "\n" + " https\n" + - " balsslconnep\n" + + " library\n" + " File\n" + " OAuth\n" + " Header\n" + @@ -353,8 +439,8 @@ public void testEndpointOMElementGenerationWithOAuthPassword() throws XMLStreamE " admin\n" + ""; String expectedEndpointOMElementString = - "" + - "" + + "" + + "" + "" + "Discard" + "" + @@ -386,6 +472,6 @@ public void testEndpointOMElementGenerationWithOAuthPassword() throws XMLStreamE new StAXOMBuilder(StAXUtils.createXMLStreamReader(inputStream)).getDocumentElement(); HTTPConnectionRepresentation httpConnectionRepresentation = new HTTPConnectionRepresentation(documentElement); OMElement generatedEndpointOMElement = httpConnectionRepresentation.generateOMElement(); - Assert.assertEquals(generatedEndpointOMElement.toString(), expectedEndpointOMElementString); + Assert.assertEquals(expectedEndpointOMElementString, generatedEndpointOMElement.toString()); } } From ad1cd5ab79f9095d8c2bd14666876b2825a24dfc Mon Sep 17 00:00:00 2001 From: chathurangaj Date: Thu, 12 Dec 2024 20:36:34 +0530 Subject: [PATCH 06/21] handle oauth additional properties --- .../HTTPConnectionRepresentation.java | 194 ++++++++++-------- 1 file changed, 113 insertions(+), 81 deletions(-) diff --git a/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java b/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java index f1bec2b08f..b417026c1d 100644 --- a/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java +++ b/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java @@ -30,12 +30,14 @@ public class HTTPConnectionRepresentation { private String oauthClientClientId; private String oauthClientClientSecret; private String oauthClientTokenUrl; + private String oauthClientAdditionalProperties; private String oauthPasswordClientId; private String oauthPasswordClientSecret; private String oauthPasswordTokenUrl; private String oauthPasswordUsername; private String oauthPasswordPassword; + private String oauthPasswordAdditionalProperties; private int timeoutDuration; private String timeoutAction; @@ -223,99 +225,129 @@ public OMElement generateOMElement() { http.addChild(markForSuspension); } - if (authType.equalsIgnoreCase(Constant.BASIC_AUTH)) { - OMElement authentication = factory.createOMElement("authentication", synapseNS); - OMElement basicAuth = factory.createOMElement("basicAuth", synapseNS); - OMElement username = factory.createOMElement("username", synapseNS); - username.setText(this.basicCredentialsUsername); - basicAuth.addChild(username); - OMElement password = factory.createOMElement("password", synapseNS); - password.setText(this.basicCredentialsPassword); - basicAuth.addChild(password); - authentication.addChild(basicAuth); - http.addChild(authentication); - } else if (authType.equalsIgnoreCase(Constant.OAUTH)) { - OMElement authentication = factory.createOMElement("authentication", synapseNS); - OMElement oauth = factory.createOMElement("oauth", synapseNS); - OMElement authMode = factory.createOMElement("authMode", synapseNS); - authMode.setText(this.oauthAuthorizationMode); - if (oauthGrantType.equalsIgnoreCase(Constant.OAUTH_GRANT_TYPE_AUTHORIZATION_CODE)) { - OMElement authorizationCode = factory.createOMElement("authorizationCode", synapseNS); + if (StringUtils.isNotEmpty(authType)) { + if (authType.equalsIgnoreCase(Constant.BASIC_AUTH)) { + OMElement authentication = factory.createOMElement("authentication", synapseNS); + OMElement basicAuth = factory.createOMElement("basicAuth", synapseNS); + OMElement username = factory.createOMElement("username", synapseNS); + username.setText(this.basicCredentialsUsername); + basicAuth.addChild(username); + OMElement password = factory.createOMElement("password", synapseNS); + password.setText(this.basicCredentialsPassword); + basicAuth.addChild(password); + authentication.addChild(basicAuth); + http.addChild(authentication); + } else if (authType.equalsIgnoreCase(Constant.OAUTH)) { + OMElement authentication = factory.createOMElement("authentication", synapseNS); + OMElement oauth = factory.createOMElement("oauth", synapseNS); + OMElement authMode = factory.createOMElement("authMode", synapseNS); + authMode.setText(this.oauthAuthorizationMode); + if (oauthGrantType.equalsIgnoreCase(Constant.OAUTH_GRANT_TYPE_AUTHORIZATION_CODE)) { + OMElement authorizationCode = factory.createOMElement("authorizationCode", synapseNS); - OMElement refreshToken = factory.createOMElement("refreshToken", synapseNS); - refreshToken.setText(this.oauthAuthorizationRefreshToken); - OMElement clientId = factory.createOMElement("clientId", synapseNS); - clientId.setText(this.oauthAuthorizationClientId); - OMElement clientSecret = factory.createOMElement("clientSecret", synapseNS); - clientSecret.setText(this.oauthAuthorizationClientSecret); - OMElement tokenUrl = factory.createOMElement("tokenUrl", synapseNS); - tokenUrl.setText(this.oauthAuthorizationTokenUrl); + OMElement refreshToken = factory.createOMElement("refreshToken", synapseNS); + refreshToken.setText(this.oauthAuthorizationRefreshToken); + OMElement clientId = factory.createOMElement("clientId", synapseNS); + clientId.setText(this.oauthAuthorizationClientId); + OMElement clientSecret = factory.createOMElement("clientSecret", synapseNS); + clientSecret.setText(this.oauthAuthorizationClientSecret); + OMElement tokenUrl = factory.createOMElement("tokenUrl", synapseNS); + tokenUrl.setText(this.oauthAuthorizationTokenUrl); - authorizationCode.addChild(refreshToken); - authorizationCode.addChild(clientId); - authorizationCode.addChild(clientSecret); - authorizationCode.addChild(tokenUrl); - authorizationCode.addChild(authMode); + authorizationCode.addChild(refreshToken); + authorizationCode.addChild(clientId); + authorizationCode.addChild(clientSecret); + authorizationCode.addChild(tokenUrl); + authorizationCode.addChild(authMode); - if (StringUtils.isNotEmpty(this.oauthAuthorizationAdditionalProperties)) { - OMElement additionalProperties = factory.createOMElement("requestParameters", synapseNS); - for (String additionalProperty : this.oauthAuthorizationAdditionalProperties.split(",")) { - String[] keyValue = additionalProperty.split(":"); - if (keyValue.length == 2) { - OMElement parameter = factory.createOMElement("parameter", synapseNS); - parameter.addAttribute("name", keyValue[0], null); - parameter.setText(keyValue[1]); - additionalProperties.addChild(parameter); + if (StringUtils.isNotEmpty(this.oauthAuthorizationAdditionalProperties)) { + OMElement additionalProperties = factory.createOMElement("requestParameters", synapseNS); + for (String additionalProperty : this.oauthAuthorizationAdditionalProperties.split(",")) { + String[] keyValue = additionalProperty.split(":"); + if (keyValue.length == 2) { + OMElement parameter = factory.createOMElement("parameter", synapseNS); + parameter.addAttribute("name", keyValue[0].trim(), null); + parameter.setText(keyValue[1].trim()); + additionalProperties.addChild(parameter); + } } + authorizationCode.addChild(additionalProperties); } - authorizationCode.addChild(additionalProperties); - } - oauth.addChild(authorizationCode); - authentication.addChild(oauth); - http.addChild(authentication); - } else if (oauthGrantType.equalsIgnoreCase(Constant.OAUTH_GRANT_TYPE_CLIENT_CREDENTIALS)) { - OMElement clientCredentials = factory.createOMElement("clientCredentials", synapseNS); + oauth.addChild(authorizationCode); + authentication.addChild(oauth); + http.addChild(authentication); + } else if (oauthGrantType.equalsIgnoreCase(Constant.OAUTH_GRANT_TYPE_CLIENT_CREDENTIALS)) { + OMElement clientCredentials = factory.createOMElement("clientCredentials", synapseNS); - OMElement clientId = factory.createOMElement("clientId", synapseNS); - clientId.setText(this.oauthClientClientId); - OMElement clientSecret = factory.createOMElement("clientSecret", synapseNS); - clientSecret.setText(this.oauthClientClientSecret); - OMElement tokenUrl = factory.createOMElement("tokenUrl", synapseNS); - tokenUrl.setText(this.oauthClientTokenUrl); + OMElement clientId = factory.createOMElement("clientId", synapseNS); + clientId.setText(this.oauthClientClientId); + OMElement clientSecret = factory.createOMElement("clientSecret", synapseNS); + clientSecret.setText(this.oauthClientClientSecret); + OMElement tokenUrl = factory.createOMElement("tokenUrl", synapseNS); + tokenUrl.setText(this.oauthClientTokenUrl); - clientCredentials.addChild(clientId); - clientCredentials.addChild(clientSecret); - clientCredentials.addChild(tokenUrl); - clientCredentials.addChild(authMode); + clientCredentials.addChild(clientId); + clientCredentials.addChild(clientSecret); + clientCredentials.addChild(tokenUrl); + clientCredentials.addChild(authMode); - oauth.addChild(clientCredentials); - authentication.addChild(oauth); - http.addChild(authentication); - } else if (oauthGrantType.equalsIgnoreCase(Constant.OAUTH_GRANT_TYPE_PASSWORD)) { - OMElement passwordCredentials = factory.createOMElement("passwordCredentials", synapseNS); + if (StringUtils.isNotEmpty(this.oauthAuthorizationAdditionalProperties)) { + OMElement additionalProperties = factory.createOMElement("requestParameters", synapseNS); + for (String additionalProperty : this.oauthAuthorizationAdditionalProperties.split(",")) { + String[] keyValue = additionalProperty.split(":"); + if (keyValue.length == 2) { + OMElement parameter = factory.createOMElement("parameter", synapseNS); + parameter.addAttribute("name", keyValue[0].trim(), null); + parameter.setText(keyValue[1].trim()); + additionalProperties.addChild(parameter); + } + } + clientCredentials.addChild(additionalProperties); + } - OMElement username = factory.createOMElement("username", synapseNS); - username.setText(this.oauthPasswordUsername); - OMElement password = factory.createOMElement("password", synapseNS); - password.setText(this.oauthPasswordPassword); - OMElement clientId = factory.createOMElement("clientId", synapseNS); - clientId.setText(this.oauthPasswordClientId); - OMElement clientSecret = factory.createOMElement("clientSecret", synapseNS); - clientSecret.setText(this.oauthPasswordClientSecret); - OMElement tokenUrl = factory.createOMElement("tokenUrl", synapseNS); - tokenUrl.setText(this.oauthPasswordTokenUrl); + oauth.addChild(clientCredentials); + authentication.addChild(oauth); + http.addChild(authentication); + } else if (oauthGrantType.equalsIgnoreCase(Constant.OAUTH_GRANT_TYPE_PASSWORD)) { + OMElement passwordCredentials = factory.createOMElement("passwordCredentials", synapseNS); - passwordCredentials.addChild(username); - passwordCredentials.addChild(password); - passwordCredentials.addChild(clientId); - passwordCredentials.addChild(clientSecret); - passwordCredentials.addChild(tokenUrl); - passwordCredentials.addChild(authMode); + OMElement username = factory.createOMElement("username", synapseNS); + username.setText(this.oauthPasswordUsername); + OMElement password = factory.createOMElement("password", synapseNS); + password.setText(this.oauthPasswordPassword); + OMElement clientId = factory.createOMElement("clientId", synapseNS); + clientId.setText(this.oauthPasswordClientId); + OMElement clientSecret = factory.createOMElement("clientSecret", synapseNS); + clientSecret.setText(this.oauthPasswordClientSecret); + OMElement tokenUrl = factory.createOMElement("tokenUrl", synapseNS); + tokenUrl.setText(this.oauthPasswordTokenUrl); - oauth.addChild(passwordCredentials); - authentication.addChild(oauth); - http.addChild(authentication); + passwordCredentials.addChild(username); + passwordCredentials.addChild(password); + passwordCredentials.addChild(clientId); + passwordCredentials.addChild(clientSecret); + passwordCredentials.addChild(tokenUrl); + passwordCredentials.addChild(authMode); + + if (StringUtils.isNotEmpty(this.oauthAuthorizationAdditionalProperties)) { + OMElement additionalProperties = factory.createOMElement("requestParameters", synapseNS); + for (String additionalProperty : this.oauthAuthorizationAdditionalProperties.split(",")) { + String[] keyValue = additionalProperty.split(":"); + if (keyValue.length == 2) { + OMElement parameter = factory.createOMElement("parameter", synapseNS); + parameter.addAttribute("name", keyValue[0].trim(), null); + parameter.setText(keyValue[1].trim()); + additionalProperties.addChild(parameter); + } + } + passwordCredentials.addChild(additionalProperties); + } + + oauth.addChild(passwordCredentials); + authentication.addChild(oauth); + http.addChild(authentication); + } } } From 5ad9997122f2749492a61e99f01e737425a3300d Mon Sep 17 00:00:00 2001 From: chathurangaj Date: Thu, 12 Dec 2024 20:42:36 +0530 Subject: [PATCH 07/21] keep seperate field for each ui field --- .../synapse/deployers/HTTPConnectionRepresentation.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java b/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java index b417026c1d..6ae33f18f8 100644 --- a/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java +++ b/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java @@ -103,6 +103,9 @@ public HTTPConnectionRepresentation(OMElement inputOMElement) { case "oauthClientTokenUrl": this.oauthClientTokenUrl = child.getText(); break; + case "oauthClientAdditionalProperties": + this.oauthClientAdditionalProperties = child.getText(); + break; case "oauthPasswordClientId": this.oauthPasswordClientId = child.getText(); break; @@ -118,6 +121,9 @@ public HTTPConnectionRepresentation(OMElement inputOMElement) { case "oauthPasswordPassword": this.oauthPasswordPassword = child.getText(); break; + case "oauthPasswordAdditionalProperties": + this.oauthPasswordAdditionalProperties = child.getText(); + break; case "timeoutDuration": this.timeoutDuration = Integer.parseInt(child.getText()); break; From d37109aeaa3bfc5dfdc250472f72ebc1e25bd490 Mon Sep 17 00:00:00 2001 From: chathurangaj Date: Thu, 12 Dec 2024 21:07:07 +0530 Subject: [PATCH 08/21] refine local entry code --- .../synapse/deployers/LocalEntryDeployer.java | 84 ++++++++----------- 1 file changed, 34 insertions(+), 50 deletions(-) diff --git a/modules/core/src/main/java/org/apache/synapse/deployers/LocalEntryDeployer.java b/modules/core/src/main/java/org/apache/synapse/deployers/LocalEntryDeployer.java index ee8b84219d..2100875982 100644 --- a/modules/core/src/main/java/org/apache/synapse/deployers/LocalEntryDeployer.java +++ b/modules/core/src/main/java/org/apache/synapse/deployers/LocalEntryDeployer.java @@ -106,63 +106,47 @@ public String deploySynapseArtifact(OMElement artifactConfig, String fileName, return null; } - private void deployEndpointsForHTTPConnection(OMElement artifactConfig, String fileName, Properties properties) - throws XMLStreamException { + private void deployEndpointsForHTTPConnection(OMElement artifactConfig, String fileName, Properties properties) { OMElement httpInitElement = - artifactConfig.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, HTTP_CONNECTION_IDENTIFIER)); + artifactConfig.getFirstChildWithName( + new QName(SynapseConstants.SYNAPSE_NAMESPACE, HTTP_CONNECTION_IDENTIFIER)); if (httpInitElement != null) { OMElement documentElement = generateHTTPEndpointOMElement(httpInitElement); + deployHTTPEndpointForElement(documentElement, fileName, properties); + } + } -// String omElementString = "" + -// "" + -// "" + -// "" + -// ""; -// String omElementString = -// "" + -// "" + -// "" + -// "-1" + -// "1" + -// "" + -// "" + -// "0" + -// "" + -// "" + -// ""; -// InputStream inputStream = new ByteArrayInputStream(omElementString.getBytes(StandardCharsets.UTF_8)); -// OMElement documentElement = -// new StAXOMBuilder(StAXUtils.createXMLStreamReader(inputStream)).getDocumentElement(); - try { - Endpoint ep = EndpointFactory.getEndpointFromElement(documentElement, false, properties); - - //Set the car name - ep.setArtifactContainerName(customLogContent); - if (ep != null) { - ep.setFileName((new File(fileName)).getName()); - if (log.isDebugEnabled()) { - log.debug("Endpoint named '" + ep.getName() - + "' has been built from the file " + fileName); - } - ep.init(getSynapseEnvironment()); - if (log.isDebugEnabled()) { - log.debug("Initialized the endpoint : " + ep.getName()); - } - getSynapseConfiguration().addEndpoint(ep.getName(), ep); - if (log.isDebugEnabled()) { - log.debug("Endpoint Deployment from file : " + fileName + " : Completed"); - } - log.info("Endpoint named '" + ep.getName() - + "' has been deployed from file : " + fileName); - } else { - handleSynapseArtifactDeploymentError("Endpoint Deployment Failed. The artifact " + - "described in the file " + fileName + " is not an Endpoint"); + private void deployHTTPEndpointForElement(OMElement documentElement, String fileName, Properties properties) { + + try { + Endpoint ep = EndpointFactory.getEndpointFromElement(documentElement, false, properties); + + //Set the car name + ep.setArtifactContainerName(customLogContent); + if (ep != null) { + ep.setFileName((new File(fileName)).getName()); + if (log.isDebugEnabled()) { + log.debug("Endpoint named '" + ep.getName() + + "' has been built from the file " + fileName); } - } catch (Exception e) { - handleSynapseArtifactDeploymentError("Endpoint Deployment from the file : " - + fileName + " : Failed.", e); + ep.init(getSynapseEnvironment()); + if (log.isDebugEnabled()) { + log.debug("Initialized the endpoint : " + ep.getName()); + } + getSynapseConfiguration().addEndpoint(ep.getName(), ep); + if (log.isDebugEnabled()) { + log.debug("Endpoint Deployment from file : " + fileName + " : Completed"); + } + log.info("Endpoint named '" + ep.getName() + + "' has been deployed from file : " + fileName); + } else { + handleSynapseArtifactDeploymentError("Endpoint Deployment Failed. The artifact " + + "described in the file " + fileName + " is not an Endpoint"); } + } catch (Exception e) { + handleSynapseArtifactDeploymentError("Endpoint Deployment from the file : " + + fileName + " : Failed.", e); } } From b2a0b7a370cb0b668746d6c378ab6549b5688c21 Mon Sep 17 00:00:00 2001 From: chathurangaj Date: Thu, 12 Dec 2024 21:13:47 +0530 Subject: [PATCH 09/21] add generate oauth additional properties method --- .../HTTPConnectionRepresentation.java | 165 +++++++----------- 1 file changed, 62 insertions(+), 103 deletions(-) diff --git a/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java b/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java index 6ae33f18f8..ecd36ca829 100644 --- a/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java +++ b/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java @@ -16,28 +16,16 @@ public class HTTPConnectionRepresentation { private String baseUrl; private String certificateType; private String authType; - private String basicCredentialsUsername; - private String basicCredentialsPassword; private String oauthAuthorizationMode; private String oauthGrantType; - private String oauthAuthorizationClientId; - private String oauthAuthorizationClientSecret; - private String oauthAuthorizationTokenUrl; - private String oauthAuthorizationRefreshToken; - private String oauthAuthorizationAdditionalProperties; - - private String oauthClientClientId; - private String oauthClientClientSecret; - private String oauthClientTokenUrl; - private String oauthClientAdditionalProperties; - - private String oauthPasswordClientId; - private String oauthPasswordClientSecret; - private String oauthPasswordTokenUrl; - private String oauthPasswordUsername; - private String oauthPasswordPassword; - private String oauthPasswordAdditionalProperties; + private String username; + private String password; + private String clientId; + private String clientSecret; + private String tokenUrl; + private String refreshToken; + private String oauthAdditionalProperties; private int timeoutDuration; private String timeoutAction; @@ -68,10 +56,12 @@ public HTTPConnectionRepresentation(OMElement inputOMElement) { this.authType = child.getText(); break; case "basicCredentialsUsername": - this.basicCredentialsUsername = child.getText(); + case "oauthPasswordUsername": + this.username = child.getText(); break; case "basicCredentialsPassword": - this.basicCredentialsPassword = child.getText(); + case "oauthPasswordPassword": + this.password = child.getText(); break; case "oauthAuthorizationMode": this.oauthAuthorizationMode = child.getText(); @@ -80,49 +70,27 @@ public HTTPConnectionRepresentation(OMElement inputOMElement) { this.oauthGrantType = child.getText(); break; case "oauthAuthorizationClientId": - this.oauthAuthorizationClientId = child.getText(); + case "oauthClientClientId": + case "oauthPasswordClientId": + this.clientId = child.getText(); break; case "oauthAuthorizationClientSecret": - this.oauthAuthorizationClientSecret = child.getText(); + case "oauthClientClientSecret": + case "oauthPasswordClientSecret": + this.clientSecret = child.getText(); break; case "oauthAuthorizationTokenUrl": - this.oauthAuthorizationTokenUrl = child.getText(); + case "oauthClientTokenUrl": + case "oauthPasswordTokenUrl": + this.tokenUrl = child.getText(); break; case "oauthAuthorizationRefreshToken": - this.oauthAuthorizationRefreshToken = child.getText(); + this.refreshToken = child.getText(); break; case "oauthAuthorizationAdditionalProperties": - this.oauthAuthorizationAdditionalProperties = child.getText(); - break; - case "oauthClientClientId": - this.oauthClientClientId = child.getText(); - break; - case "oauthClientClientSecret": - this.oauthClientClientSecret = child.getText(); - break; - case "oauthClientTokenUrl": - this.oauthClientTokenUrl = child.getText(); - break; case "oauthClientAdditionalProperties": - this.oauthClientAdditionalProperties = child.getText(); - break; - case "oauthPasswordClientId": - this.oauthPasswordClientId = child.getText(); - break; - case "oauthPasswordClientSecret": - this.oauthPasswordClientSecret = child.getText(); - break; - case "oauthPasswordTokenUrl": - this.oauthPasswordTokenUrl = child.getText(); - break; - case "oauthPasswordUsername": - this.oauthPasswordUsername = child.getText(); - break; - case "oauthPasswordPassword": - this.oauthPasswordPassword = child.getText(); - break; case "oauthPasswordAdditionalProperties": - this.oauthPasswordAdditionalProperties = child.getText(); + this.oauthAdditionalProperties = child.getText(); break; case "timeoutDuration": this.timeoutDuration = Integer.parseInt(child.getText()); @@ -186,7 +154,8 @@ public OMElement generateOMElement() { http.addChild(timeout); } - if (StringUtils.isNotEmpty(this.suspendErrorCodes) || this.suspendInitialDuration > 0 || this.suspendProgressionFactor > 0 || this.suspendMaximumDuration > 0) { + if (StringUtils.isNotEmpty(this.suspendErrorCodes) || this.suspendInitialDuration > 0 || + this.suspendProgressionFactor > 0 || this.suspendMaximumDuration > 0) { OMElement suspendOnFailure = factory.createOMElement("suspendOnFailure", synapseNS); if (StringUtils.isNotEmpty(this.suspendErrorCodes)) { OMElement errorCodes = factory.createOMElement("errorCodes", synapseNS); @@ -235,12 +204,15 @@ public OMElement generateOMElement() { if (authType.equalsIgnoreCase(Constant.BASIC_AUTH)) { OMElement authentication = factory.createOMElement("authentication", synapseNS); OMElement basicAuth = factory.createOMElement("basicAuth", synapseNS); + OMElement username = factory.createOMElement("username", synapseNS); - username.setText(this.basicCredentialsUsername); - basicAuth.addChild(username); + username.setText(this.username); OMElement password = factory.createOMElement("password", synapseNS); - password.setText(this.basicCredentialsPassword); + password.setText(this.password); + + basicAuth.addChild(username); basicAuth.addChild(password); + authentication.addChild(basicAuth); http.addChild(authentication); } else if (authType.equalsIgnoreCase(Constant.OAUTH)) { @@ -252,13 +224,13 @@ public OMElement generateOMElement() { OMElement authorizationCode = factory.createOMElement("authorizationCode", synapseNS); OMElement refreshToken = factory.createOMElement("refreshToken", synapseNS); - refreshToken.setText(this.oauthAuthorizationRefreshToken); + refreshToken.setText(this.refreshToken); OMElement clientId = factory.createOMElement("clientId", synapseNS); - clientId.setText(this.oauthAuthorizationClientId); + clientId.setText(this.clientId); OMElement clientSecret = factory.createOMElement("clientSecret", synapseNS); - clientSecret.setText(this.oauthAuthorizationClientSecret); + clientSecret.setText(this.clientSecret); OMElement tokenUrl = factory.createOMElement("tokenUrl", synapseNS); - tokenUrl.setText(this.oauthAuthorizationTokenUrl); + tokenUrl.setText(this.tokenUrl); authorizationCode.addChild(refreshToken); authorizationCode.addChild(clientId); @@ -266,17 +238,8 @@ public OMElement generateOMElement() { authorizationCode.addChild(tokenUrl); authorizationCode.addChild(authMode); - if (StringUtils.isNotEmpty(this.oauthAuthorizationAdditionalProperties)) { - OMElement additionalProperties = factory.createOMElement("requestParameters", synapseNS); - for (String additionalProperty : this.oauthAuthorizationAdditionalProperties.split(",")) { - String[] keyValue = additionalProperty.split(":"); - if (keyValue.length == 2) { - OMElement parameter = factory.createOMElement("parameter", synapseNS); - parameter.addAttribute("name", keyValue[0].trim(), null); - parameter.setText(keyValue[1].trim()); - additionalProperties.addChild(parameter); - } - } + if (StringUtils.isNotEmpty(this.oauthAdditionalProperties)) { + OMElement additionalProperties = generateOAuthAdditionalPropertiesElement(factory, synapseNS); authorizationCode.addChild(additionalProperties); } @@ -287,28 +250,19 @@ public OMElement generateOMElement() { OMElement clientCredentials = factory.createOMElement("clientCredentials", synapseNS); OMElement clientId = factory.createOMElement("clientId", synapseNS); - clientId.setText(this.oauthClientClientId); + clientId.setText(this.clientId); OMElement clientSecret = factory.createOMElement("clientSecret", synapseNS); - clientSecret.setText(this.oauthClientClientSecret); + clientSecret.setText(this.clientSecret); OMElement tokenUrl = factory.createOMElement("tokenUrl", synapseNS); - tokenUrl.setText(this.oauthClientTokenUrl); + tokenUrl.setText(this.tokenUrl); clientCredentials.addChild(clientId); clientCredentials.addChild(clientSecret); clientCredentials.addChild(tokenUrl); clientCredentials.addChild(authMode); - if (StringUtils.isNotEmpty(this.oauthAuthorizationAdditionalProperties)) { - OMElement additionalProperties = factory.createOMElement("requestParameters", synapseNS); - for (String additionalProperty : this.oauthAuthorizationAdditionalProperties.split(",")) { - String[] keyValue = additionalProperty.split(":"); - if (keyValue.length == 2) { - OMElement parameter = factory.createOMElement("parameter", synapseNS); - parameter.addAttribute("name", keyValue[0].trim(), null); - parameter.setText(keyValue[1].trim()); - additionalProperties.addChild(parameter); - } - } + if (StringUtils.isNotEmpty(this.oauthAdditionalProperties)) { + OMElement additionalProperties = generateOAuthAdditionalPropertiesElement(factory, synapseNS); clientCredentials.addChild(additionalProperties); } @@ -319,15 +273,15 @@ public OMElement generateOMElement() { OMElement passwordCredentials = factory.createOMElement("passwordCredentials", synapseNS); OMElement username = factory.createOMElement("username", synapseNS); - username.setText(this.oauthPasswordUsername); + username.setText(this.username); OMElement password = factory.createOMElement("password", synapseNS); - password.setText(this.oauthPasswordPassword); + password.setText(this.password); OMElement clientId = factory.createOMElement("clientId", synapseNS); - clientId.setText(this.oauthPasswordClientId); + clientId.setText(this.clientId); OMElement clientSecret = factory.createOMElement("clientSecret", synapseNS); - clientSecret.setText(this.oauthPasswordClientSecret); + clientSecret.setText(this.clientSecret); OMElement tokenUrl = factory.createOMElement("tokenUrl", synapseNS); - tokenUrl.setText(this.oauthPasswordTokenUrl); + tokenUrl.setText(this.tokenUrl); passwordCredentials.addChild(username); passwordCredentials.addChild(password); @@ -336,17 +290,8 @@ public OMElement generateOMElement() { passwordCredentials.addChild(tokenUrl); passwordCredentials.addChild(authMode); - if (StringUtils.isNotEmpty(this.oauthAuthorizationAdditionalProperties)) { - OMElement additionalProperties = factory.createOMElement("requestParameters", synapseNS); - for (String additionalProperty : this.oauthAuthorizationAdditionalProperties.split(",")) { - String[] keyValue = additionalProperty.split(":"); - if (keyValue.length == 2) { - OMElement parameter = factory.createOMElement("parameter", synapseNS); - parameter.addAttribute("name", keyValue[0].trim(), null); - parameter.setText(keyValue[1].trim()); - additionalProperties.addChild(parameter); - } - } + if (StringUtils.isNotEmpty(this.oauthAdditionalProperties)) { + OMElement additionalProperties = generateOAuthAdditionalPropertiesElement(factory, synapseNS); passwordCredentials.addChild(additionalProperties); } @@ -360,4 +305,18 @@ public OMElement generateOMElement() { endpoint.addChild(http); return endpoint; } + + private OMElement generateOAuthAdditionalPropertiesElement(OMFactory factory, OMNamespace synapseNS) { + OMElement additionalProperties = factory.createOMElement("requestParameters", synapseNS); + for (String additionalProperty : this.oauthAdditionalProperties.split(",")) { + String[] keyValue = additionalProperty.split(":"); + if (keyValue.length == 2) { + OMElement parameter = factory.createOMElement("parameter", synapseNS); + parameter.addAttribute("name", keyValue[0].trim(), null); + parameter.setText(keyValue[1].trim()); + additionalProperties.addChild(parameter); + } + } + return additionalProperties; + } } From 6de60178d0100dbaf01bc8b26e512237a46f5cd5 Mon Sep 17 00:00:00 2001 From: chathurangaj Date: Thu, 12 Dec 2024 21:20:07 +0530 Subject: [PATCH 10/21] remove using int and use string for all attributes --- .../HTTPConnectionRepresentation.java | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java b/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java index ecd36ca829..4059654e3a 100644 --- a/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java +++ b/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java @@ -27,15 +27,15 @@ public class HTTPConnectionRepresentation { private String refreshToken; private String oauthAdditionalProperties; - private int timeoutDuration; + private String timeoutDuration; private String timeoutAction; private String suspendErrorCodes; - private int suspendInitialDuration; - private int suspendMaximumDuration; - private int suspendProgressionFactor; + private String suspendInitialDuration; + private String suspendMaximumDuration; + private String suspendProgressionFactor; private String retryErrorCodes; - private int retryCount; - private int retryDelay; + private String retryCount; + private String retryDelay; public HTTPConnectionRepresentation(OMElement inputOMElement) { // Parse input OMElement and populate the attributes @@ -93,7 +93,7 @@ public HTTPConnectionRepresentation(OMElement inputOMElement) { this.oauthAdditionalProperties = child.getText(); break; case "timeoutDuration": - this.timeoutDuration = Integer.parseInt(child.getText()); + this.timeoutDuration = child.getText(); break; case "timeoutAction": this.timeoutAction = child.getText(); @@ -102,22 +102,22 @@ public HTTPConnectionRepresentation(OMElement inputOMElement) { this.suspendErrorCodes = child.getText(); break; case "suspendInitialDuration": - this.suspendInitialDuration = Integer.parseInt(child.getText()); + this.suspendInitialDuration = child.getText(); break; case "suspendMaximumDuration": - this.suspendMaximumDuration = Integer.parseInt(child.getText()); + this.suspendMaximumDuration = child.getText(); break; case "suspendProgressionFactor": - this.suspendProgressionFactor = Integer.parseInt(child.getText()); + this.suspendProgressionFactor = child.getText(); break; case "retryErrorCodes": this.retryErrorCodes = child.getText(); break; case "retryCount": - this.retryCount = Integer.parseInt(child.getText()); + this.retryCount = child.getText(); break; case "retryDelay": - this.retryDelay = Integer.parseInt(child.getText()); + this.retryDelay = child.getText(); break; case "name": this.name = child.getText(); @@ -139,9 +139,9 @@ public OMElement generateOMElement() { OMElement http = factory.createOMElement("http", synapseNS); http.addAttribute("uri-template", "{uri.var.base}{+uri.var.path}{+uri.var.query}", null); - if (this.timeoutDuration > 0 || StringUtils.isNotEmpty(this.timeoutAction)) { + if (StringUtils.isNotEmpty(this.timeoutDuration) || StringUtils.isNotEmpty(this.timeoutAction)) { OMElement timeout = factory.createOMElement("timeout", synapseNS); - if (this.timeoutDuration > 0) { + if (StringUtils.isNotEmpty(this.timeoutDuration)) { OMElement duration = factory.createOMElement("duration", synapseNS); duration.setText(String.valueOf(this.timeoutDuration)); timeout.addChild(duration); @@ -154,25 +154,25 @@ public OMElement generateOMElement() { http.addChild(timeout); } - if (StringUtils.isNotEmpty(this.suspendErrorCodes) || this.suspendInitialDuration > 0 || - this.suspendProgressionFactor > 0 || this.suspendMaximumDuration > 0) { + if (StringUtils.isNotEmpty(this.suspendErrorCodes) || StringUtils.isNotEmpty(this.suspendInitialDuration) || + StringUtils.isNotEmpty(this.suspendProgressionFactor) || StringUtils.isNotEmpty(this.suspendMaximumDuration)) { OMElement suspendOnFailure = factory.createOMElement("suspendOnFailure", synapseNS); if (StringUtils.isNotEmpty(this.suspendErrorCodes)) { OMElement errorCodes = factory.createOMElement("errorCodes", synapseNS); errorCodes.setText(this.suspendErrorCodes); suspendOnFailure.addChild(errorCodes); } - if (this.suspendInitialDuration > 0) { + if (StringUtils.isNotEmpty(this.suspendInitialDuration)) { OMElement initialDuration = factory.createOMElement("initialDuration", synapseNS); initialDuration.setText(String.valueOf(this.suspendInitialDuration)); suspendOnFailure.addChild(initialDuration); } - if (this.suspendProgressionFactor > 0) { + if (StringUtils.isNotEmpty(this.suspendProgressionFactor)) { OMElement progressionFactor = factory.createOMElement("progressionFactor", synapseNS); progressionFactor.setText(String.valueOf(this.suspendProgressionFactor)); suspendOnFailure.addChild(progressionFactor); } - if (this.suspendMaximumDuration > 0) { + if (StringUtils.isNotEmpty(this.suspendMaximumDuration)) { OMElement maximumDuration = factory.createOMElement("maximumDuration", synapseNS); maximumDuration.setText(String.valueOf(this.suspendMaximumDuration)); suspendOnFailure.addChild(maximumDuration); @@ -180,20 +180,20 @@ public OMElement generateOMElement() { http.addChild(suspendOnFailure); } - if (StringUtils.isNotEmpty(this.retryErrorCodes) || this.retryCount > 0 || this.retryDelay > 0) { + if (StringUtils.isNotEmpty(this.retryErrorCodes) || StringUtils.isNotEmpty(this.retryCount) || StringUtils.isNotEmpty(this.retryDelay)) { OMElement markForSuspension = factory.createOMElement("markForSuspension", synapseNS); - OMElement retryErrorCodes = factory.createOMElement("errorCodes", synapseNS); if (StringUtils.isNotEmpty(this.retryErrorCodes)) { + OMElement retryErrorCodes = factory.createOMElement("errorCodes", synapseNS); retryErrorCodes.setText(this.retryErrorCodes); markForSuspension.addChild(retryErrorCodes); } - OMElement retriesBeforeSuspension = factory.createOMElement("retriesBeforeSuspension", synapseNS); - if (this.retryCount > 0) { + if (StringUtils.isNotEmpty(this.retryCount)) { + OMElement retriesBeforeSuspension = factory.createOMElement("retriesBeforeSuspension", synapseNS); retriesBeforeSuspension.setText(String.valueOf(this.retryCount)); markForSuspension.addChild(retriesBeforeSuspension); } - OMElement retryDelay = factory.createOMElement("retryDelay", synapseNS); - if (this.retryDelay > 0) { + if (StringUtils.isNotEmpty(this.retryDelay)) { + OMElement retryDelay = factory.createOMElement("retryDelay", synapseNS); retryDelay.setText(String.valueOf(this.retryDelay)); markForSuspension.addChild(retryDelay); } From 9096bc2bcc31a7f143ef04d44abb1f864a5a413b Mon Sep 17 00:00:00 2001 From: chathurangaj Date: Thu, 12 Dec 2024 21:48:05 +0530 Subject: [PATCH 11/21] add seperate methods to generate OMElements --- .../HTTPConnectionRepresentation.java | 215 +++++++++++------- 1 file changed, 136 insertions(+), 79 deletions(-) diff --git a/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java b/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java index 4059654e3a..d30eb6d406 100644 --- a/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java +++ b/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java @@ -180,7 +180,8 @@ public OMElement generateOMElement() { http.addChild(suspendOnFailure); } - if (StringUtils.isNotEmpty(this.retryErrorCodes) || StringUtils.isNotEmpty(this.retryCount) || StringUtils.isNotEmpty(this.retryDelay)) { + if (StringUtils.isNotEmpty(this.retryErrorCodes) || + StringUtils.isNotEmpty(this.retryCount) || StringUtils.isNotEmpty(this.retryDelay)) { OMElement markForSuspension = factory.createOMElement("markForSuspension", synapseNS); if (StringUtils.isNotEmpty(this.retryErrorCodes)) { OMElement retryErrorCodes = factory.createOMElement("errorCodes", synapseNS); @@ -203,98 +204,24 @@ public OMElement generateOMElement() { if (StringUtils.isNotEmpty(authType)) { if (authType.equalsIgnoreCase(Constant.BASIC_AUTH)) { OMElement authentication = factory.createOMElement("authentication", synapseNS); - OMElement basicAuth = factory.createOMElement("basicAuth", synapseNS); - - OMElement username = factory.createOMElement("username", synapseNS); - username.setText(this.username); - OMElement password = factory.createOMElement("password", synapseNS); - password.setText(this.password); - - basicAuth.addChild(username); - basicAuth.addChild(password); - + OMElement basicAuth = generateBasicAuthenticationElement(factory, synapseNS); authentication.addChild(basicAuth); http.addChild(authentication); } else if (authType.equalsIgnoreCase(Constant.OAUTH)) { OMElement authentication = factory.createOMElement("authentication", synapseNS); OMElement oauth = factory.createOMElement("oauth", synapseNS); - OMElement authMode = factory.createOMElement("authMode", synapseNS); - authMode.setText(this.oauthAuthorizationMode); if (oauthGrantType.equalsIgnoreCase(Constant.OAUTH_GRANT_TYPE_AUTHORIZATION_CODE)) { - OMElement authorizationCode = factory.createOMElement("authorizationCode", synapseNS); - - OMElement refreshToken = factory.createOMElement("refreshToken", synapseNS); - refreshToken.setText(this.refreshToken); - OMElement clientId = factory.createOMElement("clientId", synapseNS); - clientId.setText(this.clientId); - OMElement clientSecret = factory.createOMElement("clientSecret", synapseNS); - clientSecret.setText(this.clientSecret); - OMElement tokenUrl = factory.createOMElement("tokenUrl", synapseNS); - tokenUrl.setText(this.tokenUrl); - - authorizationCode.addChild(refreshToken); - authorizationCode.addChild(clientId); - authorizationCode.addChild(clientSecret); - authorizationCode.addChild(tokenUrl); - authorizationCode.addChild(authMode); - - if (StringUtils.isNotEmpty(this.oauthAdditionalProperties)) { - OMElement additionalProperties = generateOAuthAdditionalPropertiesElement(factory, synapseNS); - authorizationCode.addChild(additionalProperties); - } - + OMElement authorizationCode = generateOAuthAuthorizatonCodeElement(factory, synapseNS); oauth.addChild(authorizationCode); authentication.addChild(oauth); http.addChild(authentication); } else if (oauthGrantType.equalsIgnoreCase(Constant.OAUTH_GRANT_TYPE_CLIENT_CREDENTIALS)) { - OMElement clientCredentials = factory.createOMElement("clientCredentials", synapseNS); - - OMElement clientId = factory.createOMElement("clientId", synapseNS); - clientId.setText(this.clientId); - OMElement clientSecret = factory.createOMElement("clientSecret", synapseNS); - clientSecret.setText(this.clientSecret); - OMElement tokenUrl = factory.createOMElement("tokenUrl", synapseNS); - tokenUrl.setText(this.tokenUrl); - - clientCredentials.addChild(clientId); - clientCredentials.addChild(clientSecret); - clientCredentials.addChild(tokenUrl); - clientCredentials.addChild(authMode); - - if (StringUtils.isNotEmpty(this.oauthAdditionalProperties)) { - OMElement additionalProperties = generateOAuthAdditionalPropertiesElement(factory, synapseNS); - clientCredentials.addChild(additionalProperties); - } - + OMElement clientCredentials = generateOAuthClientCredentialsElement(factory, synapseNS); oauth.addChild(clientCredentials); authentication.addChild(oauth); http.addChild(authentication); } else if (oauthGrantType.equalsIgnoreCase(Constant.OAUTH_GRANT_TYPE_PASSWORD)) { - OMElement passwordCredentials = factory.createOMElement("passwordCredentials", synapseNS); - - OMElement username = factory.createOMElement("username", synapseNS); - username.setText(this.username); - OMElement password = factory.createOMElement("password", synapseNS); - password.setText(this.password); - OMElement clientId = factory.createOMElement("clientId", synapseNS); - clientId.setText(this.clientId); - OMElement clientSecret = factory.createOMElement("clientSecret", synapseNS); - clientSecret.setText(this.clientSecret); - OMElement tokenUrl = factory.createOMElement("tokenUrl", synapseNS); - tokenUrl.setText(this.tokenUrl); - - passwordCredentials.addChild(username); - passwordCredentials.addChild(password); - passwordCredentials.addChild(clientId); - passwordCredentials.addChild(clientSecret); - passwordCredentials.addChild(tokenUrl); - passwordCredentials.addChild(authMode); - - if (StringUtils.isNotEmpty(this.oauthAdditionalProperties)) { - OMElement additionalProperties = generateOAuthAdditionalPropertiesElement(factory, synapseNS); - passwordCredentials.addChild(additionalProperties); - } - + OMElement passwordCredentials = generateOAuthPasswordCredentialsElement(factory, synapseNS); oauth.addChild(passwordCredentials); authentication.addChild(oauth); http.addChild(authentication); @@ -306,6 +233,136 @@ public OMElement generateOMElement() { return endpoint; } + private OMElement generateOAuthPasswordCredentialsElement(OMFactory factory, OMNamespace synapseNS) { + + OMElement passwordCredentials = factory.createOMElement("passwordCredentials", synapseNS); + + OMElement username = generateAuthUsernameElement(factory, synapseNS); + OMElement password = generateAuthPasswordElement(factory, synapseNS); + OMElement clientId = generateOAuthClientIDElement(factory, synapseNS); + OMElement clientSecret = generateOAuthClientSecretElement(factory, synapseNS); + OMElement tokenUrl = generateOAuthTokenUrlElement(factory, synapseNS); + OMElement authMode = generateOAuthAuthorizationModeElement(factory, synapseNS); + + passwordCredentials.addChild(username); + passwordCredentials.addChild(password); + passwordCredentials.addChild(clientId); + passwordCredentials.addChild(clientSecret); + passwordCredentials.addChild(tokenUrl); + passwordCredentials.addChild(authMode); + + if (StringUtils.isNotEmpty(this.oauthAdditionalProperties)) { + OMElement additionalProperties = generateOAuthAdditionalPropertiesElement(factory, synapseNS); + passwordCredentials.addChild(additionalProperties); + } + return passwordCredentials; + } + + private OMElement generateOAuthTokenUrlElement(OMFactory factory, OMNamespace synapseNS) { + + OMElement oauthTokenUrl = factory.createOMElement("tokenUrl", synapseNS); + oauthTokenUrl.setText(this.tokenUrl); + return oauthTokenUrl; + } + + private OMElement generateAuthUsernameElement(OMFactory factory, OMNamespace synapseNS) { + + OMElement authUsername = factory.createOMElement("username", synapseNS); + authUsername.setText(this.username); + return authUsername; + } + + private OMElement generateOAuthClientCredentialsElement(OMFactory factory, OMNamespace synapseNS) { + + OMElement clientCredentials = factory.createOMElement("clientCredentials", synapseNS); + + OMElement clientId = generateOAuthClientIDElement(factory, synapseNS); + OMElement clientSecret = generateOAuthClientSecretElement(factory, synapseNS); + OMElement tokenUrl = generateOAuthTokenUrlElement(factory, synapseNS); + OMElement authMode = generateOAuthAuthorizationModeElement(factory, synapseNS); + + clientCredentials.addChild(clientId); + clientCredentials.addChild(clientSecret); + clientCredentials.addChild(tokenUrl); + clientCredentials.addChild(authMode); + + if (StringUtils.isNotEmpty(this.oauthAdditionalProperties)) { + OMElement additionalProperties = generateOAuthAdditionalPropertiesElement(factory, synapseNS); + clientCredentials.addChild(additionalProperties); + } + return clientCredentials; + } + + private OMElement generateOAuthAuthorizatonCodeElement(OMFactory factory, OMNamespace synapseNS) { + + OMElement authorizationCode = factory.createOMElement("authorizationCode", synapseNS); + + OMElement refreshToken = generateOAuthRefreshTokenElement(factory, synapseNS); + OMElement clientId = generateOAuthClientIDElement(factory, synapseNS); + OMElement clientSecret = generateOAuthClientSecretElement(factory, synapseNS); + OMElement tokenUrl = generateOAuthTokenUrlElement(factory, synapseNS); + OMElement authMode = generateOAuthAuthorizationModeElement(factory, synapseNS); + + authorizationCode.addChild(refreshToken); + authorizationCode.addChild(clientId); + authorizationCode.addChild(clientSecret); + authorizationCode.addChild(tokenUrl); + authorizationCode.addChild(authMode); + + if (StringUtils.isNotEmpty(this.oauthAdditionalProperties)) { + OMElement additionalProperties = generateOAuthAdditionalPropertiesElement(factory, synapseNS); + authorizationCode.addChild(additionalProperties); + } + return authorizationCode; + } + + private OMElement generateOAuthRefreshTokenElement(OMFactory factory, OMNamespace synapseNS) { + + OMElement oauthRefreshToken = factory.createOMElement("refreshToken", synapseNS); + oauthRefreshToken.setText(this.refreshToken); + return oauthRefreshToken; + } + + private OMElement generateOAuthClientSecretElement(OMFactory factory, OMNamespace synapseNS) { + + OMElement oauthClientSecret = factory.createOMElement("clientSecret", synapseNS); + oauthClientSecret.setText(this.clientSecret); + return oauthClientSecret; + } + + private OMElement generateOAuthClientIDElement(OMFactory factory, OMNamespace synapseNS) { + + OMElement oauthClientID = factory.createOMElement("clientId", synapseNS); + oauthClientID.setText(this.clientId); + return oauthClientID; + } + + private OMElement generateOAuthAuthorizationModeElement(OMFactory factory, OMNamespace synapseNS) { + + OMElement authMode = factory.createOMElement("authMode", synapseNS); + authMode.setText(this.oauthAuthorizationMode); + return authMode; + } + + private OMElement generateBasicAuthenticationElement(OMFactory factory, OMNamespace synapseNS) { + + OMElement basicAuth = factory.createOMElement("basicAuth", synapseNS); + + OMElement username = generateAuthUsernameElement(factory, synapseNS); + OMElement password = generateAuthPasswordElement(factory, synapseNS); + + basicAuth.addChild(username); + basicAuth.addChild(password); + return basicAuth; + } + + private OMElement generateAuthPasswordElement(OMFactory factory, OMNamespace synapseNS) { + + OMElement authPassword = factory.createOMElement("password", synapseNS); + authPassword.setText(this.password); + return authPassword; + } + private OMElement generateOAuthAdditionalPropertiesElement(OMFactory factory, OMNamespace synapseNS) { OMElement additionalProperties = factory.createOMElement("requestParameters", synapseNS); for (String additionalProperty : this.oauthAdditionalProperties.split(",")) { From bf76f39855513e103da57febafb2e62bb31a1bbb Mon Sep 17 00:00:00 2001 From: chathurangaj Date: Thu, 12 Dec 2024 21:56:49 +0530 Subject: [PATCH 12/21] add trace and statistics --- .../deployers/HTTPConnectionRepresentation.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java b/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java index d30eb6d406..52d2ac82b4 100644 --- a/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java +++ b/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java @@ -37,6 +37,9 @@ public class HTTPConnectionRepresentation { private String retryCount; private String retryDelay; + private String trace; + private String statistics; + public HTTPConnectionRepresentation(OMElement inputOMElement) { // Parse input OMElement and populate the attributes Iterator children = inputOMElement.getChildElements(); @@ -123,6 +126,12 @@ public HTTPConnectionRepresentation(OMElement inputOMElement) { this.name = child.getText(); this.endpointName = child.getText() + Constant.ENDPOINT_IDENTIFIER; break; + case "trace": + this.trace = child.getText(); + break; + case "statistics": + this.statistics = child.getText(); + break; default: // Ignore unknown elements } @@ -137,6 +146,12 @@ public OMElement generateOMElement() { endpoint.addAttribute("name", endpointName, null); OMElement http = factory.createOMElement("http", synapseNS); + if (StringUtils.isNotEmpty(this.trace) && this.trace.equalsIgnoreCase("enable")) { + http.addAttribute("trace", "enable", null); + } + if (StringUtils.isNotEmpty(this.statistics) && this.statistics.equalsIgnoreCase("enable")) { + http.addAttribute("statistics", "enable", null); + } http.addAttribute("uri-template", "{uri.var.base}{+uri.var.path}{+uri.var.query}", null); if (StringUtils.isNotEmpty(this.timeoutDuration) || StringUtils.isNotEmpty(this.timeoutAction)) { From 6e2d35527e530ffddd7e3bccbea7bd024dcbe729 Mon Sep 17 00:00:00 2001 From: chathurangaj Date: Thu, 12 Dec 2024 23:04:00 +0530 Subject: [PATCH 13/21] rename generateOMElement to generateEndpointOMElement --- .../HTTPConnectionRepresentation.java | 2 +- .../synapse/deployers/LocalEntryDeployer.java | 3 +-- .../HTTPConnectionRepresentationTest.java | 18 +++++++++--------- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java b/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java index 52d2ac82b4..b8359076bc 100644 --- a/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java +++ b/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java @@ -138,7 +138,7 @@ public HTTPConnectionRepresentation(OMElement inputOMElement) { } } - public OMElement generateOMElement() { + public OMElement generateEndpointOMElement() { OMFactory factory = new OMLinkedListImplFactory(); OMNamespace synapseNS = factory.createOMNamespace("http://ws.apache.org/ns/synapse", ""); diff --git a/modules/core/src/main/java/org/apache/synapse/deployers/LocalEntryDeployer.java b/modules/core/src/main/java/org/apache/synapse/deployers/LocalEntryDeployer.java index 2100875982..124e174fc9 100644 --- a/modules/core/src/main/java/org/apache/synapse/deployers/LocalEntryDeployer.java +++ b/modules/core/src/main/java/org/apache/synapse/deployers/LocalEntryDeployer.java @@ -50,7 +50,6 @@ import java.util.Properties; import javax.xml.namespace.QName; -import javax.xml.stream.XMLStreamException; /** * Handles the LocalEntry deployment and undeployment tasks @@ -154,7 +153,7 @@ private OMElement generateHTTPEndpointOMElement(OMElement httpConnectionElement) HTTPConnectionRepresentation httpConnectionRepresentation = new HTTPConnectionRepresentation(httpConnectionElement); - return httpConnectionRepresentation.generateOMElement(); + return httpConnectionRepresentation.generateEndpointOMElement(); } private void handleSSLSenderCertificates(OMElement element) throws DeploymentException { diff --git a/modules/core/src/test/java/org/apache/synapse/deployers/HTTPConnectionRepresentationTest.java b/modules/core/src/test/java/org/apache/synapse/deployers/HTTPConnectionRepresentationTest.java index d862b47992..75ba460df8 100644 --- a/modules/core/src/test/java/org/apache/synapse/deployers/HTTPConnectionRepresentationTest.java +++ b/modules/core/src/test/java/org/apache/synapse/deployers/HTTPConnectionRepresentationTest.java @@ -53,7 +53,7 @@ public void testEndpointOMElementGeneration() throws XMLStreamException { OMElement documentElement = new StAXOMBuilder(StAXUtils.createXMLStreamReader(inputStream)).getDocumentElement(); HTTPConnectionRepresentation httpConnectionRepresentation = new HTTPConnectionRepresentation(documentElement); - OMElement generatedEndpointOMElement = httpConnectionRepresentation.generateOMElement(); + OMElement generatedEndpointOMElement = httpConnectionRepresentation.generateEndpointOMElement(); Assert.assertEquals(expectedEndpointOMElementString, generatedEndpointOMElement.toString()); } @@ -74,7 +74,7 @@ public void testEndpointOMElementGenerationWithoutErrorHandling() throws XMLStre OMElement documentElement = new StAXOMBuilder(StAXUtils.createXMLStreamReader(inputStream)).getDocumentElement(); HTTPConnectionRepresentation httpConnectionRepresentation = new HTTPConnectionRepresentation(documentElement); - OMElement generatedEndpointOMElement = httpConnectionRepresentation.generateOMElement(); + OMElement generatedEndpointOMElement = httpConnectionRepresentation.generateEndpointOMElement(); Assert.assertEquals(expectedEndpointOMElementString, generatedEndpointOMElement.toString()); } @@ -115,7 +115,7 @@ public void testEndpointOMElementGenerationWithTimeoutActionNever() throws XMLSt OMElement documentElement = new StAXOMBuilder(StAXUtils.createXMLStreamReader(inputStream)).getDocumentElement(); HTTPConnectionRepresentation httpConnectionRepresentation = new HTTPConnectionRepresentation(documentElement); - OMElement generatedEndpointOMElement = httpConnectionRepresentation.generateOMElement(); + OMElement generatedEndpointOMElement = httpConnectionRepresentation.generateEndpointOMElement(); Assert.assertEquals(expectedEndpointOMElementString, generatedEndpointOMElement.toString()); } @@ -166,7 +166,7 @@ public void testEndpointOMElementGenerationWithBasicAuth() throws XMLStreamExcep OMElement documentElement = new StAXOMBuilder(StAXUtils.createXMLStreamReader(inputStream)).getDocumentElement(); HTTPConnectionRepresentation httpConnectionRepresentation = new HTTPConnectionRepresentation(documentElement); - OMElement generatedEndpointOMElement = httpConnectionRepresentation.generateOMElement(); + OMElement generatedEndpointOMElement = httpConnectionRepresentation.generateEndpointOMElement(); Assert.assertEquals(expectedEndpointOMElementString, generatedEndpointOMElement.toString()); } @@ -226,7 +226,7 @@ public void testEndpointOMElementGenerationWithOAuthAuthorizationCode() throws X OMElement documentElement = new StAXOMBuilder(StAXUtils.createXMLStreamReader(inputStream)).getDocumentElement(); HTTPConnectionRepresentation httpConnectionRepresentation = new HTTPConnectionRepresentation(documentElement); - OMElement generatedEndpointOMElement = httpConnectionRepresentation.generateOMElement(); + OMElement generatedEndpointOMElement = httpConnectionRepresentation.generateEndpointOMElement(); Assert.assertEquals(expectedEndpointOMElementString, generatedEndpointOMElement.toString()); } @@ -291,7 +291,7 @@ public void testEndpointOMElementGenerationWithOAuthAuthorizationCodeAdditionalP OMElement documentElement = new StAXOMBuilder(StAXUtils.createXMLStreamReader(inputStream)).getDocumentElement(); HTTPConnectionRepresentation httpConnectionRepresentation = new HTTPConnectionRepresentation(documentElement); - OMElement generatedEndpointOMElement = httpConnectionRepresentation.generateOMElement(); + OMElement generatedEndpointOMElement = httpConnectionRepresentation.generateEndpointOMElement(); Assert.assertEquals(expectedEndpointOMElementString, generatedEndpointOMElement.toString()); } @@ -351,7 +351,7 @@ public void testEndpointOMElementGenerationWithOAuthAuthorizationCodeAndExpressi OMElement documentElement = new StAXOMBuilder(StAXUtils.createXMLStreamReader(inputStream)).getDocumentElement(); HTTPConnectionRepresentation httpConnectionRepresentation = new HTTPConnectionRepresentation(documentElement); - OMElement generatedEndpointOMElement = httpConnectionRepresentation.generateOMElement(); + OMElement generatedEndpointOMElement = httpConnectionRepresentation.generateEndpointOMElement(); Assert.assertEquals(expectedEndpointOMElementString, generatedEndpointOMElement.toString()); } @@ -409,7 +409,7 @@ public void testEndpointOMElementGenerationWithOAuthClientCredentials() throws X OMElement documentElement = new StAXOMBuilder(StAXUtils.createXMLStreamReader(inputStream)).getDocumentElement(); HTTPConnectionRepresentation httpConnectionRepresentation = new HTTPConnectionRepresentation(documentElement); - OMElement generatedEndpointOMElement = httpConnectionRepresentation.generateOMElement(); + OMElement generatedEndpointOMElement = httpConnectionRepresentation.generateEndpointOMElement(); Assert.assertEquals(expectedEndpointOMElementString, generatedEndpointOMElement.toString()); } @@ -471,7 +471,7 @@ public void testEndpointOMElementGenerationWithOAuthPassword() throws XMLStreamE OMElement documentElement = new StAXOMBuilder(StAXUtils.createXMLStreamReader(inputStream)).getDocumentElement(); HTTPConnectionRepresentation httpConnectionRepresentation = new HTTPConnectionRepresentation(documentElement); - OMElement generatedEndpointOMElement = httpConnectionRepresentation.generateOMElement(); + OMElement generatedEndpointOMElement = httpConnectionRepresentation.generateEndpointOMElement(); Assert.assertEquals(expectedEndpointOMElementString, generatedEndpointOMElement.toString()); } } From 24253a046bd30d63b256a679bdcfb3399d1391be Mon Sep 17 00:00:00 2001 From: chathurangaj Date: Thu, 12 Dec 2024 23:05:25 +0530 Subject: [PATCH 14/21] add trace and statistics tests --- .../HTTPConnectionRepresentationTest.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/modules/core/src/test/java/org/apache/synapse/deployers/HTTPConnectionRepresentationTest.java b/modules/core/src/test/java/org/apache/synapse/deployers/HTTPConnectionRepresentationTest.java index 75ba460df8..8acdf145f3 100644 --- a/modules/core/src/test/java/org/apache/synapse/deployers/HTTPConnectionRepresentationTest.java +++ b/modules/core/src/test/java/org/apache/synapse/deployers/HTTPConnectionRepresentationTest.java @@ -78,6 +78,50 @@ public void testEndpointOMElementGenerationWithoutErrorHandling() throws XMLStre Assert.assertEquals(expectedEndpointOMElementString, generatedEndpointOMElement.toString()); } + @Test + public void testEndpointOMElementGenerationWithTrace() throws XMLStreamException { + + String omElementString = + "\n" + + " http\n" + + " library\n" + + " http://jsonplaceholder.typicode.com/posts\n" + + " enable\n" + + ""; + String expectedEndpointOMElementString = + "" + + "" + + ""; + InputStream inputStream = new ByteArrayInputStream(omElementString.getBytes(StandardCharsets.UTF_8)); + OMElement documentElement = + new StAXOMBuilder(StAXUtils.createXMLStreamReader(inputStream)).getDocumentElement(); + HTTPConnectionRepresentation httpConnectionRepresentation = new HTTPConnectionRepresentation(documentElement); + OMElement generatedEndpointOMElement = httpConnectionRepresentation.generateEndpointOMElement(); + Assert.assertEquals(expectedEndpointOMElementString, generatedEndpointOMElement.toString()); + } + + @Test + public void testEndpointOMElementGenerationWithStatistics() throws XMLStreamException { + + String omElementString = + "\n" + + " http\n" + + " library\n" + + " http://jsonplaceholder.typicode.com/posts\n" + + " enable\n" + + ""; + String expectedEndpointOMElementString = + "" + + "" + + ""; + InputStream inputStream = new ByteArrayInputStream(omElementString.getBytes(StandardCharsets.UTF_8)); + OMElement documentElement = + new StAXOMBuilder(StAXUtils.createXMLStreamReader(inputStream)).getDocumentElement(); + HTTPConnectionRepresentation httpConnectionRepresentation = new HTTPConnectionRepresentation(documentElement); + OMElement generatedEndpointOMElement = httpConnectionRepresentation.generateEndpointOMElement(); + Assert.assertEquals(expectedEndpointOMElementString, generatedEndpointOMElement.toString()); + } + @Test public void testEndpointOMElementGenerationWithTimeoutActionNever() throws XMLStreamException { From e244c93c977f3123d776fa25b4c922f56eb94ea0 Mon Sep 17 00:00:00 2001 From: chathurangaj Date: Thu, 12 Dec 2024 23:20:49 +0530 Subject: [PATCH 15/21] handle miscellaneous properties --- .../HTTPConnectionRepresentation.java | 40 ++++++++++++++- .../HTTPConnectionRepresentationTest.java | 51 +++++++++++++++++++ 2 files changed, 90 insertions(+), 1 deletion(-) diff --git a/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java b/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java index b8359076bc..cd35d5f3fa 100644 --- a/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java +++ b/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java @@ -6,7 +6,9 @@ import org.apache.axiom.om.impl.llom.factory.OMLinkedListImplFactory; import org.apache.commons.lang.StringUtils; +import java.util.ArrayList; import java.util.Iterator; +import java.util.List; public class HTTPConnectionRepresentation { @@ -40,6 +42,9 @@ public class HTTPConnectionRepresentation { private String trace; private String statistics; + private String miscellaneousDescription; + private String miscellaneousProperties; + public HTTPConnectionRepresentation(OMElement inputOMElement) { // Parse input OMElement and populate the attributes Iterator children = inputOMElement.getChildElements(); @@ -132,6 +137,12 @@ public HTTPConnectionRepresentation(OMElement inputOMElement) { case "statistics": this.statistics = child.getText(); break; + case "miscellaneousDescription": + this.miscellaneousDescription = child.getText(); + break; + case "miscellaneousProperties": + this.miscellaneousProperties = child.getText(); + break; default: // Ignore unknown elements } @@ -243,8 +254,18 @@ public OMElement generateEndpointOMElement() { } } } - endpoint.addChild(http); + if (StringUtils.isNotEmpty(miscellaneousProperties)) { + List miscellaneousProperties = generateMiscellaneousPropertiesElement(factory, synapseNS); + for (OMElement property : miscellaneousProperties) { + endpoint.addChild(property); + } + } + if (StringUtils.isNotEmpty(miscellaneousDescription)) { + OMElement description = factory.createOMElement("description", synapseNS); + description.setText(this.miscellaneousDescription); + endpoint.addChild(description); + } return endpoint; } @@ -378,7 +399,24 @@ private OMElement generateAuthPasswordElement(OMFactory factory, OMNamespace syn return authPassword; } + private List generateMiscellaneousPropertiesElement(OMFactory factory, OMNamespace synapseNS) { + + List miscelleneousProperties = new ArrayList<>(); + for (String miscProperty : this.miscellaneousProperties.split(",")) { + String[] keyScopeValue = miscProperty.split(":"); + if (keyScopeValue.length == 3) { + OMElement property = factory.createOMElement("property", synapseNS); + property.addAttribute("name", keyScopeValue[0].trim(), null); + property.addAttribute("scope", keyScopeValue[1].trim(), null); + property.addAttribute("value", keyScopeValue[2].trim(), null); + miscelleneousProperties.add(property); + } + } + return miscelleneousProperties; + } + private OMElement generateOAuthAdditionalPropertiesElement(OMFactory factory, OMNamespace synapseNS) { + OMElement additionalProperties = factory.createOMElement("requestParameters", synapseNS); for (String additionalProperty : this.oauthAdditionalProperties.split(",")) { String[] keyValue = additionalProperty.split(":"); diff --git a/modules/core/src/test/java/org/apache/synapse/deployers/HTTPConnectionRepresentationTest.java b/modules/core/src/test/java/org/apache/synapse/deployers/HTTPConnectionRepresentationTest.java index 8acdf145f3..1de48e3884 100644 --- a/modules/core/src/test/java/org/apache/synapse/deployers/HTTPConnectionRepresentationTest.java +++ b/modules/core/src/test/java/org/apache/synapse/deployers/HTTPConnectionRepresentationTest.java @@ -122,6 +122,57 @@ public void testEndpointOMElementGenerationWithStatistics() throws XMLStreamExce Assert.assertEquals(expectedEndpointOMElementString, generatedEndpointOMElement.toString()); } + @Test + public void testEndpointOMElementGenerationWithMiscellaneousDescription() throws XMLStreamException { + + String omElementString = + "\n" + + " http\n" + + " library\n" + + " http://jsonplaceholder.typicode.com/posts\n" + + " enable\n" + + " hello world\n" + + ""; + String expectedEndpointOMElementString = + "" + + "" + + "hello world" + + ""; + InputStream inputStream = new ByteArrayInputStream(omElementString.getBytes(StandardCharsets.UTF_8)); + OMElement documentElement = + new StAXOMBuilder(StAXUtils.createXMLStreamReader(inputStream)).getDocumentElement(); + HTTPConnectionRepresentation httpConnectionRepresentation = new HTTPConnectionRepresentation(documentElement); + OMElement generatedEndpointOMElement = httpConnectionRepresentation.generateEndpointOMElement(); + Assert.assertEquals(expectedEndpointOMElementString, generatedEndpointOMElement.toString()); + } + + @Test + public void testEndpointOMElementGenerationWithMiscellaneousProperties() throws XMLStreamException { + + String omElementString = + "\n" + + " http\n" + + " library\n" + + " http://jsonplaceholder.typicode.com/posts\n" + + " enable\n" + + " hello world\n" + + " name1:scope1:value1,name2:scope2:value2,\n" + + ""; + String expectedEndpointOMElementString = + "" + + "" + + "" + + "" + + "hello world" + + ""; + InputStream inputStream = new ByteArrayInputStream(omElementString.getBytes(StandardCharsets.UTF_8)); + OMElement documentElement = + new StAXOMBuilder(StAXUtils.createXMLStreamReader(inputStream)).getDocumentElement(); + HTTPConnectionRepresentation httpConnectionRepresentation = new HTTPConnectionRepresentation(documentElement); + OMElement generatedEndpointOMElement = httpConnectionRepresentation.generateEndpointOMElement(); + Assert.assertEquals(expectedEndpointOMElementString, generatedEndpointOMElement.toString()); + } + @Test public void testEndpointOMElementGenerationWithTimeoutActionNever() throws XMLStreamException { From 4a93a85210c5c25f5428797ace5cc1acb40717d8 Mon Sep 17 00:00:00 2001 From: chathurangaj Date: Thu, 12 Dec 2024 23:33:48 +0530 Subject: [PATCH 16/21] handle quality of service addressing properties --- .../HTTPConnectionRepresentation.java | 25 +++++++++++++++++ .../HTTPConnectionRepresentationTest.java | 27 +++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java b/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java index cd35d5f3fa..bf2647d900 100644 --- a/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java +++ b/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java @@ -45,6 +45,10 @@ public class HTTPConnectionRepresentation { private String miscellaneousDescription; private String miscellaneousProperties; + private String qualityServiceAddressOption; + private String qualityServiceAddressVersion; + private String qualityServiceAddressSeparateListener; + public HTTPConnectionRepresentation(OMElement inputOMElement) { // Parse input OMElement and populate the attributes Iterator children = inputOMElement.getChildElements(); @@ -143,6 +147,15 @@ public HTTPConnectionRepresentation(OMElement inputOMElement) { case "miscellaneousProperties": this.miscellaneousProperties = child.getText(); break; + case "qualityServiceAddressOption": + this.qualityServiceAddressOption = child.getText(); + break; + case "qualityServiceAddressVersion": + this.qualityServiceAddressVersion = child.getText(); + break; + case "qualityServiceAddressSeparateListener": + this.qualityServiceAddressSeparateListener = child.getText(); + break; default: // Ignore unknown elements } @@ -165,6 +178,18 @@ public OMElement generateEndpointOMElement() { } http.addAttribute("uri-template", "{uri.var.base}{+uri.var.path}{+uri.var.query}", null); + if (StringUtils.isNotEmpty(this.qualityServiceAddressOption) && this.qualityServiceAddressOption.equalsIgnoreCase("enable")) { + OMElement enableAddressing = factory.createOMElement("enableAddressing", synapseNS); + if (StringUtils.isNotEmpty(this.qualityServiceAddressSeparateListener) && + this.qualityServiceAddressSeparateListener.equalsIgnoreCase("enable")) { + enableAddressing.addAttribute("separateListener", "true", null); + } + if (StringUtils.isNotEmpty(this.qualityServiceAddressVersion)) { + enableAddressing.addAttribute("version", this.qualityServiceAddressVersion, null); + } + http.addChild(enableAddressing); + } + if (StringUtils.isNotEmpty(this.timeoutDuration) || StringUtils.isNotEmpty(this.timeoutAction)) { OMElement timeout = factory.createOMElement("timeout", synapseNS); if (StringUtils.isNotEmpty(this.timeoutDuration)) { diff --git a/modules/core/src/test/java/org/apache/synapse/deployers/HTTPConnectionRepresentationTest.java b/modules/core/src/test/java/org/apache/synapse/deployers/HTTPConnectionRepresentationTest.java index 1de48e3884..7a3846f255 100644 --- a/modules/core/src/test/java/org/apache/synapse/deployers/HTTPConnectionRepresentationTest.java +++ b/modules/core/src/test/java/org/apache/synapse/deployers/HTTPConnectionRepresentationTest.java @@ -173,6 +173,33 @@ public void testEndpointOMElementGenerationWithMiscellaneousProperties() throws Assert.assertEquals(expectedEndpointOMElementString, generatedEndpointOMElement.toString()); } + @Test + public void testEndpointOMElementGenerationWithQualityOfServiceAddressing() throws XMLStreamException { + + String omElementString = + "\n" + + " http\n" + + " library\n" + + " http://jsonplaceholder.typicode.com/posts\n" + + " enable\n" + + " enable\n" + + " final\n" + + " enable\n" + + ""; + String expectedEndpointOMElementString = + "" + + "" + + "" + + "" + + ""; + InputStream inputStream = new ByteArrayInputStream(omElementString.getBytes(StandardCharsets.UTF_8)); + OMElement documentElement = + new StAXOMBuilder(StAXUtils.createXMLStreamReader(inputStream)).getDocumentElement(); + HTTPConnectionRepresentation httpConnectionRepresentation = new HTTPConnectionRepresentation(documentElement); + OMElement generatedEndpointOMElement = httpConnectionRepresentation.generateEndpointOMElement(); + Assert.assertEquals(expectedEndpointOMElementString, generatedEndpointOMElement.toString()); + } + @Test public void testEndpointOMElementGenerationWithTimeoutActionNever() throws XMLStreamException { From e5bb0864182ce362c770c29cfca6b6b4a5e652cb Mon Sep 17 00:00:00 2001 From: chathurangaj Date: Thu, 12 Dec 2024 23:56:18 +0530 Subject: [PATCH 17/21] handle quality of service security --- .../HTTPConnectionRepresentation.java | 39 ++++++++++++ .../HTTPConnectionRepresentationTest.java | 62 +++++++++++++++++++ 2 files changed, 101 insertions(+) diff --git a/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java b/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java index bf2647d900..5226a92c7c 100644 --- a/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java +++ b/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java @@ -49,6 +49,12 @@ public class HTTPConnectionRepresentation { private String qualityServiceAddressVersion; private String qualityServiceAddressSeparateListener; + private String qualityServiceSecurityOption; + private String qualityServiceSecurityInboundOutboundPolicyOption; + private String qualityServiceSecurityPolicyKey; + private String qualityServiceSecurityInboundPolicyKey; + private String qualityServiceSecurityOutboundPolicyKey; + public HTTPConnectionRepresentation(OMElement inputOMElement) { // Parse input OMElement and populate the attributes Iterator children = inputOMElement.getChildElements(); @@ -156,6 +162,21 @@ public HTTPConnectionRepresentation(OMElement inputOMElement) { case "qualityServiceAddressSeparateListener": this.qualityServiceAddressSeparateListener = child.getText(); break; + case "qualityServiceSecurityOption": + this.qualityServiceSecurityOption = child.getText(); + break; + case "qualityServiceSecurityInboundOutboundPolicyOption": + this.qualityServiceSecurityInboundOutboundPolicyOption = child.getText(); + break; + case "qualityServiceSecurityPolicyKey": + this.qualityServiceSecurityPolicyKey = child.getText(); + break; + case "qualityServiceSecurityInboundPolicyKey": + this.qualityServiceSecurityInboundPolicyKey = child.getText(); + break; + case "qualityServiceSecurityOutboundPolicyKey": + this.qualityServiceSecurityOutboundPolicyKey = child.getText(); + break; default: // Ignore unknown elements } @@ -190,6 +211,24 @@ public OMElement generateEndpointOMElement() { http.addChild(enableAddressing); } + if (StringUtils.isNotEmpty(this.qualityServiceSecurityOption) && this.qualityServiceSecurityOption.equalsIgnoreCase("enable")) { + OMElement enableSecurity = factory.createOMElement("enableSec", synapseNS); + if (StringUtils.isNotEmpty(this.qualityServiceSecurityInboundOutboundPolicyOption) && + this.qualityServiceSecurityInboundOutboundPolicyOption.equalsIgnoreCase("enable")) { + if (StringUtils.isNotEmpty(this.qualityServiceSecurityInboundPolicyKey)) { + enableSecurity.addAttribute("inboundPolicy", this.qualityServiceSecurityInboundPolicyKey, null); + } + if (StringUtils.isNotEmpty(this.qualityServiceSecurityOutboundPolicyKey)) { + enableSecurity.addAttribute("outboundPolicy", this.qualityServiceSecurityOutboundPolicyKey, null); + } + } else { + if (StringUtils.isNotEmpty(this.qualityServiceSecurityPolicyKey)) { + enableSecurity.addAttribute("policy", this.qualityServiceSecurityPolicyKey, null); + } + } + http.addChild(enableSecurity); + } + if (StringUtils.isNotEmpty(this.timeoutDuration) || StringUtils.isNotEmpty(this.timeoutAction)) { OMElement timeout = factory.createOMElement("timeout", synapseNS); if (StringUtils.isNotEmpty(this.timeoutDuration)) { diff --git a/modules/core/src/test/java/org/apache/synapse/deployers/HTTPConnectionRepresentationTest.java b/modules/core/src/test/java/org/apache/synapse/deployers/HTTPConnectionRepresentationTest.java index 7a3846f255..c56182e9af 100644 --- a/modules/core/src/test/java/org/apache/synapse/deployers/HTTPConnectionRepresentationTest.java +++ b/modules/core/src/test/java/org/apache/synapse/deployers/HTTPConnectionRepresentationTest.java @@ -200,6 +200,68 @@ public void testEndpointOMElementGenerationWithQualityOfServiceAddressing() thro Assert.assertEquals(expectedEndpointOMElementString, generatedEndpointOMElement.toString()); } + @Test + public void testEndpointOMElementGenerationWithQualityOfServiceSecurityPolicy() throws XMLStreamException { + + String omElementString = + "\n" + + " http\n" + + " library\n" + + " http://jsonplaceholder.typicode.com/posts\n" + + " enable\n" + + " enable\n" + + " final\n" + + " enable\n" + + " enable\n" + + " samplePolicy\n" + + ""; + String expectedEndpointOMElementString = + "" + + "" + + "" + + "" + + "" + + ""; + InputStream inputStream = new ByteArrayInputStream(omElementString.getBytes(StandardCharsets.UTF_8)); + OMElement documentElement = + new StAXOMBuilder(StAXUtils.createXMLStreamReader(inputStream)).getDocumentElement(); + HTTPConnectionRepresentation httpConnectionRepresentation = new HTTPConnectionRepresentation(documentElement); + OMElement generatedEndpointOMElement = httpConnectionRepresentation.generateEndpointOMElement(); + Assert.assertEquals(expectedEndpointOMElementString, generatedEndpointOMElement.toString()); + } + + @Test + public void testEndpointOMElementGenerationWithQualityOfServiceSecurityInboundOutboundPolicy() throws XMLStreamException { + + String omElementString = + "\n" + + " http\n" + + " library\n" + + " http://jsonplaceholder.typicode.com/posts\n" + + " enable\n" + + " enable\n" + + " final\n" + + " enable\n" + + " enable\n" + + " enable\n" + + " sampleInboundPolicy\n" + + " sampleOutboundPolicy\n" + + ""; + String expectedEndpointOMElementString = + "" + + "" + + "" + + "" + + "" + + ""; + InputStream inputStream = new ByteArrayInputStream(omElementString.getBytes(StandardCharsets.UTF_8)); + OMElement documentElement = + new StAXOMBuilder(StAXUtils.createXMLStreamReader(inputStream)).getDocumentElement(); + HTTPConnectionRepresentation httpConnectionRepresentation = new HTTPConnectionRepresentation(documentElement); + OMElement generatedEndpointOMElement = httpConnectionRepresentation.generateEndpointOMElement(); + Assert.assertEquals(expectedEndpointOMElementString, generatedEndpointOMElement.toString()); + } + @Test public void testEndpointOMElementGenerationWithTimeoutActionNever() throws XMLStreamException { From d3e546973b104051c3cd60f2f5a7a429b05cf87b Mon Sep 17 00:00:00 2001 From: chathurangaj Date: Thu, 12 Dec 2024 23:58:50 +0530 Subject: [PATCH 18/21] add license headers --- .../apache/synapse/deployers/Constant.java | 18 +++++++++++++++++ .../HTTPConnectionRepresentation.java | 20 ++++++++++++++++++- .../HTTPConnectionRepresentationTest.java | 18 +++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/modules/core/src/main/java/org/apache/synapse/deployers/Constant.java b/modules/core/src/main/java/org/apache/synapse/deployers/Constant.java index 3f4780e6fc..4171757959 100644 --- a/modules/core/src/main/java/org/apache/synapse/deployers/Constant.java +++ b/modules/core/src/main/java/org/apache/synapse/deployers/Constant.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (https://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.apache.synapse.deployers; public class Constant { diff --git a/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java b/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java index 5226a92c7c..6268b43fbd 100644 --- a/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java +++ b/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (https://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.apache.synapse.deployers; import org.apache.axiom.om.OMElement; @@ -56,7 +74,7 @@ public class HTTPConnectionRepresentation { private String qualityServiceSecurityOutboundPolicyKey; public HTTPConnectionRepresentation(OMElement inputOMElement) { - // Parse input OMElement and populate the attributes + Iterator children = inputOMElement.getChildElements(); while (children.hasNext()) { OMElement child = (OMElement) children.next(); diff --git a/modules/core/src/test/java/org/apache/synapse/deployers/HTTPConnectionRepresentationTest.java b/modules/core/src/test/java/org/apache/synapse/deployers/HTTPConnectionRepresentationTest.java index c56182e9af..6e23a68c08 100644 --- a/modules/core/src/test/java/org/apache/synapse/deployers/HTTPConnectionRepresentationTest.java +++ b/modules/core/src/test/java/org/apache/synapse/deployers/HTTPConnectionRepresentationTest.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (https://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.apache.synapse.deployers; import org.apache.axiom.om.OMElement; From ef602e9476eb77b403e12dedf57e298e31199765 Mon Sep 17 00:00:00 2001 From: chathurangaj Date: Fri, 13 Dec 2024 02:26:30 +0530 Subject: [PATCH 19/21] update log/error messages --- .../synapse/deployers/LocalEntryDeployer.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/core/src/main/java/org/apache/synapse/deployers/LocalEntryDeployer.java b/modules/core/src/main/java/org/apache/synapse/deployers/LocalEntryDeployer.java index 124e174fc9..0fde2e77c7 100644 --- a/modules/core/src/main/java/org/apache/synapse/deployers/LocalEntryDeployer.java +++ b/modules/core/src/main/java/org/apache/synapse/deployers/LocalEntryDeployer.java @@ -111,8 +111,8 @@ private void deployEndpointsForHTTPConnection(OMElement artifactConfig, String f artifactConfig.getFirstChildWithName( new QName(SynapseConstants.SYNAPSE_NAMESPACE, HTTP_CONNECTION_IDENTIFIER)); if (httpInitElement != null) { - OMElement documentElement = generateHTTPEndpointOMElement(httpInitElement); - deployHTTPEndpointForElement(documentElement, fileName, properties); + OMElement generatedEndpointElement = generateHTTPEndpointOMElement(httpInitElement); + deployHTTPEndpointForElement(generatedEndpointElement, fileName, properties); } } @@ -127,7 +127,7 @@ private void deployHTTPEndpointForElement(OMElement documentElement, String file ep.setFileName((new File(fileName)).getName()); if (log.isDebugEnabled()) { log.debug("Endpoint named '" + ep.getName() - + "' has been built from the file " + fileName); + + "' has been built from the http connection file " + fileName); } ep.init(getSynapseEnvironment()); if (log.isDebugEnabled()) { @@ -135,16 +135,16 @@ private void deployHTTPEndpointForElement(OMElement documentElement, String file } getSynapseConfiguration().addEndpoint(ep.getName(), ep); if (log.isDebugEnabled()) { - log.debug("Endpoint Deployment from file : " + fileName + " : Completed"); + log.debug("Endpoint Deployment from the http connection file : " + fileName + " : Completed"); } log.info("Endpoint named '" + ep.getName() - + "' has been deployed from file : " + fileName); + + "' has been deployed from the http connection file : " + fileName); } else { handleSynapseArtifactDeploymentError("Endpoint Deployment Failed. The artifact " + - "described in the file " + fileName + " is not an Endpoint"); + "described in the http connection file " + fileName + " has filed to describe an Endpoint"); } } catch (Exception e) { - handleSynapseArtifactDeploymentError("Endpoint Deployment from the file : " + handleSynapseArtifactDeploymentError("Endpoint Deployment from the http connection file : " + fileName + " : Failed.", e); } } From 6858d759bf51a4fb1278209b15b910d974d75e1c Mon Sep 17 00:00:00 2001 From: chathurangaj Date: Fri, 13 Dec 2024 10:29:37 +0530 Subject: [PATCH 20/21] introduce constants to handle endpoint deployment from http connection --- .../org/apache/synapse/SynapseConstants.java | 97 +++++++++ .../apache/synapse/deployers/Constant.java | 43 ---- .../HTTPConnectionRepresentation.java | 199 +++++++++--------- 3 files changed, 197 insertions(+), 142 deletions(-) delete mode 100644 modules/core/src/main/java/org/apache/synapse/deployers/Constant.java diff --git a/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java b/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java index edcdbeb1b0..b627b4a239 100644 --- a/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java +++ b/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java @@ -626,6 +626,103 @@ public enum ENDPOINT_TIMEOUT_TYPE { ENDPOINT_TIMEOUT, GLOBAL_TIMEOUT, HTTP_CONNE public static final String ANALYTICS_METADATA = "ANALYTICS_METADATA"; + // Constants for the HTTP Connection + public static final String ENDPOINT_IDENTIFIER = "INTERNAL_ENDPOINT_REFERENCE"; + public static final String BASIC_AUTH = "Basic Auth"; + public static final String OAUTH = "OAuth"; + public static final String OAUTH_GRANT_TYPE_AUTHORIZATION_CODE = "Authorization Code"; + public static final String OAUTH_GRANT_TYPE_CLIENT_CREDENTIALS = "Client Credentials"; + public static final String OAUTH_GRANT_TYPE_PASSWORD = "Password"; + + public static final String NAME = "name"; + public static final String BASE_URL = "baseUrl"; + public static final String CONNECTION_TYPE = "connectionType"; + public static final String CERTIFICATE_TYPE = "certificateType"; + public static final String AUTH_TYPE = "authType"; + public static final String OAUTH_AUTHORIZATION_MODE = "oauthAuthorizationMode"; + public static final String OAUTH_GRANT_TYPE = "oauthGrantType"; + public static final String BASIC_CREDENTIALS_USERNAME = "basicCredentialsUsername"; + public static final String BASIC_CREDENTIALS_PASSWORD = "basicCredentialsPassword"; + public static final String OAUTH_PASSWORD_GRANT_USERNAME = "oauthPasswordUsername"; + public static final String OAUTH_PASSWORD_GRANT_PASSWORD = "oauthPasswordPassword"; + public static final String OAUTH_PASSWORD_GRANT_CLIENT_ID = "oauthPasswordClientId"; + public static final String OAUTH_PASSWORD_GRANT_CLIENT_SECRET = "oauthPasswordClientSecret"; + public static final String OAUTH_PASSWORD_GRANT_TOKEN_URL = "oauthPasswordTokenUrl"; + public static final String OAUTH_PASSWORD_GRANT_ADDITIONAL_PROPERTIES = "oauthPasswordAdditionalProperties"; + + public static final String OAUTH_CLIENT_CREDENTIALS_GRANT_CLIENT_ID = "oauthClientClientId"; + public static final String OAUTH_CLIENT_CREDENTIALS_GRANT_CLIENT_SECRET = "oauthClientClientSecret"; + public static final String OAUTH_CLIENT_CREDENTIALS_GRANT_TOKEN_URL = "oauthClientTokenUrl"; + public static final String OAUTH_CLIENT_CREDENTIALS_GRANT_ADDITIONAL_PROPERTIES = "oauthClientAdditionalProperties"; + + public static final String OAUTH_AUTHORIZATION_GRANT_CLIENT_SECRET = "oauthAuthorizationClientSecret"; + public static final String OAUTH_AUTHORIZATION_GRANT_CLIENT_ID = "oauthAuthorizationClientId"; + public static final String OAUTH_AUTHORIZATION_GRANT_TOKEN_URL = "oauthAuthorizationTokenUrl"; + public static final String OAUTH_AUTHORIZATION_GRANT_REFRESH_TOKEN = "oauthAuthorizationRefreshToken"; + public static final String OAUTH_AUTHORIZATION_GRANT_ADDITIONAL_PROPERTIES = "oauthAuthorizationAdditionalProperties"; + + public static final String OAUTH_CLIENT_ID = "oauthClientId"; + public static final String TIMEOUT_DURATION = "timeoutDuration"; + public static final String TIMEOUT_ACTION = "timeoutAction"; + public static final String SUSPEND_ERROR_CODES = "suspendErrorCodes"; + public static final String SUSPEND_INITIAL_DURATION = "suspendInitialDuration"; + public static final String SUSPEND_MAXIMUM_DURATION = "suspendMaximumDuration"; + public static final String SUSPEND_PROGRESSION_FACTOR = "suspendProgressionFactor"; + public static final String RETRY_ERROR_CODES = "retryErrorCodes"; + public static final String RETRY_COUNT = "retryCount"; + public static final String RETRY_DELAY = "retryDelay"; + + public static final String TRACE = "trace"; + public static final String STATISTICS = "statistics"; + public static final String MISCELLANEOUS_DESCRIPTION = "miscellaneousDescription"; + public static final String MISCELLANEOUS_PROPERTIES = "miscellaneousProperties"; + public static final String QUALITY_OF_SERVICE_ADDRESS_OPTION = "qualityServiceAddressOption"; + public static final String QUALITY_OF_SERVICE_ADDRESS_VERSION = "qualityServiceAddressVersion"; + public static final String QUALITY_OF_SERVICE_ADDRESS_SEPARATE_LISTENER = "qualityServiceAddressSeparateListener"; + + public static final String QUALITY_OF_SERVICE_SECURITY_OPTION = "qualityServiceSecurityOption"; + public static final String QUALITY_OF_SERVICE_SECURITY_INBOUND_OUTBOUND_POLICY_OPTION = "qualityServiceSecurityInboundOutboundPolicyOption"; + public static final String QUALITY_OF_SERVICE_SECURITY_INBOUND_POLICY_KEY = "qualityServiceSecurityInboundPolicyKey"; + public static final String QUALITY_OF_SERVICE_SECURITY_OUTBOUND_POLICY_KEY = "qualityServiceSecurityOutboundPolicyKey"; + public static final String QUALITY_OF_SERVICE_SECURITY_POLICY_KEY = "qualityServiceSecurityPolicyKey"; + + public static final String ENDPOINT = "endpoint"; + public static final String HTTP = "http"; + public static final String ENABLE = "enable"; + public static final String URI_TEMPLATE = "uri-template"; + public static final String ENABLE_ADDRESSING = "enableAddressing"; + public static final String ENABLE_SECURITY = "enableSec"; + public static final String SEPARATE_LISTENER = "separateListener"; + public static final String VERSION = "version"; + public static final String POLICY = "policy"; + public static final String INBOUND_POLICY = "inboundPolicy"; + public static final String OUTBOUND_POLICY = "outboundPolicy"; + public static final String TIMEOUT = "timeout"; + public static final String DURATION = "duration"; + public static final String RESPONSE_ACTION = "responseAction"; + public static final String NEVER = "never"; + public static final String SUSPEND_ON_FAILURE = "suspendOnFailure"; + public static final String ERROR_CODES = "errorCodes"; + public static final String INITIAL_DURATION = "initialDuration"; + public static final String MAXIMUM_DURATION = "maximumDuration"; + public static final String PROGRESSION_FACTOR = "progressionFactor"; + public static final String MARK_FOR_SUSPENSION = "markForSuspension"; + public static final String RETRIES_BEFORE_SUSPENSION = "retriesBeforeSuspension"; + public static final String AUTHENTICATION = "authentication"; + public static final String DESCRIPTION = "description"; + public static final String AUTHORIZATION_CODE = "authorizationCode"; + public static final String PASSWORD_CREDENTIALS = "passwordCredentials"; + public static final String CLIENT_CREDENTIALS = "clientCredentials"; + public static final String TOKEN_URL = "tokenUrl"; + public static final String CLIENT_ID = "clientId"; + public static final String CLIENT_SECRET = "clientSecret"; + public static final String USERNAME = "username"; + public static final String PASSWORD = "password"; + public static final String REFRESH_TOKEN = "refreshToken"; + public static final String AUTH_MODE = "authMode"; + public static final String REQUEST_PARAMETERS = "requestParameters"; + public static final String BASIC_AUTH_TAG = "basicAuth"; + public static final String OAUTH_TAG = "oauth"; public static final String SCATTER_MESSAGES = "SCATTER_MESSAGES"; public static final String CONTINUE_FLOW_TRIGGERED_FROM_MEDIATOR_WORKER = "CONTINUE_FLOW_TRIGGERED_FROM_MEDIATOR_WORKER"; } diff --git a/modules/core/src/main/java/org/apache/synapse/deployers/Constant.java b/modules/core/src/main/java/org/apache/synapse/deployers/Constant.java deleted file mode 100644 index 4171757959..0000000000 --- a/modules/core/src/main/java/org/apache/synapse/deployers/Constant.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2024, WSO2 LLC. (https://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.apache.synapse.deployers; - -public class Constant { - - // Constants for the HTTP Endpoint - public static final String ENDPOINT_IDENTIFIER = "ep"; - public static final String BASIC_AUTH = "Basic Auth"; - public static final String OAUTH = "OAuth"; - public static final String OAUTH_GRANT_TYPE_AUTHORIZATION_CODE = "Authorization Code"; - public static final String OAUTH_GRANT_TYPE_CLIENT_CREDENTIALS = "Client Credentials"; - public static final String OAUTH_GRANT_TYPE_PASSWORD = "Password"; - - // Constants for the HTTP Connection - public static final String NAME = "name"; - public static final String BASE_URL = "baseUrl"; - public static final String TIMEOUT_DURATION = "timeoutDuration"; - public static final String TIMEOUT_ACTION = "timeoutAction"; - public static final String SUSPEND_ERROR_CODES = "suspendErrorCodes"; - public static final String SUSPEND_INITIAL_DURATION = "suspendInitialDuration"; - public static final String SUSPEND_MAXIMUM_DURATION = "suspendMaximumDuration"; - public static final String SUSPEND_PROGRESSION_FACTOR = "suspendProgressionFactor"; - public static final String RETRY_ERROR_CODES = "retryErrorCodes"; - public static final String RETRY_COUNT = "retryCount"; - public static final String RETRY_DELAY = "retryDelay"; -} diff --git a/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java b/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java index 6268b43fbd..de6c54a03e 100644 --- a/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java +++ b/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java @@ -23,6 +23,7 @@ import org.apache.axiom.om.OMNamespace; import org.apache.axiom.om.impl.llom.factory.OMLinkedListImplFactory; import org.apache.commons.lang.StringUtils; +import org.apache.synapse.SynapseConstants; import java.util.ArrayList; import java.util.Iterator; @@ -79,120 +80,120 @@ public HTTPConnectionRepresentation(OMElement inputOMElement) { while (children.hasNext()) { OMElement child = (OMElement) children.next(); switch (child.getLocalName()) { - case "connectionType": + case SynapseConstants.CONNECTION_TYPE: this.connectionType = child.getText(); break; - case "baseUrl": + case SynapseConstants.BASE_URL: this.baseUrl = child.getText(); break; - case "certificateType": + case SynapseConstants.CERTIFICATE_TYPE: this.certificateType = child.getText(); break; - case "authType": + case SynapseConstants.AUTH_TYPE: this.authType = child.getText(); break; - case "basicCredentialsUsername": - case "oauthPasswordUsername": + case SynapseConstants.BASIC_CREDENTIALS_USERNAME: + case SynapseConstants.OAUTH_PASSWORD_GRANT_USERNAME: this.username = child.getText(); break; - case "basicCredentialsPassword": - case "oauthPasswordPassword": + case SynapseConstants.BASIC_CREDENTIALS_PASSWORD: + case SynapseConstants.OAUTH_PASSWORD_GRANT_PASSWORD: this.password = child.getText(); break; - case "oauthAuthorizationMode": + case SynapseConstants.OAUTH_AUTHORIZATION_MODE: this.oauthAuthorizationMode = child.getText(); break; - case "oauthGrantType": + case SynapseConstants.OAUTH_GRANT_TYPE: this.oauthGrantType = child.getText(); break; - case "oauthAuthorizationClientId": - case "oauthClientClientId": - case "oauthPasswordClientId": + case SynapseConstants.OAUTH_AUTHORIZATION_GRANT_CLIENT_ID: + case SynapseConstants.OAUTH_CLIENT_CREDENTIALS_GRANT_CLIENT_ID: + case SynapseConstants.OAUTH_PASSWORD_GRANT_CLIENT_ID: this.clientId = child.getText(); break; - case "oauthAuthorizationClientSecret": - case "oauthClientClientSecret": - case "oauthPasswordClientSecret": + case SynapseConstants.OAUTH_AUTHORIZATION_GRANT_CLIENT_SECRET: + case SynapseConstants.OAUTH_CLIENT_CREDENTIALS_GRANT_CLIENT_SECRET: + case SynapseConstants.OAUTH_PASSWORD_GRANT_CLIENT_SECRET: this.clientSecret = child.getText(); break; - case "oauthAuthorizationTokenUrl": - case "oauthClientTokenUrl": - case "oauthPasswordTokenUrl": + case SynapseConstants.OAUTH_AUTHORIZATION_GRANT_TOKEN_URL: + case SynapseConstants.OAUTH_CLIENT_CREDENTIALS_GRANT_TOKEN_URL: + case SynapseConstants.OAUTH_PASSWORD_GRANT_TOKEN_URL: this.tokenUrl = child.getText(); break; - case "oauthAuthorizationRefreshToken": + case SynapseConstants.OAUTH_AUTHORIZATION_GRANT_REFRESH_TOKEN: this.refreshToken = child.getText(); break; - case "oauthAuthorizationAdditionalProperties": - case "oauthClientAdditionalProperties": - case "oauthPasswordAdditionalProperties": + case SynapseConstants.OAUTH_AUTHORIZATION_GRANT_ADDITIONAL_PROPERTIES: + case SynapseConstants.OAUTH_CLIENT_CREDENTIALS_GRANT_ADDITIONAL_PROPERTIES: + case SynapseConstants.OAUTH_PASSWORD_GRANT_ADDITIONAL_PROPERTIES: this.oauthAdditionalProperties = child.getText(); break; - case "timeoutDuration": + case SynapseConstants.TIMEOUT_DURATION: this.timeoutDuration = child.getText(); break; - case "timeoutAction": + case SynapseConstants.TIMEOUT_ACTION: this.timeoutAction = child.getText(); break; - case "suspendErrorCodes": + case SynapseConstants.SUSPEND_ERROR_CODES: this.suspendErrorCodes = child.getText(); break; - case "suspendInitialDuration": + case SynapseConstants.SUSPEND_INITIAL_DURATION: this.suspendInitialDuration = child.getText(); break; - case "suspendMaximumDuration": + case SynapseConstants.SUSPEND_MAXIMUM_DURATION: this.suspendMaximumDuration = child.getText(); break; - case "suspendProgressionFactor": + case SynapseConstants.SUSPEND_PROGRESSION_FACTOR: this.suspendProgressionFactor = child.getText(); break; - case "retryErrorCodes": + case SynapseConstants.RETRY_ERROR_CODES: this.retryErrorCodes = child.getText(); break; - case "retryCount": + case SynapseConstants.RETRY_COUNT: this.retryCount = child.getText(); break; - case "retryDelay": + case SynapseConstants.RETRY_DELAY: this.retryDelay = child.getText(); break; - case "name": + case SynapseConstants.NAME: this.name = child.getText(); - this.endpointName = child.getText() + Constant.ENDPOINT_IDENTIFIER; + this.endpointName = child.getText() + SynapseConstants.ENDPOINT_IDENTIFIER; break; - case "trace": + case SynapseConstants.TRACE: this.trace = child.getText(); break; - case "statistics": + case SynapseConstants.STATISTICS: this.statistics = child.getText(); break; - case "miscellaneousDescription": + case SynapseConstants.MISCELLANEOUS_DESCRIPTION: this.miscellaneousDescription = child.getText(); break; - case "miscellaneousProperties": + case SynapseConstants.MISCELLANEOUS_PROPERTIES: this.miscellaneousProperties = child.getText(); break; - case "qualityServiceAddressOption": + case SynapseConstants.QUALITY_OF_SERVICE_ADDRESS_OPTION: this.qualityServiceAddressOption = child.getText(); break; - case "qualityServiceAddressVersion": + case SynapseConstants.QUALITY_OF_SERVICE_ADDRESS_VERSION: this.qualityServiceAddressVersion = child.getText(); break; - case "qualityServiceAddressSeparateListener": + case SynapseConstants.QUALITY_OF_SERVICE_ADDRESS_SEPARATE_LISTENER: this.qualityServiceAddressSeparateListener = child.getText(); break; - case "qualityServiceSecurityOption": + case SynapseConstants.QUALITY_OF_SERVICE_SECURITY_OPTION: this.qualityServiceSecurityOption = child.getText(); break; - case "qualityServiceSecurityInboundOutboundPolicyOption": + case SynapseConstants.QUALITY_OF_SERVICE_SECURITY_INBOUND_OUTBOUND_POLICY_OPTION: this.qualityServiceSecurityInboundOutboundPolicyOption = child.getText(); break; - case "qualityServiceSecurityPolicyKey": + case SynapseConstants.QUALITY_OF_SERVICE_SECURITY_POLICY_KEY: this.qualityServiceSecurityPolicyKey = child.getText(); break; - case "qualityServiceSecurityInboundPolicyKey": + case SynapseConstants.QUALITY_OF_SERVICE_SECURITY_INBOUND_POLICY_KEY: this.qualityServiceSecurityInboundPolicyKey = child.getText(); break; - case "qualityServiceSecurityOutboundPolicyKey": + case SynapseConstants.QUALITY_OF_SERVICE_SECURITY_OUTBOUND_POLICY_KEY: this.qualityServiceSecurityOutboundPolicyKey = child.getText(); break; default: @@ -205,57 +206,57 @@ public OMElement generateEndpointOMElement() { OMFactory factory = new OMLinkedListImplFactory(); OMNamespace synapseNS = factory.createOMNamespace("http://ws.apache.org/ns/synapse", ""); - OMElement endpoint = factory.createOMElement("endpoint", synapseNS); - endpoint.addAttribute("name", endpointName, null); + OMElement endpoint = factory.createOMElement(SynapseConstants.ENDPOINT, synapseNS); + endpoint.addAttribute(SynapseConstants.NAME, endpointName, null); - OMElement http = factory.createOMElement("http", synapseNS); - if (StringUtils.isNotEmpty(this.trace) && this.trace.equalsIgnoreCase("enable")) { - http.addAttribute("trace", "enable", null); + OMElement http = factory.createOMElement(SynapseConstants.HTTP, synapseNS); + if (StringUtils.isNotEmpty(this.trace) && this.trace.equalsIgnoreCase(SynapseConstants.ENABLE)) { + http.addAttribute(SynapseConstants.TRACE, SynapseConstants.ENABLE, null); } - if (StringUtils.isNotEmpty(this.statistics) && this.statistics.equalsIgnoreCase("enable")) { - http.addAttribute("statistics", "enable", null); + if (StringUtils.isNotEmpty(this.statistics) && this.statistics.equalsIgnoreCase(SynapseConstants.ENABLE)) { + http.addAttribute(SynapseConstants.STATISTICS, SynapseConstants.ENABLE, null); } - http.addAttribute("uri-template", "{uri.var.base}{+uri.var.path}{+uri.var.query}", null); + http.addAttribute(SynapseConstants.URI_TEMPLATE, "{uri.var.base}{+uri.var.path}{+uri.var.query}", null); - if (StringUtils.isNotEmpty(this.qualityServiceAddressOption) && this.qualityServiceAddressOption.equalsIgnoreCase("enable")) { - OMElement enableAddressing = factory.createOMElement("enableAddressing", synapseNS); + if (StringUtils.isNotEmpty(this.qualityServiceAddressOption) && this.qualityServiceAddressOption.equalsIgnoreCase(SynapseConstants.ENABLE)) { + OMElement enableAddressing = factory.createOMElement(SynapseConstants.ENABLE_ADDRESSING, synapseNS); if (StringUtils.isNotEmpty(this.qualityServiceAddressSeparateListener) && - this.qualityServiceAddressSeparateListener.equalsIgnoreCase("enable")) { - enableAddressing.addAttribute("separateListener", "true", null); + this.qualityServiceAddressSeparateListener.equalsIgnoreCase(SynapseConstants.ENABLE)) { + enableAddressing.addAttribute(SynapseConstants.SEPARATE_LISTENER, "true", null); } if (StringUtils.isNotEmpty(this.qualityServiceAddressVersion)) { - enableAddressing.addAttribute("version", this.qualityServiceAddressVersion, null); + enableAddressing.addAttribute(SynapseConstants.VERSION, this.qualityServiceAddressVersion, null); } http.addChild(enableAddressing); } - if (StringUtils.isNotEmpty(this.qualityServiceSecurityOption) && this.qualityServiceSecurityOption.equalsIgnoreCase("enable")) { - OMElement enableSecurity = factory.createOMElement("enableSec", synapseNS); + if (StringUtils.isNotEmpty(this.qualityServiceSecurityOption) && this.qualityServiceSecurityOption.equalsIgnoreCase(SynapseConstants.ENABLE)) { + OMElement enableSecurity = factory.createOMElement(SynapseConstants.ENABLE_SECURITY, synapseNS); if (StringUtils.isNotEmpty(this.qualityServiceSecurityInboundOutboundPolicyOption) && - this.qualityServiceSecurityInboundOutboundPolicyOption.equalsIgnoreCase("enable")) { + this.qualityServiceSecurityInboundOutboundPolicyOption.equalsIgnoreCase(SynapseConstants.ENABLE)) { if (StringUtils.isNotEmpty(this.qualityServiceSecurityInboundPolicyKey)) { - enableSecurity.addAttribute("inboundPolicy", this.qualityServiceSecurityInboundPolicyKey, null); + enableSecurity.addAttribute(SynapseConstants.INBOUND_POLICY, this.qualityServiceSecurityInboundPolicyKey, null); } if (StringUtils.isNotEmpty(this.qualityServiceSecurityOutboundPolicyKey)) { - enableSecurity.addAttribute("outboundPolicy", this.qualityServiceSecurityOutboundPolicyKey, null); + enableSecurity.addAttribute(SynapseConstants.OUTBOUND_POLICY, this.qualityServiceSecurityOutboundPolicyKey, null); } } else { if (StringUtils.isNotEmpty(this.qualityServiceSecurityPolicyKey)) { - enableSecurity.addAttribute("policy", this.qualityServiceSecurityPolicyKey, null); + enableSecurity.addAttribute(SynapseConstants.POLICY, this.qualityServiceSecurityPolicyKey, null); } } http.addChild(enableSecurity); } if (StringUtils.isNotEmpty(this.timeoutDuration) || StringUtils.isNotEmpty(this.timeoutAction)) { - OMElement timeout = factory.createOMElement("timeout", synapseNS); + OMElement timeout = factory.createOMElement(SynapseConstants.TIMEOUT, synapseNS); if (StringUtils.isNotEmpty(this.timeoutDuration)) { - OMElement duration = factory.createOMElement("duration", synapseNS); + OMElement duration = factory.createOMElement(SynapseConstants.DURATION, synapseNS); duration.setText(String.valueOf(this.timeoutDuration)); timeout.addChild(duration); } - if (StringUtils.isNotEmpty(this.timeoutAction) && !this.timeoutAction.equalsIgnoreCase("never")) { - OMElement responseAction = factory.createOMElement("responseAction", synapseNS); + if (StringUtils.isNotEmpty(this.timeoutAction) && !this.timeoutAction.equalsIgnoreCase(SynapseConstants.NEVER)) { + OMElement responseAction = factory.createOMElement(SynapseConstants.RESPONSE_ACTION, synapseNS); responseAction.setText(this.timeoutAction); timeout.addChild(responseAction); } @@ -264,24 +265,24 @@ public OMElement generateEndpointOMElement() { if (StringUtils.isNotEmpty(this.suspendErrorCodes) || StringUtils.isNotEmpty(this.suspendInitialDuration) || StringUtils.isNotEmpty(this.suspendProgressionFactor) || StringUtils.isNotEmpty(this.suspendMaximumDuration)) { - OMElement suspendOnFailure = factory.createOMElement("suspendOnFailure", synapseNS); + OMElement suspendOnFailure = factory.createOMElement(SynapseConstants.SUSPEND_ON_FAILURE, synapseNS); if (StringUtils.isNotEmpty(this.suspendErrorCodes)) { - OMElement errorCodes = factory.createOMElement("errorCodes", synapseNS); + OMElement errorCodes = factory.createOMElement(SynapseConstants.ERROR_CODES, synapseNS); errorCodes.setText(this.suspendErrorCodes); suspendOnFailure.addChild(errorCodes); } if (StringUtils.isNotEmpty(this.suspendInitialDuration)) { - OMElement initialDuration = factory.createOMElement("initialDuration", synapseNS); + OMElement initialDuration = factory.createOMElement(SynapseConstants.INITIAL_DURATION, synapseNS); initialDuration.setText(String.valueOf(this.suspendInitialDuration)); suspendOnFailure.addChild(initialDuration); } if (StringUtils.isNotEmpty(this.suspendProgressionFactor)) { - OMElement progressionFactor = factory.createOMElement("progressionFactor", synapseNS); + OMElement progressionFactor = factory.createOMElement(SynapseConstants.PROGRESSION_FACTOR, synapseNS); progressionFactor.setText(String.valueOf(this.suspendProgressionFactor)); suspendOnFailure.addChild(progressionFactor); } if (StringUtils.isNotEmpty(this.suspendMaximumDuration)) { - OMElement maximumDuration = factory.createOMElement("maximumDuration", synapseNS); + OMElement maximumDuration = factory.createOMElement(SynapseConstants.MAXIMUM_DURATION, synapseNS); maximumDuration.setText(String.valueOf(this.suspendMaximumDuration)); suspendOnFailure.addChild(maximumDuration); } @@ -290,19 +291,19 @@ public OMElement generateEndpointOMElement() { if (StringUtils.isNotEmpty(this.retryErrorCodes) || StringUtils.isNotEmpty(this.retryCount) || StringUtils.isNotEmpty(this.retryDelay)) { - OMElement markForSuspension = factory.createOMElement("markForSuspension", synapseNS); + OMElement markForSuspension = factory.createOMElement(SynapseConstants.MARK_FOR_SUSPENSION, synapseNS); if (StringUtils.isNotEmpty(this.retryErrorCodes)) { - OMElement retryErrorCodes = factory.createOMElement("errorCodes", synapseNS); + OMElement retryErrorCodes = factory.createOMElement(SynapseConstants.ERROR_CODES, synapseNS); retryErrorCodes.setText(this.retryErrorCodes); markForSuspension.addChild(retryErrorCodes); } if (StringUtils.isNotEmpty(this.retryCount)) { - OMElement retriesBeforeSuspension = factory.createOMElement("retriesBeforeSuspension", synapseNS); + OMElement retriesBeforeSuspension = factory.createOMElement(SynapseConstants.RETRIES_BEFORE_SUSPENSION, synapseNS); retriesBeforeSuspension.setText(String.valueOf(this.retryCount)); markForSuspension.addChild(retriesBeforeSuspension); } if (StringUtils.isNotEmpty(this.retryDelay)) { - OMElement retryDelay = factory.createOMElement("retryDelay", synapseNS); + OMElement retryDelay = factory.createOMElement(SynapseConstants.RETRY_DELAY, synapseNS); retryDelay.setText(String.valueOf(this.retryDelay)); markForSuspension.addChild(retryDelay); } @@ -310,25 +311,25 @@ public OMElement generateEndpointOMElement() { } if (StringUtils.isNotEmpty(authType)) { - if (authType.equalsIgnoreCase(Constant.BASIC_AUTH)) { - OMElement authentication = factory.createOMElement("authentication", synapseNS); + if (authType.equalsIgnoreCase(SynapseConstants.BASIC_AUTH)) { + OMElement authentication = factory.createOMElement(SynapseConstants.AUTHENTICATION, synapseNS); OMElement basicAuth = generateBasicAuthenticationElement(factory, synapseNS); authentication.addChild(basicAuth); http.addChild(authentication); - } else if (authType.equalsIgnoreCase(Constant.OAUTH)) { - OMElement authentication = factory.createOMElement("authentication", synapseNS); - OMElement oauth = factory.createOMElement("oauth", synapseNS); - if (oauthGrantType.equalsIgnoreCase(Constant.OAUTH_GRANT_TYPE_AUTHORIZATION_CODE)) { + } else if (authType.equalsIgnoreCase(SynapseConstants.OAUTH)) { + OMElement authentication = factory.createOMElement(SynapseConstants.AUTHENTICATION, synapseNS); + OMElement oauth = factory.createOMElement(SynapseConstants.OAUTH_TAG, synapseNS); + if (oauthGrantType.equalsIgnoreCase(SynapseConstants.OAUTH_GRANT_TYPE_AUTHORIZATION_CODE)) { OMElement authorizationCode = generateOAuthAuthorizatonCodeElement(factory, synapseNS); oauth.addChild(authorizationCode); authentication.addChild(oauth); http.addChild(authentication); - } else if (oauthGrantType.equalsIgnoreCase(Constant.OAUTH_GRANT_TYPE_CLIENT_CREDENTIALS)) { + } else if (oauthGrantType.equalsIgnoreCase(SynapseConstants.OAUTH_GRANT_TYPE_CLIENT_CREDENTIALS)) { OMElement clientCredentials = generateOAuthClientCredentialsElement(factory, synapseNS); oauth.addChild(clientCredentials); authentication.addChild(oauth); http.addChild(authentication); - } else if (oauthGrantType.equalsIgnoreCase(Constant.OAUTH_GRANT_TYPE_PASSWORD)) { + } else if (oauthGrantType.equalsIgnoreCase(SynapseConstants.OAUTH_GRANT_TYPE_PASSWORD)) { OMElement passwordCredentials = generateOAuthPasswordCredentialsElement(factory, synapseNS); oauth.addChild(passwordCredentials); authentication.addChild(oauth); @@ -344,7 +345,7 @@ public OMElement generateEndpointOMElement() { } } if (StringUtils.isNotEmpty(miscellaneousDescription)) { - OMElement description = factory.createOMElement("description", synapseNS); + OMElement description = factory.createOMElement(SynapseConstants.DESCRIPTION, synapseNS); description.setText(this.miscellaneousDescription); endpoint.addChild(description); } @@ -353,7 +354,7 @@ public OMElement generateEndpointOMElement() { private OMElement generateOAuthPasswordCredentialsElement(OMFactory factory, OMNamespace synapseNS) { - OMElement passwordCredentials = factory.createOMElement("passwordCredentials", synapseNS); + OMElement passwordCredentials = factory.createOMElement(SynapseConstants.PASSWORD_CREDENTIALS, synapseNS); OMElement username = generateAuthUsernameElement(factory, synapseNS); OMElement password = generateAuthPasswordElement(factory, synapseNS); @@ -378,21 +379,21 @@ private OMElement generateOAuthPasswordCredentialsElement(OMFactory factory, OMN private OMElement generateOAuthTokenUrlElement(OMFactory factory, OMNamespace synapseNS) { - OMElement oauthTokenUrl = factory.createOMElement("tokenUrl", synapseNS); + OMElement oauthTokenUrl = factory.createOMElement(SynapseConstants.TOKEN_URL, synapseNS); oauthTokenUrl.setText(this.tokenUrl); return oauthTokenUrl; } private OMElement generateAuthUsernameElement(OMFactory factory, OMNamespace synapseNS) { - OMElement authUsername = factory.createOMElement("username", synapseNS); + OMElement authUsername = factory.createOMElement(SynapseConstants.USERNAME, synapseNS); authUsername.setText(this.username); return authUsername; } private OMElement generateOAuthClientCredentialsElement(OMFactory factory, OMNamespace synapseNS) { - OMElement clientCredentials = factory.createOMElement("clientCredentials", synapseNS); + OMElement clientCredentials = factory.createOMElement(SynapseConstants.CLIENT_CREDENTIALS, synapseNS); OMElement clientId = generateOAuthClientIDElement(factory, synapseNS); OMElement clientSecret = generateOAuthClientSecretElement(factory, synapseNS); @@ -413,7 +414,7 @@ private OMElement generateOAuthClientCredentialsElement(OMFactory factory, OMNam private OMElement generateOAuthAuthorizatonCodeElement(OMFactory factory, OMNamespace synapseNS) { - OMElement authorizationCode = factory.createOMElement("authorizationCode", synapseNS); + OMElement authorizationCode = factory.createOMElement(SynapseConstants.AUTHORIZATION_CODE, synapseNS); OMElement refreshToken = generateOAuthRefreshTokenElement(factory, synapseNS); OMElement clientId = generateOAuthClientIDElement(factory, synapseNS); @@ -436,35 +437,35 @@ private OMElement generateOAuthAuthorizatonCodeElement(OMFactory factory, OMName private OMElement generateOAuthRefreshTokenElement(OMFactory factory, OMNamespace synapseNS) { - OMElement oauthRefreshToken = factory.createOMElement("refreshToken", synapseNS); + OMElement oauthRefreshToken = factory.createOMElement(SynapseConstants.REFRESH_TOKEN, synapseNS); oauthRefreshToken.setText(this.refreshToken); return oauthRefreshToken; } private OMElement generateOAuthClientSecretElement(OMFactory factory, OMNamespace synapseNS) { - OMElement oauthClientSecret = factory.createOMElement("clientSecret", synapseNS); + OMElement oauthClientSecret = factory.createOMElement(SynapseConstants.CLIENT_SECRET, synapseNS); oauthClientSecret.setText(this.clientSecret); return oauthClientSecret; } private OMElement generateOAuthClientIDElement(OMFactory factory, OMNamespace synapseNS) { - OMElement oauthClientID = factory.createOMElement("clientId", synapseNS); + OMElement oauthClientID = factory.createOMElement(SynapseConstants.CLIENT_ID, synapseNS); oauthClientID.setText(this.clientId); return oauthClientID; } private OMElement generateOAuthAuthorizationModeElement(OMFactory factory, OMNamespace synapseNS) { - OMElement authMode = factory.createOMElement("authMode", synapseNS); + OMElement authMode = factory.createOMElement(SynapseConstants.AUTH_MODE, synapseNS); authMode.setText(this.oauthAuthorizationMode); return authMode; } private OMElement generateBasicAuthenticationElement(OMFactory factory, OMNamespace synapseNS) { - OMElement basicAuth = factory.createOMElement("basicAuth", synapseNS); + OMElement basicAuth = factory.createOMElement(SynapseConstants.BASIC_AUTH_TAG, synapseNS); OMElement username = generateAuthUsernameElement(factory, synapseNS); OMElement password = generateAuthPasswordElement(factory, synapseNS); @@ -476,7 +477,7 @@ private OMElement generateBasicAuthenticationElement(OMFactory factory, OMNamesp private OMElement generateAuthPasswordElement(OMFactory factory, OMNamespace synapseNS) { - OMElement authPassword = factory.createOMElement("password", synapseNS); + OMElement authPassword = factory.createOMElement(SynapseConstants.PASSWORD, synapseNS); authPassword.setText(this.password); return authPassword; } @@ -499,7 +500,7 @@ private List generateMiscellaneousPropertiesElement(OMFactory factory private OMElement generateOAuthAdditionalPropertiesElement(OMFactory factory, OMNamespace synapseNS) { - OMElement additionalProperties = factory.createOMElement("requestParameters", synapseNS); + OMElement additionalProperties = factory.createOMElement(SynapseConstants.REQUEST_PARAMETERS, synapseNS); for (String additionalProperty : this.oauthAdditionalProperties.split(",")) { String[] keyValue = additionalProperty.split(":"); if (keyValue.length == 2) { From 41ee9c787f454958aa5257bffc473dac98785d91 Mon Sep 17 00:00:00 2001 From: chathurangaj Date: Fri, 13 Dec 2024 12:31:02 +0530 Subject: [PATCH 21/21] fix spelling in method name --- .../synapse/deployers/HTTPConnectionRepresentation.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java b/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java index de6c54a03e..6ebd04295e 100644 --- a/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java +++ b/modules/core/src/main/java/org/apache/synapse/deployers/HTTPConnectionRepresentation.java @@ -320,7 +320,7 @@ public OMElement generateEndpointOMElement() { OMElement authentication = factory.createOMElement(SynapseConstants.AUTHENTICATION, synapseNS); OMElement oauth = factory.createOMElement(SynapseConstants.OAUTH_TAG, synapseNS); if (oauthGrantType.equalsIgnoreCase(SynapseConstants.OAUTH_GRANT_TYPE_AUTHORIZATION_CODE)) { - OMElement authorizationCode = generateOAuthAuthorizatonCodeElement(factory, synapseNS); + OMElement authorizationCode = generateOAuthAuthorizationCodeElement(factory, synapseNS); oauth.addChild(authorizationCode); authentication.addChild(oauth); http.addChild(authentication); @@ -412,7 +412,7 @@ private OMElement generateOAuthClientCredentialsElement(OMFactory factory, OMNam return clientCredentials; } - private OMElement generateOAuthAuthorizatonCodeElement(OMFactory factory, OMNamespace synapseNS) { + private OMElement generateOAuthAuthorizationCodeElement(OMFactory factory, OMNamespace synapseNS) { OMElement authorizationCode = factory.createOMElement(SynapseConstants.AUTHORIZATION_CODE, synapseNS);