Author: objectiser
Date: 2011-01-06 09:27:47 -0500 (Thu, 06 Jan 2011)
New Revision: 1213
Modified:
dsp/trunk/api/src/main/java/org/jboss/soa/dsp/deployer/ServiceDeployer.java
dsp/trunk/distribution/
dsp/trunk/docs/GettingStartedForTomcat.txt
dsp/trunk/jboss/src/main/java/org/jboss/soa/dsp/deployer/jboss/JBossServiceDeployer.java
dsp/trunk/samples/deployer/src/main/java/org/jboss/soa/dsp/example/WSDeployer.java
dsp/trunk/tomcat/src/main/java/org/jboss/soa/dsp/deployer/tomcat/TomcatServiceDeployer.java
dsp/trunk/tomcat/src/main/java/org/jboss/soa/dsp/server/tomcat/TomcatServerConfigLocator.java
Log:
Supports undeployment in tomcat version of example.
Modified: dsp/trunk/api/src/main/java/org/jboss/soa/dsp/deployer/ServiceDeployer.java
===================================================================
--- dsp/trunk/api/src/main/java/org/jboss/soa/dsp/deployer/ServiceDeployer.java 2011-01-06
12:34:06 UTC (rev 1212)
+++ dsp/trunk/api/src/main/java/org/jboss/soa/dsp/deployer/ServiceDeployer.java 2011-01-06
14:27:47 UTC (rev 1213)
@@ -20,22 +20,47 @@
import org.jboss.soa.dsp.EndpointMetaData;
import org.jboss.soa.dsp.ServiceEndpointReference;
+import org.jboss.soa.dsp.server.ServerConfig;
import org.jboss.soa.dsp.ws.BuildProcessor;
+/**
+ * This interface represents a service deployer.
+ *
+ */
public interface ServiceDeployer {
+ /**
+ * This method is used to deploy a servicer within a target environment.
+ *
+ * @param metaData The service endpoint metadata
+ * @param providerImpl The service provider implementation
+ * @param serviceUrl The service endpoint URL
+ * @param classLoader The classloader used in creation of the service provider
implementation
+ * @param deployment The deployment archive containing service artifacts
+ * @param serverConfig The server configuration
+ * @return The service endpoint reference
+ * @throws Exception Failed to deploy the service
+ */
public ServiceEndpointReference deploy(EndpointMetaData metaData, Class<?>
providerImpl, URL serviceUrl,
- ClassLoader classLoader, java.io.File deployment) throws Exception;
+ ClassLoader classLoader, java.io.File deployment, ServerConfig serverConfig)
+ throws Exception;
- public void undeploy(ServiceEndpointReference ref) throws Exception;
+ /**
+ * This method undeploys the service associated with the supplied endpoint reference.
+ *
+ * @param ref The service endpoint reference
+ * @param serverConfig The server configuration
+ * @throws Exception
+ */
+ public void undeploy(ServiceEndpointReference ref, ServerConfig serverConfig) throws
Exception;
/**
* This method returns the optional build processor associated with the
- * service deployer. This build processor can be used to performed any
+ * service deployer. This build processor can be used to perform any
* platform specific deployment archive modifications prior to it being
* deployed to the target platform.
*
- * @return The optional build procesor
+ * @return The optional build processor
*/
public BuildProcessor getBuildProcessor();
Property changes on: dsp/trunk/distribution
___________________________________________________________________
Name: svn:ignore
+ target
Modified: dsp/trunk/docs/GettingStartedForTomcat.txt
===================================================================
--- dsp/trunk/docs/GettingStartedForTomcat.txt 2011-01-06 12:34:06 UTC (rev 1212)
+++ dsp/trunk/docs/GettingStartedForTomcat.txt 2011-01-06 14:27:47 UTC (rev 1213)
@@ -41,6 +41,8 @@
Step 2 - Start the Apache Tomcat server
+NOTE: Make sure that the CATALINA_HOME environment variable is set correctly before
starting the server.
+
Step 3 - Install the Example Service Provider's Deployer Web App
Copy the dsp-example-deployer.war into $CATALINA_HOME/webapps
Modified:
dsp/trunk/jboss/src/main/java/org/jboss/soa/dsp/deployer/jboss/JBossServiceDeployer.java
===================================================================
---
dsp/trunk/jboss/src/main/java/org/jboss/soa/dsp/deployer/jboss/JBossServiceDeployer.java 2011-01-06
12:34:06 UTC (rev 1212)
+++
dsp/trunk/jboss/src/main/java/org/jboss/soa/dsp/deployer/jboss/JBossServiceDeployer.java 2011-01-06
14:27:47 UTC (rev 1213)
@@ -33,6 +33,7 @@
import org.jboss.soa.dsp.EndpointMetaData;
import org.jboss.soa.dsp.ServiceEndpointReference;
import org.jboss.soa.dsp.deployer.ServiceDeployer;
+import org.jboss.soa.dsp.server.ServerConfig;
import org.jboss.soa.dsp.server.jboss.KernelLocator;
import org.jboss.soa.dsp.ws.BuildProcessor;
import org.jboss.virtual.VFS;
@@ -41,7 +42,7 @@
public class JBossServiceDeployer implements ServiceDeployer {
public ServiceEndpointReference deploy(EndpointMetaData metaData, Class<?>
providerImpl, URL serviceUrl,
- final ClassLoader classLoader, File warArchive) throws Exception {
+ final ClassLoader classLoader, File warArchive, ServerConfig serverConfig) throws
Exception {
Deployment deployment = createVFSDeployment(warArchive);
// Classloading
@@ -74,7 +75,7 @@
return(ref);
}
- public void undeploy(ServiceEndpointReference ref) throws Exception {
+ public void undeploy(ServiceEndpointReference ref, ServerConfig serverConfig) throws
Exception {
getMainDeployer().undeploy(ref.getDeploymentName());
}
Modified:
dsp/trunk/samples/deployer/src/main/java/org/jboss/soa/dsp/example/WSDeployer.java
===================================================================
---
dsp/trunk/samples/deployer/src/main/java/org/jboss/soa/dsp/example/WSDeployer.java 2011-01-06
12:34:06 UTC (rev 1212)
+++
dsp/trunk/samples/deployer/src/main/java/org/jboss/soa/dsp/example/WSDeployer.java 2011-01-06
14:27:47 UTC (rev 1213)
@@ -67,11 +67,11 @@
javax.wsdl.Service
service=(javax.wsdl.Service)wsdl.getServices().values().iterator().next();
- _log.info("SERVICE="+service);
+ _log.fine("SERVICE="+service);
javax.wsdl.Port port=(javax.wsdl.Port)service.getPorts().values().iterator().next();
- _log.info("PORT="+port);
+ _log.fine("PORT="+port);
EndpointMetaData metaData=new EndpointMetaData(service.getQName(),
port.getName(), new QName("http://www.example.org",
"ProcessId"),
@@ -83,7 +83,7 @@
providerFactory.createProvider(metaData, wsdlRef, cl,
null, ExampleWebServiceFactory.class);
- _log.info("PROVIDER="+providerImpl);
+ _log.fine("Provider="+providerImpl);
ServerConfig serverConfig=getServerConfig();
@@ -98,21 +98,21 @@
providerFactory.writeClass(warArchive);
- _log.info("War Archive="+warArchive);
+ _log.fine("War Archive="+warArchive);
URL serviceUrl = new
WSDLParser(wsdlRef.getDefinition()).getServiceLocationURL(metaData.getServiceName(),
metaData.getPortName());
- _log.info("Service URL="+serviceUrl);
+ _log.fine("Service URL="+serviceUrl);
ref = deployer.deploy(metaData, providerImpl.getClass(),
- serviceUrl, cl, warArchive);
+ serviceUrl, cl, warArchive, getServerConfig());
} catch (Throwable t) {
_log.log(Level.SEVERE, "Failed", t);
}
- _log.info("DEPLOYED endpoint ref="+ref);
+ _log.fine("DEPLOYED endpoint ref="+ref);
return(ref);
}
@@ -120,7 +120,7 @@
public void undeploy(ServiceEndpointReference ref) throws Exception {
ServiceDeployer deployer=getServiceDeployer();
- deployer.undeploy(ref);
+ deployer.undeploy(ref, getServerConfig());
}
protected ServerConfig getServerConfig() {
Modified:
dsp/trunk/tomcat/src/main/java/org/jboss/soa/dsp/deployer/tomcat/TomcatServiceDeployer.java
===================================================================
---
dsp/trunk/tomcat/src/main/java/org/jboss/soa/dsp/deployer/tomcat/TomcatServiceDeployer.java 2011-01-06
12:34:06 UTC (rev 1212)
+++
dsp/trunk/tomcat/src/main/java/org/jboss/soa/dsp/deployer/tomcat/TomcatServiceDeployer.java 2011-01-06
14:27:47 UTC (rev 1213)
@@ -17,6 +17,11 @@
package org.jboss.soa.dsp.deployer.tomcat;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
import java.net.URL;
import javax.wsdl.Definition;
@@ -30,6 +35,7 @@
import org.jboss.soa.dsp.EndpointMetaData;
import org.jboss.soa.dsp.ServiceEndpointReference;
import org.jboss.soa.dsp.deployer.ServiceDeployer;
+import org.jboss.soa.dsp.server.ServerConfig;
import org.jboss.soa.dsp.ws.BuildProcessor;
import org.jboss.soa.dsp.ws.DeploymentBuilder;
@@ -39,39 +45,87 @@
public ServiceEndpointReference deploy(EndpointMetaData metaData,
Class<?> providerImpl, URL serviceUrl, ClassLoader classLoader,
- File deployment) throws Exception {
+ File deployment, ServerConfig serverConfig) throws Exception {
String warPath=deployment.getAbsolutePath();
- // Send request to the server
+ File deployDir=getDeployDir(serviceUrl, serverConfig);
- /* ISSUE: Use of manager requires user authentication. See if there is other way to do
this
- * locally within the server
- *
- String
path="http://localhost:8080/manager/deploy?path=/Quickstart_bpel_hello_worldWS&war=file:"+warPath;
+ log.debug("Copy "+warPath+" to "+deployDir);
- URL url = new URL(path);
-
- HttpURLConnection con=(HttpURLConnection)url.openConnection();
+ copyDirectory(new File(warPath), deployDir);
- con.setDoOutput(true);
- con.setRequestMethod("GET");
-
- con.connect();
-
- System.out.println("CONNECTED TO: "+path+" url="+url);
- */
-
ServiceEndpointReference ret=new ServiceEndpointReference(metaData.getEndpointId(),
serviceUrl, metaData.getServiceName().getLocalPart(), warPath);
return(ret);
}
+
+ protected File getDeployDir(URL serviceUrl, ServerConfig serverConfig) throws Exception
{
+ String context=serviceUrl.getPath();
+
+ int ind=context.indexOf(1, '/');
+ if (ind != -1) {
+ context = context.substring(0, ind);
+ }
+
+ File deployDir=new File(serverConfig.getServerDataDir(), context);
+
+ return(deployDir);
+ }
- public void undeploy(ServiceEndpointReference ref) throws Exception {
+ protected void copyDirectory(File sourceLocation , File targetLocation) throws
IOException {
+
+ if (sourceLocation.isDirectory()) {
+ if (!targetLocation.exists()) {
+ targetLocation.mkdir();
+ }
+
+ String[] children = sourceLocation.list();
+ for (int i=0; i<children.length; i++) {
+ copyDirectory(new File(sourceLocation, children[i]),
+ new File(targetLocation, children[i]));
+ }
+ } else {
+
+ InputStream in = new FileInputStream(sourceLocation);
+ OutputStream out = new FileOutputStream(targetLocation);
+
+ // Copy the bits from instream to outstream
+ byte[] buf = new byte[1024];
+ int len;
+ while ((len = in.read(buf)) > 0) {
+ out.write(buf, 0, len);
+ }
+ in.close();
+ out.close();
+ }
+ }
+
+ public void undeploy(ServiceEndpointReference ref, ServerConfig serverConfig) throws
Exception {
+ File deployDir=getDeployDir(ref.getServiceUrl(), serverConfig);
+
+ // Remove directory from the deployment folder
+ if (deployDir != null) {
+ delete(deployDir);
+ }
}
+ protected void delete(File file) {
+ if (file.isDirectory()) {
+ File[] children=file.listFiles();
+
+ for (int i=0; i < children.length; i++) {
+ delete(children[i]);
+ }
+ }
+
+ if (!file.delete()) {
+ log.error("Failed to delete '"+file+"' when undeploying
service");
+ }
+ }
+
/**
* This method returns the optional build processor associated with the
* service deployer. This build processor can be used to performed any
Modified:
dsp/trunk/tomcat/src/main/java/org/jboss/soa/dsp/server/tomcat/TomcatServerConfigLocator.java
===================================================================
---
dsp/trunk/tomcat/src/main/java/org/jboss/soa/dsp/server/tomcat/TomcatServerConfigLocator.java 2011-01-06
12:34:06 UTC (rev 1212)
+++
dsp/trunk/tomcat/src/main/java/org/jboss/soa/dsp/server/tomcat/TomcatServerConfigLocator.java 2011-01-06
14:27:47 UTC (rev 1213)
@@ -38,14 +38,31 @@
public String getImplementationVersion() {
return("1.0");
}
+
+ protected File getTomcatRoot() {
+ String path=System.getenv("CATALINA_HOME");
+
+ if (path == null) {
+ return(null);
+ }
+
+ return(new File(path));
+ }
public File getServerTempDir() {
- return(new java.io.File("/tmp"));
+ File tomcat=getTomcatRoot();
+ if (tomcat == null) {
+ return(null);
+ }
+ return(new java.io.File(tomcat, "temp"));
}
public File getServerDataDir() {
- // TODO Auto-generated method stub
- return null;
+ File tomcat=getTomcatRoot();
+ if (tomcat == null) {
+ return(null);
+ }
+ return(new java.io.File(tomcat, "webapps"));
}
public String getWebServiceHost() {