Search in sources :

Example 1 with ClientContainer

use of org.glassfish.appclient.client.acc.config.ClientContainer in project Payara by payara.

the class AppClientFacade method prepareACC.

public static void prepareACC(String agentArgsText, Instrumentation inst) throws UserError, MalformedURLException, URISyntaxException, JAXBException, FileNotFoundException, ParserConfigurationException, SAXException, IOException, Exception {
    if (!JDK.isRunningLTSJDK()) {
        logger.warning("You are running the product on an unsupported JDK version and might see unexpected results or exceptions.");
    }
    /*
         * Analyze the agent argument string.
         */
    AgentArguments agentArgs = AgentArguments.newInstance(agentArgsText);
    /*
         * The agent arguments that correspond to the ones that we want to
         * pass to the ACC are the ones with the "arg=" keyword prefix.  These
         * will include arguments with meaning to the ACC (-textauth for example)
         * as well as arguments to be passed on to the client's main method.
         */
    appClientCommandArgs = AppclientCommandArguments.newInstance(agentArgs.namedValues("arg"));
    if (appClientCommandArgs.isUsage()) {
        usage(0);
    } else if (appClientCommandArgs.isHelp()) {
        help();
    }
    /*
         * Examine the agent arguments for settings about how to launch the
         * client.
         */
    launchInfo = CommandLaunchInfo.newInstance(agentArgs);
    if (launchInfo.getClientLaunchType() == ClientLaunchType.UNKNOWN) {
        usage(1);
    }
    /*
         * Handle the legacy env. variable APPCPATH.
         */
    ACCClassLoader loader = initClassLoader((inst == null));
    Thread.currentThread().setContextClassLoader(loader);
    isJWS = Boolean.getBoolean("appclient.is.jws");
    /*
         * The installRoot property will be set by the ServerEnvironment
         * initialization using the ACC start-up context.  That happens during
         * the ACCModulesManager warm-up.
         */
    /*
         * Load the ACC configuration XML file.
         */
    ClientContainer clientContainer = readConfig(appClientCommandArgs.getConfigFilePath(), loader);
    /*
         * Decide what target servers to use.  This combines any
         * specified on the command line with any in the config file's
         * target-server elements as well as any set in the properties
         * of the config file.
         */
    final TargetServer[] targetServers = TargetServerHelper.targetServers(clientContainer, appClientCommandArgs.getTargetServer());
    /*
         * Get the builder.  Doing so correctly involves merging
         * the configuration file data with some of the command line and
         * agent arguments.
         */
    final AppClientContainer.Builder builder = createBuilder(targetServers, clientContainer, appClientCommandArgs);
    /*
         * Create the ACC.  Again, precisely how we create it depends on some
         * of the command line arguments and agent arguments.
         */
    final AppClientContainer newACC = createContainer(builder, launchInfo, appClientCommandArgs);
    /*
         * Because the JMV might invoke the client's main class, the agent
         * needs to prepare the container.  (This is done as part of the
         * AppClientContainer.start() processing in the public API.
         */
    newACC.prepare(inst);
    acc = newACC;
}
Also used : Builder(org.glassfish.appclient.client.acc.AppClientContainer.Builder) ACCClassLoader(org.glassfish.appclient.client.acc.ACCClassLoader) ClientContainer(org.glassfish.appclient.client.acc.config.ClientContainer) AppClientContainer(org.glassfish.appclient.client.acc.AppClientContainer) AppClientContainer(org.glassfish.appclient.client.acc.AppClientContainer) AgentArguments(org.glassfish.appclient.client.acc.AgentArguments) TargetServer(org.glassfish.appclient.client.acc.config.TargetServer)

Example 2 with ClientContainer

use of org.glassfish.appclient.client.acc.config.ClientContainer in project Payara by payara.

the class AppClientFacade method readConfig.

private static ClientContainer readConfig(final String configPath, final ClassLoader loader) throws UserError, JAXBException, FileNotFoundException, ParserConfigurationException, SAXException, URISyntaxException, IOException {
    ClientContainer result = null;
    Reader configReader = null;
    String configFileLocationForErrorMessage = "";
    try {
        /*
             * During a Java Web Start launch, the config is passed as a property
             * value.
             */
        String configInProperty = System.getProperty(ACC_CONFIG_CONTENT_PROPERTY_NAME);
        if (configInProperty != null) {
            /*
                 * Awkwardly, the glassfish-acc.xml content refers to a config file.
                 * We work around this for Java Web Start launch by capturing the
                 * content of that config file into a property setting in the
                 * generated JNLP document.  We need to write that content into
                 * a temporary file here on the client and then replace a
                 * placeholder in the glassfish-acc.xml content with the path to that
                 * temp file.
                 */
            final File securityConfigTempFile = Util.writeTextToTempFile(configInProperty, "wss-client-config", ".xml", false);
            final Properties p = new Properties();
            p.setProperty("security.config.path", securityConfigTempFile.getAbsolutePath());
            configInProperty = Util.replaceTokens(configInProperty, p);
            configReader = new StringReader(configInProperty);
        } else {
            /*
                 * This is not a Java Web Start launch, so read the configuration
                 * from a disk file.
                 */
            File configFile = checkXMLFile(configPath);
            checkXMLFile(appClientCommandArgs.getConfigFilePath());
            configReader = new FileReader(configFile);
            configFileLocationForErrorMessage = configFile.getAbsolutePath();
        }
        /*
             * Although JAXB makes it very simple to parse the XML into Java objects,
             * we have to do several things explicitly to use our local copies of
             * DTDs and XSDs.
             */
        SAXParserFactory spf = SAXParserFactory.newInstance();
        spf.setValidating(true);
        spf.setNamespaceAware(true);
        SAXParser parser = spf.newSAXParser();
        XMLReader reader = parser.getXMLReader();
        /*
             * Get the local entity resolver that knows about the
             * bundled .dtd and .xsd files.
             */
        reader.setEntityResolver(new SaxParserHandlerBundled());
        /*
             * To support installation-directory independence the default glassfish-acc.xml
             * refers to the wss-config file using ${com.sun.aas.installRoot}...  So
             * preprocess the glassfish-acc.xml file to replace any tokens with the
             * corresponding values, then submit that result to JAXB.
             */
        InputSource inputSource = replaceTokensForParsing(configReader);
        SAXSource saxSource = new SAXSource(reader, inputSource);
        JAXBContext jc = JAXBContext.newInstance(ClientContainer.class);
        final ValidationEventCollector vec = new ValidationEventCollector();
        Unmarshaller u = jc.createUnmarshaller();
        u.setEventHandler(vec);
        result = (ClientContainer) u.unmarshal(saxSource);
        if (vec.hasEvents()) {
            /*
                 * The parser reported at least one warning or error.  If all
                 * events were warnings, display them as a message and continue.
                 * Otherwise there was at least one error or fatal, so say so
                 * and try to continue but say that such errors might be fatal
                 * in future releases.
                 */
            boolean isError = false;
            final StringBuilder sb = new StringBuilder();
            for (ValidationEvent ve : vec.getEvents()) {
                sb.append(ve.getMessage()).append(LINE_SEP);
                isError |= (ve.getSeverity() != ValidationEvent.WARNING);
            }
            final String messageIntroduction = localStrings.getLocalString(AppClientFacade.class, isError ? "appclient.errParsingConfig" : "appclient.warnParsingConfig", isError ? "Error parsing app client container configuration {0}.  Attempting to continue.  In future releases such parsing errors might become fatal.  Please correct your configuration file." : "Warning(s) parsing app client container configuration {0}.  Continuing.", new Object[] { configFileLocationForErrorMessage });
            /*
                 * Following code - which throws an exception if the config
                 * validation fails - is commented out to prevent possible
                 * regressions.  Users might have customized the acc config file
                 * in a way that does not validate but would have worked silently
                 * before.
                 */
            // if (isErrorOrWorse) {
            // throw new UserError(messageIntroduction,
            // new ValidationException(sb.toString()));
            // } else {
            System.err.println(messageIntroduction + LINE_SEP + sb.toString());
        // }
        }
        return result;
    } finally {
        if (configReader != null) {
            configReader.close();
        }
    }
}
Also used : InputSource(org.xml.sax.InputSource) ClientContainer(org.glassfish.appclient.client.acc.config.ClientContainer) AppClientContainer(org.glassfish.appclient.client.acc.AppClientContainer) Reader(java.io.Reader) XMLReader(org.xml.sax.XMLReader) InputStreamReader(java.io.InputStreamReader) StringReader(java.io.StringReader) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) Properties(java.util.Properties) SaxParserHandlerBundled(com.sun.enterprise.deployment.node.SaxParserHandlerBundled) SAXSource(javax.xml.transform.sax.SAXSource) StringReader(java.io.StringReader) SAXParser(javax.xml.parsers.SAXParser) FileReader(java.io.FileReader) File(java.io.File) ValidationEventCollector(javax.xml.bind.util.ValidationEventCollector) XMLReader(org.xml.sax.XMLReader) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 3 with ClientContainer

use of org.glassfish.appclient.client.acc.config.ClientContainer in project Payara by payara.

the class XMLTest method readConfig.

private static ClientContainer readConfig(final String configPath) throws JAXBException, FileNotFoundException, ParserConfigurationException, SAXException, IOException {
    ClientContainer result = null;
    InputStream is = XMLTest.class.getResourceAsStream(configPath);
    try {
        if (is == null) {
            fail("cannot locate test file " + configPath);
        }
        JAXBContext jc = JAXBContext.newInstance(ClientContainer.class);
        Unmarshaller u = jc.createUnmarshaller();
        final SAXSource src = setUpToUseLocalDTDs(is);
        result = (ClientContainer) u.unmarshal(src);
        return result;
    } finally {
        is.close();
    }
}
Also used : SAXSource(javax.xml.transform.sax.SAXSource) InputStream(java.io.InputStream) ClientContainer(org.glassfish.appclient.client.acc.config.ClientContainer) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 4 with ClientContainer

use of org.glassfish.appclient.client.acc.config.ClientContainer in project Payara by payara.

the class XMLTest method testReadSampleXML.

@Test
public void testReadSampleXML() throws Exception {
    System.out.println("testReadSampleXML");
    for (String sampleXMLPath : SAMPLE_XML_PATH) {
        System.out.println("  Testing with " + sampleXMLPath);
        ClientContainer cc = readConfig(sampleXMLPath);
        List<TargetServer> servers = cc.getTargetServer();
        assertTrue("target servers did not read correctly from " + sampleXMLPath, servers.get(0).getAddress().equals(FIRST_HOST) && servers.get(0).getPort().equals(FIRST_PORT) && servers.get(1).getAddress().equals(SECOND_HOST) && servers.get(1).getPort() == SECOND_PORT);
    }
}
Also used : ClientContainer(org.glassfish.appclient.client.acc.config.ClientContainer) TargetServer(org.glassfish.appclient.client.acc.config.TargetServer) Test(org.junit.Test)

Example 5 with ClientContainer

use of org.glassfish.appclient.client.acc.config.ClientContainer in project Payara by payara.

the class XMLTest method testProps.

@Test
public void testProps() throws Exception {
    System.out.println("testProps");
    for (String sampleXMLPath : SAMPLE_XML_PATH) {
        System.out.println("  Testing with " + sampleXMLPath);
        ClientContainer cc = readConfig(sampleXMLPath);
        Properties props = XML.toProperties(cc.getProperty());
        assertEquals("property value mismatch for first property from " + sampleXMLPath, FIRST_PROP_VALUE, props.getProperty(FIRST_PROP_NAME));
        assertEquals("property value mismatch for second property from " + sampleXMLPath, SECOND_PROP_VALUE, props.getProperty(SECOND_PROP_NAME));
    }
}
Also used : ClientContainer(org.glassfish.appclient.client.acc.config.ClientContainer) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

ClientContainer (org.glassfish.appclient.client.acc.config.ClientContainer)5 Properties (java.util.Properties)2 SAXSource (javax.xml.transform.sax.SAXSource)2 AppClientContainer (org.glassfish.appclient.client.acc.AppClientContainer)2 TargetServer (org.glassfish.appclient.client.acc.config.TargetServer)2 Test (org.junit.Test)2 SaxParserHandlerBundled (com.sun.enterprise.deployment.node.SaxParserHandlerBundled)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileReader (java.io.FileReader)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 JAXBContext (javax.xml.bind.JAXBContext)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 ValidationEventCollector (javax.xml.bind.util.ValidationEventCollector)1 SAXParser (javax.xml.parsers.SAXParser)1 SAXParserFactory (javax.xml.parsers.SAXParserFactory)1 ACCClassLoader (org.glassfish.appclient.client.acc.ACCClassLoader)1