use of com.sun.enterprise.deploy.shared.FileArchive in project Payara by payara.
the class AppClientDeployerHelper method JAROfExpandedSubmodule.
/**
* If the specified URI is for an expanded submodule, makes a copy of
* the submodule as a JAR and returns the URI for the copy.
* @param classPathElement
* @return URI to the safe copy of the submodule, relative to the top level
* if the classPathElement is for a submodule; null otherwise
*/
File JAROfExpandedSubmodule(final URI candidateSubmoduleURI) throws IOException {
ReadableArchive source = new FileArchive();
source.open(dc().getSource().getParentArchive().getURI().resolve(expandedDirURI(candidateSubmoduleURI)));
OutputJarArchive target = new OutputJarArchive();
target.create(dc().getScratchDir("xml").toURI().resolve(candidateSubmoduleURI));
/*
* Copy the manifest explicitly because the ReadableArchive
* entries() method omits it.
*/
Manifest mf = source.getManifest();
OutputStream os = target.putNextEntry(JarFile.MANIFEST_NAME);
mf.write(os);
target.closeEntry();
copyArchive(source, target, Collections.EMPTY_SET);
target.close();
return new File(target.getURI());
}
use of com.sun.enterprise.deploy.shared.FileArchive 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);
}
use of com.sun.enterprise.deploy.shared.FileArchive in project Payara by payara.
the class FacadeLaunchable method newFacade.
/**
* Returns a Facade object for the specified app client group facade.
* <p>
* The caller-supplied information is used to select the first app client
* facade in the app client group that matches either the main class or
* the app client name. If the caller-supplied values are both null then
* the method returns the first app client facade in the group. If the
* caller passes at least one non-null selector (main class or app client
* name) but no app client matches, the method returns null.
*
* @param groupFacadeURI URI to the app client group facade
* @param callerSuppliedMainClassName main class name to find; null if
* the caller does not require selection based on the main class name
* @param callerSuppliedAppName (display) nane of the app client to find; null
* if the caller does not require selection based on display name
* @return a Facade object representing the selected app client facade;
* null if at least one of callerSuppliedMainClasName and callerSuppliedAppName
* is not null and no app client matched the selection criteria
* @throws java.io.IOException
* @throws com.sun.enterprise.module.bootstrap.BootException
* @throws java.net.URISyntaxException
* @throws javax.xml.stream.XMLStreamException
*/
static FacadeLaunchable newFacade(final ServiceLocator habitat, final ReadableArchive facadeRA, final String callerSuppliedMainClassName, final String callerSuppliedAppName) throws IOException, BootException, URISyntaxException, XMLStreamException, SAXParseException, UserError {
Manifest mf = facadeRA.getManifest();
if (mf == null) {
throw new UserError(MessageFormat.format(logger.getResourceBundle().getString("appclient.noMFInFacade"), facadeRA instanceof FileArchive ? 1 : 0, new File(facadeRA.getURI().getPath()).getAbsolutePath()));
}
final Attributes mainAttrs = mf.getMainAttributes();
FacadeLaunchable result = null;
if (mainAttrs.containsKey(GLASSFISH_APPCLIENT)) {
if (!(facadeRA instanceof HTTPInputArchive)) {
result = new FacadeLaunchable(habitat, mainAttrs, facadeRA, dirContainingStandAloneFacade(facadeRA));
} else {
result = new JWSFacadeLaunchable(habitat, mainAttrs, facadeRA);
}
} else {
/*
* The facade does not contain GlassFish-AppClient so if it is
* a facade it must be an app client group facade. Select
* which app client facade within the group, if any, matches
* the caller's selection criteria.
*/
final String facadeGroupURIs = mainAttrs.getValue(GLASSFISH_APPCLIENT_GROUP);
if (facadeGroupURIs != null) {
result = selectFacadeFromGroup(habitat, facadeRA.getURI(), archiveFactory, facadeGroupURIs, callerSuppliedMainClassName, callerSuppliedAppName, dirContainingClientFacadeInGroup(facadeRA));
} else {
return null;
}
}
return result;
}
use of com.sun.enterprise.deploy.shared.FileArchive in project Payara by payara.
the class ConnectorsUtil method extractRar.
/**
* GlassFish (Embedded) Uber jar will have .rar bundled in it.
* This method will extract the .rar from the uber jar into specified directory.
* As of now, this method is only used in EMBEDDED mode
* @param fileName rar-directory-name
* @param rarName resource-adapter name
* @param destDir destination directory
* @return status indicating whether .rar is exploded successfully or not
*/
public static boolean extractRar(String fileName, String rarName, String destDir) {
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(rarName);
if (is != null) {
FileArchive fa = new FileArchive();
OutputStream os = null;
try {
os = fa.putNextEntry(fileName);
FileUtils.copy(is, os, 0);
} catch (IOException e) {
Object[] args = new Object[] { rarName, e };
_logger.log(Level.WARNING, "error.extracting.archive", args);
return false;
} finally {
try {
if (os != null) {
fa.closeEntry();
}
} catch (IOException ioe) {
if (_logger.isLoggable(Level.FINEST)) {
_logger.log(Level.FINEST, "Exception while closing archive [ " + fileName + " ]", ioe);
}
}
try {
is.close();
} catch (IOException ioe) {
if (_logger.isLoggable(Level.FINEST)) {
_logger.log(Level.FINEST, "Exception while closing archive [ " + rarName + " ]", ioe);
}
}
}
File file = new File(fileName);
if (file.exists()) {
try {
extractJar(file, destDir);
} catch (Exception e) {
e.printStackTrace();
}
return true;
} else {
_logger.log(Level.INFO, "could not find RAR [ " + rarName + " ] location [ " + fileName + " ] " + "after extraction");
return false;
}
} else {
_logger.log(Level.INFO, "could not find RAR [ " + rarName + " ] in the archive, skipping .rar extraction");
return false;
}
}
use of com.sun.enterprise.deploy.shared.FileArchive in project Payara by payara.
the class WebServicesDeployer method populateWsdlFilesForPublish.
/**
* Populate the wsdl files entries to download (if any) (Only for webservices which use file
* publishing).
*
* TODO File publishing currently works only for wsdls packaged in the application for jax-ws. Need
* to publish the dynamically generated wsdls as well. Lazy creation of WSEndpoint objects prohibits
* it now.
*/
private Set<String> populateWsdlFilesForPublish(DeploymentContext dc, Set<WebService> webservices) throws IOException {
Set<String> publishedFiles = new HashSet<String>();
for (WebService webService : webservices) {
if (!webService.hasFilePublishing()) {
continue;
}
copyExtraFilesToGeneratedFolder(dc);
BundleDescriptor bundle = webService.getBundleDescriptor();
ArchiveType moduleType = bundle.getModuleType();
// only EAR, WAR and EJB archives could contain wsdl files for publish
if (moduleType == null || !(moduleType.equals(DOLUtils.earType()) || moduleType.equals(DOLUtils.warType()) || moduleType.equals(DOLUtils.ejbType()))) {
return publishedFiles;
}
File sourceDir = dc.getScratchDir("xml");
File parent;
try {
URI clientPublishURI = webService.getClientPublishUrl().toURI();
if (!clientPublishURI.isOpaque()) {
parent = new File(clientPublishURI);
} else {
parent = new File(webService.getClientPublishUrl().getPath());
}
} catch (URISyntaxException e) {
logger.log(Level.WARNING, LogUtils.EXCEPTION_THROWN, e);
parent = new File(webService.getClientPublishUrl().getPath());
}
// Collect the names of all entries in or below the
// dedicated wsdl directory.
FileArchive archive = new FileArchive();
archive.open(sourceDir.toURI());
Enumeration entries = archive.entries(bundle.getWsdlDir());
while (entries.hasMoreElements()) {
String name = (String) entries.nextElement();
String wsdlName = stripWsdlDir(name, bundle);
File clientwsdl = new File(parent, wsdlName);
File fulluriFile = new File(sourceDir, name);
if (!fulluriFile.isDirectory()) {
publishFile(fulluriFile, clientwsdl);
publishedFiles.add(clientwsdl.getAbsolutePath());
}
}
}
return publishedFiles;
}
Aggregations