Skip to content

Commit

Permalink
MONDRIAN: Namespace-aware handling of XML/A requests. Also set conten…
Browse files Browse the repository at this point in the history
…t-type to "text/xml".

[git-p4: depot-paths = "//open/mondrian/": change = 3767]
  • Loading branch information
julianhyde committed Jun 29, 2005
1 parent cb25f5c commit 06cad3d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
17 changes: 9 additions & 8 deletions src/main/mondrian/xmla/XmlaMediator.java
Expand Up @@ -45,6 +45,7 @@ public class XmlaMediator {
*/
public void process(String request, Writer response) {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder documentBuilder = null;
try {
documentBuilder = factory.newDocumentBuilder();
Expand Down Expand Up @@ -82,22 +83,22 @@ public void process(Element element, SAXHandler saxHandler) throws SAXException
}

private void processEnvelope(Element element, SAXHandler saxHandler) throws SAXException {
String tagName = element.getTagName();
Util.assertTrue(tagName.equals("SOAP-ENV:Envelope"));
String tagName = element.getLocalName();
Util.assertTrue(tagName.equals("Envelope"));
//final NodeList childNodes = element.getChildNodes();
saxHandler.startElement("SOAP-ENV:Envelope", new String[] {
"xmlns:SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/",
"SOAP-ENV:encodingStyle", "http://schemas.xmlsoap.org/soap/encoding/",
});
saxHandler.startElement("SOAP-ENV:Body");
processBody(firstElement(element, "SOAP-ENV:Body"), saxHandler);
processBody(firstElement(element, "Body"), saxHandler);
saxHandler.endElement();
saxHandler.endElement();
}

private void processBody(Element element, SAXHandler saxHandler) throws SAXException {
String tagName = element.getTagName();
Util.assertTrue(tagName.equals("SOAP-ENV:Body"));
String tagName = element.getLocalName();
Util.assertTrue(tagName.equals("Body"));
final NodeList childNodes = element.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
final Node node = childNodes.item(i);
Expand Down Expand Up @@ -458,7 +459,7 @@ static Connection getConnection(Properties properties) {
* none.
*/
private Element firstElement(Element element, String tagName) {
NodeList elements = element.getElementsByTagName(tagName);
NodeList elements = element.getElementsByTagNameNS("*", tagName);
for (int i = 0; i < elements.getLength(); i++) {
Node node = elements.item(i);
if (node instanceof Element) {
Expand All @@ -469,8 +470,8 @@ private Element firstElement(Element element, String tagName) {
}

/**
* Returns the text content of the first child element with a given tag, or
* null if there is no such child.
* Returns the text content of the first child element with a
* given tag, or null if there is no such child.
*/
private String firstElementCDATA(Element element, String tagName) {
Element child = firstElement(element, tagName);
Expand Down
15 changes: 10 additions & 5 deletions src/main/mondrian/xmla/XmlaServlet.java
Expand Up @@ -34,7 +34,7 @@
*/
public class XmlaServlet extends HttpServlet {
private static final Logger LOGGER = Logger.getLogger(XmlaServlet.class);

private final XmlaMediator mediator = new XmlaMediator();

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Expand All @@ -59,7 +59,11 @@ public void process(HttpServletRequest request, HttpServletResponse response) {
final Map map = request.getParameterMap();
for (Iterator iterator = map.keySet().iterator(); iterator.hasNext();) {
String att = (String) iterator.next();
LOGGER.debug(att + "=" + map.get(att));
String[] vals = (String[]) map.get(att);
LOGGER.debug(
att + "=" +
(vals != null && vals.length > 0 ? vals[0] :
"<null>"));
}
final Enumeration headerNames = request.getHeaderNames();
while (headerNames.hasMoreElements()) {
Expand All @@ -80,7 +84,7 @@ public void process(HttpServletRequest request, HttpServletResponse response) {
if (LOGGER.isDebugEnabled()) {
printWriter = new PrintWriter(
new FilterWriter(printWriter) {

public void write(int c) throws IOException {
this.out.write(c);
sb.append((char) c);
Expand All @@ -99,10 +103,11 @@ public void write(String str, int off, int len) throws IOException {
);
}
mediator.threadServletContext.set(getServletContext());
response.setContentType("text/xml");
mediator.process(soapRequest, printWriter);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Response:");
LOGGER.debug(sb.toString());
LOGGER.debug("Response:");
LOGGER.debug(sb.toString());
}
}

Expand Down

0 comments on commit 06cad3d

Please sign in to comment.