Skip to content

Commit 93c8eed

Browse files
Merge pull request #1460 from smmribeiro/BACKLOG-41287
fix[BACKLOG-41287] Fix Integration Tests
2 parents 28664c0 + 12d1459 commit 93c8eed

1 file changed

Lines changed: 139 additions & 115 deletions

File tree

mondrian/src/it/java/mondrian/xmla/test/XmlaTestServletRequestWrapper.java

Lines changed: 139 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,16 @@
1313

1414
package mondrian.xmla.test;
1515

16-
import mondrian.olap.Util;
17-
import mondrian.xmla.XmlaServlet;
18-
19-
import java.io.*;
16+
import jakarta.servlet.ReadListener;
2017
import jakarta.servlet.ServletInputStream;
2118
import jakarta.servlet.http.HttpServletRequest;
2219
import jakarta.servlet.http.HttpServletRequestWrapper;
20+
import mondrian.olap.Util;
21+
import mondrian.xmla.XmlaServlet;
22+
23+
import java.io.ByteArrayInputStream;
24+
import java.io.IOException;
25+
import java.io.InputStreamReader;
2326

2427
/**
2528
* Dummy request for testing XmlaServlet. Provides a 'text/xml' content stream
@@ -30,122 +33,143 @@
3033
*/
3134
public class XmlaTestServletRequestWrapper extends HttpServletRequestWrapper {
3235

33-
private HttpServletRequest originalRequest;
34-
private ServletInputStream servletInStream;
36+
private HttpServletRequest originalRequest;
37+
private ServletInputStream servletInStream;
38+
39+
public XmlaTestServletRequestWrapper( HttpServletRequest req ) {
40+
super( req );
41+
originalRequest = req;
42+
init();
43+
}
44+
45+
/**
46+
* Extract the data from the HTTP request and create an XML/A request
47+
*/
48+
private void init() {
49+
String soapRequest = originalRequest.getParameter( "SOAPRequest" );
50+
51+
if ( soapRequest == null || soapRequest.isEmpty() ) {
52+
// Parameter not set. Look for the request in the body of the http request.
53+
54+
try {
55+
final ServletInputStream inputStream = originalRequest.getInputStream();
56+
soapRequest = Util.readFully( new InputStreamReader( inputStream ), 2048 );
57+
} catch ( IOException e ) {
58+
throw Util.newInternal( e, "error reading body of soap request" );
59+
}
60+
61+
if ( soapRequest.isEmpty() ) {
62+
throw new RuntimeException( "SOAPRequest not set" );
63+
}
64+
}
3565

36-
public XmlaTestServletRequestWrapper(HttpServletRequest req) {
37-
super(req);
38-
originalRequest = req;
39-
init();
66+
/*
67+
* Strip the XML preamble if it is there
68+
*/
69+
if ( soapRequest.indexOf( "<?" ) == 0 ) {
70+
soapRequest = soapRequest.substring( soapRequest.indexOf( "?>" ) + 2 );
4071
}
4172

42-
/**
43-
* Extract the data from the HTTP request and create an XML/A request
73+
/*
74+
* Make a SOAP message
4475
*/
45-
private void init() {
46-
String soapRequest = originalRequest.getParameter("SOAPRequest");
47-
48-
if (soapRequest == null || soapRequest.length() == 0) {
49-
// Parameter not set. Look for the request in the body of the http
50-
// request.
51-
52-
try {
53-
final ServletInputStream inputStream =
54-
originalRequest.getInputStream();
55-
soapRequest = Util.readFully(
56-
new InputStreamReader(inputStream), 2048);
57-
} catch (IOException e) {
58-
throw Util.newInternal(e, "error reading body of soap request");
59-
}
60-
61-
if (soapRequest.length() == 0) {
62-
throw new RuntimeException("SOAPRequest not set");
63-
}
64-
}
65-
66-
/*
67-
* Strip the XML premable if it is there
68-
*/
69-
if (soapRequest.indexOf("<?") == 0) {
70-
soapRequest = soapRequest.substring(soapRequest.indexOf("?>") + 2);
71-
}
72-
73-
/*
74-
* Make a SOAP message
75-
*/
76-
String request =
77-
"<?xml version=\"1.0\"?>\r\n"
78-
+ "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\""
79-
+ XmlaServlet.NS_SOAP_ENV_1_1
80-
+ "\" SOAP-ENV:encodingStyle=\""
81-
+ XmlaServlet.NS_SOAP_ENC_1_1
82-
+ "\">\r\n"
83-
+ "<SOAP-ENV:Header/>\r\n"
84-
+ "<SOAP-ENV:Body>\r\n"
85-
+ soapRequest
86-
+ "</SOAP-ENV:Body>\r\n</SOAP-ENV:Envelope>\r\n";
87-
88-
servletInStream = new XmlaTestServletInputStream(request);
89-
}
90-
91-
public String getContentType() {
92-
return "text/xml";
93-
}
94-
95-
public ServletInputStream getInputStream() {
96-
return servletInStream;
97-
}
98-
99-
private static class XmlaTestServletInputStream extends ServletInputStream {
100-
101-
private ByteArrayInputStream bais;
102-
103-
XmlaTestServletInputStream(String source) {
104-
bais = new ByteArrayInputStream(source.getBytes());
105-
}
106-
107-
public int readLine(byte[] arg0, int arg1, int arg2)
108-
throws IOException
109-
{
110-
return bais.read(arg0, arg1, arg2);
111-
}
112-
113-
public int available() throws IOException {
114-
return bais.available();
115-
}
116-
117-
public void close() throws IOException {
118-
bais.close();
119-
}
120-
121-
public synchronized void mark(int readlimit) {
122-
bais.mark(readlimit);
123-
}
124-
125-
public boolean markSupported() {
126-
return bais.markSupported();
127-
}
128-
129-
public int read() throws IOException {
130-
return bais.read();
131-
}
132-
133-
public int read(byte[] b, int off, int len) throws IOException {
134-
return bais.read(b, off, len);
135-
}
136-
137-
public int read(byte[] b) throws IOException {
138-
return bais.read(b);
139-
}
140-
141-
public synchronized void reset() throws IOException {
142-
bais.reset();
143-
}
144-
145-
public long skip(long n) throws IOException {
146-
return bais.skip(n);
147-
}
76+
String request =
77+
"<?xml version=\"1.0\"?>\r\n"
78+
+ "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\""
79+
+ XmlaServlet.NS_SOAP_ENV_1_1
80+
+ "\" SOAP-ENV:encodingStyle=\""
81+
+ XmlaServlet.NS_SOAP_ENC_1_1
82+
+ "\">\r\n"
83+
+ "<SOAP-ENV:Header/>\r\n"
84+
+ "<SOAP-ENV:Body>\r\n"
85+
+ soapRequest
86+
+ "</SOAP-ENV:Body>\r\n</SOAP-ENV:Envelope>\r\n";
87+
88+
servletInStream = new XmlaTestServletInputStream( request );
89+
}
90+
91+
@Override
92+
public String getContentType() {
93+
return "text/xml";
94+
}
95+
96+
@Override
97+
public ServletInputStream getInputStream() {
98+
return servletInStream;
99+
}
100+
101+
private static class XmlaTestServletInputStream extends ServletInputStream {
102+
103+
private ByteArrayInputStream bais;
104+
105+
XmlaTestServletInputStream( String source ) {
106+
bais = new ByteArrayInputStream( source.getBytes() );
107+
}
108+
109+
@Override
110+
public int readLine( byte[] arg0, int arg1, int arg2 ) throws IOException {
111+
return bais.read( arg0, arg1, arg2 );
112+
}
113+
114+
@Override
115+
public boolean isFinished() {
116+
return false;
117+
}
118+
119+
@Override
120+
public boolean isReady() {
121+
return false;
122+
}
123+
124+
@Override
125+
public void setReadListener( ReadListener readListener ) {
126+
127+
}
128+
129+
@Override
130+
public int available() throws IOException {
131+
return bais.available();
132+
}
133+
134+
@Override
135+
public void close() throws IOException {
136+
bais.close();
137+
}
138+
139+
@Override
140+
public synchronized void mark( int readLimit ) {
141+
bais.mark( readLimit );
142+
}
143+
144+
@Override
145+
public boolean markSupported() {
146+
return bais.markSupported();
147+
}
148+
149+
public int read() throws IOException {
150+
return bais.read();
151+
}
152+
153+
@Override
154+
public int read( byte[] b, int off, int len ) throws IOException {
155+
return bais.read( b, off, len );
156+
}
157+
158+
@Override
159+
public int read( byte[] b ) throws IOException {
160+
return bais.read( b );
161+
}
162+
163+
@Override
164+
public synchronized void reset() throws IOException {
165+
bais.reset();
166+
}
167+
168+
@Override
169+
public long skip( long n ) throws IOException {
170+
return bais.skip( n );
148171
}
172+
}
149173
}
150174

151175
// End XmlaTestServletRequestWrapper.java

0 commit comments

Comments
 (0)