Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Consuming GET and POST request rest webservices in cq5

Avatar

Avatar
Validate 10
Level 2
veerareddyc2547
Level 2

Likes

5 likes

Total Posts

36 posts

Correct Reply

1 solution
Top badges earned
Validate 10
Validate 1
Boost 5
Boost 3
Boost 1
View profile

Avatar
Validate 10
Level 2
veerareddyc2547
Level 2

Likes

5 likes

Total Posts

36 posts

Correct Reply

1 solution
Top badges earned
Validate 10
Validate 1
Boost 5
Boost 3
Boost 1
View profile
veerareddyc2547
Level 2

25-06-2016

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-c273...");
        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();

      }

    }

}

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Establish
Community Manager
kautuk_sahni
Community Manager

Likes

1,168 likes

Total Posts

6,294 posts

Correct Reply

1,144 solutions
Top badges earned
Establish
Coach
Originator
Contributor 2
Contributor
View profile

Avatar
Establish
Community Manager
kautuk_sahni
Community Manager

Likes

1,168 likes

Total Posts

6,294 posts

Correct Reply

1,144 solutions
Top badges earned
Establish
Coach
Originator
Contributor 2
Contributor
View profile
kautuk_sahni
Community Manager

27-06-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

Answers (2)

Answers (2)

Avatar

Avatar
Validate 1
Level 7
Jitendra_S_Toma
Level 7

Likes

74 likes

Total Posts

615 posts

Correct Reply

84 solutions
Top badges earned
Validate 1
Give Back 50
Give Back 5
Give Back 3
Give Back 25
View profile

Avatar
Validate 1
Level 7
Jitendra_S_Toma
Level 7

Likes

74 likes

Total Posts

615 posts

Correct Reply

84 solutions
Top badges earned
Validate 1
Give Back 50
Give Back 5
Give Back 3
Give Back 25
View profile
Jitendra_S_Toma
Level 7

26-06-2016

What is the your question here?

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,408 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,408 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

25-06-2016

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