Skip to content

Commit

Permalink
Issue eclipse-ee4j#23873 Fixed deployment logs
Browse files Browse the repository at this point in the history
- just message keys I have seen in logs, tested manually
  • Loading branch information
dmatej committed Jul 15, 2022
1 parent 94c6ce5 commit de27fe3
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 56 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -32,6 +33,9 @@
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXParseException;

import static com.sun.enterprise.deployment.node.SaxParserHandler.JAXP_SCHEMA_LANGUAGE;
import static com.sun.enterprise.deployment.util.DOLUtils.INVALILD_DESCRIPTOR_SHORT;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
Expand Down Expand Up @@ -110,8 +114,7 @@ public SAXParser getSAXParser (boolean validating) {
// this is a hack for a few days so people can continue runnning
// with crimson
if (spf.getClass().getName().indexOf("xerces")!=-1) {
spf.setFeature(
"http://apache.org/xml/features/allow-java-encodings", true);
spf.setFeature("http://apache.org/xml/features/allow-java-encodings", true);
} else {
DOLUtils.getDefaultLogger().log(Level.WARNING, "SAXParserFactory should be xerces, but was not.");
}
Expand All @@ -132,34 +135,28 @@ public SAXParser getSAXParser (boolean validating) {

// put the default schema for this deployment file type
String path = getDefaultSchemaSource();
if (path!=null) {
if (path != null) {
sp.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation",path);
}

// Set Xerces feature to allow dynamic validation. This prevents
// SAX errors from being reported when no schemaLocation attr
// is seen for a DTD based (J2EE1.3) XML descriptor.
sp.getXMLReader().setFeature(
"http://apache.org/xml/features/validation/dynamic", validating);

sp.getXMLReader().setFeature("http://apache.org/xml/features/validation/dynamic", validating);
return sp;

} catch (SAXNotRecognizedException x) {
// This can happen if the parser does not support JAXP 1.2
DOLUtils.getDefaultLogger().log(Level.SEVERE,
"INFO: JAXP SAXParser property not recognized: "
+ SaxParserHandler.JAXP_SCHEMA_LANGUAGE);
DOLUtils.getDefaultLogger().log(Level.SEVERE,
"Check to see if parser conforms to JAXP 1.2 spec.");
"INFO: JAXP SAXParser property not recognized: " + JAXP_SCHEMA_LANGUAGE);
DOLUtils.getDefaultLogger().log(Level.SEVERE, "Check to see if parser conforms to JAXP 1.2 spec.");

}
} catch (Exception e) {
DOLUtils.getDefaultLogger().log(Level.SEVERE, "enterprise.deployment.backend.saxParserError",
new Object[]{e.getMessage()});
DOLUtils.getDefaultLogger().log(Level.SEVERE, INVALILD_DESCRIPTOR_SHORT, e.getMessage());
DOLUtils.getDefaultLogger().log(Level.WARNING, "Error occurred", e);

} finally {
Thread.currentThread().setContextClassLoader(currentLoader);
Thread.currentThread().setContextClassLoader(currentLoader);
}
return null;
}
Expand Down Expand Up @@ -193,15 +190,12 @@ public DocumentBuilder getDocumentBuilder(boolean validating) {
} catch (ParserConfigurationException x) {
// This can happen if the parser does not support JAXP 1.2
DOLUtils.getDefaultLogger().log(Level.SEVERE,
"Error: JAXP DOMParser property not recognized: "
+ SaxParserHandler.JAXP_SCHEMA_LANGUAGE);
DOLUtils.getDefaultLogger().log(Level.SEVERE,
"Check to see if parser conforms to JAXP 1.2 spec.");
"Error: JAXP DOMParser property not recognized: " + JAXP_SCHEMA_LANGUAGE);
DOLUtils.getDefaultLogger().log(Level.SEVERE, "Check to see if parser conforms to JAXP 1.2 spec.");

}
} catch (Exception e) {
DOLUtils.getDefaultLogger().log(Level.SEVERE, "enterprise.deployment.backend.saxParserError",
new Object[]{e.getMessage()});
DOLUtils.getDefaultLogger().log(Level.SEVERE, INVALILD_DESCRIPTOR_SHORT, e.getMessage());
DOLUtils.getDefaultLogger().log(Level.WARNING, "Error occurred", e);
}
return null;
Expand Down Expand Up @@ -285,8 +279,7 @@ public T read(T descriptor, InputStream is) throws IOException, SAXException {
try {
sp.parse(input,dh);
} catch(SAXParseException e) {
DOLUtils.getDefaultLogger().log(Level.SEVERE, "enterprise.deployment.backend.saxParserError",
new Object[]{e.getMessage()});
DOLUtils.getDefaultLogger().log(Level.SEVERE, INVALILD_DESCRIPTOR_SHORT, e.getMessage());

errorReporting += " " + e.getLocalizedMessage();
SAXParseException spe = new SAXParseException(errorReporting,
Expand All @@ -298,13 +291,11 @@ public T read(T descriptor, InputStream is) throws IOException, SAXException {

throw spe;
} catch(SAXException e) {
DOLUtils.getDefaultLogger().log(Level.SEVERE, "enterprise.deployment.backend.saxParserError",
new Object[]{e.getMessage()});
DOLUtils.getDefaultLogger().log(Level.SEVERE, INVALILD_DESCRIPTOR_SHORT, e.getMessage());
DOLUtils.getDefaultLogger().log(Level.SEVERE, "Error occurred", e);
throw e;
} catch (IOException e) {
DOLUtils.getDefaultLogger().log(Level.SEVERE, "enterprise.deployment.backend.saxParserError",
e.getMessage() == null ? "" : new Object[]{e.getMessage()});
DOLUtils.getDefaultLogger().log(Level.SEVERE, INVALILD_DESCRIPTOR_SHORT, e.getMessage());

// Let's check if the root cause of this IOException is failing to
// connect. If yes, it means two things:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -19,7 +20,6 @@
import org.glassfish.deployment.common.Descriptor;
import com.sun.enterprise.deployment.io.DeploymentDescriptorFile;
import com.sun.enterprise.deployment.util.DOLUtils;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;
import org.w3c.dom.Node;

Expand Down Expand Up @@ -56,30 +56,22 @@ public J2EEDocumentBuilder() {
public static Document newDocument() {
try {
// always use system default, see IT 8229
ClassLoader currentLoader =
Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(
J2EEDocumentBuilder.class.getClassLoader());
ClassLoader currentLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(J2EEDocumentBuilder.class.getClassLoader());
DocumentBuilderFactory factory = null;
try {
factory = DocumentBuilderFactory.newInstance();
} finally {
Thread.currentThread().setContextClassLoader(currentLoader);
}

DocumentBuilder builder = factory.newDocumentBuilder();

DOMImplementation domImplementation =
builder.getDOMImplementation();

Document document = builder.newDocument();
return document;
} catch (Exception e) {
DOLUtils.getDefaultLogger().log(Level.SEVERE, "enterprise.deployment.backend.saxParserError",
new Object[] {"JAXP configuration error"});
DOLUtils.getDefaultLogger().log(Level.SEVERE, DOLUtils.INVALILD_DESCRIPTOR_SHORT, e.getMessage());
DOLUtils.getDefaultLogger().log(Level.WARNING, "Error occurred", e);
return null;
}
return null;
}

/**
Expand All @@ -89,14 +81,14 @@ public static Document newDocument() {
public static Document getDocument(Descriptor descriptor, XMLNode node) {
try {
Node domNode = node.writeDescriptor(newDocument(), descriptor);
if (domNode instanceof Document)
if (domNode instanceof Document) {
return (Document) domNode;
else
return domNode.getOwnerDocument();
}
return domNode.getOwnerDocument();
} catch (Exception e) {
DOLUtils.getDefaultLogger().log(Level.WARNING, "Error occurred", e);
return null;
}
return null;
}

public static void write (Descriptor descriptor, final RootXMLNode node, final File resultFile) throws Exception {
Expand All @@ -107,8 +99,9 @@ public static void write (Descriptor descriptor, final RootXMLNode node, final
}
if (resultFile.getParent() != null) {
File f = new File(resultFile.getParent());
if (!f.isDirectory() && !f.mkdirs())
if (!f.isDirectory() && !f.mkdirs()) {
throw new IOException("Cannot create parent directory " + f.getAbsolutePath());
}
}
FileOutputStream out = new FileOutputStream(resultFile);
try {
Expand All @@ -118,13 +111,12 @@ public static void write (Descriptor descriptor, final RootXMLNode node, final
}
}

public static void write (Descriptor descriptor, final RootXMLNode node, final OutputStream os) throws Exception {
public static void write(Descriptor descriptor, final RootXMLNode node, final OutputStream os) throws Exception {
Result output = new StreamResult(os);
write(descriptor, node, output);
}

public static void write (Descriptor descriptor, final RootXMLNode node, final Result output)
throws Exception {
public static void write(Descriptor descriptor, final RootXMLNode node, final Result output) throws Exception {
if (node==null) {
DOLUtils.getDefaultLogger().log(Level.SEVERE, DOLUtils.INVALID_DESC_MAPPING,
new Object[] {descriptor, null});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public void setStopOnError(boolean stop) {

@Override
public void error(SAXParseException spe) throws SAXParseException {
DOLUtils.getDefaultLogger().log(Level.SEVERE, DOLUtils.INVALILD_DESCRIPTOR,
DOLUtils.getDefaultLogger().log(Level.SEVERE, DOLUtils.INVALILD_DESCRIPTOR_LONG,
new Object[] {errorReportingString, String.valueOf(spe.getLineNumber()),
String.valueOf(spe.getColumnNumber()), spe.getLocalizedMessage()});
if (stopOnXMLErrors) {
Expand All @@ -280,7 +280,7 @@ public void error(SAXParseException spe) throws SAXParseException {

@Override
public void fatalError(SAXParseException spe) throws SAXParseException {
DOLUtils.getDefaultLogger().log(Level.SEVERE, DOLUtils.INVALILD_DESCRIPTOR,
DOLUtils.getDefaultLogger().log(Level.SEVERE, DOLUtils.INVALILD_DESCRIPTOR_LONG,
new Object[] {errorReportingString, String.valueOf(spe.getLineNumber()),
String.valueOf(spe.getColumnNumber()), spe.getLocalizedMessage()});
if (stopOnXMLErrors) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,16 @@ public class DOLUtils {
cause = "Failed to find the resource specified in the deployment descriptor. May be because of wrong specification in the descriptor",
action = "Ensure that the resource specified is present. Ensure that there is no typo in the resource specified in the descriptor"
)
public static final String INVALILD_DESCRIPTOR = "AS-DEPLOYMENT-00118";
public static final String INVALILD_DESCRIPTOR_LONG = "AS-DEPLOYMENT-00118";

@LogMessageInfo(message = "Deployment Descriptor parsing failure: {0}",
cause="Error while parsing the deployment descriptor."
+ " May be because of malformed descriptor or absence of all required descriptor elements.",
action="Ensure that the descriptor is well formed and as per specification."
+ " Ensure that the SAX parser configuration is correct and the descriptor has right permissions."
)
public static final String INVALILD_DESCRIPTOR_SHORT = "AS-DEPLOYMENT-00120";



// The system property to control the precedence between GF DD
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,6 @@ DPL8004.diag.cause.2=May be because of lack of permission or wrong file name
DPL8004.diag.check.1=Ensure that the file name is correct
DPL8004.diag.check.2=Ensure that the permissions are set as expected

enterprise.deployment.backend.saxParserError=DPL8005: Deployment Descriptor parsing failure : {0}
DPL8005.diag.cause.1=Error while parsing the deployment descriptor
DPL8005.diag.cause.2=May be because of malformed descriptor or absence of all required descriptor elements
DPL8005.diag.check.1=Ensure that the descriptor is well formed and as per specification
DPL8005.diag.check.2=Ensure that the SAX parser configuration is correct and the descriptor has right permissions

enterprise.deployment.backend.addDescriptorFailure=DPL8006: get/add descriptor failure : {0} TO {1}
DPL8006.diag.cause.1=Adding or getting a descriptor failed
DPL8006.diag.cause.2=May be because the node / information to be added is not valid; may be because of the descriptor was not registered
Expand Down

0 comments on commit de27fe3

Please sign in to comment.