Avoid building the API completely to get name
Partially build the API to get the API name.
Fixes wso2/micro-integrator/issues/2127
package org.wso2.micro.integrator.initializer.deployment.application.deployer;
import com.google.gson.JsonObject;
+import org.apache.axiom.om.OMAttribute;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMException;
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
@@ -30,10 +31,12 @@ import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.api.version.VersionStrategy;
import org.apache.synapse.config.SynapseConfigUtils;
import org.apache.synapse.config.SynapseConfiguration;
import org.apache.synapse.config.xml.rest.APIFactory;
import org.apache.synapse.api.API;
+import org.apache.synapse.config.xml.rest.VersionStrategyFactory;
import org.wso2.micro.application.deployer.AppDeployerUtils;
import org.wso2.micro.application.deployer.CarbonApplication;
import org.wso2.micro.application.deployer.config.ApplicationConfiguration;
@@ -56,6 +59,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;
import static org.wso2.micro.core.Constants.SUPER_TENANT_DOMAIN_NAME;
@@ -635,7 +639,7 @@ public class CappDeployer extends AbstractDeployer {
}
/**
- * Building the API to get the API name
+ * Partially building the API to get the API name
*
* @param apiXmlStream input stream of the API file.
* @return name of the API.
@@ -644,7 +648,11 @@ public class CappDeployer extends AbstractDeployer {
try {
OMElement apiElement = new StAXOMBuilder(apiXmlStream).getDocumentElement();
- API api = APIFactory.createAPI(apiElement);
+ OMAttribute nameAtt = apiElement.getAttribute(new QName("name"));
+ OMAttribute contextAtt = apiElement.getAttribute(new QName("context"));
+ API api = new API(nameAtt.getAttributeValue(), contextAtt.getAttributeValue());
+ VersionStrategy vStrategy = VersionStrategyFactory.createVersioningStrategy(api, apiElement);
+ api.setVersionStrategy(vStrategy);
return api.getName();
} catch (XMLStreamException | OMException e) {
// Cannot find the API file or API is faulty.
