Skip to content

Commit

Permalink
NOJIRA : RequestSending & ResponseReceive EventNotifiers - endpoint p…
Browse files Browse the repository at this point in the history
…attern switch to String
  • Loading branch information
kkovarik committed Feb 28, 2018
1 parent 16403df commit ba42319
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 12 deletions.
Expand Up @@ -28,6 +28,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import org.springframework.util.Assert;

import org.openhubframework.openhub.api.asynch.AsynchConstants;
Expand All @@ -37,6 +39,7 @@
import org.openhubframework.openhub.api.entity.Request;
import org.openhubframework.openhub.api.event.EventNotifier;
import org.openhubframework.openhub.api.event.EventNotifierBase;
import org.springframework.util.StringUtils;


/**
Expand Down Expand Up @@ -67,21 +70,34 @@ public class RequestSendingEventNotifier extends EventNotifierBase<ExchangeSendi
* Pattern for filtering endpoints URI which requests/response should be saved.
*/
@ConfigurableValue(key = REQUEST_SAVING_ENDPOINT_FILTER)
private ConfigurationItem<Pattern> endpointFilterPattern;
private ConfigurationItem<String> endpointFilter;

private Pattern endpointFilterPattern;

/**
* After all the db properties are set, set pattern for endpointFilter.
*/
@EventListener
public void onApplicationEvent(ApplicationReadyEvent event) {
if (StringUtils.hasText(endpointFilter.getValue(null))) {
endpointFilterPattern = Pattern.compile(endpointFilter.getValue());
LOG.debug("Initialized RequestSendingEventNotifier: enabled [{}], filterPattern [{}].", enable, endpointFilterPattern);
}
}

@Autowired
private RequestResponseService requestResponseService;

@Override
public boolean isEnabled(EventObject event) {
return super.isEnabled(event) && enable.getValue();
return super.isEnabled(event) && enable.getValue() && endpointFilterPattern != null;
}

@Override
protected void doNotify(ExchangeSendingEvent event) throws Exception {
String endpointUri = event.getEndpoint().getEndpointUri();

if (filter(endpointUri, endpointFilterPattern.getValue())) {
if (filter(endpointUri, endpointFilterPattern)) {
Message msg = event.getExchange().getIn().getHeader(AsynchConstants.MSG_HEADER, Message.class);

// create request
Expand Down
Expand Up @@ -36,6 +36,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import org.springframework.util.Assert;
import org.springframework.ws.soap.client.SoapFaultClientException;

Expand Down Expand Up @@ -72,21 +74,34 @@ public class ResponseReceiveEventNotifier extends EventNotifierBase<ExchangeSent
* Pattern for filtering endpoints URI which requests/response should be saved.
*/
@ConfigurableValue(key = REQUEST_SAVING_ENDPOINT_FILTER)
private ConfigurationItem<Pattern> endpointFilterPattern;
private ConfigurationItem<String> endpointFilter;

private Pattern endpointFilterPattern;

/**
* After all the db properties are set, set pattern for endpointFilter.
*/
@EventListener
public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {
if (StringUtils.isNotEmpty(endpointFilter.getValue(null))) {
endpointFilterPattern = Pattern.compile(endpointFilter.getValue());
LOG.debug("Initialized ResponseReceiveEventNotifier: enabled [{}], filterPattern [{}].", enable, endpointFilterPattern);
}
}

@Autowired
private RequestResponseService requestResponseService;

@Override
public boolean isEnabled(EventObject event) {
return super.isEnabled(event) && enable.getValue();
return super.isEnabled(event) && enable.getValue() && endpointFilterPattern != null;
}

@Override
protected void doNotify(ExchangeSentEvent event) throws Exception {
String endpointUri = event.getEndpoint().getEndpointUri();

if (RequestSendingEventNotifier.filter(endpointUri, endpointFilterPattern.getValue())) {
if (RequestSendingEventNotifier.filter(endpointUri, endpointFilterPattern)) {
// get response
String resStr;
String failedReason = null;
Expand Down
Expand Up @@ -90,11 +90,11 @@ public class RequestResponseTest extends AbstractCoreDbTest {
public void prepareConfiguration() {
setPrivateField(reqSendingEventNotifier, "enable", new FixedConfigurationItem<>(Boolean.TRUE));
setPrivateField(reqSendingEventNotifier, "endpointFilterPattern",
new FixedConfigurationItem<>(java.util.regex.Pattern.compile("^(direct.*target).*$")));
java.util.regex.Pattern.compile("^(direct.*target).*$"));

setPrivateField(resReceiveEventNotifier, "enable", new FixedConfigurationItem<>(Boolean.TRUE));
setPrivateField(resReceiveEventNotifier, "endpointFilterPattern",
new FixedConfigurationItem<>(java.util.regex.Pattern.compile("^(direct.*target).*$")));
java.util.regex.Pattern.compile("^(direct.*target).*$"));
}

@Before
Expand Down Expand Up @@ -128,10 +128,8 @@ public void testSavingRequest() throws Exception {


// try it again but change pattern for filtering
setPrivateField(reqSendingEventNotifier, "endpointFilterPattern",
new FixedConfigurationItem<>(java.util.regex.Pattern.compile("^(noUrl).*$")));
setPrivateField(resReceiveEventNotifier, "endpointFilterPattern",
new FixedConfigurationItem<>(java.util.regex.Pattern.compile("^(noUrl).*$")));
setPrivateField(reqSendingEventNotifier, "endpointFilterPattern", java.util.regex.Pattern.compile("^(noUrl).*$"));
setPrivateField(resReceiveEventNotifier, "endpointFilterPattern", java.util.regex.Pattern.compile("^(noUrl).*$"));

producer.sendBody(REQUEST);

Expand Down

0 comments on commit ba42319

Please sign in to comment.