Process an HTML get or post.
@exception ServletException From inherited class.
@exception IOException From inherited class.
348819
public void doProcess(HttpServletRequest req, HttpServletResponse res) 
        throws ServletException, IOException
    {
        try {
            res.setDateHeader("Expires", 0);        // Make sure the browser never caches these requests
            res.setHeader("Pragma", "No-cache");
            res.setHeader("Cache-Control", "no-cache");
            m_servletTask.doProcess(this, req, res, null);
        } catch (Throwable ex)  {
            ex.printStackTrace();
        }
    }
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);
    }
838992
@Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {

        String url = this.getURL(req);

        LOGGER.debug("Started processing request : {}", url);

        List<String> resourcesToMerge = findResourcesToMerge(req.getContextPath(), url);
        String extensionOrPath = detectExtension(url);//in case of non js/css files it null
        if (extensionOrPath.isEmpty()) {
            extensionOrPath = resourcesToMerge.get(0);//non grouped i.e. non css/js file, we refer it's path in that case
        }

        //If not modified, return 304 and stop
        ResourceStatus status = JSCSSMergeServlet.isNotModified(this.getServletContext(), req, resourcesToMerge, this.turnOffETag);
        if (status.isNotModified()) {
            LOGGER.trace("Resources Not Modified. Sending 304.");
            String ETag = !this.turnOffETag ? status.getActualETag() : null;
            JSCSSMergeServlet.sendNotModified(resp, extensionOrPath, ETag, this.expiresMinutes, this.cacheControl, this.overrideExistingHeaders);
            return;
        }


        //Add appropriate headers
        this.addAppropriateResponseHeaders(extensionOrPath, resourcesToMerge, status.getActualETag(), resp);

        OutputStream outputStream = resp.getOutputStream();
        String contextPathForCss = customContextPathForCSSUrls != null ?
                customContextPathForCSSUrls : req.getContextPath();
        ProcessedResult processedResult = this.processResources(contextPathForCss, outputStream, resourcesToMerge);
        int resourcesNotFound = processedResult.getNumberOfMissingResources();

        if (resourcesNotFound > 0 && resourcesNotFound == resourcesToMerge.size()) { //all resources not found
            resp.sendError(HttpServletResponse.SC_NOT_FOUND);
            LOGGER.warn("All resources are not found. Sending 404.");
            return;
        }
        if (outputStream != null) {
            try {
                resp.setStatus(HttpServletResponse.SC_OK);
                outputStream.close();
            } catch (Exception e) {
                // ignore
            }
        }
        resp.setHeader("Content-Length", String.valueOf(processedResult.contentLength));
        LOGGER.debug("Finished processing Request : {}", url);
    }
502681
public void doPost (HttpServletRequest request, HttpServletResponse response)
    		throws ServletException, IOException {
        String alertId = request.getParameter("alertId");
        String tel = request.getParameter("tel");
        String alertText = request.getParameter("alertText");        
        if(alertText == null || alertText.length() < 1) {
	        // Get the content of the request as the text to parse
	        byte[] content = new byte[request.getContentLength()];
	        request.getInputStream().read(content,0, request.getContentLength());        
	        alertText = new String(content); 	        
        }
        if(logger.isInfoEnabled()) {
        	logger.info("Got an alert : \n alertID : " + alertId + " \n tel : " + tel + " \n text : " +alertText);
        }
        // 
        try {
        	Properties jndiProps = new Properties();			
			Context initCtx = new InitialContext(jndiProps);
			// Commented out since the preferred way is through SMS Servlets
//        	SleeConnectionFactory factory = (SleeConnectionFactory) initCtx.lookup("java:/MobicentsConnectionFactory");
//        	
//			SleeConnection conn1 = factory.getConnection();
//			ExternalActivityHandle handle = conn1.createActivityHandle();
//
//			EventTypeID requestType = conn1.getEventTypeID(
//					EVENT_TYPE,
//					"org.mobicents", "1.0");
//			SmsAlertingCustomEvent smsAlertingCustomEvent = new SmsAlertingCustomEvent(alertId, tel, alertText);
//			
//			conn1.fireEvent(smsAlertingCustomEvent, requestType, handle, null);
//			conn1.close();
		} catch (Exception e) {
			logger.error("unexpected exception while firing the event " + EVENT_TYPE + " into jslee", e);
		}	
        
        sendHttpResponse(response, OK_BODY);
    }
288833
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 incBinaries = getParameter(items, INCLUDE_BINARY_PARAMETER);
        String reindexOnFinish = getParameter(items, REINDEX_ON_FINISH_PARAMETER);

        RestoreParams params = new RestoreParams();
        params.setIncludeBinaries(Boolean.valueOf(incBinaries));
        params.setReindexOnFinish(Boolean.valueOf(reindexOnFinish));
        
        InputStream in = getStream(items);

        File dir = new File(tempDir.getAbsolutePath() + File.pathSeparator + 
                Long.toString(System.currentTimeMillis()));
        
        FileUtil.unzip(in, dir.getAbsolutePath());
        Connector connector = (Connector) request.getSession().getAttribute(REPOSITORY_CONNECTOR);

        try {
            connector.find(repository).restore(dir.getAbsolutePath(), params);
        } catch (Exception e) {
            throw new ServletException(e);
        }

        String uri = request.getContextPath()
                + String.format(DESTINATION_URL, repository);
        response.sendRedirect(uri);
    }
886941
protected void doGet(HttpServletRequest request,
                         HttpServletResponse response)
        throws ServletException, IOException
    {
        if (processStatus(request, response)) {
            return;
        }
        
        if (!isRunning()) {
            int errorCode = mProperties.getInt("startup.codes.error", 503);
            response.sendError(errorCode);
            return;
        }
        
        if (mUseSpiderableRequest) {
            request = new SpiderableRequest(request,
                                            mQuerySeparator,
                                            mParameterSeparator,
                                            mValueSeparator);
        }

        // start transaction
        TeaServletTransaction tsTrans = 
            getEngine().createTransaction(request, response, true);
    
        // load associated request/response
        ApplicationRequest appRequest = tsTrans.getRequest();
        ApplicationResponse appResponse = tsTrans.getResponse();

        // process template
        processTemplate(appRequest, appResponse);
        appResponse.finish();
        
        // flush the output
        response.flushBuffer();
    }
556701
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {
        String servletPath = (String) request.getAttribute(Dispatcher.__INCLUDE_SERVLET_PATH);
        String pathInfo = null;
        if (servletPath == null)
        {
            servletPath = request.getServletPath();
            pathInfo = request.getPathInfo();
        }
        else
            pathInfo = (String) request.getAttribute(Dispatcher.__INCLUDE_PATH_INFO);

        String pathInContext = URI.addPaths(servletPath, pathInfo);
                
        boolean endsWithSlash = pathInContext.endsWith("/");
        Resource resource = getResource(pathInContext);

        // Is the method allowed?
        String method = request.getMethod();
        if (_AllowString.indexOf(method) < 0)
        {
            if (resource != null && resource.exists())
            {
                response.setHeader(HttpFields.__Allow, _AllowString);
                response.sendError(HttpResponse.__405_Method_Not_Allowed);
            }
            else
                response.sendError(HttpResponse.__404_Not_Found);
            return;
        }

        // Handle the request
        try
        {
            // handle by method.
            if (method.equals(HttpRequest.__GET) || method.equals(HttpRequest.__POST) || method.equals(HttpRequest.__HEAD))
                handleGet(request, response, pathInContext, resource, endsWithSlash);
            else if (_putAllowed && method.equals(HttpRequest.__PUT))
                handlePut(request, response, pathInContext, resource);
            else if (_delAllowed && method.equals(HttpRequest.__DELETE))
                handleDelete(request, response, pathInContext, resource);
            else if (_putAllowed && _delAllowed && method.equals(HttpRequest.__MOVE))
                handleMove(request, response, pathInContext, resource);
            else if (method.equals(HttpRequest.__OPTIONS))
                handleOptions(request, response);
            else if (method.equals(HttpRequest.__TRACE))
                _servletHandler.handleTrace(request, response);
            else
            {
                // anything else...
                try
                {
                    if (resource.exists())
                        response.sendError(HttpResponse.__501_Not_Implemented);
                    else
                        _servletHandler.notFound(request, response);
                }
                catch (Exception e)
                {
                    LogSupport.ignore(log, e);
                }
            }
        }
        catch (IllegalArgumentException e)
        {
            LogSupport.ignore(log, e);
        }
        finally
        {
            if (resource != null && !(resource instanceof CachedResource))
                resource.release();
        }

    }
372326
public void doTag()
            throws JspException, IOException
    {
        PageContext pageContext = getPageContext();
        HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
        TagRenderingBase br = TagRenderingBase.Factory.getRendering(TagRenderingBase.BASE_TAG, request);

        // evaluate the body, this is called basically so any attributes my be applied.
        getBufferBody(false);

        InternalStringBuilder buf = new InternalStringBuilder(64);

        // calculate the href
        buf.append(request.getScheme());
        buf.append("://");
        buf.append(request.getServerName());

        String scheme = request.getScheme();
        int port = request.getServerPort();
        if ("http".equals(scheme) && (80 == port)) {
            //Do nothing
        }
        else if ("https".equals(scheme) && (443 == port)) {
            //Do nothing
        }
        else {
            buf.append(":");
            buf.append(request.getServerPort());
        }
        buf.append(request.getRequestURI());
        _state.href = buf.toString();

        // render the tag.
        WriteRenderAppender writer = new WriteRenderAppender(pageContext);
        br.doStartTag(writer, _state);
        br.doEndTag(writer);

        // This will produce invalid HTML/XHTML if there are errors
        // because we are going to put markup out into the head.
        if (hasErrors())
            reportErrors();
    }
86944
public void process(File input) throws IOException {
        File filtered = getFilteredVersion(input);
        if (filtered == null) {
            // It was not copied.
            getLog().warn("Cannot find the filtered version of " + input.getAbsolutePath() + ", " +
                    "using source file.");
            filtered = input;
        }

        // Actual processing.
        String result = instance.markdownToHtml(FileUtils.readFileToString(filtered));

        FileUtils.write(getOutputFile(input, "html"), result);
    }
1046146
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException
   {
      String action = request.getParameter(ACTION_PARAM);

      if (action == null)
         action = DISPLAY_MBEANS_ACTION;

      if (action.equals(DISPLAY_MBEANS_ACTION))
         displayMBeans(request, response);
      else if (action.equals(INSPECT_MBEAN_ACTION))
         inspectMBean(request, response);
      else if (action.equals(UPDATE_ATTRIBUTES_ACTION))
         updateAttributes(request, response);
      else if (action.equals(INVOKE_OP_ACTION))
         invokeOp(request, response);
      else if (action.equals(INVOKE_OP_BY_NAME_ACTION))
         invokeOpByName(request, response);
   }
239132
public void doProcess(HttpServletRequest req, HttpServletResponse res) 
        throws ServletException, IOException
    {
        Utility.getLogger().info("doProcess called in xmlws servlet");
        XMLMessageTransport xmlMessageTransport = null;
        ServletTask servletTask = null;
        BaseMessage msgReplyInternal = null;
        try {
            Map<String,Object> properties = m_initProperties;
        	String strDomain = BaseHttpTask.getParam(req, DBParams.DOMAIN);
        	if (strDomain != null)
        	{
		        properties = new HashMap<String,Object>();
		        if (m_initProperties != null)
		        	properties.putAll(m_initProperties);
				properties.put(DBParams.DOMAIN, strDomain);
        	}
            servletTask = new ServletTask(this, BasicServlet.SERVLET_TYPE.XML);
            servletTask.setProperties(properties);
            Environment env = null;
            if (servletTask.getApplication() != null)
                env = ((BaseApplication)servletTask.getApplication()).getEnvironment();
            if (env == null)
                env = Environment.getEnvironment(null);
            App app = env.getMessageApplication(true, properties);
            servletTask.setApplication(app);

            xmlMessageTransport = new XMLMessageTransport(servletTask);
            InputStream inStream = req.getInputStream();	// .getReader();
            Reader in = new InputStreamReader(inStream);
            String message = Utility.transferURLStream(null, null, in, null);
            try   {
                message = URLDecoder.decode(message, DBConstants.URL_ENCODING);
            } catch (java.io.UnsupportedEncodingException ex) {
                ex.printStackTrace();
            }
            //xMap<String,Object> properties = PropertiesField.stringToProperties(message);
            if (message.startsWith("xml="))	// Always
                message = message.substring(4);
            Map<String, Object> propMessage = null;
            if (message.length() == 0)
            {
            	Enumeration<?> names = req.getParameterNames();
            	while (names.hasMoreElements())
            	{
            		String key = names.nextElement().toString();
            		if ("xml".equalsIgnoreCase(key))
            			message = (String)req.getParameter(key);
            		else
            		{
            			if (propMessage == null)
            				propMessage = new HashMap<String, Object>();
            			propMessage.put(key, req.getParameter(key));	// RESTful params
            		}
            	}
            }

            BaseMessage messageIn = new TreeMessage(null, null);
            new XmlTrxMessageIn(messageIn, message);
            if (propMessage != null)
            {
            	for (String key : propMessage.keySet())
            	{
            		messageIn.put(key, propMessage.get(key));
            	}
            }

            msgReplyInternal = xmlMessageTransport.processIncomingMessage(messageIn, null);
            Utility.getLogger().info("msgReplyInternal: " + msgReplyInternal);

            int iErrorCode = xmlMessageTransport.convertToExternal(msgReplyInternal, null);
            Utility.getLogger().info("externalMessageReply: " + msgReplyInternal);

            if (iErrorCode == DBConstants.NORMAL_RETURN)
            {
            	if (msgReplyInternal.getExternalMessage() != null)
            	{	// Always
	                String strReply = msgReplyInternal.getExternalMessage().toString();
    	            res.getWriter().print(strReply);
        	        String strTrxID = (String)msgReplyInternal.getMessageHeader().get(TrxMessageHeader.LOG_TRX_ID);
            	    xmlMessageTransport.logMessage(strTrxID, msgReplyInternal, MessageInfoTypeModel.REPLY, MessageTypeModel.MESSAGE_OUT, MessageStatusModel.SENTOK, null, null);    // Sent (no reply required)
            	}
            }
        } catch (Throwable ex)  {
            ex.printStackTrace();
            String strError = "Error in processing or replying to a message";
            Utility.getLogger().warning(strError);
            if ((msgReplyInternal != null) && (xmlMessageTransport != null))
            {
                String strTrxID = (String)msgReplyInternal.getMessageHeader().get(TrxMessageHeader.LOG_TRX_ID);
                xmlMessageTransport.logMessage(strTrxID, msgReplyInternal, MessageInfoTypeModel.REPLY, MessageTypeModel.MESSAGE_OUT, MessageStatusModel.ERROR, strError, null);
            }
            return; // Error
        } finally   {
            if (xmlMessageTransport != null)
            {
                xmlMessageTransport.free();
                xmlMessageTransport = null;
            }
            if (servletTask != null)
                servletTask.free();
        }
    }
1059223
public void doPost(HttpServletRequest request,
                       HttpServletResponse response) 
        throws ServletException, IOException
    {
        HttpSession session = request.getSession(false);
        String action = request.getParameter("Action");
        String name =  request.getParameter("Name");
        String value =  request.getParameter("Value");
        String age =  request.getParameter("MaxAge");

        String nextUrl = getURI(request)+"?R="+redirectCount++;
        if (action.equals("New Session"))
        {   
            session = request.getSession(true);
        }
        else 
        if (session!=null)
        {
            if (action.equals("Invalidate"))
                session.invalidate();
            else if (action.equals("Set"))
            {   
                session.setAttribute(name,value);
                try
                {
                    int m = Integer.parseInt(age);
                    session.setMaxInactiveInterval(m);
                }
                catch(Exception e)
                {
                    LogSupport.ignore(log,e);
                }
            }
            else if (action.equals("Remove"))
                session.removeAttribute(name);
        }

        String encodedUrl=response.encodeRedirectURL(nextUrl);
        response.sendRedirect(encodedUrl);
        
    }
560411
private final void init() throws ServletException
	{
		ServletConfig conf;
		ServletContext ctx;

		logger.debug("servlet={}", servlet);

		// If the api user doesn't init a HttpServlet right
		// the conf may be null. Let's double check it all with
		// useful exception messages.
		if(servlet == null)
			throw new IllegalStateException("Servlet was null in. Initialization issue?");
		if((conf = servlet.getServletConfig()) == null)
			throw new IllegalStateException("ServletConfig was null in. Initialization issue?");
		if((ctx = conf.getServletContext()) == null)
			throw new IllegalStateException("ServletContext was null in. Initialization issue?");

		// get the actual dispatcher
		if(isName)
			dispatcher = ctx.getNamedDispatcher(nameOrPath);
		else
			dispatcher = ctx.getRequestDispatcher(nameOrPath);
		if(dispatcher == null)
			throw new ServletException("Unable to get dispatcher for \"" + nameOrPath + "\".");
	}
847319
@Override
	final protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		resp.setBufferSize(BUFFER_SIZE);
		postCount.incrementAndGet();
		try {
			reportingDoPost(req, resp);
		} catch (ThreadDeath t) {
			throw t;
		} catch (RuntimeException | ServletException | IOException e) {
			getLogger().log(Level.SEVERE, null, e);
			throw e;
		} catch (SQLException t) {
			getLogger().log(Level.SEVERE, null, t);
			throw new ServletException(t);
		}
	}
37855
protected final void error(final HttpServletResponse httpServletResponse, final Throwable e) {
        httpServletResponse.setContentType("text/plain");
        httpServletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
        try (PrintWriter out = httpServletResponse.getWriter()) {
            out.println("Error while processing request:");
            LOGGER.error("Error while processing request", e);
        } catch (IOException ex) {
            throw ExceptionUtils.getRuntimeException(ex);
        }
    }
478191
private void responseEntity(String html, HttpServletResponse servletResponse)
            throws IOException {
        PrintWriter printWriter = servletResponse.getWriter();
        try {
            printWriter.write(html);
            printWriter.flush();
        } finally {
            closeQuietly(printWriter);
        }
    }
337067
public void doGet(HttpServletRequest request,
                      HttpServletResponse response) 
        throws ServletException, IOException
    {
        response.setContentType("text/html");
        Page page= new Page();

        HttpSession session = request.getSession(getURI(request).indexOf("new")>0);
        
        page.title("Session Dump Servlet: ");        
        
        TableForm tf = new TableForm(response.encodeURL(getURI(request)));
        tf.method("POST");
        
        if (session==null)
        {
            page.add("<H1>No Session</H1>");
            tf.addButton("Action","New Session");
        }
        else
        {
            try
            {   
                tf.addText("ID",session.getId());
                tf.addText("State",session.isNew()?"NEW":"Valid");
                tf.addText("Creation",
                           new Date(session.getCreationTime()).toString());
                tf.addText("Last Access",
                           new Date(session.getLastAccessedTime()).toString());
                tf.addText("Max Inactive",
                           ""+session.getMaxInactiveInterval());

                tf.addText("Context",""+session.getServletContext());
                
                Enumeration keys=session.getAttributeNames();
                while(keys.hasMoreElements())
                {
                    String name=(String)keys.nextElement();
                    String value=session.getAttribute(name).toString();
                    tf.addText(name,value);
                }
                
                tf.addTextField("Name","Property Name",20,"name");
                tf.addTextField("Value","Property Value",20,"value");
                tf.addTextField("MaxAge","MaxAge(s)",5,"");
                tf.addButtonArea();
                tf.addButton("Action","Set");
                tf.addButton("Action","Remove");
                tf.addButton("Action","Invalidate");

                page.add(tf);
                tf=null;
                if (request.isRequestedSessionIdFromCookie())
                    page.add("<P>Turn off cookies in your browser to try url encoding<BR>");
                
                if (request.isRequestedSessionIdFromURL())
                    page.add("<P>Turn on cookies in your browser to try cookie encoding<BR>");
                
            }
            catch (IllegalStateException e)
            {
                log.debug(LogSupport.EXCEPTION,e);
                page.add("<H1>INVALID Session</H1>");
                tf=new TableForm(getURI(request));
                tf.addButton("Action","New Session");
            }
        }

        if (tf!=null)
            page.add(tf);
        
        Writer writer=response.getWriter();
        page.write(writer);
        writer.flush();
    }