我需要从PHP调用一个Java服务,它看起来像这样:
getProductsForMode(java.util.Calendar date, int modeId)
我有麻烦映射我的PHP日期类到java.util.Calendar类。我尝试了几种不同的方法,都无济于事:
方法#1(将DateTime对象包装在一个CalendarHandle中,并映射到Java的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);
错误:[06-07-2011 11:16:52] PHP致命错误:未捕获的异常'HttpError'HttpError: MalformedHTTP头信息/用户/jordanb/网站/proposal-framework/箱子/插件/srHessianClientPlugin/hessianphp/Http.php: 265
方法# 2:将DateTime映射到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);
错误:[06-06-2011 11:28:50] PHP致命错误:Uncaught exception 'HessianError' with message 'Hessian Parser, Malformed reply: expected r' in/Users/jordanb/Sites/proposal-framework/trunk/plugins/srHessianClientPlugin/hessianphp/Protocol.php:350
有没有人成功地发送一个日期时间或某种时间戳从PHP到Java使用Hessian?提前感谢!
使用php time()函数(返回int并将其作为long发送到Java)是否可行?在Java中,你可以直接将long传递给new Date(long Date)。
使用unix时间戳。这是最好的选择。
PHP:$ts = time();
以某种方式将$ts
传递给java。
long ts = getTimeFromPhp();
Date dt = new Date(ts);
或者您可以使用Calendar:
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(ts);