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.


35 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
  16. Nice blog. Fine theme except of footer. I really like this post. It`s amazing what you wrote here. I hope you will write something so amazing soon. web design company san francisco

    ReplyDelete
  17. Very efficiently written information. It will be beneficial to anybody who utilizes it, including me. Keep up the good work. For sure i will check out more posts. This site seems to get a good amount of visitors. Javascript Commission Bot Review

    ReplyDelete
  18. Music started playing anytime I opened up this web-site, so irritating! la web design

    ReplyDelete
  19. Colin Ferrell and Jennifer Aniston step out of their usual roles and surprisingly deliver plenty of laughs with their own cruelly aggressive mannerisms. web design agency los angeles

    ReplyDelete
  20. i just started dating and well, dating is a very exciting experience. i just love to date women** web design company los angeles

    ReplyDelete
  21. I’m not sure exactly how I discovered your blog because I had been researching information on Real Estate in Lake Mary, FL, but anyway, I have had a pleasant time reading it, keep it up! design firms los angeles

    ReplyDelete
  22. I love your wp format, where did you get a hold of it? website tips

    ReplyDelete
  23. bless you with regard to the particular blog post ive really been looking with regard to this kind of advice on the net for sum time these days hence with thanks web design company

    ReplyDelete
  24. i always look for golf courses with well-maintained lawn and golf courses with very clean recreational area,, los angeles branding

    ReplyDelete
  25. Big thanks to you for sharing such great information.industrial ui services

    ReplyDelete
  26. eCommerce Website Designers who are 100% Australian developers from Website Development Australia. We build high performing eCommerce websites. ecommerce

    ReplyDelete
  27. Share great information about your blog , Blog really helpful for us . We read your blog , share most useful information in blog . Thanks for share your blog here .
    Homeowners association website

    ReplyDelete
  28. While the admin of the web site is working, no question soon it will likely be famous, due to its feature blogs.
    premium corporate gifts

    ReplyDelete
  29. Thanks for the blog loaded with so many information. Stopping by your blog helped me to get what I was looking for. wordpress developers

    ReplyDelete
  30. Thank you for another great article. Where else could anyone get that kind of information in such a perfect way of writing? I have a presentation next week, and I am on the look for such information. web design in Switzerland

    ReplyDelete
  31. Download All Movie Subtitles Here for Hollywood, Bollywood and all kinds of movies. Download English SRT Subtitles Here subtitleplanet.com

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

    ReplyDelete
  33. I have found your article very informative and interesting. I appreciate your points of view and I agree with so many. You’ve done a great job with making this clear enough for anyone to understand.
    digital marketing agency near me

    ReplyDelete
  34. I think this is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article. Epik-protocolEPIK

    ReplyDelete

Recent Posts

Recent Posts Widget

Popular Posts