Skip to content

Commit

Permalink
MONDRIAN: XML for Analysis servlet.
Browse files Browse the repository at this point in the history
[git-p4: depot-paths = "//open/mondrian/": change = 583]
  • Loading branch information
julianhyde committed Jun 4, 2003
1 parent 0fec48b commit 4b0861b
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 14 deletions.
22 changes: 22 additions & 0 deletions src/main/mondrian/util/SAXWriter.java
Expand Up @@ -17,6 +17,7 @@
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;

import mondrian.xom.XMLUtil;
import mondrian.xom.XOMUtil;
Expand All @@ -43,10 +44,31 @@ public class SAXWriter implements ContentHandler {
/** After a burst of character data. */
private static final int STATE_CHARACTERS = 3;

/**
* Creates a <code>SAXWriter</code> writing to an {@link OutputStream}.
*/
public SAXWriter(OutputStream stream) {
this.pw = new PrintWriter(new OutputStreamWriter(stream));
}

/**
* Creates a <code>SAXWriter</code> writing to a {@link Writer}.
*
* <p>If <code>writer</code> is a {@link PrintWriter},
* {@link #SAXWriter(PrintWriter)} is preferred.
*/
public SAXWriter(Writer writer) {
this.pw = new PrintWriter(writer);
}

/**
* Creates a <code>SAXWriter</code> writing to a {@link PrintWriter}.
* @param writer
*/
public SAXWriter(PrintWriter writer) {
this.pw = writer;
}

public void setDocumentLocator(Locator locator) {
}

Expand Down
12 changes: 6 additions & 6 deletions src/main/mondrian/xmla/XmlaMediator.java
Expand Up @@ -20,11 +20,11 @@
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.io.OutputStream;
import java.io.StringReader;
import java.util.Properties;
import java.util.HashMap;
import java.io.Writer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Properties;

/**
* An <code>XmlaMediator</code> responds to XML for Analysis requests.
Expand All @@ -38,10 +38,10 @@ public class XmlaMediator {

/**
* Processes a request.
* @param request
* @param response
* @param request XML request, for example, "<SOAP-ENV:Envelope ...>".
* @param response Destination for response
*/
public void process(String request, OutputStream response) {
public void process(String request, Writer response) {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = null;
try {
Expand Down
53 changes: 53 additions & 0 deletions src/main/mondrian/xmla/XmlaServlet.java
@@ -0,0 +1,53 @@
/*
// $Id$
// This software is subject to the terms of the Common Public License
// Agreement, available at the following URL:
// http://www.opensource.org/licenses/cpl.html.
// Copyright (C) 2003-2003 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
//
// jhyde, May 2, 2003
*/
package mondrian.xmla;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
* An <code>XmlaServlet</code> responds to XML for Analysis SOAP requests.
*
* @see XmlaMediator
*
* @author jhyde
* @since 27 April, 2003
* @version $Id$
*/
public class XmlaServlet extends HttpServlet {
private final XmlaMediator mediator = new XmlaMediator();

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
process(request, response);
}

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
process(request, response);
}

public void process(HttpServletRequest request, HttpServletResponse response) {
final String soapRequest = request.getParameter("SOAPRequest");
final PrintWriter printWriter;
try {
printWriter = response.getWriter();
} catch (IOException e) {
return;
}
mediator.process(soapRequest, printWriter);
}
}

// End XmlaServlet.java
53 changes: 45 additions & 8 deletions src/main/mondrian/xmla/XmlaTest.java
Expand Up @@ -13,8 +13,9 @@

import junit.framework.TestCase;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.StringWriter;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.regex.Pattern;

/**
Expand All @@ -30,19 +31,55 @@ public class XmlaTest extends TestCase {
//private static final String dataSource = "Provider=MSOLAP;Data Source=local;";
private static final String dataSource = "Provider=Mondrian;Jdbc=jdbc:odbc:MondrianFoodMart;Catalog=file:/E:/mondrian/demo/FoodMart.xml;JdbcDrivers=sun.jdbc.odbc.JdbcOdbcDriver;";
private static final String catalogName = "file:/E:/mondrian/demo/FoodMart.xml";
/**
* Usually null, when {@link #getRequests} sets it, {@link #executeRequest}
* writes request strings into it and returns null.
*/
private ArrayList requestList;

public XmlaTest(String s) {
super(s);
}

/**
* Executes a request and returns the result.
*
* <p>When called from {@link #getRequests}, {@link #requestList} is not
* null, and this method behaves very differently: it records the request
* and returns null.
*/
private String executeRequest(String request) {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
new XmlaMediator().process(request, baos);
try {
baos.flush();
} catch (IOException e) {
if (requestList != null) {
requestList.add(request);
return null;
}
final StringWriter sw = new StringWriter();
final XmlaMediator mediator = new XmlaMediator();
mediator.process(request, sw);
return sw.toString();
}

/**
* Returns a list of all requests in this test. (These requests are used
* in the sample web page, <code>xmlaTest.jsp</code>.)
*/
public synchronized String[] getRequests() {
this.requestList = new ArrayList();
Method[] methods = getClass().getMethods();
for (int i = 0; i < methods.length; i++) {
Method method = methods[i];
if (method.getName().startsWith("test")) {
try {
method.invoke(this, null);
} catch (Throwable e) {
// ignore
}
}
}
return baos.toString();
final String[] requests = (String[])
requestList.toArray(new String[requestList.size()]);
this.requestList = null;
return requests;
}

private void assertRequestYields(String request, String expected) {
Expand Down
10 changes: 10 additions & 0 deletions webapp/WEB-INF/web-jpivot.xml
Expand Up @@ -54,11 +54,21 @@ You must accept the terms of that agreement to use this software.
</init-param>
</servlet>

<servlet>
<servlet-name>MondrianXmlaServlet</servlet-name>
<servlet-class>mondrian.xmla.XmlaServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>MDXQueryServlet</servlet-name>
<url-pattern>/mdxquery</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>MondrianXmlaServlet</servlet-name>
<url-pattern>/xmla</url-pattern>
</servlet-mapping>

<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
Expand Down
10 changes: 10 additions & 0 deletions webapp/WEB-INF/web.xml
Expand Up @@ -38,11 +38,21 @@ You must accept the terms of that agreement to use this software.
</init-param>
</servlet>

<servlet>
<servlet-name>MondrianXmlaServlet</servlet-name>
<servlet-class>mondrian.xmla.XmlaServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>MDXQueryServlet</servlet-name>
<url-pattern>/mdxquery</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>MondrianXmlaServlet</servlet-name>
<url-pattern>/xmla</url-pattern>
</servlet-mapping>

<session-config>
<session-timeout>30</session-timeout>
</session-config>
Expand Down
23 changes: 23 additions & 0 deletions webapp/xmla.jsp
@@ -0,0 +1,23 @@
<%@ page import="mondrian.xmla.XmlaMediator,
mondrian.xmla.XmlaServlet,
java.io.OutputStream"%>
<%@ page language="java" %>
<%--
// $Id$
// This software is subject to the terms of the Common Public License
// Agreement, available at the following URL:
// http://www.opensource.org/licenses/cpl.html.
// (C) Copyright 2003-2003 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
//
// Julian Hyde, 3 June, 2003
--%>
<%!
final XmlaMediator mediator = new XmlaMediator();
%>
<%
final ServletContext servletContext = config.getServletContext();
final RequestDispatcher dispatcher = servletContext.getNamedDispatcher("MondrianXmlaServlet");
dispatcher.forward(request, response);
%>

0 comments on commit 4b0861b

Please sign in to comment.