{"id":2287,"date":"2014-06-18T02:01:03","date_gmt":"2014-06-18T02:01:03","guid":{"rendered":"http:\/\/www.garysieling.com\/blog\/?p=2287"},"modified":"2014-06-18T02:01:03","modified_gmt":"2014-06-18T02:01:03","slug":"tips-debugging-olingo-services","status":"publish","type":"post","link":"https:\/\/www.garysieling.com\/blog\/tips-debugging-olingo-services\/","title":{"rendered":"Tips for Debugging Olingo Services"},"content":{"rendered":"<p>If you get an error debugging an Olingo service (one of the Java libraries for OData), you often get an error like &#8220;An exception occurred.&#8221;<\/p>\n<p>This, apparently, is a result of decision by the Olingo team to not be dependent on a specific logging library (although I&#8217;m not sure how this makes sense, since they are dependent on CXF, which seems pretty heavy).<\/p>\n<p>The simple solution to this problem they recommend is to add a callback method to your ODataServiceFactory implementation:<\/p>\n<pre lang=\"java\">\npublic <T extends ODataCallback> T getCallback(final Class<? extends ODataCallback> callbackInterface)\n{ \n  return (T) (callbackInterface.isAssignableFrom(ScenarioErrorCallback.class) ? \n    new ScenarioErrorCallback() : \n      callbackInterface.isAssignableFrom(ODataDebugCallback.class) ? \n        new ScenarioDebugCallback() : \n        super.getCallback(callbackInterface));\n}\n<\/pre>\n<p>And then, classes for each:<\/p>\n<pre lang=\"java\">\nprivate final class ScenarioDebugCallback implements ODataDebugCallback {\n  @Override\n  public boolean isDebugEnabled()\n  { \n    return true; \n  }\n}\n\t\nprivate final class ScenarioErrorCallback implements ODataDebugCallback {\n@Override\n  public boolean isDebugEnabled()\n  { \n    return true; \n  }\n}\n<\/pre>\n<p>Now, it seems silly that you&#8217;d want to have both of these, but this adds error messages to the JSON response, with each line of Java stack traces as a separate JSON object. <\/p>\n<p>With these attributes set, add &#8220;odata-debug=json&#8221; to any Olingo URL and you&#8217;ll get debug information back.<\/p>\n<p>Once you do this, you will then discover that the JSON payloads of Olingo are monstrous, and to deal with this you need a browser plugin &#8211; I like <a href=\"https:\/\/chrome.google.com\/webstore\/detail\/json-formatter\/bcjindcccaagfpapjjmafapmmgkkhgoa\/related?hl=en\">JSON Formatter<\/a>, which auto-detects JSON, then formats and colorizes it:<\/p>\n<p><a href=\"http:\/\/172.104.26.128\/wp-content\/uploads\/2014\/06\/json-formatter2.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.garysieling.com\/blog\/wp-content\/uploads\/2014\/06\/json-formatter2-578x246.png\" alt=\"json-formatter2\" width=\"578\" height=\"246\" class=\"aligncenter size-large wp-image-2290\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you get an error debugging an Olingo service (one of the Java libraries for OData), you often get an error like &#8220;An exception occurred.&#8221; This, apparently, is a result of decision by the Olingo team to not be dependent on a specific logging library (although I&#8217;m not sure how this makes sense, since they &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.garysieling.com\/blog\/tips-debugging-olingo-services\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Tips for Debugging Olingo Services&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[4],"tags":[398,399],"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/2287"}],"collection":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/comments?post=2287"}],"version-history":[{"count":0,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/2287\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/media?parent=2287"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/categories?post=2287"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/tags?post=2287"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}