Skip to content

Commit 6c34023

Browse files
Merge pull request #627 from rabbitmq/rabbitmq-java-client-classes-for-update-secret-extension
Do not depend on generated classes for update-secret extension
2 parents d0e1a08 + e3c662e commit 6c34023

File tree

3 files changed

+111
-3
lines changed

3 files changed

+111
-3
lines changed

src/main/java/com/rabbitmq/client/impl/AMQConnection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ public void start()
442442
}
443443
String refreshedPassword = credentialsProvider.getPassword();
444444

445-
AMQImpl.Connection.UpdateSecret updateSecret = new AMQImpl.Connection.UpdateSecret(
445+
UpdateSecretExtension.UpdateSecret updateSecret = new UpdateSecretExtension.UpdateSecret(
446446
LongStringHelper.asLongString(refreshedPassword), "Refresh scheduled by client"
447447
);
448448
try {
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
// Copyright (c) 2019 Pivotal Software, Inc. All rights reserved.
2+
//
3+
// This software, the RabbitMQ Java client library, is triple-licensed under the
4+
// Mozilla Public License 1.1 ("MPL"), the GNU General Public License version 2
5+
// ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
6+
// LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL,
7+
// please see LICENSE-APACHE2.
8+
//
9+
// This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
10+
// either express or implied. See the LICENSE file for specific language governing
11+
// rights and limitations of this software.
12+
//
13+
// If you have any questions regarding licensing, please contact us at
14+
15+
16+
package com.rabbitmq.client.impl;
17+
18+
import com.rabbitmq.client.LongString;
19+
20+
import java.io.IOException;
21+
import java.util.Objects;
22+
23+
/**
24+
* Helper for <code>update-secret</code> extension {@link com.rabbitmq.client.Method}.
25+
* <p>
26+
* {@link com.rabbitmq.client.Method} classes are usually automatically
27+
* generated, but providing the class directly is necessary in this case
28+
* for some internal CI testing jobs running against RabbitMQ 3.7.
29+
*
30+
* @since 5.8.0
31+
*/
32+
abstract class UpdateSecretExtension {
33+
34+
static class UpdateSecret extends Method {
35+
36+
private final LongString newSecret;
37+
private final String reason;
38+
39+
public UpdateSecret(LongString newSecret, String reason) {
40+
if (newSecret == null)
41+
throw new IllegalStateException("Invalid configuration: 'newSecret' must be non-null.");
42+
if (reason == null)
43+
throw new IllegalStateException("Invalid configuration: 'reason' must be non-null.");
44+
this.newSecret = newSecret;
45+
this.reason = reason;
46+
}
47+
48+
public String getReason() {
49+
return reason;
50+
}
51+
52+
public int protocolClassId() {
53+
return 10;
54+
}
55+
56+
public int protocolMethodId() {
57+
return 70;
58+
}
59+
60+
public String protocolMethodName() {
61+
return "connection.update-secret";
62+
}
63+
64+
public boolean hasContent() {
65+
return false;
66+
}
67+
68+
public Object visit(AMQImpl.MethodVisitor visitor) throws IOException {
69+
return null;
70+
}
71+
72+
73+
@Override
74+
public boolean equals(Object o) {
75+
if (this == o)
76+
return true;
77+
if (o == null || getClass() != o.getClass())
78+
return false;
79+
UpdateSecret that = (UpdateSecret) o;
80+
if (!Objects.equals(newSecret, that.newSecret))
81+
return false;
82+
return Objects.equals(reason, that.reason);
83+
}
84+
85+
@Override
86+
public int hashCode() {
87+
int result = 0;
88+
result = 31 * result + (newSecret != null ? newSecret.hashCode() : 0);
89+
result = 31 * result + (reason != null ? reason.hashCode() : 0);
90+
return result;
91+
}
92+
93+
public void appendArgumentDebugStringTo(StringBuilder acc) {
94+
acc.append("(new-secret=")
95+
.append(this.newSecret)
96+
.append(", reason=")
97+
.append(this.reason)
98+
.append(")");
99+
}
100+
101+
public void writeArgumentsTo(MethodArgumentWriter writer)
102+
throws IOException {
103+
writer.writeLongstr(this.newSecret);
104+
writer.writeShortstr(this.reason);
105+
}
106+
}
107+
}
108+

src/test/java/com/rabbitmq/client/impl/AMQConnectionRefreshCredentialsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ public boolean processAsync(Command c) throws IOException {
6666

6767
@Override
6868
public AMQCommand rpc(Method m) throws IOException, ShutdownSignalException {
69-
if (m instanceof AMQImpl.Connection.UpdateSecret) {
69+
if (m instanceof UpdateSecretExtension.UpdateSecret) {
7070
super.rpc(m);
71-
return super.rpc(new AMQImpl.Connection.UpdateSecret(LongStringHelper.asLongString(""), "Refresh scheduled by client") {
71+
return super.rpc(new UpdateSecretExtension.UpdateSecret(LongStringHelper.asLongString(""), "Refresh scheduled by client") {
7272
@Override
7373
public int protocolMethodId() {
7474
return 255;

0 commit comments

Comments
 (0)