{"id":364,"date":"2007-09-09T08:17:05","date_gmt":"2007-09-09T12:17:05","guid":{"rendered":"http:\/\/www.dr-chuck.com\/wordpress\/?p=364"},"modified":"2011-12-17T12:23:53","modified_gmt":"2011-12-17T16:23:53","slug":"calling-rest-web-services-from-java","status":"publish","type":"post","link":"https:\/\/www.dr-chuck.com\/csev-blog\/2007\/09\/calling-rest-web-services-from-java\/","title":{"rendered":"Calling REST Web Services from Java"},"content":{"rendered":"<p>Wow &#8211; it initially seemed much harder to do REST web services in Java than it should have been &#8211; it took a while for me to find this web site.  Everyone wanted me to download a jar or something &#8211; I knew this had to work in a few lines of Java with no jars&#8230;<\/p>\n<p>\nThanks to: http:\/\/xml.nig.ac.jp\/tutorial\/rest\/index.html<\/p>\n<p>\nMy code below.<\/p>\n<p><!--more--><br \/>\n<font size=-1><\/p>\n<pre>\ntry {\n\/\/ Thanks: http:\/\/xml.nig.ac.jp\/tutorial\/rest\/index.html\nURL url = new URL(restEndPoint);\n\/\/make connection, use post mode, and send query\nURLConnection urlc = url.openConnection();\nurlc.setDoOutput(true);\nurlc.setAllowUserInteraction(false);\nString encodedPost = URLEncoder.encode(ret);\nPrintStream ps = new PrintStream(urlc.getOutputStream());\nps.print(\"launchData=\"+encodedPost);\nps.close();\n\/\/retrieve result\nBufferedReader br = new BufferedReader(new InputStreamReader(urlc\n.getInputStream()));\nString str;\nStringBuffer sb = new StringBuffer();\nwhile ((str = br.readLine()) != null) {\nsb.append(str);\nsb.append(\"\\n\");\n}\nbr.close();\nresponse = sb.toString();\nif ( response == null ) {\nsetErrorMessage(request, \"Launch REST Web Service returned nothing\");\n}\n}\ncatch(Exception e) {\ne.printStackTrace();\nsetErrorMessage(request, \"Failed REST service call. Exception=\"+e);\nresponse = null;\n}\n<\/pre>\n<p><\/font><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Wow &#8211; it initially seemed much harder to do REST web services in Java than it should have been &#8211; it took a while for me to find this web site. Everyone wanted me to download a jar or something &#8211; I knew this had to work in a few lines of Java with no [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-364","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/posts\/364","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/comments?post=364"}],"version-history":[{"count":1,"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/posts\/364\/revisions"}],"predecessor-version":[{"id":2453,"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/posts\/364\/revisions\/2453"}],"wp:attachment":[{"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/media?parent=364"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/categories?post=364"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/tags?post=364"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}