1. Suhas Shravagi
  2. PowerBuilder
  3. Thursday, 3 September 2020 18:42 PM UTC

I have a java class that has one method that takes some parameters as input and returns an array. I need to call this java method from PowerBuilder desktop application by passing the required parameters, and then capture the response from the method (array in this case.) How can this be achieved? Please provide step-by-step information for the same. Thanks!

Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Friday, 11 September 2020 18:58 PM UTC
  2. PowerBuilder
  3. # 1

Hi Suhas;
    FYI: I reworked your PB to Java example and got it working. I had to tweak both the PB and Java sides a little.

HTH

Regards ... Chris

Attachments (1)
Comment
There are no comments made yet.
Suhas Shravagi Accepted Answer Pending Moderation
  1. Friday, 11 September 2020 11:25 AM UTC
  2. PowerBuilder
  3. # 2

Hi Chris,

The test application where we have tried to call java method is attached (attachment: JavaCallInPB.zip) It also contains the java code that we are using. The main issue here is the proxy is not at all getting generated.

Thanks,

Suhas Shravagi.

Attachments (1)
Comment
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Thursday, 3 September 2020 20:25 PM UTC
  2. PowerBuilder
  3. # 3

Hi Suhas;

  FYI: You can call a Java Class and its method(s) directly from a PB App.

Example: http://chrispollach.blogspot.com/2019/09/pb2j.html

HTH  Regards ... Chris

Comment
  1. Chris Pollach @Appeon
  2. Thursday, 3 September 2020 23:11 PM UTC
Hi Olan ... You can do this since PB 8. This feature was added along with the EAServer support. ;-)

I have PB 12.x examples in my Archive folder. I have older ones if needed in my backups (if needed).

https://sourceforge.net/projects/stdfndclass/files/Applications/PowerBuilder/PB2Java/Archive

  1. Helpful
  1. Suhas Shravagi
  2. Friday, 4 September 2020 19:18 PM UTC
Chris, I tried with the creating the EJB Client Proxy, but it is failing to deploy. I followed below steps:

1) Created a java class as below:

public class Converter implements ConverterHome {

public double dollarToYen(double dollar) {

return dollar * 60;

}

}



2) Created an interface as below:

public interface ConverterHome {

public double dollarToYen(double dollar);

}



3) compiled and copied both these .class files in the same directory as my application exe.



4) Thru PowerBuilder, set the required parameters in the EJBClient Proxy Wizard as below:

EJB Component name: Converter

EJB Component Home Interface name: ConverterHome

EJB stub classpath: left blank

Prefix for EJB Component Proxy name: left blank



5) Selected the deployment pbl and then start deploying the proxy. Here it is throwing the error as:

---------- Deploy: Deploy of p_mailsend_ejbclientproxy (12:45:15 AM)

Retrieving PowerBuilder Proxies from EJB...

Generation Errors: Can't get information of ConverterHome

Deployment Error: No files returned for package/component 'Converter'. Error code: Unknown. Proxy was not created.

---------- Finished Deploy of p_mailsend_ejbclientproxy (12:45:15 AM)



Can you help what is wrong in the procedure above? I have added the pbejbclient170.pbd in in the library search path.
  1. Helpful
  1. Chris Pollach @Appeon
  2. Tuesday, 8 September 2020 17:43 PM UTC
Hi Suhas;

Just follow my PB2017 Rx example and documentation from the above links. If that does not help, I would suggest posting your test app work here for us to look into further.

Regards ... Chris
  1. Helpful
There are no comments made yet.
Olan Knight Accepted Answer Pending Moderation
  1. Thursday, 3 September 2020 20:19 PM UTC
  2. PowerBuilder
  3. # 4

This is not all that difficult if the class you are calling is set up to handle all of the parameter the Java code will require. The base of the following code is the call to the RUN command.


// OKnight, 29-JAN-2007.
ib_first_pass  = TRUE
ls_java_exe = "c:\windows\system32\java.exe"      // We have code to ensure this is correct
is_java_title  = ls_java_exe      

logWrite (il_aurlog, "   Source UID   = " + string (ii_source_uid))
logWrite (il_aurlog, "   File name      = " + is_pathname + is_filename)


// OKnight, 15-FEB-2005.   Wrap all string parms in double-quotes.
//      The variables used in the string below were all determined previously.
//      The class is StartCabsProcessing and everything after that are the class parameters.

// ----------------------------------------------------------------------------------------------------------
ls_cmd = ls_java_exe                                                       + &
                ' -Xmx' + String(ii_memory)  + 'm'                     + &
                ' -cp "' + ls_jar_file + '"'                                     + &
                ' StartCabsProcessing -UID=' + String(ii_aur_source_uid) + &
                ' -FILEUID=' + String(ii_source_uid)                 + &
                ' -SS=' + String(il_batch_size)                          + &
                ' -CONFIGFILE="'   + ls_config_file        + '"'    + &
                ' "' + is_pathname + is_filename            + '"'
                             

// Actually start the JAVA process....
li_ret = run (ls_cmd, Minimized!)
IF li_ret <= 0 THEN
    ls_txt = "The RUN command failed to start JAVA.EXE. ~r~n "     + &
                "~r~n Java: "             + ls_java_exe                                + &
                "~r~n CFG:  "             + ls_config_file                               + &
                "~r~n Jar:  "               + ls_jar_file                                    + &
                "~r~n Path: "              + is_pathname                              + &
                "~r~n File: "                + is_filename                                + &
                "~r~n Memory: "         + String(ii_memory)                     + &
                "~r~n UID:  "               + String(ii_aur_source_uid)         + &
                "~r~n Source ID: "      + String(ii_source_uid)                 + &
                "~r~n Batch Size: "     + String(il_batch_size)                  + &
                "~r~n~r~n ls_cmd: "  + ls_cmd
   GOTO Exit_Function
END IF

// Prevent the user from closing the window before we are done
of_set_prevent_close (TRUE)

// OKnight, 10-NOV-2014, R#550105:  Enable the CANCEL button.
cb_cancel_processing.Enabled  = TRUE
cb_folder_start.Enabled            = FALSE


wf_set_progress (0.20)                  // Progress meter displayed to the user
ib_javaprocstarted = TRUE
ls_pathname           = is_pathname + is_filename + ".out"        // OKnight, 24-OCT-2006.

// OKnight, 24-OCT-2006.  Its possible that the Java processing will complete
//    before we get here, so check for that condition.
time        lt_start, lt_curr
long        ll_seconds

Sleep (2)
lt_start = Now ()
DO
    val             = FindWindowW(0, is_java_title)
    lb_exists   = FileExists (ls_pathname)
    lt_curr       = Now ()
    ll_seconds = SecondsAfter (lt_start, lt_curr)
    Sleep (0.5)
LOOP UNTIL(val > 0) OR (val = 0 AND lb_exists) OR (ABS (ll_seconds) > 5)

    
// OKnight, 14-FEB-2007.
logWrite (il_aurlog, "wf_start_java - val = " + string (val))
       

Comment
There are no comments made yet.
Michael Kramer Accepted Answer Pending Moderation
  1. Thursday, 3 September 2020 19:32 PM UTC
  2. PowerBuilder
  3. # 5

 Hi Suhas,

Chris has excellent "direct" approach for current releases of PB. Thanks, Chris!

Olan has excellent example of interfacing via command-line which also works for older versions of PB.

An alternative is to wrap your java class in COM - and then call via OLEObject like any other COM. This example calls java code from VBScript using COM as interface.

HTH /Michael

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.