0

I have a problem in implementing a Camel Route, where I call a URl and convert the JSON Response into Pojo. I use Camel-Jackson.

Connection establishes with status 200.

But I get

at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:541)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:644)
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:152)
caused because of java.lang.StackOverflowError. 

Here is a sample code

from("direct:start")
    .setHeader(Exchange.HTTP_METHOD, constant("GET"))
    .to("URL")
    .process(new Processor() {
        @Override
        public void process(Exchange exchange) throws Exception {
            int responseCode = exchange.getIn().getHeader(Exchange.HTTP_RESPONSE_CODE, Integer.class);
            System.out.println(exchange.getIn().getBody());
            System.out.println(responseCode);
        }
    })
    .marshal(cont)
    .process(new MyProcessor())
    .end();

cont is the Jackson data format. I increased my heap memory to 1024 M. But still it's showing Stack overflow error. But the Json file is just 26 Kb. I used http://www.jsonschema2pojo.org/‎ site to create the Pojos for the json.

5
  • You increase the stack size with the '-Xss<number>m' flag.
    – Erik
    Apr 10, 2014 at 7:38
  • yes i did. I cant increase more than 1GB. i have my internal memory occupied for 2.2 gb. my total occupiable space in ram is 3.25 gb. But i guess the program demands more..
    – bks4line
    Apr 10, 2014 at 8:52
  • If that is the case then I think JonK:s answer below is a correct analysis. It definitely sounds like run-away recursion.
    – Erik
    Apr 10, 2014 at 10:20
  • You absolutely should not be giving your thread stack that much space. The default setting should be more than enough for the vast majority of applications. If I needed anything more than -Xss128k for my thread stack I would be taking a serious look at my code to see what I should be changing to avoid needing that much.
    – JonK
    Apr 10, 2014 at 10:58
  • my bad people. i gave marshal instead of unmarshal(). Sorry for wasting your valuable time. thanks!
    – bks4line
    Apr 11, 2014 at 6:28

2 Answers 2

2

Generally speaking, a large or endless chain of recursive method calls are the main culprit of StackOverflowErrors, although they are by no means the only cause. One of your other issues is that your thread stack size may be set to a low number (if you're seeing a StackOverflowError but only have a small stack trace this is probably what's happening).

If your stack trace only has a small number of frames, check to see if your JVM has the -Xss launch option set. If it does, you may need to change it to something larger, if it doesn't then try adding -Xss256k to your JVM's launch options (the default is -Xss128k for Windows x64 machines). This can be increased further if need be.

If your stack trace is pretty large, then it's more likely to be recursive method calls. You should be able to tell from the trace itself which method(s) are being recursively called, and can then look to correcting the behaviour.

0

You should check your JSON Java class, if it contains a recursive cycle that may blow up your application. If this is the case add @JsonIgnore to the relevant attribute to break the cycle.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.