Skip to content

Troubleshooting

java

no suitable creator for tomcat

In catalina.out you get errors like these :

Error

org.codehaus.jackson.map.JsonMappingException: Can not construct instance of org.klopt.backend.UserSetting, problem: no suitable creator method found to de-serialize from JSON String

First: Adding a constructor to your class does not help ! Second: neither seem these lines to be needed

import
1
2
3
4
//import org.codehaus.jackson.annotate.JsonAutoDetect;
//import org.codehaus.jackson.annotate.JsonAutoDetect.Visibility;

//@JsonAutoDetect(fieldVisibility = Visibility.ANY)

The problem last time was the way the json string was built (the wrong version with error)

output
"{"fullname":"Kees Klop","save":"false","login":"true","offline":"false","trace":"false"}"
org.codehaus.jackson.map.JsonMappingException: Can not construct instance of org.klopt.backend.UserSetting, problem: no suitable creator method found to deserialize from JSON String

The wrong string is :

fault
"{"fullname":"Kees Klop","save":"false","login":"true","offline":"false","trace":"false"}"

As opposed to what it should be :

correct
{"fullname":"Kees Klop","save":false,"login":true,"offline":false,"trace":false}

This was made with a function that tried to construct a json string from a settings object. DON'T. You should just send the javascript object.

In my case it was a struct that prints a settings dialog and so it had much more fields than needed, actually if i print the whole thing you get yet another error :

output
[{"name":"fullname","caption":"Naam","type":"string","val":"Kees Klop"},{"name":"save","caption":"Automatisch bewaren","type":"boolean","val":false},{"name":"login","caption":"Ingelogd blijven","type":"boolean","val":true},{"name":"offline","caption":"Offline wanneer onderweg","type":"boolean","val":false},{"name":"trace","caption":"Tracing aan","type":"boolean","val":false}]
org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of org.klopt.backend.UserSetting out of START_ARRAY token

What you want is a simple dynamic array that can be constructed with this function :

dynamic array
// turn the structure into an json hash object
 self.get_object=function() {
     var dta = new Object();

     for (var s in self.settings) {
         var stng = self.settings[s];

         dta[stng.name] = stng.val;
     } 
     return dta;
 }

Leading to a simple json object :

object
{"fullname":"Kees Klop","save":false,"login":true,"offline":false,"trace":false}

cannot find config.properties from war file

If you want a properties file to be included into a war file and open it. First : put it into the resources directory ! : src/main/resources/config.properties

These get put into the war file by the mvn package:

war file
jar tvf target/backend.war :
output
1
2
3
4
5
6
...
2154 Thu Oct 27 13:25:14 CEST 2016 WEB-INF/classes/org/klopt/backend/AuthServlet.class
  531 Thu Oct 27 13:25:14 CEST 2016 WEB-INF/classes/org/klopt/backend/GenericMsg.class
   35 Thu Oct 27 13:25:12 CEST 2016 WEB-INF/classes/config.properties
147933 Thu May 26 21:37:40 CEST 2016 WEB-INF/lib/jersey-json-1.8.jar
...

Now read it with something like :

read file
   Properties prop = new Properties();
       InputStream in = null;

       try {
           String filename = "config.properties";
           in = TokenService.class.getClassLoader().getResourceAsStream(filename);
           System.out.println("Dang");
           System.out.println(in);
           prop.load(in);
           webUrl = prop.getProperty("webUrl");
           System.out.println(this.webUrl);
       } catch (IOException e) {
           e.printStackTrace();
       } finally {
           if (in != null) {
               try {
                   in.close();
               } catch (IOException e) {
                   e.printStackTrace();
               }
           }
       }