Skip to content

Commit

Permalink
Change the fake feature for file descriptor leak
Browse files Browse the repository at this point in the history
  • Loading branch information
k-tamura committed Apr 12, 2017
1 parent 2ded43b commit 1167428
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package org.t246osslab.easybuggy.troubles;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Date;
import java.util.Locale;

Expand All @@ -21,25 +24,53 @@
@WebServlet(urlPatterns = { "/filedescriptorleak" })
public class FileDescriptorLeakServlet extends HttpServlet {

private static final int MAX_DISPLAY_COUNT = 15;
private static final Logger log = LoggerFactory.getLogger(FileDescriptorLeakServlet.class);
private long count = 0;

protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {

StringBuilder bodyHtml = new StringBuilder();
Locale locale = req.getLocale();
bodyHtml.append(MessageUtils.getMsg("label.current.time", locale) + ": ");
bodyHtml.append(new Date());
bodyHtml.append("<br><br>");
StringBuilder bodyHtml = new StringBuilder();
try {
File file = new File(System.getProperty("java.io.tmpdir"), "test.txt");
FileOutputStream fos1 = new FileOutputStream(file);
bodyHtml.append(MessageUtils.getInfoMsg("msg.file.descriptor.leak.occur", req.getLocale()));
File file = new File(req.getServletContext().getAttribute("javax.servlet.context.tempdir").toString(),
"test.txt");
FileOutputStream fos1 = new FileOutputStream(file, true);
OutputStreamWriter osw = new OutputStreamWriter(fos1);
osw.write("<tr>");
osw.write("<td>" + new Date().toString() + "</td>");
osw.write("<td>" + req.getRemoteAddr() + "</td>");
osw.write("<td>" + req.getRequestedSessionId() + "</td>");
osw.write("</tr>" + System.getProperty("line.separator"));
osw.flush();
count++;

BufferedReader br = new BufferedReader(new FileReader(file));
bodyHtml.append("<p>" + MessageUtils.getMsg("description.access.history", req.getLocale()) + "</p>");
bodyHtml.append(
"<table class=\"table table-striped table-bordered table-hover\" style=\"font-size:small;\">");
bodyHtml.append("<th>" + MessageUtils.getMsg("label.access.time", locale) + "</th>");
bodyHtml.append("<th>" + MessageUtils.getMsg("label.ip.address", locale) + "</th>");
bodyHtml.append("<th>" + MessageUtils.getMsg("label.session.id", locale) + "</th>");
int headerLength = bodyHtml.length();
String line;
long currentLineNum = 0;
while ((line = br.readLine()) != null) {
if (count - currentLineNum <= MAX_DISPLAY_COUNT) {
bodyHtml.insert(headerLength, line);
}
currentLineNum++;
}
bodyHtml.append("</table>");
} catch (Exception e) {
log.error("Exception occurs: ", e);
bodyHtml.append(MessageUtils.getErrMsg("msg.unknown.exception.occur", new String[]{e.getMessage()}, locale));
bodyHtml.append(
MessageUtils.getErrMsg("msg.unknown.exception.occur", new String[] { e.getMessage() }, locale));
bodyHtml.append(e.getLocalizedMessage());
} finally {
HTTPResponseCreator.createSimpleResponse(req, res, MessageUtils.getMsg("title.current.time", locale), bodyHtml.toString());
bodyHtml.append(MessageUtils.getInfoMsg("msg.file.descriptor.leak.occur", req.getLocale()));
HTTPResponseCreator.createSimpleResponse(req, res, MessageUtils.getMsg("title.access.history", locale),
bodyHtml.toString());
}
}
}
5 changes: 5 additions & 0 deletions src/main/resources/messages_en.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
description.access.history=Access history in this page (The latest 15 records).
description.capitalize.string=If you enter a string, then the capitalized string is shown.
description.design.page=You can change design of this page. Please click one of the links below and change \
this page to your style.
Expand All @@ -8,6 +9,7 @@ description.random.string.generator=If you enter a character count, then a rando
description.reverse.string=If you enter a string, then the reversed string is shown.
description.test.regular.expression=Please test if an input string matches the regular expression <code>^([a-z0-9]+[-]{0,1}){1,100}$</code>.
description.send.mail=You can send a mail to the site administrator.
label.access.time=Access Time
label.available.characters=Available Characters
label.asc=asc
label.attach.file=Attach File
Expand All @@ -22,6 +24,7 @@ label.execution.result=Execution Result:
label.goto.admin.page=Go to admin main page
label.go.to.main=Go to main page
label.history.back=Back
label.ip.address=IP Address
label.json.string=JSON String
label.mail=Mail Address
label.login=Log in
Expand All @@ -36,6 +39,7 @@ label.password=Password
label.phone=Phone
label.reversed.string=Reversed String
label.secret=Secret Number
label.session.id=Session ID
label.signs=Signs
label.string=String
label.subject=Subject
Expand Down Expand Up @@ -176,6 +180,7 @@ style.name.monochro=Monochrome
style.description.monochro=Monochrome header and footer are used.
style.name.noframe=No Frame
style.description.noframe=No header and footer are used.
title.access.history=Access History
title.admins.main.page=Main Page for Administrators
title.current.date=Display Current Date
title.current.time=Display Current Time
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/messages_ja.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
description.access.history=\u3053\u306e\u30da\u30fc\u30b8\u306e\u30a2\u30af\u30bb\u30b9\u5c65\u6b74 (\u6700\u65b0\u306e15\u4ef6)
description.capitalize.string=\u6587\u5b57\u5217\u3092\u5165\u529b\u3059\u308b\u3068\u3001\u6587\u5b57\u5217\u306e\u5148\u982d\u3092\u5927\u6587\u5b57\u306b\u3057\u3066\u8868\u793a\u3057\u307e\u3059\u3002
description.design.page=\u3053\u306e\u30da\u30fc\u30b8\u3067\u306f\u3001\u30c7\u30b6\u30a4\u30f3\u306e\u5fae\u8abf\u6574\u3092\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u4ee5\u4e0b\u306e\u3044\u305a\u308c\u304b\u306e\u30ea\u30f3\u30af\u3092\u30af\u30ea\u30c3\u30af\u3057\u3066\u3001\
\u3053\u306e\u30da\u30fc\u30b8\u3092\u304a\u597d\u307f\u306e\u30b9\u30bf\u30a4\u30eb\u306b\u5909\u66f4\u3057\u3066\u4e0b\u3055\u3044\u3002
Expand All @@ -8,6 +9,7 @@ description.random.string.generator=\u6587\u5b57\u6570\u3092\u5165\u529b\u3059\u
description.reverse.string=\u6587\u5b57\u5217\u3092\u5165\u529b\u3059\u308b\u3068\u3001\u6587\u5b57\u5217\u304c\u9006\u8ee2\u3057\u3066\u8868\u793a\u3055\u308c\u307e\u3059\u3002
description.test.regular.expression=\u6b63\u898f\u8868\u73fe <code>^([a-z0-9]+[-]{0,1}){1,100}$</code> \u306b\u4e00\u81f4\u3059\u308b\u6587\u5b57\u5217\u304b\u30c6\u30b9\u30c8\u3057\u3066\u4e0b\u3055\u3044\u3002
description.send.mail=\u30b5\u30a4\u30c8\u306e\u7ba1\u7406\u8005\u306b\u30e1\u30fc\u30eb\u3092\u9001\u4fe1\u3067\u304d\u307e\u3059\u3002
label.access.time=\u30a2\u30af\u30bb\u30b9\u6642\u523b
label.available.characters=\u5229\u7528\u53ef\u80fd\u306a\u6587\u5b57
label.asc=\u6607\u9806
label.attach.file=\u6dfb\u4ed8\u30d5\u30a1\u30a4\u30eb
Expand All @@ -22,6 +24,7 @@ label.execution.result=\u5b9f\u884c\u7d50\u679c:
label.goto.admin.page=\u7ba1\u7406\u8005\u30e1\u30a4\u30f3\u30da\u30fc\u30b8\u3078
label.go.to.main=\u30e1\u30a4\u30f3\u30da\u30fc\u30b8\u3078
label.history.back=\u623b\u308b
label.ip.address=IP\u30a2\u30c9\u30ec\u30b9
label.json.string=JSON\u6587\u5b57\u5217
label.login=\u30ed\u30b0\u30a4\u30f3
label.login.user.id=\u30ed\u30b0\u30a4\u30f3\u30e6\u30fc\u30b6\u30fcID
Expand All @@ -36,6 +39,7 @@ label.password=\u30d1\u30b9\u30ef\u30fc\u30c9
label.phone=\u96fb\u8a71\u756a\u53f7
label.reversed.string=\u9006\u8ee2\u3057\u305f\u6587\u5b57\u5217
label.secret=\u6697\u8a3c\u756a\u53f7
label.session.id=\u30bb\u30c3\u30b7\u30e7\u30f3ID
label.signs=\u8a18\u53f7
label.subject=\u4ef6\u540d
label.submit=\u9001\u4fe1
Expand Down Expand Up @@ -176,6 +180,7 @@ style.name.monochro=\u30e2\u30ce\u30af\u30ed\u30fc\u30e0
style.description.monochro =\u30e2\u30ce\u30af\u30ed\u306e\u30d8\u30c3\u30c0\u30fc\u3068\u30d5\u30c3\u30bf\u30fc\u304c\u4f7f\u7528\u3055\u308c\u307e\u3059\u3002
style.name.noframe=\u30d5\u30ec\u30fc\u30e0\u306a\u3057
style.description.noframe=\u30d8\u30c3\u30c0\u3068\u30d5\u30c3\u30bf\u306f\u4f7f\u7528\u3055\u308c\u307e\u305b\u3093\u3002
title.access.history=\u30a2\u30af\u30bb\u30b9\u5c65\u6b74
title.admins.main.page=\u7ba1\u7406\u8005\u5411\u3051\u30e1\u30a4\u30f3\u30da\u30fc\u30b8
title.current.date=\u73fe\u5728\u65e5\u4ed8\u306e\u8868\u793a
title.current.time=\u73fe\u5728\u6642\u523b\u306e\u8868\u793a
Expand Down

0 comments on commit 1167428

Please sign in to comment.