Author: alessio.soldano(a)jboss.com
Date: 2012-06-07 12:58:49 -0400 (Thu, 07 Jun 2012)
New Revision: 16395
Added:
common/trunk/src/main/java/org/jboss/ws/common/configuration/ConfigDelegateHandler.java
common/trunk/src/main/java/org/jboss/ws/common/configuration/ConfigDelegateHandlerComparator.java
common/trunk/src/main/java/org/jboss/ws/common/configuration/LogicalConfigDelegateHandler.java
common/trunk/src/test/java/org/jboss/test/ws/common/configuration/
common/trunk/src/test/java/org/jboss/test/ws/common/configuration/ConfigDelegateHandlerComparatorTestCase.java
Modified:
common/trunk/src/main/java/org/jboss/ws/common/configuration/ConfigHelper.java
common/trunk/src/main/java/org/jboss/ws/common/configuration/Message.properties
Log:
[JBWS-3335] Adding ConfigDelegateHandler and a specific comparator to allow PRE/POST
handlers' sorting
Added:
common/trunk/src/main/java/org/jboss/ws/common/configuration/ConfigDelegateHandler.java
===================================================================
---
common/trunk/src/main/java/org/jboss/ws/common/configuration/ConfigDelegateHandler.java
(rev 0)
+++
common/trunk/src/main/java/org/jboss/ws/common/configuration/ConfigDelegateHandler.java 2012-06-07
16:58:49 UTC (rev 16395)
@@ -0,0 +1,67 @@
+/*
+ * 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.ws.common.configuration;
+
+import javax.xml.ws.handler.Handler;
+import javax.xml.ws.handler.MessageContext;
+
+
+/**
+ * JBossWS client / endpoint configuration-contributed handler
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 06-Jun-2012
+ *
+ */
+public class ConfigDelegateHandler<T extends MessageContext> implements
Handler<T>
+{
+ protected final Handler<T> delegate;
+ private final boolean isPre;
+
+ public ConfigDelegateHandler(Handler<T> delegate, boolean isPre) {
+ this.delegate = delegate;
+ this.isPre = isPre;
+ }
+
+ @Override
+ public boolean handleMessage(T context)
+ {
+ return delegate.handleMessage(context);
+ }
+
+ @Override
+ public boolean handleFault(T context)
+ {
+ return handleFault(context);
+ }
+
+ @Override
+ public void close(MessageContext context)
+ {
+ delegate.close(context);
+ }
+
+ public boolean isPre()
+ {
+ return isPre;
+ }
+}
Added:
common/trunk/src/main/java/org/jboss/ws/common/configuration/ConfigDelegateHandlerComparator.java
===================================================================
---
common/trunk/src/main/java/org/jboss/ws/common/configuration/ConfigDelegateHandlerComparator.java
(rev 0)
+++
common/trunk/src/main/java/org/jboss/ws/common/configuration/ConfigDelegateHandlerComparator.java 2012-06-07
16:58:49 UTC (rev 16395)
@@ -0,0 +1,53 @@
+/*
+ * 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.ws.common.configuration;
+
+import java.util.Comparator;
+
+import javax.xml.ws.handler.Handler;
+
+/**
+ * A Handler comparator properly dealing with PRE/POST ConfigDelegateHandler instances
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 06-Jun-2012
+ *
+ */
+@SuppressWarnings("rawtypes")
+public final class ConfigDelegateHandlerComparator<T extends Handler> implements
Comparator<T>
+{
+ @Override
+ public int compare(Handler o1, Handler o2)
+ {
+ int i1 = 0;
+ int i2 = 0;
+ if (o1 instanceof ConfigDelegateHandler)
+ {
+ i1 = ((ConfigDelegateHandler) o1).isPre() ? -1 : 1;
+ }
+ if (o2 instanceof ConfigDelegateHandler)
+ {
+ i2 = ((ConfigDelegateHandler) o2).isPre() ? -1 : 1;
+ }
+ return i1 - i2;
+ }
+}
\ No newline at end of file
Modified: common/trunk/src/main/java/org/jboss/ws/common/configuration/ConfigHelper.java
===================================================================
---
common/trunk/src/main/java/org/jboss/ws/common/configuration/ConfigHelper.java 2012-06-07
16:31:49 UTC (rev 16394)
+++
common/trunk/src/main/java/org/jboss/ws/common/configuration/ConfigHelper.java 2012-06-07
16:58:49 UTC (rev 16395)
@@ -33,6 +33,7 @@
import javax.xml.ws.Binding;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.handler.Handler;
+import javax.xml.ws.handler.LogicalHandler;
import javax.xml.ws.http.HTTPBinding;
import javax.xml.ws.soap.SOAPBinding;
@@ -40,7 +41,11 @@
import org.jboss.ws.api.configuration.ClientConfigurer;
import org.jboss.ws.api.util.BundleUtils;
import org.jboss.ws.common.utils.DelegateClassLoader;
+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.config.CommonConfig;
import org.jboss.wsf.spi.metadata.config.ConfigMetaDataParser;
@@ -76,24 +81,37 @@
}
private static ClientConfig readConfig(String configFile, String configName) {
- InputStream is = null;
- try
- {
- is = SecurityActions.getContextClassLoader().getResourceAsStream(configFile);
- ConfigRoot config = ConfigMetaDataParser.parse(is);
- return config.getClientConfigByName(configName);
- }
- catch (Exception e)
- {
- throw new RuntimeException(BundleUtils.getMessage(bundle,
"COULD_NOT_READ_CONFIG", configFile));
- }
- finally
- {
- if (is != null) {
- try {
- is.close();
- } catch (IOException e) { } //ignore
+ if (configFile != null) {
+ InputStream is = null;
+ try
+ {
+ is =
SecurityActions.getContextClassLoader().getResourceAsStream(configFile);
+ ConfigRoot config = ConfigMetaDataParser.parse(is);
+ return config.getClientConfigByName(configName);
}
+ catch (Exception e)
+ {
+ throw new RuntimeException(BundleUtils.getMessage(bundle,
"COULD_NOT_READ_CONFIG", configFile));
+ }
+ finally
+ {
+ if (is != null) {
+ try {
+ is.close();
+ } catch (IOException e) { } //ignore
+ }
+ }
+ } else {
+ ServerConfig sc = getServerConfig();
+ if (sc != null) {
+ for (ClientConfig config : sc.getClientConfigs()) {
+ if (config.getConfigName().equals(configName))
+ {
+ return config;
+ }
+ }
+ }
+ throw new RuntimeException(BundleUtils.getMessage(bundle,
"CONFIG_NOT_FOUND", configName));
}
}
@@ -107,15 +125,15 @@
public void setupConfigHandlers(Binding binding, CommonConfig config)
{
if (config != null) {
- List<Handler> handlers = convertToHandlers(config.getPreHandlerChains(),
binding); //PRE
+ List<Handler> handlers = convertToHandlers(config.getPreHandlerChains(),
binding, true); //PRE
handlers.addAll(binding.getHandlerChain()); //ENDPOINT
- handlers.addAll(convertToHandlers(config.getPostHandlerChains(), binding));
//POST
+ handlers.addAll(convertToHandlers(config.getPostHandlerChains(), binding,
false)); //POST
binding.setHandlerChain(handlers);
}
}
- @SuppressWarnings("rawtypes")
- private static List<Handler>
convertToHandlers(List<UnifiedHandlerChainMetaData> handlerChains, Binding binding)
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ private static List<Handler>
convertToHandlers(List<UnifiedHandlerChainMetaData> handlerChains, Binding binding,
boolean isPre)
{
List<Handler> handlers = new LinkedList<Handler>();
if (handlerChains != null && !handlerChains.isEmpty())
@@ -139,7 +157,14 @@
{
if (h instanceof Handler)
{
- handlers.add((Handler)h);
+ if (h instanceof LogicalHandler)
+ {
+ handlers.add(new
LogicalConfigDelegateHandler((LogicalHandler)h, isPre));
+ }
+ else
+ {
+ handlers.add(new ConfigDelegateHandler((Handler)h, isPre));
+ }
}
else
{
@@ -181,4 +206,12 @@
return null;
}
}
+
+ private static ServerConfig getServerConfig()
+ {
+ final ClassLoader cl =
ClassLoaderProvider.getDefaultProvider().getServerIntegrationClassLoader();
+ SPIProvider spiProvider = SPIProviderResolver.getInstance(cl).getProvider();
+ ServerConfigFactory scf = spiProvider.getSPI(ServerConfigFactory.class, cl);
+ return scf != null ? scf.getServerConfig() : null;
+ }
}
Added:
common/trunk/src/main/java/org/jboss/ws/common/configuration/LogicalConfigDelegateHandler.java
===================================================================
---
common/trunk/src/main/java/org/jboss/ws/common/configuration/LogicalConfigDelegateHandler.java
(rev 0)
+++
common/trunk/src/main/java/org/jboss/ws/common/configuration/LogicalConfigDelegateHandler.java 2012-06-07
16:58:49 UTC (rev 16395)
@@ -0,0 +1,40 @@
+/*
+ * 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.ws.common.configuration;
+
+import javax.xml.ws.handler.LogicalHandler;
+import javax.xml.ws.handler.LogicalMessageContext;
+
+
+/**
+ * JBossWS client / endpoint configuration-contributed logical handler
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 06-Jun-2012
+ *
+ */
+public class LogicalConfigDelegateHandler<T extends LogicalMessageContext> extends
ConfigDelegateHandler<T> implements LogicalHandler<T>
+{
+ public LogicalConfigDelegateHandler(LogicalHandler<T> delegate, boolean isPre)
{
+ super(delegate, isPre);
+ }
+}
Modified: common/trunk/src/main/java/org/jboss/ws/common/configuration/Message.properties
===================================================================
---
common/trunk/src/main/java/org/jboss/ws/common/configuration/Message.properties 2012-06-07
16:31:49 UTC (rev 16394)
+++
common/trunk/src/main/java/org/jboss/ws/common/configuration/Message.properties 2012-06-07
16:58:49 UTC (rev 16395)
@@ -2,4 +2,5 @@
INIT_PARAMS_NOT_SUPPORTED=Init params not supported.
NOT_HANDLER_INSTANCE={0} is not a JAX-WS Handler instance
CAN_NOT_ADD_HANDLER=Could not add handler {0} as part of client or endpoint
configuration
-COULD_NOT_READ_CONFIG=Could not read configuration from file {0}
\ No newline at end of file
+COULD_NOT_READ_CONFIG=Could not read configuration from file {0}
+CONFIG_NOT_FOUND=Configuration {0} not found
\ No newline at end of file
Added:
common/trunk/src/test/java/org/jboss/test/ws/common/configuration/ConfigDelegateHandlerComparatorTestCase.java
===================================================================
---
common/trunk/src/test/java/org/jboss/test/ws/common/configuration/ConfigDelegateHandlerComparatorTestCase.java
(rev 0)
+++
common/trunk/src/test/java/org/jboss/test/ws/common/configuration/ConfigDelegateHandlerComparatorTestCase.java 2012-06-07
16:58:49 UTC (rev 16395)
@@ -0,0 +1,129 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.common.configuration;
+
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.xml.ws.handler.Handler;
+import javax.xml.ws.handler.MessageContext;
+
+import junit.framework.TestCase;
+
+import org.jboss.ws.common.configuration.ConfigDelegateHandler;
+import org.jboss.ws.common.configuration.ConfigDelegateHandlerComparator;
+
+/**
+ * Test the ConfigDelegateHandlerComparator
+ *
+ * @author alessio.soldano(a)jboss.org
+ * @since 07-Jun-2012
+ */
+public class ConfigDelegateHandlerComparatorTestCase extends TestCase
+{
+ public void testComparator() throws Exception
+ {
+ List<NamedHandler> list = new LinkedList<NamedHandler>();
+ list.add(new TestConfigDelegateHandler(new TestHandler("post1"),
false));
+ list.add(new TestHandler("h1"));
+ list.add(new TestConfigDelegateHandler(new TestHandler("post2"),
false));
+ list.add(new TestConfigDelegateHandler(new TestHandler("pre1"), true));
+ list.add(new TestConfigDelegateHandler(new TestHandler("pre2"), true));
+ list.add(new TestHandler("h2"));
+ list.add(new TestHandler("h3"));
+ list.add(new TestHandler("h4"));
+ list.add(new TestHandler("h5"));
+ list.add(new TestConfigDelegateHandler(new TestHandler("post3"),
false));
+ list.add(new TestConfigDelegateHandler(new TestHandler("pre3"), true));
+ list.add(new TestConfigDelegateHandler(new TestHandler("pre4"), true));
+ list.add(new TestHandler("h6"));
+ list.add(new TestConfigDelegateHandler(new TestHandler("post4"),
false));
+
+ Collections.sort(list, new
ConfigDelegateHandlerComparator<Handler<MessageContext>>());
+
+ StringBuilder sb = new StringBuilder();
+ for (NamedHandler h : list)
+ {
+ sb.append(h.getName());
+ sb.append(" ");
+ }
+ assertEquals("pre1 pre2 pre3 pre4 h1 h2 h3 h4 h5 h6 post1 post2 post3
post4", sb.toString().trim());
+ }
+
+ private static interface NamedHandler extends Handler<MessageContext>
+ {
+
+ public String getName();
+
+ }
+
+ private static class TestConfigDelegateHandler extends
ConfigDelegateHandler<MessageContext> implements NamedHandler
+ {
+
+ public TestConfigDelegateHandler(Handler<MessageContext> delegate, boolean
isPre)
+ {
+ super(delegate, isPre);
+ }
+
+ @Override
+ public String getName()
+ {
+ return delegate instanceof NamedHandler ? ((NamedHandler) delegate).getName() :
null;
+ }
+
+ }
+
+ private static class TestHandler implements NamedHandler
+ {
+
+ private String name;
+
+ public TestHandler(String name)
+ {
+ this.name = name;
+ }
+
+ @Override
+ public String getName()
+ {
+ return name;
+ }
+
+ @Override
+ public boolean handleMessage(MessageContext context)
+ {
+ return false;
+ }
+
+ @Override
+ public boolean handleFault(MessageContext context)
+ {
+ return false;
+ }
+
+ @Override
+ public void close(MessageContext context)
+ {
+ }
+ }
+}