1 Reply Latest reply on Nov 15, 2019 6:08 AM by Srini Veeravalli

    Java transformation and rest api using Developer

    Luiz Evora New Member

      Hi,

       

      I am trying to use java transformation in the Developer tool, but I am receiving the folowing error: "illegal start of expression".

       

      -- Imports tab

      import java.io.BufferedReader;

      import java.io.InputStreamReader;

      import java.net.HttpURLConnection;

      import java.net.URL;

       

       

      -- Input tab

      public class Main {

        public static void main(String[] args) throws Exception  {

          //System.out.println("Hello world!");

       

              URL url = new URL("https://viacep.com.br/ws/24120191/json");

              HttpURLConnection con = (HttpURLConnection) url.openConnection();

              con.setRequestMethod("GET");

         

              BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));

       

              String inputLine;

              while ((inputLine = in.readLine()) != null) {

                 System.out.println(inputLine);

              }

              in.close();

            }

      }

       

      Are there any limitations regarding the java code I am writing? The code works fine when I run using an external compiler.

        • 1. Re: Java transformation and rest api using Developer
          Srini Veeravalli Guru

          The below works fine for me at command prompt.

           

          import java.io.BufferedReader;

          import java.io.InputStreamReader;

          import java.net.HttpURLConnection;

          import java.net.URL;

          public class Main {

            public static void main(String[] args) throws Exception  {

              //System.out.println("Hello world!");

                   URL url = new URL("https://viacep.com.br/ws/24120191/json");

                  HttpURLConnection con = (HttpURLConnection) url.openConnection();

                  con.setRequestMethod("GET");

                     BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));

                   String inputLine;

                  while ((inputLine = in.readLine()) != null) {

                     System.out.println(inputLine);        }

                  in.close();

                }

          }