Author: heiko.braun(a)jboss.com
Date: 2008-04-17 15:40:09 -0400 (Thu, 17 Apr 2008)
New Revision: 6477
Added:
stack/native/trunk/src/main/java/org/jboss/wsf/stack/jbws/embedded/DeploymentModelBuilder.java
Modified:
stack/native/trunk/build.xml
stack/native/trunk/src/test/java/org/jboss/test/ws/embedded/EmbeddedTestCase.java
Log:
Simplify embedded use by providing a DeploymentModelBuilder
Modified: stack/native/trunk/build.xml
===================================================================
--- stack/native/trunk/build.xml 2008-04-17 18:54:38 UTC (rev 6476)
+++ stack/native/trunk/build.xml 2008-04-17 19:40:09 UTC (rev 6477)
@@ -185,19 +185,6 @@
</copy>
</target>
- <!--target name="clean-42x-resources">
- <delete dir="${core.output.dir}/resources"/>
- <mkdir dir="${core.output.dir}/resources"/>
- </target>
-
- <target name="unzip-jboss422-resources"
depends="clean-42x-resources" if="jbossws.integration.jboss422">
- <unzip dest="${core.output.dir}/resources"
src="${thirdparty.dir}/jbossws-jboss422-resources.zip"
overwrite="true"/>
- </target>
-
- <target name="unzip-jboss423-resources"
depends="clean-42x-resources" if="jbossws.integration.jboss423">
- <unzip dest="${core.output.dir}/resources"
src="${thirdparty.dir}/jbossws-jboss422-resources.zip"
overwrite="true"/>
- </target-->
-
<!-- Compile resource files -->
<target name="compile42-resources"
if="jbossws.integration.jboss42">
<mkdir dir="${core.output.resources.dir}"/>
Added:
stack/native/trunk/src/main/java/org/jboss/wsf/stack/jbws/embedded/DeploymentModelBuilder.java
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/wsf/stack/jbws/embedded/DeploymentModelBuilder.java
(rev 0)
+++
stack/native/trunk/src/main/java/org/jboss/wsf/stack/jbws/embedded/DeploymentModelBuilder.java 2008-04-17
19:40:09 UTC (rev 6477)
@@ -0,0 +1,106 @@
+/*
+ * 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.wsf.stack.jbws.embedded;
+
+import org.jboss.wsf.spi.deployment.*;
+import org.jboss.wsf.spi.SPIProvider;
+import org.jboss.wsf.spi.SPIProviderResolver;
+import org.jboss.wsf.common.ResourceLoaderAdapter;
+
+import java.util.UUID;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * A builder that helps creating {@link org.jboss.wsf.spi.deployment.Deployment}'s
+ * for embedded use.
+ *
+ * @author Heiko.Braun <heiko.braun(a)jboss.com>
+ */
+public class DeploymentModelBuilder
+{
+ private Deployment deployment;
+ private DeploymentModelFactory modelFactory;
+
+ public DeploymentModelBuilder()
+ {
+ SPIProvider spi = SPIProviderResolver.getInstance().getProvider();
+ modelFactory = spi.getSPI(DeploymentModelFactory.class);
+
+ // Deployment
+ ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
+ this.deployment = modelFactory.newDeployment(UUID.randomUUID().toString(),
contextClassLoader);
+ this.deployment.setRuntimeClassLoader(contextClassLoader);
+
+ // TODO: Hack, should this become another DeploymentAspect?
+ ((ArchiveDeployment)this.deployment).setRootFile(new ResourceLoaderAdapter());
+
+ this.deployment.setType(Deployment.DeploymentType.JAXWS_JSE);
+
+ // Service
+ this.deployment.setService(modelFactory.newService());
+
+ }
+
+ public DeploymentModelBuilder setContextRoot(String contextRoot)
+ {
+ assert contextRoot!=null;
+ this.deployment.getService().setContextRoot(contextRoot);
+ return this;
+ }
+
+ public DeploymentModelBuilder addEndpoint(String className, String urlPattern)
+ {
+ assert className!=null;
+ assert urlPattern!=null;
+
+ // Endpoint
+ Endpoint endpoint =
modelFactory.newEndpoint("org.jboss.test.ws.embedded.HelloWorldEndpoint");
+ endpoint.setShortName(className + "-Endpoint");
+ endpoint.setURLPattern(urlPattern);
+ this.deployment.getService().addEndpoint(endpoint);
+ return this;
+ }
+
+ public Deployment build()
+ {
+ if(null == this.deployment.getService().getContextRoot())
+ throw new IllegalArgumentException("No context root");
+
+ List<String> usedPatterns = new ArrayList<String>();
+ for(Endpoint ep : this.deployment.getService().getEndpoints())
+ {
+ String urlPattern = ep.getURLPattern();
+ if(null == urlPattern)
+ throw new IllegalArgumentException("No urlPattern");
+
+ for(String usedPattern : usedPatterns)
+ {
+ if(urlPattern.equals(usedPattern))
+ throw new IllegalArgumentException("URL pattern already used: "
+ urlPattern);
+ }
+
+ usedPatterns.add(urlPattern);
+ }
+ return this.deployment;
+ }
+}
Property changes on:
stack/native/trunk/src/main/java/org/jboss/wsf/stack/jbws/embedded/DeploymentModelBuilder.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified:
stack/native/trunk/src/test/java/org/jboss/test/ws/embedded/EmbeddedTestCase.java
===================================================================
---
stack/native/trunk/src/test/java/org/jboss/test/ws/embedded/EmbeddedTestCase.java 2008-04-17
18:54:38 UTC (rev 6476)
+++
stack/native/trunk/src/test/java/org/jboss/test/ws/embedded/EmbeddedTestCase.java 2008-04-17
19:40:09 UTC (rev 6477)
@@ -22,13 +22,8 @@
package org.jboss.test.ws.embedded;
import junit.framework.TestCase;
-import org.jboss.wsf.common.ResourceLoaderAdapter;
-import org.jboss.wsf.spi.SPIProvider;
-import org.jboss.wsf.spi.SPIProviderResolver;
-import org.jboss.wsf.spi.deployment.ArchiveDeployment;
import org.jboss.wsf.spi.deployment.Deployment;
-import org.jboss.wsf.spi.deployment.DeploymentModelFactory;
-import org.jboss.wsf.spi.deployment.Endpoint;
+import org.jboss.wsf.stack.jbws.embedded.DeploymentModelBuilder;
import org.jboss.wsf.stack.jbws.embedded.EmbeddableWSFRuntime;
import javax.xml.namespace.QName;
@@ -53,30 +48,12 @@
* @throws Exception
*/
public void testEmbeddedContainer() throws Exception
- {
- SPIProvider spi = SPIProviderResolver.getInstance().getProvider();
- DeploymentModelFactory modelFactory = spi.getSPI(DeploymentModelFactory.class);
+ {
+ Deployment dep = new DeploymentModelBuilder()
+ .setContextRoot("/hello")
+ .addEndpoint("org.jboss.test.ws.embedded.HelloWorldEndpoint",
"/endpoint")
+ .build();
- // Deployment
- ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
- Deployment dep = modelFactory.newDeployment("HelloWorldDeployment",
contextClassLoader);
- dep.setRuntimeClassLoader(contextClassLoader);
-
- // TODO: Hack, should this become another DeploymentAspect?
- ((ArchiveDeployment)dep).setRootFile(new ResourceLoaderAdapter());
-
- dep.setType(Deployment.DeploymentType.JAXWS_JSE);
- dep.setService(modelFactory.newService());
-
- // Service
- dep.getService().setContextRoot("/hello");
-
- // Endpoint
- Endpoint endpoint =
modelFactory.newEndpoint("org.jboss.test.ws.embedded.HelloWorldEndpoint");
- endpoint.setShortName("hello");
- endpoint.setURLPattern("/endpoint");
- dep.getService().addEndpoint(endpoint);
-
// Publish
EmbeddableWSFRuntime container = EmbeddableWSFRuntime.bootstrap(
EmbeddableWSFRuntime.DEFAULT_CONFIG_URL);
container.create(dep);