AMQ-7037 - allow sslContext attribute of networkConnector to be added via runtime config plugin jaxb processor

This commit is contained in:
gtully 2018-08-22 12:20:21 +01:00
parent 54b2e21f4a
commit b488df694c
5 changed files with 48 additions and 8 deletions

View File

@ -20,6 +20,7 @@ import org.apache.activemq.util.IntrospectionSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.PostConstruct;
import javax.xml.bind.JAXBElement;
import java.lang.reflect.Method;
import java.util.ArrayList;
@ -204,12 +205,28 @@ public class DefaultConfigurationProcessor implements ConfigurationProcessor {
try {
setter.invoke(instance, JAXBUtils.matchType(argument, setter.getParameterTypes()[0]));
} catch (Exception e) {
plugin.info("failed to invoke " + setter + " on " + instance, e);
plugin.info("failed to invoke " + setter + " on " + instance + " with args " + argument, e);
}
} else {
plugin.info("failed to find setter for " + elementName + " on :" + instance);
}
}
invokePostConstruct(instance);
return instance;
}
private <T> void invokePostConstruct(T instance) {
try {
for (Method m : instance.getClass().getDeclaredMethods()) {
if (m.isAnnotationPresent(PostConstruct.class) && m.getParameterCount() == 0) {
try {
JAXBUtils.ensureAccessible(m);
m.invoke(instance, null);
} catch (Exception e) {
plugin.info("failed to invoke @PostConstruct method " + m + " on " + instance, e);
}
}
}
} catch (Exception ignored) {}
}
}

View File

@ -16,22 +16,24 @@
*/
package org.apache.activemq.plugin;
import javax.xml.bind.JAXBElement;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import org.apache.activemq.broker.region.virtual.FilteredDestination;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.command.ActiveMQTopic;
import org.apache.activemq.schema.core.DtoFilteredDestination;
import org.apache.activemq.schema.core.DtoTopic;
import org.apache.activemq.schema.core.DtoQueue;
import org.apache.activemq.schema.core.DtoAuthenticationUser;
import org.apache.activemq.schema.core.DtoFilteredDestination;
import org.apache.activemq.schema.core.DtoQueue;
import org.apache.activemq.schema.core.DtoSslContext;
import org.apache.activemq.schema.core.DtoTopic;
import org.apache.activemq.security.AuthenticationUser;
import org.apache.activemq.spring.SpringSslContext;
public class JAXBUtils {
@ -45,6 +47,12 @@ public class JAXBUtils {
return null;
}
public static void ensureAccessible(Method m) {
if ((!Modifier.isPublic(m.getModifiers()) || !Modifier.isPublic(m.getDeclaringClass().getModifiers())) && !m.isAccessible()) {
m.setAccessible(true);
}
}
public static Object inferTargetObject(Object elementContent) {
if (DtoTopic.class.isAssignableFrom(elementContent.getClass())) {
return new ActiveMQTopic();
@ -53,7 +61,9 @@ public class JAXBUtils {
} else if (DtoAuthenticationUser.class.isAssignableFrom(elementContent.getClass())) {
return new AuthenticationUser();
} else if (DtoFilteredDestination.class.isAssignableFrom(elementContent.getClass())) {
return new FilteredDestination();
return new FilteredDestination();
} else if (DtoSslContext.class.isAssignableFrom(elementContent.getClass())) {
return new SpringSslContext();
} else {
return new Object();
}
@ -63,6 +73,8 @@ public class JAXBUtils {
Object result = parameterValues;
if (Set.class.isAssignableFrom(aClass)) {
result = new HashSet(parameterValues);
} else if (!Collection.class.isAssignableFrom(aClass)) {
result = parameterValues.get(0);
}
return result;
}

View File

@ -68,6 +68,10 @@
<jxb:property name="Contents" />
</jxb:bindings>
<jxb:bindings node="xs:element[@name='networkConnector']/xs:complexType/xs:choice/xs:choice/xs:element[@name='sslContext']/xs:complexType/xs:choice">
<jxb:property name="Contents" />
</jxb:bindings>
<jxb:bindings node="xs:element[@name='broker']/xs:complexType/xs:choice/xs:choice/xs:element[@name='destinationInterceptors']/xs:complexType/xs:choice">
<jxb:property name="Contents" />
</jxb:bindings>

View File

@ -89,6 +89,8 @@ public class NetworkConnectorTest extends RuntimeConfigTestSupport {
NetworkConnector modNetworkConnector = brokerService.getNetworkConnectors().get(0);
assertEquals("got ttl update", 2, modNetworkConnector.getNetworkTTL());
assertNotNull("got ssl", modNetworkConnector.getSslContext());
// apply again - ensure no change
applyNewConfig(brokerConfig, configurationSeed + "-mod-one-nc", SLEEP);
assertEquals("no new network connectors", 1, brokerService.getNetworkConnectors().size());

View File

@ -27,7 +27,12 @@
</plugins>
<networkConnectors>
<networkConnector uri="static:(tcp://localhost:5555)" networkTTL="2" name="one" />
<networkConnector uri="static:(tcp://localhost:5555)" networkTTL="2" name="one">
<sslContext>
<sslContext keyStorePassword="PPAA" trustStorePassword="PPBB" />
</sslContext>
</networkConnector>
</networkConnectors>
</broker>
</beans>