Author: richard.opalka(a)jboss.com
Date: 2011-10-03 09:47:54 -0400 (Mon, 03 Oct 2011)
New Revision: 15031
Added:
stack/native/trunk/modules/core/src/main/java/org/jboss/wsf/stack/jbws/NativeInstanceProvider.java
stack/native/trunk/modules/core/src/main/java/org/jboss/wsf/stack/jbws/NativeInstanceProviderDeploymentAspect.java
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxrpc/handler/HandlerChainBaseImpl.java
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/handler/HandlerResolverImpl.java
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyHttpServerAdapter.java
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/server/ServiceEndpointInvoker.java
stack/native/trunk/modules/core/src/main/java/org/jboss/wsf/stack/jbws/Message.properties
stack/native/trunk/modules/core/src/main/resources/jbossws-native-config-as6.xml
stack/native/trunk/modules/core/src/main/resources/jbossws-native-config-as7.xml
Log:
[JBWS-3363] extending SPI - providing hook for instances retrieval
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxrpc/handler/HandlerChainBaseImpl.java
===================================================================
---
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxrpc/handler/HandlerChainBaseImpl.java 2011-10-03
13:10:26 UTC (rev 15030)
+++
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxrpc/handler/HandlerChainBaseImpl.java 2011-10-03
13:47:54 UTC (rev 15031)
@@ -48,6 +48,8 @@
import org.jboss.ws.core.soap.SOAPElementImpl;
import org.jboss.ws.core.soap.SOAPElementWriter;
import org.jboss.ws.core.soap.SOAPEnvelopeImpl;
+import org.jboss.wsf.spi.deployment.Endpoint;
+import org.jboss.wsf.spi.invocation.EndpointAssociation;
import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedHandlerMetaData.HandlerType;
/**
@@ -128,7 +130,7 @@
{
for (HandlerInfo info : infos)
{
- HandlerWrapper handler = new
HandlerWrapper((Handler)info.getHandlerClass().newInstance());
+ HandlerWrapper handler = new HandlerWrapper(getInstance(info));
HandlerType type =
(HandlerType)info.getHandlerConfig().get(HandlerType.class.getName());
handlers.add(new HandlerEntry(handler, info, type));
}
@@ -151,6 +153,21 @@
state = STATE_CREATED;
}
+ private Handler getInstance(final HandlerInfo info) throws Exception
+ {
+ final Endpoint ep = EndpointAssociation.getEndpoint();
+ final Handler handler;
+ if (ep != null)
+ {
+ handler =
(Handler)ep.getInstanceProvider().getInstance(info.getHandlerClass().getName());
+ }
+ else
+ {
+ handler = (Handler)info.getHandlerClass().newInstance();
+ }
+ return handler;
+ }
+
/**
* Get the state of this handler chain
*/
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/handler/HandlerResolverImpl.java
===================================================================
---
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/handler/HandlerResolverImpl.java 2011-10-03
13:10:26 UTC (rev 15030)
+++
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/handler/HandlerResolverImpl.java 2011-10-03
13:47:54 UTC (rev 15031)
@@ -168,14 +168,13 @@
try
{
// Load the handler class using the deployments top level CL
- Class hClass = classLoader.loadClass(className);
- Handler handler = (Handler)hClass.newInstance();
+ Handler<?> handler = getInstance(classLoader, className);
if (handler instanceof GenericHandler)
((GenericHandler)handler).setHandlerName(handlerName);
if (handler instanceof GenericSOAPHandler)
- ((GenericSOAPHandler)handler).setHeaders(soapHeaders);
+ ((GenericSOAPHandler<?>)handler).setHeaders(soapHeaders);
if (injections != null)
{
@@ -197,6 +196,22 @@
}
}
+ private Handler<?> getInstance(final ClassLoader fallbackLoader, final String
className) throws Exception
+ {
+ final Endpoint ep = EndpointAssociation.getEndpoint();
+ final Handler<?> handler;
+ if (ep != null)
+ {
+ handler = (Handler<?>)ep.getInstanceProvider().getInstance(className);
+ }
+ else
+ {
+ final Class<?> hClass = fallbackLoader.loadClass(className);
+ handler = (Handler<?>)hClass.newInstance();
+ }
+ return handler;
+ }
+
private boolean addHandler(HandlerMetaDataJAXWS hmd, Handler handler, HandlerType
type)
{
if (log.isDebugEnabled())
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyHttpServerAdapter.java
===================================================================
---
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyHttpServerAdapter.java 2011-10-03
13:10:26 UTC (rev 15030)
+++
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyHttpServerAdapter.java 2011-10-03
13:47:54 UTC (rev 15031)
@@ -51,6 +51,7 @@
import org.jboss.wsf.spi.deployment.DeploymentModelFactory;
import org.jboss.wsf.spi.deployment.HttpEndpoint;
import org.jboss.wsf.stack.jbws.EagerInitializeDeploymentAspect;
+import org.jboss.wsf.stack.jbws.NativeInstanceProviderDeploymentAspect;
import org.jboss.wsf.stack.jbws.PublishContractDeploymentAspect;
import org.jboss.wsf.stack.jbws.ServiceEndpointInvokerDeploymentAspect;
import org.jboss.wsf.stack.jbws.UnifiedMetaDataDeploymentAspect;
@@ -221,6 +222,7 @@
retVal.add(new EndpointAddressDeploymentAspect());
retVal.add(new EndpointNameDeploymentAspect());
retVal.add(new UnifiedMetaDataDeploymentAspect());
+ retVal.add(new NativeInstanceProviderDeploymentAspect());
retVal.add(new ServiceEndpointInvokerDeploymentAspect());
retVal.add(new PublishContractDeploymentAspect());
retVal.add(new EagerInitializeDeploymentAspect());
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/server/ServiceEndpointInvoker.java
===================================================================
---
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/server/ServiceEndpointInvoker.java 2011-10-03
13:10:26 UTC (rev 15030)
+++
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/server/ServiceEndpointInvoker.java 2011-10-03
13:47:54 UTC (rev 15031)
@@ -371,7 +371,7 @@
{
// create endpoint instance
final Class<?> endpointImplClass = endpoint.getTargetBeanClass();
- endpointImpl = endpointImplClass.newInstance();
+ endpointImpl =
endpoint.getInstanceProvider().getInstance(endpointImplClass.getName());
endpoint.addAttachment(Object.class, endpointImpl);
}
catch (Exception ex)
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/wsf/stack/jbws/Message.properties
===================================================================
---
stack/native/trunk/modules/core/src/main/java/org/jboss/wsf/stack/jbws/Message.properties 2011-10-03
13:10:26 UTC (rev 15030)
+++
stack/native/trunk/modules/core/src/main/java/org/jboss/wsf/stack/jbws/Message.properties 2011-10-03
13:47:54 UTC (rev 15031)
@@ -26,3 +26,5 @@
CANNOT_PROCESS_METRICS=Cannot process metrics
INVALID_ENDPOINT_ADDRESS=Invalid endpoint address: {0}
ERROR_PROCESSING_WEB_SERVICE_REQUEST=Error processing web service request
+
+CANNOT_LOAD_CLASS=Cannot load class: {0}
Added:
stack/native/trunk/modules/core/src/main/java/org/jboss/wsf/stack/jbws/NativeInstanceProvider.java
===================================================================
---
stack/native/trunk/modules/core/src/main/java/org/jboss/wsf/stack/jbws/NativeInstanceProvider.java
(rev 0)
+++
stack/native/trunk/modules/core/src/main/java/org/jboss/wsf/stack/jbws/NativeInstanceProvider.java 2011-10-03
13:47:54 UTC (rev 15031)
@@ -0,0 +1,62 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat, Inc., 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.wsf.stack.jbws;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.ResourceBundle;
+
+import org.jboss.ws.WSException;
+import org.jboss.ws.api.util.BundleUtils;
+import org.jboss.wsf.spi.deployment.InstanceProvider;
+
+/**
+ * Native instance provider.
+ *
+ * @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
+ */
+final class NativeInstanceProvider implements InstanceProvider {
+
+ private static final ResourceBundle bundle =
BundleUtils.getBundle(NativeInstanceProvider.class);
+ private final ClassLoader loader;
+ private final Map<String, Object> cache = new HashMap<String, Object>();
+
+ NativeInstanceProvider(final ClassLoader loader)
+ {
+ this.loader = loader;
+ }
+
+ public synchronized Object getInstance(final String className) {
+ Object instance = cache.get(className);
+ if (instance == null) {
+ try {
+ instance = loader.loadClass(className).newInstance();
+ cache.put(className, instance);
+ } catch (Exception e) {
+ throw new WSException(BundleUtils.getMessage(bundle,
"CANNOT_LOAD_CLASS", className), e);
+ }
+ }
+ return instance;
+ }
+
+}
Added:
stack/native/trunk/modules/core/src/main/java/org/jboss/wsf/stack/jbws/NativeInstanceProviderDeploymentAspect.java
===================================================================
---
stack/native/trunk/modules/core/src/main/java/org/jboss/wsf/stack/jbws/NativeInstanceProviderDeploymentAspect.java
(rev 0)
+++
stack/native/trunk/modules/core/src/main/java/org/jboss/wsf/stack/jbws/NativeInstanceProviderDeploymentAspect.java 2011-10-03
13:47:54 UTC (rev 15031)
@@ -0,0 +1,60 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat, Inc., 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.wsf.stack.jbws;
+
+import org.jboss.ws.common.integration.AbstractDeploymentAspect;
+import org.jboss.ws.common.utils.DelegateClassLoader;
+import org.jboss.wsf.spi.classloading.ClassLoaderProvider;
+import org.jboss.wsf.spi.deployment.Deployment;
+import org.jboss.wsf.spi.deployment.Endpoint;
+
+/**
+ * Instance provider DA.
+ *
+ * @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
+ */
+public final class NativeInstanceProviderDeploymentAspect extends
AbstractDeploymentAspect
+{
+
+ @Override
+ public void start(final Deployment dep)
+ {
+ final ClassLoader loader = dep.getRuntimeClassLoader();
+ final ClassLoader integrationCL =
ClassLoaderProvider.getDefaultProvider().getServerIntegrationClassLoader();
+ final ClassLoader newCL = new DelegateClassLoader(integrationCL, loader);
+ for (final Endpoint ep : dep.getService().getEndpoints())
+ {
+ ep.setInstanceProvider(new NativeInstanceProvider(newCL));
+ }
+ }
+
+ @Override
+ public void stop(final Deployment dep)
+ {
+ for (final Endpoint ep : dep.getService().getEndpoints())
+ {
+ ep.setInstanceProvider(null);
+ }
+ }
+
+}
Modified:
stack/native/trunk/modules/core/src/main/resources/jbossws-native-config-as6.xml
===================================================================
---
stack/native/trunk/modules/core/src/main/resources/jbossws-native-config-as6.xml 2011-10-03
13:10:26 UTC (rev 15030)
+++
stack/native/trunk/modules/core/src/main/resources/jbossws-native-config-as6.xml 2011-10-03
13:47:54 UTC (rev 15031)
@@ -43,6 +43,11 @@
<property name="provides">StackEndpointHandler</property>
</bean>
+ <bean name="WSNativeInstanceProviderDeploymentAspect"
class="org.jboss.wsf.stack.jbws.NativeInstanceProviderDeploymentAspect">
+ <property name="requires">ContainerMetaData</property>
+ <property name="provides">StackInstanceProvider</property>
+ </bean>
+
<bean name="WSNativeEndpointRecordProcessorDeploymentAspect"
class="org.jboss.ws.common.deployment.EndpointRecordProcessorDeploymentAspect">
<property name="mbeanServer"><inject
bean="WSMBeanServerLocator"
property="mbeanServer"/></property>
<property name="requires">RegisteredEndpoint</property>
Modified:
stack/native/trunk/modules/core/src/main/resources/jbossws-native-config-as7.xml
===================================================================
---
stack/native/trunk/modules/core/src/main/resources/jbossws-native-config-as7.xml 2011-10-03
13:10:26 UTC (rev 15030)
+++
stack/native/trunk/modules/core/src/main/resources/jbossws-native-config-as7.xml 2011-10-03
13:47:54 UTC (rev 15031)
@@ -46,6 +46,11 @@
<property name="provides"
class="java.lang.String">StackEndpointHandler</property>
</deploymentAspect>
+ <deploymentAspect
class="org.jboss.wsf.stack.jbws.NativeInstanceProviderDeploymentAspect">
+ <property name="requires"
class="java.lang.String">ContainerMetaData</property>
+ <property name="provides"
class="java.lang.String">StackInstanceProvider</property>
+ </deploymentAspect>
+
<deploymentAspect
class="org.jboss.wsf.stack.jbws.PublishContractDeploymentAspect">
<property name="requires"
class="java.lang.String">UnifiedMetaDataModel, JAXBIntros</property>
<property name="provides"
class="java.lang.String">PublishedContract</property>