Skip to content

Commit 601adf4

Browse files
committed
Providing capability to override default strategy in OSGi environment.
1 parent e90adcc commit 601adf4

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

errormap/decorator/src/main/java/org/microbule/errormap/decorator/ErrorMapperProxyDecorator.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,27 @@
3232
@Singleton
3333
@Named("errorMapperProxyDecorator")
3434
public class ErrorMapperProxyDecorator implements JaxrsProxyDecorator {
35-
//----------------------------------------------------------------------------------------------------------------------
35+
//----------------------------------------------------------------------------------------------------------------------
3636
// Fields
3737
//----------------------------------------------------------------------------------------------------------------------
38+
3839
private static final Logger LOGGER = LoggerFactory.getLogger(ErrorMapperProxyDecorator.class);
3940
private static final String STRATEGY = "strategy";
4041
private final ErrorMapperService errorMapperService;
42+
private final String defaultStrategy;
4143

4244
//----------------------------------------------------------------------------------------------------------------------
4345
// Constructors
4446
//----------------------------------------------------------------------------------------------------------------------
4547

4648
@Inject
4749
public ErrorMapperProxyDecorator(ErrorMapperService errorMapperService) {
50+
this(errorMapperService, ErrorMapperUtils.DEFAULT_STRATEGY);
51+
}
52+
53+
public ErrorMapperProxyDecorator(ErrorMapperService errorMapperService, String defaultStrategy) {
4854
this.errorMapperService = errorMapperService;
55+
this.defaultStrategy = defaultStrategy;
4956
}
5057

5158
//----------------------------------------------------------------------------------------------------------------------
@@ -54,7 +61,7 @@ public ErrorMapperProxyDecorator(ErrorMapperService errorMapperService) {
5461

5562
@Override
5663
public void decorate(JaxrsServiceDescriptor descriptor, Config config) {
57-
final String strategy = config.value(STRATEGY).orElse(ErrorMapperUtils.DEFAULT_STRATEGY);
64+
final String strategy = config.value(STRATEGY).orElse(defaultStrategy);
5865
LOGGER.debug("Using \"{}\" error response strategy for {} JAX-RS proxy.", strategy, descriptor.serviceInterface().getSimpleName());
5966
descriptor.addProvider(new ErrorMapperResponseExceptionMapper(errorMapperService, strategy));
6067
}

errormap/decorator/src/main/java/org/microbule/errormap/decorator/ErrorMapperServerDecorator.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,20 @@ public class ErrorMapperServerDecorator implements JaxrsServerDecorator {
4040
private static final String STRATEGY = "strategy";
4141

4242
private final ErrorMapperService errorMapperService;
43+
private final String defaultStrategy;
4344

4445
//----------------------------------------------------------------------------------------------------------------------
4546
// Constructors
4647
//----------------------------------------------------------------------------------------------------------------------
4748

4849
@Inject
4950
public ErrorMapperServerDecorator(ErrorMapperService errorMapperService) {
51+
this(errorMapperService, ErrorMapperUtils.DEFAULT_STRATEGY);
52+
}
53+
54+
public ErrorMapperServerDecorator(ErrorMapperService errorMapperService, String defaultStrategy) {
5055
this.errorMapperService = errorMapperService;
56+
this.defaultStrategy = defaultStrategy;
5157
}
5258

5359
//----------------------------------------------------------------------------------------------------------------------
@@ -56,7 +62,7 @@ public ErrorMapperServerDecorator(ErrorMapperService errorMapperService) {
5662

5763
@Override
5864
public void decorate(JaxrsServiceDescriptor descriptor, Config config) {
59-
final String strategy = config.value(STRATEGY).orElse(ErrorMapperUtils.DEFAULT_STRATEGY);
65+
final String strategy = config.value(STRATEGY).orElse(defaultStrategy);
6066
LOGGER.debug("Using \"{}\" error response strategy for {} JAX-RS server.", strategy, descriptor.serviceInterface().getSimpleName());
6167
descriptor.addProvider(new WebApplicationExceptionMapper(errorMapperService, strategy));
6268
descriptor.addProvider(new RootExceptionMapper(errorMapperService, strategy));

errormap/decorator/src/main/resources/OSGI-INF/blueprint/microbule-errormap-decorator.xml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,27 @@
1717
~
1818
-->
1919

20-
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
20+
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
21+
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0">
22+
23+
<cm:property-placeholder persistent-id="org.microbule.errormap.decorator" update-strategy="reload">
24+
<cm:default-properties>
25+
<cm:property name="defaultStrategy" value="text"/>
26+
</cm:default-properties>
27+
</cm:property-placeholder>
2128

2229
<reference id="errorMapperService" interface="org.microbule.errormap.api.ErrorMapperService"/>
2330

2431
<bean id="serverDecorator" class="org.microbule.errormap.decorator.ErrorMapperServerDecorator">
2532
<argument ref="errorMapperService"/>
33+
<argument value="${defaultStrategy}" />
2634
</bean>
2735

2836
<service ref="serverDecorator" interface="org.microbule.spi.JaxrsServerDecorator"/>
2937

3038
<bean id="proxyDecorator" class="org.microbule.errormap.decorator.ErrorMapperProxyDecorator">
3139
<argument ref="errorMapperService"/>
40+
<argument value="${defaultStrategy}" />
3241
</bean>
3342

3443
<service ref="proxyDecorator" interface="org.microbule.spi.JaxrsProxyDecorator"/>

0 commit comments

Comments
 (0)