Skip to Main Content

How to call REST API from oracle adf ?

CoderArif03Aug 7 2022

i have an ADF Application Where i called a API using java URLConnection ,which is developed using PHP. Problem is ,my application works fine when it is in my local server but when i deploy it in weblogic server it takes long time and stop loading without any result. I am Using Jdeveloper 12.2.1.4.0
---------------------Code for My api calling ------------------------
URL url = new URL("myAPpiurl .php");
Map<String, Object> params = new LinkedHashMap<>();
params.put("emp_no", emp_no);
params.put("attnDate", attnDate);
params.put("element1", element1);
params.put("element2", element2);
params.put("stdIn", stdIn);
params.put("stdOut", stdOut);
params.put("inTime", inTime);
params.put("outTime", outTime);
params.put("group_id", grpid);

StringBuilder postData = new StringBuilder();  
for (Map.Entry\<String, Object> param : params.entrySet()) {  
  if (postData.length() != 0)  
    postData.append('&');  
  postData.append(URLEncoder.encode(param.getKey(), "UTF-8"));  
  postData.append('=');  
  postData.append(URLEncoder.encode(String.valueOf(param.getValue()), "UTF-8"));  
}  
byte\[\] postDataBytes = postData.toString().getBytes("UTF-8");  


URLConnection conn2 = url.openConnection();  
    conn2.setDoOutput(true);  
    conn2.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");  
    conn2.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));  
   
    try (DataOutputStream dos = new DataOutputStream(conn2.getOutputStream())) {  
      dos.write(postDataBytes);  
    }
This post has been answered by Timo Hahn on Aug 8 2022
Jump to Answer
Comments
Post Details
Added on Aug 7 2022
3 comments
194 views