Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
g.skorupa@gmail.com committed Jan 3, 2017
1 parent 33ccaaf commit 85fef34
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 64 deletions.
2 changes: 1 addition & 1 deletion src/java/cricket.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#Tue, 27 Dec 2016 23:25:52 +0100
#Tue, 03 Jan 2017 08:25:22 +0100

version=1.0.0
12 changes: 9 additions & 3 deletions src/java/org/cricketmsf/in/http/TxtFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import java.util.List;
import java.util.Map;
import org.cricketmsf.Event;
import org.cricketmsf.Kernel;

/**
*
Expand All @@ -37,15 +39,18 @@ public static TxtFormatter getInstance() {

public String format(Result r) {
StringBuilder sb = new StringBuilder();
if (r.getData() == null) {
return "";
}
try {
if (r.getData() instanceof List) {
List list = (List) r.getData();
if (list.size() > 0) {
List header = (List) list.get(0);
List row;
for (int i = 1; i < list.size(); i++) {
row=(List) list.get(i);
for(int j=0; j<header.size(); j++){
row = (List) list.get(i);
for (int j = 0; j < header.size(); j++) {
sb.append(header.get(j));
sb.append("=");
sb.append(row.get(j));
Expand All @@ -67,7 +72,8 @@ public String format(Result r) {
sb.append("\r\n");
}
} catch (Exception e) {
e.printStackTrace();
//e.printStackTrace();
Kernel.handle(Event.logSevere("TxtFormatter", e.getMessage()));
sb.append(e.getMessage());
}
return sb.toString();
Expand Down
65 changes: 5 additions & 60 deletions src/java/org/cricketmsf/services/EchoService.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.cricketmsf.in.http.HttpAdapterIface;
import org.cricketmsf.in.http.StandardResult;
import org.cricketmsf.in.scheduler.SchedulerIface;
import org.cricketmsf.out.db.KeyValueCacheAdapterIface;
import org.cricketmsf.out.file.FileReaderAdapterIface;
import org.cricketmsf.in.http.ParameterMapResult;
import org.cricketmsf.in.monitor.EnvironmentMonitorIface;
Expand Down Expand Up @@ -118,66 +117,12 @@ public void processEvent(Event event) {
* @return ParameterMapResult with the file content as a byte array
*/
@HttpAdapterHook(adapterName = "HtmlGenAdapterIface", requestMethod = "GET")
public Object doGet(Event event) {
RequestObject request = event.getRequest();
String filePath = fileReader.getFilePath(request);
byte[] content;
ParameterMapResult result = new ParameterMapResult();
public Object htmlGet(Event event) {

// we can use database if available
FileObject fo = null;
boolean fileReady = false;
if (htmlAdapter.useCache()) {
try {
try {
fo = (FileObject) database.get("wwwcache", filePath);
} catch (KeyValueDBException e) {
e.printStackTrace();
fo = null;
}
if (fo != null) {
fileReady = true;
result.setCode(HttpAdapter.SC_OK);
result.setMessage("");
result.setPayload(fo.content);
result.setFileExtension(fo.fileExtension);
result.setModificationDate(fo.modified);
handle(Event.logFine(this.getClass().getSimpleName(), "read from database"));
return result;
}
} catch (ClassCastException e) {
}
}
// if not in database
if (!fileReady) {
File file = new File(filePath);
content = fileReader.getFileBytes(file, filePath);
if (content.length == 0) {
// file not found or empty file
result.setCode(HttpAdapter.SC_NOT_FOUND);
result.setMessage("file not found");
result.setData(request.parameters);
result.setPayload("file not found".getBytes());
return result;
}
fo = new FileObject();
fo.content = content;
fo.modified = new Date(file.lastModified());
fo.filePath = filePath;
fo.fileExtension = fileReader.getFileExt(filePath);
if (htmlAdapter.useCache() && content.length > 0) {
try {
database.put("wwwcache", filePath, fo);
} catch (KeyValueDBException e) {
e.printStackTrace();
}
}
}
result.setCode(HttpAdapter.SC_OK);
result.setMessage("");
result.setPayload(fo.content);
result.setFileExtension(fo.fileExtension);
result.setModificationDate(fo.modified);
RequestObject request = event.getRequest();
ParameterMapResult result
= (ParameterMapResult) fileReader
.getFile(request, htmlAdapter.useCache() ? (KeyValueDB) database : null, "webcache");
return result;
}

Expand Down

0 comments on commit 85fef34

Please sign in to comment.