How to make calls to http sites from groovy in Designer

  • KM03770072
  • 28-Dec-2020
  • 28-Dec-2020

Summary

Some times users need to make calls to http outside sites from the BF, here you will find the way as reference and an open groovy code.

Question

 There isn’t documentation taking about it, some, groovy programming will take place in order to do that calls from the business flow, here you will find the way to do it.

Answer

 What are the versions being affected?
All versions

 How to show an example of that groovy?

1. Go to Designer
2. Do simple Model and cartridge without purse, just for this need and purposes.
3. Now to go Business Flow creation
4. Choose Groovy activity
5. Then there you would include bellow code
6. Just check it out and make adjustments on your needs
7. But having this you can understand how to handle it
8. This is only for reference, but, just like this, it works fine
9. Code is:


// Java program to demonstrate working of URL
import java.net.MalformedURLException;
import java.net.URL;
import java.lang.Object;

public class URLclass1
{
public static void main(String[] args)
throws MalformedURLException
{
// creates a URL with string representation.
URL url1 =
new URL("https://www.google.co.in/?gfe=cr&ei=ptq" +
"WK26I4fT8gfth6CACg#q=geeks+for+geeks+java");
// creates a URL with a protocol,hostname,and path
URL url2 = new URL("http", "www.<yourhttpsitehere>.org",
"/jvm-works-jvm-architecture/");
URL url3 = new URL("https://www.google.co.in/search?"+
"q=gnu&rlz=1C1CHZL_enIN71" +
"4IN715&oq=gnu&aqs=chrome..69i57j6" +
"9i60l5.653j0j7&sourceid=chrome&ie=UTF" +
"-8#q=geeks+for+geeks+java");
URL url4 = new URL("https://www.<yoursitehttphere>.com/index.html");
// print the string representation of the URL.
System.out.println(url1.toString());
System.out.println(url2.toString());
System.out.println();
System.out.println("Different components of the URL3-");
// retrieve the protocol for the URL
System.out.println("Protocol:- " + url3.getProtocol());
// retrieve the hostname of the url
System.out.println("Hostname:- " + url3.getHost());
// retrieve the defalut port
System.out.println("Default port:- " +
url3.getDefaultPort());
// retrieve the query part of URL
System.out.println("Query:- " + url3.getQuery());
// retrive the path of URL
System.out.println("Path:- " + url3.getPath());
// retrive the file name
System.out.println("File:- " + url3.getFile());
// retrieve the reference
System.out.println("Reference:- " + url3.getRef());

// Yo metiendo mas aqui
System.out.println(" ++++++++++ GATO ++++++++");
// https://www.<yoursitehttphere>.com/index.html
"cmd /c \"start chrome https://www.<yoursitehttphere>.com/index.html\"".execute()
System.out.println(" ++++++++++ Fin ++++++++");

}
}


10. This is only a code FYReference.