Author: jim.ma
Date: 2010-04-26 22:59:28 -0400 (Mon, 26 Apr 2010)
New Revision: 12116
Added:
stack/cxf/branches/jms-integration/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/CXFEndpointsDeployment.java
stack/cxf/branches/jms-integration/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/SecurityActions.java
stack/cxf/branches/jms-integration/modules/server/src/main/java/org/jboss/wsf/stack/cxf/metadata/services/DDJmsAddressBean.java
Modified:
stack/cxf/branches/jms-integration/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/aspect/BusDeploymentAspect.java
stack/cxf/branches/jms-integration/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/aspect/EndpointsDescriptorDeploymentAspect.java
Log:
[JBWS-2791]:Used CXFEndpointsDeployment Pojo bean to start the cxf jms endpoints
Added:
stack/cxf/branches/jms-integration/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/CXFEndpointsDeployment.java
===================================================================
---
stack/cxf/branches/jms-integration/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/CXFEndpointsDeployment.java
(rev 0)
+++
stack/cxf/branches/jms-integration/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/CXFEndpointsDeployment.java 2010-04-27
02:59:28 UTC (rev 12116)
@@ -0,0 +1,152 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.wsf.stack.cxf.deployment;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.cxf.BusFactory;
+import org.jboss.wsf.common.integration.WSHelper;
+import org.jboss.wsf.spi.SPIProvider;
+import org.jboss.wsf.spi.SPIProviderResolver;
+import org.jboss.wsf.spi.deployment.DeploymentModelFactory;
+import org.jboss.wsf.spi.deployment.Endpoint;
+import org.jboss.wsf.spi.management.EndpointRegistry;
+import org.jboss.wsf.spi.management.EndpointRegistryFactory;
+import org.jboss.wsf.spi.metadata.endpoints.AbstractEndpointsDeployment;
+import org.jboss.wsf.spi.metadata.endpoints.EndpointMetaData;
+import org.jboss.wsf.spi.metadata.endpoints.EndpointsMetaData;
+import org.jboss.wsf.spi.metadata.endpoints.jms.JMSAddressMetaData;
+import org.jboss.wsf.spi.metadata.endpoints.jms.JMSDestinationMetaData;
+import org.jboss.wsf.stack.cxf.configuration.BusHolder;
+
+/**
+ * The pojo bean to deploy the jbossws-endpoints.xml to cxf stack
+ *
+ * @author <a href="ema(a)redhat.com">Jim Ma</a>
+ */
+public class CXFEndpointsDeployment extends AbstractEndpointsDeployment
+{
+
+ private EndpointRegistry registry;
+
+ private BusHolder busHolder = null;
+
+ private List<Endpoint> endpointsList = new ArrayList<Endpoint>();
+
+ @Override
+ public void start() throws Exception
+ {
+ log.debug("Deploying jbossws-endpoints.xml in " +
this.getDeployment().getSimpleName());
+ if (this.getURL() != null)
+ {
+ ClassLoader origClassLoader = SecurityActions.getContextClassLoader();
+ try
+ {
+
SecurityActions.setContextClassLoader(this.getDeployment().getRuntimeClassLoader());
+ busHolder = BusHolder.create(this.getURL());
+ }
+ catch (Exception e)
+ {
+ log.error("Failed to create endpoints deployment");
+ throw e;
+ }
+
+ finally
+ {
+ BusFactory.setDefaultBus(null);
+ BusFactory.setThreadDefaultBus(null);
+ SecurityActions.setContextClassLoader(origClassLoader);
+ }
+
+ registerEndpoints();
+ }
+ }
+
+ @Override
+ public void stop() throws Exception
+ {
+ log.debug("Undeploying jbossws-endpoints.xml in " +
this.getDeployment().getSimpleName());
+ if (busHolder != null & busHolder.getBus() != null)
+ {
+ //close LifecycleListener if exists
+ busHolder.getBus().shutdown(false);
+ busHolder.close();
+ }
+ unregisterEndpoints();
+ }
+
+ private void registerEndpoints()
+ {
+ SPIProvider spiProvider = SPIProviderResolver.getInstance().getProvider();
+ if (registry == null)
+ registry =
spiProvider.getSPI(EndpointRegistryFactory.class).getEndpointRegistry();
+ DeploymentModelFactory deploymentModelFactory =
spiProvider.getSPI(DeploymentModelFactory.class);
+ EndpointsMetaData endpointsMD =
WSHelper.getRequiredAttachment(this.getDeployment(), EndpointsMetaData.class);
+ for (EndpointMetaData endpointMD : endpointsMD.getEndpointsMetaData())
+ {
+ Endpoint endpoint =
deploymentModelFactory.newEndpoint(endpointMD.getImplementor());
+ endpoint.setShortName(this.getDeployment().getSimpleName());
+
+ if (endpointMD.getAddressMetaData() instanceof JMSAddressMetaData)
+ {
+ StringBuffer address = new StringBuffer("jms:");
+ JMSAddressMetaData jmsAddressMetaData = (JMSAddressMetaData)
endpointMD.getAddressMetaData();
+ JMSDestinationMetaData request = jmsAddressMetaData.getRequestDestination();
+ if (request.getProperty("jndiDestinationName") != null)
+ {
+ address.append("jndi:" +
request.getProperty("jndiDestinationName"));
+ }
+ else if (request.getProperty("jmsDestinationName") != null)
+ {
+ address.append("jndi:" +
request.getProperty("jmsDestinationName"));
+ }
+
+ JMSDestinationMetaData reply = jmsAddressMetaData.getReplyDestination();
+ if (reply.getProperty("jndiDestinationName") != null)
+ {
+ address.append("?replyToName =" +
reply.getProperty("jndiDestinationName"));
+ }
+ else if (reply.getProperty("jmsDestinationName") != null)
+ {
+ address.append("?replyToName =" +
reply.getProperty("jmsDestinationName"));
+ }
+
+ endpoint.setAddress(address.toString());
+ registry.register(endpoint);
+ endpointsList.add(endpoint);
+ }
+ }
+ }
+
+ public void unregisterEndpoints()
+ {
+ SPIProvider spiProvider = SPIProviderResolver.getInstance().getProvider();
+ if (registry == null)
+ registry =
spiProvider.getSPI(EndpointRegistryFactory.class).getEndpointRegistry();
+ for (Endpoint ep : this.endpointsList)
+ {
+ registry.unregister(ep);
+ }
+
+ }
+}
Added:
stack/cxf/branches/jms-integration/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/SecurityActions.java
===================================================================
---
stack/cxf/branches/jms-integration/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/SecurityActions.java
(rev 0)
+++
stack/cxf/branches/jms-integration/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/SecurityActions.java 2010-04-27
02:59:28 UTC (rev 12116)
@@ -0,0 +1,82 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.wsf.stack.cxf.deployment;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 17-Feb-2010
+ *
+ */
+class SecurityActions
+{
+ /**
+ * Get context classloader.
+ *
+ * @return the current context classloader
+ */
+ static ClassLoader getContextClassLoader()
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm == null)
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ else
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
{
+ public ClassLoader run()
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ });
+ }
+ }
+
+ /**
+ * Set context classloader.
+ *
+ * @param classLoader the classloader
+ */
+ static void setContextClassLoader(final ClassLoader classLoader)
+ {
+ if (System.getSecurityManager() == null)
+ {
+ Thread.currentThread().setContextClassLoader(classLoader);
+ }
+ else
+ {
+ AccessController.doPrivileged(new PrivilegedAction<Object>()
+ {
+ public Object run()
+ {
+ Thread.currentThread().setContextClassLoader(classLoader);
+ return null;
+ }
+ });
+ }
+ }
+
+}
Modified:
stack/cxf/branches/jms-integration/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/aspect/BusDeploymentAspect.java
===================================================================
---
stack/cxf/branches/jms-integration/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/aspect/BusDeploymentAspect.java 2010-04-26
07:58:05 UTC (rev 12115)
+++
stack/cxf/branches/jms-integration/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/aspect/BusDeploymentAspect.java 2010-04-27
02:59:28 UTC (rev 12116)
@@ -25,12 +25,9 @@
import java.net.URL;
import java.util.Map;
-import org.apache.cxf.Bus;
import org.apache.cxf.BusFactory;
-import org.apache.cxf.bus.spring.SpringBusFactory;
import org.jboss.wsf.common.integration.AbstractDeploymentAspect;
import org.jboss.wsf.common.integration.WSConstants;
-import org.jboss.wsf.common.integration.WSHelper;
import org.jboss.wsf.spi.binding.BindingCustomization;
import org.jboss.wsf.spi.deployment.ArchiveDeployment;
import org.jboss.wsf.spi.deployment.Deployment;
@@ -54,7 +51,7 @@
@Override
public void start(Deployment dep)
{
- BusHolder holder = null;
+ BusHolder holder;
ClassLoader origClassLoader = SecurityActions.getContextClassLoader();
try
{
@@ -62,57 +59,30 @@
//set the runtime classloader (pointing to the deployment unit) to allow CXF
accessing to the classes
SecurityActions.setContextClassLoader(dep.getRuntimeClassLoader());
- Map<String, String> contextParams = (Map<String,
String>)dep.getProperty(WSConstants.STACK_CONTEXT_PARAMS);
-
ResourceResolver deploymentResolver = aDep.getResourceResolver();
- org.apache.cxf.resource.ResourceResolver resolver = new
JBossWSResourceResolver(deploymentResolver);
-
- if (contextParams != null)
+
+ URL cxfServletURL = null;
+ try
{
-
+ cxfServletURL =
deploymentResolver.resolve("WEB-INF/cxf-servlet.xml");
+ }
+ catch (IOException e)
+ {
+ } //ignore, cxf-servlet.xml is optional, we might even decide not to support
this
- URL cxfServletURL = null;
- try
- {
- cxfServletURL =
deploymentResolver.resolve("WEB-INF/cxf-servlet.xml");
- }
- catch (IOException e)
- {
- } //ignore, cxf-servlet.xml is optional, we might even decide not to support
this
+ holder = BusHolder.create(cxfServletURL);
- holder = BusHolder.create(cxfServletURL);
-
- try
- {
- URL jbossCxfXml =
deploymentResolver.resolve(contextParams.get(BusHolder.PARAM_CXF_BEANS_URL));
-
- JBossWSCXFConfigurer configurer =
holder.createConfigurer(dep.getAttachment(BindingCustomization.class),
- new WSDLFilePublisher(aDep));
- holder.configure(jbossCxfXml, new SoapTransportFactoryExt(), resolver,
configurer);
-
- //if there is jbossws endpoints deployment descriptor
- if (WSHelper.hasEndpointsDeployment(dep) &&
dep.getProperty(BusHolder.PARAM_CXF_BEANS_URL) != null)
- {
- URL url = (URL) dep.getProperty(BusHolder.PARAM_CXF_BEANS_URL);
- holder.loadCXFConfig(holder.getBus(), url);
- }
-
- }
- catch (IOException e)
- {
- throw new RuntimeException(e); //re-throw, jboss-cxf.xml is required
- }
+ Map<String, String> contextParams = (Map<String,
String>)dep.getProperty(WSConstants.STACK_CONTEXT_PARAMS);
+ try
+ {
+ URL jbossCxfXml =
deploymentResolver.resolve(contextParams.get(BusHolder.PARAM_CXF_BEANS_URL));
+ org.apache.cxf.resource.ResourceResolver resolver = new
JBossWSResourceResolver(deploymentResolver);
+ JBossWSCXFConfigurer configurer =
holder.createConfigurer(dep.getAttachment(BindingCustomization.class), new
WSDLFilePublisher(aDep));
+ holder.configure(jbossCxfXml, new SoapTransportFactoryExt(), resolver,
configurer);
}
-
- if (contextParams == null && WSHelper.hasEndpointsDeployment(dep))
+ catch (IOException e)
{
- //TODO:BusHolder needs refactor to createBus automatically or getDefaultBus
- URL tmp = null;
- //holder = BusHolder.create(url);
- //Bus bus = new SpringBusFactory().createBus();
- if (holder == null) holder = BusHolder.create(tmp);
- URL url = (URL)dep.getProperty(BusHolder.PARAM_CXF_BEANS_URL);
- holder.loadCXFConfig(holder.getBus(), url);
+ throw new RuntimeException(e); //re-throw, jboss-cxf.xml is required
}
}
finally
@@ -147,4 +117,4 @@
holder.close();
}
}
-}
+}
\ No newline at end of file
Modified:
stack/cxf/branches/jms-integration/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/aspect/EndpointsDescriptorDeploymentAspect.java
===================================================================
---
stack/cxf/branches/jms-integration/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/aspect/EndpointsDescriptorDeploymentAspect.java 2010-04-26
07:58:05 UTC (rev 12115)
+++
stack/cxf/branches/jms-integration/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/aspect/EndpointsDescriptorDeploymentAspect.java 2010-04-27
02:59:28 UTC (rev 12116)
@@ -26,10 +26,11 @@
import org.jboss.wsf.common.integration.AbstractDeploymentAspect;
import org.jboss.wsf.common.integration.WSHelper;
import org.jboss.wsf.spi.deployment.Deployment;
+import org.jboss.wsf.spi.metadata.endpoints.AbstractEndpointsDeployment;
import org.jboss.wsf.spi.metadata.endpoints.EndpointMetaData;
import org.jboss.wsf.spi.metadata.endpoints.EndpointsMetaData;
import org.jboss.wsf.spi.metadata.endpoints.jms.JMSAddressMetaData;
-import org.jboss.wsf.stack.cxf.configuration.BusHolder;
+import org.jboss.wsf.stack.cxf.deployment.CXFEndpointsDeployment;
import org.jboss.wsf.stack.cxf.metadata.services.DDBeans;
import org.jboss.wsf.stack.cxf.metadata.services.DDEndpoint;
import org.jboss.wsf.stack.cxf.metadata.services.DDJmsAddressBean;
@@ -41,20 +42,26 @@
*/
public class EndpointsDescriptorDeploymentAspect extends AbstractDeploymentAspect
{
+
+
@Override
public void start(Deployment dep)
{
if (WSHelper.getOptionalAttachment(dep, EndpointsMetaData.class) != null)
{
URL url = this.generateCXFDeploymentDescriptor(dep);
- dep.setProperty(BusHolder.PARAM_CXF_BEANS_URL, url);
+ AbstractEndpointsDeployment endpointsDeployment = new CXFEndpointsDeployment();
+ endpointsDeployment.setURL(url);
+ endpointsDeployment.setDeployment(dep);
+ endpointsDeployment.setEndpointsMetaData(WSHelper.getOptionalAttachment(dep,
EndpointsMetaData.class));
+ dep.addAttachment(AbstractEndpointsDeployment.class, endpointsDeployment);
}
}
@Override
public void stop(Deployment dep)
{
- dep.removeProperty(BusHolder.PARAM_CXF_BEANS_URL);
+ dep.removeAttachment(AbstractEndpointsDeployment.class);
}
@Override
Added:
stack/cxf/branches/jms-integration/modules/server/src/main/java/org/jboss/wsf/stack/cxf/metadata/services/DDJmsAddressBean.java
===================================================================
---
stack/cxf/branches/jms-integration/modules/server/src/main/java/org/jboss/wsf/stack/cxf/metadata/services/DDJmsAddressBean.java
(rev 0)
+++
stack/cxf/branches/jms-integration/modules/server/src/main/java/org/jboss/wsf/stack/cxf/metadata/services/DDJmsAddressBean.java 2010-04-27
02:59:28 UTC (rev 12116)
@@ -0,0 +1,85 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.wsf.stack.cxf.metadata.services;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.Properties;
+
+/**
+ * DDJmsAddressBean.
+ *
+ * @author <a href="ema(a)redhat.com">Jim Ma</a>
+ */
+public class DDJmsAddressBean
+{
+ private String portName;
+ private Properties properties;
+ private boolean isRequest = true;
+
+ public DDJmsAddressBean(String portName, boolean isRequest, Properties properties)
+ {
+ this.portName = portName;
+ this.isRequest = isRequest;
+ this.properties = properties;
+ }
+
+ public void writeTo(Writer writer) throws IOException
+ {
+ if (isRequest)
+ {
+ writer.write("<jms:destination name='" + portName +
".jms-destination'>");
+ }
+ else
+ {
+ writer.write("<jms:conduit name='" + portName +
".jms-conduit'>");
+ }
+ writer.write("<jms:address");
+ for (String name : properties.stringPropertyNames())
+ {
+ writer.write(" " + name + "='" +
properties.getProperty(name) + "'");
+ }
+ writer.write("/>");
+ if (isRequest)
+ {
+ writer.write("</jms:destination>");
+ }
+ else
+ {
+ writer.write("</jms:conduit>");
+ }
+ }
+
+ public String toString()
+ {
+ StringWriter strWriter = new StringWriter();
+ strWriter.write("JMSAddressing");
+ strWriter.write("\n portName=" + portName);
+ strWriter.write("\n isRequest=" + isRequest);
+ strWriter.write("\n");
+ properties.list(new java.io.PrintWriter(strWriter));
+ return strWriter.toString();
+ }
+
+
+}