Skip to content

Commit d956dde

Browse files
authored
create Subscription Rule with CorrelationFilter does not create respect properties (#22556)
1 parent 525606e commit d956dde

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

sdk/servicebus/azure-messaging-servicebus/src/main/java/com/azure/messaging/servicebus/implementation/ServiceBusManagementSerializer.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ public class ServiceBusManagementSerializer implements SerializerAdapter {
3131
Pattern.MULTILINE);
3232
private static final Pattern FILTER_ACTION_PATTERN = Pattern.compile("<(Filter|Action) type=",
3333
Pattern.MULTILINE);
34+
private static final Pattern FILTER_VALUE_PATTERN = Pattern.compile("<(Value)",
35+
Pattern.MULTILINE);
36+
private static final String RULE_VALUE_ATTRIBUTE_XML = "<$1 xmlns:d6p1=\"http://www.w3.org/2001/XMLSchema\" ns0:type=\"d6p1:string\"";
3437

3538
private final JacksonAdapter jacksonAdapter = new JacksonAdapter();
3639
private final ClientLogger logger = new ClientLogger(ServiceBusManagementSerializer.class);
@@ -56,14 +59,25 @@ public String serialize(Object object, SerializerEncoding encoding) throws IOExc
5659
}
5760

5861
final String namespace = namespaceMatcher.group("namespace");
59-
final String replaced = contents
62+
String replaced = contents
6063
.replaceAll(namespace + ":", "")
6164
.replace("xmlns:" + namespace + "=", "xmlns=");
6265

6366
if (!CreateRuleBody.class.equals(clazz)) {
6467
return replaced;
6568
}
6669

70+
// This hack is here because value of custom property within RuleFilter should have a namespace like xmlns:d6p1="http://www.w3.org/2001/XMLSchema" ns0:type="d6p1:string".
71+
if (CreateRuleBody.class.equals(clazz)) {
72+
final Matcher filterValue = FILTER_VALUE_PATTERN.matcher(replaced);
73+
if (filterValue.find()) {
74+
replaced = filterValue.replaceAll(RULE_VALUE_ATTRIBUTE_XML);
75+
} else {
76+
logger.warning("Could not find filter name pattern '{}' in {}.", FILTER_VALUE_PATTERN.pattern(),
77+
contents);
78+
}
79+
}
80+
6781
// This hack is here because RuleFilter and RuleAction type="Foo" should have a namespace like n0:type="Foo".
6882
final Matcher filterType = FILTER_ACTION_PATTERN.matcher(replaced);
6983
if (filterType.find()) {

sdk/servicebus/azure-messaging-servicebus/src/main/java/com/azure/messaging/servicebus/implementation/models/CorrelationFilterImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ public final class CorrelationFilterImpl extends RuleFilterImpl {
8585
private String contentType;
8686

8787
private static final class PropertiesWrapper {
88-
@JacksonXmlProperty(localName = "KeyValueOfstringanyType")
88+
@JacksonXmlProperty(localName = "KeyValueOfstringanyType", namespace = "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect")
8989
private final List<KeyValueImpl> items;
9090

9191
@JsonCreator
92-
private PropertiesWrapper(@JacksonXmlProperty(localName = "KeyValueOfstringanyType") List<KeyValueImpl> items) {
92+
private PropertiesWrapper(@JacksonXmlProperty(localName = "KeyValueOfstringanyType", namespace = "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect") List<KeyValueImpl> items) {
9393
this.items = items;
9494
}
9595
}

sdk/servicebus/azure-messaging-servicebus/src/main/java/com/azure/messaging/servicebus/implementation/models/SqlFilterImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ public class SqlFilterImpl extends RuleFilterImpl {
4646
private String compatibilityLevel;
4747

4848
private static final class ParametersWrapper {
49-
@JacksonXmlProperty(localName = "KeyValueOfstringanyType")
49+
@JacksonXmlProperty(localName = "KeyValueOfstringanyType", namespace = "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect")
5050
private final List<KeyValueImpl> items;
5151

5252
@JsonCreator
53-
private ParametersWrapper(@JacksonXmlProperty(localName = "KeyValueOfstringanyType") List<KeyValueImpl> items) {
53+
private ParametersWrapper(@JacksonXmlProperty(localName = "KeyValueOfstringanyType", namespace = "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect") List<KeyValueImpl> items) {
5454
this.items = items;
5555
}
5656
}

sdk/servicebus/azure-messaging-servicebus/src/main/java/com/azure/messaging/servicebus/implementation/models/SqlRuleActionImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ public final class SqlRuleActionImpl extends RuleActionImpl {
3737
private String compatibilityLevel;
3838

3939
private static final class ParametersWrapper {
40-
@JacksonXmlProperty(localName = "KeyValueOfstringanyType")
40+
@JacksonXmlProperty(localName = "KeyValueOfstringanyType", namespace = "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect")
4141
private final List<KeyValueImpl> items;
4242

4343
@JsonCreator
44-
private ParametersWrapper(@JacksonXmlProperty(localName = "KeyValueOfstringanyType") List<KeyValueImpl> items) {
44+
private ParametersWrapper(@JacksonXmlProperty(localName = "KeyValueOfstringanyType", namespace = "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect") List<KeyValueImpl> items) {
4545
this.items = items;
4646
}
4747
}

0 commit comments

Comments
 (0)