HashMap 通过 SOAP 从 Java 到 PHP 再返回 [英] HashMap via SOAP from Java to PHP and back

查看:26
本文介绍了HashMap 通过 SOAP 从 Java 到 PHP 再返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  • 我有一个包含不同方法的 Java-Web 服务.其中之一创建了一个新对象(命名为Bestellung",德语中的Order").这个对象包含一些属性,大部分是Strings,一个是名为applikationsDaten"(应用数据)的Hashmap.
  • 我通过 SoapClient 在 php 中接收到这个对象 - 所有属性都按照我的需要填充.print_r() 显示以下内容(缩短为相关部分):
<前>标准类对象 ([enthMWsT] => 0[preisStreckeGesamt] => 28.6[waehrung] => 欧元[applikationsDaten] => stdClass 对象([条目] => 数组 ([0] => 数组( [键] => 测试 [值] => 1)[1] => 数组 ( [key] => fahrDrucken [value] => 1 )[2] => 数组( [key] => fahrLfdnr [value] => 0)))

  • 在操作一些属性(但不是应用程序数据)之后,我试图将该对象发送回我的网络服务,该服务应该检查一些内容并将订单保存到数据库中.这就是问题出现的地方:所有属性都被完美接收,但应用程序数据不是.当我尝试 System.out.print() 它时,我得到以下信息:
<前>[STDOUT] {[key: null]=[value: null], [key: null]=[value: null], [key: null]=[value: null]}

如您所见,元素的数量是正确的,但所有键和值都是null.

我的问题是:为什么我在 java 端没有得到正确的键/值?

PS:如果你需要更多信息来分析这个,请不要犹豫,问

在 java 端,我正在运行 jBoss 4.2.2GA

在 PHP 端,我使用 SoapClient 对象,如下所示:

$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;//一些东西$return = $soap->saveBestellung(array($bst))->return;

解决方案

我找到了解决方案:问题出在我的 java 代码中.像这样在对象中声明哈希图是不够的:

private HashMap applikationsDaten;公共 HashMap getApplikationsDaten() {返回应用程序日期;}公共无效 setApplikationsDaten(HashMap applikationsDaten) {this.applikationsDaten = applikationsDaten;}

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

私有HashMap应用程序日期;公共 HashMapgetApplikationsDaten() {返回应用程序日期;}public void setApplikationsDaten(HashMap applikationsDaten) {this.applikationsDaten = applikationsDaten;}

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

PS:感谢蔡司的提示.

i'm facing a little problem and can't find a solution. The situation:

  • I have a Java-Webservice containing different Methods. One of these creates a new Object (named "Bestellung", which is german for "Order"). This object contains some attributes, most of them are Strings, one is a Hashmap named "applikationsDaten" (application data).
  • I'm receiving this object in php via SoapClient - all attributes are filled as i want them. print_r() shows the following (shortened to the relevant parts):

    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;

解决方案

i found the solution: the problem was in my java code. it's not enough to declare the hashmap in the object like this:

private HashMap applikationsDaten;

public HashMap getApplikationsDaten() {
    return applikationsDaten;
}

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

to make it work, i had to specify datatypes for the Hashmap like this:

private HashMap<String,String> applikationsDaten;

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

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

after changing this and redeploying the webservice it worked as expected. I'll leave this question and mark it as community wiki instead of deleting it - maybe it helps someone looking for the same failure.

PS: thanks to ZeissS for his hints.

这篇关于HashMap 通过 SOAP 从 Java 到 PHP 再返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆