0

I had success to run Php/Java bridge project and test.php but i got a problem. i would like to invoke a Java method with Java Object parameter Java Source:

public class OtherClass {
    public BaseBean funBean(BaseBean param){
        param.setName("Bean Name");
        return param;
    }
}

public class BaseBean {
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String name;

}

PHP Script: I would like to it can run like that,it can't.

<?php
require_once("java/Java.inc");
//require_once("java/java_helper.php");

class BaseBean{
    public $name;
}
$eh = new java("com.anima.service.OtherClass");
$cla = new BaseBean();
$cla->name = "nameTest";
$eh->funBean($cla);
?>

Or there are some solution can help me to implement this idea. I want to invoke java method with php object.

Can you please anyone help me on this.

Thanks in advance.

1 Answer 1

0

I guess you should create BaseBean as a "java instance" as well:

$cla = new java("com.anima.service.BaseBean");

Or alternatively you can try out with java_closure but I think in this case you have to change the expected type in your java method like this:

public Object funBean(Object param){ ... }
$cla = new BaseBean();
$cla->name = "nameTest";
$jObjCla = java_closure($cla);
$eh->funBean($jObjCla);

I've found in PHP/Java bridge documentation that java_closure method has got a third parameter what is an array of Java interfaces should be implemented by the created wrapped object:

java_closure(new Listener(), null, array(new Java("java.awt.event.ActionListener")));

Java source:

public interface IBaseBean {
    String getName();
    void setName(String name);
}

public class OtherClass {
    public IBaseBean funBean(IBaseBean param){
        param.setName("Bean Name");
        return param;
    }
}

public class BaseBean implements IBaseBean {
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String name;
}

PHP script:

<?php
require_once("java/Java.inc");

class BaseBean{
    public $name;
}
$eh = new java("com.anima.service.OtherClass");
$cla = new BaseBean();
$cla->name = "nameTest";
$jObjCla = java_closure($cla, null, array(new Java("com.anima.service.IBaseBean")));
$eh->funBean($jObjCla );
?>
Sign up to request clarification or add additional context in comments.

4 Comments

thanks to answer,but it got a error java call stack: Feb 11 19:52:15 JavaBridge ERROR: An exception occured: java.lang.IllegalArgumentException: argument type mismatch php call stack: Warning: Unchecked exception detected: [[o:Response$UndeclaredThrowableErrorMarker]:"FATAL: Undeclared java.lang.RuntimeException detected. java.lang.Exception: Invoke failed: [[o:OtherClass]]->funBean((o:BaseBean)[o:$Proxy1]). Cause: java.lang.IllegalArgumentException: argument type mismatch VM:
I'm sorry I cannot try it out now because I don't have an environment here but have you changed the funBean method as well? (to expect the interface instead of the class)
so, is it working now? or shall I check it when I arrive home?
yes,it work,Thanks a lot:) but php script should implements getter&setter just like Java interface

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.