Skip to content

Commit

Permalink
Fix Service Catalog not publishing SOAP Proxy
Browse files Browse the repository at this point in the history
The specific problem arises when the WSDLReader component in APIM
attempts to read the WSDL content with a schemaLocation attribute
set to 'proxy2?xsd=sample.xsd'. Upon parsing, WSDLReader treats this schemaLocation
as a file path rather than as a query string, leading to a failure in resolving the actual schema location.
So changed the schemaLocation into actual URL.

Fixes: #2967
  • Loading branch information
malakaganga committed Sep 22, 2023
1 parent c003cd7 commit 19d2afa
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 19d2afa

Please sign in to comment.