Error Calling my testImage() Method from inside an imported .jar file from Eclipe in Wavemaker

65 Views Asked by At

I am simply trying to call my testImage() method in Wavemaker. I imported the .jar file after running the application perfectly in Eclipse. However when I call the same method in the .jar file in Wavemaker it gives my this error:

  Error
Compile failed with output: [{"filename" : "master/services/MyJavaService1/src/com/demo_jquery/myjavaservice1/MyJavaService1.java","type" : "ERROR","lineNumber" : 134,"columnNumber" : 22,"startPosition" : 4743,"endPosition" : 4751,"message" : "The method testImage() in the type pictures.TestUrl is not applicable for the arguments (java.lang.String)"}]

I will now show you the TestUrl class which I call to invoke my two methods testImage() and getImage():

package pictures;



import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

import javax.imageio.ImageIO;

/*
 * By: Victor Foning
 * 
 * This program will consist of two Methods: 
 * 
 * The First will Test the Validity and reachability of an validity 
 *  of an image URL.
 *  
 * The second methods will log4j
 * 
 * 
 * 
 * 
 * 
 */
public class TestUrl {

       public Boolean testImage (String l) {

         //  String urlString = "http://www.eurobiopark.org/sites/default/files/EurobioparkMashups5.1.png";
             System.out.println("Using " + l);

          // Open connection

             URL u = null;
            try {
                u = new URL( l);
            } catch (MalformedURLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
             URLConnection connection = null;
            try {
                connection = u.openConnection();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

          // Check if response code is HTTP_OK (200)

             HttpURLConnection httpConnection 
                   = (HttpURLConnection) connection;
             int code = 0;
            try {
                code = httpConnection.getResponseCode();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
             String message = null;
            try {
                message = httpConnection.getResponseMessage();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } 
             System.out.println(code + " " + message);
             if (code == HttpURLConnection.HTTP_OK) {

                 return true;

             } else {
                return false;
             }



       }

       public void getImage (String u)  {

           BufferedImage image =null;
            try{

                URL url =new URL(u);


                // read the url
               image = ImageIO.read(url);



                ImageIO.write(image, "jpg",new File("C://Users//Foning//Desktop//GeoDataLab//mash7.jpg"));

            }catch(IOException e){
                e.printStackTrace();
            }

        }
}

The Picture is downloaded locally and the Console out is this:

Using http://www.eurobiopark.org/sites/default/files/EurobioparkMashups5.1.png

200 OK true

Here is my TestDownload main Class through which I call my two Methods:

   package pictures;

import java.io.IOException;


/*
 * By: Victor Foning 17/Septembre/2019
 * 
 * From this Main Methods we will call: 
 * 
 * TestUrl.java and the GetImage.java Methods
 * 
 * 
 * 
 */
public class TestDownload {

    public static void main(String[] args)  {

           String path = "http://www.eurobiopark.org/sites/default/files/EurobioparkMashups5.1.png";

        // We Begin encapsulating the TestUrl Methods


        TestUrl im = new TestUrl();

        boolean image = im.testImage(path);
        if(image){
             im.getImage(path);
           System.out.print("true");



        }

        else{
            System.out.print(" victor_WakeUP_false");
        }



    }

}

Here I then export the .jar file (in Bold) into Wavemaker and Make the same method invocation through my JavaService Class:

package com.demo_jquery.myjavaservice1;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pictures.TestUrl;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

import org.springframework.beans.factory.annotation.Autowired;


import com.wavemaker.runtime.security.SecurityService;
import com.wavemaker.runtime.service.annotations.ExposeToClient;
import com.wavemaker.runtime.service.annotations.HideFromClient;

Here you will find the class getImageFromWaveMaker()I create inside my javaService1 class to invoke my two methods:

    package com.demo_jquery.myjavaservice1;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pictures.TestUrl;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

import org.springframework.beans.factory.annotation.Autowired;


import com.wavemaker.runtime.security.SecurityService;
import com.wavemaker.runtime.service.annotations.ExposeToClient;
import com.wavemaker.runtime.service.annotations.HideFromClient;

import com.demo_jquery.myjavaservice1.model.*;


@ExposeToClient
public class MyJavaService1 {

    private static final Logger logger = LoggerFactory.getLogger(MyJavaService1.class);

    @Autowired
    private SecurityService securityService;


    public void getImageFromWavemaker( String p) {



           String path  = 
          "http://www.eurobiopark.org/sites/default/files/EurobioparkMashups5.1.png";


        // We Begin encapsulating the TestUrl Methods


        TestUrl im = new TestUrl();

        boolean image = im.testImage(path);
        if(image){
             //im.getImage(url);
           logger.info("true");



        }

        else{
            logger.info("victor_WakeUP_false");
        }

    }
}

Please help me figure out why I get and Error when I run this code?

1

There are 1 best solutions below

0
BorrchoInternational On

Thanks to a bit of meditation and positive re-orientation from some good friends I was able to solve this issue.

I came to realize that even though camelcase is accepted when declaring method. I re-declared both methods in my TestUrl Class by starting them with a Capital Letter.

With reference to the Error Code:

Aslo, understanding that all classes in java are derived from the object class and that the String class is one of the most important class in Java. I made that java.lang.String class the Super Class when I created all my Classes in Eclipse.

I did a maven Compile, which generated a .jar file. I proceeded to upload the .jar file in my resource lib file on Wavemaker, Binded my variables accordingly with my JavaService class and the results were good.

Please feel free to express any further perspective on this issue, I would be glad to hear it. Thank you!