Index: deployment/admin/src/main/java/org/glassfish/deployment/admin/InstanceDeployCommand.java =================================================================== --- deployment/admin/src/main/java/org/glassfish/deployment/admin/InstanceDeployCommand.java (revision 38356) +++ deployment/admin/src/main/java/org/glassfish/deployment/admin/InstanceDeployCommand.java (working copy) @@ -37,8 +37,6 @@ import java.io.File; import java.io.IOException; -import java.util.Arrays; -import java.util.Collections; import java.util.Calendar; import java.util.logging.Logger; import java.util.logging.Level; @@ -48,8 +46,6 @@ import org.glassfish.api.admin.RuntimeType; import org.glassfish.api.admin.ServerEnvironment; import org.glassfish.api.ActionReport; -import org.glassfish.api.container.Sniffer; -import org.glassfish.api.deployment.DeploymentContext; import org.glassfish.api.deployment.archive.ArchiveHandler; import org.glassfish.api.deployment.archive.ReadableArchive; import org.glassfish.internal.data.ApplicationInfo; @@ -57,7 +53,6 @@ import org.glassfish.internal.deployment.ExtendedDeploymentContext; import org.glassfish.internal.deployment.SnifferManager; import org.jvnet.hk2.annotations.Service; -import org.glassfish.api.ActionReport.ExitCode; import org.jvnet.hk2.annotations.Inject; import org.jvnet.hk2.annotations.Scoped; import org.jvnet.hk2.component.PerLookup; @@ -115,8 +110,9 @@ this.previousContextRoot = preservedcontextroot; try { - if (!path.exists()) { - report.setMessage(localStrings.getLocalString("fnf","File not found", path.getAbsolutePath())); + File file = getPathAsFile(); + if (file != null && !file.exists()) { + report.setMessage(localStrings.getLocalString("fnf","File not found", file.getAbsolutePath())); report.setActionExitCode(ActionReport.ExitCode.FAILURE); return; } @@ -127,10 +123,10 @@ return; } - archive = archiveFactory.openArchive(path, this); + archive = archiveFactory.openArchive(getPath(), this); ArchiveHandler archiveHandler = deployment.getArchiveHandler(archive); if (archiveHandler==null) { - report.failure(logger,localStrings.getLocalString("deploy.unknownarchivetype","Archive type of {0} was not recognized",path.getName())); + report.failure(logger,localStrings.getLocalString("deploy.unknownarchivetype","Archive type of {0} was not recognized", getPath())); return; } @@ -204,7 +200,7 @@ logger.log(Level.INFO, localStrings.getLocalString( "errClosingArtifact", "Error while closing deployable artifact : ", - path.getAbsolutePath()), e); + getPath()), e); } logger.info(localStrings.getLocalString( "deploy.done", Index: deployment/admin/src/main/java/org/glassfish/deployment/admin/ReDeployCommand.java =================================================================== --- deployment/admin/src/main/java/org/glassfish/deployment/admin/ReDeployCommand.java (revision 38356) +++ deployment/admin/src/main/java/org/glassfish/deployment/admin/ReDeployCommand.java (working copy) @@ -56,7 +56,8 @@ import org.jvnet.hk2.annotations.Inject; import org.jvnet.hk2.component.PerLookup; import org.jvnet.hk2.annotations.Scoped; -import java.util.Properties; + +import java.net.URI; import java.util.Collection; import java.util.ArrayList; import java.io.File; @@ -85,8 +86,14 @@ String name; @Param(primary=true, optional=true) - File path = null; + public void setPath(URI path) { + super.setPath(path); + } + public URI getPath() { + return super.getPath(); + } + //define this variable to skip parameter valadation. //Param validation will be done when referening deploy command. boolean skipParamValidation = true; @@ -139,7 +146,7 @@ report.setActionExitCode(ActionReport.ExitCode.FAILURE); return false; } - else if (path == null) { + else if (getPath() == null) { /** * If path is not specified on the command line but the application * is not directory deployed then throw an exception since we don't @@ -153,12 +160,8 @@ } //if path not specified on the command line then get it from domain.xml - super.path = (path==null)?new File(ConfigBeansUtilities.getLocation(name)):path; - if (super.path == null) { - //if unable to get path from domain.xml then return error. - report.setMessage(localStrings.getLocalString("redeploy.command.invalid.path", "Cannot determine the path of application.")); - report.setActionExitCode(ActionReport.ExitCode.FAILURE); - return false; + if (getPath() == null) { + setPath(URI.create(ConfigBeansUtilities.getLocation(name))); } return true; } Index: deployment/admin/src/main/java/org/glassfish/deployment/admin/DeployCommand.java =================================================================== --- deployment/admin/src/main/java/org/glassfish/deployment/admin/DeployCommand.java (revision 38356) +++ deployment/admin/src/main/java/org/glassfish/deployment/admin/DeployCommand.java (working copy) @@ -36,6 +36,7 @@ package org.glassfish.deployment.admin; +import java.net.URI; import java.net.URISyntaxException; import com.sun.enterprise.config.serverbeans.*; import com.sun.enterprise.deploy.shared.ArchiveFactory; @@ -43,7 +44,6 @@ import com.sun.enterprise.util.io.FileUtils; import org.glassfish.api.ActionReport; import org.glassfish.api.I18n; -import org.glassfish.api.container.Sniffer; import org.glassfish.api.admin.AdminCommand; import org.glassfish.api.admin.AdminCommandContext; import org.glassfish.api.admin.CommandRunner; @@ -52,7 +52,6 @@ import org.glassfish.api.admin.ParameterMap; import org.glassfish.api.admin.ServerEnvironment; import org.glassfish.api.deployment.DeployCommandParameters; -import org.glassfish.api.deployment.UndeployCommandParameters; import org.glassfish.api.deployment.DeploymentContext; import org.glassfish.api.deployment.archive.ArchiveHandler; import org.glassfish.api.deployment.archive.ReadableArchive; @@ -75,15 +74,12 @@ import org.jvnet.hk2.config.Transaction; import java.io.File; -import java.io.FileFilter; import java.io.IOException; -import java.net.URI; import java.util.*; import java.util.logging.Level; import java.util.logging.Logger; import java.util.logging.LogRecord; import org.glassfish.api.ActionReport.ExitCode; -import org.glassfish.api.admin.ParameterMap; import org.glassfish.api.admin.Payload; import org.glassfish.api.event.EventListener; import org.glassfish.api.event.Events; @@ -143,7 +139,7 @@ private File safeCopyOfApp = null; private File safeCopyOfDeploymentPlan = null; - private File originalPathValue; + private URI originalPathValue; private boolean isRedeploy = false; private List previousTargets = new ArrayList(); @@ -170,9 +166,10 @@ final ActionReport report = context.getActionReport(); final Logger logger = context.getLogger(); - originalPathValue = path; - if (!path.exists()) { - report.setMessage(localStrings.getLocalString("fnf","File not found", path.getAbsolutePath())); + originalPathValue = getPath(); + File file = getPathAsFile(); + if (file != null && !file.exists()) { + report.setMessage(localStrings.getLocalString("fnf","File not found", file.getAbsolutePath())); report.setActionExitCode(ActionReport.ExitCode.FAILURE); return; } @@ -185,14 +182,15 @@ ReadableArchive archive; try { - archive = archiveFactory.openArchive(path, this); + archive = file != null ? archiveFactory.openArchive(file, this) + : archiveFactory.openArchive(getPath(), this); } catch (IOException e) { final String msg = localStrings.getLocalString("deploy.errOpeningArtifact", - "deploy.errOpeningArtifact", path.getAbsolutePath()); + "deploy.errOpeningArtifact", getPath()); if (logReportedErrors) { report.failure(logger, msg, e); } else { - report.setMessage(msg + path.getAbsolutePath() + e.toString()); + report.setMessage(msg + " " + getPath() + " " + e.toString()); report.setActionExitCode(ActionReport.ExitCode.FAILURE); } return; @@ -202,7 +200,7 @@ ArchiveHandler archiveHandler = deployment.getArchiveHandler(archive); if (archiveHandler==null) { - report.failure(logger,localStrings.getLocalString("deploy.unknownarchivetype","Archive type of {0} was not recognized",path.getName())); + report.failure(logger,localStrings.getLocalString("deploy.unknownarchivetype","Archive type of {0} was not recognized", getPath())); return; } @@ -246,7 +244,7 @@ if (!source.isDirectory()) { isDirectoryDeployed = false; expansionDir = new File(domain.getApplicationRoot(), name); - path = expansionDir; + setPath(expansionDir); } // create the parent class loader @@ -334,7 +332,7 @@ logger.log(Level.INFO, localStrings.getLocalString( "errClosingArtifact", "Error while closing deployable artifact : ", - path.getAbsolutePath()), e); + getPath()), e); } if (report.getActionExitCode().equals(ActionReport.ExitCode.SUCCESS)) { if (report.hasWarnings()) { @@ -384,9 +382,9 @@ } private File renameUploadedFileOrCopyInPlaceFile( - final File finalUploadDir, - final File fileParam, - final Logger logger) throws IOException { + File finalUploadDir, + URI fileParam, + Logger logger) throws IOException { if (fileParam == null) { return null; } @@ -396,43 +394,74 @@ */ final File appsDir = env.getApplicationRepositoryPath(); - /* - * The default answer is the in-place file, to handle the - * directory-deployment case or the in-place archive case if we ae - * not copying the in-place archive. - */ - File result = fileParam; - - if ( ! appsDir.toURI().relativize(fileParam.toURI()).isAbsolute()) { +// /* +// * The default answer is the in-place file, to handle the +// * directory-deployment case or the in-place archive case if we are +// * not copying the in-place archive. +// */ +// File result = fileParam; + + File result; + + if ( ! appsDir.toURI().relativize(fileParam).isAbsolute()) { /* - * The file lies within the apps directory, so it was + * The file lies within the apps directory, so it was * uploaded. */ - result = new File(finalUploadDir, fileParam.getName()); - FileUtils.renameFile(fileParam, result); - result.setLastModified(fileParam.lastModified()); + File file = new File(fileParam); + result = new File(finalUploadDir, file.getName()); + FileUtils.renameFile(file, result); + result.setLastModified(file.lastModified()); } else { + // See if it is actually a file + File file; + try { + file = new File(fileParam); + } catch (IllegalArgumentException iae) { + // it is not a file + file = null; + } + final boolean copyInPlaceArchive = Boolean.valueOf( System.getProperty(COPY_IN_PLACE_ARCHIVE_PROP_NAME, "true")); - if ( ! fileParam.isDirectory() && copyInPlaceArchive) { - /* - * The file was not uploaded and the in-place file is not a directory, - * so copy the archive to the permanent location. - */ - final long startTime = System.currentTimeMillis(); - result = new File(finalUploadDir, fileParam.getName()); + if (file != null) { + if ( ! file.isDirectory() && copyInPlaceArchive) { + /* + * The file was not uploaded and the in-place file is not a directory, + * so copy the archive to the permanent location. + */ + final long startTime = System.currentTimeMillis(); + result = new File(finalUploadDir, file.getName()); + FileUtils.copy(file, result); + result.setLastModified(file.lastModified()); + if (logger.isLoggable(Level.FINE)) { + logger.fine("*** In-place archive copy of " + + file.getAbsolutePath() + " took " + + (System.currentTimeMillis() - startTime) + " ms"); + } + } else { + result = file; + } + } else { + // It is not a file URI. So, we need to copy it + final String child = fileParam.getSchemeSpecificPart(); // FIXME: This is not correct + result = new File(finalUploadDir, child); FileUtils.copy(fileParam, result); - result.setLastModified(fileParam.lastModified()); - if (logger.isLoggable(Level.FINE)) { - logger.fine("*** In-place archive copy of " + - fileParam.getAbsolutePath() + " took " + - (System.currentTimeMillis() - startTime) + " ms"); - } } } return result; } + private File renameUploadedFileOrCopyInPlaceFile( + final File finalUploadDir, + final File fileParam, + final Logger logger) throws IOException { + if (fileParam == null) { + return null; + } + return renameUploadedFileOrCopyInPlaceFile(finalUploadDir, fileParam.toURI(), logger); + } + private void recordFileLocations( final Properties appProps) throws URISyntaxException { /* Index: deployment/common/src/main/java/com/sun/enterprise/deploy/shared/ArchiveFactory.java =================================================================== --- deployment/common/src/main/java/com/sun/enterprise/deploy/shared/ArchiveFactory.java (revision 38356) +++ deployment/common/src/main/java/com/sun/enterprise/deploy/shared/ArchiveFactory.java (working copy) @@ -172,6 +172,19 @@ } } + public ReadableArchive openArchive(URI uri, DeployCommandParameters properties) throws IOException { + for (ReadableArchiveFactory fac : habitat.getAllByContract(ReadableArchiveFactory.class)) { + //get the first ReadableArchive and move + try{ + ReadableArchive archive = fac.open(uri, properties); + if(archive != null) return archive; + }catch(Exception e){ + //ignore? + } + } + return openArchive(uri); + } + /** *Create a URI for the jar specified by the path string. *

@@ -188,4 +201,5 @@ URI answer = new URI(scheme, null /* authority */, archiveURI.getPath(), null /* query */, null /* fragment */); return answer; } + } Index: core/kernel/src/main/java/com/sun/enterprise/v3/server/UpgradeStartup.java =================================================================== --- core/kernel/src/main/java/com/sun/enterprise/v3/server/UpgradeStartup.java (revision 38356) +++ core/kernel/src/main/java/com/sun/enterprise/v3/server/UpgradeStartup.java (working copy) @@ -299,7 +299,7 @@ } logger.log(Level.INFO, "Repackaged application " + app.getName() + " at " + repackagedFile.getPath()); - deployParams.path = repackagedFile; + deployParams.setPath(repackagedFile); } deployParams.properties = app.getDeployProperties(); Index: common/glassfish-api/src/main/java/org/glassfish/api/deployment/DeployCommandParameters.java =================================================================== --- common/glassfish-api/src/main/java/org/glassfish/api/deployment/DeployCommandParameters.java (revision 38356) +++ common/glassfish-api/src/main/java/org/glassfish/api/deployment/DeployCommandParameters.java (working copy) @@ -40,6 +40,7 @@ import org.glassfish.api.I18n; import java.io.File; +import java.net.URI; import java.util.Properties; /** @@ -110,8 +111,10 @@ @Param(optional=true, defaultValue="true") public Boolean logReportedErrors = false; - @Param(primary=true) - public File path; + /** + * @see #setPath + */ + private URI path; @Param(optional=true) public String description; @@ -130,6 +133,38 @@ public String previousContextRoot = null; + + public URI getPath() { + return path; + } + + @Param(primary=true) + public void setPath(URI path) { + // An absolute URI has a scheme, in such a case, we use the URI as is. + // If user has not specified a scheme, then we treat the input as a file system path + if (!path.isAbsolute()) { + setPath(new File(path.getSchemeSpecificPart())); + } else { + this.path = path; + } + } + + public void setPath(File path) { + this.path = path.toURI(); + } + + /** + * + * @return path as a file. If path can't be converted to a file, return null + */ + public File getPathAsFile() { + try { + return new File(path); + } catch (IllegalArgumentException iae) { + return null; + } + } + public String name() { return name; } @@ -142,7 +177,7 @@ } public DeployCommandParameters(File path) { - this.path = path; + this.setPath(path); if (path.getName().lastIndexOf('.')!=-1) { name=path.getName().substring(0, path.getName().lastIndexOf('.')); } else { Index: common/common-util/src/main/java/org/glassfish/common/util/admin/MapInjectionResolver.java =================================================================== --- common/common-util/src/main/java/org/glassfish/common/util/admin/MapInjectionResolver.java (revision 38356) +++ common/common-util/src/main/java/org/glassfish/common/util/admin/MapInjectionResolver.java (working copy) @@ -37,6 +37,7 @@ package org.glassfish.common.util.admin; import java.lang.reflect.*; +import java.net.URI; import java.util.*; import java.io.File; import java.io.IOException; @@ -305,6 +306,8 @@ convertStringToStringArray(paramValStr, param.separator()); } else if (type.isAssignableFrom(File.class)) { return new File(paramValStr); + } else if (type.isAssignableFrom(URI.class)) { + return URI.create(paramValStr); } return paramValue; } Index: common/common-util/src/main/java/com/sun/enterprise/util/io/FileUtils.java =================================================================== --- common/common-util/src/main/java/com/sun/enterprise/util/io/FileUtils.java (revision 38356) +++ common/common-util/src/main/java/com/sun/enterprise/util/io/FileUtils.java (working copy) @@ -61,6 +61,7 @@ package com.sun.enterprise.util.io; import java.io.*; +import java.net.URI; import java.util.*; import com.sun.enterprise.util.OS; @@ -1066,6 +1067,41 @@ return f; } + public static void copy(URI fileParam, File result) throws IOException { + ByteBuffer byteBuffer = ByteBuffer.allocate(1024); + InputStream in = null; + OutputStream out = null; + try { + in = fileParam.toURL().openStream(); + out = new FileOutputStream(result); + ReadableByteChannel inChannel = Channels.newChannel(in); + WritableByteChannel outChannel = Channels.newChannel(out); + + int read; + do { + read = inChannel.read(byteBuffer); + if (read>0) { + byteBuffer.limit(byteBuffer.position()); + byteBuffer.rewind(); + int written = 0; + while((written += outChannel.write(byteBuffer)) < read) {} + byteBuffer.clear(); + } + } while (read != -1); + } finally { + byteBuffer.clear(); + try { + if (in != null) in.close(); + } catch (IOException e) { + } + try { + if (out != null) out.close(); + } catch (IOException e) { + } + } + + } + /** * Represents a unit of work that should be retried, if needed, until it * succeeds or the configured retry limit is reached. Index: ejb/ejb-container/src/main/java/org/glassfish/ejb/embedded/EJBContainerImpl.java =================================================================== --- ejb/ejb-container/src/main/java/org/glassfish/ejb/embedded/EJBContainerImpl.java (revision 38356) +++ ejb/ejb-container/src/main/java/org/glassfish/ejb/embedded/EJBContainerImpl.java (working copy) @@ -45,7 +45,6 @@ import javax.naming.Context; import javax.naming.InitialContext; -import javax.naming.NamingException; import javax.ejb.embeddable.EJBContainer; import javax.ejb.EJBException; import javax.transaction.TransactionManager; @@ -129,7 +128,7 @@ if (app instanceof File) { File f = (File)app; - dp.path = f; + dp.setPath(f); deployedAppName = deployer.deploy(f, dp); } else { deployedAppName = deployer.deploy((ScatteredArchive)app, dp);