org.apache.velocity.runtime.log.CommonsLogLogChute Java Examples

The following examples show how to use org.apache.velocity.runtime.log.CommonsLogLogChute. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RESTToSOAPMsgTemplate.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
/**
 * gets in sequence for the soap operation
 *
 * @param mapping       soap to rest mapping json
 * @param method        http method for the resource
 * @param soapAction    soap action for the operation
 * @param namespace     soap namespace for the operation
 * @param soapNamespace soap namespace for the soap version
 * @return in sequence string
 */
public String getMappingInSequence(Map<String, String> mapping, String method, String soapAction, String namespace,
        String soapNamespace, JSONArray array) {

    ConfigContext configcontext = new SOAPToRESTConfigContext(mapping, method, soapAction, namespace, soapNamespace,
            array);
    StringWriter writer = new StringWriter();
    try {
        VelocityContext context = configcontext.getContext();
        context.internalGetKeys();

        VelocityEngine velocityengine = new VelocityEngine();
        if (!SOAPToRESTConstants.Template.NOT_DEFINED.equalsIgnoreCase(getVelocityLogger())) {
            velocityengine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,
                    CommonsLogLogChute.class.getName());
            velocityengine.setProperty(VelocityEngine.RESOURCE_LOADER, "classpath");
            velocityengine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
        }
        velocityengine.init();
        org.apache.velocity.Template t = velocityengine.getTemplate(this.getInSeqTemplatePath());
        t.merge(context, writer);
    } catch (Exception e) {
        log.error("Velocity Error", e);
    }
    return writer.toString();
}
 
Example #2
Source File: RESTToSOAPMsgTemplate.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
/**
 * gets out sequence for the soap operation
 *
 * @return out sequence for the converted soap operation
 */
public String getMappingOutSequence() {

    ConfigContext configcontext = new SOAPToRESTConfigContext();
    StringWriter writer = new StringWriter();
    try {
        VelocityContext context = configcontext.getContext();
        context.internalGetKeys();

        VelocityEngine velocityengine = new VelocityEngine();
        if (!SOAPToRESTConstants.Template.NOT_DEFINED.equalsIgnoreCase(getVelocityLogger())) {
            velocityengine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,
                    CommonsLogLogChute.class.getName());
            velocityengine.setProperty(VelocityEngine.RESOURCE_LOADER, "classpath");
            velocityengine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
        }

        velocityengine.init();
        org.apache.velocity.Template template = velocityengine.getTemplate(this.getOutSeqTemplatePath());

        template.merge(context, writer);
    } catch (Exception e) {
        log.error("Velocity Error", e);
    }
    return writer.toString();
}
 
Example #3
Source File: SchemaWriter.java    From qemu-java with GNU General Public License v2.0 6 votes vote down vote up
@Nonnull
private static VelocityEngine newVelocityEngine() {
    VelocityEngine engine = new VelocityEngine();
    engine
            .setProperty(VelocityEngine.RUNTIME_LOG_LOGSYSTEM_CLASS, CommonsLogLogChute.class
            .getName());
    // engine.setProperty(VelocityEngine.RUNTIME_LOG_LOGSYSTEM_CLASS, SystemLogChute.class.getName());
    engine.setProperty(VelocityEngine.RESOURCE_LOADER,
            "classpath");
    engine.setProperty(
            "classpath.resource.loader.class", ClasspathResourceLoader.class
            .getName());
    // engine.setProperty(VelocityEngine.FILE_RESOURCE_LOADER_CACHE, "true");
    // engine.setProperty(VelocityEngine.FILE_RESOURCE_LOADER_PATH, "velocity/");
    engine.init();
    return engine;
}
 
Example #4
Source File: VelocityEngineFactory.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Prepare the VelocityEngine instance and return it.
 * @return the VelocityEngine instance
 * @throws IOException if the config file wasn't found
 * @throws VelocityException on Velocity initialization failure
 */
public VelocityEngine createVelocityEngine() throws IOException, VelocityException {
	VelocityEngine velocityEngine = newVelocityEngine();
	Map<String, Object> props = new HashMap<String, Object>();

	// Load config file if set.
	if (this.configLocation != null) {
		if (logger.isInfoEnabled()) {
			logger.info("Loading Velocity config from [" + this.configLocation + "]");
		}
		CollectionUtils.mergePropertiesIntoMap(PropertiesLoaderUtils.loadProperties(this.configLocation), props);
	}

	// Merge local properties if set.
	if (!this.velocityProperties.isEmpty()) {
		props.putAll(this.velocityProperties);
	}

	// Set a resource loader path, if required.
	if (this.resourceLoaderPath != null) {
		initVelocityResourceLoader(velocityEngine, this.resourceLoaderPath);
	}

	// Log via Commons Logging?
	if (this.overrideLogging) {
		velocityEngine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM, new CommonsLogLogChute());
	}

	// Apply properties to VelocityEngine.
	for (Map.Entry<String, Object> entry : props.entrySet()) {
		velocityEngine.setProperty(entry.getKey(), entry.getValue());
	}

	postProcessVelocityEngine(velocityEngine);

	// Perform actual initialization.
	velocityEngine.init();

	return velocityEngine;
}
 
Example #5
Source File: VelocityEngineFactory.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Prepare the VelocityEngine instance and return it.
 * @return the VelocityEngine instance
 * @throws IOException if the config file wasn't found
 * @throws VelocityException on Velocity initialization failure
 */
public VelocityEngine createVelocityEngine() throws IOException, VelocityException {
	VelocityEngine velocityEngine = newVelocityEngine();
	Map<String, Object> props = new HashMap<String, Object>();

	// Load config file if set.
	if (this.configLocation != null) {
		if (logger.isInfoEnabled()) {
			logger.info("Loading Velocity config from [" + this.configLocation + "]");
		}
		CollectionUtils.mergePropertiesIntoMap(PropertiesLoaderUtils.loadProperties(this.configLocation), props);
	}

	// Merge local properties if set.
	if (!this.velocityProperties.isEmpty()) {
		props.putAll(this.velocityProperties);
	}

	// Set a resource loader path, if required.
	if (this.resourceLoaderPath != null) {
		initVelocityResourceLoader(velocityEngine, this.resourceLoaderPath);
	}

	// Log via Commons Logging?
	if (this.overrideLogging) {
		velocityEngine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM, new CommonsLogLogChute());
	}

	// Apply properties to VelocityEngine.
	for (Map.Entry<String, Object> entry : props.entrySet()) {
		velocityEngine.setProperty(entry.getKey(), entry.getValue());
	}

	postProcessVelocityEngine(velocityEngine);

	// Perform actual initialization.
	velocityEngine.init();

	return velocityEngine;
}
 
Example #6
Source File: VelocityEngineFactory.java    From MaxKey with Apache License 2.0 5 votes vote down vote up
/**
 * Prepare the VelocityEngine instance and return it.
 * @return the VelocityEngine instance
 * @throws IOException if the config file wasn't found
 * @throws VelocityException on Velocity initialization failure
 */
public VelocityEngine createVelocityEngine() throws IOException, VelocityException {
	VelocityEngine velocityEngine = newVelocityEngine();
	Map<String, Object> props = new HashMap<String, Object>();

	// Load config file if set.
	if (this.configLocation != null) {
		if (logger.isInfoEnabled()) {
			logger.info("Loading Velocity config from [" + this.configLocation + "]");
		}
		CollectionUtils.mergePropertiesIntoMap(PropertiesLoaderUtils.loadProperties(this.configLocation), props);
	}

	// Merge local properties if set.
	if (!this.velocityProperties.isEmpty()) {
		props.putAll(this.velocityProperties);
	}

	// Set a resource loader path, if required.
	if (this.resourceLoaderPath != null) {
		initVelocityResourceLoader(velocityEngine, this.resourceLoaderPath);
	}

	// Log via Commons Logging?
	if (this.overrideLogging) {
		velocityEngine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM, new CommonsLogLogChute());
	}

	// Apply properties to VelocityEngine.
	for (Map.Entry<String, Object> entry : props.entrySet()) {
		velocityEngine.setProperty(entry.getKey(), entry.getValue());
	}

	postProcessVelocityEngine(velocityEngine);

	// Perform actual initialization.
	velocityEngine.init();

	return velocityEngine;
}
 
Example #7
Source File: ThrottlePolicyTemplateBuilder.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
/**
 * Generate application level policy.
 * 
 * @param policy policy with level 'app'. Multiple pipelines are not allowed. Can define more than one condition
 *            as set of conditions. all these conditions should be passed as a single pipeline
 * @return
 * @throws APITemplateException
 */
public String getThrottlePolicyForAppLevel(ApplicationPolicy policy) throws APITemplateException {
    StringWriter writer = new StringWriter();

    if (log.isDebugEnabled()) {
        log.debug("Generating policy for appLevel :" + policy.toString());
    }

    if (!(policy instanceof ApplicationPolicy)) {
        throw new APITemplateException("Invalid policy level : Has to be 'app'");
    }
    try {
        VelocityEngine velocityengine = new VelocityEngine();
        velocityengine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,
                CommonsLogLogChute.class.getName());
        if (!"not-defined".equalsIgnoreCase(getVelocityLogger())) {
            velocityengine.setProperty(VelocityEngine.RESOURCE_LOADER, "classpath");
            velocityengine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
        }
        velocityengine.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, CarbonUtils.getCarbonHome());
        velocityengine.init();
        Template template = velocityengine.getTemplate(getTemplatePathForApplication());

        VelocityContext context = new VelocityContext();
        setConstantContext(context);
        context.put("policy", policy);
        context.put("quotaPolicy", policy.getDefaultQuotaPolicy());
        template.merge(context, writer);
        if (log.isDebugEnabled()) {
            log.debug("Policy : " + writer.toString());
        }

    } catch (Exception e) {
        log.error("Velocity Error", e);
        throw new APITemplateException("Velocity Error", e);
    }
    String str = writer.toString();
    return writer.toString();
}
 
Example #8
Source File: ThrottlePolicyTemplateBuilder.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
/**
 * Generate policy for subscription level.
 * @param policy policy with level 'sub'. Multiple pipelines are not allowed. Can define more than one condition
 * as set of conditions. all these conditions should be passed as a single pipeline 
 * @return
 * @throws APITemplateException
 */
public String getThrottlePolicyForSubscriptionLevel(SubscriptionPolicy policy) throws APITemplateException {
    StringWriter writer = new StringWriter();

    if (log.isDebugEnabled()) {
        log.debug("Generating policy for subscriptionLevel :" + policy.toString());
    }

    if (!(policy instanceof SubscriptionPolicy)) {
        throw new APITemplateException("Invalid policy level :  Has to be 'sub'");
    }
    try {
        VelocityEngine velocityengine = new VelocityEngine();
        velocityengine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,
                CommonsLogLogChute.class.getName());
        if (!"not-defined".equalsIgnoreCase(getVelocityLogger())) {
            velocityengine.setProperty(VelocityEngine.RESOURCE_LOADER, "classpath");
            velocityengine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
        }
        velocityengine.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, CarbonUtils.getCarbonHome());
        velocityengine.init();
        Template t = velocityengine.getTemplate(getTemplatePathForSubscription());

        VelocityContext context = new VelocityContext();
        setConstantContext(context);
        context.put("policy", policy);
        context.put("quotaPolicy", policy.getDefaultQuotaPolicy());
        t.merge(context, writer);
        if (log.isDebugEnabled()) {
            log.debug("Policy : " + writer.toString());
        }
    } catch (Exception e) {
        log.error("Velocity Error", e);
        throw new APITemplateException("Velocity Error", e);
    }

    return writer.toString();
}
 
Example #9
Source File: APITemplateBuilderImpl.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the necessary variables to velocity context
 *
 * @param endpointType Type of the endpoint : production or sandbox
 * @return The string of endpoint file content
 * @throws APITemplateException Thrown if an error occurred
 */
@Override
public String getConfigStringForEndpointTemplate(String endpointType) throws APITemplateException {
    StringWriter writer = new StringWriter();

    try {
        ConfigContext configcontext = new APIConfigContext(this.api);
        configcontext = new EndpointBckConfigContext(configcontext, api);
        configcontext = new EndpointConfigContext(configcontext, api);
        configcontext = new TemplateUtilContext(configcontext);

        configcontext.validate();

        VelocityContext context = configcontext.getContext();

        context.internalGetKeys();

        VelocityEngine velocityengine = new VelocityEngine();
        if (!"not-defined".equalsIgnoreCase(getVelocityLogger())) {
            velocityengine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,
                    CommonsLogLogChute.class.getName());
            velocityengine.setProperty(VelocityEngine.RESOURCE_LOADER, "classpath");
            velocityengine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
        }

        velocityengine.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, CarbonUtils.getCarbonHome());
        initVelocityEngine(velocityengine);

        context.put("type", endpointType);

        Template template = velocityengine.getTemplate(this.getEndpointTemplatePath());

        template.merge(context, writer);

    } catch (Exception e) {
        log.error("Velocity Error");
        throw new APITemplateException("Velocity Error", e);
    }
    return writer.toString();
}
 
Example #10
Source File: ThrottlePolicyTemplateBuilder.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
/**
 * Generate policy for global level. 
 * @param policy policy with level 'global'. Multiple pipelines are not allowed. Can define more than one condition
 * as set of conditions. all these conditions should be passed as a single pipeline 
 * @return
 * @throws APITemplateException
 */
public String getThrottlePolicyForGlobalLevel(GlobalPolicy policy) throws APITemplateException {
    StringWriter writer = new StringWriter();

    if (log.isDebugEnabled()) {
        log.debug("Generating policy for globalLevel :" + policy.toString());
    }

    if (!(policy instanceof GlobalPolicy)) {
        throw new APITemplateException("Invalid policy level : Has to be 'global'");
    }
    try {
        VelocityEngine velocityengine = new VelocityEngine();
        velocityengine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,
                CommonsLogLogChute.class.getName());
        if (!"not-defined".equalsIgnoreCase(getVelocityLogger())) {
            velocityengine.setProperty(VelocityEngine.RESOURCE_LOADER, "classpath");
            velocityengine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
        }
        velocityengine.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, CarbonUtils.getCarbonHome());
        velocityengine.init();

        Template template = velocityengine.getTemplate(getTemplatePathForGlobal());

        VelocityContext context = new VelocityContext();
        setConstantContext(context);
        context.put("policy", policy);
       /* if (policy.getPipelines() != null && !policy.getPipelines().isEmpty()) {
            String conditionString = getPolicyCondition(policy.getPipelines().get(0).getConditions());
            context.put("condition", conditionString);
        } else {
            context.put("condition", "");
        }*/
        if (log.isDebugEnabled()) {
            log.debug("Policy : " + writer.toString());
        }
        template.merge(context, writer);
    } catch (Exception e) {
        log.error("Velocity Error", e);
        throw new APITemplateException("Velocity Error", e);
    }

    return writer.toString();
}
 
Example #11
Source File: APITemplateBuilderImpl.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
@Override
public String getConfigStringForTemplate(Environment environment) throws APITemplateException {
    StringWriter writer = new StringWriter();

    try {
        // build the context for template and apply the necessary decorators
        ConfigContext configcontext = null;

        if (api != null) {
            configcontext = createConfigContext(api, environment);
        } else { // API Product scenario
            configcontext = createConfigContext(apiProduct, environment);
        }

        //@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();
        if (!"not-defined".equalsIgnoreCase(getVelocityLogger())) {
            velocityengine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,
                    CommonsLogLogChute.class.getName());
            velocityengine.setProperty(VelocityEngine.RESOURCE_LOADER, "classpath");
            velocityengine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
        }

        velocityengine.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, CarbonUtils.getCarbonHome());
        initVelocityEngine(velocityengine);

        Template t = null;

        if (api != null) {
            t = velocityengine.getTemplate(getTemplatePath());
        } else {
            t = velocityengine.getTemplate(getApiProductTemplatePath());
        }

        t.merge(context, writer);

    } catch (Exception e) {
        log.error("Velocity Error", e);
        throw new APITemplateException("Velocity Error", e);
    }
    return writer.toString();
}
 
Example #12
Source File: APITemplateBuilderImpl.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
@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 BAMMediatorConfigContext(configcontext);
        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();
        if (!"not-defined".equalsIgnoreCase(getVelocityLogger())) {
            velocityengine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,
                    CommonsLogLogChute.class.getName());
            velocityengine.setProperty(VelocityEngine.RESOURCE_LOADER, "classpath");
            velocityengine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
        }

        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();
}
 
Example #13
Source File: APITemplateBuilderImpl.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
@Override
public String getConfigStringForDefaultAPITemplate(String defaultVersion) throws APITemplateException {
    StringWriter writer = new StringWriter();

    try {
        VelocityEngine velocityengine = new VelocityEngine();
        if (!"not-defined".equalsIgnoreCase(getVelocityLogger())) {
            velocityengine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,
                    CommonsLogLogChute.class.getName());
            velocityengine.setProperty(VelocityEngine.RESOURCE_LOADER, "classpath");
            velocityengine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
        }

        velocityengine.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, CarbonUtils.getCarbonHome());
        initVelocityEngine(velocityengine);

        ConfigContext configcontext = new APIConfigContext(this.api);
        configcontext = new TransportConfigContext(configcontext, api);
        configcontext = new ResourceConfigContext(configcontext, api);
        configcontext = new TemplateUtilContext(configcontext);

        VelocityContext context = configcontext.getContext();
        context.put("defaultVersion", defaultVersion);
        String fwdApiContext = this.api.getContext();
        if (fwdApiContext != null && fwdApiContext.charAt(0) == '/') {
            fwdApiContext = fwdApiContext.substring(1);
        }
        context.put("fwdApiContext", fwdApiContext);

        // for default version, we remove the {version} param from the apiContext
        String apiContext = this.api.getContextTemplate();
        if(apiContext.contains("{version}")){
            apiContext = apiContext.replace("/{version}","");
            apiContext = apiContext.replace("{version}","");
        }

        context.put("apiContext", apiContext);

        Template t = velocityengine.getTemplate(this.getDefaultAPITemplatePath());

        t.merge(context, writer);
    } catch (Exception e) {
        log.error("Velocity Error", e);
        throw new APITemplateException("Velocity Error", e);
    }
    return writer.toString();
}