Skip to content

Commit

Permalink
Merge pull request #79 from OpenWiseSolutions/feature/R2.0-merge
Browse files Browse the repository at this point in the history
Merge bugfixes from R2.0
  • Loading branch information
hanusto committed Mar 4, 2018
2 parents 4885465 + 282e57a commit 32592f6
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 18 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Welcome to OpenHub Framework
[![Build Status](https://travis-ci.org/OpenWiseSolutions/openhub-framework.svg?branch=develop)](https://travis-ci.org/OpenWiseSolutions/openhub-framework) [![Coverage Status](https://coveralls.io/repos/github/OpenWiseSolutions/openhub-framework/badge.svg?branch=develop)](https://coveralls.io/github/OpenWiseSolutions/openhub-framework?branch=develop) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.openhubframework/openhub/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.openhubframework/openhub)

## Apache Camel, but improved
## Apache Camel for enterprise

* open source
* power of Apache Camel community
Expand All @@ -18,6 +18,8 @@ We believe OpenHub framework is useful and effective integration framework, see

[Apache License 2.0]

> Apache Camel is open source project of The Apache Software Foundation.
### Getting Started
To help you get started, try the following links:

Expand Down
2 changes: 1 addition & 1 deletion admin-console/src/services/api.service.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import CreateApi from './CreateApi'

const apiService = new CreateApi({
base: '/web/admin',
base: '../',
headers: {
Accept: 'application/json',
'content-type': 'application/json'
Expand Down
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,6 @@ private static String getBaseUrl(final HttpServletRequest request) {
throw new RuntimeException("Not valid request.requestURL for parsing:", e);
}
final String port = requestURL.getPort() == -1 ? "" : ":" + requestURL.getPort();
return requestURL.getProtocol() + "://" + requestURL.getHost() + port;
return requestURL.getProtocol() + "://" + requestURL.getHost() + port + request.getContextPath();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import java.util.Map;
import javax.servlet.DispatcherType;
import javax.servlet.FilterRegistration;
import javax.servlet.ServletContext;

import net.bull.javamelody.MonitoringFilter;
import net.bull.javamelody.SessionListener;
Expand Down Expand Up @@ -59,6 +61,9 @@ public class WebConfigurer {

private static final Logger LOG = LoggerFactory.getLogger(WebConfigurer.class);

// java melody filter name
private static final String JAVAMELODY_FILTER_NAME = "javamelody";

@Autowired
private JavaMelodyConfigurationProperties javaMelodyProps;

Expand All @@ -69,14 +74,14 @@ public class WebConfigurer {
* Creates {@link MonitoringFilter} filter.
*/
@Bean
public FilterRegistrationBean monitoringJavaMelody() {
public FilterRegistrationBean monitoringJavaMelody(ServletContext servletContext) {
LOG.info("JavaMelody initialization: " + javaMelodyProps.getInitParameters());

final MonitoringFilter filter = new MonitoringFilter();
filter.setApplicationType("OpenHub");
FilterRegistrationBean registration = new FilterRegistrationBean(filter);
registration.setAsyncSupported(true);
registration.setName("javamelody");
registration.setName(JAVAMELODY_FILTER_NAME);
registration.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.ASYNC);
registration.setEnabled(javaMelodyProps.isEnabled());

Expand All @@ -87,6 +92,19 @@ public FilterRegistrationBean monitoringJavaMelody() {

// Set the URL patterns to activate the monitoring filter for.
registration.addUrlPatterns("/*");

// Check if javaMelody filter is already registered by container, if so, just configure it.
final FilterRegistration filterRegistration = servletContext.getFilterRegistration(JAVAMELODY_FILTER_NAME);
if (filterRegistration != null) {
LOG.info("JavaMelody filter already registered by container, just configure it:");
// disable this bean
registration.setEnabled(false);
// pass init parameters
for (final Map.Entry<String, String> entry : registration.getInitParameters().entrySet()) {
filterRegistration.setInitParameter(entry.getKey(), entry.getValue());
}
}

return registration;
}

Expand Down
3 changes: 2 additions & 1 deletion web/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ management.security.roles=${management.security.role}
javamelody.enabled = true
# Initialization parameters for JavaMelody (optional)
# to change the default "/monitoring" path
# Note: if you change it, you will probably want to update admin console external link config property accordingly.
javamelody.init-parameters.monitoring-path = /web/admin/monitoring/javamelody


Expand Down Expand Up @@ -397,7 +398,7 @@ ohf.admin.console.config.menu.configuration.environment.enabled = ${endpoints.en
ohf.admin.console.config.menu.configuration.error-code-catalog.enabled = true
ohf.admin.console.config.menu.external-links.enabled = true
ohf.admin.console.config.menu.external-links.items[0].title = Javamelody Monitoring
ohf.admin.console.config.menu.external-links.items[0].link = ${javamelody.init-parameters.monitoring-path}
ohf.admin.console.config.menu.external-links.items[0].link = ../monitoring/javamelody
ohf.admin.console.config.menu.external-links.items[0].enabled = ${javamelody.enabled}
ohf.admin.console.config.menu.changes.enabled = true

Expand Down

0 comments on commit 32592f6

Please sign in to comment.