Skip to content

Commit

Permalink
Merge pull request #2979 from malakaganga/fix_service_cat
Browse files Browse the repository at this point in the history
Fix Service Catalog not publishing SOAP Proxy
  • Loading branch information
malakaganga authored Sep 22, 2023
2 parents c003cd7 + 19d2afa commit 8457467
Showing 1 changed file with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.synapse.commons.resolvers.ResolverException;
import org.apache.synapse.commons.resolvers.SystemResolver;
import org.apache.synapse.config.SynapseConfigUtils;
import org.apache.synapse.core.axis2.ProxyService;
import org.wso2.carbon.securevault.SecretCallbackHandlerService;
import org.wso2.config.mapper.ConfigParser;
import org.wso2.micro.application.deployer.AppDeployerUtils;
Expand Down Expand Up @@ -818,6 +819,9 @@ private static String getFileChecksum(File file) throws NoSuchAlgorithmException
* @return WSDL file creation result.
*/
private static boolean readProxyServiceWSDL(File metadataYamlFile, File storeLocation) {
Collection proxyTable =
SynapseConfigUtils.getSynapseConfiguration(
org.wso2.micro.core.Constants.SUPER_TENANT_DOMAIN_NAME).getProxyServices();
BufferedReader bufferedReader = null;
try {
String proxyServiceUrl = getProxyServiceUrlFromMetadata(metadataYamlFile);
Expand All @@ -843,8 +847,17 @@ private static boolean readProxyServiceWSDL(File metadataYamlFile, File storeLoc
return false;
}
if (storeLocation.exists()) {
String wsdlString = responseWSDL.toString();
boolean shouldSchemaLocationBeChanged = shouldSchemaLocationBeChanged(storeLocation, proxyTable);
if (shouldSchemaLocationBeChanged) {
// Replace schemaLocation values ending with .xsd and change everything up to ? to xyz using regex
String regexPattern = "(schemaLocation=\")[^\"?]*\\?(.*\\.xsd\")";
String baseUrl = proxyServiceUrl.replace(WSDL_URL_PATH, "?");
String replacement = "$1" + baseUrl + "$2";
wsdlString = wsdlString.replaceAll(regexPattern, replacement);
}
Files.write(Paths.get(storeLocation.getAbsolutePath(), WSDL_FILE_NAME),
responseWSDL.toString().getBytes());
wsdlString.getBytes());
return true;
}
} catch (IOException e) {
Expand All @@ -862,6 +875,23 @@ private static boolean readProxyServiceWSDL(File metadataYamlFile, File storeLoc
return false;
}

private static boolean shouldSchemaLocationBeChanged(File storeLocation, Collection proxyTable) {
String metaFileName = storeLocation.getName();
String proxyServiceName = metaFileName.substring(0,
metaFileName.indexOf(PROXY_SERVICE_SUFFIX + METADATA_FOLDER_STRING));
if (proxyTable != null && !proxyTable.isEmpty()) {
for (Object proxy : proxyTable) {
if (proxy instanceof ProxyService) {
ProxyService proxyService = (ProxyService) proxy;
if (proxyService.getName().equals(proxyServiceName) && proxyService.getResourceMap() != null) {
return true;
}
}
}
}
return false;
}

/**
* Reads service URL from metadata file.
*
Expand Down

0 comments on commit 8457467

Please sign in to comment.