CRXHttpServlet.java 3.96 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  javax.servlet.ServletContext
 *  javax.servlet.ServletException
 *  javax.servlet.http.HttpServlet
 *  javax.servlet.http.HttpServletRequest
 *  javax.servlet.http.HttpServletResponse
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.day.crx.explorer.impl.j2ee;

import com.day.crx.explorer.impl.j2ee.CRXContext;
import com.day.crx.explorer.impl.j2ee.CRXHttpServletRequest;
import com.day.crx.explorer.impl.j2ee.CRXHttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Properties;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class CRXHttpServlet
extends HttpServlet {
    private static final Logger log = LoggerFactory.getLogger(CRXHttpServlet.class);

    public void init() throws ServletException {
        if (this.getServletContext().getAttribute(this.getClass().getName()) != null) {
            throw new ServletException("Only one servlet allowed per web-app.");
        }
        this.getServletContext().setAttribute(this.getClass().getName(), (Object)this);
        log.info(this.getClass().getSimpleName() + " initialized.");
    }

    public Properties getInitProperties() {
        Properties props = new Properties();
        Enumeration e = this.getInitParameterNames();
        while (e.hasMoreElements()) {
            String name = e.nextElement().toString();
            String value = this.getInitParameter(name);
            props.put(name, value);
        }
        return props;
    }

    public static CRXHttpServlet getInstance(ServletContext ctx, String name) {
        CRXHttpServlet instance = (CRXHttpServlet)((Object)ctx.getAttribute(name));
        if (instance == null) {
            throw new IllegalStateException("No Servlet instance in ServletContext, Servlet not initialized?");
        }
        return instance;
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        CRXContext ctx = null;
        if (!(req instanceof CRXHttpServletRequest)) {
            ctx = CRXContext.getInstance(this.getServletContext(), (HttpServletRequest)req);
            req = new CRXHttpServletRequest(ctx);
        }
        if (!(resp instanceof CRXHttpServletResponse)) {
            resp = new CRXHttpServletResponse((HttpServletResponse)resp);
        }
        try {
            super.service((HttpServletRequest)req, (HttpServletResponse)resp);
        }
        finally {
            if (ctx != null) {
                ctx.close();
            }
        }
    }

    protected void doGet(CRXHttpServletRequest req, CRXHttpServletResponse resp) throws ServletException, IOException {
        super.doGet((HttpServletRequest)req, (HttpServletResponse)resp);
    }

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        if (req instanceof CRXHttpServletRequest && resp instanceof CRXHttpServletResponse) {
            this.doGet((CRXHttpServletRequest)req, (CRXHttpServletResponse)resp);
        } else {
            super.doGet(req, resp);
        }
    }

    protected void doPost(CRXHttpServletRequest req, CRXHttpServletResponse resp) throws ServletException, IOException {
        super.doPost((HttpServletRequest)req, (HttpServletResponse)resp);
    }

    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        if (req instanceof CRXHttpServletRequest && resp instanceof CRXHttpServletResponse) {
            this.doPost((CRXHttpServletRequest)req, (CRXHttpServletResponse)resp);
        } else {
            super.doPost(req, resp);
        }
    }
}