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();
}
}
}
Solved! Go to Solution.
Views
Replies
Total Likes
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
Views
Replies
Total Likes
To learn how to consume 3rd party Restful web service, see http://scottsdigitalcommunity.blogspot.ca/2013/11/creating-adobe-experience-manager.html.
Views
Replies
Total Likes
What is the your question here?
Views
Replies
Total Likes
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
Views
Replies
Total Likes
Views
Likes
Replies