belgattitude / soluble-japha

PHP Java integration
https://belgattitude.github.io/soluble-japha/
MIT License
69 stars 15 forks source link

Symfony integration #56

Closed chandrantwins closed 4 years ago

chandrantwins commented 4 years ago

Dear developer,

Thanks for awesome solution for connecting php and java. Please help me to resolve this following issue

request Uncaught PHP Exception Soluble\Japha\Bridge\Exception\JavaException: "Invoke failed: [[o:RestConnection]]->getAttributes((o:String)[o:String]). Cause: java.lang.NullPointerException VM: 1.8.0_222@http://java.oracle.com/" at /home/root/app/vendor/soluble/japha/src/Soluble/Japha/Bridge/Driver/Pjb62/Proxy/DefaultThrowExceptionProxyFactory.php line 102{ "exception": {} }

I hope you can solve this issue ASAP..

Let me know how to resolve this solution.. i hope this is caused by invoke failed.. i dont know how to handle this.. is that already handled in this connector? this is my code used with bridge.

        $options = [
            'servlet_address' => 'http://localhost:8080/MyJavaBridge/servlet.phpjavabridge'
        ];

        try {
            $ba = new BridgeAdapter($options);
            $d = $ba->getDriver();
            $javaObject = $ba->java('com.google.api.external.RestConnection');
            $attributeString = $javaObject->getAttributes($storehash);
                   } catch (BridgeException\ConnectionException $e) {  
            // Server is not reachable
            echo $e->getMessage();
            //echo $e->getMessage();    
            //echo $e->getJavaClassName();
            //echo $e->getStackTrace();
        }
belgattitude commented 4 years ago

Hey @chandrantwins can you just help me a bit...

I would like to exclude setup issues...

  1. can you confirm this works:
$options = [ 'servlet_address' => 'http://localhost:8080/MyJavaBridge/servlet.phpjavabridge' ];

try {
  $ba = new BridgeAdapter($options);
  $d = $ba->getDriver();

  $hashMap = $ba->java('java.util.HashMap', [
        'message' => 'Hello world',
        'value'   => $ba->java('java.math.BigInteger', PHP_INT_MAX)
  ]);
  $hashMap->put('message', '你好,世界');
  echo $hashMap->get('message');

} catch (BridgeException\ConnectionException $e) {  
}
  1. Lib is available on the javabridge server ?

In your case com.google.api.external.RestConnection

You can check by pointing on the bridge address on http://localhost:8080/MyJavaBridge/

image

From there I can provide more support

Nice day !

chandrantwins commented 4 years ago

Hi Belgattitude, Thanks for your quick answer. I have to add some more information to you.. This error not happens always, every time first loading i have this problem, after that its working normally. so i can say this error is not stable at all.

image

and one more additional info is, this symfony application is loaded inside iframe.. is that make difference?

shortly speaking its working as expected except first time

belgattitude commented 4 years ago

I guess not related to iframe...

What gives this ?

$ba = new BridgeAdapter($options);
$restConn = $ba->java('com.google.api.external.RestConnection');
echo $ba->getDriver()->inspect($restConn);
die();

The doc about inspect is here: https://belgattitude.github.io/soluble-japha/language_useful_functions/#inspect-a-javaobject

chandrantwins commented 4 years ago

Hi, This is the response from above code [class com.google.api.external.RestConnection: Constructors: public com.google.api.external.RestConnection()

Fields:

Methods: public java.lang.String com.google.api.external.RestConnection.getChannels(java.lang.String) public java.lang.String com.google.api.external.RestConnection.getAkeneoStatus(java.lang.String) public org.json.JSONObject com.google.api.external.RestConnection.getAkeneoInfo() public org.json.JSONObject com.google.api.external.RestConnection.categorySync(java.lang.String) public org.json.JSONObject com.google.api.external.RestConnection.syncData(java.lang.String) public java.lang.String com.google.api.external.RestConnection.getVersion() public org.json.JSONObject com.google.api.external.RestConnection.getInfo() public java.lang.String com.google.api.external.RestConnection.getAttributes(java.lang.String) public final void java.lang.Object.wait(long,int) throws java.lang.InterruptedException public final native void java.lang.Object.wait(long) throws java.lang.InterruptedException public final void java.lang.Object.wait() throws java.lang.InterruptedException public boolean java.lang.Object.equals(java.lang.Object) public java.lang.String java.lang.Object.toString() public native int java.lang.Object.hashCode() public final native java.lang.Class java.lang.Object.getClass() public final native void java.lang.Object.notify() public final native void java.lang.Object.notifyAll()

Classes: ]

chandrantwins commented 4 years ago

Hi, For your information this method call one external api and return that response as array. is that possible? if api call not yet finished but returns this method called? $attributeString = $javaObject->getAttributes($storehash);

any idea? this is just my guess

belgattitude commented 4 years ago

NullPointerException is always tricky :D

With the little context I have, I just feel there's something to look into:

For your information this method call one external api and return that response as array

but

public java.lang.String com.google.api.external.RestConnection.getAttributes(java.lang.String)

(Just to be sure, the nullpointer is not actually real and sent from there)

Second path I would investigate... because "this problem seems to occur from time to time". Be sure the initialization of the bridge is done only once (during the life of you php request)

Does it help ?

PS:

BTW, I'm not using the bridge anymore... It was more a playground for me although there's still few heavy production workloads based on it... But IMO I don't really see big future as rest api's are so easy to write now. Just for you to know, but of course there's a bit of fun doing it :) Choose with care.

chandrantwins commented 4 years ago

Hi belgattitude,

Thanks for your reply, i found reason for null pointer ,finally. its jdbc connection problem in hibernate access, i solved that.. now i dont see that error.

Thanks Chandran