Package com.sun.enterprise.admin.servermgmt

Examples of com.sun.enterprise.admin.servermgmt.DomainException


    private void initialize() throws DomainException {
        String templateJarPath = (String)_domainConfig.get(DomainConfig.K_TEMPLATE_NAME);
        if (templateJarPath == null || templateJarPath.isEmpty()) {
            String defaultTemplateName = Version.getDefaultDomainTemplate();
            if (defaultTemplateName == null || defaultTemplateName.isEmpty()) {
                throw new DomainException(_strings.get("missingDefaultTemplateName"));
            }
            Map<String, String> envProperties = new ASenvPropertyReader().getProps();
            templateJarPath = envProperties.get(SystemPropertyConstants.INSTALL_ROOT_PROPERTY) + File.separator
                    + DEFUALT_TEMPLATE_RELATIVE_PATH + File.separator + defaultTemplateName;
        }
        File template = new File(templateJarPath);
        if (!template.exists() || !template.getName().endsWith(".jar")) {
            throw new DomainException(_strings.get("invalidTemplateJar", template.getAbsolutePath()));
        }
        try {
            _templateJar = new JarFile(new File(templateJarPath));
            JarEntry je = _templateJar.getJarEntry("config/" + DomainConstants.DOMAIN_XML_FILE);
            if (je == null) {
                throw new DomainException(_strings.get("missingMandatoryFile", DomainConstants.DOMAIN_XML_FILE));
            }
            // Loads template-info.xml
            je = _templateJar.getJarEntry(TEMPLATE_INFO_XML);
            if (je == null) {
                throw new DomainException(_strings.get("missingMandatoryFile", TEMPLATE_INFO_XML));
            }
            TemplateInfoHolder templateInfoHolder = new TemplateInfoHolder(_templateJar.getInputStream(je), templateJarPath);
            _extractedEntries.add(TEMPLATE_INFO_XML);

            // Loads string substitution XML.
            je = _templateJar.getJarEntry(STRINGSUBS_FILE);
            StringSubstitutor stringSubstitutor = null;
            if (je != null) {
                stringSubstitutor = StringSubstitutionFactory.createStringSubstitutor(_templateJar.getInputStream(je));
                List<Property> defaultStringSubsProps = stringSubstitutor.getDefaultProperties(PropertyType.PORT);
                for (Property prop : defaultStringSubsProps) {
                    _defaultPortValues.setProperty(prop.getKey(), prop.getValue());
                }
                _extractedEntries.add(je.getName());
            } else {
                _logger.log(Level.WARNING, _strings.get("missingFile", STRINGSUBS_FILE));
            }
            _domainTempalte = new DomainTemplate(templateInfoHolder, stringSubstitutor, templateJarPath);

            // Loads default self signed certificate.
            je = _templateJar.getJarEntry("config/" + DomainConstants.KEYSTORE_FILE);
            if (je != null) {
                _keystoreBytes = new byte[(int)je.getSize()];
                InputStream in = null;
                int count = 0;
                try {
                    in = _templateJar.getInputStream(je);
                    count = in.read(_keystoreBytes);
                    if (count < _keystoreBytes.length) {
                        throw new DomainException(_strings.get("loadingFailure", je.getName()));
                    }
                } finally {
                    if (in != null) {
                        in.close();
                    }
                }
                _extractedEntries.add(je.getName());
            }
            File parentDomainDir = FileUtils.safeGetCanonicalFile(new File(_domainConfig.getRepositoryRoot()));
            createDirectory(parentDomainDir);
        } catch (Exception e) {
            throw new DomainException(e);
        }
    };
View Full Code Here


            // Validate other domain config parameters.
            new PEDomainConfigValidator().validate(_domainConfig);

        } catch (Exception ex) {
            throw new DomainException(ex);
        }
    }
View Full Code Here

            try {
                //4958533
                domainSecurity.changeMode("-R u+x "new File(domainDir, DomainConstants.BIN_DIR));
                domainSecurity.changeMode("-R g-rwx,o-rwx ", configDir);
            } catch (Exception e) {
                throw new DomainException(_strings.get("setPermissionError"), e);
            }

            // Generate domain-info.xml
            DomainInfoManager domainInfoManager = new DomainInfoManager();
            domainInfoManager.process(_domainTempalte, domainDir);
        } catch (DomainException de) {
            //roll-back
            FileUtils.liquidate(domainDir);
            throw de;
        } catch (Exception ex) {
            //roll-back
            FileUtils.liquidate(domainDir);
            throw new DomainException(ex);
        }
    }
View Full Code Here

                try {
                    reader = new FileReader(domainXMLFile);
                    char[] buf = new char[(int)domainXMLFile.length()];
                    count = reader.read(buf);
                    if (count < buf.length) {
                        throw new DomainException(_strings.get("loadingFailure", domainXMLFile.getAbsolutePath()));
                    }
                    loadedDomainXML = new String(buf);
                } finally {
                    if (reader != null) {
                        reader.close();
                    }
                }

                // Check presence of token place-holder
                if (loadedDomainXML.indexOf(CUSTOM_TOKEN_PLACE_HOLDER) != -1) {
                    Set<String> existingSysProps = new HashSet<String>();
                    Pattern sysPropTagPattern = Pattern.compile("<system-property.*?>");
                    Pattern nameAttributePattern = Pattern.compile("name=[\\\"](.*?)[\\\"]");
                    Matcher sysPropTagMatcher = sysPropTagPattern.matcher(loadedDomainXML);
                    while (sysPropTagMatcher.find()) {
                        String systemTag = sysPropTagMatcher.group();
                        Matcher nameTagMatcher = nameAttributePattern.matcher(systemTag);
                        while (nameTagMatcher.find()) {
                            String strs[] = nameTagMatcher.group().split("\"");
                            if (strs != null && strs.length == 2) {
                                existingSysProps.add(strs[1]);
                            }
                        }
                    }
                    Set<Integer> usedPorts = new HashSet<Integer>();
                    Properties domainProps = _domainConfig.getDomainProperties();
                    String portBase = (String)_domainConfig.get(DomainConfig.K_PORTBASE);

                    Map<String, String> filePaths = new HashMap<String, String>(3, 1);
                    filePaths.put(SystemPropertyConstants.INSTALL_ROOT_PROPERTY, System.getProperty(SystemPropertyConstants.INSTALL_ROOT_PROPERTY));
                    filePaths.put(SystemPropertyConstants.INSTANCE_ROOT_PROPERTY, System.getProperty(SystemPropertyConstants.INSTANCE_ROOT_PROPERTY));
                    filePaths.put(SystemPropertyConstants.JAVA_ROOT_PROPERTY, System.getProperty(SystemPropertyConstants.JAVA_ROOT_PROPERTY));
                    int noOfTokens = customTokens.size();
                    String lineSeparator = System.getProperty("line.separator");
                    for (ConfigCustomizationToken token : customTokens) {
                        String key = token.getName();
                        // Check for valid custom token parameters.
                        if (isNullOrEmpty(key) || isNullOrEmpty(token.getValue()) || isNullOrEmpty(token.getDescription())) {
                            throw new IllegalArgumentException(_strings.get("invalidTokenParameters", key, token.getValue(), token.getDescription()));
                        }
                        // Skipping the token processing if token already exist in domain.xml
                        if (existingSysProps.contains(key)) {
                            _logger.log(Level.FINER, _strings.get("existingCustomToken", key));
                            continue;
                        }
                        switch (token.getCustomizationType()) {
                            case PORT :
                                Integer port = null;
                                if (domainProps.containsKey(token.getName())) {
                                    port = Integer.valueOf(domainProps.getProperty(token.getName()));
                                    if (!NetUtils.isPortFree(port)) {
                                        throw new DomainException(_strings.get("unavailablePort", port));
                                    }
                                } else {
                                    if (portBase != null && token.getTokenTypeDetails() instanceof PortTypeDetails) {
                                        PortTypeDetails portTypeDetails = (PortTypeDetails)token.getTokenTypeDetails();
                                        port = Integer.valueOf(domainProps.getProperty(token.getName())) + Integer.valueOf(portTypeDetails.getBaseOffset());
                                        generatedTokens.put(PORTBASE_PLACE_HOLDER, SystemPropertyTagBuilder.buildSystemTag(
                                                PORTBASE_PLACE_HOLDER, portBase));
                                    } else {
                                        port = Integer.valueOf(token.getValue());
                                    }
                                    while (!NetUtils.isPortFree(port) && !usedPorts.contains(port++));
                                }
                                usedPorts.add(port);
                                newlyCreatedSysProps.append(SystemPropertyTagBuilder.buildSystemTag(token, port.toString()));
                                break;
                            case FILE:
                                String path = token.getValue();
                                for (Map.Entry<String, String> entry : filePaths.entrySet()) {
                                    if (path.contains(entry.getKey())) {
                                        path = path.replace(entry.getKey(), entry.getValue());
                                        break;
                                    }
                                }
                                if (token.getTokenTypeDetails() instanceof FileTypeDetails) {
                                    FileTypeDetails details = (FileTypeDetails) token.getTokenTypeDetails();
                                    File file = new File(path);
                                    switch (details.getExistCondition()) {
                                        case MUST_EXIST:
                                            if (!file.exists()) {
                                                throw new DomainException(_strings.get("missingFile", file.getAbsolutePath()));
                                            }
                                            break;
                                        case MUST_NOT_EXIST:
                                            if (file.exists()) {
                                                throw new DomainException(_strings.get("filePresenceNotDesired", file.getAbsolutePath()));
                                            }
                                            break;
                                        case NO_OP:
                                            break;
                                    }
                                }
                                newlyCreatedSysProps.append(SystemPropertyTagBuilder.buildSystemTag(token, path));
                                break;
                            case STRING:
                                break;
                        }
                        if (--noOfTokens > 1) {
                            newlyCreatedSysProps.append(lineSeparator);
                        }
                    }
                    generatedTokens.put(CUSTOM_TOKEN_PLACE_HOLDER, newlyCreatedSysProps.toString());
                }
            }
        } catch (DomainException de) {
            throw de;
        } catch (Exception ex) {
            throw new DomainException(ex);
        }
        return generatedTokens;
    }
View Full Code Here

        try {
            // Loads template-info.xml
            _templateJar = new JarFile(new File(templateJarPath));
            JarEntry je = _templateJar.getJarEntry(TEMPLATE_INFO_XML);
            if (je == null) {
                throw new DomainException(_strings.get("missingMandatoryFile", TEMPLATE_INFO_XML));
            }
            TemplateInfoHolder templateInfoHolder = new TemplateInfoHolder(_templateJar.getInputStream(je), templateJarPath);
            extractedEntries.add(TEMPLATE_INFO_XML);

            // Loads string substitution XML.
            je = _templateJar.getJarEntry(STRINGSUBS_FILE);
            StringSubstitutor stringSubstitutor = null;
            if (je != null) {
                stringSubstitutor = StringSubstitutionFactory.createStringSubstitutor(_templateJar.getInputStream(je));
                List<Property> defaultStringSubsProps = stringSubstitutor.getDefaultProperties(PropertyType.PORT);
                for (Property prop : defaultStringSubsProps) {
                    _defaultPortValues.setProperty(prop.getKey(), prop.getValue());
                }
                extractedEntries.add(je.getName());
            } else {
                _logger.log(Level.WARNING, _strings.get("missingFile", STRINGSUBS_FILE));
            }
            _domainTempalte = new DomainTemplate(templateInfoHolder, stringSubstitutor);

            // Loads default self signed certificate.
            je = _templateJar.getJarEntry("config/" + DomainConstants.KEYSTORE_FILE);
            if (je != null) {
                keystoreBytes = new byte[(int)je.getSize()];
                InputStream in = null;
                int count = 0;
                try {
                    in = _templateJar.getInputStream(je);
                    count = in.read(keystoreBytes);
                    if (count < keystoreBytes.length) {
                        throw new DomainException(_strings.get("loadingFailure", je.getName()));
                    }
                } finally {
                    if (in != null) {
                        in.close();
                    }
                }
                extractedEntries.add(je.getName());
            }
        } catch (Exception e) {
            throw new DomainException(e);
        }
    };
View Full Code Here

            // Validate other domain config parameters.
            new PEDomainConfigValidator().validate(_domainConfig);

        } catch (Exception ex) {
            throw new DomainException(ex);
        }
    }
View Full Code Here

                //4958533
                domainSecurity.changeMode("-R u+x ", new File(domainDir, DomainConstants.BIN_DIR));
                domainSecurity.changeMode("-R g-rwx,o-rwx ", configDir);
                //4958533
            } catch (Exception e) {
                throw new DomainException(_strings.get("setPermissionError"), e);
            }

            // Generate domain-info.xml
            DomainInfoManager domainInfoManager = new DomainInfoManager();
            domainInfoManager.process(_domainTempalte, domainDir);

        } catch (DomainException de) {
            //roll-back
            FileUtils.liquidate(domainDir);
            throw de;
        } catch (Exception ex) {
            //roll-back
            FileUtils.liquidate(domainDir);
            throw new DomainException(ex);
        }
    };
View Full Code Here

    public TemplateInfoHolder(InputStream inputSteam, String location)
            throws DomainException {
        try {
            _templateInfo = parse(inputSteam);
        } catch (Exception e) {
            throw new DomainException(_strings.get("failedToParse", TEMPLATE_INFO_SCHEMA_PATH));
        }
        _location = location;
    }
View Full Code Here

     */
    @SuppressWarnings("rawtypes")
    private TemplateInfo parse(InputStream configStream)
            throws Exception {
        if (configStream == null) {
            throw new DomainException("Invalid stream");
        }
        try {
            URL schemaUrl = getClass().getClassLoader().getResource(TEMPLATE_INFO_SCHEMA_PATH);
            JAXBContext context = JAXBContext.newInstance(TemplateInfo.class.getPackage().getName());
            Unmarshaller unmarshaller = context.createUnmarshaller();
View Full Code Here

    private void initialize() throws DomainException {
        String templateJarPath = (String)_domainConfig.get(DomainConfig.K_TEMPLATE_NAME);
        if (templateJarPath == null || templateJarPath.isEmpty()) {
            String defaultTemplateName = Version.getDefaultDomainTemplate();
            if (defaultTemplateName == null || defaultTemplateName.isEmpty()) {
                throw new DomainException(_strings.get("missingDefaultTemplateName"));
            }
            Map<String, String> envProperties = new ASenvPropertyReader().getProps();
            templateJarPath = envProperties.get(SystemPropertyConstants.INSTALL_ROOT_PROPERTY) + File.separator
                    + DEFUALT_TEMPLATE_RELATIVE_PATH + File.separator + defaultTemplateName;
        }
        File template = new File(templateJarPath);
        if (!template.exists() || !template.getName().endsWith(".jar")) {
            throw new DomainException(_strings.get("invalidTemplateJar", template.getAbsolutePath()));
        }
        try {
            _templateJar = new JarFile(new File(templateJarPath));
            JarEntry je = _templateJar.getJarEntry("config/" + DomainConstants.DOMAIN_XML_FILE);
            if (je == null) {
                throw new DomainException(_strings.get("missingMandatoryFile", DomainConstants.DOMAIN_XML_FILE));
            }
            // Loads template-info.xml
            je = _templateJar.getJarEntry(TEMPLATE_INFO_XML);
            if (je == null) {
                throw new DomainException(_strings.get("missingMandatoryFile", TEMPLATE_INFO_XML));
            }
            TemplateInfoHolder templateInfoHolder = new TemplateInfoHolder(_templateJar.getInputStream(je), templateJarPath);
            _extractedEntries.add(TEMPLATE_INFO_XML);

            // Loads string substitution XML.
            je = _templateJar.getJarEntry(STRINGSUBS_FILE);
            StringSubstitutor stringSubstitutor = null;
            if (je != null) {
                stringSubstitutor = StringSubstitutionFactory.createStringSubstitutor(_templateJar.getInputStream(je));
                List<Property> defaultStringSubsProps = stringSubstitutor.getDefaultProperties(PropertyType.PORT);
                for (Property prop : defaultStringSubsProps) {
                    _defaultPortValues.setProperty(prop.getKey(), prop.getValue());
                }
                _extractedEntries.add(je.getName());
            } else {
                _logger.log(Level.WARNING, SLogger.MISSING_FILE, STRINGSUBS_FILE);
            }
            _domainTempalte = new DomainTemplate(templateInfoHolder, stringSubstitutor, templateJarPath);

            // Loads default self signed certificate.
            je = _templateJar.getJarEntry("config/" + DomainConstants.KEYSTORE_FILE);
            if (je != null) {
                _keystoreBytes = new byte[(int)je.getSize()];
                InputStream in = null;
                int count = 0;
                try {
                    in = _templateJar.getInputStream(je);
                    count = in.read(_keystoreBytes);
                    if (count < _keystoreBytes.length) {
                        throw new DomainException(_strings.get("loadingFailure", je.getName()));
                    }
                } finally {
                    if (in != null) {
                        in.close();
                    }
                }
                _extractedEntries.add(je.getName());
            }
            File parentDomainDir = FileUtils.safeGetCanonicalFile(new File(_domainConfig.getRepositoryRoot()));
            createDirectory(parentDomainDir);
        } catch (Exception e) {
            throw new DomainException(e);
        }
    };
View Full Code Here

TOP

Related Classes of com.sun.enterprise.admin.servermgmt.DomainException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.