All Downloads are FREE. Search and download functionalities are using the official Maven repository.

bichromate.tools.MainServlet Maven / Gradle / Ivy

Go to download

Java, Selenium, Appium, Winium, Extend, and TestNG automated testing framework. Bichromate integrates the best of these frameworks and takes automation to the next level. With Bichromate there is one function call that builds any type of Web,IOS Mobile, Android, and Windows App driver on any platform (Windows, Mac, Linux). From Local web drivers, to SauceLabs, Browserstack, and Selenium grid. Build data driven tests is never easier. Bichromate also gives you built in Factories that, access DBs, Video Capture, FTP, POM Generation, Hilite element.

There is a newer version: 3.13
Show newest version
/*******************************************************************************
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 ******************************************************************************/

package bichromate.tools;

import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.*;


/**
 * This is the main servlet for testing our load testing program. This servlet
 * is just a simple demo so we have something to test against. This server will
 * show the form MainForm.html on get requests and display the parameters on put
 * and post requests.
 */
public class MainServlet extends HttpServlet
{
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/**
     * This is the default content type for an HTML file.
     */
    static final String CONTENT_TYPE = "text/html";

    /**
     * This method handles GET requests from the browser or the load client.
     * This method will load the return the text of MainForm.html
     * 
     * @param request
     *        the http request
     * @param response
     *        the http response
     * @throws ServletException - failed to create servlet
     * @throws IOException - failed to execute http request 
     */
    public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException,
            IOException
    {
        response.setContentType(CONTENT_TYPE);
        PrintWriter out = response.getWriter();

        out.print(getMainForm());
        out.flush();
        out.close();
    }

    /**
     * This method handles POST requests from the browser or the load client.
     * This method will just print out the parameters which were passed followed
     * by the text "Everything worked fine". That is the text the load client
     * will look for.
     * 
     * @param request
     *        the http request
     * @param response
     *        the http response
     * @throws ServletException - failed to create servlet
     * @throws IOException - failed to execute http request 
     */
    public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException,
            IOException
    {
        response.setContentType(CONTENT_TYPE);
        PrintWriter out = response.getWriter();

        out.println("");

        Enumeration params = request.getParameterNames();
        do {
            String name = (String) params.nextElement();
            out.print(name);
            out.print(": ");
            String vals[] = request.getParameterValues(name);
            for (int i = 0; i < vals.length; i++) {
                out.print(vals[i]);
                out.print(", ");
            }
            out.println("
"); } while (params.hasMoreElements()); out.println("

Everything worked fine"); out.println(""); out.flush(); out.close(); } /** * This method handles PUT requests from the browser or the load client. In * this servlet the doPut method just calls doPost. * * @param request * the http request * @param response * the http response * @throws ServletException - failed to create servlet * @throws IOException - failed to execute http request */ public void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request, response); } /** * A static variable for holding onto the main form's text. */ private static String g_mainForm = null; /** * We want to load the text of the main form, but we only want to load it * once. * * @return the HTML text of the form for the get method */ private String getMainForm() { if (g_mainForm == null) { StringBuffer out = new StringBuffer(); try { ClassLoader cl = this.getClass().getClassLoader(); InputStream input = cl.getResourceAsStream("loadtest/server/MainForm.html"); /* * It is just a good practice to use an InputStreamReader in * case there are any international characters. This will read * them with the system's default encoding. */ InputStreamReader in = new InputStreamReader(input); try { int read; char[] buf = new char[512]; while ((read = in.read(buf)) > 0) { out.append(buf, 0, read); } } finally { /* * It is important to make sure that we close the * inputstream once we are done with it. */ if (in != null) { in.close(); } } } catch (IOException e) { e.printStackTrace(); return null; } g_mainForm = out.toString(); } return g_mainForm; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy