簡體   English   中英

將Hashmap作為參數傳遞給EJB3 WebService

[英]Passing Hashmap as parameter in EJB3 WebService

我已經將EJB3 bean的api公開為WebService,它以java的HashMap作為參數,但是從hashMap獲取WebService Bean中的值時,我得到的是空值。

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

我從SOAP UI執行的請求XML如下:

<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>

當我傳遞java String對象時,相同的Web服務運行正常。

我想我在這里找不到但未找到的注釋。

<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>

正確的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>

您沒有發送鍵值對,因此您的Web方法無法讀取所需的鍵“名稱”。 用以下代碼替換您的SOAP主體:

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

另外,將輸入參數的類型從HashMap更改為HashMap<String,String> 這應該夠了吧。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM