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.


10 comments :

  1. 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
  2. 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
  3. 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
  4. Adapted to new systems and processes well and seeks out training to enhance knowledge, skills and abilities. 타이마사지

    ReplyDelete
  5. 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
  6. 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

  7. 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
  8. 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
  9. I really like what you guys are up too. This type of clsver work and exposure!
    Keep up the amazing works guys I've added you guys tto our
    blogroll.경마



    ReplyDelete

Recent Posts

Recent Posts Widget

Popular Posts