use of com.sun.enterprise.deploy.shared.FileArchive in project Payara by payara.
the class ASEntBeanPmDescriptors method testPmDescriptor.
/**
* @param i int
* @param result Result
* @param idVerMap Map
* @param descriptor EjbDescriptor
*/
protected void testPmDescriptor(int i, Result result, Map<String, String> idVerMap, EjbDescriptor descriptor) {
try {
String value = null;
// pm-identifier
String pmIdentifier = getXPathValue("sun-ejb-jar/enterprise-beans/pm-descriptors/pm-descriptor[\"" + i + "\"]/pm-identifier");
if (pmIdentifier == null || pmIdentifier.length() == 0) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed2", "FAILED [AS-EJB pm-descriptor] : pm-identifier cannot be an empty string"));
oneFailed = true;
} else {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed2", "PASSED [AS-EJB pm-descriptor] : pm-identifier is {0}", new Object[] { pmIdentifier }));
}
// pm-version
String pmVersion = getXPathValue("sun-ejb-jar/enterprise-beans/pm-descriptors/pm-descriptor[\"" + i + "\"]/pm-version");
if (pmVersion == null || pmVersion.length() == 0) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed3", "FAILED [AS-EJB pm-descritor] : pm-version cannot be an empty string"));
oneFailed = true;
} else {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed3", "PASSED [AS-EJB pm-descriptor] : pm-version is {0}", new Object[] { pmVersion }));
}
if (pmIdentifier != null && pmVersion != null)
idVerMap.put(pmIdentifier, pmVersion);
// pm-config
value = getXPathValue("sun-ejb-jar/enterprise-beans/pm-descriptors/pm-descriptor[\"" + i + "\"]/pm-config");
if (value != null) {
// //// //4698035
if (value.length() == 0) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
oneFailed = true;
result.failed(smh.getLocalString(getClass().getName() + ".failed4", "FAILED [AS-EJB pm-descritor] : pm-config cannot be an empty string"));
} else {
// File f = Verifier.getArchiveFile(descriptor.getEjbBundleDescriptor().getModuleDescriptor().getArchiveUri());
JarFile jarFile = null;
InputStream deploymentEntry = null;
try {
// if (f==null){
String uri = getAbstractArchiveUri(descriptor);
try {
FileArchive arch = new FileArchive();
arch.open(uri);
deploymentEntry = arch.getEntry(value);
} catch (Exception e) {
}
if (deploymentEntry != null) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed4", "PASSED [AS-EJB pm-descriptor] : pm-config is {0}", new Object[] { value }));
} else {
result.addWarningDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
oneWarning = true;
result.warning(smh.getLocalString(getClass().getName() + ".warning3", "WARNING [AS-EJB pm-descriptor] : config file {0} pointed in pm-config is not present in the jar file", new Object[] { value }));
}
} catch (Exception e) {
} finally {
try {
if (jarFile != null)
jarFile.close();
if (deploymentEntry != null)
deploymentEntry.close();
} catch (Exception x) {
}
}
}
// ///////
}
// pm-class-generator
value = getXPathValue("sun-ejb-jar/enterprise-beans/pm-descriptors/pm-descriptor[\"" + i + "\"]/pm-class-generator");
if (value == null || value.length() == 0) {
// check for spec version accordingly give error or warning
Float specVer = getRuntimeSpecVersion();
if ((Float.compare(specVer.floatValue(), (new Float("2.1")).floatValue()) >= 0)) {
oneFailed = true;
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed13", "FAILED [AS-EJB pm-descriptor] : pm-class-generator cannot be empty."));
}
} else {
if (value.trim().indexOf(" ") != -1) {
oneFailed = true;
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed7", "FAILED [AS-EJB pm-descriptor] : pm-class-generator class name is invalid"));
} else {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed5", "PASSED [AS-EJB pm-descriptor] : pm-class-generator is {0}", new Object[] { value }));
}
}
// pm-mapping-factory
value = getXPathValue("sun-ejb-jar/enterprise-beans/pm-descriptors/pm-descriptor[\"" + i + "\"]/pm-mapping-factory");
if (value != null) {
if (value.trim().indexOf(" ") != -1) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
oneFailed = true;
result.failed(smh.getLocalString(getClass().getName() + ".failed8", "FAILED [AS-EJB pm-descriptor] : pm-mapping-factory class name is invalid"));
} else {
if (value.trim().length() == 0) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
oneFailed = true;
result.failed(smh.getLocalString(getClass().getName() + ".failed6", "FAILED [AS-EJB pm-descritor] : pm-pm-mapping-factory cannot be an empty string"));
} else {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed6", "PASSED [AS-EJB pm-descriptor] : pm-mapping-factory is {0}", new Object[] { value }));
}
}
}
} catch (RuntimeException ex) {
oneFailed = true;
result.failed(smh.getLocalString(getClass().getName() + ".notRun", "NOT RUN [AS-EJB] Could not create descriptor Object."));
} finally {
}
}
use of com.sun.enterprise.deploy.shared.FileArchive in project Payara by payara.
the class ConnectorPublicID method check.
/**
* Connector PUBLIC identifier test
* The Connector deployment descriptor has PUBLIC identifier with a PubidLiteral
* of "-//Sun Microsystems, Inc.//DTD Connector 1.0//EN"
*
* @param descriptor the Connector deployment descriptor
*
* @return <code>Result</code> the results for this assertion
*/
public Result check(ConnectorDescriptor descriptor) {
Result result = getInitializedResult();
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
String[] acceptablePubidLiterals = { "-//Sun Microsystems, Inc.//DTD Connector 1.0//EN" };
String[] acceptableURLs = { "http://java.sun.com/dtd/connector_1_0.dtd" };
// open the jar and read the XML deployment descriptor
if (descriptor.getSpecVersion().compareTo("1.5") < 0) {
InputStream deploymentEntry = null;
BufferedReader in = null;
String uri = null;
try {
uri = getAbstractArchiveUri(descriptor);
FileArchive arch = new FileArchive();
arch.open(uri);
deploymentEntry = arch.getEntry(ConnectorDeploymentDescriptorFile.DESC_PATH);
if (deploymentEntry != null) {
in = new BufferedReader(new InputStreamReader(deploymentEntry));
String s = in.readLine();
boolean foundDOCTYPE = false, foundPubid = false, foundURL = false;
while (s != null) {
// did we find the DOCTYPE entry?
if (s.indexOf("DOCTYPE") > -1)
foundDOCTYPE = true;
if (foundDOCTYPE) {
for (int i = 0; i < acceptablePubidLiterals.length; i++) {
if (s.indexOf(acceptablePubidLiterals[i]) > -1) {
foundPubid = true;
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "The deployment descriptor has the proper PubidLiteral: {0}", new Object[] { acceptablePubidLiterals[i] }));
}
if (s.indexOf(acceptableURLs[i]) > -1) {
foundURL = true;
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed1", "The deployment descriptor has the proper URL corresponding to the PubIdLiteral: {0}", new Object[] { acceptableURLs[i] }));
}
}
}
if (foundPubid && foundURL) {
result.setStatus(Result.PASSED);
break;
} else // DOCTYPE doesn't have any more lines to check
if (foundDOCTYPE && s.endsWith(">"))
break;
s = in.readLine();
}
if (!foundDOCTYPE) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed1", "No document type declaration found in the deployment descriptor for {0}", new Object[] { descriptor.getName() }));
} else if (!foundPubid) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed2", "The deployment descriptor for {0} does not have an expected PubidLiteral ", new Object[] { descriptor.getName() }));
} else if (!foundURL) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed", "The deployment descriptor {0} doesnot have the right URL corresponding to the PubIdLiteral", new Object[] { descriptor.getName() }));
}
}
} catch (IOException e) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".IOException", "I/O error trying to open {0}", new Object[] { uri }));
} finally {
try {
if (in != null)
in.close();
if (deploymentEntry != null)
deploymentEntry.close();
} catch (Exception x) {
}
}
} else {
// NOT APPLICABLE
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "NOT-APPLICABLE: No DOCTYPE found for [ {0} ]", new Object[] { descriptor.getName() }));
}
return result;
}
use of com.sun.enterprise.deploy.shared.FileArchive in project Payara by payara.
the class VerifierTest method testFileExistence.
/**
* <p>
* Test for a file existence in the archive file
* </p>
*
* @param uri The archive to look in
* @param fileName The file Name to look for
* @param fileID The archive file name
* @param result where to place the result
*/
public static void testFileExistence(String uri, String fileName, String fileID, Result result) {
FileArchive arch = null;
// ZipEntry ze=null;
JarFile jarFile = null;
if (fileName == null || fileName.length() == 0) {
result.notApplicable(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.VerifierTest.fileexistence.notApplicable", "No {0} defined in deployment descriptors", new Object[] { fileID }));
return;
}
// if (file==null){
try {
arch = new FileArchive();
arch.open(URI.create(uri));
} catch (Exception e) {
}
// }
try {
// if (file!=null){
// ze = jarFile.getEntry(fileName);
// if (ze == null) {
// result.failed(smh.getLocalString
// ("com.sun.enterprise.tools.verifier.tests.VerifierTest.fileexistence.failed",
// "Error: {0} [ {1} ] not found in the archive",
// new Object[] {fileID, fileName}));
// }else{
// result.passed(smh.getLocalString
// ("com.sun.enterprise.tools.verifier.tests.VerifierTest.fileexistence.passed",
// "{0} [ {1} ] found in the archive",
// new Object[] {fileID, fileName}));
// }
// }
// else{
File urif = new File(new File(arch.getURI()), fileName);
if (urif.exists()) {
result.passed(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.VerifierTest.fileexistence.passed", "{0} [ {1} ] found in the archive", new Object[] { fileID, fileName }));
} else {
result.warning(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.VerifierTest.fileexistence.warning", "{0} [ {1} ] not found in the archive", new Object[] { fileID, fileName }));
}
urif = null;
if (jarFile != null)
jarFile.close();
} catch (Exception ex) {
}
}
use of com.sun.enterprise.deploy.shared.FileArchive in project Payara by payara.
the class AppAltDDWeb method check.
/**
* The alt-dd element specifies a URI to the post-assembly deployment descriptor
* relative to the root of the application
*
* @param descriptor the Application deployment descriptor
*
* @return <code>Result</code> the results for this assertion
*/
public Result check(Application descriptor) {
Result result = getInitializedResult();
if (descriptor.getBundleDescriptors(WebBundleDescriptor.class).size() > 0) {
boolean oneFailed = false;
int na = 0;
for (Iterator itr = descriptor.getBundleDescriptors(WebBundleDescriptor.class).iterator(); itr.hasNext(); ) {
WebBundleDescriptor wbd = (WebBundleDescriptor) itr.next();
if (wbd.getModuleDescriptor().getAlternateDescriptor() != null) {
if (!(wbd.getModuleDescriptor().getAlternateDescriptor().equals(""))) {
InputStream deploymentEntry = null;
try {
// if (f==null){
String uri = getAbstractArchiveUri(descriptor);
// try {
FileArchive arch = new FileArchive();
arch.open(uri);
deploymentEntry = arch.getEntry(wbd.getModuleDescriptor().getAlternateDescriptor());
if (deploymentEntry != null) {
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "Found alternate web deployment descriptor URI file [ {0} ] within [ {1} ]", new Object[] { wbd.getModuleDescriptor().getAlternateDescriptor(), wbd.getName() }));
} else {
if (!oneFailed) {
oneFailed = true;
}
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: No alternate web deployment descriptor URI file found, looking for [{0} ] within [ {1} ]", new Object[] { wbd.getModuleDescriptor().getAlternateDescriptor(), wbd.getName() }));
}
// jarFile.close();
} catch (FileNotFoundException ex) {
Verifier.debug(ex);
if (!oneFailed) {
oneFailed = true;
}
result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: File not found trying to read deployment descriptor file [ {0} ] within [ {1} ]", new Object[] { wbd.getModuleDescriptor().getAlternateDescriptor(), wbd.getName() }));
} catch (IOException ex) {
Verifier.debug(ex);
if (!oneFailed) {
oneFailed = true;
}
result.failed(smh.getLocalString(getClass().getName() + ".failedException1", " Error: IO Error trying to read deployment descriptor file [ {0} ] within [ {1} ]", new Object[] { wbd.getModuleDescriptor().getAlternateDescriptor(), wbd.getName() }));
} finally {
try {
if (deploymentEntry != null)
deploymentEntry.close();
} catch (Exception x) {
}
}
}
} else {
na++;
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", "There is no java web alternative deployment descriptor in [ {0} ]", new Object[] { wbd.getName() }));
}
}
if (oneFailed) {
result.setStatus(Result.FAILED);
} else if (na == descriptor.getBundleDescriptors(WebBundleDescriptor.class).size()) {
result.setStatus(Result.NOT_APPLICABLE);
} else {
result.setStatus(Result.PASSED);
}
} else {
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "There are no web components in application [ {0} ]", new Object[] { descriptor.getName() }));
}
return result;
}
use of com.sun.enterprise.deploy.shared.FileArchive in project Payara by payara.
the class JarContainsXMLFile method check.
/**
* An enterprise archive (.ear) file must contain the XML-based deployment descriptor.
* The deployment descriptor must be named META-INF/application.xml in the JAR file.
*
* @param descriptor the Application deployment descriptor
*
* @return <code>Result</code> the results for this assertion
*/
public Result check(Application descriptor) {
Result result = getInitializedResult();
// hence we must exclude this test based on platform version.
if (getVerifierContext().getJavaEEVersion().compareTo(SpecVersionMapper.JavaEEVersion_5) >= 0) {
result.setStatus(Result.NOT_APPLICABLE);
return result;
}
JarFile jarFile = null;
InputStream deploymentEntry = null;
try {
// File applicationJarFile = null;
// if (Verifier.getEarFile() != null)
// applicationJarFile = new File(Verifier.getEarFile());
// should try to validate against SAX XML parser before
// continuing, report syntax errors and drop out, otherwise
// continue...
// if (applicationJarFile == null) {
// try {
FileArchive arch = (FileArchive) getVerifierContext().getAbstractArchive();
deploymentEntry = arch.getEntry(ApplicationDeploymentDescriptorFile.DESC_PATH);
if (deploymentEntry != null) {
result.passed(smh.getLocalString(getClass().getName() + ".passed", "Found deployment descriptor xml file [ {0} ]", new Object[] { ApplicationDeploymentDescriptorFile.DESC_PATH }));
} else {
result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: No deployment descriptor xml file found, looking for [ {0} ]", new Object[] { ApplicationDeploymentDescriptorFile.DESC_PATH }));
}
} catch (FileNotFoundException ex) {
Verifier.debug(ex);
result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: File not found trying to read deployment descriptor file [ {0} ]", new Object[] { ApplicationDeploymentDescriptorFile.DESC_PATH }));
} catch (IOException ex) {
Verifier.debug(ex);
result.failed(smh.getLocalString(getClass().getName() + ".failedException1", "Error: IO Error trying to read deployment descriptor file [ {0} ]", new Object[] { ApplicationDeploymentDescriptorFile.DESC_PATH }));
} finally {
try {
if (jarFile != null)
jarFile.close();
if (deploymentEntry != null)
deploymentEntry.close();
} catch (Exception x) {
}
}
return result;
}
Aggregations