Skip to content

Do not depend on generated classes for update-secret extension #627

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/com/rabbitmq/client/impl/AMQConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ public void start()
}
String refreshedPassword = credentialsProvider.getPassword();

AMQImpl.Connection.UpdateSecret updateSecret = new AMQImpl.Connection.UpdateSecret(
UpdateSecretExtension.UpdateSecret updateSecret = new UpdateSecretExtension.UpdateSecret(
LongStringHelper.asLongString(refreshedPassword), "Refresh scheduled by client"
);
try {
Expand Down
108 changes: 108 additions & 0 deletions src/main/java/com/rabbitmq/client/impl/UpdateSecretExtension.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// Copyright (c) 2019 Pivotal Software, Inc. All rights reserved.
//
// This software, the RabbitMQ Java client library, is triple-licensed under the
// Mozilla Public License 1.1 ("MPL"), the GNU General Public License version 2
// ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
// LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL,
// please see LICENSE-APACHE2.
//
// This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
// either express or implied. See the LICENSE file for specific language governing
// rights and limitations of this software.
//
// If you have any questions regarding licensing, please contact us at
// [email protected].

package com.rabbitmq.client.impl;

import com.rabbitmq.client.LongString;

import java.io.IOException;
import java.util.Objects;

/**
* Helper for <code>update-secret</code> extension {@link com.rabbitmq.client.Method}.
* <p>
* {@link com.rabbitmq.client.Method} classes are usually automatically
* generated, but providing the class directly is necessary in this case
* for some internal CI testing jobs running against RabbitMQ 3.7.
*
* @since 5.8.0
*/
abstract class UpdateSecretExtension {

static class UpdateSecret extends Method {

private final LongString newSecret;
private final String reason;

public UpdateSecret(LongString newSecret, String reason) {
if (newSecret == null)
throw new IllegalStateException("Invalid configuration: 'newSecret' must be non-null.");
if (reason == null)
throw new IllegalStateException("Invalid configuration: 'reason' must be non-null.");
this.newSecret = newSecret;
this.reason = reason;
}

public String getReason() {
return reason;
}

public int protocolClassId() {
return 10;
}

public int protocolMethodId() {
return 70;
}

public String protocolMethodName() {
return "connection.update-secret";
}

public boolean hasContent() {
return false;
}

public Object visit(AMQImpl.MethodVisitor visitor) throws IOException {
return null;
}


@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
UpdateSecret that = (UpdateSecret) o;
if (!Objects.equals(newSecret, that.newSecret))
return false;
return Objects.equals(reason, that.reason);
}

@Override
public int hashCode() {
int result = 0;
result = 31 * result + (newSecret != null ? newSecret.hashCode() : 0);
result = 31 * result + (reason != null ? reason.hashCode() : 0);
return result;
}

public void appendArgumentDebugStringTo(StringBuilder acc) {
acc.append("(new-secret=")
.append(this.newSecret)
.append(", reason=")
.append(this.reason)
.append(")");
}

public void writeArgumentsTo(MethodArgumentWriter writer)
throws IOException {
writer.writeLongstr(this.newSecret);
writer.writeShortstr(this.reason);
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ public boolean processAsync(Command c) throws IOException {

@Override
public AMQCommand rpc(Method m) throws IOException, ShutdownSignalException {
if (m instanceof AMQImpl.Connection.UpdateSecret) {
if (m instanceof UpdateSecretExtension.UpdateSecret) {
super.rpc(m);
return super.rpc(new AMQImpl.Connection.UpdateSecret(LongStringHelper.asLongString(""), "Refresh scheduled by client") {
return super.rpc(new UpdateSecretExtension.UpdateSecret(LongStringHelper.asLongString(""), "Refresh scheduled by client") {
@Override
public int protocolMethodId() {
return 255;
Expand Down