|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2003, 2004 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* IBM Corporation - initial API and implementation |
| 10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.jst.ws.internal.axis.consumption.core.command; |
| 12 |
|
| 13 |
|
| 14 |
import java.io.File; |
| 15 |
import java.io.FileOutputStream; |
| 16 |
import java.io.InputStream; |
| 17 |
import java.util.ResourceBundle; |
| 18 |
|
| 19 |
import org.apache.axis.AxisEngine; |
| 20 |
import org.apache.axis.server.AxisServer; |
| 21 |
import org.apache.axis.tools.ant.axis.AdminClientTask; |
| 22 |
import org.apache.axis.utils.ClassUtils; |
| 23 |
import org.apache.tools.ant.BuildException; |
| 24 |
import org.apache.tools.ant.Project; |
| 25 |
import org.apache.tools.ant.Target; |
| 26 |
import org.eclipse.core.resources.IFile; |
| 27 |
import org.eclipse.core.resources.IFolder; |
| 28 |
import org.eclipse.core.resources.IResource; |
| 29 |
import org.eclipse.core.runtime.IPath; |
| 30 |
import org.eclipse.core.runtime.Path; |
| 31 |
import org.eclipse.jst.ws.internal.axis.consumption.core.common.JavaWSDLParameter; |
| 32 |
import org.eclipse.jst.ws.internal.common.J2EEUtils; |
| 33 |
import org.eclipse.jst.ws.internal.common.ResourceUtils; |
| 34 |
import org.eclipse.wst.command.internal.provisional.env.core.SimpleCommand; |
| 35 |
import org.eclipse.wst.command.internal.provisional.env.core.common.Environment; |
| 36 |
import org.eclipse.wst.command.internal.provisional.env.core.common.SimpleStatus; |
| 37 |
import org.eclipse.wst.command.internal.provisional.env.core.common.Status; |
| 38 |
import org.eclipse.wst.common.componentcore.internal.StructureEdit; |
| 39 |
import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; |
| 40 |
|
| 41 |
/** |
| 42 |
* Commands are executable, undoable, redoable objects. Every Command has a name and a description. |
| 43 |
*/ |
| 44 |
|
| 45 |
public class GeronimoAxisDeployCommand extends SimpleCommand |
| 46 |
{ |
| 47 |
|
| 48 |
private JavaWSDLParameter javaWSDLParam; |
| 49 |
private ResourceBundle resource = ResourceBundle.getBundle("org.eclipse.jst.ws.axis.consumption.core.consumption"); //$NON-NLS-1$ |
| 50 |
|
| 51 |
private String projectName_; |
| 52 |
private String componentName_; |
| 53 |
|
| 54 |
private static final String AXIS_SERVER_CONFIG_FILE = "axis.ServerConfigFile"; |
| 55 |
|
| 56 |
IFolder outputRoot; |
| 57 |
|
| 58 |
/** |
| 59 |
* Constructor for GeronimoAxisDeployCommand. |
| 60 |
* @param String projectName |
| 61 |
* @param String componentName |
| 62 |
* |
| 63 |
*/ |
| 64 |
public GeronimoAxisDeployCommand(String projectName, String componentName) |
| 65 |
{ |
| 66 |
super("org.eclipse.jst.ws.internal.axis.consumption.core.command.GeronimoAxisDeployCommand", "org.eclipse.jst.ws.internal.axis.consumption.core.command.GeronimoAxisDeployCommand"); |
| 67 |
this.projectName_ = projectName; |
| 68 |
this.componentName_ = componentName; |
| 69 |
} |
| 70 |
|
| 71 |
public Status execute(Environment environment) |
| 72 |
{ |
| 73 |
|
| 74 |
if (javaWSDLParam == null) |
| 75 |
{ |
| 76 |
return new SimpleStatus("Java2WSDLCommand", //$NON-NLS-1$ |
| 77 |
getMessage("MSG_ERROR_JAVA_WSDL_PARAM_NOT_SET"), Status.ERROR); |
| 78 |
} |
| 79 |
|
| 80 |
if (javaWSDLParam.getProjectURL() == null || javaWSDLParam.getProjectURL().equals("")) |
| 81 |
{ //$NON-NLS-1$ |
| 82 |
return new SimpleStatus("Java2WSDLCommand", //$NON-NLS-1$ |
| 83 |
getMessage("MSG_ERROR_PROJECT_URL_PARAM_NOT_SET"), Status.ERROR); |
| 84 |
} |
| 85 |
|
| 86 |
if (javaWSDLParam.getDeploymentFiles() == null || javaWSDLParam.getDeploymentFiles().length == 0) |
| 87 |
{ |
| 88 |
return new SimpleStatus("Java2WSDLCommand", //$NON-NLS-1$ |
| 89 |
getMessage("MSG_ERROR_DEPLOY_FILE_PARAM_NOT_SET"), Status.ERROR); |
| 90 |
} |
| 91 |
|
| 92 |
environment.getProgressMonitor().report(getMessage("MSG_AXIS_DEPLOY")); |
| 93 |
|
| 94 |
Status status = executeAdminTask(); |
| 95 |
if (status.getSeverity() == Status.ERROR) |
| 96 |
{ |
| 97 |
environment.getStatusHandler().reportError(status); |
| 98 |
} |
| 99 |
|
| 100 |
status = executeAntTask(); |
| 101 |
if (status.getSeverity() == Status.ERROR) |
| 102 |
{ |
| 103 |
environment.getStatusHandler().reportError(status); |
| 104 |
} |
| 105 |
return status; |
| 106 |
} |
| 107 |
|
| 108 |
protected Status executeAntTask() |
| 109 |
{ |
| 110 |
final class DeployTask extends AdminClientTask |
| 111 |
{ |
| 112 |
public DeployTask() |
| 113 |
{ |
| 114 |
project = new Project(); |
| 115 |
project.init(); |
| 116 |
taskType = "axis"; //$NON-NLS-1$ |
| 117 |
taskName = "axis-admin"; //$NON-NLS-1$ |
| 118 |
target = new Target(); |
| 119 |
} |
| 120 |
} |
| 121 |
|
| 122 |
DeployTask adminClient = new DeployTask(); |
| 123 |
String url = javaWSDLParam.getProjectURL() + AxisDeployCommand.SERVICE_EXT; |
| 124 |
adminClient.setUrl(url); |
| 125 |
adminClient.setXmlFile(new File(javaWSDLParam.getDeploymentFiles()[0])); |
| 126 |
|
| 127 |
// Since the admin server may not be available right away we will try |
| 128 |
// several times to execute it. |
| 129 |
try |
| 130 |
{ |
| 131 |
BuildException lastException = null; |
| 132 |
|
| 133 |
for( int index = 0; index < 20; index++ ) |
| 134 |
{ |
| 135 |
try |
| 136 |
{ |
| 137 |
lastException = null; |
| 138 |
adminClient.execute(); |
| 139 |
} |
| 140 |
catch( BuildException exc ) |
| 141 |
{ |
| 142 |
lastException = exc; |
| 143 |
|
| 144 |
try |
| 145 |
{ |
| 146 |
Thread.sleep( 200 ); |
| 147 |
} |
| 148 |
catch( InterruptedException threadException ) |
| 149 |
{ |
| 150 |
} |
| 151 |
} |
| 152 |
|
| 153 |
// If no exception occured then we should break out of the loop. |
| 154 |
if( lastException == null ) break; |
| 155 |
} |
| 156 |
|
| 157 |
// If after many tries we still get an exception, then we will re throw it. |
| 158 |
if( lastException != null ) throw lastException; |
| 159 |
} |
| 160 |
catch (BuildException e) |
| 161 |
{ |
| 162 |
e.printStackTrace(); |
| 163 |
String message = e.getMessage(); |
| 164 |
if (e.getCause() != null) |
| 165 |
{ |
| 166 |
message = e.getCause().toString(); |
| 167 |
} |
| 168 |
|
| 169 |
Status[] childStatus = new Status[1]; |
| 170 |
childStatus[0] = new SimpleStatus("AxisDeployCommand", message, Status.ERROR); |
| 171 |
return new SimpleStatus("AxisDeployCommand", //$NON-NLS-1$ |
| 172 |
getMessage("MSG_ERROR_AXIS_DEPLOY"), childStatus); |
| 173 |
} |
| 174 |
return new SimpleStatus("AxisDeployCommand", //$NON-NLS-1$ |
| 175 |
getMessage("MSG_AXIS_DEPLOY_OK"), Status.OK); |
| 176 |
|
| 177 |
} |
| 178 |
|
| 179 |
protected Status executeAdminTask(){ |
| 180 |
|
| 181 |
Status status = new SimpleStatus(""); |
| 182 |
// check if server-config.wsdd exists |
| 183 |
IVirtualComponent component = J2EEUtils.getVirtualComponent( projectName_, componentName_ ); |
| 184 |
outputRoot = StructureEdit.getOutputContainerRoot( component ); |
| 185 |
IPath path = new Path( "WEB-INF" ).append( "server-config.wsdd" ); |
| 186 |
IFile descriptorFile = outputRoot.getFile( path ); |
| 187 |
|
| 188 |
if (!descriptorFile.exists()){ |
| 189 |
status = createServerConfigFile(); |
| 190 |
if (status.getSeverity()==Status.ERROR) |
| 191 |
return status; |
| 192 |
} |
| 193 |
|
| 194 |
// check if deploy.wsdd exists |
| 195 |
String deployWSDD = javaWSDLParam.getDeploymentFiles()[0]; |
| 196 |
File deployFile = new File(deployWSDD); |
| 197 |
if (deployFile==null || !deployFile.exists()){ |
| 198 |
return status; |
| 199 |
} |
| 200 |
|
| 201 |
try { |
| 202 |
// get Classpath |
| 203 |
String jarsCP = new String(); |
| 204 |
// classes dir |
| 205 |
IPath classesPath = new Path("WEB-INF").append("classes"); |
| 206 |
IFile classesDir = outputRoot.getFile(classesPath); |
| 207 |
jarsCP = "\""+classesDir.getRawLocation().toOSString()+"\""; |
| 208 |
|
| 209 |
// lib JARs |
| 210 |
IPath libPath = new Path("WEB-INF").append("lib"); |
| 211 |
IFile libEntry = outputRoot.getFile(libPath); |
| 212 |
IFolder libFolder = (IFolder)ResourceUtils.findResource(libEntry.getFullPath()); |
| 213 |
IResource[] JARfiles = libFolder.members(); |
| 214 |
for (int i=0;i<JARfiles.length;i++){ |
| 215 |
IResource res = JARfiles[i]; |
| 216 |
if (res.getFileExtension().equals("jar")){ |
| 217 |
jarsCP = jarsCP + ";\""+ res.getRawLocation().toOSString()+"\""; |
| 218 |
} |
| 219 |
} |
| 220 |
|
| 221 |
// form and run utils.Admin command |
| 222 |
String adminCommand = new String("java -Daxis.ServerConfigFile="+ descriptorFile.getRawLocation().toOSString() |
| 223 |
+" -cp "+jarsCP+" org.apache.axis.utils.Admin server "+deployFile.getCanonicalPath()); |
| 224 |
Runtime.getRuntime().exec(adminCommand); |
| 225 |
|
| 226 |
} |
| 227 |
catch(Exception e){ |
| 228 |
System.setProperty(AXIS_SERVER_CONFIG_FILE,"server-conifg.wsdd"); |
| 229 |
e.printStackTrace(); |
| 230 |
String message = e.getMessage(); |
| 231 |
if (e.getCause() != null) |
| 232 |
{ |
| 233 |
message = e.getCause().toString(); |
| 234 |
} |
| 235 |
|
| 236 |
Status[] childStatus = new Status[1]; |
| 237 |
childStatus[0] = new SimpleStatus("AxisDeployCommand", message, Status.ERROR); |
| 238 |
return new SimpleStatus("AxisDeployCommand", //$NON-NLS-1$ |
| 239 |
getMessage("MSG_ERROR_AXIS_DEPLOY"), childStatus); |
| 240 |
} |
| 241 |
|
| 242 |
return status; |
| 243 |
} |
| 244 |
|
| 245 |
/**t |
| 246 |
* Creates the initial server-config.wsdd file from a template in Axis |
| 247 |
* @return |
| 248 |
*/ |
| 249 |
private Status createServerConfigFile(){ |
| 250 |
try{ |
| 251 |
|
| 252 |
// server-config.wsdd file |
| 253 |
IPath path = new Path( "WEB-INF" ).append( "server-config.wsdd" ); |
| 254 |
IFile descriptorFile = outputRoot.getFile( path ); |
| 255 |
|
| 256 |
// create the initial server-config.wsdd file |
| 257 |
AxisEngine preEngine = new AxisServer(); |
| 258 |
InputStream is = ClassUtils.getResourceAsStream(preEngine.getClass(), "server-config.wsdd"); |
| 259 |
FileOutputStream fos = new FileOutputStream(descriptorFile.getRawLocation().toOSString()); |
| 260 |
ResourceUtils.copyStream(is, fos); |
| 261 |
fos.close(); |
| 262 |
|
| 263 |
return new SimpleStatus(""); |
| 264 |
} |
| 265 |
catch(Exception e){ |
| 266 |
e.printStackTrace(); |
| 267 |
String message = e.getMessage(); |
| 268 |
if (e.getCause() != null) |
| 269 |
{ |
| 270 |
message = e.getCause().toString(); |
| 271 |
} |
| 272 |
|
| 273 |
Status[] childStatus = new Status[1]; |
| 274 |
childStatus[0] = new SimpleStatus("AxisDeployCommand", message, Status.ERROR); |
| 275 |
return new SimpleStatus("AxisDeployCommand", //$NON-NLS-1$ |
| 276 |
getMessage("MSG_ERROR_AXIS_DEPLOY"), childStatus); |
| 277 |
} |
| 278 |
} |
| 279 |
|
| 280 |
/** |
| 281 |
* Returns the message string identified by the given key from plugin.properties. |
| 282 |
* |
| 283 |
* @return The String message. |
| 284 |
*/ |
| 285 |
public String getMessage(String key) |
| 286 |
{ |
| 287 |
return resource.getString(key); |
| 288 |
} |
| 289 |
|
| 290 |
/** |
| 291 |
* @param javaWSDLParam The javaWSDLParam to set. |
| 292 |
*/ |
| 293 |
public void setJavaWSDLParam(JavaWSDLParameter javaWSDLParam) |
| 294 |
{ |
| 295 |
this.javaWSDLParam = javaWSDLParam; |
| 296 |
} |
| 297 |
|
| 298 |
} |