Skip to content

Commit

Permalink
add documentation comments for HTTPConnectionRepresentation
Browse files Browse the repository at this point in the history
  • Loading branch information
chathuranga-jayanath-99 committed Dec 16, 2024
1 parent 6858d75 commit 969d628
Show file tree
Hide file tree
Showing 2 changed files with 393 additions and 163 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
import java.util.Iterator;
import java.util.List;

/**
* Represents the HTTP connection configuration.
* This class is responsible for parsing an OMElement to extract
* various HTTP connection parameters and generating an OMElement
* representation of an HTTP Endpoint.
*/
public class HTTPConnectionRepresentation {

private String name;
Expand Down Expand Up @@ -74,6 +80,12 @@ public class HTTPConnectionRepresentation {
private String qualityServiceSecurityInboundPolicyKey;
private String qualityServiceSecurityOutboundPolicyKey;

/**
* Constructs an `HTTPConnectionRepresentation` object by parsing the given `OMElement`.
* Extracts HTTP connection parameters from the provided `OMElement`.
*
* @param inputOMElement the `OMElement` containing the HTTP connection configuration
*/
public HTTPConnectionRepresentation(OMElement inputOMElement) {

Iterator<?> children = inputOMElement.getChildElements();
Expand Down Expand Up @@ -202,6 +214,10 @@ public HTTPConnectionRepresentation(OMElement inputOMElement) {
}
}

/**
* Generates an OMElement representation of the HTTP endpoint.
* @return the OMElement representing the HTTP endpoint
*/
public OMElement generateEndpointOMElement() {
OMFactory factory = new OMLinkedListImplFactory();
OMNamespace synapseNS = factory.createOMNamespace("http://ws.apache.org/ns/synapse", "");
Expand Down Expand Up @@ -320,7 +336,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);
Expand Down Expand Up @@ -352,6 +368,15 @@ public OMElement generateEndpointOMElement() {
return endpoint;
}

/**
* Generates an OMElement representing the OAuth password credentials grant type.
* This includes the username, password, client ID, client secret, token URL,
* authorization mode, and any additional properties.
*
* @param factory the OMFactory used to create OMElements
* @param synapseNS the OMNamespace for the Synapse configuration
* @return the OMElement representing the OAuth password credentials grant type
*/
private OMElement generateOAuthPasswordCredentialsElement(OMFactory factory, OMNamespace synapseNS) {

OMElement passwordCredentials = factory.createOMElement(SynapseConstants.PASSWORD_CREDENTIALS, synapseNS);
Expand All @@ -377,20 +402,44 @@ private OMElement generateOAuthPasswordCredentialsElement(OMFactory factory, OMN
return passwordCredentials;
}

/**
* Generates an OMElement representing the OAuth token URL.
*
* @param factory the OMFactory used to create OMElements
* @param synapseNS the OMNamespace for the Synapse configuration
* @return the OMElement representing the OAuth token URL
*/
private OMElement generateOAuthTokenUrlElement(OMFactory factory, OMNamespace synapseNS) {

OMElement oauthTokenUrl = factory.createOMElement(SynapseConstants.TOKEN_URL, synapseNS);
oauthTokenUrl.setText(this.tokenUrl);
return oauthTokenUrl;
}

/**
* Generates an OMElement representing the authentication username.
* This element contains the username used for authentication.
*
* @param factory the OMFactory used to create OMElements
* @param synapseNS the OMNamespace for the Synapse configuration
* @return the OMElement representing the authentication username
*/
private OMElement generateAuthUsernameElement(OMFactory factory, OMNamespace synapseNS) {

OMElement authUsername = factory.createOMElement(SynapseConstants.USERNAME, synapseNS);
authUsername.setText(this.username);
return authUsername;
}

/**
* Generates an OMElement representing the OAuth client credentials grant type.
* This includes the client ID, client secret, token URL, authorization mode,
* and any additional properties.
*
* @param factory the OMFactory used to create OMElements
* @param synapseNS the OMNamespace for the Synapse configuration
* @return the OMElement representing the OAuth client credentials grant type
*/
private OMElement generateOAuthClientCredentialsElement(OMFactory factory, OMNamespace synapseNS) {

OMElement clientCredentials = factory.createOMElement(SynapseConstants.CLIENT_CREDENTIALS, synapseNS);
Expand All @@ -412,7 +461,16 @@ private OMElement generateOAuthClientCredentialsElement(OMFactory factory, OMNam
return clientCredentials;
}

private OMElement generateOAuthAuthorizatonCodeElement(OMFactory factory, OMNamespace synapseNS) {
/**
* Generates an OMElement representing the OAuth authorization code grant type.
* This includes the refresh token, client ID, client secret, token URL,
* authorization mode, and any additional properties.
*
* @param factory the OMFactory used to create OMElements
* @param synapseNS the OMNamespace for the Synapse configuration
* @return the OMElement representing the OAuth authorization code grant type
*/
private OMElement generateOAuthAuthorizationCodeElement(OMFactory factory, OMNamespace synapseNS) {

OMElement authorizationCode = factory.createOMElement(SynapseConstants.AUTHORIZATION_CODE, synapseNS);

Expand All @@ -435,34 +493,70 @@ private OMElement generateOAuthAuthorizatonCodeElement(OMFactory factory, OMName
return authorizationCode;
}

/**
* Generates an OMElement representing the OAuth refresh token.
*
* @param factory the OMFactory used to create OMElements
* @param synapseNS the OMNamespace for the Synapse configuration
* @return the OMElement representing the OAuth refresh token
*/
private OMElement generateOAuthRefreshTokenElement(OMFactory factory, OMNamespace synapseNS) {

OMElement oauthRefreshToken = factory.createOMElement(SynapseConstants.REFRESH_TOKEN, synapseNS);
oauthRefreshToken.setText(this.refreshToken);
return oauthRefreshToken;
}

/**
* Generates an OMElement representing the OAuth client secret.
*
* @param factory the OMFactory used to create OMElements
* @param synapseNS the OMNamespace for the Synapse configuration
* @return the OMElement representing the OAuth client secret
*/
private OMElement generateOAuthClientSecretElement(OMFactory factory, OMNamespace synapseNS) {

OMElement oauthClientSecret = factory.createOMElement(SynapseConstants.CLIENT_SECRET, synapseNS);
oauthClientSecret.setText(this.clientSecret);
return oauthClientSecret;
}

/**
* Generates an OMElement representing the OAuth client ID.
*
* @param factory the OMFactory used to create OMElements
* @param synapseNS the OMNamespace for the Synapse configuration
* @return the OMElement representing the OAuth client ID
*/
private OMElement generateOAuthClientIDElement(OMFactory factory, OMNamespace synapseNS) {

OMElement oauthClientID = factory.createOMElement(SynapseConstants.CLIENT_ID, synapseNS);
oauthClientID.setText(this.clientId);
return oauthClientID;
}

/**
* Generates an OMElement representing the OAuth authorization mode.
*
* @param factory the OMFactory used to create OMElements
* @param synapseNS the OMNamespace for the Synapse configuration
* @return the OMElement representing the OAuth authorization mode
*/
private OMElement generateOAuthAuthorizationModeElement(OMFactory factory, OMNamespace synapseNS) {

OMElement authMode = factory.createOMElement(SynapseConstants.AUTH_MODE, synapseNS);
authMode.setText(this.oauthAuthorizationMode);
return authMode;
}

/**
* Generates an OMElement representing the basic authentication credentials.
* This element contains the username and password used for basic authentication.
*
* @param factory the OMFactory used to create OMElements
* @param synapseNS the OMNamespace for the Synapse configuration
* @return the OMElement representing the basic authentication credentials
*/
private OMElement generateBasicAuthenticationElement(OMFactory factory, OMNamespace synapseNS) {

OMElement basicAuth = factory.createOMElement(SynapseConstants.BASIC_AUTH_TAG, synapseNS);
Expand All @@ -475,29 +569,53 @@ private OMElement generateBasicAuthenticationElement(OMFactory factory, OMNamesp
return basicAuth;
}

/**
* Generates an OMElement representing the authentication password.
* This element contains the password used for authentication.
*
* @param factory the OMFactory used to create OMElements
* @param synapseNS the OMNamespace for the Synapse configuration
* @return the OMElement representing the authentication password
*/
private OMElement generateAuthPasswordElement(OMFactory factory, OMNamespace synapseNS) {

OMElement authPassword = factory.createOMElement(SynapseConstants.PASSWORD, synapseNS);
authPassword.setText(this.password);
return authPassword;
}

/**
* Generates a list of OMElements representing miscellaneous properties.
* Each property is parsed from a comma-separated string of key:scope:value pairs.
*
* @param factory the OMFactory used to create OMElements
* @param synapseNS the OMNamespace for the Synapse configuration
* @return a list of OMElements representing the miscellaneous properties
*/
private List<OMElement> generateMiscellaneousPropertiesElement(OMFactory factory, OMNamespace synapseNS) {

List<OMElement> miscelleneousProperties = new ArrayList<>();
List<OMElement> miscellaneousProperties = 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);
miscellaneousProperties.add(property);
}
}
return miscelleneousProperties;
return miscellaneousProperties;
}

/**
* Generates an OMElement representing additional OAuth properties.
* This element contains key-value pairs of additional properties used for OAuth authentication.
*
* @param factory the OMFactory used to create OMElements
* @param synapseNS the OMNamespace for the Synapse configuration
* @return the OMElement representing the additional OAuth properties
*/
private OMElement generateOAuthAdditionalPropertiesElement(OMFactory factory, OMNamespace synapseNS) {

OMElement additionalProperties = factory.createOMElement(SynapseConstants.REQUEST_PARAMETERS, synapseNS);
Expand Down
Loading

0 comments on commit 969d628

Please sign in to comment.