Consuming GET and POST request rest webservices in cq5 | Community
Skip to main content
Level 3
June 25, 2016
Solved

Consuming GET and POST request rest webservices in cq5

Hi  All,

http://www.mkyong.com/webservices/jax-rs/restfull-java-client-with-java-net-url/

Here is my simple POST request webservices with header and body

 

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class NetClientPost {

    // http://localhost:8080/RESTfulExample/json/product/post
    public static void main(String[] args) {

      try {

        //URL url = new URL("http://api.sewadwaar.rajasthan.gov.in/app/live/evolt_services?client_id=4ec78278-dfa0-4d26-9cd6-c273099f8afa");
        URL url = new URL("http://rsldc.rajasthan.gov.in/rsldcscripts/ASBIViewRest.dll/datasnap/rest/TASBIViewREST/getiview");
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setDoOutput(true);
        conn.setRequestMethod("POST");
        conn.setRequestProperty("Content-Type", "text/xml");
        conn.setRequestProperty("Content-Type", "application/json");
        //conn.setRequestProperty("SOAPAction", "http://tempuri.org/EvoltServices");

        //String input = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:tem='http://tempuri.org/'><soapenv:Header/><soapenv:Body><tem:EvoltServices/></soapenv:Body></soapenv:Envelope>";
        String input = "{\"_parameters\": [{\"getiview\": {\"name\": \"mobiledm\",\"axpapp\": \"rsldcnew\",\"username\":\"mobileuser\",\"password\":\"f42072a505a77871369cbfcade976a3a\",\"seed\":\"\",\"s\": \"\",\"pageno\": \"1\",\"pagesize\": \"100\",\"sqlpagination\": \"true\",\"params\": {}}}]}";
        OutputStream os = conn.getOutputStream();
        os.write(input.getBytes());
        os.flush();

        if (conn.getResponseCode() != HttpURLConnection.HTTP_CREATED) {
            //throw new RuntimeException("Failed : HTTP error code : "
            //    + conn.getResponseCode());
        }

        BufferedReader br = new BufferedReader(new InputStreamReader(
                (conn.getInputStream())));

        String output;
        System.out.println("Output from Server .... \n");
        while ((output = br.readLine()) != null) {
            System.out.println(output);
        }

        conn.disconnect();

      } catch (MalformedURLException e) {

        e.printStackTrace();

      } catch (IOException e) {

        e.printStackTrace();

     }

    }

}

  

 

 

 

and  here is my simple GET request webservices 

 

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class NetClientGet {

    // http://localhost:8080/RESTfulExample/json/product/get
    public static void main(String[] args) {

      try {

        URL url = new URL("http://164.100.222.109/eemsapptest/webservices/eemsservice.asmx/GetCasteCategory");
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("GET");
        conn.setRequestProperty("Accept", "application/json");

        if (conn.getResponseCode() != 200) {
            throw new RuntimeException("Failed : HTTP error code : "
                    + conn.getResponseCode());
        }

        BufferedReader br = new BufferedReader(new InputStreamReader(
            (conn.getInputStream())));

        String output;
        System.out.println("Output from Server .... \n");
        while ((output = br.readLine()) != null) {
            System.out.println(output);
        }

        conn.disconnect();

      } catch (MalformedURLException e) {

        e.printStackTrace();

      } catch (IOException e) {

        e.printStackTrace();

      }

    }

}

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
kautuk_sahni
kautuk_sahniAccepted solution
Employee
June 27, 2016

Hi, 

What is question here, do you have problem in consuming GET and POST request rest webservices in cq5 ??

Please have a look at the Helpx article covering the same:- 

 

Link:- https://helpx.adobe.com/experience-manager/using/uploading-files-aem1.html

// This article will show you how to invoke doPost/doGet methods from AJEX/Form Submission.

 

Link:- https://helpx.adobe.com/experience-manager/using/aem_wordpress.html

// consume 3rd party Restful web service

 

Link:- https://helpx.adobe.com/experience-manager/using/vanitypath.html

//Ajex to doGet/doPost invocation

 

I hope this will help you.

Thanks and Regards

Kautuk Sahni

Kautuk Sahni

3 replies

kautuk_sahni
kautuk_sahniAccepted solution
Employee
June 27, 2016

Hi, 

What is question here, do you have problem in consuming GET and POST request rest webservices in cq5 ??

Please have a look at the Helpx article covering the same:- 

 

Link:- https://helpx.adobe.com/experience-manager/using/uploading-files-aem1.html

// This article will show you how to invoke doPost/doGet methods from AJEX/Form Submission.

 

Link:- https://helpx.adobe.com/experience-manager/using/aem_wordpress.html

// consume 3rd party Restful web service

 

Link:- https://helpx.adobe.com/experience-manager/using/vanitypath.html

//Ajex to doGet/doPost invocation

 

I hope this will help you.

Thanks and Regards

Kautuk Sahni

Translate
Kautuk Sahni
Jitendra_S_Toma
Level 10
June 27, 2016

What is the your question here?

Translate
smacdonald2008
Level 10
June 25, 2016

To learn how to consume 3rd party Restful web service, see http://scottsdigitalcommunity.blogspot.ca/2013/11/creating-adobe-experience-manager.html.

Translate