@Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,
            IOException {

        try {
            Class.forName("io.apiman.manager.ui.server.UIConfig"); //$NON-NLS-1$
        } catch (Throwable t) {
            t.printStackTrace();
        }

        JsonGenerator g = null;
        try {
            response.getOutputStream().write("window.APIMAN_CONFIG_DATA = ".getBytes(StandardCharsets.UTF_8)); //$NON-NLS-1$
            JsonFactory f = new JsonFactory();
            g = f.createGenerator(response.getOutputStream(), JsonEncoding.UTF8);
            ObjectMapper mapper = new ObjectMapper();
            mapper.setSerializationInclusion(Include.NON_NULL);
            g.setCodec(mapper);
            g.useDefaultPrettyPrinter();

            // Get data from various sources.
            String endpoint = getConfig().getManagementApiEndpoint();
            if (endpoint == null) {
                endpoint = getDefaultEndpoint(request);
            }
            UIVersion version = UIVersion.get();
            ApiAuthType authType = getConfig().getManagementApiAuthType();

            ConfigurationBean configBean = new ConfigurationBean();
            configBean.setApiman(new AppConfigurationBean());
            configBean.setUser(new UserConfigurationBean());
            configBean.setUi(new UiConfigurationBean());
            configBean.setApi(new ApiConfigurationBean());
            configBean.getUi().setHeader("community"); //$NON-NLS-1$
            configBean.getUi().setMetrics(getConfig().isMetricsEnabled());
            configBean.getUi().setNotifications(getConfig().isNotificationsEnabled());
            configBean.getUi().setPlatform(getConfig().getPlatform());
            configBean.getUi().setAdminOnlyOrgCreation(getConfig().isAdminOnlyOrgCreationEnabled());
            configBean.getApiman().setVersion(version.getVersionString());
            configBean.getApiman().setBuiltOn(version.getVersionDate());
            configBean.getApiman().setLogoutUrl(getConfig().getLogoutUrl());
            configBean.getUser().setUsername(request.getRemoteUser());
            configBean.getApi().setEndpoint(endpoint);
            configBean.getApi().setAuth(new ApiAuthConfigurationBean());
            switch (authType) {
                case authToken: {
                    configBean.getApi().getAuth().setType(ApiAuthType.authToken);
                    String tokenGeneratorClassName = getConfig().getManagementApiAuthTokenGenerator();
                    if (tokenGeneratorClassName == null) {
                        throw new ServletException("No token generator class specified."); //$NON-NLS-1$
                    }
                    Class<?> c = Class.forName(tokenGeneratorClassName);
                    ITokenGenerator tokenGenerator = (ITokenGenerator) c.newInstance();
                    configBean.getApi().getAuth().setBearerToken(tokenGenerator.generateToken(request));
                    break;
                }
                case basic: {
                    configBean.getApi().getAuth().setType(ApiAuthType.basic);
                    configBean.getApi().getAuth().setBasic(new BasicAuthCredentialsBean());
                    String username = getConfig().getManagementApiAuthUsername();
                    String password = getConfig().getManagementApiAuthPassword();
                    configBean.getApi().getAuth().getBasic().setUsername(username);
                    configBean.getApi().getAuth().getBasic().setPassword(password);
                    break;
                }
                case bearerToken: {
                    configBean.getApi().getAuth().setType(ApiAuthType.bearerToken);
                    String tokenGeneratorClassName = getConfig().getManagementApiAuthTokenGenerator();
                    if (tokenGeneratorClassName == null)
                        throw new ServletException("No token generator class specified."); //$NON-NLS-1$
                    Class<?> c = Class.forName(tokenGeneratorClassName);
                    ITokenGenerator tokenGenerator = (ITokenGenerator) c.newInstance();
                    configBean.getApi().getAuth().setBearerToken(tokenGenerator.generateToken(request));
                    break;
                }
                case samlBearerToken: {
                    configBean.getApi().getAuth().setType(ApiAuthType.samlBearerToken);
                    String tokenGeneratorClassName = getConfig().getManagementApiAuthTokenGenerator();
                    if (tokenGeneratorClassName == null)
                        throw new ServletException("No token generator class specified."); //$NON-NLS-1$
                    Class<?> c = Class.forName(tokenGeneratorClassName);
                    ITokenGenerator tokenGenerator = (ITokenGenerator) c.newInstance();
                    configBean.getApi().getAuth().setBearerToken(tokenGenerator.generateToken(request));
                    break;
                }
            }
            g.writeObject(configBean);

            g.flush();
            response.getOutputStream().write(";".getBytes(StandardCharsets.UTF_8)); //$NON-NLS-1$ //$NON-NLS-2$
        } catch (Exception e) {
            throw new ServletException(e);
        } finally {
            IOUtils.closeQuietly(g);
        }
    }
@see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest,
     javax.servlet.http.HttpServletResponse)
manager/ui/war/src/main/java/io/apiman/manager/ui/server/servlets/ConfigurationServlet.java