diff options
author | liamfallon <liam.fallon@ericsson.com> | 2018-07-03 15:19:52 +0100 |
---|---|---|
committer | liamfallon <liam.fallon@ericsson.com> | 2018-07-03 15:30:54 +0100 |
commit | dd6627d723a23bada5721d5d7bd7121ebd0c3245 (patch) | |
tree | 38f51cef27d0d70d862ef95dff4dc17b179b3626 /plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms | |
parent | 436d824ea21f56cf5c055a2f41d940e1145dea35 (diff) |
Remove JMS dependencies with license problems
The JMS API dependency wa removed by checking for the methods
using refection rather than casting the objects.
The other JMS dependencies were not needed.
Issue-ID: POLICY-905
Change-Id: I9146ede67e97c0e0ccc8a9a8a20f98f1b9e5390d
Signed-off-by: liamfallon <liam.fallon@ericsson.com>
Diffstat (limited to 'plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms')
3 files changed, 39 insertions, 42 deletions
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/pom.xml b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/pom.xml index 98328951e..e2518031a 100644 --- a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/pom.xml +++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/pom.xml @@ -33,12 +33,4 @@ <properties> <apex-plugins-event-protocol-jms-dir>${project.basedir}/src</apex-plugins-event-protocol-jms-dir> </properties> - - <dependencies> - <dependency> - <groupId>javax.jms</groupId> - <artifactId>javax.jms-api</artifactId> - <version>2.0.1</version> - </dependency> - </dependencies> </project>
\ No newline at end of file diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JMSObjectEventConverter.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JMSObjectEventConverter.java index 52c678407..6c21070c2 100644 --- a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JMSObjectEventConverter.java +++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JMSObjectEventConverter.java @@ -20,11 +20,10 @@ package org.onap.policy.apex.plugins.event.protocol.jms; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; -import javax.jms.ObjectMessage; - import org.onap.policy.apex.service.engine.event.ApexEvent; import org.onap.policy.apex.service.engine.event.ApexEventException; import org.onap.policy.apex.service.engine.event.ApexEventProtocolConverter; @@ -35,7 +34,7 @@ import org.slf4j.ext.XLoggerFactory; /** * The Class Apex2JMSObjectEventConverter converts {@link ApexEvent} instances into string instances of - * {@link javax.jms.ObjectMessage} message events for JMS. + * object message events for JMS. * * @author Liam Fallon (liam.fallon@ericsson.com) */ @@ -48,9 +47,12 @@ public final class Apex2JMSObjectEventConverter implements ApexEventProtocolConv /** * Constructor to create the Apex to JMS Object converter. * - * @throws ApexEventException the apex event exception + * @throws ApexEventException + * the apex event exception */ - public Apex2JMSObjectEventConverter() throws ApexEventException {} + public Apex2JMSObjectEventConverter() throws ApexEventException { + // Nothing specific to initiate for this plugin + } @Override public void init(final EventProtocolParameters parameters) { @@ -59,8 +61,8 @@ public final class Apex2JMSObjectEventConverter implements ApexEventProtocolConv // on both sides of Apex if (!(parameters instanceof JMSObjectEventProtocolParameters)) { final String errormessage = "specified Event Protocol Parameters properties of type \"" - + parameters.getClass().getCanonicalName() + "\" are not applicable to a " - + Apex2JMSObjectEventConverter.class.getName() + " converter"; + + parameters.getClass().getCanonicalName() + "\" are not applicable to a " + + Apex2JMSObjectEventConverter.class.getName() + " converter"; LOGGER.error(errormessage); } else { this.eventProtocolParameters = (JMSObjectEventProtocolParameters) parameters; @@ -75,30 +77,31 @@ public final class Apex2JMSObjectEventConverter implements ApexEventProtocolConv */ @Override public List<ApexEvent> toApexEvent(final String eventName, final Object eventObject) throws ApexEventException { - // Check if this is an ObjectMessage from JMS - if (!(eventObject instanceof ObjectMessage)) { - final String errorMessage = "message \"" + eventObject + "\" received from JMS is not an instance of \"" - + ObjectMessage.class.getCanonicalName() + "\""; + // Look for a "getObject()" method on the incoming object, if there is no such method, then we cannot fetch the + // object from JMS + Method getObjectMethod; + try { + getObjectMethod = eventObject.getClass().getMethod("getObject", (Class<?>[]) null); + } catch (Exception e) { + final String errorMessage = "message \"" + eventObject + + "\" received from JMS does not have a \"getObject()\" method"; LOGGER.warn(errorMessage); throw new ApexEventRuntimeException(errorMessage); } - // Get the object from the object message - final ObjectMessage objectMessage = (ObjectMessage) eventObject; Object jmsIncomingObject; try { - jmsIncomingObject = objectMessage.getObject(); + jmsIncomingObject = getObjectMethod.invoke(eventObject, (Object[]) null); } catch (final Exception e) { final String errorMessage = "object contained in message \"" + eventObject - + "\" received from JMS could not be retrieved as a Java object"; + + "\" received from JMS could not be retrieved as a Java object"; LOGGER.debug(errorMessage, e); throw new ApexEventRuntimeException(errorMessage, e); } // Check that the consumer parameters for JMS->Apex messaging have been set if (eventProtocolParameters == null) { - final String errorMessage = - "consumer parameters for JMS events consumed by Apex are not set in the Apex configuration for this engine"; + final String errorMessage = "consumer parameters for JMS events consumed by Apex are not set in the Apex configuration for this engine"; LOGGER.debug(errorMessage); throw new ApexEventRuntimeException(errorMessage); } @@ -106,18 +109,18 @@ public final class Apex2JMSObjectEventConverter implements ApexEventProtocolConv // Create the Apex event // @formatter:off final ApexEvent apexEvent = new ApexEvent( - jmsIncomingObject.getClass().getSimpleName() + eventProtocolParameters.getIncomingEventSuffix(), - eventProtocolParameters.getIncomingEventVersion(), - jmsIncomingObject.toString().getClass().getPackage().getName(), - eventProtocolParameters.getIncomingEventSource(), - eventProtocolParameters.getIncomingEventTarget()); + jmsIncomingObject.getClass().getSimpleName() + eventProtocolParameters.getIncomingEventSuffix(), + eventProtocolParameters.getIncomingEventVersion(), + jmsIncomingObject.toString().getClass().getPackage().getName(), + eventProtocolParameters.getIncomingEventSource(), + eventProtocolParameters.getIncomingEventTarget()); // @formattter:on // Set the data on the apex event as the incoming object apexEvent.put(jmsIncomingObject.getClass().getSimpleName(), jmsIncomingObject); // Return the event in a single element - final ArrayList<ApexEvent> eventList = new ArrayList<ApexEvent>(); + final ArrayList<ApexEvent> eventList = new ArrayList<>(); eventList.add(apexEvent); return eventList; } diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JMSTextEventConverter.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JMSTextEventConverter.java index f48843125..e845a4a08 100644 --- a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JMSTextEventConverter.java +++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JMSTextEventConverter.java @@ -20,10 +20,9 @@ package org.onap.policy.apex.plugins.event.protocol.jms; +import java.lang.reflect.Method; import java.util.List; -import javax.jms.TextMessage; - import org.onap.policy.apex.service.engine.event.ApexEvent; import org.onap.policy.apex.service.engine.event.ApexEventException; import org.onap.policy.apex.service.engine.event.ApexEventRuntimeException; @@ -33,7 +32,7 @@ import org.slf4j.ext.XLoggerFactory; /** * The Class Apex2JMSTextEventConverter converts {@link ApexEvent} instances into string instances of - * {@link javax.jms.TextMessage} message events for JMS. It is a proxy for the built in + * text message events for JMS. It is a proxy for the built in * {@link org.onap.policy.apex.service.engine.event.impl.jsonprotocolplugin.Apex2JSONEventConverter} plugin. * * @author Liam Fallon (liam.fallon@ericsson.com) @@ -55,19 +54,22 @@ public final class Apex2JMSTextEventConverter extends Apex2JSONEventConverter { */ @Override public List<ApexEvent> toApexEvent(final String eventName, final Object eventObject) throws ApexEventException { - // Check if this is an TextMessage from JMS - if (!(eventObject instanceof TextMessage)) { - final String errorMessage = "message \"" + eventObject + "\" received from JMS is not an instance of \"" - + TextMessage.class.getCanonicalName() + "\""; - LOGGER.debug(errorMessage); + // Look for a "getText()" method on the incoming object, if there is no such method, then we cannot fetch the + // text from JMS + Method getTextMethod; + try { + getTextMethod = eventObject.getClass().getMethod("getText", (Class<?>[]) null); + } catch (Exception e) { + final String errorMessage = "message \"" + eventObject + + "\" received from JMS does not have a \"getText()\" method"; + LOGGER.warn(errorMessage); throw new ApexEventRuntimeException(errorMessage); } - // Get the string from the object message - final TextMessage textMessage = (TextMessage) eventObject; + String jmsString; try { - jmsString = textMessage.getText(); + jmsString = (String) getTextMethod.invoke(eventObject, (Object[]) null); } catch (final Exception e) { final String errorMessage = "object contained in message \"" + eventObject + "\" received from JMS could not be retrieved as a Java String"; |