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. Nice Information Your first-class knowledge of this great job can become a suitable foundation for these people. I did some research on the subject and found that almost everyone will agree with your blog.
    Cyber Security Course in Bangalore

    ReplyDelete
  2. Writing in style and getting good compliments on the article is hard enough, to be honest, but you did it so calmly and with such a great feeling and got the job done. This item is owned with style and I give it a nice compliment. Better!
    Cyber Security Training in Bangalore

    ReplyDelete


  3. Top quality blog with unique content and found valuable looking forward for next updated thank you
    Ethical Hacking Course in Bangalore

    ReplyDelete
  4. Hi there, I discovered your web site by means of
    Google while searching for a related topic, 바카라사이트 your site came up, it appears to be
    like great. I have bookmarked it in my google bookmarks.

    ReplyDelete
  5. Fantastic blog! Do you have any helpful hints for aspiring writers?
    I'm hoping to start my own blog soon but I'm a little 온라인카지노
    lost on everything. Would you advise starting with a free platform like Wordpress or go for a paid
    option? There are so many choices out there that I'm totally confused ..
    Any suggestions? Many thanks!

    ReplyDelete
  6. Great blog here! Also your web site loads up very fast!

    What host are you using? Can I get your affiliate link to your host?
    I wish my web site loaded up as fast as yours lol 토토

    ReplyDelete
  7. I'd like to find out more? I'd like to find out some additional information. 토토

    ReplyDelete
  8. But he's trying none the less. I've been using Movable-type on a variety of websites for about a year and am nervous about switching to another platform. I have heard good things about . Is there a way I can import all my word press posts into it? Any help would be really appreciated! 야설

    ReplyDelete
  9. Hello there and thank you for your information – I've definitely picked up anything new from right here. I did however expertise a few technical points using this website, since I experienced to reload the site a lot of times previous to I could get it to load properly. I had been wondering if your web host is OK? 오피헌터

    ReplyDelete
  10. Adapted to new systems and processes well and seeks out training to enhance knowledge, skills and abilities. 타이마사지

    ReplyDelete
  11. Not that I am complaining, but slow loading instances times will sometimes affect your placement in google and could damage your high-quality score if advertising and marketing with Adwords. Well I am adding this RSS to my e-mail and can look out for a lot more of your respective fascinating content. 안마

    ReplyDelete
  12. I’m very pleased to discover this site. I want to to thank you for ones time for this particularly wonderful read!! I definitely savored every part of it and i also have you saved as a favorite to see new information on your blog
    카지노사이트

    wep

    ReplyDelete
  13. Great post. I was checking continuously this blog and I am impressed! Extremely helpful info particularly the last part :) I care for such info a lot. I was seeking this particular information for a long time. Thank you and good luck.
    슬롯사이트


    >cc

    ReplyDelete

  14. Very good written article. It will be supportive to anyone who utilizes it, including me. Keep doing what you are doing ? can’r wait to read more posts.
    very nice article. 오피월드

    ReplyDelete
  15. Aw, this was a really nice post. In idea I would like to put in writing like this additionally –
    taking time and actual effort to make a very good article… but what can I say…
    I procrastinate alot and by no means seem to get something done.

    my web page;온라인경마

    ReplyDelete

Recent Posts

Recent Posts Widget

Popular Posts