1

There is a Java service that I need to invoke from PHP that looks something like this:

getProductsForMode(java.util.Calendar date, int modeId)

I'm having trouble mapping my PHP date class to the java.util.Calendar class. I've tried a couple different approaches, all to no avail:

Approach #1 (wrapping DateTime object in a CalendarHandle that gets mapped to Java's CalendarHandle):

class CalendarHandle
{
  public $type;
  public $date;

  function __construct($date=null)
  {
    $this->date = $date;
  }
}

$this->hessianClient = new HessianClient(_HESSIAN_ENDPOINT, $hessianOptions);
$config = &HessianConfig::globalConfig();
$config->typeMap->mapRemoteType('com.caucho.hessian.io.CalendarHandle', 'CalendarHandle');

$time = new CalendarHandle(new DateTime($dateEvaluated));
$products = $this->hessianClient->getProductsForMode($time, 1234);

Error:

[06-Jul-2011 11:16:52] PHP Fatal error: Uncaught exception 'HttpError' with message 'HttpError: Malformed HTTP header' in /Users/jordanb/Sites/proposal-framework/trunk/plugins/srHessianClientPlugin/hessianphp/Http.php:265

Approach #2: Mapping DateTime to java.util.Calendar

$this->hessianClient = new HessianClient(_HESSIAN_ENDPOINT, $hessianOptions);
$config = &HessianConfig::globalConfig();
$config->typeMap->mapRemoteType('java.util.Calendar', 'DateTime');

$time = new DateTime($dateEvaluated);
$products = $this->hessianClient->getProductsForMode($time, 1234);

Error:

[06-Jul-2011 11:28:50] PHP Fatal error: Uncaught exception 'HessianError' with message 'Hessian Parser, Malformed reply: expected r' in /Users/jordanb/Sites/proposal-framework/trunk/plugins/srHessianClientPlugin/hessianphp/Protocol.php:350

Has anyone had success sending a DateTime or some sort of timestamp from PHP to Java using Hessian? Thanks in advance!

Jordan Brown
  • 13,603
  • 6
  • 30
  • 29

2 Answers2

1

Would it be practical to just use the php time() function (which returns an int and send this as a long to Java? In Java you could just pass the long to new Date(long Date).

James Scriven
  • 7,784
  • 1
  • 32
  • 36
1

Use unix timestamp. That's the best bet.

PHP:

$ts = time();

Pass $ts to java in someway.

Java:

long ts = getTimeFromPhp();
Date dt = new Date(ts); 

Or you can use Calendar:

Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(ts);
DarthJDG
  • 16,511
  • 11
  • 49
  • 56
Sid Malani
  • 11
  • 1