java - HashMap 通过 SOAP 从 Java 到 PHP 再返回

标签 java php web-services soap wiki

我遇到了一个小问题,找不到解决方案。情况:

  • 我有一个包含不同方法的 Java-Webservice。其中之一创建了一个新对象(名为“Bestellung”,德语为“Order”)。这个对象包含一些属性,大部分是String,一个是名为“applikationsDaten”(应用数据)的Hashmap。
  • 我正在通过 SoapClient 在 php 中接收这个对象 - 所有属性都按我想要的方式填充。 print_r() 显示以下内容(缩短为相关部分):
    stdClass Object (
      [enthMWsT] => 0
      [preisStreckeGesamt] => 28.6
      [waehrung] => EUR
      [applikationsDaten] => stdClass Object (
      [entry] => Array (
        [0] => Array ( [key] => test [value] => 1 )
        [1] => Array ( [key] => fahrDrucken [value] => 1 )
        [2] => Array ( [key] => fahrLfdnr [value] => 0 )
      )
    )
  • after manipulation some of the attributes (but not the application data) i'm trying to send that object back to my webservice which should check some things and save the Order to the Database. This is where the problem appears: all attributes are received perfectly, but the application data isn't. When i'm trying to System.out.print() it, i get the following:
[STDOUT] {[key: null]=[value: null], [key: null]=[value: null], [key: null]=[value: null]}

as you can see, it's the number of elements is correct, but all keys an values are null.

my problem is: why don't i get the correct keys/values on java-side?

PS: if you need more information to analyse this, please don't hesitate to ask

EDIT:

on java-side i'm running a jBoss 4.2.2GA

on PHP-side i use the SoapClient Object like this:

$conf['soap_wsdl'] = "http://192.168.0.213:8180/R1WebService/Service?wsdl";
$conf['soap_timeout'] = 5;

$soap = new SoapClient($conf['soap_wsdl'], array('connection_timeout' => $conf['soap_timeout']));

$bst = $soap->getBestellung()->return;

// some stuff

$return = $soap->saveBestellung(array($bst))->return;

最佳答案

我找到了解决方案:问题出在我的 Java 代码中。像这样在对象中声明 hashmap 是不够的:

private HashMap applikationsDaten;

public HashMap getApplikationsDaten() {
    return applikationsDaten;
}

public void setApplikationsDaten(HashMap applikationsDaten) {
    this.applikationsDaten = applikationsDaten;
}

为了让它工作,我必须像这样为 Hashmap 指定数据类型:

private HashMap<String,String> applikationsDaten;

public HashMap<String,String> getApplikationsDaten() {
    return applikationsDaten;
}

public void setApplikationsDaten(HashMap<String,String> applikationsDaten) {
    this.applikationsDaten = applikationsDaten;
}

更改此设置并重新部署网络服务后,它按预期工作。我会留下这个问题并将其标记为社区 wiki 而不是删除它 - 也许它可以帮助寻找同样失败的人。

PS:感谢 ZeissS 的提示。

关于java - HashMap 通过 SOAP 从 Java 到 PHP 再返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3922163/

相关文章:

web-services - 使用 maven surefire 插件进行 SOAP web 服务测试的可能性

Java可变字节数组数据结构

PHP PDO bindParam 不适用于数组内容

java - 将实体从另一个微服务引用到 jdl-jhipster

php - 简单的内联 diff 算法添加 <ins> <del> 标签以与 PHP 和 HTML 一起使用?

php - 想要一个 while 循环仅在表中显示数据库中的商店列表

java - Eclipse java web项目手动设置WEB-INF中的lib文件夹

vb.net - Silverlight DataGrid 控件 - 如何停止对列进行排序?

java - 将一些字符串日期解析为另一种格式

java - 空指针访问: The variable b can only be null at this location