Subversion Repositories bacoAlunos

Rev

Rev 851 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 fvelez 1
package pt.estgp.estgweb.web;
2
 
3
import org.apache.log4j.Logger;
4
 
5
import javax.servlet.http.HttpServlet;
6
import javax.servlet.http.HttpServletRequest;
7
import javax.servlet.http.HttpServletResponse;
8
import javax.servlet.ServletException;
9
import java.io.IOException;
10
import java.io.FileNotFoundException;
11
 
223 jmachado 12
import jomm.web.utils.NavPlace;
13
 
1 fvelez 14
/**
15
 * @author Jorge Machado
16
 * @date 26/Fev/2008
17
 * @time 12:46:16
18
 * @see pt.estgp.estgweb.web
19
 */
20
public class LayoutProxy extends HttpServlet {
21
 
851 jmachado 22
    /** sss requests for both HTTP <code>GET</code> and <code>POST</code> methods.
1 fvelez 23
     * @param request servlet request
24
     * @param response servlet response
25
     */
26
 
223 jmachado 27
 
28
 
1 fvelez 29
    private static final 1.5.0/docs/api/java/util/logging/Logger.html">Logger logger = 1.5.0/docs/api/java/util/logging/Logger.html">Logger.getLogger(LayoutProxy.class);
30
 
223 jmachado 31
    protected void setQueryString(1.5.0/docs/api/java/lang/String.html">String queryString, HttpServletRequest request)
32
    {
33
        NavPlace.setAuxiliaryQueryString(queryString,request);
34
    }
1 fvelez 35
 
36
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
37
            throws ServletException, 1.5.0/docs/api/java/io/IOException.html">IOException
38
    {
39
 
40
        1.5.0/docs/api/java/lang/String.html">String path = request.getPathInfo();
41
        int layoutEnd = path.indexOf("/",1);
42
        1.5.0/docs/api/java/lang/String.html">String layout = path.substring(1,layoutEnd);
43
        logger.info("layout:" + layout);
44
        path = path.substring(layoutEnd);
45
        int serverEnd = path.indexOf("/",1);
165 jmachado 46
        if(serverEnd < 0)
47
            serverEnd = path.length();
1 fvelez 48
        1.5.0/docs/api/java/lang/String.html">String server = path.substring(1,serverEnd);
49
        logger.info("server:" + server);
50
        path = path.substring(serverEnd);
51
        logger.info("path:" + path);
52
 
53
        if(path != null)
54
        {
55
            try
56
            {
39 fvelez 57
                getServletContext().getRequestDispatcher("/layout.do?server=" + server + "&path=" + path + "&layout=" + layout + "&" + request.getQueryString()).forward(request,response);
1 fvelez 58
            }
59
            catch(1.5.0/docs/api/java/io/FileNotFoundException.html">FileNotFoundException e)
60
            {
61
                throw new 1.5.0/docs/api/java/io/FileNotFoundException.html">FileNotFoundException(path);
62
            }
63
            catch(1.5.0/docs/api/java/lang/Exception.html">Exception e)
64
            {
400 jmachado 65
                if(e.toString().indexOf("HTTP response code")>=0)
66
                {
67
                    logger.info(e,e);
68
                    //do nothing it's some file in proxy that is not there
69
                }
70
                else
71
                {
72
                    throw new 1.5.0/docs/api/java/io/IOException.html">IOException(e.toString());
73
                }
1 fvelez 74
            }
75
        }
76
        else
77
        {
78
            throw new 1.5.0/docs/api/java/io/FileNotFoundException.html">FileNotFoundException("url not found for server:" + server + " and path:" + path);
79
        }
80
    }
81
 
82
    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
83
    /** Handles the HTTP <code>GET</code> method.
84
     * @param request servlet request
85
     * @param response servlet response
86
     */
87
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
88
            throws ServletException, 1.5.0/docs/api/java/io/IOException.html">IOException
89
    {
90
        processRequest(request, response);
91
    }
92
 
93
    /** Handles the HTTP <code>POST</code> method.
94
     * @param request servlet request
95
     * @param response servlet response
96
     */
97
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
98
            throws ServletException, 1.5.0/docs/api/java/io/IOException.html">IOException {
99
        processRequest(request, response);
100
    }
101
 
102
    /** Returns a short description of the servlet.
103
     */
104
    public 1.5.0/docs/api/java/lang/String.html">String getServletInfo() {
105
        return "Proxy Servlet to get pages form static web page servers";
106
    }
107
    // </editor-fold>
108
}