0

I am using hessian between php and java service.

In php client:

$proxy = new HessianClient($testurl, $options);
$result = $proxy->waoo(309000100340);

In java server:

public Long waoo(long id) {
    System.out.println(id);
    return id;
}

But java printed -237544972 and php got int(4057422324).

That means java regard the input as int while it's long.

How can I solve this problem?

wwulfric
  • 521
  • 1
  • 4
  • 14

2 Answers2

0

Perhaps there is no solution for this problem. Java received hessian binary data and deserialize it based on the data's characters. Thus the int from php will be deserialized as java int. Then java transform value to the declared type(long), but in the pervious step the int variable has been already overflown.

The alternative solution is to use string to transfer data between different language.

wwulfric
  • 521
  • 1
  • 4
  • 14
0
class HessianWriter extends HessianProtocolHandler
{
    function writeObject(&$value)
    {
        $type = gettype($value);
        switch ($type) {
            case 'integer':
                if (defined('HESSAIN_USE_LONG') && HESSAIN_USE_LONG)
                    $dispatch = 'writeLong';
                else
                    $dispatch = 'writeInt';
                break;
    }
}

Set the constant HESSAIN_USE_LONG to true before calling the method and be happy