AWS源代码出错?

时间:2016-12-23 21:12:13

标签: java spring amazon-web-services amazon-sqs

在我们的代码中,我们从sqs队列中删除一条消息并获取deletResponse

String deleteResponse = sqsClient.deleteMessage(simBridge2ESBUrl, message.getReceiptHandle()).toString();

此通话后系统会删除该消息,但deleteResponse始终为{}。所以我们检查了源代码,发现DeleteMessageResult::toString函数只返回{}

以下是AWS源代码。 toString()hashCode()函数似乎很奇怪。源代码中是否有错误或者我做错了?谢谢。

/*
 * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights
 * Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License").
 * You may not use this file except in compliance with the License.
 * A copy of the License is located at
 *
 *  http://aws.amazon.com/apache2.0
 *
 * or in the "license" file accompanying this file. This file is distributed
 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */

package com.amazonaws.services.sqs.model;

import java.io.Serializable;

/**
 * 
 */
public class DeleteMessageResult implements Serializable, Cloneable {

    /**
     * Returns a string representation of this object; useful for testing and
     * debugging.
     *
     * @return A string representation of this object.
     *
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("{");
        sb.append("}");
        return sb.toString();
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;

        if (obj instanceof DeleteMessageResult == false)
            return false;
        DeleteMessageResult other = (DeleteMessageResult) obj;
        return true;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int hashCode = 1;

        return hashCode;
    }

    @Override
    public DeleteMessageResult clone() {
        try {
            return (DeleteMessageResult) super.clone();
        } catch (CloneNotSupportedException e) {
            throw new IllegalStateException(
                    "Got a CloneNotSupportedException from Object.clone() "
                            + "even though we're Cloneable!", e);
        }
    }
}

1 个答案:

答案 0 :(得分:1)

从编程角度toString()写得正确。想想这个功能的作用:

  

此对象的字符串表示。

由于DeleteMessageResult类没有属性,因此无需返回任何内容。同样适用于hashCode()DeleteMessageResult的两个对象始终相同,因此每次都有相同的哈希值。

话虽如此,我确实认为DeleteMessageResult应包含ResposeMetadata RequestId API reference中显示的唯一<DeleteMessageResponse> <ResponseMetadata> <RequestId> b5293cb5-d306-4a17-9048-b263635abe42 </RequestId> </ResponseMetadata> </DeleteMessageResponse>

x^2

所以,是的,这个类可能(可能应该)修补完全支持SQS API。