Author: asoldano
Date: 2015-03-03 06:12:58 -0500 (Tue, 03 Mar 2015)
New Revision: 19506
Added:
common/trunk/src/main/java/org/jboss/ws/common/configuration/AbstractCommonConfigResolver.java
common/trunk/src/main/java/org/jboss/ws/common/configuration/BasicConfigResolver.java
Modified:
common/trunk/src/main/java/org/jboss/ws/common/Messages.java
common/trunk/src/main/java/org/jboss/ws/common/configuration/ConfigDelegateHandler.java
common/trunk/src/main/java/org/jboss/ws/common/deployment/AbstractDefaultEndpoint.java
common/trunk/src/test/java/org/jboss/test/ws/common/management/DefaultEndpointRegistryTestCase.java
Log:
[JBWS-3846] Providing facilities for resolving configuration for a given endpoint
Modified: common/trunk/src/main/java/org/jboss/ws/common/Messages.java
===================================================================
--- common/trunk/src/main/java/org/jboss/ws/common/Messages.java 2015-03-03 11:11:21 UTC
(rev 19505)
+++ common/trunk/src/main/java/org/jboss/ws/common/Messages.java 2015-03-03 11:12:58 UTC
(rev 19506)
@@ -37,6 +37,7 @@
import org.jboss.ws.common.injection.InjectionException;
import org.jboss.wsf.spi.WSFException;
import org.jboss.wsf.spi.deployment.EndpointState;
+import org.jboss.wsf.spi.deployment.WSFDeploymentException;
import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedServiceRefMetaData;
/**
@@ -264,4 +265,10 @@
@Message(id = 22117, value = "Invalid address provided: %s")
IllegalArgumentException invalidAddressProvided(String address);
+
+ @Message(id = 22120, value = "Could not read from config file: %s")
+ RuntimeException couldNotReadConfigFile(String file);
+
+ @Message(id = 22121, value = "Could not find endpoint config name: %s")
+ WSFDeploymentException couldNotFindEndpointConfigName(String name);
}
Added:
common/trunk/src/main/java/org/jboss/ws/common/configuration/AbstractCommonConfigResolver.java
===================================================================
---
common/trunk/src/main/java/org/jboss/ws/common/configuration/AbstractCommonConfigResolver.java
(rev 0)
+++
common/trunk/src/main/java/org/jboss/ws/common/configuration/AbstractCommonConfigResolver.java 2015-03-03
11:12:58 UTC (rev 19506)
@@ -0,0 +1,238 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2015, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ws.common.configuration;
+
+import java.io.IOException;
+import java.lang.annotation.Annotation;
+import java.net.URL;
+import java.security.AccessController;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jboss.ws.common.Messages;
+import org.jboss.ws.common.management.AbstractServerConfig;
+import org.jboss.wsf.spi.management.ServerConfig;
+import org.jboss.wsf.spi.metadata.config.ConfigMetaDataParser;
+import org.jboss.wsf.spi.metadata.config.ConfigRoot;
+import org.jboss.wsf.spi.metadata.config.EndpointConfig;
+import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedHandlerChainMetaData;
+import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedHandlerMetaData;
+
+
+/**
+ * Base class for resolving common configs
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 26-Feb-2015
+ */
+public abstract class AbstractCommonConfigResolver {
+
+ /**
+ * Returns the EndpointConfig resolved for the current endpoint
+ *
+ * @return the EndpointConfig resolved for the current endpoint
+ */
+ public EndpointConfig resolveEndpointConfig() {
+ final String endpointClassName = getEndpointClassName();
+ // 1) default values
+ //String configName =
org.jboss.wsf.spi.metadata.config.EndpointConfig.STANDARD_ENDPOINT_CONFIG;
+ String configName = endpointClassName;
+ String configFile = EndpointConfig.DEFAULT_ENDPOINT_CONFIG_FILE;
+ boolean specifiedConfig = false;
+ // 2) annotation contribution
+ if (isEndpointClassAnnotated(org.jboss.ws.api.annotation.EndpointConfig.class))
+ {
+ final String cfgName = getEndpointConfigNameFromAnnotation();
+ if (cfgName != null && !cfgName.isEmpty())
+ {
+ configName = cfgName;
+ }
+ final String cfgFile = getEndpointConfigFileFromAnnotation();
+ if (cfgFile != null && !cfgFile.isEmpty())
+ {
+ configFile = cfgFile;
+ }
+ specifiedConfig = true;
+ }
+ // 3) descriptor overrides (jboss-webservices.xml or web.xml)
+ final String epCfgNameOverride = getEndpointConfigNameOverride();
+ if (epCfgNameOverride != null && !epCfgNameOverride.isEmpty())
+ {
+ configName = epCfgNameOverride;
+ specifiedConfig = true;
+ }
+ final String epCfgFileOverride = getEndpointConfigFileOverride();
+ if (epCfgFileOverride != null && !epCfgFileOverride.isEmpty())
+ {
+ configFile = epCfgFileOverride;
+ }
+ // 4) setup of configuration
+ if (configFile != EndpointConfig.DEFAULT_ENDPOINT_CONFIG_FILE) {
+ //look for provided endpoint config file
+ try
+ {
+ ConfigRoot configRoot =
ConfigMetaDataParser.parse(getConfigFile(configFile));
+ EndpointConfig config = configRoot.getEndpointConfigByName(configName);
+ if (config == null && !specifiedConfig) {
+ config =
configRoot.getEndpointConfigByName(EndpointConfig.STANDARD_ENDPOINT_CONFIG);
+ }
+ if (config != null) {
+ return config;
+ }
+ }
+ catch (IOException e)
+ {
+ throw Messages.MESSAGES.couldNotReadConfigFile(configFile);
+ }
+ }
+ else
+ {
+ EndpointConfig config = null;
+ URL url = getDefaultConfigFile(configFile);
+ if (url != null) {
+ //the default file exists
+ try
+ {
+ ConfigRoot configRoot = ConfigMetaDataParser.parse(url);
+ config = configRoot.getEndpointConfigByName(configName);
+ if (config == null && !specifiedConfig) {
+ config =
configRoot.getEndpointConfigByName(EndpointConfig.STANDARD_ENDPOINT_CONFIG);
+ }
+ }
+ catch (IOException e)
+ {
+ throw Messages.MESSAGES.couldNotReadConfigFile(configFile);
+ }
+ }
+ if (config == null) {
+ //use endpoint configs from AS domain
+ ServerConfig sc = getServerConfig();
+ config = sc.getEndpointConfig(configName);
+ if (config == null && !specifiedConfig) {
+ config = sc.getEndpointConfig(EndpointConfig.STANDARD_ENDPOINT_CONFIG);
+ }
+ if (config == null && specifiedConfig) {
+ throw Messages.MESSAGES.couldNotFindEndpointConfigName(configName);
+ }
+ }
+ if (config != null) {
+ return config;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns a set of full qualified class names of the handlers from the specified
endpoint config
+ *
+ * @param The config to get the handler class names of
+ * @return A set of full qualified class names of the handlers from the specified
endpoint config
+ */
+ public Set<String> getAllHandlers(EndpointConfig config) {
+ Set<String> set = new HashSet<String>();
+ if (config != null) {
+ for (UnifiedHandlerChainMetaData uhcmd : config.getPreHandlerChains()) {
+ for (UnifiedHandlerMetaData uhmd : uhcmd.getHandlers()) {
+ set.add(uhmd.getHandlerClass());
+ }
+ }
+ for (UnifiedHandlerChainMetaData uhcmd : config.getPostHandlerChains()) {
+ for (UnifiedHandlerMetaData uhmd : uhcmd.getHandlers()) {
+ set.add(uhmd.getHandlerClass());
+ }
+ }
+ }
+ return set;
+ }
+
+ /**
+ * Gets the FQN of the endpoint class whose config is to be resolved by this class
+ *
+ * @return the FQN of the endpoint class
+ */
+ protected abstract String getEndpointClassName();
+
+ /**
+ * Returns true or false depending on the current endpoint class being annotated or
+ * not with the specified annotation.
+ *
+ * @param annotation The annotation to look for
+ * @return True if the endpoint is annotated with the specified
annotation,
+ * false otherwise.
+ */
+ protected abstract <T extends Annotation> boolean
isEndpointClassAnnotated(Class<T> annotation);
+
+ /**
+ * Returns the config name specified on the @EndpointConfig annotation (if any) on
+ * the current endpoint
+ *
+ * @return The config name in the @EndpointConfig annotation on the endpoint
+ */
+ protected abstract String getEndpointConfigNameFromAnnotation();
+
+ /**
+ * Returns the config file specified on the @EndpointConfig annotation (if any) on
+ * the current endpoint
+ *
+ * @return The config file in the @EndpointConfig annotation on the endpoint
+ */
+ protected abstract String getEndpointConfigFileFromAnnotation();
+
+ /**
+ * Returns the config name value coming from deployment descriptor
+ *
+ * @return The config name value from deployment descriptor
+ */
+ protected abstract String getEndpointConfigNameOverride();
+
+ /**
+ * Returns the config file value coming from deployment descriptor
+ *
+ * @return The config file value from deployment descriptor
+ */
+ protected abstract String getEndpointConfigFileOverride();
+
+ /**
+ * Returns the URL of the config file for the given name; this can either be in the
root of the deployment
+ * or at the same level of the endpoint class file (a sibling of it)
+ *
+ * @param configFileName The name of the config file to look for
+ * @return the URL of the config file or null if it's not found
+ */
+ protected abstract URL getConfigFile(String configFileName) throws IOException;
+
+ /**
+ * Returns the URL of the specified default config file; this can either be in the
root of the deployment
+ * or at the same level of the endpoint class file (a sibling of it)
+ *
+ * @param defaultConfigFileName The name of the config file to look for
+ * @return the URL of the config file or null if it's
not found
+ */
+ protected abstract URL getDefaultConfigFile(String defaultConfigFileName);
+
+ protected ServerConfig getServerConfig() {
+ if(System.getSecurityManager() == null) {
+ return AbstractServerConfig.getServerIntegrationServerConfig();
+ }
+ return
AccessController.doPrivileged(AbstractServerConfig.GET_SERVER_INTEGRATION_SERVER_CONFIG);
+ }
+}
Property changes on:
common/trunk/src/main/java/org/jboss/ws/common/configuration/AbstractCommonConfigResolver.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date
Added: svn:eol-style
+ native
Added:
common/trunk/src/main/java/org/jboss/ws/common/configuration/BasicConfigResolver.java
===================================================================
--- common/trunk/src/main/java/org/jboss/ws/common/configuration/BasicConfigResolver.java
(rev 0)
+++
common/trunk/src/main/java/org/jboss/ws/common/configuration/BasicConfigResolver.java 2015-03-03
11:12:58 UTC (rev 19506)
@@ -0,0 +1,125 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2015, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ws.common.configuration;
+
+import java.io.IOException;
+import java.lang.annotation.Annotation;
+import java.net.URL;
+
+import org.jboss.ws.api.annotation.EndpointConfig;
+import org.jboss.wsf.spi.deployment.ArchiveDeployment;
+import org.jboss.wsf.spi.deployment.UnifiedVirtualFile;
+import org.jboss.wsf.spi.metadata.j2ee.JSEArchiveMetaData;
+import org.jboss.wsf.spi.metadata.webservices.JBossWebservicesMetaData;
+
+/**
+ * A config resolver that operates on a JBossWS deployment
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 03-Mar-2015
+ */
+public class BasicConfigResolver extends AbstractCommonConfigResolver
+{
+ private final UnifiedVirtualFile deploymentRoot;
+ private final Class<?> implementorClass;
+ private final String configNameOverride;
+ private final String configFileOverride;
+ private final EndpointConfig ann;
+
+ public BasicConfigResolver(ArchiveDeployment dep, Class<?> implementorClass) {
+ String epConfigName = null;
+ String epConfigFile = null;
+ JSEArchiveMetaData jsemd = dep.getAttachment(JSEArchiveMetaData.class);
+ JBossWebservicesMetaData wsmd = dep.getAttachment(JBossWebservicesMetaData.class);
+ //first check JSEArchiveMetaData as that has the actual merged value for POJO
deployments
+ if (jsemd != null) {
+ epConfigName = jsemd.getConfigName();
+ epConfigFile = jsemd.getConfigFile();
+ } else if (wsmd != null) {
+ epConfigName = wsmd.getConfigName();
+ epConfigFile = wsmd.getConfigFile();
+ }
+ this.configNameOverride = epConfigName;
+ this.configFileOverride = epConfigFile;
+ this.implementorClass = implementorClass;
+ this.deploymentRoot = dep.getRootFile();
+ this.ann = implementorClass.getAnnotation(EndpointConfig.class);
+ }
+
+ @Override
+ protected URL getDefaultConfigFile(String defaultConfigFileName)
+ {
+ URL url = implementorClass.getResource("/" + defaultConfigFileName);
+ if (url == null)
+ {
+ UnifiedVirtualFile vf =
deploymentRoot.findChildFailSafe(defaultConfigFileName);
+ if (vf != null)
+ {
+ url = vf.toURL();
+ }
+ }
+ return url;
+ }
+
+ @Override
+ protected URL getConfigFile(String configFileName) throws IOException
+ {
+ UnifiedVirtualFile vf = deploymentRoot.findChild(configFileName);
+ return vf.toURL();
+ }
+
+ @Override
+ protected String getEndpointClassName()
+ {
+ return implementorClass.getName();
+ }
+
+ @Override
+ protected <T extends Annotation> boolean isEndpointClassAnnotated(Class<T>
annotation)
+ {
+ return ann != null;
+ }
+
+ @Override
+ protected String getEndpointConfigNameFromAnnotation()
+ {
+ return ann.configName();
+ }
+
+ @Override
+ protected String getEndpointConfigFileFromAnnotation()
+ {
+ return ann.configFile();
+ }
+
+ @Override
+ protected String getEndpointConfigNameOverride()
+ {
+ return configNameOverride;
+ }
+
+ @Override
+ protected String getEndpointConfigFileOverride()
+ {
+ return configFileOverride;
+ }
+}
Property changes on:
common/trunk/src/main/java/org/jboss/ws/common/configuration/BasicConfigResolver.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date
Added: svn:eol-style
+ native
Modified:
common/trunk/src/main/java/org/jboss/ws/common/configuration/ConfigDelegateHandler.java
===================================================================
---
common/trunk/src/main/java/org/jboss/ws/common/configuration/ConfigDelegateHandler.java 2015-03-03
11:11:21 UTC (rev 19505)
+++
common/trunk/src/main/java/org/jboss/ws/common/configuration/ConfigDelegateHandler.java 2015-03-03
11:12:58 UTC (rev 19506)
@@ -64,4 +64,9 @@
{
return isPre;
}
+
+ public Handler<T> getDelegate()
+ {
+ return delegate;
+ }
}
Modified:
common/trunk/src/main/java/org/jboss/ws/common/deployment/AbstractDefaultEndpoint.java
===================================================================
---
common/trunk/src/main/java/org/jboss/ws/common/deployment/AbstractDefaultEndpoint.java 2015-03-03
11:11:21 UTC (rev 19505)
+++
common/trunk/src/main/java/org/jboss/ws/common/deployment/AbstractDefaultEndpoint.java 2015-03-03
11:12:58 UTC (rev 19506)
@@ -44,6 +44,7 @@
import org.jboss.wsf.spi.invocation.InvocationHandler;
import org.jboss.wsf.spi.invocation.RequestHandler;
import org.jboss.wsf.spi.management.EndpointMetrics;
+import org.jboss.wsf.spi.metadata.config.EndpointConfig;
import org.jboss.wsf.spi.security.SecurityDomainContext;
/**
@@ -70,6 +71,7 @@
protected volatile List<RecordProcessor> recordProcessors = new
CopyOnWriteArrayList<RecordProcessor>();
protected volatile SecurityDomainContext securityDomainContext;
protected volatile InstanceProvider instanceProvider;
+ protected volatile EndpointConfig endpointConfig;
AbstractDefaultEndpoint(String targetBean)
{
@@ -318,4 +320,14 @@
this.instanceProvider = instanceProvider;
}
+ public void setEndpointConfig(final EndpointConfig endpointConfig)
+ {
+ assertEndpointSetterAccess();
+ this.endpointConfig = endpointConfig;
+ }
+
+ public EndpointConfig getEndpointConfig()
+ {
+ return endpointConfig;
+ }
}
Modified:
common/trunk/src/test/java/org/jboss/test/ws/common/management/DefaultEndpointRegistryTestCase.java
===================================================================
---
common/trunk/src/test/java/org/jboss/test/ws/common/management/DefaultEndpointRegistryTestCase.java 2015-03-03
11:11:21 UTC (rev 19505)
+++
common/trunk/src/test/java/org/jboss/test/ws/common/management/DefaultEndpointRegistryTestCase.java 2015-03-03
11:12:58 UTC (rev 19506)
@@ -48,6 +48,7 @@
import org.jboss.wsf.spi.invocation.RequestHandler;
import org.jboss.wsf.spi.management.EndpointMetrics;
import org.jboss.wsf.spi.management.EndpointRegistry;
+import org.jboss.wsf.spi.metadata.config.EndpointConfig;
import org.jboss.wsf.spi.security.SecurityDomainContext;
import junit.framework.TestCase;
@@ -403,6 +404,19 @@
{
return null;
}
+
+ @Override
+ public EndpointConfig getEndpointConfig()
+ {
+ return null;
+ }
+
+ @Override
+ public void setEndpointConfig(EndpointConfig config)
+ {
+ // TODO Auto-generated method stub
+
+ }
};
}
}