8000 Merge pull request #62 from giastfader/master · githubcs/baasbox@980cf2c · GitHub
[go: up one dir, main page]

Skip to content

Commit 980cf2c

Browse files
committed
Merge pull request baasbox#62 from giastfader/master
Version 0.6
2 parents 2bfed83 + 9e2c7cf commit 980cf2c

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

app/com/baasbox/controllers/actions/filters/WrapResponse.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.baasbox.controllers.actions.filters;
1818

1919
import java.io.IOException;
20+
import java.util.HashMap;
2021

2122
import org.codehaus.jackson.JsonProcessingException;
2223
import org.codehaus.jackson.map.ObjectMapper;
@@ -103,7 +104,10 @@ public Result wrap(Context ctx, Result result) throws Throwable {
103104
Logger.trace("Method Start");
104105

105106
ctx.response().setHeader("Access-Control-Allow-Origin", "*");
106-
107+
//this is an hack because scala can't access to the http context, and we need this information for the access log
108+
String username=(String) ctx.args.get("username");
109+
if (username!=null) ctx.response().setHeader("BB-USERNAME", username);
110+
107111
if (BBConfiguration.getWrapResponse()){
108112
Logger.debug("Wrapping the response");
109113
final int statusCode = JavaResultExtractor.getStatus(result);
@@ -134,9 +138,12 @@ public Result wrap(Context ctx, Result result) throws Throwable {
134138
}else{ //status is not an error
135139
result=onOk(statusCode,ctx.request(),stringBody);
136140
} //if (statusCode>399)
141+
//We was expecting that this would be done by the framework, apparently this is false
142+
ctx.response().setHeader("Content-Length",String.valueOf(JavaResultExtractor.getBody(result).length));
137143
}else{ //if (BBConfiguration.getWrapResponse())
138144
Logger.debug("The response will not be wrapped due configuration parameter");
139145
}
146+
140147
Logger.debug(" + result: \n" + result.toString());
141148
Logger.trace("Method End");
142149
return result;

app/com/baasbox/controllers/actions/filters/accesslog/AccessLogFilter.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@ package com.baasbox.filters {
1717
val time = System.currentTimeMillis - start
1818
val dateFormatted = new Date(start)
1919
val userAgent = rh.headers.get("User-Agent").getOrElse("")
20-
filterLogger.info(s"${rh.remoteAddress}\t[${dateFormatted}]\t${rh.method}\t${rh.uri}\t${rh.version}\t${result.header.status}\t${userAgent}\t${rh.contentType}\t-\t${time}")
20+
val contentLength = result.header.headers.get("Content-Length").getOrElse("-")
21+
/*
22+
* Log format is the combined one: http://httpd.apache.org/docs/2.2/logs.html
23+
* Unfortunely we have to do a litlle hack to log the authenticated username due a limitation of the framework: scala cannot access to the current Http Context where the username is stored
24+
*/
25+
val username = result.header.headers.get("BB-USERNAME").getOrElse("-")
26+
result.withHeaders("BB-USERNAME"->"")
27+
filterLogger.info(s"""${rh.remoteAddress}\t-\t${username}\t[${dateFormatted}]\t${"\""}${rh.method} ${rh.uri} ${rh.version}${"\""}\t${result.header.status}\t${contentLength}\t${"\""}${"\""}\t${"\""}${userAgent}${"\""}\t${time}""")
2128
result
2229
}
2330

conf/application.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ logger.baasbox.accesslog=TRACE
3737

3838
#baasbox api version
3939

40-
api.version="0.6.0-snapshot"
40+
api.version="0.6.0"
4141

4242
#baasbox orientdb credential
4343
orient.baasbox.user=baasbox

0 commit comments

Comments
 (0)
0