com.ebay.pulsar.metric.server.MetricDispatcherServlet.java Source code

Java tutorial

Introduction

Here is the source code for com.ebay.pulsar.metric.server.MetricDispatcherServlet.java

Source

/*
Pulsar
Copyright (C) 2013-2015 eBay Software Foundation
Licensed under the GPL v2 license.  See LICENSE for full terms.
*/
package com.ebay.pulsar.metric.server;

import org.springframework.beans.BeanUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextException;
import org.springframework.web.context.ConfigurableWebApplicationContext;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;

public class MetricDispatcherServlet extends DispatcherServlet {
    private static final long serialVersionUID = 7689614315500644056L;

    protected WebApplicationContext createWebApplicationContext(ApplicationContext parent) {
        Class<?> contextClass = getContextClass();
        if (this.logger.isDebugEnabled()) {
            this.logger.debug("Servlet with name '" + getServletName()
                    + "' will try to create custom WebApplicationContext context of class '"
                    + contextClass.getName() + "'" + ", using parent context [" + parent + "]");
        }
        if (!ConfigurableWebApplicationContext.class.isAssignableFrom(contextClass)) {
            throw new ApplicationContextException("Fatal initialization error in servlet with name '"
                    + getServletName() + "': custom WebApplicationContext class [" + contextClass.getName()
                    + "] is not of type ConfigurableWebApplicationContext");
        }
        ConfigurableWebApplicationContext wac = (ConfigurableWebApplicationContext) BeanUtils
                .instantiateClass(contextClass);

        wac.setParent(parent);
        if (wac.getParent() == null) {
            ApplicationContext rootContext = (ApplicationContext) getServletContext().getAttribute("JetStreamRoot");
            wac.setParent(rootContext);
        }
        wac.setConfigLocation(getContextConfigLocation());
        configureAndRefreshWebApplicationContext(wac);
        return wac;
    }
}