From 3ee359aae9eaa8d6b36b91b061e31efffebc4fb5 Mon Sep 17 00:00:00 2001 From: Luc Boudreau Date: Mon, 3 Nov 2008 17:39:10 +0000 Subject: [PATCH] Fixed an issue with the LS serializer usage that triggered an AbstractMethodError at runtime under certain environments. The parsing is now done old-school. git-svn-id: https://olap4j.svn.sourceforge.net/svnroot/olap4j/trunk@128 c6a108a4-781c-0410-a6c6-c2d559e19af0 --- .../olap4j/driver/xmla/XmlaOlap4jCellSet.java | 10 +- .../driver/xmla/XmlaOlap4jConnection.java | 10 +- .../olap4j/driver/xmla/XmlaOlap4jUtil.java | 100 ++++++++++++++++++ testsrc/org/olap4j/XmlaConnectionTest.java | 6 -- 4 files changed, 104 insertions(+), 22 deletions(-) diff --git a/src/org/olap4j/driver/xmla/XmlaOlap4jCellSet.java b/src/org/olap4j/driver/xmla/XmlaOlap4jCellSet.java index ccf15be..75b304c 100644 --- a/src/org/olap4j/driver/xmla/XmlaOlap4jCellSet.java +++ b/src/org/olap4j/driver/xmla/XmlaOlap4jCellSet.java @@ -121,15 +121,9 @@ void populate() throws OlapException { */ // TODO: log doc to logfile - // A message must include the fault XML content. This is the right - // and efficient way to do it, according to - // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6181019 - // They changed the node.getString() in java... .... - DOMImplementation impl = fault.getOwnerDocument().getImplementation(); - DOMImplementationLS factory = (DOMImplementationLS) impl.getFeature("LS", "3.0"); - LSSerializer serializer = factory.createLSSerializer(); throw OlapExceptionHelper.createException( - "XMLA provider gave exception: " + serializer.writeToString(fault)); + "XMLA provider gave exception: " + + XmlaOlap4jUtil.prettyPrint(fault)); } Element executeResponse = findChild(body, XMLA_NS, "ExecuteResponse"); diff --git a/src/org/olap4j/driver/xmla/XmlaOlap4jConnection.java b/src/org/olap4j/driver/xmla/XmlaOlap4jConnection.java index 9daf330..322f503 100644 --- a/src/org/olap4j/driver/xmla/XmlaOlap4jConnection.java +++ b/src/org/olap4j/driver/xmla/XmlaOlap4jConnection.java @@ -659,15 +659,9 @@ Element xxx(String request) throws OlapException { */ // TODO: log doc to logfile - // A message must include the fault XML content. This is the right - // and efficient way to do it, according to - // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6181019 - // They changed the node.getString() in java... .... - DOMImplementation impl = fault.getOwnerDocument().getImplementation(); - DOMImplementationLS factory = (DOMImplementationLS) impl.getFeature("LS", "3.0"); - LSSerializer serializer = factory.createLSSerializer(); throw OlapExceptionHelper.createException( - "XMLA provider gave exception: " + serializer.writeToString(fault) + "XMLA provider gave exception: " + + XmlaOlap4jUtil.prettyPrint(fault) + "\n Request was: \n" + request); } Element discoverResponse = diff --git a/src/org/olap4j/driver/xmla/XmlaOlap4jUtil.java b/src/org/olap4j/driver/xmla/XmlaOlap4jUtil.java index 2ed98b2..36f04f8 100644 --- a/src/org/olap4j/driver/xmla/XmlaOlap4jUtil.java +++ b/src/org/olap4j/driver/xmla/XmlaOlap4jUtil.java @@ -155,6 +155,106 @@ static String gatherText(Element element) { return buf.toString(); } + static String prettyPrint(Element element) { + StringBuilder string = new StringBuilder(); + prettyPrintLoop(element, string, ""); + return string.toString(); + } + + private static void prettyPrintLoop( + NodeList nodes, + StringBuilder string, + String indentation) + { + for (int index = 0; index < nodes.getLength(); index++){ + prettyPrintLoop(nodes.item(index), string, indentation); + } + } + + private static void prettyPrintLoop( + Node node, + StringBuilder string, + String indentation) + { + if (node == null) { + return; + } + + int type = node.getNodeType(); + + switch (type) { + case Node.DOCUMENT_NODE: { + string.append("\n"); + prettyPrintLoop(node.getChildNodes(), string, indentation+"\t"); + break; + } + + case Node.ELEMENT_NODE: { + string.append(indentation); + string.append("<"); + string.append(node.getNodeName()); + + int length = (node.getAttributes() != null) ? + node.getAttributes().getLength() : 0; + Attr attributes[] = new Attr[length]; + for (int loopIndex = 0; loopIndex < length; loopIndex++) { + attributes[loopIndex] = + (Attr)node.getAttributes().item(loopIndex); + } + + for (int loopIndex = 0; loopIndex < attributes.length; + loopIndex++) + { + Attr attribute = attributes[loopIndex]; + string.append(" "); + string.append(attribute.getNodeName()); + string.append("=\""); + string.append(attribute.getNodeValue()); + string.append("\""); + } + + string.append(">\n"); + + prettyPrintLoop(node.getChildNodes(), string, indentation+"\t"); + + string.append(indentation); + string.append("\n"); + + break; + } + + case Node.TEXT_NODE: { + string.append(indentation); + string.append(node.getNodeValue().trim()+"\n"); + //prettyPrintLoop(node, string, indentation+"\t"); + break; + } + + case Node.PROCESSING_INSTRUCTION_NODE: { + string.append(indentation); + string.append(" 0) { + string.append(text); + } + string.append("?>\n"); + break; + } + + case Node.CDATA_SECTION_NODE: { + string.append(indentation); + string.append(""); + break; + } + } + } + + static Element findChild(Element element, String ns, String tag) { final NodeList childNodes = element.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { diff --git a/testsrc/org/olap4j/XmlaConnectionTest.java b/testsrc/org/olap4j/XmlaConnectionTest.java index 4922586..8aa7d57 100644 --- a/testsrc/org/olap4j/XmlaConnectionTest.java +++ b/testsrc/org/olap4j/XmlaConnectionTest.java @@ -42,16 +42,10 @@ public DoubleSubmissionTestProxy( { super(catalogNameUrls,urlString); } - @Override public byte[] get(URL url, String request) throws IOException { this.checkup(request); return super.get(url, request); } -// @Override -// public Future submit(URL url, String request) { -// this.checkup(request); -// return super.submit(url, request); -// } private void checkup(String request) { String hash = Encoder.convertToHex(request.getBytes()); if ( request.indexOf("MDSCHEMA_CUBES") == -1 &&