Ankit
Ankit

Reputation: 2753

Passing Hashmap as parameter in EJB3 WebService

I have exposed an api of EJB3 bean as a WebService and it takes HashMap of java as a parameter but while getting value in WebService Bean from hashMap I am getting null value.

@EJB(mappedName = "ODBillGenerationSession",name = "ODBillGenerationSession")
IODBillGenerationSessionRemoteHome iodBillGenerationSessionRemoteHome = null;
IODBillGenerationSessionRemote iodBillGenerationSessionRemote = null; 
public String echo(@WebParam(name="hashMap") HashMap hashMap) {
    return "Hello "+hashMap.get("name");
}

My request XML which I am executing from SOAP UI is below:-

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:int="http://interfaces.billingengine.ws.billingengine.elitecore.com/"> <soapenv:Header/>    <soapenv:Body>
      <int:echo>
         <!--Optional:-->
         <arg0>Test</arg0>
      </int:echo>    </soapenv:Body> </soapenv:Envelope>

And the same web service is working fine when I am passing java String object.

I think I am missing some annotation here which I searched but not found.

<definitions name="ODBillGenerationWsSessionFacadeService" targetNamespace="http://session.billingengine.ws.billingengine.elitecore.com/">
<import location="http://10.105.1.6:8180/odbillgeneration-ws/ODBillGenerationWsSessionFacade?wsdl&resource=IODBillGenerationWsSessionRemote_PortType6834015600007002099.wsdl" namespace="http://interfaces.billingengine.ws.billingengine.elitecore.com/"/>
    <service name="ODBillGenerationWsSessionFacadeService">
        <port binding="ns1:IODBillGenerationWsSessionRemoteBinding" name="ODBillGenerationWsSessionFacadePort">
            <soap:address location="http://10.105.1.6:8180/odbillgeneration-ws/ODBillGenerationWsSessionFacade"/>
        </port>
    </service>

Correct WSDL

<definitions name="ODBillGenerationWsSessionFacadeService" targetNamespace="http://interfaces.billingengine.ws.billingengine.elitecore.com/">
    <types>
        <xs:schema targetNamespace="http://interfaces.billingengine.ws.billingengine.elitecore.com/" version="1.0">
            <xs:element name="echo" type="tns:echo"/>
            <xs:element name="echoResponse" type="tns:echoResponse"/>
            <xs:complexType name="echo">
                <xs:sequence>
                    <xs:element minOccurs="0" name="arg0" type="tns:hashMap"/>
                </xs:sequence>
            </xs:complexType>
            <xs:complexType name="hashMap">
                <xs:complexContent>
                    <xs:extension base="tns:abstractMap">
                        <xs:sequence/>
                    </xs:extension>
                </xs:complexContent>
            </xs:complexType>
            <xs:complexType abstract="true" name="abstractMap">
                <xs:sequence/>
            </xs:complexType>
            <xs:complexType name="echoResponse">
                <xs:sequence>
                    <xs:element minOccurs="0" name="return" type="xs:string"/>
                </xs:sequence>
            </xs:complexType>
        </xs:schema>
    </types>
    <message name="IODBillGenerationWsSessionRemote_echoResponse">
        <part element="ns1:echoResponse" name="echoResponse"/>
    </message>
    <message name="IODBillGenerationWsSessionRemote_echo">
        <part element="ns1:echo" name="echo"/>
    </message>
    <portType name="IODBillGenerationWsSessionRemote">
        <operation name="echo" parameterOrder="echo">
            <input message="ns1:IODBillGenerationWsSessionRemote_echo"/>
            <output message="ns1:IODBillGenerationWsSessionRemote_echoResponse"/>
        </operation>
    </portType>
    <binding name="IODBillGenerationWsSessionRemoteBinding" type="ns1:IODBillGenerationWsSessionRemote">
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
        <operation name="echo">
            <soap:operation soapAction=""/>
            <input>
                <soap:body use="literal"/>
            </input>
            <output>
                <soap:body use="literal"/>
            </output>
        </operation>
    </binding>
</definitions>

Upvotes: 0

Views: 2155

Answers (1)

Miljen Mikic
Miljen Mikic

Reputation: 15251

You're not sending key-value pair, so your Web method cannot read required key "name". Replace your SOAP body with this one:

<soapenv:Body>
      <int:echo>
         <hashMap>
            <!--Zero or more repetitions:-->
            <arg0>
               <key>name</key>
               <value>someValue</value>
            </arg0>
         </hashMap>
      </int:echo>
   </soapenv:Body>

Also, change the type of input parameter from HashMap to HashMap<String,String>. That should do the trick.

Upvotes: 1

Related Questions