开发者

HashMap via SOAP from Java to PHP and back

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 v开发者_如何学Goia 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.


You may also need to this bit of code:

class MapAdapter extends XmlAdapter<MapElements[], Map<String, String>> {
    public MapElements[] marshal(Map<String, String> arg0) throws Exception {
        MapElements[] mapElements = new MapElements[arg0.size()];
        int i = 0;
        for (Map.Entry<String, String> team : arg0.entrySet())
            mapElements[i++] = new MapElements(team.getKey(), team.getValue());

        return mapElements;
    }

    public Map<String, String> unmarshal(MapElements[] arg0) throws Exception {
        Map<String, String> r = new HashMap<String, String>();
        for (MapElements mapelement : arg0)
            r.put(mapelement.Kryptonim, mapelement.Status);
        return r;
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜