Search in sources :

Example 1 with HandlerConfigContex

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.HandlerConfigContex 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();
}
Also used : VelocityEngine(org.apache.velocity.app.VelocityEngine) VelocityContext(org.apache.velocity.VelocityContext) UserStoreException(org.wso2.carbon.user.api.UserStoreException) RegistryException(org.wso2.carbon.registry.api.RegistryException) APITemplateException(org.wso2.carbon.apimgt.impl.template.APITemplateException) Template(org.apache.velocity.Template) StringWriter(java.io.StringWriter) APITemplateException(org.wso2.carbon.apimgt.impl.template.APITemplateException)

Example 2 with HandlerConfigContex

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.HandlerConfigContex in project carbon-apimgt by wso2.

the class HandlerConfigContextTest method testHandlerConfigContex.

@Test
public void testHandlerConfigContex() throws Exception {
    API api = new API(new APIIdentifier("admin", "TestAPI", "1.0.0"));
    api.setStatus(APIConstants.CREATED);
    api.setContextTemplate("/");
    ConfigContext configcontext = new APIConfigContext(api);
    List<HandlerConfig> handlers = new ArrayList<HandlerConfig>();
    HandlerConfigContex handlerConfigContex = new HandlerConfigContex(configcontext, handlers);
    Assert.assertNotNull(handlerConfigContex.getContext().get("handlers"));
}
Also used : HandlerConfigContex(org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.HandlerConfigContex) HandlerConfig(org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.HandlerConfig) ArrayList(java.util.ArrayList) API(org.wso2.carbon.apimgt.api.model.API) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) APIConfigContext(org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.APIConfigContext) ConfigContext(org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.ConfigContext) APIConfigContext(org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.APIConfigContext) Test(org.junit.Test)

Aggregations

StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 Template (org.apache.velocity.Template)1 VelocityContext (org.apache.velocity.VelocityContext)1 VelocityEngine (org.apache.velocity.app.VelocityEngine)1 Test (org.junit.Test)1 API (org.wso2.carbon.apimgt.api.model.API)1 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)1 APITemplateException (org.wso2.carbon.apimgt.impl.template.APITemplateException)1 APIConfigContext (org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.APIConfigContext)1 ConfigContext (org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.ConfigContext)1 HandlerConfig (org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.HandlerConfig)1 HandlerConfigContex (org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.HandlerConfigContex)1 RegistryException (org.wso2.carbon.registry.api.RegistryException)1 UserStoreException (org.wso2.carbon.user.api.UserStoreException)1