Rev 1945 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | fvelez | 1 | package pt.estgp.estgweb.web; |
2 | |||
1350 | jmachado | 3 | import jomm.web.utils.NavPlace; |
1 | fvelez | 4 | import org.apache.log4j.Logger; |
5 | |||
1350 | jmachado | 6 | import javax.servlet.ServletException; |
1 | fvelez | 7 | import javax.servlet.http.HttpServlet; |
8 | import javax.servlet.http.HttpServletRequest; |
||
9 | import javax.servlet.http.HttpServletResponse; |
||
1350 | jmachado | 10 | import java.io.FileNotFoundException; |
1 | fvelez | 11 | import java.io.IOException; |
1350 | jmachado | 12 | import java.net.URLEncoder; |
1 | fvelez | 13 | |
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 | { |
||
1350 | jmachado | 57 | //Aqui temos de codificar em UTf-8 porque estamos dentro da máquina em UTF-8 |
58 | //Tem de ser com o URLEncoder e não com o URIUtil porque o URLEncoder trabalha com o + e o URIUtil apenas trabalha com diacriticos |
||
59 | getServletContext().getRequestDispatcher("/layout.do?server=" + server + "&path=" + 1.5.0/docs/api/java/net/URLEncoder.html">URLEncoder.encode(path, "UTF-8") + "&layout=" + layout + "&" + request.getQueryString()).forward(request, response); |
||
1 | fvelez | 60 | } |
61 | catch(1.5.0/docs/api/java/io/FileNotFoundException.html">FileNotFoundException e) |
||
62 | { |
||
63 | throw new 1.5.0/docs/api/java/io/FileNotFoundException.html">FileNotFoundException(path); |
||
64 | } |
||
65 | catch(1.5.0/docs/api/java/lang/Exception.html">Exception e) |
||
66 | { |
||
400 | jmachado | 67 | if(e.toString().indexOf("HTTP response code")>=0) |
68 | { |
||
69 | logger.info(e,e); |
||
70 | //do nothing it's some file in proxy that is not there |
||
71 | } |
||
72 | else |
||
73 | { |
||
74 | throw new 1.5.0/docs/api/java/io/IOException.html">IOException(e.toString()); |
||
75 | } |
||
1 | fvelez | 76 | } |
77 | } |
||
78 | else |
||
79 | { |
||
80 | throw new 1.5.0/docs/api/java/io/FileNotFoundException.html">FileNotFoundException("url not found for server:" + server + " and path:" + path); |
||
81 | } |
||
82 | } |
||
83 | |||
84 | // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code."> |
||
85 | /** Handles the HTTP <code>GET</code> method. |
||
86 | * @param request servlet request |
||
87 | * @param response servlet response |
||
88 | */ |
||
89 | protected void doGet(HttpServletRequest request, HttpServletResponse response) |
||
90 | throws ServletException, 1.5.0/docs/api/java/io/IOException.html">IOException |
||
91 | { |
||
92 | processRequest(request, response); |
||
93 | } |
||
94 | |||
95 | /** Handles the HTTP <code>POST</code> method. |
||
96 | * @param request servlet request |
||
97 | * @param response servlet response |
||
98 | */ |
||
99 | protected void doPost(HttpServletRequest request, HttpServletResponse response) |
||
100 | throws ServletException, 1.5.0/docs/api/java/io/IOException.html">IOException { |
||
101 | processRequest(request, response); |
||
102 | } |
||
103 | |||
104 | /** Returns a short description of the servlet. |
||
105 | */ |
||
106 | public 1.5.0/docs/api/java/lang/String.html">String getServletInfo() { |
||
107 | return "Proxy Servlet to get pages form static web page servers"; |
||
108 | } |
||
109 | // </editor-fold> |
||
110 | } |