process an HTML get or post.
@exception ServletException From inherited class.
@exception IOException From inherited class.
11736
public void service(HttpServletRequest req, HttpServletResponse res) 
        throws ServletException, IOException
    {
        String regex = this.getProperty(REGEX);
        String server = req.getServerName();
        if (regex != null)
        	if (server != null)
        {
        	String match = null;
        	if (regex.indexOf('/') != -1)
        	{
        	    match = regex.substring(regex.indexOf('/'));
        	    regex = regex.substring(0, regex.indexOf('/'));
        	}
        	if (server.matches(regex))
	        {
        		String target = this.getProperty(REGEX_TARGET);
        		if (target != null)
        		{
        	        if (logger != null)
        	        	logger.info("Redirect " + server + " to " + target);
                    String requestPath = req.getServletPath();
        	        if ((match == null) || (requestPath.matches(match)))
        	        	res.sendRedirect(target);
        	        else
        	        {
        	            boolean fileFound = sendResourceFile(req, res);
        	            if (!fileFound)
        	                res.sendError(HttpServletResponse.SC_NOT_FOUND, "File not found");
        	        }
                    return;
        		}
	        }
        }
    	super.service(req, res);
    }
1186880
@Override
    public void init() throws ServletException {
        super.init();

        // GET
        operations.setOperation(ServletOperationSet.Method.GET, Extension.json,
            Operation.list, new ListOperation());
        operations.setOperation(ServletOperationSet.Method.GET, Extension.json,
                Operation.tree, new TreeOperation());
        operations.setOperation(ServletOperationSet.Method.GET, Extension.json,
                Operation.query, new QueryOperation());
        operations.setOperation(ServletOperationSet.Method.GET, Extension.json,
                Operation.filterList, new ListFiltersOperation());
        operations.setOperation(ServletOperationSet.Method.GET, Extension.json,
                Operation.coverage, new CoverageOperation());
        operations.setOperation(ServletOperationSet.Method.GET, Extension.zip,
                Operation.download, new DownloadOperation());
        operations.setOperation(ServletOperationSet.Method.GET, Extension.html,
                Operation.download, new DownloadOperation());

        // POST
        operations.setOperation(ServletOperationSet.Method.POST, Extension.html,
                Operation.service, new ServiceOperation());

        operations.setOperation(ServletOperationSet.Method.POST, Extension.json,
                Operation.create, new CreateOperation());
        operations.setOperation(ServletOperationSet.Method.POST, Extension.json,
                Operation.update, new UpdateOperation());
        operations.setOperation(ServletOperationSet.Method.POST, Extension.json,
                Operation.upload, new UploadOperation());
        operations.setOperation(ServletOperationSet.Method.POST, Extension.json,
                Operation.install, new InstallOperation());
        operations.setOperation(ServletOperationSet.Method.POST, Extension.json,
            Operation.uninstall, new UninstallOperation());
        operations.setOperation(ServletOperationSet.Method.POST, Extension.json,
                Operation.deploy, new ServiceOperation());

        operations.setOperation(ServletOperationSet.Method.POST, Extension.html,
                Operation.filterChange, new ChangeFilterOperation());
        operations.setOperation(ServletOperationSet.Method.POST, Extension.html,
                Operation.filterAdd, new AddFilterOperation());
        operations.setOperation(ServletOperationSet.Method.POST, Extension.html,
                Operation.filterRemove, new RemoveFilterOperation());
        operations.setOperation(ServletOperationSet.Method.POST, Extension.html,
                Operation.filterMoveUp, new MoveFilterOperation(true));
        operations.setOperation(ServletOperationSet.Method.POST, Extension.html,
                Operation.filterMoveDown, new MoveFilterOperation(false));

        // PUT
        operations.setOperation(ServletOperationSet.Method.PUT, Extension.json,
                Operation.update, new JsonUpdateOperation());

        // DELETE
        operations.setOperation(ServletOperationSet.Method.DELETE, Extension.json,
                Operation.delete, new DeleteOperation());
    }
194614
public void doGet(HttpServletRequest request, HttpServletResponse response) 
        throws ServletException, IOException
    {
        response.setContentType("text/html");
        response.setHeader("Pragma", "no-cache");
        response.setHeader("Cache-Control", "no-cache,no-store");

        String url=request.getParameter("URL");
        if (url!=null && url.length()>0)
        {
            response.sendRedirect(url);
        }
        else
        {
            PrintWriter pout = response.getWriter();
            Page page=null;
            
            try{
                page = new Page();
                page.title("SendRedirect Servlet");     
                
                page.add(new Heading(1,"SendRedirect Servlet"));
                
                page.add(new Heading(1,"Form to generate Dump content"));
                TableForm tf = new TableForm
                    (response.encodeURL(URI.addPaths(request.getContextPath(),
                                                     request.getServletPath())+
                                        "/action"));
                tf.method("GET");
                tf.addTextField("URL","URL",40,request.getContextPath()+"/dump");
                tf.addButton("Redirect","Redirect");
                page.add(tf);
                page.write(pout);
                pout.close();
            }
            catch (Exception e)
            {
                log.warn(LogSupport.EXCEPTION,e);
            }
        }
    }
319166
protected final OutputStream getHTMLOutputStream(WebSiteRequest req, HttpServletResponse resp) throws IOException {
		resp.setContentType("text/html");
		resp.setCharacterEncoding("UTF-8");
		String[] headers=getAdditionalHeaders(req);
		if(headers!=null) {
			int len=headers.length;
			for(int c=0; c<len; c+=2) resp.setHeader(headers[c], headers[c+1]);
		}
		return resp.getOutputStream();
	}
227543
@Override
    public void doGet(HttpServletRequest request,
            HttpServletResponse response)
            throws IOException, ServletException {
        super.doGet(request, response);
        String target = request.getPathInfo();
        if (target == null) target = "/";
        try {
            unauthenticate(request);
            response.setContentType(HTML_CONTENT_TYPE);
            response.sendRedirect("/");
        } catch (Exception ex) {
            rateLimitedLogWarn("Not servicing url: %s Details: ", target, ex.getMessage());
            response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
            response.getWriter().print(buildClientResponse(null, ClientResponse.UNEXPECTED_FAILURE, Throwables.getStackTraceAsString(ex)));
        }
    }
676224
protected void service(HttpServletRequest request, HttpServletResponse response)
	throws ServletException, IOException
    {
        // Get the requested path and info
        boolean included=false;
        String servlet_path=(String)request.getAttribute(Dispatcher.__INCLUDE_SERVLET_PATH);
        if (servlet_path==null)
            servlet_path=request.getServletPath();
        else
            included=true;
        String path_info = (String)request.getAttribute(Dispatcher.__INCLUDE_PATH_INFO);
        if (path_info==null)
            path_info=request.getPathInfo();
        
        // Get the servlet class
        String servlet = path_info;
        if (servlet==null || servlet.length()<=1 )
        {
            response.sendError(404);
            return;
        }
        
        int i0=servlet.charAt(0)=='/'?1:0;
        int i1=servlet.indexOf('/',i0);
        servlet=i1<0?servlet.substring(i0):servlet.substring(i0,i1);

        // look for a named holder
        ServletHolder holder=_servletHandler.getServletHolder(servlet);
        if (holder!=null)
        {
            // Add named servlet mapping
            _servletHandler.addServletHolder(holder);
            _servletHandler.mapPathToServlet(URI.addPaths(servlet_path,servlet)+"/*", holder.getName());
        }
        else
        {
            // look for a class mapping
            if (servlet.endsWith(".class"))
                servlet=servlet.substring(0,servlet.length()-6);
            if (servlet==null || servlet.length()==0)
            {
                response.sendError(404);
                return;
            }   
        
            synchronized(_servletHandler)
            {
                // find the entry for the invoker
                if (_invokerEntry==null)
                    _invokerEntry=_servletHandler.getHolderEntry(servlet_path);
            
                // Check for existing mapping (avoid threaded race).
                String path=URI.addPaths(servlet_path,servlet);
                Map.Entry entry = _servletHandler.getHolderEntry(path);

                if (entry!=null && entry!=_invokerEntry)
                {
                    // Use the holder
                    holder=(ServletHolder)entry.getValue();       
                }
                else
                {
                    // Make a holder
                    holder=new ServletHolder(_servletHandler,servlet,servlet);
                    
                    if (_parameters!=null)
                        holder.putAll(_parameters);
                    
                    try {holder.start();}
                    catch (Exception e)
                    {
                        log.debug(LogSupport.EXCEPTION,e);
                        throw new UnavailableException(e.toString());
                    }
                    
                    // Check it is from an allowable classloader
                    if (!_nonContextServlets)
                    {
                        Object s=holder.getServlet();
                        
                        if (_servletHandler.getClassLoader()!=
                            s.getClass().getClassLoader())
                        {
                            holder.stop();
                            log.warn("Dynamic servlet "+s+
                                         " not loaded from context "+
                                         request.getContextPath());
                            throw new UnavailableException("Not in context");
                        }
                    }

                    // Add the holder for all the possible paths
                    if (_verbose)
                        log("Dynamic load '"+servlet+"' at "+path);
                    _servletHandler.addServletHolder(holder);
                    _servletHandler.mapPathToServlet(path+"/*",holder.getName());
                    _servletHandler.mapPathToServlet(path+".class/*",holder.getName());
                }
            }
            
        }
        
        if (holder!=null)
            holder.handle(new Request(request,included,servlet,servlet_path,path_info),
                          response);
        else
            response.sendError(404);
        
    }
297718
public int doEndTag() throws JspException
    {
        ServletRequest req = pageContext.getRequest();

        // Create an appropriate "input" element based on our parameters
        if (_password) {
            _state.type = INPUT_PASSWORD;
        }
        else {
            _state.type = INPUT_TEXT;
        }


        // Create the state for the input tag
        ByRef ref = new ByRef();
        nameHtmlControl(_state, ref);

        _state.disabled = isDisabled();

        // Create the text value of the TextBox
        Object textObject = evaluateDataSource();
        if ((textObject == null) || (textObject.toString().length() == 0)) {
            textObject = _defaultValue;
        }

        // Get the text value for the textbox, the result
        String text = null;
        if (textObject != null) {
            text = formatText(textObject);
            InternalStringBuilder sb = new InternalStringBuilder(text.length() + 16);
            StringBuilderRenderAppender sbAppend = new StringBuilderRenderAppender(sb);
            HtmlUtils.filter(text, sbAppend);
            text = sb.toString();
        }
        _state.value = text;

        // if there were format errors then report them
        if (_formatErrors) {
            if (bodyContent != null) {
                String value = bodyContent.getString().trim();
                bodyContent.clearBody();
                write(value);
            }
        }

        if (hasErrors())
            return reportAndExit(EVAL_PAGE);

        // create the input tag.
        WriteRenderAppender writer = new WriteRenderAppender(pageContext);
        TagRenderingBase br = TagRenderingBase.Factory.getRendering(TagRenderingBase.INPUT_TEXT_TAG, req);
        assert(br != null);

        br.doStartTag(writer, _state);
        br.doEndTag(writer);

        // write any script that needs to be written
        if (!ref.isNull())
            write((String) ref.getRef());

        localRelease();
        return EVAL_PAGE;
    }
1002080
public void doProcessOutput(BasicServlet servlet, HttpServletRequest req, HttpServletResponse res, PrintWriter outExt, ScreenModel screen) 
        throws ServletException, IOException
    {
        PrintWriter out = outExt;
        if (screen == null)
        {
        	if (out != null)
        		out.println("Error: default screen not available");
        }
        else
        {
            try
            { // create and execute the query
                // if no parameters, just print the form
                String strDatatype = this.getProperty(DBParams.DATATYPE); // Raw data (such as in image from the DB)
                if (strDatatype == null)
                {
                    if (out == null)
                        out = servlet.getOutputStream(res); // Always
                    ((ScreenModel)screen).printReport(out);
                }
                else
                {       // Raw data output
                    ((ScreenModel)screen).getScreenFieldView().sendData(req, res);
                }
                screen.free();
                screen = null;
            }
            catch (DBException ex) {
                if (out != null)
                {
                    out.println("<hr>*** SQLException caught ***<p>");
                    out.println("Message:  " + ex.getMessage() + "<br>");
                    ex.printStackTrace(out);
                }
                ex.printStackTrace();
            }
            catch (java.lang.Exception ex) {
                ex.printStackTrace();
            } finally {
            	if (outExt == null)
            		if (out != null)
            			out.close();
            }
        }
    }
1241772
@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		Window window = new Window();
		window.add(new Text("Hello world!"));
		
		Reflector<Component> reflector = new HtmlComponentReflector();
		response.setContentType(reflector.getContentType());
		
		try
		{
			reflector.reflect(window, response.getWriter());
		}
		catch (ReflectorException exception)
		{
			throw new ServletException("Error writing component", exception);
		}
	}
1176001
protected void process(HttpServletRequest request, HttpServletResponse response, String fileName)
            throws IOException {
        // TODO put this html code in a template
        response.setContentType("text/html");
        response.setCharacterEncoding("UTF-8");
        response.setStatus(200);
        FileBackedStringBuffer buffer = new FileBackedStringBuffer();

        buffer.append("<html><head><title>");
        buffer.append(request.getRemoteHost());
        buffer.append("</title><script type=text/javascript>");
        buffer.append("function submitform() { document.myform.submit(); } </script>");
        buffer.append("</head><body><H1>View Logs on - ");
        buffer.append(request.getRemoteHost()).append("</H1>");

        if (isLogsDirectoryEmpty()) {
            buffer.append("<br>No Logs available.</br></body></html>");
            dumpStringToStream(buffer, response.getOutputStream());
            return;
        }
        buffer.append(appendMoreLogsLink(fileName, request.getRequestURL().toString()));
        buffer.append(renderLogFileContents(fileName));
        buffer.append("</body></html>");
        dumpStringToStream(buffer, response.getOutputStream());
    }
527378
@Override
    public void service(final ServletRequest req, final ServletResponse resp) throws ServletException, IOException {
        HttpServletRequest request = (HttpServletRequest) req;
        HttpServletResponse response = (HttpServletResponse) resp;

        final String beanName = request.getPathInfo().substring(1); // remove "/"
        htorp.process(beanName, request, response);
    }
321714
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        List<FileItem> items;
        // Parse the request
        try {
            items = upload.parseRequest(request);
        } catch (FileUploadException e) {
            throw new ServletException(e);
        }

        String repository = getParameter(items, REPOSITORY_NAME_PARAMETER);
        String workspace = getParameter(items, WORKSPACE_NAME_PARAMETER);
        String path = getParameter(items, NODE_PATH_PARAMETER);
        String pname = getParameter(items, PROPERTY_NAME_PARAMETER);
        
        if (logger.isDebugEnabled()) {
            logger.debug(String.format("Upload %s at %s/%s%s", 
                    pname, repository, workspace, path));
        }
        
        String mimeType = getContentType(items);
        Connector connector = (Connector) 
                request.getSession().getAttribute(REPOSITORY_CONNECTOR);
        
        try {
            Session session = connector.find(repository).session(workspace);
            ValueFactory valueFactory = session.getValueFactory(); 
            Binary bin = valueFactory.createBinary(getStream(items));
            
            Node node = session.getNode(path);
            node.setProperty(pname, bin);
            node.setProperty(MIME_TYPE, mimeType);
            bin.dispose();
        } catch (Exception e) {
            throw new ServletException(e);
        }
        
        String uri = request.getContextPath() + 
                String.format(DESTINATION_URL, repository, workspace, path);
        response.sendRedirect(uri);
    }
638983
public void doGet(HttpServletRequest sreq, HttpServletResponse sres) 
        throws ServletException, IOException
    {
        String path = (String)
            sreq.getAttribute("javax.servlet.include.servlet_path");
        if (path==null)
            path=sreq.getServletPath();
        if (path.length()==0)
        {
            path=(String)sreq.getAttribute("javax.servlet.include.path_info");
            if (path==null)
                path=sreq.getPathInfo();
        }

        String forward=(String)_forwardMap.get(path);
        if(log.isDebugEnabled())log.debug("Forward "+path+" to "+forward);
        if (forward!=null)
        {            
            ServletContext context =
                getServletContext().getContext(forward);
            String contextPath=sreq.getContextPath();
            if (contextPath.length()>1)
                forward=forward.substring(contextPath.length());
            
            RequestDispatcher dispatch =
                context.getRequestDispatcher(forward);
            if (dispatch!=null)
            {
                dispatch.forward(sreq,sres);
                return;
            }
        }

        sres.sendError(404);
    }
602910
@RequestMapping(method = RequestMethod.POST)
    @ResponseBody
    protected final String process(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
//        if(StrUtil.isBlank(legalStr(request))){
//            return "";
//        }
        String result = processRequest(request);
        response.getWriter().write(result);
        return null;
    }
326487
protected void processRequest(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {

        //get user's credentials from the request
        String uname = request.getParameter("j_username");
        String pass = request.getParameter("j_password");

        try {
            //validate given user using container's login mechanism
            request.login(uname, pass);

            ServletContext context = getServletConfig().getServletContext();
            
            //put user's credentials in the servlet context
            context.setAttribute("uname", uname);
            context.setAttribute("password", pass);
            
            //forward request to the initial page
            response.sendRedirect(request.getContextPath() + "/Console.html");
        } catch (ServletException e) {
            //login failed to forward user to the login form
            response.sendRedirect(request.getContextPath() + "/loginform.html");
        }
    }
1232948
protected void initServlet(XmlParser.Node node) throws ClassNotFoundException,UnavailableException,IOException,
            MalformedURLException
    {
        String name=node.getString("servlet-name",false,true);
        String className=node.getString("servlet-class",false,true);
        String jspFile=null;
        Holder template=null;
        if(className==null)
        {
            // There is no class, so look for a jsp file
            jspFile=node.getString("jsp-file",false,true);
            if(jspFile!=null)
            {
                Map.Entry entry=getWebApplicationHandler().getHolderEntry(jspFile);
                if(entry!=null)
                {
                    template = (Holder)entry.getValue();
                    className=template.getClassName();  
                }
            }
            if(className==null)
            {
                log.warn("Missing servlet-class|jsp-file in "+node);
                return;
            }
        }
        if(name==null)
            name=className;
        ServletHolder holder=getWebApplicationHandler().newServletHolder(name,className,jspFile);

        // handle JSP configuration
        if(jspFile!=null)
        {
            Enumeration e=template.getInitParameterNames();
            
            while(e.hasMoreElements())
            {   
                String p=(String)e.nextElement();
                holder.setInitParameter(p, template.getInitParameter(p));
            }
            if (holder.getInitParameter("classpath")==null)
                holder.setInitParameter("classpath",getWebApplicationContext().getFileClassPath());
        }
       
        // handle init params
        Iterator iParamsIter=node.iterator("init-param");
        while(iParamsIter.hasNext())
        {
            XmlParser.Node paramNode=(XmlParser.Node)iParamsIter.next();
            String pname=paramNode.getString("param-name",false,true);
            String pvalue=paramNode.getString("param-value",false,true);
            holder.put(pname,pvalue);
        }
        XmlParser.Node startup=node.get("load-on-startup");
        if(startup!=null)
        {
            String s=startup.toString(false,true).toLowerCase();
            if(s.startsWith("t"))
            {
                log.warn("Deprecated boolean load-on-startup.  Please use integer");
                holder.setInitOrder(1);
            }
            else
            {
                int order=0;
                try
                {
                    if(s!=null&&s.trim().length()>0)
                        order=Integer.parseInt(s);
                }
                catch(Exception e)
                {
                    log.warn("Cannot parse load-on-startup "+s+". Please use integer");
                    LogSupport.ignore(log,e);
                }
                holder.setInitOrder(order);
            }
        }
        Iterator sRefsIter=node.iterator("security-role-ref");
        while(sRefsIter.hasNext())
        {
            XmlParser.Node securityRef=(XmlParser.Node)sRefsIter.next();
            String roleName=securityRef.getString("role-name",false,true);
            String roleLink=securityRef.getString("role-link",false,true);
            if(roleName!=null&&roleName.length()>0&&roleLink!=null&&roleLink.length()>0)
            {
                if(log.isDebugEnabled())
                    log.debug("link role "+roleName+" to "+roleLink+" for "+this);
                holder.setUserRoleLink(roleName,roleLink);
            }
            else
            {
                log.warn("Ignored invalid security-role-ref element: "+"servlet-name="+name+", "+securityRef);
            }
        }
        XmlParser.Node run_as=node.get("run-as");
        if(run_as!=null)
        {
            String roleName=run_as.getString("role-name",false,true);
            if(roleName!=null)
                holder.setRunAs(roleName);
        }
    }
771166
protected void doCancel(javax.servlet.sip.SipServletRequest req) throws javax.servlet.ServletException, java.io.IOException{
       
    }