Skip to content

Commit

Permalink
Fixed error processing around JMS Destination admin commands
Browse files Browse the repository at this point in the history
- errors were swallowed, so I saw just HTTP 500 without any info neither
  in response nor in server.log
  • Loading branch information
dmatej committed Apr 3, 2022
1 parent 4090e1e commit e08d842
Show file tree
Hide file tree
Showing 16 changed files with 988 additions and 1,276 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) 2009, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -138,7 +139,7 @@ public static void getPhysicalDestination(HandlerContext handlerCtx) {
Map valueMap = new HashMap();
try {
String objectName = getJmsDestinationObjectName(SUBTYPE_CONFIG, name, type);
AttributeList attributes = (AttributeList) JMXUtil.getMBeanServer().getAttributes(new ObjectName(objectName), ATTRS_CONFIG);
AttributeList attributes = JMXUtil.getMBeanServer().getAttributes(new ObjectName(objectName), ATTRS_CONFIG);
for (Attribute attribute : attributes.asList()) {
valueMap.put(attribute.getName(), (attribute.getValue() != null) ? attribute.getValue().toString() : null);
}
Expand Down Expand Up @@ -168,7 +169,7 @@ public static void getPhysicalDestinationStats(HandlerContext handlerCtx) {
insureJmsBrokerIsRunning();

String objectName = getJmsDestinationObjectName(SUBTYPE_MONITOR, name, type);
AttributeList attributes = (AttributeList) getMBeanServerConnection(target).getAttributes(new ObjectName(objectName), ATTRS_MONITOR);
AttributeList attributes = getMBeanServerConnection(target).getAttributes(new ObjectName(objectName), ATTRS_MONITOR);
ResourceBundle bundle = GuiUtil.getBundle("org.glassfish.jms.admingui.Strings");
statsList.add(createRow("Name", name, ""));
statsList.add(createRow("Type", type.substring(0, 1).toUpperCase(GuiUtil.guiLocale) + type.substring(1), ""));
Expand Down Expand Up @@ -208,12 +209,12 @@ public static void getPhysicalDestinations(HandlerContext handlerCtx) {
List<Map> selectedList = (List) handlerCtx.getInputValue("selectedRows");
boolean hasOrig = (selectedList == null || selectedList.size() == 0) ? false : true;

for (int i = 0; i < objectNames.length; i++) {
for (ObjectName objectName : objectNames) {
// getAttributes for the given objectName...
HashMap oneRow = new HashMap();
oneRow.put("name", objectNames[i].getKeyProperty(PROP_NAME).replaceAll("\"", ""));
oneRow.put("type", "t".equals(objectNames[i].getKeyProperty(PROP_DEST_TYPE)) ? "topic" : "queue");
oneRow.put("selected", (hasOrig) ? isSelected(objectNames[i].getKeyProperty(PROP_NAME), selectedList) : false);
oneRow.put("name", objectName.getKeyProperty(PROP_NAME).replaceAll("\"", ""));
oneRow.put("type", "t".equals(objectName.getKeyProperty(PROP_DEST_TYPE)) ? "topic" : "queue");
oneRow.put("selected", (hasOrig) ? isSelected(objectName.getKeyProperty(PROP_NAME), selectedList) : false);
result.add(oneRow);
}

Expand Down Expand Up @@ -287,7 +288,7 @@ public static void updatePhysicalDestination(HandlerContext handlerCtx) {
public static void deleteJMSDest(HandlerContext handlerCtx) {
// String configName = ((String) handlerCtx.getInputValue("targetName"));
List obj = (List) handlerCtx.getInputValue("selectedRows");
List<Map> selectedRows = (List) obj;
List<Map> selectedRows = obj;
try {
for (Map oneRow : selectedRows) {
String name = (String) oneRow.get("name");
Expand Down Expand Up @@ -403,7 +404,7 @@ protected static void buildAttributeList(AttributeList list, Map attrMap, String
list.add(new Attribute(ATTR_MAX_NUM_MSGS, Long.parseLong((String) attrMap.get(ATTR_MAX_NUM_MSGS))));
list.add(new Attribute(ATTR_MAX_BYTES_PER_MSG, Long.parseLong((String) attrMap.get(ATTR_MAX_BYTES_PER_MSG))));
list.add(new Attribute(ATTR_MAX_TOTAL_MSG_BYTES, Long.parseLong((String) attrMap.get(ATTR_MAX_TOTAL_MSG_BYTES))));
list.add(new Attribute(ATTR_LIMIT_BEHAVIOR, (String) attrMap.get(ATTR_LIMIT_BEHAVIOR)));
list.add(new Attribute(ATTR_LIMIT_BEHAVIOR, attrMap.get(ATTR_LIMIT_BEHAVIOR)));
list.add(new Attribute(ATTR_MAX_NUM_PRODUCERS, Integer.parseInt((String) attrMap.get(ATTR_MAX_NUM_PRODUCERS))));
if ("queue".equals(type)) {
list.add(new Attribute(ATTR_MAX_NUM_ACTIVE_CONSUMERS, Integer.parseInt((String) attrMap.get(ATTR_MAX_NUM_ACTIVE_CONSUMERS))));
Expand All @@ -413,7 +414,7 @@ protected static void buildAttributeList(AttributeList list, Map attrMap, String
list.add(new Attribute(ATTR_CONSUMER_FLOW_LIMIT, Long.parseLong((String) attrMap.get(ATTR_CONSUMER_FLOW_LIMIT))));
list.add(new Attribute(ATTR_USE_DMQ, Boolean.valueOf((String) attrMap.get(ATTR_USE_DMQ))));
list.add(new Attribute(ATTR_VALIDATE_XML_SCHEMA_ENABLED, Boolean.valueOf((String) attrMap.get(ATTR_VALIDATE_XML_SCHEMA_ENABLED))));
list.add(new Attribute(ATTR_XML_SCHEMA_URI_LIST, (String) attrMap.get(ATTR_XML_SCHEMA_URI_LIST)));
list.add(new Attribute(ATTR_XML_SCHEMA_URI_LIST, attrMap.get(ATTR_XML_SCHEMA_URI_LIST)));
}

protected static void insureJmsBrokerIsRunning() throws ConnectorRuntimeException {
Expand Down Expand Up @@ -444,14 +445,15 @@ private static MBeanServerConnection getMBeanServerConnection(String target) thr
}

PhysicalDestinations pd = new PhysicalDestinations();
MQJMXConnectorInfo mqInfo = pd.getConnectorInfo(target, configRef, habitat, domain);

return mqInfo.getMQMBeanServerConnection();
try (MQJMXConnectorInfo mqInfo = pd.createConnectorInfo(target, configRef, habitat, domain)) {
// fyi, the connection is just a description, not closeable.
return mqInfo.getMQMBeanServerConnection();
}
}

private static class PhysicalDestinations extends JMSDestination {
public MQJMXConnectorInfo getConnectorInfo(String target, String configName, ServiceLocator habitat, Domain domain) throws Exception {
return getMQJMXConnectorInfo(target, domain.getConfigNamed(configName), habitat.<ServerContext>getService(ServerContext.class),
public MQJMXConnectorInfo createConnectorInfo(String target, String configName, ServiceLocator habitat, Domain domain) throws Exception {
return createMQJMXConnectorInfo(target, domain.getConfigNamed(configName), habitat.<ServerContext>getService(ServerContext.class),
domain, habitat.<ConnectorRuntime>getService(ConnectorRuntime.class));
}
}
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 @@ -22,22 +23,35 @@
import com.sun.enterprise.deployment.xml.TagNames;
import com.sun.enterprise.util.LocalStringManagerImpl;

import org.jvnet.hk2.annotations.Service;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.EmptyStackException;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Stack;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.logging.Level;

import org.glassfish.hk2.api.PerLookup;
import org.jvnet.hk2.annotations.Service;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.helpers.NamespaceSupport;

import java.io.*;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.logging.Level;


/**
* This class implements all the callbacks for the SAX Parser in JAXP 1.1
Expand All @@ -57,8 +71,8 @@ public class SaxParserHandler extends DefaultHandler {
private static final String FALSE_STR = "false";

private static final class MappingStuff {
public final ConcurrentMap<String, Boolean> mBundleRegistrationStatus = new ConcurrentHashMap<String, Boolean>();
public final ConcurrentMap<String,String> mMapping = new ConcurrentHashMap<String,String>();
public final ConcurrentMap<String, Boolean> mBundleRegistrationStatus = new ConcurrentHashMap<>();
public final ConcurrentMap<String,String> mMapping = new ConcurrentHashMap<>();

private final ConcurrentMap<String,Class> mRootNodesMutable;
public final Map<String,Class> mRootNodes;
Expand All @@ -72,33 +86,33 @@ private static final class MappingStuff {
private final Map<String, List<VersionUpgrade>> mVersionUpgrades;

MappingStuff() {
mRootNodesMutable = new ConcurrentHashMap<String,Class>();
mRootNodesMutable = new ConcurrentHashMap<>();
mRootNodes = Collections.unmodifiableMap( mRootNodesMutable );

mElementsAllowingEmptyValuesMutable = new CopyOnWriteArraySet<String>();
mElementsAllowingEmptyValuesMutable = new CopyOnWriteArraySet<>();
mElementsAllowingEmptyValues = Collections.unmodifiableSet(mElementsAllowingEmptyValuesMutable);

mElementsPreservingWhiteSpaceMutable = new CopyOnWriteArraySet<String>();
mElementsPreservingWhiteSpaceMutable = new CopyOnWriteArraySet<>();
mElementsPreservingWhiteSpace = Collections.unmodifiableSet(mElementsPreservingWhiteSpaceMutable);
mVersionUpgradeClasses = new ConcurrentHashMap<String, List<Class>>();
mVersionUpgrades = new ConcurrentHashMap<String, List<VersionUpgrade>>();
mVersionUpgradeClasses = new ConcurrentHashMap<>();
mVersionUpgrades = new ConcurrentHashMap<>();
}
}

private static final MappingStuff _mappingStuff = new MappingStuff();

private final List<XMLNode> nodes = new ArrayList<XMLNode>();
private final List<XMLNode> nodes = new ArrayList<>();
public XMLNode topNode = null;
protected String publicID=null;
private StringBuffer elementData=null;
private Map<String, String> prefixMapping=null;
protected String publicID = null;
private StringBuffer elementData = null;
private Map<String, String> prefixMapping = null;

private boolean stopOnXMLErrors = false;

private boolean pushedNamespaceContext=false;
private NamespaceSupport namespaces = new NamespaceSupport();
private final NamespaceSupport namespaces = new NamespaceSupport();

private Stack elementStack = new Stack();
private final Stack elementStack = new Stack();

private static final LocalStringManagerImpl localStrings = new LocalStringManagerImpl(SaxParserHandler.class);

Expand All @@ -112,9 +126,10 @@ protected static List<VersionUpgrade> getVersionUpgrades(String key) {
return versionUpgradeList;
}
List<Class> classList = _mappingStuff.mVersionUpgradeClasses.get(key);
if (classList == null)
if (classList == null) {
return null;
versionUpgradeList = new ArrayList<VersionUpgrade>();
}
versionUpgradeList = new ArrayList<>();
for (int n = 0; n < classList.size(); ++n) {
VersionUpgrade versionUpgrade = null;
try {
Expand Down Expand Up @@ -154,8 +169,8 @@ public static void registerBundleNode(BundleNode bn, String bundleTagName) {
return;
}

final HashMap<String, String> dtdMapping = new HashMap<String, String>();
final Map<String, List<Class>> versionUpgrades = new HashMap<String, List<Class>>();
final HashMap<String, String> dtdMapping = new HashMap<>();
final Map<String, List<Class>> versionUpgrades = new HashMap<>();

String rootNodeKey = bn.registerBundle(dtdMapping);
_mappingStuff.mRootNodesMutable.putIfAbsent(rootNodeKey, bn.getClass());
Expand Down Expand Up @@ -199,6 +214,7 @@ public static void registerBundleNode(BundleNode bn, String bundleTagName) {
_mappingStuff.mBundleRegistrationStatus.put(rootNodeKey, Boolean.TRUE);
}

@Override
public InputSource resolveEntity(String publicID, String systemID) throws SAXException {
try {
if(DOLUtils.getDefaultLogger().isLoggable(Level.FINE)) {
Expand Down Expand Up @@ -229,7 +245,7 @@ public InputSource resolveEntity(String publicID, String systemID) throws SAXExc
"Requested schema is not found in local repository, please ensure that there are no typos in the XML namespace declaration."));
}
if (DOLUtils.getDefaultLogger().isLoggable(Level.FINE)) {
DOLUtils.getDefaultLogger().fine("Resolved to " + fileName);;
DOLUtils.getDefaultLogger().fine("Resolved to " + fileName);
}
return new InputSource(fileName);
}
Expand All @@ -251,8 +267,9 @@ public void setStopOnError(boolean stop) {
}


@Override
public void error(SAXParseException spe) throws SAXParseException {
DOLUtils.getDefaultLogger().log(Level.SEVERE, "enterprise.deployment.backend.invalidDescriptorFailure",
DOLUtils.getDefaultLogger().log(Level.SEVERE, DOLUtils.INVALILD_DESCRIPTOR,
new Object[] {errorReportingString, String.valueOf(spe.getLineNumber()),
String.valueOf(spe.getColumnNumber()), spe.getLocalizedMessage()});
if (stopOnXMLErrors) {
Expand All @@ -261,8 +278,9 @@ public void error(SAXParseException spe) throws SAXParseException {
}


@Override
public void fatalError(SAXParseException spe) throws SAXParseException {
DOLUtils.getDefaultLogger().log(Level.SEVERE, "enterprise.deployment.backend.invalidDescriptorFailure",
DOLUtils.getDefaultLogger().log(Level.SEVERE, DOLUtils.INVALILD_DESCRIPTOR,
new Object[] {errorReportingString, String.valueOf(spe.getLineNumber()),
String.valueOf(spe.getColumnNumber()), spe.getLocalizedMessage()});
if (stopOnXMLErrors) {
Expand Down Expand Up @@ -327,8 +345,7 @@ public static File getSchemaFileFor(String schemaSystemID) throws IOException {
*/
public static String resolveSchemaNamespace(String systemID) {
List<String> namespaces = DOLUtils.getProprietarySchemaNamespaces();
for (int n = 0; n < namespaces.size(); ++n) {
String namespace = namespaces.get(n);
for (String namespace : namespaces) {
if (systemID.startsWith(namespace)) {
return systemID.substring(namespace.length());
}
Expand All @@ -346,15 +363,15 @@ public static String resolveSchemaNamespace(String systemID) {
*/
public static String resolvePublicID(String publicID, String dtd) {
List<String> dtdStarts = DOLUtils.getProprietaryDTDStart();
for (int n = 0; n < dtdStarts.size(); ++n) {
String dtdStart = dtdStarts.get(n);
for (String dtdStart : dtdStarts) {
if (dtd.startsWith(dtdStart)) {
return dtd.substring(dtdStart.length());
}
}
return null;
}

@Override
public void notationDecl(java.lang.String name,
java.lang.String publicId,
java.lang.String systemId)
Expand All @@ -365,12 +382,13 @@ public void notationDecl(java.lang.String name,
}


@Override
public void startPrefixMapping(String prefix,
String uri)
throws SAXException {

if (prefixMapping==null) {
prefixMapping = new HashMap<String, String>();
prefixMapping = new HashMap<>();
}

// We need one namespace context per element, but any prefix mapping
Expand All @@ -385,6 +403,7 @@ public void startPrefixMapping(String prefix,
}


@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) {
if (!pushedNamespaceContext) {
// We need one namespae context per element, so push a context
Expand All @@ -405,8 +424,7 @@ public void startElement(String uri, String localName, String qName, Attributes
rootElement = localName;
versionUpgradeList = getVersionUpgrades(rootElement);
if (versionUpgradeList != null) {
for (int n = 0; n < versionUpgradeList.size(); ++n) {
VersionUpgrade versionUpgrade = versionUpgradeList.get(n);
for (VersionUpgrade versionUpgrade : versionUpgradeList) {
versionUpgrade.init();
}
}
Expand All @@ -417,8 +435,7 @@ public void startElement(String uri, String localName, String qName, Attributes
}

if (versionUpgradeList != null) {
for (int n = 0; n < versionUpgradeList.size(); ++n) {
VersionUpgrade versionUpgrade = versionUpgradeList.get(n);
for (VersionUpgrade versionUpgrade : versionUpgradeList) {
if (VersionUpgrade.UpgradeType.REMOVE_ELEMENT == versionUpgrade.getUpgradeType()) {
Map<String, String> matchXPath = versionUpgrade.getMatchXPath();
int entriesMatched = 0;
Expand Down Expand Up @@ -495,6 +512,7 @@ public void startElement(String uri, String localName, String qName, Attributes
}
}

@Override
public void endElement(String uri, String localName, String qName) {

String lastElement = null;
Expand All @@ -521,8 +539,7 @@ public void endElement(String uri, String localName, String qName) {
String replacementName = null;
String replacementValue = null;
if (versionUpgradeList != null) {
for (int n = 0; n < versionUpgradeList.size(); ++n) {
VersionUpgrade versionUpgrade = versionUpgradeList.get(n);
for (VersionUpgrade versionUpgrade : versionUpgradeList) {
if (VersionUpgrade.UpgradeType.REPLACE_ELEMENT == versionUpgrade.getUpgradeType()) {
Map<String, String> matchXPath = versionUpgrade.getMatchXPath();
int entriesMatched = 0;
Expand Down Expand Up @@ -612,6 +629,7 @@ public void endElement(String uri, String localName, String qName) {
}
}

@Override
public void characters(char[] ch, int start, int stop) {
if (elementData!=null) {
elementData = elementData.append(ch,start, stop);
Expand Down

0 comments on commit e08d842

Please sign in to comment.