Java Code Examples for org.apache.tomcat.util.res.StringManager#getManager()

The following examples show how to use org.apache.tomcat.util.res.StringManager#getManager() . These examples are extracted from open source projects. 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
public DefaultInstanceManager(Context context, Map<String, Map<String, String>> injectionMap, org.apache.catalina.Context catalinaContext, ClassLoader containerClassLoader) {
    classLoader = catalinaContext.getLoader().getClassLoader();
    privileged = catalinaContext.getPrivileged();
    this.containerClassLoader = containerClassLoader;
    ignoreAnnotations = catalinaContext.getIgnoreAnnotations();
    StringManager sm = StringManager.getManager(Constants.Package);
    restrictedServlets = loadProperties(
            "org/apache/catalina/core/RestrictedServlets.properties",
            sm.getString("defaultInstanceManager.restrictedServletsResource"),
            catalinaContext.getLogger());
    restrictedListeners = loadProperties(
            "org/apache/catalina/core/RestrictedListeners.properties",
            "defaultInstanceManager.restrictedListenersResources",
            catalinaContext.getLogger());
    restrictedFilters = loadProperties(
            "org/apache/catalina/core/RestrictedFilters.properties",
            "defaultInstanceManager.restrictedFiltersResource",
            catalinaContext.getLogger());
    this.context = context;
    this.injectionMap = injectionMap;
    this.postConstructMethods = catalinaContext.findPostConstructMethods();
    this.preDestroyMethods = catalinaContext.findPreDestroyMethods();
}
 
Example 2
/**
 * Process a GET request for the specified resource.
 *
 * @param request The servlet request we are processing
 * @param response The servlet response we are creating
 *
 * @exception IOException if an input/output error occurs
 * @exception ServletException if a servlet-specified error occurs
 */
@Override
public void doGet(HttpServletRequest request,
                  HttpServletResponse response)
    throws IOException, ServletException {

    StringManager smClient = StringManager.getManager(
            Constants.Package, request.getLocales());

    // Identify the request parameters that we need
    String command = request.getPathInfo();

    // Prepare our output writer to generate the response message
    response.setContentType("text/html; charset=" + Constants.CHARSET);

    String message = "";
    // Process the requested command
    if (command == null) {
        // No command == list
    } else if (command.equals("/list")) {
        // Nothing to do - always generate list
    } else if (command.equals("/add") || command.equals("/remove") ||
            command.equals("/start") || command.equals("/stop") ||
            command.equals("/persist")) {
        message = smClient.getString(
                "hostManagerServlet.postCommand", command);
    } else {
        message = smClient.getString(
                "hostManagerServlet.unknownCommand", command);
    }

    list(request, response, message, smClient);
}
 
Example 3
/**
 * Process a POST request for the specified resource.
 *
 * @param request The servlet request we are processing
 * @param response The servlet response we are creating
 *
 * @exception IOException if an input/output error occurs
 * @exception ServletException if a servlet-specified error occurs
 */
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    StringManager smClient = StringManager.getManager(
            Constants.Package, request.getLocales());

    // Identify the request parameters that we need
    String command = request.getPathInfo();

    String name = request.getParameter("name");

    // Prepare our output writer to generate the response message
    response.setContentType("text/html; charset=" + Constants.CHARSET);

    String message = "";

    // Process the requested command
    if (command == null) {
        // No command == list
    } else if (command.equals("/add")) {
        message = add(request, name, smClient);
    } else if (command.equals("/remove")) {
        message = remove(name, smClient);
    } else if (command.equals("/start")) {
        message = start(name, smClient);
    } else if (command.equals("/stop")) {
        message = stop(name, smClient);
    } else if (command.equals("/persist")) {
        message = persist(smClient);
    } else {
        //Try GET
        doGet(request, response);
    }

    list(request, response, message, smClient);
}
 
Example 4
Source Project: Tomcat8-Source-Read   File: HttpMessages.java    License: MIT License 5 votes vote down vote up
public static HttpMessages getInstance(Locale locale) {
    HttpMessages result = instances.get(locale);
    if (result == null) {
        StringManager sm = StringManager.getManager(
                "org.apache.tomcat.util.http.res", locale);
        if (Locale.getDefault().equals(sm.getLocale())) {
            result = DEFAULT;
        } else {
            result = new HttpMessages(sm);
        }
        instances.put(locale, result);
    }
    return result;
}
 
Example 5
Source Project: Tomcat7.0.67   File: HostManagerServlet.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @deprecated Use {@link StringManager#getManager(String, Enumeration)}.
 *             This method will be removed in Tomcat 8.
 */
@Deprecated
protected StringManager getStringManager(HttpServletRequest req) {
    Enumeration<Locale> requestedLocales = req.getLocales();
    while (requestedLocales.hasMoreElements()) {
        Locale locale = requestedLocales.nextElement();
        StringManager result = StringManager.getManager(Constants.Package,
                locale);
        if (result.getLocale().equals(locale)) {
            return result;
        }
    }
    // Return the default
    return sm;
}
 
Example 6
/**
 * Process a GET request for the specified resource.
 *
 * @param request The servlet request we are processing
 * @param response The servlet response we are creating
 *
 * @exception IOException if an input/output error occurs
 * @exception ServletException if a servlet-specified error occurs
 */
@Override
public void doGet(HttpServletRequest request,
                  HttpServletResponse response)
    throws IOException, ServletException {

    StringManager smClient = StringManager.getManager(
            Constants.Package, request.getLocales());

    // Identify the request parameters that we need
    String command = request.getPathInfo();

    // Prepare our output writer to generate the response message
    response.setContentType("text/html; charset=" + Constants.CHARSET);

    String message = "";
    // Process the requested command
    if (command == null) {
        // No command == list
    } else if (command.equals("/list")) {
        // Nothing to do - always generate list
    } else if (command.equals("/add") || command.equals("/remove") ||
            command.equals("/start") || command.equals("/stop")) {
        message = smClient.getString(
                "hostManagerServlet.postCommand", command);
    } else {
        message = smClient.getString(
                "hostManagerServlet.unknownCommand", command);
    }

    list(request, response, message, smClient);
}
 
Example 7
/**
 * Process a POST request for the specified resource.
 *
 * @param request The servlet request we are processing
 * @param response The servlet response we are creating
 *
 * @exception IOException if an input/output error occurs
 * @exception ServletException if a servlet-specified error occurs
 */
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    StringManager smClient = StringManager.getManager(
            Constants.Package, request.getLocales());

    // Identify the request parameters that we need
    String command = request.getPathInfo();

    String name = request.getParameter("name");
 
    // Prepare our output writer to generate the response message
    response.setContentType("text/html; charset=" + Constants.CHARSET);

    String message = "";
    
    // Process the requested command
    if (command == null) {
        // No command == list
    } else if (command.equals("/add")) {
        message = add(request, name, smClient);
    } else if (command.equals("/remove")) {
        message = remove(name, smClient);
    } else if (command.equals("/start")) {
        message = start(name, smClient);
    } else if (command.equals("/stop")) {
        message = stop(name, smClient);
    } else {
        //Try GET
        doGet(request, response);
    }

    list(request, response, message, smClient);
}
 
Example 8
Source Project: Tomcat7.0.67   File: ManagerServlet.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @deprecated Use {@link StringManager#getManager(String, Enumeration)}.
 *             This method will be removed in Tomcat 8.
 */
@Deprecated
protected StringManager getStringManager(HttpServletRequest req) {
    Enumeration<Locale> requestedLocales = req.getLocales();
    while (requestedLocales.hasMoreElements()) {
        Locale locale = requestedLocales.nextElement();
        StringManager result = StringManager.getManager(Constants.Package,
                locale);
        if (result.getLocale().equals(locale)) {
            return result;
        }
    }
    // Return the default
    return sm;
}
 
Example 9
Source Project: Tomcat7.0.67   File: HttpMessages.java    License: Apache License 2.0 5 votes vote down vote up
public static HttpMessages getInstance(Locale locale) {
    HttpMessages result = instances.get(locale);
    if (result == null) {
        StringManager sm = StringManager.getManager(
                "org.apache.tomcat.util.http.res", locale);
        if (Locale.getDefault().equals(sm.getLocale())) {
            result = DEFAULT;
        } else {
            result = new HttpMessages(sm);
        }
        instances.put(locale, result);
    }
    return result;
}
 
Example 10
Source Project: scipio-erp   File: LoginServices.java    License: Apache License 2.0 5 votes vote down vote up
private static boolean TomcatSSOLogin(HttpServletRequest request, String userName, String currentPassword) {
    try {
        request.login(userName, currentPassword);
    } catch (ServletException e) {
        StringManager sm = StringManager.getManager("org.apache.catalina.connector");
        if (sm.getString("coyoteRequest.alreadyAuthenticated").equals(e.getMessage())){
            return true;
        } else {
            Debug.logError(e, module);
            return false;
        }
    }
    return true;
}
 
Example 11
Source Project: tomcatsrc   File: HostManagerServlet.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @deprecated Use {@link StringManager#getManager(String, Enumeration)}.
 *             This method will be removed in Tomcat 8.
 */
@Deprecated
protected StringManager getStringManager(HttpServletRequest req) {
    Enumeration<Locale> requestedLocales = req.getLocales();
    while (requestedLocales.hasMoreElements()) {
        Locale locale = requestedLocales.nextElement();
        StringManager result = StringManager.getManager(Constants.Package,
                locale);
        if (result.getLocale().equals(locale)) {
            return result;
        }
    }
    // Return the default
    return sm;
}
 
Example 12
/**
 * Process a GET request for the specified resource.
 *
 * @param request The servlet request we are processing
 * @param response The servlet response we are creating
 *
 * @exception IOException if an input/output error occurs
 * @exception ServletException if a servlet-specified error occurs
 */
@Override
public void doGet(HttpServletRequest request,
                  HttpServletResponse response)
    throws IOException, ServletException {

    StringManager smClient = StringManager.getManager(
            Constants.Package, request.getLocales());

    // Identify the request parameters that we need
    String command = request.getPathInfo();

    // Prepare our output writer to generate the response message
    response.setContentType("text/html; charset=" + Constants.CHARSET);

    String message = "";
    // Process the requested command
    if (command == null) {
        // No command == list
    } else if (command.equals("/list")) {
        // Nothing to do - always generate list
    } else if (command.equals("/add") || command.equals("/remove") ||
            command.equals("/start") || command.equals("/stop")) {
        message = smClient.getString(
                "hostManagerServlet.postCommand", command);
    } else {
        message = smClient.getString(
                "hostManagerServlet.unknownCommand", command);
    }

    list(request, response, message, smClient);
}
 
Example 13
/**
 * Process a POST request for the specified resource.
 *
 * @param request The servlet request we are processing
 * @param response The servlet response we are creating
 *
 * @exception IOException if an input/output error occurs
 * @exception ServletException if a servlet-specified error occurs
 */
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    StringManager smClient = StringManager.getManager(
            Constants.Package, request.getLocales());

    // Identify the request parameters that we need
    String command = request.getPathInfo();

    String name = request.getParameter("name");
 
    // Prepare our output writer to generate the response message
    response.setContentType("text/html; charset=" + Constants.CHARSET);

    String message = "";
    
    // Process the requested command
    if (command == null) {
        // No command == list
    } else if (command.equals("/add")) {
        message = add(request, name, smClient);
    } else if (command.equals("/remove")) {
        message = remove(name, smClient);
    } else if (command.equals("/start")) {
        message = start(name, smClient);
    } else if (command.equals("/stop")) {
        message = stop(name, smClient);
    } else {
        //Try GET
        doGet(request, response);
    }

    list(request, response, message, smClient);
}
 
Example 14
Source Project: tomcatsrc   File: ManagerServlet.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @deprecated Use {@link StringManager#getManager(String, Enumeration)}.
 *             This method will be removed in Tomcat 8.
 */
@Deprecated
protected StringManager getStringManager(HttpServletRequest req) {
    Enumeration<Locale> requestedLocales = req.getLocales();
    while (requestedLocales.hasMoreElements()) {
        Locale locale = requestedLocales.nextElement();
        StringManager result = StringManager.getManager(Constants.Package,
                locale);
        if (result.getLocale().equals(locale)) {
            return result;
        }
    }
    // Return the default
    return sm;
}
 
Example 15
Source Project: tomcatsrc   File: HttpMessages.java    License: Apache License 2.0 5 votes vote down vote up
public static HttpMessages getInstance(Locale locale) {
    HttpMessages result = instances.get(locale);
    if (result == null) {
        StringManager sm = StringManager.getManager(
                "org.apache.tomcat.util.http.res", locale);
        if (Locale.getDefault().equals(sm.getLocale())) {
            result = DEFAULT;
        } else {
            result = new HttpMessages(sm);
        }
        instances.put(locale, result);
    }
    return result;
}
 
Example 16
Source Project: Tomcat8-Source-Read   File: HostManagerServlet.java    License: MIT License 4 votes vote down vote up
/**
 * Process a GET request for the specified resource.
 *
 * @param request The servlet request we are processing
 * @param response The servlet response we are creating
 *
 * @exception IOException if an input/output error occurs
 * @exception ServletException if a servlet-specified error occurs
 */
@Override
public void doGet(HttpServletRequest request,
                  HttpServletResponse response)
    throws IOException, ServletException {

    StringManager smClient = StringManager.getManager(
            Constants.Package, request.getLocales());

    // Identify the request parameters that we need
    String command = request.getPathInfo();
    if (command == null)
        command = request.getServletPath();
    String name = request.getParameter("name");

    // Prepare our output writer to generate the response message
    response.setContentType("text/plain; charset=" + Constants.CHARSET);
    // Stop older versions of IE thinking they know best. We set text/plain
    // in the line above for a reason. IE's behaviour is unwanted at best
    // and dangerous at worst.
    response.setHeader("X-Content-Type-Options", "nosniff");
    PrintWriter writer = response.getWriter();

    // Process the requested command
    if (command == null) {
        writer.println(smClient.getString("hostManagerServlet.noCommand"));
    } else if (command.equals("/add")) {
        add(request, writer, name, false, smClient);
    } else if (command.equals("/remove")) {
        remove(writer, name, smClient);
    } else if (command.equals("/list")) {
        list(writer, smClient);
    } else if (command.equals("/start")) {
        start(writer, name, smClient);
    } else if (command.equals("/stop")) {
        stop(writer, name, smClient);
    } else if (command.equals("/persist")) {
        persist(writer, smClient);
    } else {
        writer.println(smClient.getString("hostManagerServlet.unknownCommand",
                                    command));
    }

    // Finish up the response
    writer.flush();
    writer.close();

}
 
Example 17
@Override
protected String getResponseBodyFrameTrace(int streamId, String body) {
    if (testData.getExpectedStatus() == 200) {
        return super.getResponseBodyFrameTrace(streamId, body);
    } else if (testData.getExpectedStatus() == 400) {
        /*
         * Need to be careful here. The test wants the exact content length
         * in bytes.
         * This will vary depending on where the test is run due to:
         * - The length of the version string that appears once in the error
         *   page
         * - The status header uses a UTF-8 EN dash. When running in an IDE
         *   the UTF-8 properties files will be used directly rather than
         *   after native2ascii conversion.
         *
         * Note: The status header appears twice in the error page.
         */
        int serverInfoLength = ServerInfo.getServerInfo().getBytes().length;
        StringManager sm = StringManager.getManager(
                ErrorReportValve.class.getPackage().getName(), Locale.ENGLISH);
        String reason = sm.getString("http." + testData.getExpectedStatus() + ".reason");
        int descriptionLength = sm.getString("http." + testData.getExpectedStatus() + ".desc")
                .getBytes(StandardCharsets.UTF_8).length;
        int statusHeaderLength = sm
                .getString("errorReportValve.statusHeader",
                        String.valueOf(testData.getExpectedStatus()), reason)
                .getBytes(StandardCharsets.UTF_8).length;
        int typeLabelLength = sm.getString("errorReportValve.type")
                .getBytes(StandardCharsets.UTF_8).length;
        int statusReportLabelLength = sm.getString("errorReportValve.statusReport")
                .getBytes(StandardCharsets.UTF_8).length;
        int descriptionLabelLength = sm.getString("errorReportValve.description")
                .getBytes(StandardCharsets.UTF_8).length;
        // 196 bytes is the static length of the pure HTML code from the ErrorReportValve
        int len = 196 + org.apache.catalina.util.TomcatCSS.TOMCAT_CSS
                .getBytes(StandardCharsets.UTF_8).length +
                typeLabelLength + statusReportLabelLength + descriptionLabelLength +
                descriptionLength + serverInfoLength + statusHeaderLength * 2;
        String contentLength = String.valueOf(len);
        return getResponseBodyFrameTrace(streamId,
                testData.getExpectedStatus(), "text/html;charset=utf-8",
                "en", contentLength, contentLength);
    } else {
        Assert.fail();
        // To keep the IDE happy
        return null;
    }
}
 
Example 18
Source Project: Tomcat7.0.67   File: HostManagerServlet.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Process a GET request for the specified resource.
 *
 * @param request The servlet request we are processing
 * @param response The servlet response we are creating
 *
 * @exception IOException if an input/output error occurs
 * @exception ServletException if a servlet-specified error occurs
 */
@Override
public void doGet(HttpServletRequest request,
                  HttpServletResponse response)
    throws IOException, ServletException {

    StringManager smClient = StringManager.getManager(
            Constants.Package, request.getLocales());

    // Identify the request parameters that we need
    String command = request.getPathInfo();
    if (command == null)
        command = request.getServletPath();
    String name = request.getParameter("name");
  
    // Prepare our output writer to generate the response message
    response.setContentType("text/plain; charset=" + Constants.CHARSET);
    PrintWriter writer = response.getWriter();

    // Process the requested command
    if (command == null) {
        writer.println(sm.getString("hostManagerServlet.noCommand"));
    } else if (command.equals("/add")) {
        add(request, writer, name, false, smClient);
    } else if (command.equals("/remove")) {
        remove(writer, name, smClient);
    } else if (command.equals("/list")) {
        list(writer, smClient);
    } else if (command.equals("/start")) {
        start(writer, name, smClient);
    } else if (command.equals("/stop")) {
        stop(writer, name, smClient);
    } else {
        writer.println(sm.getString("hostManagerServlet.unknownCommand",
                                    command));
    }

    // Finish up the response
    writer.flush();
    writer.close();

}
 
Example 19
Source Project: tomcatsrc   File: HostManagerServlet.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Process a GET request for the specified resource.
 *
 * @param request The servlet request we are processing
 * @param response The servlet response we are creating
 *
 * @exception IOException if an input/output error occurs
 * @exception ServletException if a servlet-specified error occurs
 */
@Override
public void doGet(HttpServletRequest request,
                  HttpServletResponse response)
    throws IOException, ServletException {

    StringManager smClient = StringManager.getManager(
            Constants.Package, request.getLocales());

    // Identify the request parameters that we need
    String command = request.getPathInfo();
    if (command == null)
        command = request.getServletPath();
    String name = request.getParameter("name");
  
    // Prepare our output writer to generate the response message
    response.setContentType("text/plain; charset=" + Constants.CHARSET);
    PrintWriter writer = response.getWriter();

    // Process the requested command
    if (command == null) {
        writer.println(sm.getString("hostManagerServlet.noCommand"));
    } else if (command.equals("/add")) {
        add(request, writer, name, false, smClient);
    } else if (command.equals("/remove")) {
        remove(writer, name, smClient);
    } else if (command.equals("/list")) {
        list(writer, smClient);
    } else if (command.equals("/start")) {
        start(writer, name, smClient);
    } else if (command.equals("/stop")) {
        stop(writer, name, smClient);
    } else {
        writer.println(sm.getString("hostManagerServlet.unknownCommand",
                                    command));
    }

    // Finish up the response
    writer.flush();
    writer.close();

}