Skip to content

Commit 94cc926

Browse files
committed
Upgrade the tinystruct framework to be 0.4.9.
1 parent e5c97a2 commit 94cc926

File tree

6 files changed

+114
-164
lines changed

6 files changed

+114
-164
lines changed

bin/dispatcher

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env sh
22
ROOT="`pwd`"
3-
VERSION="0.4.5"
3+
VERSION="0.4.9"
44
cd "`dirname "$0"`"
55
cd "../"
66
cd "$ROOT"

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<dependency>
1010
<groupId>org.tinystruct</groupId>
1111
<artifactId>tinystruct</artifactId>
12-
<version>0.4.5</version>
12+
<version>0.4.9</version>
1313
<classifier>jar-with-dependencies</classifier>
1414
</dependency>
1515
<!-- https://mvnrepository.com/artifact/com.h2database/h2 -->

src/main/java/tinystruct/examples/bible.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public String open(String pattern) throws ApplicationException {
3030
try {
3131
uri = new URL("http://rcuv.hkbs.org.hk/bb/info/CUNPs_1/"+pattern+"/");
3232
URLResourceLoader loader = new URLResourceLoader(uri );
33-
StringBuffer buffer = loader.getContent();
33+
StringBuilder buffer = loader.getContent();
3434

3535
return this.preprocess(buffer.toString());
3636
} catch (MalformedURLException e) {

src/main/java/tinystruct/examples/error.java

Lines changed: 60 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -5,114 +5,69 @@
55
import org.tinystruct.ApplicationException;
66
import org.tinystruct.dom.Element;
77
import org.tinystruct.handler.Reforward;
8-
9-
import javax.servlet.http.HttpServletRequest;
10-
import javax.servlet.http.HttpServletResponse;
11-
import javax.servlet.http.HttpSession;
8+
import org.tinystruct.http.Request;
9+
import org.tinystruct.http.Response;
10+
import org.tinystruct.http.Session;
1211

1312
public class error extends AbstractApplication {
1413

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

70+
return errors;
71+
}
11772

11873
}

0 commit comments

Comments
 (0)