|
Glassfish example source code file (AppClientFacade.java)
The Glassfish AppClientFacade.java source code/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development * and Distribution License("CDDL") (collectively, the "License"). You * may not use this file except in compliance with the License. You can * obtain a copy of the License at * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html * or packager/legal/LICENSE.txt. See the License for the specific * language governing permissions and limitations under the License. * * When distributing the software, include this License Header Notice in each * file and include the License file at packager/legal/LICENSE.txt. * * GPL Classpath Exception: * Oracle designates this particular file as subject to the "Classpath" * exception as provided by Oracle in the GPL Version 2 section of the License * file that accompanied this code. * * Modifications: * If applicable, add the following below the License Header, with the fields * enclosed by brackets [] replaced by your own identifying information: * "Portions Copyright [year] [name of copyright owner]" * * Contributor(s): * If you wish your version of this file to be governed by only the CDDL or * only the GPL Version 2, indicate your decision by adding "[Contributor] * elects to include this software in this distribution under the [CDDL or GPL * Version 2] license." If you don't indicate a single choice of license, a * recipient has the option to distribute your version of this file under * either the CDDL, the GPL Version 2 or to extend the choice of license to * its licensees as provided above. However, if you add GPL Version 2 code * and therefore, elected the GPL Version 2 license, then the option applies * only if the new code is made subject to such option by the copyright * holder. */ package org.glassfish.appclient.client; import com.sun.enterprise.container.common.spi.util.InjectionException; import com.sun.enterprise.deployment.node.SaxParserHandlerBundled; import com.sun.enterprise.universal.glassfish.TokenResolver; import com.sun.enterprise.util.LocalStringManager; import com.sun.enterprise.util.LocalStringManagerImpl; import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.CharArrayWriter; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.io.StringReader; import java.lang.instrument.Instrumentation; import java.lang.reflect.InvocationTargetException; import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; import java.util.Enumeration; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Properties; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import javax.xml.transform.sax.SAXSource; import org.glassfish.appclient.client.acc.ACCClassLoader; import org.glassfish.appclient.client.acc.ACCLogger; import org.glassfish.appclient.client.acc.AgentArguments; import org.glassfish.appclient.client.acc.AppClientContainer; import org.glassfish.appclient.client.acc.AppClientContainer.Builder; import org.glassfish.appclient.client.acc.AppclientCommandArguments; import org.glassfish.appclient.client.acc.CommandLaunchInfo; import org.glassfish.appclient.client.acc.CommandLaunchInfo.ClientLaunchType; import org.glassfish.appclient.client.acc.TargetServerHelper; import org.glassfish.appclient.client.acc.UserError; import org.glassfish.appclient.client.acc.Util; import org.glassfish.appclient.client.acc.config.AuthRealm; import org.glassfish.appclient.client.acc.config.ClientContainer; import org.glassfish.appclient.client.acc.config.ClientCredential; import org.glassfish.appclient.client.acc.config.MessageSecurityConfig; import org.glassfish.appclient.client.acc.config.Property; import org.glassfish.appclient.client.acc.config.TargetServer; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; import org.xml.sax.XMLReader; /** * * @author tjquinn */ public class AppClientFacade { private static final String SUN_ACC_CONTENT_PROPERTY_NAME = "sun-acc.xml.content"; private static final String MAN_PAGE_PATH = "/org/glassfish/appclient/client/acc/appclient.1m"; private static final Class<?> stringsAnchor = ACCClassLoader.class; private static LocalStringManager localStrings = new LocalStringManagerImpl(stringsAnchor); private static CommandLaunchInfo launchInfo = null; private static AppclientCommandArguments appClientCommandArgs = null; private static URI installRootURI = null; private static AppClientContainer acc = null; private static boolean isJWS = false; /** * Prepares the ACC (if not already done by the agent) and then transfers * control to the ACC. * <p> * Eventually, the Java runtime will invoke this method as the main method * of the application, whether or not the command line specified the * Java agent. If the agent has already run, then it will have prepared * the ACC already. If the agent has not already run, then this method * prepares it. * <p> * If the user has run the generated app client JAR directly - not using * the appclient script - then the Java runtime will invoke this method * directly and the command-line arguments should be intended for the client * only; no agent or ACC settings are possible. If the user has used the * appclient script, then the script will have created a Java command which * specifies the agent, constructs an agent argument string, and passes as * command line arguments only those values which should be passed to the * client. The net result is that, no matter how the app client was * launched, the args array contains only the arguments that are for the * client's consumption, without any agent or ACC arguments. * * @param args the command line arguments */ public static void main(String[] args) { try { if (acc == null) { /* * The facade JAR has been run directly, not via the appclient * script and not via Java Web Start. So we have no agent * arguments and no instrumentation for registering transformations. * * Because the agent has not run, we prepare the ACC here. (The * agent would have done so itself had it run.) */ prepareACC(null, null); } /* * In any case, the ACC is now prepared. Launch the app client in * the prepared ACC. */ acc.launch(args); } catch (Exception ex) { ex.printStackTrace(); System.exit(1); } catch (UserError ue) { ue.displayAndExit(); } } public static AppClientContainer acc() { return acc; } public static void launch(String[] args) throws NoSuchMethodException, ClassNotFoundException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, IOException, SAXParseException, InjectionException, UserError { acc.launch(args); } public static void prepareACC(String agentArgsText, Instrumentation inst) throws UserError, MalformedURLException, URISyntaxException, JAXBException, FileNotFoundException, ParserConfigurationException, SAXException, IOException, Exception { JavaVersion javaVersion = new JavaVersion(); if (javaVersion.asInt() < 16) { throw new UserError(localStrings.getLocalString( stringsAnchor, "main.badVersion", "Current Java version {0} is too low; {1} or later required", new Object[] {javaVersion.versionString, "1.6"})); } /* * 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) { throw new IllegalArgumentException(); } /* * 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; } private static AppClientContainer prepareACC() { // XXX Implement this to support java -jar launching. return null; } private static void usage(final int exitStatus) { System.err.println(getUsage()); System.exit(exitStatus); } private static void help() throws IOException { final InputStream is = AppClientFacade.class.getResourceAsStream(MAN_PAGE_PATH); if (is == null) { usage(0); } final BufferedReader helpReader = new BufferedReader(new InputStreamReader(is)); String line; try { while ((line = helpReader.readLine()) != null) { System.err.println(line); } } finally { if (is != null) { is.close(); } System.exit(0); } } private static String getUsage() { return localStrings.getLocalString( stringsAnchor, "main.usage", "appclient [ <classfile> | -client Other Glassfish examples (source code examples)Here is a short list of links related to this Glassfish AppClientFacade.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.