Tuesday, November 27, 2012

Java Client to Consuming Liferay JSON web Services

Download java class and required jar files from following URL
Consuming Liferay Json Web Service

1)      Write fooling java program in your java project.

public static void main(String[] args) throws ClientProtocolException, IOException {
            ArrayList<HashMap<String, String>>mylist = new ArrayList<HashMap<String, String>>();

                        //Get the data (see above)
                        HttpHost targetHost = new HttpHost("localhost", 8080, "http");
                        DefaultHttpClient httpclient = new DefaultHttpClient();
                        httpclient.getCredentialsProvider().setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()),new UsernamePasswordCredentials("test@liferay.com", "test"));
                        AuthCache authCache = new BasicAuthCache();
                        BasicScheme basicAuth = new BasicScheme();
                        authCache.put(targetHost, basicAuth);
                        BasicHttpContext ctx = new BasicHttpContext();
                        //ctx.setAttribute(ClientContext.AUTH_CACHE,authCache);
                        HttpPost post = new HttpPost("/tunnel-web/secure/json");
                        List<NameValuePair> params = new ArrayList<NameValuePair>();
                        params.add(new BasicNameValuePair("serviceClassName", "com.liferay.portal.service.CountryServiceUtil"));
                        params.add(new BasicNameValuePair("serviceMethodName", "getCountries"));
                        params.add(new BasicNameValuePair("serviceParameters", "[]"));
                        UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, "UTF-8");
                        post.setEntity(entity);
                        HttpResponse resp = httpclient.execute(targetHost, post, ctx);
                        resp.getEntity().writeTo(System.out);
                        httpclient.getConnectionManager().shutdown();
      
            }
           
}


2)       Compile and Run the java program using dos command prompt or using eclipse.
3)      See the console you will get the all Countries data in the json format.
Following are the required Jar files
commons-codec-1.7.jar
httpclient-4.1-beta1.jar
           
Add above jar file in your project build path. these are required to compile and run the the java client program.


16 comments :

  1. it's far profitable analyzing this blog. i was looking such kind of blog for a long time however now I assume I had been given a weblog of my interest. i'm thankful for those all hints noted beneath this weblog. Avaya Cloud

    ReplyDelete
  2. An excellent web design should not only be visually appealing but alsopowerful concerning achieving the goals of the site. If you're also one
    searching for the best web design business in India then think about Webtids.online

    ReplyDelete
  3. If your organization wants a responsive, beautiful website, give us acall today! Make sure you aren't sold on an organization, only to discover they
    are likely to outsource your design and coding to somebody else.web design singapore

    ReplyDelete
  4. I genuinely enjoyed this. It was incredibly educational and useful. I will return to examine on upcoming posts web design manhattan

    ReplyDelete
  5. Oh my goodness! an amazing article dude. Thanks Nevertheless I am experiencing concern with ur rss . Don’t know why Unable to subscribe to it. Is there anybody getting an identical rss downside? Anyone who is aware of kindly respond. Thnkx new york website design company

    ReplyDelete
  6. This comment has been removed by the author.

    ReplyDelete
  7. Hi, you used to write excellent articles, but the last several posts have been kinda boring… I miss your tremendous posts. Past few posts are just a little out of track! san francisco brand agency

    ReplyDelete
  8. Hi to everybody, here everyone is sharing web design agencies such knowledge, so it’s fastidious to see this site, and I used to visit this blog daily.

    ReplyDelete
  9. wonderful post, very informative. I wonder why the other experts of this sector do not notice this. You must continue your writing. I’m sure, you’ve a great readers’ base already! see

    ReplyDelete
  10. Heya i’m for the first time here. I found this board and I to find It truly helpful & it helped me out a lot. I hope to provide something back and aid others such as you helped me. website design san francisco

    ReplyDelete
  11. We cater to all levels of site development from small business sites to large e-commerce websites. web development agency in usa

    ReplyDelete
  12. I’m having a small problem. I’m unable to subscribe to your rss feed for some reason. I’m using google reader by the way. web design agency san francisco

    ReplyDelete
  13. The actual challenge to become is normally you can actually SOLE check out that level of your tax discount over the internet by looking at your RATES web-site. website designers san francisco

    ReplyDelete
  14. I really like your site.. excellent colorations & motif. Would people design and style this fabulous website your self or would you actually hire an attorney to acheive it available for you? Plz answer while I!|m trying to style my own website and would choose to learn wherever ough acquired the following coming from. thank you web design agency san francisco

    ReplyDelete
  15. Thanks for the tips you have provided here. One more thing I would like to mention is that laptop memory requirements generally increase along with other breakthroughs in the engineering. For instance, as soon as new generations of processors are introduced to the market, there is usually a matching increase in the shape demands of all computer system memory plus hard drive room. This is because the application operated by these cpus will inevitably boost in power to leverage the new engineering. design agency san francisco

    ReplyDelete

Recent Posts

Recent Posts Widget

Popular Posts