0

私はJava Webサービスを持っています

その中で、応答を呼び出すオブジェクトを返したい

同じ親タイプのオブジェクトがいくつかあります

public class ParentType{
         public ParentType();
}

public class Childtype1 extends ParentType{

}

public class Childtype2 extends ParentType{

}

public class Response{

ParentType data;
}

私の問題は、childtype1のオブジェクトを返すと、すべてがうまくいくことです

しかし、childtype2 のオブジェクトを返そうとすると、データ オブジェクトは空に戻ります

私はこれにAxisを使用しています。

childtype1 と childtype2 の両方がデータを返すようにする方法は?

編集

これは実際のコードです:

public class ServerObject{
public ServerObject(){
}
//this is really an empty class, nothing written here besides this
}

public User extends ServerObject(){
private int userID = 0;
private String firstName = "N/A";
private String lastName = "N/A";
private String login;
private String password = "N/A";
private int authLevel = 0;
private String address = "N/A";
private String phone = "N/A";
private String email = "N/A";

public User(){
super();
}
public int getUserID() {
return userID;
}

public void setUserID(int userID) {
this.userID = userID;
}

public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

public String getLogin() {
return login;
}

public void setLogin(String login) {
this.login = login;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

public int getAuthLevel() {
return authLevel;
}

public void setAuthLevel(int authLevel) {
this.authLevel = authLevel;
}

public String getAddress() {
return address;
}

public void setAddress(String address) {
this.address = address;
}

public String getPhone() {
return phone;
}

public void setPhone(String phone) {
this.phone = phone;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

@Override
public String toString() {
return "User [userID=" + userID + ", firstName=" + firstName + ", lastName=" + lastName + ", login=" + login + ", password=" + password + ", authLevel=" + authLevel + ", address=" + address
+ ", phone=" + phone + ", email=" + email + "]";
}



}

public class UserLoginInformation extends ServerObject{
private int userID = 0;
private long lastSeen=System.currentTimeMillis();
private boolean loggedIn = false;
private String login="N/A";

public int getUserID() {
return userID;
}

public boolean isLoggedIn() {
return loggedIn;
}

public void setLoggedIn(boolean loggedIn) {
this.loggedIn = loggedIn;
this.lastSeen = System.currentTimeMillis();
}

public void setLogin(String login) {
this.login = login;
}
public String getLastSeen() {
return lastSeen+"";
}

public String getLogin() {
return login;
}

public void setUserID(int userID) {
this.userID = userID;
}

public void setLastSeen(long lastSeen) {
this.lastSeen = lastSeen;
}

@Override
public String toString() {
return "UserLoginInformation [userID=" + userID + ", lastSeen=" + lastSeen + ", loggedIn=" + loggedIn + ", login=" + login + "]";
}

}

public class ServerResponse{

ServerObject data;
int status;
String message;

public ServerResponse(){
//also empty constructor, does nothing
}
public ServerObject getData(){
Log.info(data);
return data;
}
public int getStatus(){
return status;
}

public String getMessage(){
return message;
}

public void setData(ServerObject data){
this.data = data;
}
public void setStatus(int status){
this.status = status;
}

public void setMessage(String message){
this.message = message;
}

@Override
public String toString{
return "ServerResponse [data="+data+" status = " +status + " message= "+message]";
}
}

================ 自動生成された wsdl

<wsdl:message name="testUserRequest">

    <wsdl:part element="impl:testUser" name="parameters">

    </wsdl:part>

</wsdl:message>

<wsdl:message name="testUserLoginInformationRequest">

    <wsdl:part element="impl:testUserLoginInformation" name="parameters">

    </wsdl:part>

</wsdl:message>

<wsdl:message name="testUserResponse">

    <wsdl:part element="impl:testUserResponse" name="parameters">

    </wsdl:part>

</wsdl:message>


<wsdl:message name="testUserLoginInformationResponse">

    <wsdl:part element="impl:testUserLoginInformationResponse" name="parameters">

    </wsdl:part>

</wsdl:message>


<wsdl:message name="testOrderRequest">

    <wsdl:part element="impl:testOrder" name="parameters">

    </wsdl:part>

</wsdl:message>

<wsdl:message name="testOrderResponse">

    <wsdl:part element="impl:testOrderResponse" name="parameters">

    </wsdl:part>

</wsdl:message>

<wsdl:portType name="ElectronicArenaWebService">

    <wsdl:operation name="testUserLoginInformation">

        <wsdl:input message="impl:testUserLoginInformationRequest" name="testUserLoginInformationRequest">

        </wsdl:input>

        <wsdl:output message="impl:testUserLoginInformationResponse" name="testUserLoginInformationResponse">

        </wsdl:output>

    </wsdl:operation>

    <wsdl:operation name="testOrder">

        <wsdl:input message="impl:testOrderRequest" name="testOrderRequest">

        </wsdl:input>

        <wsdl:output message="impl:testOrderResponse" name="testOrderResponse">

        </wsdl:output>

    </wsdl:operation>

    <wsdl:operation name="testUser">

        <wsdl:input message="impl:testUserRequest" name="testUserRequest">

        </wsdl:input>

        <wsdl:output message="impl:testUserResponse" name="testUserResponse">

        </wsdl:output>

    </wsdl:operation>

</wsdl:portType>

<wsdl:binding name="ElectronicArenaWebServiceSoapBinding" type="impl:ElectronicArenaWebService">

    <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>

    <wsdl:operation name="testUserLoginInformation">

        <wsdlsoap:operation soapAction=""/>

        <wsdl:input name="testUserLoginInformationRequest">

            <wsdlsoap:body use="literal"/>

        </wsdl:input>

        <wsdl:output name="testUserLoginInformationResponse">

            <wsdlsoap:body use="literal"/>

        </wsdl:output>

    </wsdl:operation>

    <wsdl:operation name="testOrder">

        <wsdlsoap:operation soapAction=""/>

        <wsdl:input name="testOrderRequest">

            <wsdlsoap:body use="literal"/>

        </wsdl:input>

        <wsdl:output name="testOrderResponse">

            <wsdlsoap:body use="literal"/>

        </wsdl:output>

    </wsdl:operation>

    <wsdl:operation name="testUser">

        <wsdlsoap:operation soapAction=""/>

        <wsdl:input name="testUserRequest">

            <wsdlsoap:body use="literal"/>

        </wsdl:input>

        <wsdl:output name="testUserResponse">

            <wsdlsoap:body use="literal"/>

        </wsdl:output>

    </wsdl:operation>

</wsdl:binding>

<wsdl:service name="ElectronicArenaWebServiceService">

    <wsdl:port binding="impl:ElectronicArenaWebServiceSoapBinding" name="ElectronicArenaWebService">

        <wsdlsoap:address location="http://localhost:9080/ElectronicArenaLenasProject/services/ElectronicArenaWebService"/>

    </wsdl:port>

</wsdl:service>

==================== メソッド呼び出し testUser の応答 - 新しいユーザーを作成して返すだけです

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
     <soapenv:Body>
        <testUserResponse xmlns="http://webservice.lenabru.com">
             <testUserReturn>
                <BUILD>3.6.2</BUILD> 
                 <data xmlns:ns1="http://database.com" xsi:type="ns1:User">
                    <address>N/A</address> 
                    <authLevel>0</authLevel> 
                    <email>N/A</email> 
                    <firstName>N/A</firstName> 
                    <lastName>N/A</lastName> 
                    <login xsi:nil="true" /> 
                    <password>N/A</password> 
                    <phone>N/A</phone> 
                    <userID>0</userID> 
                </data>
                <status>0</status> 
                <message /> 
            </testUserReturn>
        </testUserResponse>
    </soapenv:Body>
</soapenv:Envelope>

メソッド呼び出し testUserLoginInformation の応答 - 新しい userLoginInformation を作成して返すだけです

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Body>
        <testUserLoginInformationResponse xmlns="http://webservice.lenabru.com">
            <testUserLoginInformationReturn>
                <BUILD>3.6.2</BUILD> 
                **<data />**  //<======= Problem is here, data is empty
                <status>0</status> 
                <message /> 
            </testUserLoginInformationReturn>
        </testUserLoginInformationResponse>
    </soapenv:Body>
</soapenv:Envelope>

ご覧のとおり、何らかの理由で - データが空に戻ってきた - 理由を知りたい

これは、Web サービスの内部操作のログ出力です。これは、データが空であってはならないことを明確に示しています。

Sep 03, 2013 10:25:02 AM com.electronicarena.utils.Log debug
INFO: [ServerResponse.java line 28 in method: setData]:setting Data: UserLoginInformation [userID=0, lastSeen=1378193102508, loggedIn=false, login=N/A]

Sep 03, 2013 10:25:02 AM com.electronicarena.utils.Log debug
INFO: [ElectronicArenaWebService.java line 64 in method: testUserLoginInformation]:outgoing response: ServerResponse [data=UserLoginInformation [userID=0, lastSeen=1378193102508, loggedIn=false, login=N/A], statusCode=0, statusMsg=, BUILD=3.6.2]

Sep 03, 2013 10:25:02 AM com.electronicarena.utils.Log debug
INFO: [ServerResponse.java line 23 in method: getData]:UserLoginInformation [userID=0, lastSeen=1378193102508, loggedIn=false, login=N/A]

Sep 03, 2013 10:25:45 AM com.electronicarena.utils.Log debug
INFO: [ServerResponse.java line 28 in method: setData]:setting Data: User [userID=0, firstName=N/A, lastName=N/A, login=null, password=N/A, authLevel=0, address=N/A, phone=N/A, email=N/A]

Sep 03, 2013 10:25:45 AM com.electronicarena.utils.Log debug
INFO: [ElectronicArenaWebService.java line 57 in method: testUser]:outgoing response: ServerResponse [data=User [userID=0, firstName=N/A, lastName=N/A, login=null, password=N/A, authLevel=0, address=N/A, phone=N/A, email=N/A], statusCode=0, statusMsg=, BUILD=3.6.2]

Sep 03, 2013 10:25:45 AM com.electronicarena.utils.Log debug
INFO: [ServerResponse.java line 23 in method: getData]:User [userID=0, firstName=N/A, lastName=N/A, login=null, password=N/A, authLevel=0, address=N/A, phone=N/A, email=N/A]
4

1 に答える 1

0

答えはここにあります: http://www.ibm.com/developerworks/websphere/techjournal/0401_brown/brown.html

簡単な解決策は、いくつかの方法を作成します

public ChildType1 childType1(){
return new ChildType1();
}

public ChildType1 childType2(){
    return new ChildType2();
    }

そして、すべてが正常に動作します

于 2013-09-07T12:18:01.193 に答える