use of org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.EnvironmentConfigContext in project carbon-apimgt by wso2.
the class APITemplateBuilderImpl method getConfigStringForPrototypeScriptAPI.
@Override
public String getConfigStringForPrototypeScriptAPI(Environment environment) throws APITemplateException {
StringWriter writer = new StringWriter();
try {
// build the context for template and apply the necessary decorators
ConfigContext configcontext = new APIConfigContext(this.api);
configcontext = new TransportConfigContext(configcontext, api);
configcontext = new ResourceConfigContext(configcontext, api);
configcontext = new EndpointBckConfigContext(configcontext, api);
configcontext = new EndpointConfigContext(configcontext, api);
configcontext = new SecurityConfigContext(configcontext, api);
configcontext = new JwtConfigContext(configcontext);
configcontext = new ResponseCacheConfigContext(configcontext, api);
configcontext = new HandlerConfigContex(configcontext, handlers);
configcontext = new EnvironmentConfigContext(configcontext, environment);
configcontext = new TemplateUtilContext(configcontext);
// @todo: this validation might be better to do when the builder is initialized.
configcontext.validate();
VelocityContext context = configcontext.getContext();
context.internalGetKeys();
/* first, initialize velocity engine */
VelocityEngine velocityengine = new VelocityEngine();
APIUtil.initializeVelocityContext(velocityengine);
velocityengine.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, CarbonUtils.getCarbonHome());
initVelocityEngine(velocityengine);
Template t = velocityengine.getTemplate(this.getPrototypeTemplatePath());
t.merge(context, writer);
} catch (Exception e) {
log.error("Velocity Error", e);
throw new APITemplateException("Velocity Error", e);
}
return writer.toString();
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.EnvironmentConfigContext in project carbon-apimgt by wso2.
the class EnvironmentConfigContextTest method testEnvironmentConfigContext.
@Test
public void testEnvironmentConfigContext() throws Exception {
API api = new API(new APIIdentifier("admin", "TestAPI", "1.0.0"));
api.setStatus(APIConstants.CREATED);
api.setContextTemplate("/");
String url = "http://maps.googleapis.com/maps/api/geocode/json?address=Colombo";
String endpointConfig = "{\"production_endpoints\":{\"url\":\"" + url + "\", \"config\":null}," + "\"sandbox_endpoint\":{\"url\":\"" + url + "\",\"config\":null},\"endpoint_type\":\"http\"}";
api.setEndpointConfig(endpointConfig);
api.setUrl(url);
api.setSandboxUrl(url);
ConfigContext configcontext = new APIConfigContext(api);
Environment environment = new Environment();
environment.setType("production");
EnvironmentConfigContext environmentConfigContext = new EnvironmentConfigContext(configcontext, environment);
Assert.assertNotNull(environmentConfigContext.getContext().get("environment"));
Assert.assertNotNull(environmentConfigContext.getContext().get("environmentType"));
}
Aggregations