From b1f26965fd674c21cbbe5d7fa121d95d43c2aa39 Mon Sep 17 00:00:00 2001 From: Andrea Gazzarini Date: Mon, 19 Jan 2009 06:56:14 +0000 Subject: QPID-1578 : WS-Resources lifecycle improved adding "destroy" feature git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@735621 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/qpid/management/ICommand.java | 32 -- .../java/org/apache/qpid/management/Messages.java | 17 +- .../java/org/apache/qpid/management/Names.java | 31 +- .../jmx/EntityLifecycleNotification.java | 4 +- .../management/servlet/ConnectQManToBroker.java | 8 + .../management/servlet/QManLifeCycleManager.java | 49 +- .../qpid/management/servlet/WSDMAdapter.java | 32 +- .../wsdm/capabilities/MBeanCapability.java | 18 +- .../wsdm/capabilities/MBeanCapabilityBuilder.java | 9 +- .../wsdm/capabilities/QManAdapterCapability.java | 175 ++++++-- .../management/wsdm/capabilities/WsdlBuilder.java | 15 +- .../wsdm/common/ObjectNameIdFactory.java | 11 +- .../wsdm/muse/engine/WSDMAdapterEnvironment.java | 45 +- .../wsdm/muse/resources/QManWsResource.java | 496 ++++++++++++++------- 14 files changed, 629 insertions(+), 313 deletions(-) delete mode 100644 qpid/java/management/client/src/main/java/org/apache/qpid/management/ICommand.java (limited to 'qpid/java/management/client/src') diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/ICommand.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/ICommand.java deleted file mode 100644 index c95270688e..0000000000 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/ICommand.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.qpid.management; - -/** - * Command interface. - */ -public interface ICommand -{ - /** - * Executes the action specified by this command. - */ - public void execute() throws Exception; -} diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/Messages.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/Messages.java index c2a102ff95..75e46afdfd 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/Messages.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/Messages.java @@ -62,6 +62,8 @@ public interface Messages String QMAN_000027_WSDM_ADAPTER_STARTED = " : WS-DM Adapter ready for incoming requests."; String QMAN_000028_TEST_MODULE_NOT_FOUND = " : Qpid emulator not found. Test notifications are disabled."; String QMAN_000029_DEFAULT_URI = " : Default URI will be set to %s"; + String QMAN_000030_RESOURCE_HAS_BEEN_CREATED = " : New resource instance has been created and registered. Resource id is %s"; + String QMAN_000031_RESOURCE_HAS_BEEN_REMOVED = " : WS-Resource %s has been removed"; // DEBUG String QMAN_200001_INCOMING_MESSAGE_HAS_BEEN_RECEIVED = " : New incoming message has been received. Message content is %s"; @@ -105,14 +107,15 @@ public interface Messages String QMAN_200039_DEBUG_JMX_NOTIFICATION = " : %s"; String QMAN_200040_WS_ARTIFACTS_CACHED = " : WS Artifacts has been stored on cache with the following id : %s"; String QMAN_200041_INCOMING_OBJECT_NAME_AND_DERIVED_KEY = " : Incoming object name : %s, derived search key : %s"; - - + String QMAN_200042_REMOVING_RESOURCE = " : WS-Resource %s is going to be removed"; // WARNING String QMAN_300001_MESSAGE_DISCARDED = " : No handler has been configured for processing messages with \"%s\" as opcode. Message will be discarded."; String QMAN_300002_UNKNOWN_SEQUENCE_NUMBER = " : Unable to deal with incoming message because it contains a unknown sequence number (%s)."; String QMAN_300003_BROKER_ALREADY_CONNECTED = " : Unable to enlist given broker connection data : QMan is already connected with broker %s"; String QMAN_300004_INVALID_CONFIGURATION_FILE = " : The given configuration file (%s) is not valid (it doesn't exist or cannot be read)"; + + String QMAN_300005_QEMU_INITIALIZATION_FAILURE = " : Unable to initialize QEmu module and therefore emulation won't be enabled..."; // ERROR String QMAN_100001_BAD_MAGIC_NUMBER_FAILURE = " : Message processing failure : incoming message contains a bad magic number (%s) and therefore will be discaded."; @@ -138,5 +141,13 @@ public interface Messages String QMAN_100023_BUILD_WS_ARTIFACTS_FAILURE = " : Unable to build WS artifacts."; String QMAN_100024_CAPABILITY_INSTANTIATION_FAILURE = " : Unable to instantiate generated capability class for %s."; String QMAN_100025_WSRF_FAILURE = " : Resource manager raised an exception while creating capability for %s."; - String QMAN_100026_SOAP_ADDRESS_REPLACEMENT_FAILURE = " : Exception occurred while replacing the placeholder soap address with resource actual location."; + String QMAN_100026_SOAP_ADDRESS_REPLACEMENT_FAILURE = " : Exception occurred while replacing the placeholder soap address with resource actual location."; + + //// NEW + String QMAN_100027_RESOURCE_SHUTDOWN_FAILURE = " : Shutdown failure while destroying resource %s."; + String QMAN_100029_MALFORMED_RESOURCE_URI_FAILURE = " : Unable to define URI for QMan resources using \"%s\". It violates RFC 2396"; + String QMAN_100030_JMX_CORE_STARTUP_FAILURE = " : QMan JMX core Unexpected failure while starting up."; + String QMAN_100031_WS_RESOURCE_ALREADY_INITIALIZED = " : Bad request has been received on this WS-Resource : Initialization is not possible because the resource has already been initialized."; + String QMAN_100032_WS_RESOURCE_NOT_YET_INITIALIZED = " : Bad request has been received on this WS-Resource : Shutdown is not possible because the resource hasn't yet been initialized."; + String QMAN_100033_WS_RESOURCE_ALREADY_SHUTDOWN = " : Bad request has been received on this WS-Resource : Shutdown is not possible because the resource has already been shutdown."; } \ No newline at end of file diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/Names.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/Names.java index 89d97d9297..da533c6f59 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/Names.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/Names.java @@ -45,7 +45,7 @@ public abstract class Names public static String PACKAGE = "package"; public static String CLASS = "class"; public static String EVENT = "event"; - public static String OBJECT_ID="objectID"; + public static String OBJECT_ID="objectId"; public static String BROKER_ID = "brokerID"; public static String DOMAIN_NAME = "Q-MAN"; @@ -61,12 +61,34 @@ public abstract class Names public static String NOT_AVAILABLE = "N.A."; + public static ObjectName QPID_EMULATOR_OBJECT_NAME; + static + { + try + { + QPID_EMULATOR_OBJECT_NAME = new ObjectName( + new StringBuilder() + .append(DOMAIN_NAME) + .append(':') + .append("Name=Qpid,Type=Emulator") + .toString()); + } catch(Exception exception) + { + throw new ExceptionInInitializerError(exception); + } + } + public static ObjectName QMAN_OBJECT_NAME; static { try { - QMAN_OBJECT_NAME = new ObjectName(new StringBuilder().append(DOMAIN_NAME).append(':').append("Type=Service").toString()); + QMAN_OBJECT_NAME = new ObjectName( + new StringBuilder() + .append(DOMAIN_NAME) + .append(':') + .append("Type=Service") + .toString()); } catch(Exception exception) { throw new ExceptionInInitializerError(exception); @@ -75,8 +97,13 @@ public abstract class Names // WSDM Stuff public static String NAMESPACE_URI = "http://amqp.apache.org/qpid/management/qman"; + public static String ADDRESSING_URI = "http://amqp.apache.org/qpid/management/qman/addressing"; + public static String ADDRESSING_PREFIX = "qman-wsa"; + + public static final QName RESOURCE_ID_QNAME = new QName(ADDRESSING_URI, "ResourceId", ADDRESSING_PREFIX); public final static String PREFIX = "qman"; public final static String QMAN_RESOURCE_NAME = "QManWsResource"; + public final static String VALIDATE_WSRP_PARAM = "validate-wsrp-schema"; public static final String WEB_APP_CLASSES_FOLDER = "/WEB-INF/classes"; diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/jmx/EntityLifecycleNotification.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/jmx/EntityLifecycleNotification.java index e387e56e2c..5a99690756 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/jmx/EntityLifecycleNotification.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/jmx/EntityLifecycleNotification.java @@ -46,8 +46,8 @@ public class EntityLifecycleNotification extends Notification public static final String SCHEMA_REQUESTED = "org.apache.qpid.management.lifecycle.entity.schema.requested"; public static final String MALFORMED_SCHEMA = "org.apache.qpid.management.lifecycle.error.schema"; - public static final String INSTANCE_ADDED = "org.apache.qpid.management.lifecycle.entity.instance.created"; - public static final String INSTANCE_REMOVED = "org.apache.qpid.management.lifecycle.entity.instance.removed"; + public static final String INSTANCE_ADDED = "qman.lifecycle.entity.instance.created"; + public static final String INSTANCE_REMOVED = "qman.lifecycle.entity.instance.removed"; private String _packageName = Names.NOT_AVAILABLE; private String _className = Names.NOT_AVAILABLE; diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/servlet/ConnectQManToBroker.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/servlet/ConnectQManToBroker.java index 574e29de81..af037861ba 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/servlet/ConnectQManToBroker.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/servlet/ConnectQManToBroker.java @@ -69,6 +69,14 @@ public class ConnectQManToBroker extends MiniServlet } } + /** + * This is a startup module only so an override of the default servlet + * behaviour must be done in order to prevent incoming http requests processing. + * + * @param request the http request. + * @param response the http response. + * @throws ServletException each time this method is called. + */ @Override public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException { diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/servlet/QManLifeCycleManager.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/servlet/QManLifeCycleManager.java index 684221f91e..edd6804e68 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/servlet/QManLifeCycleManager.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/servlet/QManLifeCycleManager.java @@ -24,34 +24,24 @@ import javax.servlet.ServletContext; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; +import org.apache.qpid.management.Messages; import org.apache.qpid.management.Names; import org.apache.qpid.management.domain.services.QMan; import org.apache.qpid.management.domain.services.StartupFailureException; +import org.apache.qpid.transport.util.Logger; /** - * QMan lifecycle management. + * QMan JMX lifecycle manager. + * Provides lifecycle management of QMan JMX core including startup and shutdown. * * @author Andrea Gazzarini */ public class QManLifeCycleManager implements ServletContextListener { + private final static Logger LOGGER = Logger.get(QManLifeCycleManager.class); + /** - * Stops QMan. - * - * @param event the application context event. - */ - public void contextDestroyed(ServletContextEvent event) - { - ServletContext context = event.getServletContext(); - - QMan qman = (QMan) context.getAttribute(Names.APPLICATION_NAME); - qman.stop(); - - context.setAttribute(Names.APPLICATION_NAME, qman); - } - - /** - * Starts QMan. + * Starts QMan JMX Core. * * @param event the application context event. */ @@ -61,12 +51,29 @@ public class QManLifeCycleManager implements ServletContextListener { QMan qman = new QMan(); qman.start(); - - event.getServletContext().setAttribute(Names.APPLICATION_NAME, qman); + event.getServletContext().setAttribute( + Names.APPLICATION_NAME, + qman); } catch (StartupFailureException exception) { - // TODO : LOG ERROR. - exception.printStackTrace(); + LOGGER.error( + exception, + Messages.QMAN_100030_JMX_CORE_STARTUP_FAILURE); } } + + /** + * Sutdown QMan JMX Core. + * + * @param event the application context event. + */ + public void contextDestroyed(ServletContextEvent event) + { + ServletContext context = event.getServletContext(); + + QMan qman = (QMan) context.getAttribute(Names.APPLICATION_NAME); + qman.stop(); + + context.removeAttribute(Names.APPLICATION_NAME); + } } \ No newline at end of file diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/servlet/WSDMAdapter.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/servlet/WSDMAdapter.java index f927ca131c..58f839bb33 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/servlet/WSDMAdapter.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/servlet/WSDMAdapter.java @@ -51,9 +51,15 @@ public class WSDMAdapter extends HttpServlet @Override public void init() throws ServletException { - _isolationLayer = new WSDMAdapterIsolationLayer(getServletContext()); + LOGGER.debug(Messages.QMAN_000026_WSDM_ADAPTER_STARTS); + + + _isolationLayer = new WSDMAdapterIsolationLayer(getServletContext()); _isolationLayer.initialize(); - } + + LOGGER.debug(Messages.QMAN_000027_WSDM_ADAPTER_STARTED); + + } /** * Accepts http requests containing a soap envelope (request) and therefore @@ -92,23 +98,11 @@ public class WSDMAdapter extends HttpServlet writer.flush(); XmlDebugger.debug(soapEnvelopeRequest); - XmlDebugger.debug(soapEnvelopeResposeAsString); - } - } - - /** - * Stops QMan Adapter. - */ - public void destroy() - { - try - { - _isolationLayer.shutdown(); - } catch (Exception exception) - { - LOGGER.error( - exception, - Messages.QMAN_100022_ISOLATION_LAYER_SHUTDOWN_FAILURE); + try { + XmlDebugger.debug(soapEnvelopeResposeAsString); + } catch(Exception exception) { + System.out.println("Unable to parse response."); + } } } } \ No newline at end of file diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/MBeanCapability.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/MBeanCapability.java index aec022d093..76edf878a0 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/MBeanCapability.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/MBeanCapability.java @@ -160,13 +160,12 @@ public abstract class MBeanCapability extends AbstractWsResourceCapability * * @param name * @param value - * TODO TODO TODO!!! Vedi che poi fà co 'sto metodo che è un pò una monnezza!!! + * TODO : Vedi che poi fà co 'sto metodo che è un pò una monnezza!!! * @return The XML representation of the resource property value(s). * */ @SuppressWarnings("unchecked") - protected Element[] getPropertyElements(QName name, Object value) - throws BaseFault { + protected Element[] getPropertyElements(QName name, Object value) throws BaseFault { // // in this case, we have to determine if there IS a property // and it's null, or there is no property @@ -226,19 +225,20 @@ public abstract class MBeanCapability extends AbstractWsResourceCapability Serializer ser = registry.getSerializer(type); for (int n = 0; n < length; ++n) + { properties[n] = serializeValue(ser, Array.get(valuesArray, n), name); - + } return properties; } private Element serializeValue(Serializer ser, Object value, QName name) throws BaseFault { - try { + try + { return ser.toXML(value, name); - } - - catch (SoapFault error) { - throw WsbfUtils.convertToFault(error); + } catch (SoapFault exception) + { + throw WsbfUtils.convertToFault(exception); } } } \ No newline at end of file diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/MBeanCapabilityBuilder.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/MBeanCapabilityBuilder.java index 3c7c2a2a42..df2a963d50 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/MBeanCapabilityBuilder.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/MBeanCapabilityBuilder.java @@ -101,7 +101,6 @@ public class MBeanCapabilityBuilder implements IArtifactBuilder{ } } catch(Exception exception) { - System.err.println(buffer); throw new BuilderException(exception); } } @@ -133,7 +132,7 @@ public class MBeanCapabilityBuilder implements IArtifactBuilder{ public void onOperation(MBeanOperationInfo operation) { - // TODO + // TODO : operation on mbean capability } public Class getCapabilityClass() @@ -157,7 +156,6 @@ public class MBeanCapabilityBuilder implements IArtifactBuilder{ _capabilityClassDefinition.addMethod(getPropertyNames); } catch(Exception exception) { - System.err.println(_properties); throw new BuilderException(exception); } } @@ -167,7 +165,10 @@ public class MBeanCapabilityBuilder implements IArtifactBuilder{ { try { - _capabilityClass = _capabilityClassDefinition.toClass(); + // Class loader and protection domain are needed for Qpid emulation. + _capabilityClass = _capabilityClassDefinition.toClass( + QManAdapterCapability.class.getClassLoader(), + QManAdapterCapability.class.getProtectionDomain()); } catch (Exception exception) { throw new BuilderException(exception); diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/QManAdapterCapability.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/QManAdapterCapability.java index 5c0afa4597..7d111b8031 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/QManAdapterCapability.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/QManAdapterCapability.java @@ -21,11 +21,12 @@ package org.apache.qpid.management.wsdm.capabilities; import java.lang.management.ManagementFactory; +import java.net.URI; import javax.management.InstanceNotFoundException; import javax.management.MBeanServer; import javax.management.Notification; -import javax.management.NotificationFilterSupport; +import javax.management.NotificationFilter; import javax.management.NotificationListener; import javax.management.ObjectName; @@ -33,35 +34,51 @@ import org.apache.muse.core.AbstractCapability; import org.apache.muse.core.Resource; import org.apache.muse.core.ResourceManager; import org.apache.muse.core.serializer.SerializerRegistry; +import org.apache.muse.ws.addressing.EndpointReference; import org.apache.muse.ws.addressing.soap.SoapFault; import org.apache.qpid.management.Messages; import org.apache.qpid.management.Names; import org.apache.qpid.management.jmx.EntityLifecycleNotification; import org.apache.qpid.management.wsdm.common.ThreadSessionManager; +import org.apache.qpid.management.wsdm.muse.engine.WSDMAdapterEnvironment; import org.apache.qpid.management.wsdm.muse.serializer.ByteArraySerializer; import org.apache.qpid.transport.util.Logger; /** - * MBean Server capabilty interface implementor. - * Providers all the operations of the MBeanServer interface using the platform MBeanServer. + * QMan Adapter capability. + * Basically it acts as a lifecycle manager of all ws resource that correspond to entities on JMX side. + * + * @author Andrea Gazzarini */ public class QManAdapterCapability extends AbstractCapability { - private MBeanServer _mxServer; private final static Logger LOGGER = Logger.get(QManAdapterCapability.class); - + + private MBeanServer _mxServer; private WsArtifactsFactory _artifactsFactory; + private URI _resourceURI; + /** + * This listener handles "create" mbean events and therefore provides procedure to create and initialize + * corresponding ws resources. + */ private final NotificationListener listenerForNewInstances = new NotificationListener() { + /** + * Handles JMX "create" notification type. + * + * @param notification the entity lifecycle notification. + * @param data user data associated with the incoming notifiication : it is not used at the moment. + */ public void handleNotification(Notification notification, Object data) { - EntityLifecycleNotification lifecycleNotification = (EntityLifecycleNotification) notification; - ObjectName eventSourceName = lifecycleNotification.getObjectName(); - ThreadSessionManager.getInstance().getSession().setObjectName(eventSourceName); - + ObjectName eventSourceName = null; try - { + { + EntityLifecycleNotification lifecycleNotification = (EntityLifecycleNotification) notification; + eventSourceName = lifecycleNotification.getObjectName(); + ThreadSessionManager.getInstance().getSession().setObjectName(eventSourceName); + LOGGER.debug(Messages.QMAN_200039_DEBUG_JMX_NOTIFICATION, notification); ResourceManager resourceManager = getResource().getResourceManager(); @@ -72,42 +89,91 @@ public class QManAdapterCapability extends AbstractCapability artifacts.getCapabilityClass(), eventSourceName); - ThreadSessionManager.getInstance().getSession().setWsdlDocument(artifacts.getWsdl()); ThreadSessionManager.getInstance().getSession().setResourceMetadataDescriptor(artifacts.getResourceMetadataDescriptor()); -// ResourceManager resourceManager = getResource().getResourceManager(); -// -// Resource resource = resourceManager.createResource(Names.QMAN_RESOURCE_NAME); -// resource.setWsdlPortType(Names.QMAN_RESOURCE_PORT_TYPE_NAME); + resource.setWsdlPortType(Names.QMAN_RESOURCE_PORT_TYPE_NAME); + capability.setCapabilityURI(Names.NAMESPACE_URI+"/"+capability.getClass().getSimpleName()); resource.addCapability(capability); resource.initialize(); resourceManager.addResource(resource.getEndpointReference(), resource); + + LOGGER.info( + Messages.QMAN_000030_RESOURCE_HAS_BEEN_CREATED, + eventSourceName); } catch (ArtifactsNotAvailableException exception) { - LOGGER.error(exception,Messages.QMAN_100023_BUILD_WS_ARTIFACTS_FAILURE); + LOGGER.error( + exception, + Messages.QMAN_100023_BUILD_WS_ARTIFACTS_FAILURE); } catch (IllegalAccessException exception) { - LOGGER.error(exception,Messages.QMAN_100024_CAPABILITY_INSTANTIATION_FAILURE,eventSourceName); + LOGGER.error( + exception, + Messages.QMAN_100024_CAPABILITY_INSTANTIATION_FAILURE, + eventSourceName); } catch (InstantiationException exception) { - LOGGER.error(exception,Messages.QMAN_100024_CAPABILITY_INSTANTIATION_FAILURE,eventSourceName); + LOGGER.error( + exception, + Messages.QMAN_100024_CAPABILITY_INSTANTIATION_FAILURE, + eventSourceName); } catch (SoapFault exception) { - LOGGER.error(exception,Messages.QMAN_100025_WSRF_FAILURE,eventSourceName); + LOGGER.error( + exception,Messages.QMAN_100025_WSRF_FAILURE, + eventSourceName); } catch (Exception exception) { - LOGGER.error(exception,Messages.QMAN_100025_WSRF_FAILURE,eventSourceName); + LOGGER.error( + exception, + Messages.QMAN_100025_WSRF_FAILURE, + eventSourceName); } - } }; + /** + * This listener handles "remove" mbean events and therefore provides procedure to shutdown and remove + * corresponding ws resources. + */ private final NotificationListener listenerForRemovedInstances = new NotificationListener() { + /** + * Handles JMX "remove" notification type. + * + * @param notification the entity lifecycle notification. + * @param data user data associated with the incoming notifiication : it is not used at the moment. + */ public void handleNotification(Notification notification, Object data) { - LOGGER.warn("TBD : Notification Listener for removed instances has not yet implemeted!"); + EntityLifecycleNotification lifecycleNotification = (EntityLifecycleNotification) notification; + ObjectName eventSourceName = lifecycleNotification.getObjectName(); + + LOGGER.debug(Messages.QMAN_200042_REMOVING_RESOURCE, eventSourceName); + + EndpointReference endpointPointReference = new EndpointReference(_resourceURI); + endpointPointReference.addParameter( + Names.RESOURCE_ID_QNAME, + eventSourceName.getCanonicalName()); + + ResourceManager resourceManager = getResource().getResourceManager(); + try + { + Resource resource = resourceManager.getResource(endpointPointReference); + resource.shutdown(); + + LOGGER.info( + Messages.QMAN_000031_RESOURCE_HAS_BEEN_REMOVED, + eventSourceName); + } + catch(Exception exception) + { + LOGGER.error( + exception, + Messages.QMAN_100027_RESOURCE_SHUTDOWN_FAILURE, + eventSourceName); + } } }; @@ -120,24 +186,71 @@ public class QManAdapterCapability extends AbstractCapability // What is the stringified name of the class? byte[].getClass().getName() is [B but is not working (ClassNotFound). // So, at the end, this is hard-coded here! SerializerRegistry.getInstance().registerSerializer(byte[].class, new ByteArraySerializer()); - + WSDMAdapterEnvironment environment = (WSDMAdapterEnvironment) getEnvironment(); + String resourceURI = environment.getDefaultURIPrefix()+Names.QMAN_RESOURCE_NAME; try { + _resourceURI = URI.create(resourceURI); + _mxServer = ManagementFactory.getPlatformMBeanServer(); _artifactsFactory = new WsArtifactsFactory(getEnvironment(),_mxServer); - NotificationFilterSupport filterForNewInstances = new NotificationFilterSupport(); - filterForNewInstances.enableType(EntityLifecycleNotification.INSTANCE_ADDED); + /** + * NotificationFilter for "create" only events. + */ + NotificationFilter filterForNewInstances = new NotificationFilter(){ + + private static final long serialVersionUID = 1733325390964454595L; + + public boolean isNotificationEnabled(Notification notification) + { + return EntityLifecycleNotification.INSTANCE_ADDED.equals(notification.getType()); + } + + }; + + /** + * NotificationFilter for "remove" only events. + */ + NotificationFilter filterForRemovedInstances = new NotificationFilter(){ + + private static final long serialVersionUID = 1733325390964454595L; + + public boolean isNotificationEnabled(Notification notification) + { + return EntityLifecycleNotification.INSTANCE_REMOVED.equals(notification.getType()); + } + + }; - NotificationFilterSupport filterForRemovedInstances = new NotificationFilterSupport(); - filterForNewInstances.enableType(EntityLifecycleNotification.INSTANCE_REMOVED); + _mxServer.addNotificationListener( + Names.QMAN_OBJECT_NAME, + listenerForNewInstances, + filterForNewInstances, + null); - _mxServer.addNotificationListener(Names.QMAN_OBJECT_NAME, listenerForNewInstances, filterForNewInstances, null); - _mxServer.addNotificationListener(Names.QMAN_OBJECT_NAME, listenerForRemovedInstances, filterForRemovedInstances, null); + _mxServer.addNotificationListener( + Names.QMAN_OBJECT_NAME, + listenerForRemovedInstances, + filterForRemovedInstances, + null); try { - _mxServer.addNotificationListener(new ObjectName("A:A=1"), listenerForNewInstances, filterForNewInstances, null); - } catch (Exception exception) { + _mxServer.addNotificationListener( + Names.QPID_EMULATOR_OBJECT_NAME, + listenerForNewInstances, + filterForNewInstances, null); + + _mxServer.addNotificationListener( + Names.QPID_EMULATOR_OBJECT_NAME, + listenerForRemovedInstances, + filterForRemovedInstances, null); + + } catch(IllegalArgumentException exception) + { + LOGGER.info(exception,Messages.QMAN_000029_DEFAULT_URI,resourceURI); + } + catch (Exception exception) { LOGGER.info(Messages.QMAN_000028_TEST_MODULE_NOT_FOUND); } diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/WsdlBuilder.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/WsdlBuilder.java index 194253bf25..85b5198493 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/WsdlBuilder.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/WsdlBuilder.java @@ -155,17 +155,17 @@ class WsdlBuilder implements IArtifactBuilder { public void onOperation(MBeanOperationInfo operation) { - // TODO + // TODO : Operations on wsdl } public void endAttributes() { - // TODO + // N.A. } public void endOperations() { - // TODO + // N.A. } public Document getWsdl() @@ -184,9 +184,10 @@ class WsdlBuilder implements IArtifactBuilder { _document = WsdlUtils.createWSDL(_environment, wsdlPath, true); try { - Attr location = (Attr) XPathAPI.selectSingleNode(_document, "/wsdl:definitions/wsdl:service/wsdl:port/wsdl-soap:address/@location"); + Attr location = (Attr) XPathAPI.selectSingleNode( + _document, + "/wsdl:definitions/wsdl:service/wsdl:port/wsdl-soap:address/@location"); - // TODO : come faccio a recuperare l'URL sul quale gira l'applicazione? StringBuilder builder = new StringBuilder("http://") .append(InetAddress.getLocalHost().getHostName()) .append(':') @@ -198,7 +199,9 @@ class WsdlBuilder implements IArtifactBuilder { location.setValue(builder.toString()); } catch(Exception exception) { - LOGGER.error(exception,Messages.QMAN_100026_SOAP_ADDRESS_REPLACEMENT_FAILURE); + LOGGER.error( + exception, + Messages.QMAN_100026_SOAP_ADDRESS_REPLACEMENT_FAILURE); } } } diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/common/ObjectNameIdFactory.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/common/ObjectNameIdFactory.java index be3bbb48d1..83c1209e42 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/common/ObjectNameIdFactory.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/common/ObjectNameIdFactory.java @@ -23,19 +23,26 @@ package org.apache.qpid.management.wsdm.common; import javax.xml.namespace.QName; import org.apache.muse.core.routing.ResourceIdFactory; -import org.apache.muse.ws.addressing.WsaConstants; +import org.apache.qpid.management.Names; /** * ResourceIdFactory implementation that is using an objectName as * resource identifier. + * This is done in order to make a relationship between an MBean (which is part of the + * JMX core domain model) and a WS-Resource (the same entity as is represented on WS-DM adapter side). * * @author Andrea Gazzarini */ public class ObjectNameIdFactory implements ResourceIdFactory { + /** + * Returns the name of the identifier element. + * + * @return the name of the identifier element. + */ public QName getIdentifierName() { - return WsaConstants.DEFAULT_RESOURCE_ID_QNAME; + return Names.RESOURCE_ID_QNAME; } /** diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/muse/engine/WSDMAdapterEnvironment.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/muse/engine/WSDMAdapterEnvironment.java index 0c70af437e..438c1d9db9 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/muse/engine/WSDMAdapterEnvironment.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/muse/engine/WSDMAdapterEnvironment.java @@ -23,7 +23,8 @@ public class WSDMAdapterEnvironment extends AbstractEnvironment { private final static Logger LOGGER = Logger.get(WSDMAdapterEnvironment.class); private final File _realDirectory; - + private final ServletContext _servletContext; + /** * Builds a new qman environment with the given application context. * @@ -31,32 +32,17 @@ public class WSDMAdapterEnvironment extends AbstractEnvironment */ public WSDMAdapterEnvironment(ServletContext servletContext) { - String realDirectoryPath = servletContext.getRealPath(Names.WEB_APP_CLASSES_FOLDER); + this._servletContext = servletContext; + String realDirectoryPath = servletContext.getRealPath(Names.WEB_APP_CLASSES_FOLDER); _realDirectory = (realDirectoryPath != null) ? new File(realDirectoryPath) : FileUtils.CURRENT_DIR; - - String host = null; - - try { - host = InetAddress.getLocalHost().getHostName(); - } catch (UnknownHostException e) { - host = "localhost"; - } - String defaultURI = new StringBuilder() - .append("http://") - .append(host) - .append(":") - .append(System.getProperty(Names.ADAPTER_PORT)) - .append(servletContext.getContextPath()) - .append("/services/adapter") - .toString(); + String defaultURI = getDefaultURIPrefix()+"adapter"; + setDefaultURI(defaultURI); LOGGER.info(Messages.QMAN_000029_DEFAULT_URI, defaultURI); - - setDefaultURI(defaultURI); } /** @@ -78,4 +64,23 @@ public class WSDMAdapterEnvironment extends AbstractEnvironment { return _realDirectory; } + + public String getDefaultURIPrefix() + { + String host = null; + try { + host = InetAddress.getLocalHost().getHostName(); + } catch (UnknownHostException e) { + host = "localhost"; + } + + return new StringBuilder() + .append("http://") + .append(host) + .append(":") + .append(System.getProperty(Names.ADAPTER_PORT)) + .append(_servletContext.getContextPath()) + .append("/services/") + .toString(); + } } \ No newline at end of file diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/muse/resources/QManWsResource.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/muse/resources/QManWsResource.java index 50b1c7cd33..c65d716fb5 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/muse/resources/QManWsResource.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/muse/resources/QManWsResource.java @@ -52,7 +52,6 @@ import org.apache.muse.ws.resource.properties.schema.ResourcePropertiesSchema; import org.apache.muse.ws.resource.properties.schema.impl.SimpleResourcePropertiesSchema; import org.apache.muse.ws.wsdl.WsdlUtils; import org.apache.qpid.management.Messages; -import org.apache.qpid.management.Names; import org.apache.qpid.management.wsdm.common.ThreadSessionManager; import org.apache.qpid.transport.util.Logger; import org.w3c.dom.Document; @@ -60,26 +59,215 @@ import org.w3c.dom.Element; /** * QMan WS resource. - * This is the WS Resource wrapper of a QMan managed entity. + * We could say that this is a QMan manageable entity under the + * WS-DM perspective. * * @author Andrea Gazzarini - * TODO :Refactoring :: use STATE Pattern! */ @SuppressWarnings("unchecked") public class QManWsResource implements WsResource { private final static Logger LOGGER = Logger.get(QManWsResource.class); + + /** + * Internal state of this resource. + * + * @author Andrea Gazzarini + */ + interface State + { + /** + * Provides initialization of this resource. + * + * @throws SoapFault when the initialization fails. + */ + void initialize() throws SoapFault; + + /** + * Returns true if this resource has been initialized. + * + * @return true if this resource has been initialized. + */ + boolean hasBeenInitialized(); + + /** + * Returns true if this resource has been shutdown. + * + * @return true if this resource has been shutdown. + */ + boolean hasBeenShutdown(); + + /** + * Shuts down this resource. + * + * @throws SoapFault when the shutdown procedure fails. + */ + void shutdown() throws SoapFault; + } - // Utility class for logging. - private final static class Log { - static void debugElement(String message,Element element) + private final State _hasBeenShutdown = new State() + { + /** + * Return false because this resource has been shutdown so therefore + * initialization occurred. + * + * @return true; + */ + public boolean hasBeenInitialized() { - if (LOGGER.isDebugEnabled()) - { - LOGGER.debug(message, XmlUtils.toString(element)); - } + return true; } - } + + /** + * Returns true because this state indicates that resource has been shutdown. + * + * @return true. + */ + public boolean hasBeenShutdown() + { + return true; + } + + /** + * Since this resource has been shutdown the initialization + * cannot be performed again. + * As conseguence of that this method throws an exception. + * + * @throws SoapFault each time this method is called. + */ + public void initialize() throws SoapFault + { + LOGGER.error(Messages.QMAN_100031_WS_RESOURCE_ALREADY_INITIALIZED); + throw new SoapFault(Messages.QMAN_100031_WS_RESOURCE_ALREADY_INITIALIZED); + } + + public void shutdown() throws SoapFault + { + LOGGER.error(Messages.QMAN_100033_WS_RESOURCE_ALREADY_SHUTDOWN); + throw new SoapFault(Messages.QMAN_100033_WS_RESOURCE_ALREADY_SHUTDOWN); + } + }; + + private final State _hasBeenInitialized = new State() + { + /** + * Returns true because this is the state where a resource is when it + * has been initialized. + * + * @return true. + */ + public boolean hasBeenInitialized() + { + return true; + } + + /** + * Returns false because this resource has been initialized but no shutdown request + * has been received. + * + * @return false. + */ + public boolean hasBeenShutdown() + { + return false; + } + + /** + * A resource in this state cannot be initialized again so if this method is called an + * exception is thrown. + * + * @throws SoapFault each time this method is called. + */ + public void initialize() throws SoapFault + { + LOGGER.error(Messages.QMAN_100031_WS_RESOURCE_ALREADY_INITIALIZED); + throw new SoapFault(Messages.QMAN_100031_WS_RESOURCE_ALREADY_INITIALIZED); + } + + /** + * Shuts down this resource. + * + * @throws SoapFault when the shutdown procedure fails. + */ + public void shutdown() throws SoapFault + { + shutdownCapabilities(); + + ResourceManager manager = getResourceManager(); + + if (manager.getResource(_enpointReference) != null) + { + manager.removeResource(_enpointReference); + } + + _currentState = _hasBeenShutdown; + } + }; + + /** + * The initial state of this resource. + * As the name suggests, it is not yet initialized. + */ + private final State _notYetInitialized = new State() + { + /** + * Provides initialization of this resource. + * + * @throws SoapFault when the initialization fails. + */ + public void initialize() throws SoapFault + { + _properties = new SimpleResourcePropertyCollection(); + _wsdl = ThreadSessionManager.getInstance().getSession().getWsdlDocument(); + + ResourcePropertiesSchema schema = createPropertiesSchema(_wsdl); + _properties.setSchema(schema); + + MetadataDescriptor metadata = createMetadataDescriptor(_wsdl); + _properties.setMetadata(metadata); + + initializeCapabilities(); + + _properties.applyMetadata(); + _properties.validateMetadata(); + + // Resource intialization completed : Let's make a state change. + _currentState = _hasBeenInitialized; + } + + /** + * Shuts down this resource. + * + * @throws SoapFault when the shutdown procedure fails. */ + public void shutdown() throws SoapFault + { + LOGGER.error(Messages.QMAN_100032_WS_RESOURCE_NOT_YET_INITIALIZED); + throw new SoapFault(Messages.QMAN_100032_WS_RESOURCE_NOT_YET_INITIALIZED); + } + + /** + * Returns false because this state indicates that + * the resource has not yet been initialized. + * + * @return false; + */ + public boolean hasBeenInitialized() + { + return false; + } + + /** + * Returns false because the resource, when is in this state + * hasn't been initialized and as conseguence of that hasn't + * been shutdonm. + * + * @return false; + */ + public boolean hasBeenShutdown() + { + return false; + } + }; private Map _capabilitiesByAction = new HashMap(); private Map _capabilitiesByURI = new LinkedHashMap(); @@ -88,14 +276,15 @@ public class QManWsResource implements WsResource private Environment _environment; private EndpointReference _enpointReference; - private boolean _hasBeenInitialized; - private boolean _hasBeenShutdown; + private State _currentState = _notYetInitialized; private ResourceManager _resourceManager; private ResourcePropertyCollection _properties; private Map _initParameters = Collections.EMPTY_MAP; + // Workaround : muse is using and hardcoded java.util.logging.Logger but we should use + // SLF4j so this is the original implementatation that won't never be used (on QMan classes) private java.util.logging.Logger _logger; private Document _wsdl; @@ -116,7 +305,10 @@ public class QManWsResource implements WsResource String uri = capability.getCapabilityURI(); _capabilitiesByURI.put(uri, capability); - LOGGER.debug(Messages.QMAN_200033_CAPABILITY_CLASS_HAS_BEEN_ADDED, capability.getClass(),uri); + LOGGER.debug( + Messages.QMAN_200033_CAPABILITY_CLASS_HAS_BEEN_ADDED, + capability.getClass(), + uri); } /** @@ -124,31 +316,20 @@ public class QManWsResource implements WsResource * * @return the capability associated with the given URI. */ - public final Capability getCapability(String capabilityURI) + public Capability getCapability(String capabilityURI) { return _capabilitiesByURI.get(capabilityURI); } - /** - * Returns all the WS-Action URIs supported by this resource. - * - * @return all of the WS-A Action URIs supported by this resource. - */ - protected Collection getCapabilityActions() - { - return Collections.unmodifiableSet(_capabilitiesByAction.keySet()); - } - - /** - * Returns the capability associated with the given action. - * - * @param action the wsa:action of the requested capability. - * @return the capability associated with the given action. - */ - protected Capability getCapabilityForAction(String action) - { - return (Capability)_capabilitiesByAction.get(action); - } +// /** +// * Returns all the WS-Action URIs supported by this resource. +// * +// * @return all of the WS-A Action URIs supported by this resource. +// */ +// protected Collection getCapabilityActions() +// { +// return Collections.unmodifiableSet(_capabilitiesByAction.keySet()); +// } /** * Returns a collection with all registered capability URIs. @@ -258,7 +439,7 @@ public class QManWsResource implements WsResource */ public final boolean hasBeenInitialized() { - return _hasBeenInitialized; + return _currentState.hasBeenInitialized(); } /** @@ -268,7 +449,7 @@ public class QManWsResource implements WsResource */ public final boolean hasBeenShutdown() { - return _hasBeenShutdown; + return _currentState.hasBeenShutdown(); } /** @@ -281,62 +462,6 @@ public class QManWsResource implements WsResource return getCapability(capabilityURI) != null; } - /** - * Creates a metadata descriptor for this resource. - * - * @param wsdl the WSDL document. - * @return a metadata descriptor for this resource. - * @throws SoapFault when it's not possible build the descriptor. - */ - protected MetadataDescriptor createMetadataDescriptor(Document wsdl) throws SoapFault - { - try - { - Element portTypeXML = WsdlUtils.getPortType(wsdl, getWsdlPortType()); - - String rmdName = XmlUtils.getAttribute(portTypeXML, WsrmdConstants.DESCRIPTOR_ATTR_QNAME); - String rmdPath = XmlUtils.getAttribute(portTypeXML, WsrmdConstants.DESCRIPTOR_LOCATION_ATTR_QNAME); - - LOGGER.debug(Messages.QMAN_200034_RMD_NAME, rmdName); - LOGGER.debug(Messages.QMAN_200035_RMD_PATH, rmdPath); - - Environment env = getEnvironment(); - String path = env.createRelativePath(getWsdlPath(), rmdPath); - Document rmdDoc = env.getDocument(path); - - Element[] additionalProperties = ThreadSessionManager.getInstance().getSession().getResourceMetadataDescriptor(); - Element metadataDescriptor = WsrmdUtils.getMetadataDescriptor(rmdDoc, rmdName); - - for (Element element : additionalProperties) - { - rmdDoc.adoptNode(element); - metadataDescriptor.appendChild(element); - - Log.debugElement(Messages.QMAN_200036_ADDITIONAL_RMD_PROPERTY,element); - } - - return new SimpleMetadataDescriptor(metadataDescriptor); - } - catch(Exception exception) - { - LOGGER.error(exception,Messages.QMAN_100021_RMD_BUID_FAILURE,getContextPath()); - throw new SoapFault(exception); - } - } - - /** - * Creates a WSRP document representing schema properties for this resource. - * - * @param wsdl the DOM document holding the resource's WSDL. - * @return the WSRP document schema. - */ - protected ResourcePropertiesSchema createPropertiesSchema(Document wsdl) - { - QName wsrpName = WsrpUtils.getPropertiesName(wsdl, getWsdlPortType()); - Element wsrpDoc = WsdlUtils.getElementDeclaration(wsdl, wsrpName); - return new SimpleResourcePropertiesSchema(wsrpName, wsrpDoc); - } - /** * Returns the collection containing all properties of this resource. * @@ -359,55 +484,16 @@ public class QManWsResource implements WsResource /** * Initializes this resources. + * Note that the what needs to be done depends on the current state of this + * resource. * * @throws SoapFault when the initialization fails. */ public void initialize() throws SoapFault { - _properties = new SimpleResourcePropertyCollection(); - _wsdl = ThreadSessionManager.getInstance().getSession().getWsdlDocument(); - - ResourcePropertiesSchema schema = createPropertiesSchema(_wsdl); - _properties.setSchema(schema); - - MetadataDescriptor metadata = createMetadataDescriptor(_wsdl); - _properties.setMetadata(metadata); - - initializeCapabilities(); - - _hasBeenInitialized = true; - - _properties.applyMetadata(); - - if (Boolean.parseBoolean(getInitializationParameter(Names.VALIDATE_WSRP_PARAM))) - { - _properties.validateSchema(); - } - - _properties.validateMetadata(); + _currentState.initialize(); } - - /** - * Initializes capabilities of this resource. - * - * @throws SoapFault when at least one capability fails to initialize. - */ - public void initializeCapabilities() throws SoapFault - { - for (Entry entry : _capabilitiesByURI.entrySet()) - { - Capability capability = entry.getValue(); - capability.initialize(); - - for (Object action : capability.getActions()) - { - _capabilitiesByAction.put((String)action, capability); - } - - capability.initializeCompleted(); - } - } - + /** * Invokes the action specified in the given soap request on this resource. * @@ -422,7 +508,10 @@ public class QManWsResource implements WsResource // Sanity check : is there a capability for the given action? if (capability == null) { - SoapFault wsaFault = new SoapFault(String.format(Messages.ACTION_NOT_SUPPORTED, action,getContextPath())); + SoapFault wsaFault = new SoapFault( + String.format( + Messages.ACTION_NOT_SUPPORTED, + action,getContextPath())); wsaFault.setCode(SoapConstants.SENDER_QNAME); wsaFault.setSubCode(WsaConstants.ACTION_NOT_SUPPORTED_FAULT_QNAME); @@ -431,7 +520,10 @@ public class QManWsResource implements WsResource XmlUtils.setElement(detail, WsaConstants.ACTION_QNAME, action); wsaFault.setDetail(detail); - LOGGER.error(Messages.QMAN_100020_ACTION_NOT_SUPPORTED, action,getContextPath()); + LOGGER.error( + Messages.QMAN_100020_ACTION_NOT_SUPPORTED, + action, + getContextPath()); return wsaFault.toXML(); } @@ -545,23 +637,39 @@ public class QManWsResource implements WsResource */ public synchronized void shutdown() throws SoapFault { - if (hasBeenShutdown()) - throw new SoapFault(("ResourceAlreadyDestroyed")); - - if (!hasBeenInitialized()) - throw new SoapFault(("ResourceNotInitialized")); - - _hasBeenShutdown = true; + _currentState.shutdown(); + } - shutdownCapabilities(); - - ResourceManager manager = getResourceManager(); - - // - // remove resource visibility - // - if (manager.getResource(_enpointReference) != null) - manager.removeResource(_enpointReference); + /** + * Returns a string representation of this resource. + * Basically the resource endpoint reference (as a string) is returned. + * + * @return the resource endpoint reference (as a string) is returned. + */ + public String toString() + { + return getEndpointReference().toString(); + } + + /** + * Initializes capabilities of this resource. + * + * @throws SoapFault when at least one capability fails to initialize. + */ + private void initializeCapabilities() throws SoapFault + { + for (Entry entry : _capabilitiesByURI.entrySet()) + { + Capability capability = entry.getValue(); + capability.initialize(); + + for (Object action : capability.getActions()) + { + _capabilitiesByAction.put((String)action, capability); + } + + capability.initializeCompleted(); + } } /** @@ -569,7 +677,7 @@ public class QManWsResource implements WsResource * * @throws SoapFault when at least one capability shutdown fails. */ - protected void shutdownCapabilities() throws SoapFault + private void shutdownCapabilities() throws SoapFault { for (Entry entry : _capabilitiesByURI.entrySet()) { @@ -577,16 +685,80 @@ public class QManWsResource implements WsResource capabilty.prepareShutdown(); capabilty.shutdown(); } - } + } /** - * Returns a string representation of this resource. - * Basically the resource endpoint reference (as a string) is returned. + * Creates a metadata descriptor for this resource. * - * @return the resource endpoint reference (as a string) is returned. + * @param wsdl the WSDL document. + * @return a metadata descriptor for this resource. + * @throws SoapFault when it's not possible build the descriptor. */ - public String toString() + private MetadataDescriptor createMetadataDescriptor(Document wsdl) throws SoapFault { - return getEndpointReference().toString(); - } + try + { + Element portTypeXML = WsdlUtils.getPortType(wsdl, getWsdlPortType()); + + String rmdName = XmlUtils.getAttribute( + portTypeXML, + WsrmdConstants.DESCRIPTOR_ATTR_QNAME); + + String rmdPath = XmlUtils.getAttribute( + portTypeXML, + WsrmdConstants.DESCRIPTOR_LOCATION_ATTR_QNAME); + + LOGGER.debug(Messages.QMAN_200034_RMD_NAME, rmdName); + LOGGER.debug(Messages.QMAN_200035_RMD_PATH, rmdPath); + + Environment env = getEnvironment(); + String path = env.createRelativePath(getWsdlPath(), rmdPath); + Document rmdDoc = env.getDocument(path); + + Element[] additionalProperties = + ThreadSessionManager + .getInstance() + .getSession() + .getResourceMetadataDescriptor(); + + Element metadataDescriptor = WsrmdUtils.getMetadataDescriptor(rmdDoc, rmdName); + + for (Element element : additionalProperties) + { + rmdDoc.adoptNode(element); + metadataDescriptor.appendChild(element); + } + + return new SimpleMetadataDescriptor(metadataDescriptor); + } + catch(Exception exception) + { + LOGGER.error(exception,Messages.QMAN_100021_RMD_BUID_FAILURE,getContextPath()); + throw new SoapFault(exception); + } + } + + /** + * Returns the capability associated with the given action. + * + * @param action the wsa:action of the requested capability. + * @return the capability associated with the given action. + */ + private Capability getCapabilityForAction(String action) + { + return (Capability)_capabilitiesByAction.get(action); + } + + /** + * Creates a WSRP document representing schema properties for this resource. + * + * @param wsdl the DOM document holding the resource's WSDL. + * @return the WSRP document schema. + */ + private ResourcePropertiesSchema createPropertiesSchema(Document wsdl) + { + QName wsrpName = WsrpUtils.getPropertiesName(wsdl, getWsdlPortType()); + Element wsrpDoc = WsdlUtils.getElementDeclaration(wsdl, wsrpName); + return new SimpleResourcePropertiesSchema(wsrpName, wsrpDoc); + } } \ No newline at end of file -- cgit v1.2.1