Author: alessio.soldano(a)jboss.com
Date: 2012-06-08 09:36:40 -0400 (Fri, 08 Jun 2012)
New Revision: 16404
Added:
shared-testsuite/trunk/testsuite/src/test/java/org/jboss/test/ws/jaxws/clientConfig/TestUtils.java
Modified:
shared-testsuite/trunk/testsuite/src/test/ant-import/build-jars-jaxws.xml
shared-testsuite/trunk/testsuite/src/test/java/org/jboss/test/ws/jaxws/clientConfig/Helper.java
Log:
[JBWS-3335] Synch with latest jbossws-api + modify testcase to show how to only leverage
jbossws-api for client configuration setup
Modified: shared-testsuite/trunk/testsuite/src/test/ant-import/build-jars-jaxws.xml
===================================================================
--- shared-testsuite/trunk/testsuite/src/test/ant-import/build-jars-jaxws.xml 2012-06-08
13:34:27 UTC (rev 16403)
+++ shared-testsuite/trunk/testsuite/src/test/ant-import/build-jars-jaxws.xml 2012-06-08
13:36:40 UTC (rev 16404)
@@ -125,15 +125,13 @@
<include name="org/jboss/test/ws/jaxws/clientConfig/Endpoint.class"
/>
<include name="org/jboss/test/ws/jaxws/clientConfig/*Handler.class"
/>
<include name="org/jboss/test/ws/jaxws/clientConfig/Helper.class" />
+ <include name="org/jboss/test/ws/jaxws/clientConfig/TestUtils.class"
/>
<include name="org/jboss/test/helper/TestServlet.class"/>
<include name="org/jboss/test/helper/ClientHelper.class"/>
</classes>
<classes dir="${tests.output.dir}/test-resources/jaxws/clientConfig">
<include name="META-INF/jaxws-client-config.xml"/>
</classes>
- <manifest>
- <attribute name="Dependencies"
value="org.jboss.ws.common services"/>
- </manifest>
</war>
<!-- jaxws-clientConfig-client -->
Modified:
shared-testsuite/trunk/testsuite/src/test/java/org/jboss/test/ws/jaxws/clientConfig/Helper.java
===================================================================
---
shared-testsuite/trunk/testsuite/src/test/java/org/jboss/test/ws/jaxws/clientConfig/Helper.java 2012-06-08
13:34:27 UTC (rev 16403)
+++
shared-testsuite/trunk/testsuite/src/test/java/org/jboss/test/ws/jaxws/clientConfig/Helper.java 2012-06-08
13:36:40 UTC (rev 16404)
@@ -22,10 +22,7 @@
package org.jboss.test.ws.jaxws.clientConfig;
import java.net.URL;
-import java.util.Iterator;
-import java.util.LinkedList;
import java.util.List;
-import java.util.ServiceLoader;
import javax.xml.namespace.QName;
import javax.xml.ws.BindingProvider;
@@ -33,15 +30,8 @@
import javax.xml.ws.handler.Handler;
import org.jboss.test.helper.ClientHelper;
+import org.jboss.ws.api.configuration.ClientConfigUtil;
import org.jboss.ws.api.configuration.ClientConfigurer;
-import org.jboss.wsf.spi.SPIProvider;
-import org.jboss.wsf.spi.SPIProviderResolver;
-import org.jboss.wsf.spi.classloading.ClassLoaderProvider;
-import org.jboss.wsf.spi.management.ServerConfig;
-import org.jboss.wsf.spi.management.ServerConfigFactory;
-import org.jboss.wsf.spi.metadata.config.ClientConfig;
-import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedHandlerChainMetaData;
-import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedHandlerMetaData;
/**
* Verifies client configuration setup
@@ -55,11 +45,7 @@
public boolean testClientConfigurer()
{
- Iterator<ClientConfigurer> it =
ServiceLoader.load(ClientConfigurer.class).iterator();
- if (!it.hasNext()) {
- return false;
- }
- ClientConfigurer configurer = it.next();
+ ClientConfigurer configurer = ClientConfigUtil.resolveClientConfigurer();
if (configurer == null) {
return false;
}
@@ -80,8 +66,7 @@
hc.add(new UserHandler());
bp.getBinding().setHandlerChain(hc);
- ClientConfigurer configurer =
ServiceLoader.load(ClientConfigurer.class).iterator().next();
- configurer.addConfigHandlers(bp, "META-INF/jaxws-client-config.xml",
"Custom Client Config");
+ ClientConfigUtil.setConfigHandlers(bp,
"META-INF/jaxws-client-config.xml", "Custom Client Config");
String resStr = port.echo("Kermit");
return
("Kermit|RoutOut|CustomOut|UserOut|LogOut|endpoint|LogIn|UserIn|CustomIn|RoutIn".equals(resStr));
@@ -101,15 +86,15 @@
hc.add(new UserHandler());
bp.getBinding().setHandlerChain(hc);
- ClientConfigurer configurer =
ServiceLoader.load(ClientConfigurer.class).iterator().next();
- configurer.addConfigHandlers(bp, "META-INF/jaxws-client-config.xml",
"Custom Client Config");
+ ClientConfigurer configurer = ClientConfigUtil.resolveClientConfigurer();
+ configurer.setConfigHandlers(bp, "META-INF/jaxws-client-config.xml",
"Custom Client Config");
String resStr = port.echo("Kermit");
if
(!"Kermit|RoutOut|CustomOut|UserOut|LogOut|endpoint|LogIn|UserIn|CustomIn|RoutIn".equals(resStr))
{
return false;
}
- configurer.addConfigHandlers(bp, "META-INF/jaxws-client-config.xml",
"Another Client Config");
+ configurer.setConfigHandlers(bp, "META-INF/jaxws-client-config.xml",
"Another Client Config");
resStr = port.echo("Kermit");
return ("Kermit|RoutOut|UserOut|endpoint|UserIn|RoutIn".equals(resStr));
@@ -128,13 +113,10 @@
QName serviceName = new
QName("http://clientConfig.jaxws.ws.test.jboss.org/",
"EndpointImplService");
URL wsdlURL = new URL(address + "?wsdl");
- ServerConfig sc = getServerConfig();
- ClientConfig defaultConfig = getAndVerifyDefaultClientConfiguration(sc);
-
+ // -- modify default conf --
try
{
- // -- modify default conf --
- modifyDefaultClientConfiguration(defaultConfig);
+
TestUtils.modifyDefaultClientConfiguration(TestUtils.getAndVerifyDefaultClientConfiguration());
// --
Service service = Service.create(wsdlURL, serviceName);
@@ -147,14 +129,12 @@
bp.getBinding().setHandlerChain(hc);
String resStr = port.echo("Kermit");
- System.out.println("--> ** " + resStr);
return
("Kermit|UserOut|LogOut|endpoint|LogIn|UserIn".equals(resStr));
}
finally
{
// -- restore default conf --
- defaultConfig.setPostHandlerChains(null);
- defaultConfig.setPreHandlerChains(null);
+ TestUtils.cleanupClientConfig();
// --
}
}
@@ -171,12 +151,11 @@
QName serviceName = new
QName("http://clientConfig.jaxws.ws.test.jboss.org/",
"EndpointImplService");
URL wsdlURL = new URL(address + "?wsdl");
- ServerConfig sc = getServerConfig();
final String testConfigName = "MyTestConfig";
try
{
//-- add test client configuration
- addTestCaseClientConfiguration(sc, testConfigName);
+ TestUtils.addTestCaseClientConfiguration(testConfigName);
// --
Service service = Service.create(wsdlURL, serviceName);
@@ -188,8 +167,7 @@
hc.add(new UserHandler());
bp.getBinding().setHandlerChain(hc);
- ClientConfigurer configurer =
ServiceLoader.load(ClientConfigurer.class).iterator().next();
- configurer.addConfigHandlers(bp, null, testConfigName);
+ ClientConfigUtil.setConfigHandlers(bp, null, testConfigName);
String resStr = port.echo("Kermit");
return
("Kermit|RoutOut|UserOut|endpoint|UserIn|RoutIn".equals(resStr));
@@ -197,72 +175,11 @@
finally
{
// -- remove test client configuration --
- removeTestCaseClientConfiguration(sc, testConfigName);
+ TestUtils.removeTestCaseClientConfiguration(testConfigName);
// --
}
}
- private ClientConfig getAndVerifyDefaultClientConfiguration(ServerConfig sc) throws
Exception {
- ClientConfig defaultConfig = null;
- for (ClientConfig c : sc.getClientConfigs()) {
- if (ClientConfig.STANDARD_CLIENT_CONFIG.equals(c.getConfigName())) {
- defaultConfig = c;
- }
- }
- if (defaultConfig == null) {
- throw new Exception("Missing AS client config '" +
ClientConfig.STANDARD_CLIENT_CONFIG + "'!");
- }
- List<UnifiedHandlerChainMetaData> preHC =
defaultConfig.getPreHandlerChains();
- List<UnifiedHandlerChainMetaData> postHC =
defaultConfig.getPostHandlerChains();
- if ((preHC != null && !preHC.isEmpty()) || (postHC != null &&
!postHC.isEmpty())) {
- throw new Exception("'" + ClientConfig.STANDARD_CLIENT_CONFIG +
"' is not empty!");
- }
- return defaultConfig;
- }
-
- private void modifyDefaultClientConfiguration(ClientConfig defaultConfig) {
- UnifiedHandlerChainMetaData uhcmd = new UnifiedHandlerChainMetaData();
- UnifiedHandlerMetaData handler = new UnifiedHandlerMetaData();
-
handler.setHandlerClass("org.jboss.test.ws.jaxws.clientConfig.LogHandler");
- handler.setHandlerName("Log Handler");
- uhcmd.addHandler(handler);
- List<UnifiedHandlerChainMetaData> postHC = new
LinkedList<UnifiedHandlerChainMetaData>();
- postHC.add(uhcmd);
- defaultConfig.setPostHandlerChains(postHC);
- }
-
- private void addTestCaseClientConfiguration(ServerConfig sc, String testConfigName) {
- UnifiedHandlerChainMetaData uhcmd = new UnifiedHandlerChainMetaData();
- UnifiedHandlerMetaData handler = new UnifiedHandlerMetaData();
-
handler.setHandlerClass("org.jboss.test.ws.jaxws.clientConfig.RoutingHandler");
- handler.setHandlerName("Routing Handler");
- uhcmd.addHandler(handler);
- ClientConfig config = new ClientConfig();
- config.setConfigName(testConfigName);
- List<UnifiedHandlerChainMetaData> preHC = new
LinkedList<UnifiedHandlerChainMetaData>();
- preHC.add(uhcmd);
- config.setPreHandlerChains(preHC);
- sc.addClientConfig(config);
- }
-
- private void removeTestCaseClientConfiguration(ServerConfig sc, String testConfigName)
{
- Iterator<ClientConfig> it = sc.getClientConfigs().iterator();
- while (it.hasNext()) {
- ClientConfig c = it.next();
- if (testConfigName.equals(c.getConfigName())) {
- it.remove();
- break;
- }
- }
- }
-
- private ServerConfig getServerConfig()
- {
- final ClassLoader cl =
ClassLoaderProvider.getDefaultProvider().getServerIntegrationClassLoader();
- SPIProvider spiProvider = SPIProviderResolver.getInstance(cl).getProvider();
- return spiProvider.getSPI(ServerConfigFactory.class, cl).getServerConfig();
- }
-
@Override
public void setTargetEndpoint(String address)
{
Added:
shared-testsuite/trunk/testsuite/src/test/java/org/jboss/test/ws/jaxws/clientConfig/TestUtils.java
===================================================================
---
shared-testsuite/trunk/testsuite/src/test/java/org/jboss/test/ws/jaxws/clientConfig/TestUtils.java
(rev 0)
+++
shared-testsuite/trunk/testsuite/src/test/java/org/jboss/test/ws/jaxws/clientConfig/TestUtils.java 2012-06-08
13:36:40 UTC (rev 16404)
@@ -0,0 +1,128 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2012, 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.test.ws.jaxws.clientConfig;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.jboss.wsf.spi.SPIProvider;
+import org.jboss.wsf.spi.SPIProviderResolver;
+import org.jboss.wsf.spi.classloading.ClassLoaderProvider;
+import org.jboss.wsf.spi.management.ServerConfig;
+import org.jboss.wsf.spi.management.ServerConfigFactory;
+import org.jboss.wsf.spi.metadata.config.ClientConfig;
+import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedHandlerChainMetaData;
+import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedHandlerMetaData;
+
+/**
+ * Support utils for client config testcase; this basically collects methods
+ * for test purposes only to allow having a clean testcase without dependencies
+ * the user is not actually going to need.
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 08-Jun-2012
+ */
+public class TestUtils
+{
+ public static ClientConfig getAndVerifyDefaultClientConfiguration() throws Exception
{
+ ServerConfig sc = getServerConfig();
+ ClientConfig defaultConfig = null;
+ for (ClientConfig c : sc.getClientConfigs()) {
+ if (ClientConfig.STANDARD_CLIENT_CONFIG.equals(c.getConfigName())) {
+ defaultConfig = c;
+ }
+ }
+ if (defaultConfig == null) {
+ throw new Exception("Missing AS client config '" +
ClientConfig.STANDARD_CLIENT_CONFIG + "'!");
+ }
+ List<UnifiedHandlerChainMetaData> preHC =
defaultConfig.getPreHandlerChains();
+ List<UnifiedHandlerChainMetaData> postHC =
defaultConfig.getPostHandlerChains();
+ if ((preHC != null && !preHC.isEmpty()) || (postHC != null &&
!postHC.isEmpty())) {
+ throw new Exception("'" + ClientConfig.STANDARD_CLIENT_CONFIG +
"' is not empty!");
+ }
+ return defaultConfig;
+ }
+
+ public static void modifyDefaultClientConfiguration(ClientConfig defaultConfig) {
+ UnifiedHandlerChainMetaData uhcmd = new UnifiedHandlerChainMetaData();
+ UnifiedHandlerMetaData handler = new UnifiedHandlerMetaData();
+
handler.setHandlerClass("org.jboss.test.ws.jaxws.clientConfig.LogHandler");
+ handler.setHandlerName("Log Handler");
+ uhcmd.addHandler(handler);
+ List<UnifiedHandlerChainMetaData> postHC = new
LinkedList<UnifiedHandlerChainMetaData>();
+ postHC.add(uhcmd);
+ defaultConfig.setPostHandlerChains(postHC);
+ }
+
+ public static void cleanupClientConfig() throws Exception {
+ ServerConfig sc = getServerConfig();
+ ClientConfig defaultConfig = null;
+ for (ClientConfig c : sc.getClientConfigs()) {
+ if (ClientConfig.STANDARD_CLIENT_CONFIG.equals(c.getConfigName())) {
+ defaultConfig = c;
+ }
+ }
+ if (defaultConfig == null) {
+ throw new Exception("Missing AS client config '" +
ClientConfig.STANDARD_CLIENT_CONFIG + "'!");
+ }
+ List<UnifiedHandlerChainMetaData> preHC =
defaultConfig.getPreHandlerChains();
+ List<UnifiedHandlerChainMetaData> postHC =
defaultConfig.getPostHandlerChains();
+ if ((preHC == null || preHC.isEmpty()) && (postHC == null ||
postHC.isEmpty())) {
+ throw new Exception("'" + ClientConfig.STANDARD_CLIENT_CONFIG +
"' is already empty!");
+ }
+ defaultConfig.setPostHandlerChains(null);
+ defaultConfig.setPreHandlerChains(null);
+ }
+
+ public static void addTestCaseClientConfiguration(String testConfigName) {
+ UnifiedHandlerChainMetaData uhcmd = new UnifiedHandlerChainMetaData();
+ UnifiedHandlerMetaData handler = new UnifiedHandlerMetaData();
+
handler.setHandlerClass("org.jboss.test.ws.jaxws.clientConfig.RoutingHandler");
+ handler.setHandlerName("Routing Handler");
+ uhcmd.addHandler(handler);
+ ClientConfig config = new ClientConfig();
+ config.setConfigName(testConfigName);
+ List<UnifiedHandlerChainMetaData> preHC = new
LinkedList<UnifiedHandlerChainMetaData>();
+ preHC.add(uhcmd);
+ config.setPreHandlerChains(preHC);
+ getServerConfig().addClientConfig(config);
+ }
+
+ public static void removeTestCaseClientConfiguration(String testConfigName) {
+ Iterator<ClientConfig> it = getServerConfig().getClientConfigs().iterator();
+ while (it.hasNext()) {
+ ClientConfig c = it.next();
+ if (testConfigName.equals(c.getConfigName())) {
+ it.remove();
+ break;
+ }
+ }
+ }
+
+ private static ServerConfig getServerConfig()
+ {
+ final ClassLoader cl =
ClassLoaderProvider.getDefaultProvider().getServerIntegrationClassLoader();
+ SPIProvider spiProvider = SPIProviderResolver.getInstance(cl).getProvider();
+ return spiProvider.getSPI(ServerConfigFactory.class, cl).getServerConfig();
+ }
+}