Could be a number of reasons. Perhaps someone introduced custom code that may have caused this issue. Please provide more details Is this a new install. Did this stop working all of a sudden,
Did you write that Java code or copy it from somewhere?The reason I am asking is that it seems strange that you know how to write that Java code for Experience Manager yet post in a Encore forum.
This is very easy. Use Sling Model and use Java logic to check a cookie. Setting and Reading Cookies : Cookie « Servlets « Java Then set a field in the Sling Model based on the value.
Can you explain what you mean by all the data needs to be transmitted through JSON. Your components are not rendering HTML? The best practice is to use editable templates. If you need to work with JSON look at Content Services.