Skip to content

Commit

Permalink
create Subscription Rule with CorrelationFilter does not create respe…
Browse files Browse the repository at this point in the history
…ct properties (#22556)
  • Loading branch information
v-hongli1 authored Jul 1, 2021
1 parent 525606e commit d956dde
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public class ServiceBusManagementSerializer implements SerializerAdapter {
Pattern.MULTILINE);
private static final Pattern FILTER_ACTION_PATTERN = Pattern.compile("<(Filter|Action) type=",
Pattern.MULTILINE);
private static final Pattern FILTER_VALUE_PATTERN = Pattern.compile("<(Value)",
Pattern.MULTILINE);
private static final String RULE_VALUE_ATTRIBUTE_XML = "<$1 xmlns:d6p1=\"http://www.w3.org/2001/XMLSchema\" ns0:type=\"d6p1:string\"";

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

final String namespace = namespaceMatcher.group("namespace");
final String replaced = contents
String replaced = contents
.replaceAll(namespace + ":", "")
.replace("xmlns:" + namespace + "=", "xmlns=");

if (!CreateRuleBody.class.equals(clazz)) {
return replaced;
}

// 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".
if (CreateRuleBody.class.equals(clazz)) {
final Matcher filterValue = FILTER_VALUE_PATTERN.matcher(replaced);
if (filterValue.find()) {
replaced = filterValue.replaceAll(RULE_VALUE_ATTRIBUTE_XML);
} else {
logger.warning("Could not find filter name pattern '{}' in {}.", FILTER_VALUE_PATTERN.pattern(),
contents);
}
}

// This hack is here because RuleFilter and RuleAction type="Foo" should have a namespace like n0:type="Foo".
final Matcher filterType = FILTER_ACTION_PATTERN.matcher(replaced);
if (filterType.find()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ public final class CorrelationFilterImpl extends RuleFilterImpl {
private String contentType;

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

@JsonCreator
private PropertiesWrapper(@JacksonXmlProperty(localName = "KeyValueOfstringanyType") List<KeyValueImpl> items) {
private PropertiesWrapper(@JacksonXmlProperty(localName = "KeyValueOfstringanyType", namespace = "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect") List<KeyValueImpl> items) {
this.items = items;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ public class SqlFilterImpl extends RuleFilterImpl {
private String compatibilityLevel;

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

@JsonCreator
private ParametersWrapper(@JacksonXmlProperty(localName = "KeyValueOfstringanyType") List<KeyValueImpl> items) {
private ParametersWrapper(@JacksonXmlProperty(localName = "KeyValueOfstringanyType", namespace = "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect") List<KeyValueImpl> items) {
this.items = items;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ public final class SqlRuleActionImpl extends RuleActionImpl {
private String compatibilityLevel;

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

@JsonCreator
private ParametersWrapper(@JacksonXmlProperty(localName = "KeyValueOfstringanyType") List<KeyValueImpl> items) {
private ParametersWrapper(@JacksonXmlProperty(localName = "KeyValueOfstringanyType", namespace = "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect") List<KeyValueImpl> items) {
this.items = items;
}
}
Expand Down

0 comments on commit d956dde

Please sign in to comment.