Search in sources :

Example 1 with MultiReadableArchive

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

the class ACCPersistenceArchivist method clientURI.

private URI clientURI(final ReadableArchive archive, final ApplicationClientDescriptor acDesc) throws IOException {
    if (archive instanceof MultiReadableArchive) {
        /*
             * Getting the manifest from a MultiReadableArchive returns the
             * manifest from the facade.
             */
        final Manifest facadeMF = archive.getManifest();
        final Attributes facadeMainAttrs = facadeMF.getMainAttributes();
        final URI clientRelativeURI = URI.create(facadeMainAttrs.getValue(AppClientArchivist.GLASSFISH_APPCLIENT));
        if (isDeployedClientAlsoStandAlone(facadeMainAttrs)) {
            return clientRelativeURI;
        }
        /*
             * We need the relative URI to the developer's client JAR within
             * the download directory.
             */
        final URI absURIToClient = ((MultiReadableArchive) archive).getURI(1);
        final String relativeURIPathToAnchorDir = facadeMainAttrs.getValue(AppClientArchivist.GLASSFISH_ANCHOR_DIR);
        final URI absURIToAnchorDir = archive.getURI().resolve(relativeURIPathToAnchorDir);
        return absURIToAnchorDir.relativize(absURIToClient);
    }
    return archive.getURI();
}
Also used : Attributes(java.util.jar.Attributes) MultiReadableArchive(com.sun.enterprise.deployment.deploy.shared.MultiReadableArchive) Manifest(java.util.jar.Manifest) URI(java.net.URI)

Example 2 with MultiReadableArchive

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

the class AppClientScanner method doProcess.

/**
 * This scanner will scan the given main class for annotation processing.
 * The archiveFile and libJarFiles correspond to classpath.
 * @param archiveFile
 * @param desc
 * @param classLoader
 */
private void doProcess(ReadableArchive archive, ApplicationClientDescriptor desc, ClassLoader classLoader) throws IOException {
    if (AnnotationUtils.getLogger().isLoggable(Level.FINE)) {
        AnnotationUtils.getLogger().fine("archiveFile is " + archive.getURI().toASCIIString());
        AnnotationUtils.getLogger().fine("classLoader is " + classLoader);
    }
    // always add main class
    String mainClassName = desc.getMainClassName();
    addScanClassName(mainClassName);
    // add callback handle if it exist in appclient-client.xml
    String callbackHandler = desc.getCallbackHandler();
    if (callbackHandler != null && !callbackHandler.trim().equals("")) {
        addScanClassName(desc.getCallbackHandler());
    }
    GenericAnnotationDetector detector = new GenericAnnotationDetector(managedBeanAnnotations);
    if (detector.hasAnnotationInArchive(archive)) {
        if (archive instanceof FileArchive) {
            addScanDirectory(new File(archive.getURI()));
        } else if (archive instanceof InputJarArchive) {
            /*
                 * This is during deployment, so use the faster code path using
                 * the File object.
                 */
            URI uriToAdd = archive.getURI();
            addScanJar(scanJar(uriToAdd));
        } else if (archive instanceof MultiReadableArchive) {
            /*
                 * During app client launches, scan the developer's archive
                 * which is in slot #1, not the facade archive which is in
                 * slot #0.  Also, use URIs instead of File objects because
                 * during Java Web Start launches we don't have access to
                 * File objects.
                 */
            addScanURI(scanURI(((MultiReadableArchive) archive).getURI(1)));
        }
    }
    this.classLoader = classLoader;
    // = archive;
    this.archiveFile = null;
}
Also used : InputJarArchive(com.sun.enterprise.deployment.deploy.shared.InputJarArchive) GenericAnnotationDetector(org.glassfish.deployment.common.GenericAnnotationDetector) FileArchive(com.sun.enterprise.deploy.shared.FileArchive) MultiReadableArchive(com.sun.enterprise.deployment.deploy.shared.MultiReadableArchive) File(java.io.File) URI(java.net.URI)

Example 3 with MultiReadableArchive

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

the class FacadeLaunchable method openCombinedReadableArchive.

private static MultiReadableArchive openCombinedReadableArchive(final ServiceLocator habitat, final ReadableArchive facadeRA, final ReadableArchive clientRA) throws IOException {
    final MultiReadableArchive combinedRA = habitat.getService(MultiReadableArchive.class);
    combinedRA.open(facadeRA.getURI(), clientRA.getURI());
    return combinedRA;
}
Also used : MultiReadableArchive(com.sun.enterprise.deployment.deploy.shared.MultiReadableArchive)

Example 4 with MultiReadableArchive

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

the class FacadeLaunchable method selectFacadeFromGroup.

private static FacadeLaunchable selectFacadeFromGroup(final ServiceLocator habitat, final URI groupFacadeURI, final ArchiveFactory af, final String groupURIs, final String callerSpecifiedMainClassName, final String callerSpecifiedAppClientName, final String anchorDir) throws IOException, BootException, URISyntaxException, SAXParseException, UserError {
    String[] archiveURIs = groupURIs.split(" ");
    /*
         * Search the app clients in the group in order, checking each for
         * a match on either the caller-specified main class or the caller-specified
         * client name.
         */
    if (archiveURIs.length == 0) {
        final String msg = MessageFormat.format(logger.getResourceBundle().getString("appclient.noClientsInGroup"), groupFacadeURI);
        throw new UserError(msg);
    }
    /*
         * Save the client names and main classes in case we need them in an
         * error to the user.
         */
    final List<String> knownClientNames = new ArrayList<String>();
    final List<String> knownMainClasses = new ArrayList<String>();
    for (String uriText : archiveURIs) {
        URI clientFacadeURI = groupFacadeURI.resolve(uriText);
        ReadableArchive clientFacadeRA = af.openArchive(clientFacadeURI);
        Manifest facadeMF = clientFacadeRA.getManifest();
        if (facadeMF == null) {
            throw new UserError(MessageFormat.format(logger.getResourceBundle().getString("appclient.noMFInFacade"), clientFacadeRA instanceof FileArchive ? 1 : 0, new File(clientFacadeRA.getURI().getPath()).getAbsolutePath()));
        }
        Attributes facadeMainAttrs = facadeMF.getMainAttributes();
        if (facadeMainAttrs == null) {
            throw new UserError(MessageFormat.format(logger.getResourceBundle().getString("appclient.MFMissingEntry"), new File(clientFacadeRA.getURI().getPath()).getAbsolutePath(), GLASSFISH_APPCLIENT));
        }
        final String gfAppClient = facadeMainAttrs.getValue(GLASSFISH_APPCLIENT);
        if (gfAppClient == null || gfAppClient.length() == 0) {
            throw new UserError(MessageFormat.format(logger.getResourceBundle().getString("appclient.MFMissingEntry"), new File(clientFacadeRA.getURI().getPath()).getAbsolutePath(), GLASSFISH_APPCLIENT));
        }
        URI clientURI = clientFacadeURI.resolve(gfAppClient);
        ReadableArchive clientRA = af.openArchive(clientURI);
        if (!clientRA.exists()) {
            throw new UserError(MessageFormat.format(logger.getResourceBundle().getString("appclient.missingClient"), new File(clientRA.getURI().getSchemeSpecificPart()).getAbsolutePath()));
        }
        AppClientArchivist facadeClientArchivist = getArchivist(habitat);
        MultiReadableArchive combinedRA = openCombinedReadableArchive(habitat, clientFacadeRA, clientRA);
        final ApplicationClientDescriptor facadeClientDescriptor = facadeClientArchivist.open(combinedRA);
        final String moduleID = Launchable.LaunchableUtil.moduleID(groupFacadeURI, clientURI, facadeClientDescriptor);
        final Manifest clientMF = clientRA.getManifest();
        if (clientMF == null) {
            throw new UserError(MessageFormat.format(logger.getResourceBundle().getString("appclient.noMFInFacade"), clientRA instanceof FileArchive ? 1 : 0, new File(clientRA.getURI().getSchemeSpecificPart()).getAbsolutePath()));
        }
        Attributes mainAttrs = clientMF.getMainAttributes();
        if (mainAttrs == null) {
            throw new UserError(MessageFormat.format(logger.getResourceBundle().getString("appclient.MFMissingEntry"), new File(clientFacadeRA.getURI().getPath()).getAbsolutePath(), Attributes.Name.MAIN_CLASS.toString()));
        }
        final String clientMainClassName = mainAttrs.getValue(Attributes.Name.MAIN_CLASS);
        if (clientMainClassName == null || clientMainClassName.length() == 0) {
            throw new UserError(MessageFormat.format(logger.getResourceBundle().getString("appclient.MFMissingEntry"), new File(clientFacadeRA.getURI().getPath()).getAbsolutePath(), Attributes.Name.MAIN_CLASS.toString()));
        }
        knownMainClasses.add(clientMainClassName);
        knownClientNames.add(moduleID);
        /*
             * Look for an entry corresponding to the
             * main class or app name the caller requested.  Treat as a%
             * special case if the user specifies no main class and no
             * app name - use the first app client present.  Also use the
             * first app client if there is only one present; warn if
             * the user specified a main class or a name but it does not
             * match the single app client that's present.
             */
        FacadeLaunchable facade = null;
        if (Launchable.LaunchableUtil.matchesAnyClass(clientRA, callerSpecifiedMainClassName)) {
            facade = new FacadeLaunchable(habitat, clientFacadeRA, facadeMainAttrs, clientRA, callerSpecifiedMainClassName, anchorDir);
            /*
                 * If the caller-specified class name does not match the
                 * Main-Class setting for this client archive then inform the user.
                 */
            if (!clientMainClassName.equals(callerSpecifiedMainClassName)) {
                logger.log(Level.INFO, MessageFormat.format(logger.getResourceBundle().getString("appclient.foundMainClassDiffFromManifest"), new Object[] { groupFacadeURI, moduleID, callerSpecifiedMainClassName, clientMainClassName }));
            }
        } else if (Launchable.LaunchableUtil.matchesName(moduleID, groupFacadeURI, facadeClientDescriptor, callerSpecifiedAppClientName)) {
            /*
                 * Get the main class name from the matching client JAR's manifest.
                 */
            facade = new FacadeLaunchable(habitat, clientFacadeRA, facadeMainAttrs, clientRA, clientMainClassName, anchorDir);
        } else if (archiveURIs.length == 1) {
            /*
                 * If only one client exists, use the main class recorded in
                 * the group facade unless the caller specified one.
                 */
            facade = new FacadeLaunchable(habitat, clientFacadeRA, facadeMainAttrs, clientRA, (callerSpecifiedMainClassName != null ? callerSpecifiedMainClassName : facadeMainAttrs.getValue(GLASSFISH_APPCLIENT_MAIN_CLASS)), anchorDir);
            /*
                 * If the user specified a main class or an app name then warn
                 * if that value does not match the one client we found - but
                 * go ahead an run it anyway.
                 */
            if ((callerSpecifiedMainClassName != null && !clientMainClassName.equals(callerSpecifiedMainClassName)) || (callerSpecifiedAppClientName != null && !Launchable.LaunchableUtil.matchesName(moduleID, groupFacadeURI, facadeClientDescriptor, callerSpecifiedAppClientName))) {
                logger.log(Level.WARNING, MessageFormat.format(logger.getResourceBundle().getString("appclient.singleNestedClientNoMatch"), new Object[] { groupFacadeURI, knownClientNames.toString(), knownMainClasses.toString(), callerSpecifiedMainClassName, callerSpecifiedAppClientName }));
            }
        }
        if (facade != null) {
            return facade;
        }
    }
    /*
         * No client facade matched the caller-provided selection (either
         * main class name or app client name), or there are multiple clients
         * but the caller did not specify either mainClass or name.
         * Yet we know we're working
         * with a group facade, so report the failure to find a matching
         * client as an error.
         */
    String msg;
    if ((callerSpecifiedAppClientName == null) && (callerSpecifiedMainClassName == null)) {
        final String format = logger.getResourceBundle().getString("appclient.multClientsNoChoice");
        msg = MessageFormat.format(format, knownMainClasses.toString(), knownClientNames.toString());
    } else {
        final String format = logger.getResourceBundle().getString("appclient.noMatchingClientInGroup");
        msg = MessageFormat.format(format, groupFacadeURI, callerSpecifiedMainClassName, callerSpecifiedAppClientName, knownMainClasses.toString(), knownClientNames.toString());
    }
    throw new UserError(msg);
}
Also used : ArrayList(java.util.ArrayList) Attributes(java.util.jar.Attributes) AppClientArchivist(com.sun.enterprise.deployment.archivist.AppClientArchivist) ACCAppClientArchivist(org.glassfish.appclient.common.ACCAppClientArchivist) MultiReadableArchive(com.sun.enterprise.deployment.deploy.shared.MultiReadableArchive) ApplicationClientDescriptor(com.sun.enterprise.deployment.ApplicationClientDescriptor) Manifest(java.util.jar.Manifest) URI(java.net.URI) FileArchive(com.sun.enterprise.deploy.shared.FileArchive) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) MultiReadableArchive(com.sun.enterprise.deployment.deploy.shared.MultiReadableArchive) File(java.io.File)

Aggregations

MultiReadableArchive (com.sun.enterprise.deployment.deploy.shared.MultiReadableArchive)4 URI (java.net.URI)3 FileArchive (com.sun.enterprise.deploy.shared.FileArchive)2 File (java.io.File)2 Attributes (java.util.jar.Attributes)2 Manifest (java.util.jar.Manifest)2 ApplicationClientDescriptor (com.sun.enterprise.deployment.ApplicationClientDescriptor)1 AppClientArchivist (com.sun.enterprise.deployment.archivist.AppClientArchivist)1 InputJarArchive (com.sun.enterprise.deployment.deploy.shared.InputJarArchive)1 ArrayList (java.util.ArrayList)1 ReadableArchive (org.glassfish.api.deployment.archive.ReadableArchive)1 ACCAppClientArchivist (org.glassfish.appclient.common.ACCAppClientArchivist)1 GenericAnnotationDetector (org.glassfish.deployment.common.GenericAnnotationDetector)1