forked from m0ver/tinystruct-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.java
More file actions
executable file
·117 lines (93 loc) · 4.23 KB
/
error.java
File metadata and controls
executable file
·117 lines (93 loc) · 4.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package tinystruct.examples;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.tinystruct.AbstractApplication;
import org.tinystruct.ApplicationException;
import org.tinystruct.dom.Element;
import org.tinystruct.handle.Reforward;
public class error extends AbstractApplication {
private HttpServletRequest request;
private HttpServletResponse response;
private Reforward reforward;
@Override
public void init() {
// TODO Auto-generated method stub
this.setAction("error", "process");
this.setAction("info", "info");
}
@Override
public String version() {
// TODO Auto-generated method stub
return null;
}
public Object process()
throws ApplicationException {
this.request = (HttpServletRequest) this.context.getAttribute("HTTP_REQUEST");
this.response = (HttpServletResponse) this.context.getAttribute("HTTP_RESPONSE");
this.reforward=new Reforward(this.request,this.response);
this.setVariable("from", this.reforward.getFromURL());
HttpSession session=this.request.getSession();
if(session.getAttribute("error")!=null)
{
ApplicationException exception=(ApplicationException)session.getAttribute("error");
String message=exception.getRootCause().getMessage();
if(message!=null) this.setVariable("exception.message", message);
else this.setVariable("exception.message", "Unknown error");
this.setVariable("exception.details", this.getDetail(exception).toString());
return this.getVariable("exception.message").getValue().toString()+this.getVariable("exception.details").getValue();
}
else
{
this.reforward.forward();
}
return "This request is forbidden!";
}
private Element getDetail(ApplicationException exception)
{
Element errors=new Element("ul");
int i=0;
Throwable ex=exception.getRootCause();
StackTraceElement[] trace=ex.getStackTrace();
while(i<trace.length)
{
Element element=new Element("li");
element.setData(trace[i++].toString());
errors.addElement(element);
}
return errors;
}
public StringBuffer info()
{
StringBuffer buffer=new StringBuffer();
buffer.append("Protocol: " + this.request.getProtocol()+"\r\n");
buffer.append("Scheme: " + this.request.getScheme()+"\r\n");
buffer.append("Server Name: " + this.request.getServerName()+"\r\n");
buffer.append("Server Port: " + this.request.getServerPort()+"\r\n");
buffer.append("Protocol: " + this.request.getProtocol()+"\r\n");
// buffer.append("Server Info: " + getServletConfig().getServletContext().getServerInfo()+"\r\n");
buffer.append("Remote Addr: " + this.request.getRemoteAddr()+"\r\n");
buffer.append("Remote Host: " + this.request.getRemoteHost()+"\r\n");
buffer.append("Character Encoding: " + this.request.getCharacterEncoding()+"\r\n");
buffer.append("Content Length: " + this.request.getContentLength()+"\r\n");
buffer.append("Content Type: "+ this.request.getContentType()+"\r\n");
buffer.append("Auth Type: " + this.request.getAuthType()+"\r\n");
buffer.append("HTTP Method: " + this.request.getMethod()+"\r\n");
buffer.append("Path Info: " + this.request.getPathInfo()+"\r\n");
buffer.append("Path Trans: " + this.request.getPathTranslated()+"\r\n");
buffer.append("Query String: " + this.request.getQueryString()+"\r\n");
buffer.append("Remote User: " + this.request.getRemoteUser()+"\r\n");
buffer.append("Session Id: " + this.request.getRequestedSessionId()+"\r\n");
buffer.append("Request URI: " + this.request.getRequestURI()+"\r\n");
buffer.append("Servlet Path: " + this.request.getServletPath()+"\r\n");
buffer.append("Accept: " + this.request.getHeader("Accept")+"\r\n");
buffer.append("Host: " + this.request.getHeader("Host")+"\r\n");
buffer.append("Referer : " + this.request.getHeader("Referer")+"\r\n");
buffer.append("Accept-Language : " + this.request.getHeader("Accept-Language")+"\r\n");
buffer.append("Accept-Encoding : " + this.request.getHeader("Accept-Encoding")+"\r\n");
buffer.append("User-Agent : " + this.request.getHeader("User-Agent")+"\r\n");
buffer.append("Connection : " + this.request.getHeader("Connection")+"\r\n");
buffer.append("Cookie : " + this.request.getHeader("Cookie")+"\r\n");
return buffer;
}
}