I want, sometimes, to log the raw data in struts2, but dont know where struts2 storage this info. (The bind of the json data to the beans work, i dont need that).
I have an interceptor that inject functionality to the action and manage the exceptions to draw a log with info of the petition.
The moment that i want to log the client send is when the server fail, in this manage of the error. But dont know where struts2 save the JSON. The other fields, like data of the struts invocation, values of the sesion, atributtes of the request, parameters of inputs... no problem. But the json data, i dont know where is.
I send the JSON from Angular, using httpclient with an observable. Something like this:
/** POST: add a new hero to the server */
addHero(hero: Hero): Observable<Hero> {
return this.http.post<Hero>(this.heroesUrl, hero, this.httpOptions).pipe(
tap((newHero: Hero) => this.log(`added hero w/ id=${newHero.id}`)),
catchError(this.handleError<Hero>('addHero'))
);
}
Some code i use to get the log:
public static String getValoresRequestToString(HttpServletRequest request)
{
String retorno = "";
Enumeration<String> nombresAtributos = request.getAttributeNames();
while (nombresAtributos.hasMoreElements())
{
String nombreAtributo = nombresAtributos.nextElement();
retorno = retorno + "\n" + "REQUEST:: " + nombreAtributo + " :" + request.getAttribute(nombreAtributo);
}
return retorno;
}
public static String getValoresParametrosConfiguracionToString(ActionInvocation invocation)
{
ActionConfig config = invocation.getProxy().getConfig();
Map<String, String> parameters = config.getParams();
return UtilString.mapToString(parameters);
}
public static String getValoresParametrosToString(ActionInvocation invocation)
{
Map<String, Object> parametros = invocation.getInvocationContext().getParameters();
return UtilString.mapToString(parametros);
}