Skip to content

Commit

Permalink
Set encoding for XMLA requests to 'UTF-8'; contributed by lucboudreau.
Browse files Browse the repository at this point in the history
git-svn-id: https://olap4j.svn.sourceforge.net/svnroot/olap4j/trunk@75 c6a108a4-781c-0410-a6c6-c2d559e19af0
  • Loading branch information
julianhyde committed Feb 29, 2008
1 parent 81a26e5 commit dd4e9e6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/org/olap4j/driver/xmla/XmlaOlap4jConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,10 @@ public String generateRequest(
final String dataSourceInfo =
context.olap4jConnection.getDataSourceInfo();
final String content = "Data";
final String encoding = "UTF-8"; // proxy.getEncodingCharsetName();
final StringBuilder buf = new StringBuilder(
"<SOAP-ENV:Envelope\n"
"<?xml version=\"1.0\" encoding=\"" + encoding + "\"?>\n"
+ "<SOAP-ENV:Envelope\n"
+ " xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"\n"
+ " SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n"
+ " <SOAP-ENV:Body>\n"
Expand Down
27 changes: 25 additions & 2 deletions src/org/olap4j/driver/xmla/XmlaOlap4jDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ public class XmlaOlap4jDriver implements Driver {
register();
} catch (SQLException e) {
e.printStackTrace();
} catch (RuntimeException e) {
e.printStackTrace();
throw e;
}
}

Expand Down Expand Up @@ -192,6 +195,14 @@ public byte[] call() throws Exception {
* Object which can respond to HTTP requests.
*/
public interface Proxy {
/**
* Sends a request to a URL and returns the response.
*
* @param url Target URL
* @param request Request string
* @return Response
* @throws IOException
*/
byte[] get(URL url, String request) throws IOException;

/**
Expand All @@ -204,6 +215,12 @@ public interface Proxy {
Future<byte[]> submit(
URL url,
String request);

/**
* Returns the name of the character set use for encoding the XML
* string.
*/
// String getEncodingCharsetName();
}

/**
Expand All @@ -224,8 +241,10 @@ public byte[] get(URL url, String request) throws IOException {
"Authorization", "Basic " + encoding);
}

// Send data (i.e. POST). Assume default encoding.
urlConnection.getOutputStream().write(request.getBytes());
// Send data (i.e. POST). Use same encoding as specified in the
// header.
final String encoding = getEncodingCharsetName();
urlConnection.getOutputStream().write(request.getBytes(encoding));

// Get the response, again assuming default encoding.
InputStream is = urlConnection.getInputStream();
Expand All @@ -250,6 +269,10 @@ public byte[] call() throws Exception {
}
);
}

public String getEncodingCharsetName() {
return "UTF-8";
}
}

/**
Expand Down

0 comments on commit dd4e9e6

Please sign in to comment.