From b3f8d4ea3e65128ce6d58486f3169204eb6bde8a Mon Sep 17 00:00:00 2001 From: objectiser Date: Tue, 30 Sep 2014 11:09:12 +0100 Subject: [PATCH] RTGOV-586 Locate ServicesProvider implementations in UI using the commons ServiceRegistry --- docs/javadoc/pom.xml | 14 +- .../rtgov/client/ActivityReporter.java | 2 +- .../rtgov/client/ActivityValidator.java | 2 +- .../rtgov/client/DefaultActivityReporter.java | 2 +- .../client/DefaultActivityValidator.java | 2 +- .../impl/ServicesProviderServiceImpl.java | 13 +- .../ui/provider/AbstractServicesProvider.java | 76 +++++++ .../rtgov/ui/provider/ActionProvider.java | 33 +++ .../ui/provider/ResubmitActionProvider.java | 61 ++++++ .../rtgov/ui/provider/ServicesProvider.java | 33 +-- .../SwitchYardResubmitActionProvider.java | 195 ++++++++++++++++++ .../SwitchYardServicesProvider.java | 160 +------------- ...verlord.rtgov.ui.provider.ServicesProvider | 1 + .../provider/switchyard/messages.properties | 3 +- .../situations/RTGovSituationsProvider.java | 41 ++-- .../provider/situations/messages.properties | 1 + 16 files changed, 436 insertions(+), 203 deletions(-) create mode 100644 ui/rtgov-ui-core/src/main/java/org/overlord/rtgov/ui/provider/AbstractServicesProvider.java create mode 100644 ui/rtgov-ui-core/src/main/java/org/overlord/rtgov/ui/provider/ActionProvider.java create mode 100644 ui/rtgov-ui-core/src/main/java/org/overlord/rtgov/ui/provider/ResubmitActionProvider.java create mode 100644 ui/rtgov-ui-services-switchyard/src/main/java/org/overlord/rtgov/ui/provider/switchyard/SwitchYardResubmitActionProvider.java create mode 100644 ui/rtgov-ui-services-switchyard/src/main/resources/META-INF/services/org.overlord.rtgov.ui.provider.ServicesProvider diff --git a/docs/javadoc/pom.xml b/docs/javadoc/pom.xml index 76def520..5dbe42d3 100644 --- a/docs/javadoc/pom.xml +++ b/docs/javadoc/pom.xml @@ -108,9 +108,13 @@ org.overlord.rtgov.call.trace:org.overlord.rtgov.call.trace.descriptors:org.overlord.rtgov.call.trace.model:org.overlord.rtgov.call.trace.util:org.overlord.rtgov.reports:org.overlord.rtgov.reports.model:org.overlord.rtgov.reports.util:org.overlord.rtgov.service.dependency:org.overlord.rtgov.service.dependency.layout:org.overlord.rtgov.service.dependency.presentation:org.overlord.rtgov.service.dependency.svg:org.overlord.rtgov.situation.manager - Integration Support + Runtime Integration org.overlord.rtgov.client* + + UI Integration + org.overlord.rtgov.ui.* + @@ -133,6 +137,14 @@ + + + + + + + + diff --git a/integration/client/src/main/java/org/overlord/rtgov/client/ActivityReporter.java b/integration/client/src/main/java/org/overlord/rtgov/client/ActivityReporter.java index cee9a511..eeb1c049 100644 --- a/integration/client/src/main/java/org/overlord/rtgov/client/ActivityReporter.java +++ b/integration/client/src/main/java/org/overlord/rtgov/client/ActivityReporter.java @@ -19,7 +19,7 @@ /** * This interface represents the capability for recording - * activity information from a JEE application. + * activity information from an application. * */ public interface ActivityReporter { diff --git a/integration/client/src/main/java/org/overlord/rtgov/client/ActivityValidator.java b/integration/client/src/main/java/org/overlord/rtgov/client/ActivityValidator.java index 0b93497f..3e11e2ee 100644 --- a/integration/client/src/main/java/org/overlord/rtgov/client/ActivityValidator.java +++ b/integration/client/src/main/java/org/overlord/rtgov/client/ActivityValidator.java @@ -19,7 +19,7 @@ /** * This interface represents the capability for validating - * activity information from a JEE application. + * activity information from an application. * */ public interface ActivityValidator { diff --git a/integration/client/src/main/java/org/overlord/rtgov/client/DefaultActivityReporter.java b/integration/client/src/main/java/org/overlord/rtgov/client/DefaultActivityReporter.java index 75382eb7..bea07c3a 100644 --- a/integration/client/src/main/java/org/overlord/rtgov/client/DefaultActivityReporter.java +++ b/integration/client/src/main/java/org/overlord/rtgov/client/DefaultActivityReporter.java @@ -27,7 +27,7 @@ /** * This interface represents the capability for recording - * activity information from a JEE application. + * activity information from an application. * */ public class DefaultActivityReporter implements ActivityReporter { diff --git a/integration/client/src/main/java/org/overlord/rtgov/client/DefaultActivityValidator.java b/integration/client/src/main/java/org/overlord/rtgov/client/DefaultActivityValidator.java index 1587cd5d..354649ba 100644 --- a/integration/client/src/main/java/org/overlord/rtgov/client/DefaultActivityValidator.java +++ b/integration/client/src/main/java/org/overlord/rtgov/client/DefaultActivityValidator.java @@ -25,7 +25,7 @@ /** * This interface represents the capability for validating - * activity information from a JEE application. + * activity information from an application. * */ public class DefaultActivityValidator implements ActivityValidator { diff --git a/ui/overlord-rtgov-ui-base/src/main/java/org/overlord/rtgov/ui/server/services/impl/ServicesProviderServiceImpl.java b/ui/overlord-rtgov-ui-base/src/main/java/org/overlord/rtgov/ui/server/services/impl/ServicesProviderServiceImpl.java index 80c49545..5ef6a173 100644 --- a/ui/overlord-rtgov-ui-base/src/main/java/org/overlord/rtgov/ui/server/services/impl/ServicesProviderServiceImpl.java +++ b/ui/overlord-rtgov-ui-base/src/main/java/org/overlord/rtgov/ui/server/services/impl/ServicesProviderServiceImpl.java @@ -21,9 +21,8 @@ import javax.enterprise.context.ApplicationScoped; import javax.enterprise.inject.Alternative; -import javax.enterprise.inject.Instance; -import javax.inject.Inject; +import org.overlord.commons.services.ServiceRegistryUtil; import org.overlord.rtgov.ui.client.model.Constants; import org.overlord.rtgov.ui.client.model.QName; import org.overlord.rtgov.ui.client.model.ReferenceBean; @@ -46,9 +45,15 @@ public class ServicesProviderServiceImpl implements IServicesServiceImpl { private static final int SERVICES_PER_PAGE=10; - @Inject - private Instance _providers; + private java.util.Set _providers; + /** + * The default constructor. + */ + public ServicesProviderServiceImpl() { + _providers = ServiceRegistryUtil.getServices(ServicesProvider.class); + } + /** * @see org.overlord.rtgov.ui.server.services.IServicesServiceImpl#getApplicationNames() */ diff --git a/ui/rtgov-ui-core/src/main/java/org/overlord/rtgov/ui/provider/AbstractServicesProvider.java b/ui/rtgov-ui-core/src/main/java/org/overlord/rtgov/ui/provider/AbstractServicesProvider.java new file mode 100644 index 00000000..f976dc1e --- /dev/null +++ b/ui/rtgov-ui-core/src/main/java/org/overlord/rtgov/ui/provider/AbstractServicesProvider.java @@ -0,0 +1,76 @@ +/* + * Copyright 2013-4 Red Hat Inc + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.overlord.rtgov.ui.provider; + +import java.util.List; + +import org.overlord.rtgov.ui.client.model.QName; +import org.overlord.rtgov.ui.client.model.ReferenceBean; +import org.overlord.rtgov.ui.client.model.UiException; + +/** + * This class provides an abstract base implementation of the ServicesProvider + * interface. + * + */ +public abstract class AbstractServicesProvider implements ServicesProvider { + + private java.util.Map, ActionProvider> _actionProviders= + new java.util.HashMap,ActionProvider>(); + + /** + * This method registers an action. + * + * @param type The action type + * @param action The action + */ + protected void registerAction(Class type, ActionProvider action) { + _actionProviders.put(type, action); + } + + /** + * This method unregisters an action. + * + * @param type The action type + * @return The action + */ + protected ActionProvider unregisterAction(Class type) { + return (_actionProviders.remove(type)); + } + + /** + * {@inheritDoc} + */ + public List getApplicationNames() throws UiException { + return (java.util.Collections.emptyList()); + } + + /** + * {@inheritDoc} + */ + public ReferenceBean getReference(String uuid) throws UiException { + return (null); + } + + /** + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + public T getAction(Class actionType) { + return ((T)_actionProviders.get(actionType)); + } + +} diff --git a/ui/rtgov-ui-core/src/main/java/org/overlord/rtgov/ui/provider/ActionProvider.java b/ui/rtgov-ui-core/src/main/java/org/overlord/rtgov/ui/provider/ActionProvider.java new file mode 100644 index 00000000..fd199abb --- /dev/null +++ b/ui/rtgov-ui-core/src/main/java/org/overlord/rtgov/ui/provider/ActionProvider.java @@ -0,0 +1,33 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2008-13, Red Hat Middleware LLC, and others contributors as indicated + * by the @authors tag. All rights reserved. + * See the copyright.txt in the distribution for a + * full listing of individual contributors. + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU Lesser General Public License, v. 2.1. + * This program is distributed in the hope that it will be useful, but WITHOUT A + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License, + * v.2.1 along with this distribution; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ +package org.overlord.rtgov.ui.provider; + +/** + * This class represents an action that can be performed. + * + */ +public abstract class ActionProvider { + + /** + * This method returns the name of the action. + * + * @return The action name + */ + public abstract String getName(); + +} diff --git a/ui/rtgov-ui-core/src/main/java/org/overlord/rtgov/ui/provider/ResubmitActionProvider.java b/ui/rtgov-ui-core/src/main/java/org/overlord/rtgov/ui/provider/ResubmitActionProvider.java new file mode 100644 index 00000000..36dd773f --- /dev/null +++ b/ui/rtgov-ui-core/src/main/java/org/overlord/rtgov/ui/provider/ResubmitActionProvider.java @@ -0,0 +1,61 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2008-13, Red Hat Middleware LLC, and others contributors as indicated + * by the @authors tag. All rights reserved. + * See the copyright.txt in the distribution for a + * full listing of individual contributors. + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU Lesser General Public License, v. 2.1. + * This program is distributed in the hope that it will be useful, but WITHOUT A + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License, + * v.2.1 along with this distribution; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ +package org.overlord.rtgov.ui.provider; + +import org.overlord.rtgov.ui.client.model.MessageBean; +import org.overlord.rtgov.ui.client.model.UiException; + +/** + * This interface represents the action provider for the Resubmit task. + * + */ +public abstract class ResubmitActionProvider extends ActionProvider { + + private static final String RESUBMIT = "Resubmit"; + + /** + * {@inheritDoc} + */ + public String getName() { + return RESUBMIT; + } + + /** + * This method determines whether this provider support's a resubmit of the + * supplied service operation. + * + * @param service The service + * @param operation The operation + * @return Whether this provider support's a resubmit for the given service + * and operation + * @throws UiException Failed to test if service operation can be resubmitted + */ + public abstract boolean isResubmitSupported(String service, String operation) throws UiException; + + /** + * This method resubmits the supplied message to the target service + * and operation. + * + * @param service The service + * @param operation The operation + * @param message The message + * @throws UiException Failed to resubmit the message + */ + public abstract void resubmit(String service, String operation, MessageBean message) throws UiException; + +} diff --git a/ui/rtgov-ui-core/src/main/java/org/overlord/rtgov/ui/provider/ServicesProvider.java b/ui/rtgov-ui-core/src/main/java/org/overlord/rtgov/ui/provider/ServicesProvider.java index 4647a57b..9fc790bd 100644 --- a/ui/rtgov-ui-core/src/main/java/org/overlord/rtgov/ui/provider/ServicesProvider.java +++ b/ui/rtgov-ui-core/src/main/java/org/overlord/rtgov/ui/provider/ServicesProvider.java @@ -17,7 +17,6 @@ import java.util.List; -import org.overlord.rtgov.ui.client.model.MessageBean; import org.overlord.rtgov.ui.client.model.QName; import org.overlord.rtgov.ui.client.model.ReferenceBean; import org.overlord.rtgov.ui.client.model.ServiceBean; @@ -48,29 +47,6 @@ public interface ServicesProvider { */ public boolean isServiceKnown(String service); - /** - * This method determines whether this provider support's a resubmit of the - * supplied service operation. - * - * @param service The service - * @param operation The operation - * @return Whether this provider support's a resubmit for the given service - * and operation - * @throws UiException Failed to test if service operation can be resubmitted - */ - public boolean isResubmitSupported(String service, String operation) throws UiException; - - /** - * This method resubmits the supplied message to the target service - * and operation. - * - * @param service The service - * @param operation The operation - * @param message The message - * @throws UiException Failed to resubmit the message - */ - public void resubmit(String service, String operation, MessageBean message) throws UiException; - /** * This method returns the list of application names. * @@ -106,4 +82,13 @@ public interface ServicesProvider { */ public ReferenceBean getReference(String uuid) throws UiException; + /** + * This method retrieves the action provider for the supplied + * type. If no action provider exists, then a null will be returned. + * + * @param actionType The action type + * @return The action provider, or null if not supported + */ + public T getAction(Class actionType); + } diff --git a/ui/rtgov-ui-services-switchyard/src/main/java/org/overlord/rtgov/ui/provider/switchyard/SwitchYardResubmitActionProvider.java b/ui/rtgov-ui-services-switchyard/src/main/java/org/overlord/rtgov/ui/provider/switchyard/SwitchYardResubmitActionProvider.java new file mode 100644 index 00000000..3098bfc1 --- /dev/null +++ b/ui/rtgov-ui-services-switchyard/src/main/java/org/overlord/rtgov/ui/provider/switchyard/SwitchYardResubmitActionProvider.java @@ -0,0 +1,195 @@ +/* + * Copyright 2013-4 Red Hat Inc + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.overlord.rtgov.ui.provider.switchyard; + +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.management.InstanceNotFoundException; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.dom.DOMSource; + +import org.overlord.rtgov.ui.client.model.BindingBean; +import org.overlord.rtgov.ui.client.model.MessageBean; +import org.overlord.rtgov.ui.client.model.UiException; +import org.overlord.rtgov.ui.provider.ResubmitActionProvider; +import org.switchyard.Property; +import org.switchyard.Scope; +import org.switchyard.remote.RemoteInvoker; +import org.switchyard.remote.RemoteMessage; +import org.switchyard.remote.http.HttpInvoker; +import org.switchyard.remote.http.HttpInvokerLabel; + +/** + * This class provides a SwitchYard implementation of the ServicesProvider + * interface obtaining its information via JMX. + * + */ +public class SwitchYardResubmitActionProvider extends ResubmitActionProvider { + + private static final String DOM_FORMAT = "dom"; + + private static final Logger LOG=Logger.getLogger(SwitchYardResubmitActionProvider.class.getName()); + + private SwitchYardServicesProvider _servicesProvider; + + private static volatile Messages i18n = new Messages(); + + /** + * The constructor. + */ + public SwitchYardResubmitActionProvider(SwitchYardServicesProvider provider) { + _servicesProvider = provider; + } + + /** + * {@inheritDoc} + */ + public boolean isResubmitSupported(String service, String operation) throws UiException { + try { + Map serviceBindings = _servicesProvider.getServiceBindings(service); + for (String btype : serviceBindings.keySet()) { + if (btype.equalsIgnoreCase(SwitchYardServicesProvider.BINDING_TYPE_SCA)) { + return (true); + } + } + return (false); + } catch (InstanceNotFoundException infe) { + return (false); + } catch (Exception e) { + throw new UiException(i18n.format("SwitchYardResubmitActionProvider.IsResubmitSupported", service, operation), e); + } + } + + /** + * {@inheritDoc} + */ + public void resubmit(String service, String operation, MessageBean message) throws UiException { + + // Currently assumes message is xml + org.w3c.dom.Document doc=null; + + try { + DocumentBuilder builder=DocumentBuilderFactory.newInstance().newDocumentBuilder(); + + java.io.InputStream is=new java.io.ByteArrayInputStream(message.getContent().getBytes()); + + doc = builder.parse(is); + + is.close(); + } catch (Exception e) { + throw new UiException(e); + } + + Object content=new DOMSource(doc.getDocumentElement()); + + java.util.List urls=_servicesProvider.getURLList(); + Exception exc=null; + + for (int i=0; i < urls.size(); i++) { + try { + // Create a new remote client invoker + RemoteInvoker invoker = new HttpInvoker(urls.get(i)); + + // Create the request message + RemoteMessage rm = new RemoteMessage(); + rm.setService(javax.xml.namespace.QName.valueOf(service)).setOperation(operation).setContent(content); + + // Check if header properties need to be initialized + if (message.getHeaders().size() > 0) { + for (String headerName : message.getHeaders().keySet()) { + String value=message.getHeaders().get(headerName); + String format=message.getHeaderFormats().get(headerName); + + configureHeader(rm, headerName, value, format); + } + } + + // Invoke the service + RemoteMessage reply = invoker.invoke(rm); + if (reply.isFault()) { + if (reply.getContent() instanceof Exception) { + throw new UiException((Exception)reply.getContent()); + } + throw new UiException("Fault response received: "+reply.getContent()); + } + + // Clear previous exceptions + exc = null; + + continue; + } catch (NullPointerException npe) { + if (LOG.isLoggable(Level.FINE)) { + LOG.fine("Remote invocation of switchyard service["+service+"] operation[" + +operation+"] failed to deserialize response"); + } + } catch (java.io.IOException e) { + exc = e; + } + } + + if (exc != null) { + // Report exception + throw new UiException(exc); + } + } + + /** + * This method configures the supplied header property, in the appropriate format, on the + * supplied remote message. + * + * @param rm The remote message + * @param headerName The header name + * @param value The value + * @param format The required format (text, dom, etc.) + * @throws UiException Failed to configure header property + */ + protected void configureHeader(RemoteMessage rm, String headerName, String value, String format) + throws UiException{ + Object propValue=value; + + if (format != null && format.equals(DOM_FORMAT)) { + + try { + // Convert to DOM + javax.xml.parsers.DocumentBuilderFactory factory= + javax.xml.parsers.DocumentBuilderFactory.newInstance(); + + factory.setNamespaceAware(true); + + javax.xml.parsers.DocumentBuilder builder= + factory.newDocumentBuilder(); + + java.io.InputStream is= + new java.io.ByteArrayInputStream(value.getBytes()); + + org.w3c.dom.Document doc=builder.parse(is); + + is.close(); + + propValue = doc.getDocumentElement(); + } catch (Exception e) { + throw new UiException("Failed to configure header '"+headerName+"'", e); + } + } + + Property prop=rm.getContext().setProperty(headerName, propValue, Scope.MESSAGE); + prop.addLabels(HttpInvokerLabel.HEADER.label()); + } + +} diff --git a/ui/rtgov-ui-services-switchyard/src/main/java/org/overlord/rtgov/ui/provider/switchyard/SwitchYardServicesProvider.java b/ui/rtgov-ui-services-switchyard/src/main/java/org/overlord/rtgov/ui/provider/switchyard/SwitchYardServicesProvider.java index 48cfb35b..268fc665 100644 --- a/ui/rtgov-ui-services-switchyard/src/main/java/org/overlord/rtgov/ui/provider/switchyard/SwitchYardServicesProvider.java +++ b/ui/rtgov-ui-services-switchyard/src/main/java/org/overlord/rtgov/ui/provider/switchyard/SwitchYardServicesProvider.java @@ -32,16 +32,12 @@ import java.util.logging.Logger; import javax.management.AttributeList; -import javax.management.InstanceNotFoundException; import javax.management.MBeanServerConnection; import javax.management.ObjectInstance; import javax.management.ObjectName; import javax.management.remote.JMXConnector; import javax.management.remote.JMXConnectorFactory; import javax.management.remote.JMXServiceURL; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.transform.dom.DOMSource; import org.overlord.rtgov.active.collection.ActiveCollection; import org.overlord.rtgov.active.collection.ActiveCollectionManager; @@ -55,7 +51,6 @@ import org.overlord.rtgov.service.dependency.layout.ServiceGraphLayoutImpl; import org.overlord.rtgov.service.dependency.svg.SVGServiceGraphGenerator; import org.overlord.rtgov.ui.client.model.BindingBean; -import org.overlord.rtgov.ui.client.model.MessageBean; import org.overlord.rtgov.ui.client.model.QName; import org.overlord.rtgov.ui.client.model.ReferenceBean; import org.overlord.rtgov.ui.client.model.ReferenceSummaryBean; @@ -63,13 +58,8 @@ import org.overlord.rtgov.ui.client.model.ServiceSummaryBean; import org.overlord.rtgov.ui.client.model.ServicesFilterBean; import org.overlord.rtgov.ui.client.model.UiException; -import org.overlord.rtgov.ui.provider.ServicesProvider; -import org.switchyard.Property; -import org.switchyard.Scope; -import org.switchyard.remote.RemoteInvoker; -import org.switchyard.remote.RemoteMessage; -import org.switchyard.remote.http.HttpInvoker; -import org.switchyard.remote.http.HttpInvokerLabel; +import org.overlord.rtgov.ui.provider.AbstractServicesProvider; +import org.overlord.rtgov.ui.provider.ResubmitActionProvider; import com.google.common.base.Optional; import com.google.common.collect.Lists; @@ -81,9 +71,9 @@ * interface obtaining its information via JMX. * */ -public class SwitchYardServicesProvider implements ServicesProvider { +public class SwitchYardServicesProvider extends AbstractServicesProvider { - private static final String BINDING_TYPE_SCA = "sca"; + protected static final String BINDING_TYPE_SCA = "sca"; private static final Logger LOG=Logger.getLogger(SwitchYardServicesProvider.class.getName()); @@ -110,6 +100,7 @@ public class SwitchYardServicesProvider implements ServicesProvider { private static final char ESCAPE_CHAR = '\\'; private static final char SEPARATOR_CHAR = ':'; + /** * The constructor. */ @@ -119,6 +110,8 @@ public SwitchYardServicesProvider() { _jmxUrl = RTGovProperties.getProperties().getProperty(SWITCHYARD_JMX_URL); _jmxUsername = RTGovProperties.getProperties().getProperty(SWITCHYARD_JMX_USERNAME); _jmxPassword = RTGovProperties.getProperties().getProperty(SWITCHYARD_JMX_PASSWORD); + + registerAction(ResubmitActionProvider.class, new SwitchYardResubmitActionProvider(this)); } /** @@ -142,32 +135,15 @@ public boolean isServiceKnown(String service) { return (true); } - @Override - public boolean isResubmitSupported(String service, String operation) throws UiException { - try { - Map serviceBindings = getServiceBindings(service); - for (String btype : serviceBindings.keySet()) { - if (btype.equalsIgnoreCase(BINDING_TYPE_SCA)) { - return (true); - } - } - return (false); - } catch (InstanceNotFoundException infe) { - return (false); - } catch (Exception e) { - throw new UiException(i18n.format("SwitchYardServicesProvider.IsResubmitSupported", service, operation), e); - } - } - - private Map getReferenceBindings(String service) throws Exception { + protected Map getReferenceBindings(String service) throws Exception { return getBindings("Reference", service); } - private Map getServiceBindings(String service) throws Exception { + protected Map getServiceBindings(String service) throws Exception { return getBindings("Service", service); } - private Map getBindings(String type, String service) throws Exception { + protected Map getBindings(String type, String service) throws Exception { Map result = Maps.newHashMapWithExpectedSize(2); MBeanServerConnection mBeanServerConnection = getMBeanServerConnection(); AttributeList attributeList = mBeanServerConnection.getAttributes(new ObjectName("org.switchyard.admin:type=" @@ -305,122 +281,6 @@ public String getJMXPassword() { return (_jmxPassword); } - /** - * {@inheritDoc} - */ - public void resubmit(String service, String operation, MessageBean message) throws UiException { - - // Currently assumes message is xml - org.w3c.dom.Document doc=null; - - try { - DocumentBuilder builder=DocumentBuilderFactory.newInstance().newDocumentBuilder(); - - java.io.InputStream is=new java.io.ByteArrayInputStream(message.getContent().getBytes()); - - doc = builder.parse(is); - - is.close(); - } catch (Exception e) { - throw new UiException(e); - } - - Object content=new DOMSource(doc.getDocumentElement()); - - java.util.List urls=getURLList(); - Exception exc=null; - - for (int i=0; i < urls.size(); i++) { - try { - // Create a new remote client invoker - RemoteInvoker invoker = new HttpInvoker(urls.get(i)); - - // Create the request message - RemoteMessage rm = new RemoteMessage(); - rm.setService(javax.xml.namespace.QName.valueOf(service)).setOperation(operation).setContent(content); - - // Check if header properties need to be initialized - if (message.getHeaders().size() > 0) { - for (String headerName : message.getHeaders().keySet()) { - String value=message.getHeaders().get(headerName); - String format=message.getHeaderFormats().get(headerName); - - configureHeader(rm, headerName, value, format); - } - } - - // Invoke the service - RemoteMessage reply = invoker.invoke(rm); - if (reply.isFault()) { - if (reply.getContent() instanceof Exception) { - throw new UiException((Exception)reply.getContent()); - } - throw new UiException("Fault response received: "+reply.getContent()); - } - - // Clear previous exceptions - exc = null; - - continue; - } catch (NullPointerException npe) { - if (LOG.isLoggable(Level.FINE)) { - LOG.fine("Remote invocation of switchyard service["+service+"] operation[" - +operation+"] failed to deserialize response"); - } - } catch (java.io.IOException e) { - exc = e; - } - } - - if (exc != null) { - // Report exception - throw new UiException(exc); - } - } - - /** - * This method configures the supplied header property, in the appropriate format, on the - * supplied remote message. - * - * @param rm The remote message - * @param headerName The header name - * @param value The value - * @param format The required format (text, dom, etc.) - * @throws UiException Failed to configure header property - */ - protected void configureHeader(RemoteMessage rm, String headerName, String value, String format) - throws UiException{ - Object propValue=value; - - if (format != null && format.equals("dom")) { - - try { - // Convert to DOM - javax.xml.parsers.DocumentBuilderFactory factory= - javax.xml.parsers.DocumentBuilderFactory.newInstance(); - - factory.setNamespaceAware(true); - - javax.xml.parsers.DocumentBuilder builder= - factory.newDocumentBuilder(); - - java.io.InputStream is= - new java.io.ByteArrayInputStream(value.getBytes()); - - org.w3c.dom.Document doc=builder.parse(is); - - is.close(); - - propValue = doc.getDocumentElement(); - } catch (Exception e) { - throw new UiException("Failed to configure header '"+headerName+"'", e); - } - } - - Property prop=rm.getContext().setProperty(headerName, propValue, Scope.MESSAGE); - prop.addLabels(HttpInvokerLabel.HEADER.label()); - } - /** * This method returns the mbean server connection. * diff --git a/ui/rtgov-ui-services-switchyard/src/main/resources/META-INF/services/org.overlord.rtgov.ui.provider.ServicesProvider b/ui/rtgov-ui-services-switchyard/src/main/resources/META-INF/services/org.overlord.rtgov.ui.provider.ServicesProvider new file mode 100644 index 00000000..5536d9e4 --- /dev/null +++ b/ui/rtgov-ui-services-switchyard/src/main/resources/META-INF/services/org.overlord.rtgov.ui.provider.ServicesProvider @@ -0,0 +1 @@ +org.overlord.rtgov.ui.provider.switchyard.SwitchYardServicesProvider \ No newline at end of file diff --git a/ui/rtgov-ui-services-switchyard/src/main/resources/org/overlord/rtgov/ui/provider/switchyard/messages.properties b/ui/rtgov-ui-services-switchyard/src/main/resources/org/overlord/rtgov/ui/provider/switchyard/messages.properties index 9c148c94..63bddbd6 100644 --- a/ui/rtgov-ui-services-switchyard/src/main/resources/org/overlord/rtgov/ui/provider/switchyard/messages.properties +++ b/ui/rtgov-ui-services-switchyard/src/main/resources/org/overlord/rtgov/ui/provider/switchyard/messages.properties @@ -1,8 +1,9 @@ +SwitchYardResubmitActionProvider.ConfigureHeaderFailed=Failed to configure header ''{0}'' +SwitchYardResubmitActionProvider.IsResubmitSupported=Failed to determine if resubmission for service ''{0}'' and operation ''{1}'' is possible SwitchYardServicesProvider.AppNamesFailed=Failed to get SwitchYard application names SwitchYardServicesProvider.GetServicesFailed=Failed to get SwitchYard service names SwitchYardServicesProvider.GetServiceFailed=Failed to get SwitchYard service for application ''{0}'' and name ''{1}'' SwitchYardServicesProvider.GetReferencesFailed=Failed to get SwitchYard references for application ''{0}'' and service ''{1}'' SwitchYardServicesProvider.GetReferenceFailed=Failed to get SwitchYard reference for application ''{0}'' and name ''{1}'' -SwitchYardServicesProvider.IsResubmitSupported=Failed to determine if resubmission for service ''{0}'' and operation ''{1}'' is possible SwitchYardServicesProvider.JMXConnectionFailed=Failed to connect to switchyard server to obtain service information SwitchYardServicesProvider.DMROperationFailed=Failed to execute DMR operation diff --git a/ui/rtgov-ui-situations/src/main/java/org/overlord/rtgov/ui/provider/situations/RTGovSituationsProvider.java b/ui/rtgov-ui-situations/src/main/java/org/overlord/rtgov/ui/provider/situations/RTGovSituationsProvider.java index c246cdbc..fc4c3e89 100644 --- a/ui/rtgov-ui-situations/src/main/java/org/overlord/rtgov/ui/provider/situations/RTGovSituationsProvider.java +++ b/ui/rtgov-ui-situations/src/main/java/org/overlord/rtgov/ui/provider/situations/RTGovSituationsProvider.java @@ -25,9 +25,8 @@ import java.util.List; import javax.annotation.PostConstruct; -import javax.enterprise.inject.Instance; -import javax.inject.Inject; +import org.overlord.commons.services.ServiceRegistryUtil; import org.overlord.rtgov.active.collection.ActiveChangeListener; import org.overlord.rtgov.active.collection.ActiveCollection; import org.overlord.rtgov.active.collection.ActiveCollectionListener; @@ -63,6 +62,7 @@ import org.overlord.rtgov.ui.client.model.SituationsFilterBean; import org.overlord.rtgov.ui.client.model.TraceNodeBean; import org.overlord.rtgov.ui.client.model.UiException; +import org.overlord.rtgov.ui.provider.ResubmitActionProvider; import org.overlord.rtgov.ui.provider.ServicesProvider; import org.overlord.rtgov.ui.provider.SituationEventListener; import org.overlord.rtgov.ui.provider.SituationsProvider; @@ -93,10 +93,7 @@ public class RTGovSituationsProvider implements SituationsProvider, ActiveChange private SituationStore _situationStore; - @Inject - private Instance _injectedProviders; - - private java.util.List _providers=new java.util.ArrayList(); + private java.util.Set _providers=null; private java.util.List _listeners=new java.util.ArrayList(); @@ -110,11 +107,11 @@ public RTGovSituationsProvider() { } /** - * This method returns the list of services providers. + * This method returns the set of services providers. * * @return The providers */ - protected java.util.List getProviders() { + protected java.util.Set getProviders() { return (_providers); } @@ -201,12 +198,7 @@ public void init() { _situationStore = SituationStoreFactory.getSituationStore(); } - if (_injectedProviders != null) { - // Copy any injected providers into the provider list - for (ServicesProvider sp : _injectedProviders) { - _providers.add(sp); - } - } + _providers = ServiceRegistryUtil.getServices(ServicesProvider.class); if (_callTraceService != null) { // Overwrite any existing activity server to ensure using the @@ -580,11 +572,16 @@ private void resubmitInternal(Situation situation, MessageBean message) throws U } try { - // TODO: Change to specify service, rather than situation - also - // possibly locate the provider appropriate for the service rather than situation - serviceProvider.get().resubmit(operationName.getService(), operationName.getOperation(), message); + ResubmitActionProvider resubmit=serviceProvider.get().getAction(ResubmitActionProvider.class); - _situationStore.recordSuccessfulResubmit(situation.getId(), userName); + if (resubmit == null) { + _situationStore.recordResubmitFailure(situation.getId(), + i18n.format("RTGovSituationsProvider.ResubmitNotSupported"), userName); + } else { + resubmit.resubmit(operationName.getService(), operationName.getOperation(), message); + + _situationStore.recordSuccessfulResubmit(situation.getId(), userName); + } } catch (Exception exception) { _situationStore.recordResubmitFailure(situation.getId(), Throwables.getStackTraceAsString(exception), userName); @@ -784,7 +781,13 @@ private IsResubmitSupported(ServiceOperationName operationName) { @Override public boolean apply(ServicesProvider input) { try { - return input.isResubmitSupported(operationName.getService(), operationName.getOperation()); + ResubmitActionProvider resubmit=input.getAction(ResubmitActionProvider.class); + + if (resubmit == null) { + return false; + } + + return resubmit.isResubmitSupported(operationName.getService(), operationName.getOperation()); } catch (UiException e) { Throwables.propagate(e); } diff --git a/ui/rtgov-ui-situations/src/main/resources/org/overlord/rtgov/ui/provider/situations/messages.properties b/ui/rtgov-ui-situations/src/main/resources/org/overlord/rtgov/ui/provider/situations/messages.properties index aeb6997d..cfa2760e 100644 --- a/ui/rtgov-ui-situations/src/main/resources/org/overlord/rtgov/ui/provider/situations/messages.properties +++ b/ui/rtgov-ui-situations/src/main/resources/org/overlord/rtgov/ui/provider/situations/messages.properties @@ -1,4 +1,5 @@ RTGovSituationsProvider.InvalidSubject=Expecting 2 or 3 parts in the situation subject "{0}", but got "{1}" RTGovSituationsProvider.ResubmitFailed=Failed to resubmit message for situation with id "{0}" RTGovSituationsProvider.ResubmitProviderNotFound=Unable to find provider to resubmit message for situation with id "{0}" +RTGovSituationsProvider.ResubmitNotSupported=Resubmit is not supported RTGovSituationsProvider.SitNotFound=Situation with id "{0}" not found