Search in sources :

Example 1 with MemoryMappedArchive

use of com.sun.enterprise.deployment.deploy.shared.MemoryMappedArchive in project Payara by payara.

the class SunDeploymentManager method deploy.

/**
 *Deploy the specified module to the list of targets.
 *The deployment plan archive can be null.
 *@param Target[] the targets to which to deploy the module
 *@param File the archive stream to be deployed
 *@param File the (optional) deployment plan stream
 *@param options set by the caller to override and augment any settings made here
 *@return ProgressObject to communicate progress and results of the deployment
 *@exception IllegalStateException if the DeploymentManager has disconnected
 *@exception IOException if there are problems working with the input streams
 */
private ProgressObject deploy(Target[] targetList, InputStream moduleStream, InputStream deploymentPlanStream, Properties presetOptions) throws IllegalStateException {
    /*
         *Create archives for the module's input stream and, if present, the deployment plan's
         *input stream, and then delegate to the variant of deploy that accepts archives as
         *arguments.
         */
    MemoryMappedArchive moduleArchive = null;
    MemoryMappedArchive deploymentPlanArchive = null;
    try {
        moduleArchive = new MemoryMappedArchive(moduleStream);
        if (deploymentPlanStream != null) {
            deploymentPlanArchive = new MemoryMappedArchive(deploymentPlanStream);
        }
        return deploy(targetList, moduleArchive, deploymentPlanArchive, presetOptions);
    } catch (Throwable e) {
        String msg = localStrings.getLocalString("enterprise.deployapi.spi.errpreparearchstream", "Could not prepare archives for module and/or deployment plan input streams");
        IllegalArgumentException ex = new IllegalArgumentException(msg);
        ex.initCause(e);
        return prepareErrorProgressObject(CommandType.DISTRIBUTE, ex);
    }
}
Also used : MemoryMappedArchive(com.sun.enterprise.deployment.deploy.shared.MemoryMappedArchive)

Example 2 with MemoryMappedArchive

use of com.sun.enterprise.deployment.deploy.shared.MemoryMappedArchive in project Payara by payara.

the class ConnectorDDTransformUtils method getResourceAdapterClassName.

public static String getResourceAdapterClassName(String rarLocation) {
    // class through the connector descriptor
    try {
        FileInputStream fis = new FileInputStream(rarLocation);
        MemoryMappedArchive mma = new MemoryMappedArchive(fis);
        ConnectorArchivist ca = new ConnectorArchivist();
        ConnectorDescriptor cd = (ConnectorDescriptor) ca.open(mma);
        return cd.getResourceAdapterClass();
    } catch (IOException e) {
        _logger.info(e.getMessage());
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, "Error while trying to read connector" + "descriptor to get resource-adapter properties", e);
        }
    } catch (SAXParseException e) {
        _logger.info(e.getMessage());
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, "Error while trying to read connector" + "descriptor to get resource-adapter properties", e);
        }
    }
    return null;
}
Also used : ConnectorArchivist(com.sun.enterprise.connectors.deployment.util.ConnectorArchivist) SAXParseException(org.xml.sax.SAXParseException) MemoryMappedArchive(com.sun.enterprise.deployment.deploy.shared.MemoryMappedArchive) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 3 with MemoryMappedArchive

use of com.sun.enterprise.deployment.deploy.shared.MemoryMappedArchive in project Payara by payara.

the class AbstractDeploymentFacility method deploy.

public DFProgressObject deploy(Target[] targets, ReadableArchive source, ReadableArchive deploymentPlan, Map deploymentOptions) throws IOException {
    if (source == null) {
        throw new IllegalArgumentException();
    }
    File tempSourceFile = null;
    File tempPlanFile = null;
    if (source instanceof MemoryMappedArchive) {
        try {
            String type = (String) deploymentOptions.remove("type");
            tempSourceFile = writeMemoryMappedArchiveToTempFile((MemoryMappedArchive) source, getSuffixFromType(type));
            URI tempPlanURI = null;
            if (deploymentPlan != null && deploymentPlan instanceof MemoryMappedArchive) {
                tempPlanFile = writeMemoryMappedArchiveToTempFile((MemoryMappedArchive) deploymentPlan, ".jar");
                tempPlanURI = tempPlanFile.toURI();
            }
            return deploy(targets, tempSourceFile.toURI(), tempPlanURI, deploymentOptions);
        } finally {
            if (tempSourceFile != null) {
                boolean isDeleted = tempSourceFile.delete();
                if (!isDeleted) {
                    deplLogger.log(Level.WARNING, FILE_DELETION_ERROR, tempSourceFile.getAbsolutePath());
                }
            }
            if (tempPlanFile != null) {
                boolean isDeleted = tempPlanFile.delete();
                if (!isDeleted) {
                    deplLogger.log(Level.WARNING, FILE_DELETION_ERROR, tempPlanFile.getAbsolutePath());
                }
            }
        }
    } else {
        if (deploymentPlan == null) {
            return deploy(targets, source.getURI(), null, deploymentOptions);
        } else {
            return deploy(targets, source.getURI(), deploymentPlan.getURI(), deploymentOptions);
        }
    }
}
Also used : MemoryMappedArchive(com.sun.enterprise.deployment.deploy.shared.MemoryMappedArchive) File(java.io.File) URI(java.net.URI)

Example 4 with MemoryMappedArchive

use of com.sun.enterprise.deployment.deploy.shared.MemoryMappedArchive in project Payara by payara.

the class MainClassLaunchable method createArchive.

// private ReadableArchive createArchive(final ClassLoader loader,
// final Class mainClass) throws IOException, URISyntaxException {
// Manifest mf = new Manifest();
// mf.getMainAttributes().put(Attributes.Name.MAIN_CLASS, mainClass.getName());
// final File tempFile = File.createTempFile("acc", ".jar");
// tempFile.deleteOnExit();
// JarOutputStream jos = new JarOutputStream(
// new BufferedOutputStream(new FileOutputStream(tempFile)), mf);
// final String mainClassResourceName = mainClass.getName().replace('.', '/') + ".class";
// final ZipEntry mainClassEntry = new ZipEntry(mainClassResourceName);
// jos.putNextEntry(mainClassEntry);
// InputStream is = loader.getResourceAsStream(mainClassResourceName);
// int bytesRead;
// byte[] buffer = new byte[1024];
// while ( (bytesRead = is.read(buffer)) != -1) {
// jos.write(buffer, 0, bytesRead);
// }
// is.close();
// jos.closeEntry();
// jos.close();
// 
// final InputJarArchive result = new InputJarArchive();
// result.open(new URI("jar", tempFile.toURI().toASCIIString(), null));
// return result;
// }
private ReadableArchive createArchive(final ClassLoader loader, final Class mainClass) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Manifest mf = new Manifest();
    Attributes mainAttrs = mf.getMainAttributes();
    /*
         * Note - must set the version or the attributes won't write
         * themselves to the output stream!
         */
    mainAttrs.put(Attributes.Name.MANIFEST_VERSION, "1.0");
    mainAttrs.put(Attributes.Name.MAIN_CLASS, mainClass.getName());
    JarOutputStream jos = new JarOutputStream(baos, mf);
    final String mainClassResourceName = mainClass.getName().replace('.', '/') + ".class";
    final ZipEntry mainClassEntry = new ZipEntry(mainClassResourceName);
    jos.putNextEntry(mainClassEntry);
    InputStream is = loader.getResourceAsStream(mainClassResourceName);
    int bytesRead;
    byte[] buffer = new byte[1024];
    while ((bytesRead = is.read(buffer)) != -1) {
        jos.write(buffer, 0, bytesRead);
    }
    is.close();
    jos.closeEntry();
    jos.close();
    MemoryMappedArchive mma = new MemoryMappedArchive(baos.toByteArray());
    /*
         * Some archive-related processing looks for the file type from the URI, so set it
         * to something.
         */
    mma.setURI(URI.create("file:///tempClient.jar"));
    return mma;
}
Also used : InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) MemoryMappedArchive(com.sun.enterprise.deployment.deploy.shared.MemoryMappedArchive) Attributes(java.util.jar.Attributes) JarOutputStream(java.util.jar.JarOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Manifest(java.util.jar.Manifest)

Aggregations

MemoryMappedArchive (com.sun.enterprise.deployment.deploy.shared.MemoryMappedArchive)4 ConnectorArchivist (com.sun.enterprise.connectors.deployment.util.ConnectorArchivist)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 Attributes (java.util.jar.Attributes)1 JarOutputStream (java.util.jar.JarOutputStream)1 Manifest (java.util.jar.Manifest)1 ZipEntry (java.util.zip.ZipEntry)1 SAXParseException (org.xml.sax.SAXParseException)1