0

I am trying to use log4javascript's ajaxAppender to send a batch of messages to the server in my app.

This is how I initialized logging:

    var log = log4javascript.getDefaultLogger();
    log.info('Logging initialized');
    var ajaxAppender = new log4javascript.AjaxAppender("http://localhost:8080/mobile2/logger/logme.json");

    ajaxAppender.addHeader("Content-Type","application/json;charset=utf-8");
    ajaxAppender.setBatchSize(10);
    var jsonLayout = new log4javascript.JsonLayout(false,true);
    ajaxAppender.setLayout(jsonLayout);

    log.info(jsonLayout.getContentType());

    log.addAppender(ajaxAppender);

I am using spring on the server and its @RequestBody tag to read in the json object.

This works for my other server requests but when using the ajaxAppender it always fails with this error; SEVERE: Servlet.service() for servlet spring threw exception java.lang.IllegalArgumentException: Invalid token character ',' in token "x-www-form-urlencoded, application/json"

The only difference I can see is that when I inspect the request headers, the headers for logging have a content type of the following: Content-Type: application/x-www-form-urlencoded, application/json;charset=UTF-8

whereas my other json requests only have the second string 'application/json;charset=UTF-8'

Is it possible to send the ajax without the first content type? Not sure what else to try.

Thanks

blong824
  • 3,920
  • 14
  • 54
  • 75
  • log4javascript is adding two `Content-Type` headers: `application/x-www-form-urlencoded` and `application/json;charset=UTF-8`. In browsers I originally tested, only the most recent header was sent but Chrome at least sends both values, separated by commas. I've added a workaround and will release a new version shortly. – Tim Down Feb 07 '13 at 23:48
  • Yea Im doing all my browser testing in Chrome. Thanks for looking into this. – blong824 Feb 08 '13 at 14:32
  • I tried to release a new version yesterday but was denied by Soureforge's uploader being broken. I'll try again later today. – Tim Down Feb 08 '13 at 14:34
  • Hi Tim, Thanks for the new version. It looks like that fixed the content-type issue. I am noticing one other problem though. The request payload (in chrome) is still encoded. I tested in safari also and the post source is also encoded. This is causing my jackson mapper to fail. Is there anything in the JsonLayout that would encode the request? My other requests to the server show the correct JSON format. Please let me know. – blong824 Feb 11 '13 at 15:49
  • Yes, you're right, it shouldn't be URL-encoded. The basic problem is that I didn't fully think things through when I wrote this stuff in 2006. I'll fix it. – Tim Down Feb 11 '13 at 16:11
  • I think I did some work on it. I'll finish it up this week. – Tim Down Feb 19 '13 at 14:26
  • I've fixed this now. There's a new version uploaded to SourceForge. – Tim Down Feb 20 '13 at 01:02

0 Answers0