Author: rareddy
Date: 2010-05-22 17:57:32 -0400 (Sat, 22 May 2010)
New Revision: 2149
Added:
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/StremableDocument.java
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/streaming/TestHttpExecution.java
trunk/connectors/translator-xml/src/test/resources/xmltest.vdb
Removed:
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/Document.java
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/streaming/DocumentImpl.java
Modified:
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/FileResultSetExecution.java
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/streaming/BaseStreamingExecution.java
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/streaming/ElementProcessor.java
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/streaming/StreamingResultsProducer.java
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/streaming/StreamingRowCollector.java
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/TestElementCollector.java
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/streaming/TestSoapExecution.java
Log:
TEIID-1077: Fixed the feature to add request parameter to the resultset; added a test for
the HTTP-relational model
Deleted:
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/Document.java
===================================================================
---
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/Document.java 2010-05-21
20:33:45 UTC (rev 2148)
+++
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/Document.java 2010-05-22
21:57:32 UTC (rev 2149)
@@ -1,12 +0,0 @@
-package org.teiid.translator.xml;
-
-import java.io.InputStream;
-import java.sql.SQLException;
-
-public interface Document {
-
- public InputStream getStream() throws SQLException;
-
- public String getCachekey();
-
-}
Modified:
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/FileResultSetExecution.java
===================================================================
---
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/FileResultSetExecution.java 2010-05-21
20:33:45 UTC (rev 2148)
+++
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/FileResultSetExecution.java 2010-05-22
21:57:32 UTC (rev 2149)
@@ -35,7 +35,6 @@
import org.teiid.translator.FileConnection;
import org.teiid.translator.ResultSetExecution;
import org.teiid.translator.TranslatorException;
-import org.teiid.translator.xml.streaming.DocumentImpl;
import org.teiid.translator.xml.streaming.InvalidPathException;
import org.teiid.translator.xml.streaming.StreamingResultsProducer;
import org.teiid.translator.xml.streaming.XPathSplitter;
@@ -47,7 +46,7 @@
private int docNumber = 0;
private File[] content;
private XMLExecutionFactory executionFactory;
- private List<Document> resultDocuments = null;
+ private List<StremableDocument> resultDocuments = null;
private StreamingResultsProducer streamProducer;
private List<Object[]> currentRowSet;
private int currentRow = 0;
@@ -87,7 +86,7 @@
@Override
public void execute() throws TranslatorException {
if (this.content != null) {
- this.resultDocuments = new ArrayList<Document>();
+ this.resultDocuments = new ArrayList<StremableDocument>();
int i = 0;
for(File f:this.content) {
this.resultDocuments.add(getDocumentStream(f, i++));
@@ -128,14 +127,14 @@
}
}
- private Document getDocumentStream(final File xmlFile, int fileNumber) {
+ private StremableDocument getDocumentStream(final File xmlFile, int fileNumber) {
InputStreamFactory isf = new InputStreamFactory() {
@Override
public InputStream getInputStream() throws IOException {
return new BufferedInputStream(new FileInputStream(xmlFile));
}
};
- return new DocumentImpl(this.executionFactory.convertToXMLType(isf),
xmlFile.getName()+fileNumber);
+ return new StremableDocument(this.executionFactory.convertToXMLType(isf),
xmlFile.getName()+fileNumber);
}
@Override
Copied:
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/StremableDocument.java
(from rev 2148,
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/Document.java)
===================================================================
---
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/StremableDocument.java
(rev 0)
+++
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/StremableDocument.java 2010-05-22
21:57:32 UTC (rev 2149)
@@ -0,0 +1,25 @@
+package org.teiid.translator.xml;
+
+import java.io.InputStream;
+import java.sql.SQLException;
+import java.sql.SQLXML;
+
+public class StremableDocument {
+
+ private SQLXML xml;
+ private String cacheKey;
+
+ public StremableDocument(SQLXML xml, String cacheKey) {
+ this.xml = xml;
+ this.cacheKey = cacheKey;
+ }
+
+ public InputStream getStream() throws SQLException{
+ return xml.getBinaryStream();
+ }
+
+ public String getCachekey() {
+ return cacheKey;
+ }
+
+}
Modified:
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/streaming/BaseStreamingExecution.java
===================================================================
---
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/streaming/BaseStreamingExecution.java 2010-05-21
20:33:45 UTC (rev 2148)
+++
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/streaming/BaseStreamingExecution.java 2010-05-22
21:57:32 UTC (rev 2149)
@@ -52,7 +52,7 @@
import org.teiid.translator.TranslatorException;
import org.teiid.translator.xml.Constants;
import org.teiid.translator.xml.CriteriaDesc;
-import org.teiid.translator.xml.Document;
+import org.teiid.translator.xml.StremableDocument;
import org.teiid.translator.xml.DocumentBuilder;
import org.teiid.translator.xml.ExecutionInfo;
import org.teiid.translator.xml.OutputXPathDesc;
@@ -81,7 +81,7 @@
Dispatch<Source> dispatch;
ExecutionInfo executionInfo;
Source soapPayload;
- Iterator<Document> resultsIterator;
+ Iterator<StremableDocument> resultsIterator;
public BaseStreamingExecution(List<CriteriaDesc> requestParams, ExecutionInfo
executionInfo, ExecutionContext context, XMLExecutionFactory executionFactory,
Dispatch<Source> dispatch) throws TranslatorException {
this.context = context;
@@ -202,9 +202,9 @@
private void fillInResults() throws TranslatorException {
List<Object[]> rows;
StreamingResultsProducer streamProducer = new
StreamingResultsProducer(this.executionInfo,
this.executionFactory.getSaxFilterProvider());
- Iterator<Document> streamIter = this.resultsIterator;
+ Iterator<StremableDocument> streamIter = this.resultsIterator;
while (streamIter.hasNext()) {
- Document xml = streamIter.next();
+ StremableDocument xml = streamIter.next();
// TODO: add stream filter class. --rareddy
rows = streamProducer.getResult(xml, getXPaths());
if (rows.isEmpty()) {
@@ -308,8 +308,8 @@
}
- private List<Document> getDocumentStream(ExecutionInfo executionInfo) {
- ArrayList<Document> docs = new ArrayList<Document>();
+ private List<StremableDocument> getDocumentStream(ExecutionInfo executionInfo) {
+ ArrayList<StremableDocument> docs = new ArrayList<StremableDocument>();
// Is this a request part joining across a document
CriteriaDesc criterion = executionInfo.getResponseIDCriterion();
@@ -318,7 +318,7 @@
List<SQLXML> xmls = this.executionFactory.getResponse(responseid);
for (SQLXML xml:xmls) {
Assertion.isNotNull(xml);
- docs.add(new DocumentImpl(xml, responseid));
+ docs.add(new StremableDocument(xml, responseid));
}
} else {
// Not a join, but might still be cached.
@@ -332,7 +332,7 @@
}
}
this.executionFactory.setResponse(this.context.getExecutionCountIdentifier(),
responseBody);
- docs.add(new DocumentImpl(responseBody,
this.context.getExecutionCountIdentifier()));
+ docs.add(new StremableDocument(responseBody,
this.context.getExecutionCountIdentifier()));
}
return docs;
}
@@ -378,7 +378,7 @@
String inputParmsXPath =
props.get(DocumentBuilder.PARM_INPUT_XPATH_TABLE_PROPERTY_NAME);
String namespacePrefixes = props.get(Constants.NAMESPACE_PREFIX_PROPERTY_NAME);
- if(inputParmsXPath.equals(SLASH)) {
+ if(inputParmsXPath == null || inputParmsXPath.equals(SLASH)) {
inputParmsXPath = "SLASH"; //$NON-NLS-1$
}
Deleted:
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/streaming/DocumentImpl.java
===================================================================
---
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/streaming/DocumentImpl.java 2010-05-21
20:33:45 UTC (rev 2148)
+++
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/streaming/DocumentImpl.java 2010-05-22
21:57:32 UTC (rev 2149)
@@ -1,27 +0,0 @@
-package org.teiid.translator.xml.streaming;
-
-import java.io.InputStream;
-import java.sql.SQLException;
-import java.sql.SQLXML;
-
-public class DocumentImpl implements org.teiid.translator.xml.Document {
-
- private SQLXML xml;
- private String cacheKey;
-
- public DocumentImpl(SQLXML xml, String cacheKey) {
- this.xml = xml;
- this.cacheKey = cacheKey;
- }
-
- @Override
- public InputStream getStream() throws SQLException{
- return xml.getBinaryStream();
- }
-
- @Override
- public String getCachekey() {
- return cacheKey;
- }
-
-}
Modified:
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/streaming/ElementProcessor.java
===================================================================
---
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/streaming/ElementProcessor.java 2010-05-21
20:33:45 UTC (rev 2148)
+++
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/streaming/ElementProcessor.java 2010-05-22
21:57:32 UTC (rev 2149)
@@ -1,7 +1,6 @@
package org.teiid.translator.xml.streaming;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -14,9 +13,9 @@
import org.teiid.translator.TranslatorException;
import org.teiid.translator.xml.CriteriaDesc;
-import org.teiid.translator.xml.Document;
import org.teiid.translator.xml.ExecutionInfo;
import org.teiid.translator.xml.OutputXPathDesc;
+import org.teiid.translator.xml.StremableDocument;
import org.teiid.translator.xml.XMLPlugin;
@@ -31,10 +30,11 @@
*/
public class ElementProcessor {
+ private static final String CRITERIA_PREFIX = "_criteria_"; //$NON-NLS-1$
private ExecutionInfo info;
private Object[] row;
private Map<String, OutputXPathDesc> resultPaths;
- private OutputXPathDesc cacheKeyColumn;
+ private OutputXPathDesc responseId;
private Map<String, String> namespacesToPrefixMap;
private boolean rowExcluded = false;
@@ -52,7 +52,7 @@
public Object[] process(Node element) {
setRowExcluded(false);
row = new Object[resultPaths.size()];
- listChildren(element, "");
+ listChildren(element, ""); //$NON-NLS-1$
return row;
}
@@ -61,26 +61,37 @@
* @param xml the XML Document
* @param result the result batch for the query
*/
- public void insertResponseId(Document xml, List<Object[]> result) {
- if (null != cacheKeyColumn) {
- Object[] aRow;
+ public void insertProjectedParameters(StremableDocument xml, List<Object[]>
result) {
+ if (responseId != null) {
if (!result.isEmpty()) {
- for (Iterator<Object[]> iter = result.iterator(); iter.hasNext();) {
- aRow = iter.next();
- aRow[cacheKeyColumn.getColumnNumber()] = xml.getCachekey();
+ for (Object[] aRow:result) {
+ aRow[responseId.getColumnNumber()] = xml.getCachekey();
}
} else {
- aRow = new Object[resultPaths.size()];
- aRow[cacheKeyColumn.getColumnNumber()] = xml.getCachekey();
+ Object[] aRow = new Object[resultPaths.size()];
+ aRow[responseId.getColumnNumber()] = xml.getCachekey();
result.add(aRow);
}
}
+
+ for (String column:resultPaths.keySet()) {
+ if (column != null && column.startsWith(CRITERIA_PREFIX)) {
+ OutputXPathDesc oxd = this.resultPaths.get(column);
+
+ if (!result.isEmpty()) {
+ for (Object[] aRow:result) {
+ aRow[oxd.getColumnNumber()] = oxd.getCurrentValue();
+ }
+ }
+ else {
+ Object[] aRow = new Object[resultPaths.size()];
+ aRow[oxd.getColumnNumber()] = oxd.getCurrentValue();
+ result.add(aRow);
+ }
+ }
+ }
}
- private void insertProjectedParameters() {
- //TODO insertProjectedParameters
- }
-
/**
* Match the current path against the Map of requested paths and add
* the matches to the result row.
@@ -97,7 +108,12 @@
Element temp = (Element) current;
for (int i = 0; i < temp.getAttributeCount(); i++) {
Attribute attribute = temp.getAttribute(i);
- String attrPath = path + "/@" + getLocalQName(attribute);
+
+ String attrPath = "@" + getLocalQName(attribute); //$NON-NLS-1$
+ if (path != null && path.length()> 0) {
+ attrPath = path + "/@" + getLocalQName(attribute); //$NON-NLS-1$
+ }
+
if(resultPaths.containsKey(attrPath)) {
handleNode(attribute, attrPath);
if(isRowExcluded()) {
@@ -115,7 +131,7 @@
path = path + '/' + temp.getRootElementName();
}
else if (current instanceof Text) {
- String textPath = path + "/text()";
+ String textPath = path + "/text()"; //$NON-NLS-1$
if(resultPaths.containsKey(textPath)) {
handleNode(current, textPath);
if(isRowExcluded()) {
@@ -161,7 +177,7 @@
localName = attribute.getLocalName();
}
if(null == namespaceURI) {
- throw new Error("namespce URI not found in model namespaces");
+ throw new Error("namespce URI not found in model namespaces");
//$NON-NLS-1$
}
String prefix = namespacesToPrefixMap.get(namespaceURI);
String result;
@@ -180,10 +196,9 @@
if(!passesCriteriaCheck(info.getCriteria(), node.getValue(), columnNum)) {
setRowExcluded(true);
return;
- } else {
- //TODO: type conversion
- row[columnNum] = node.getValue();
- }
+ }
+ //TODO: type conversion
+ row[columnNum] = node.getValue();
}
/**
@@ -229,8 +244,11 @@
if (xpathString != null) {
xpathString = relativizeAbsoluteXpath(xpathString);
}
+ else if (xPathDesc.getCurrentValue() != null) {
+ xpathString = CRITERIA_PREFIX+xPathDesc.getColumnName();
+ }
} else {
- cacheKeyColumn = xPathDesc;
+ responseId = xPathDesc;
}
xpaths.put(xpathString, xPathDesc);
}
Modified:
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/streaming/StreamingResultsProducer.java
===================================================================
---
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/streaming/StreamingResultsProducer.java 2010-05-21
20:33:45 UTC (rev 2148)
+++
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/streaming/StreamingResultsProducer.java 2010-05-22
21:57:32 UTC (rev 2149)
@@ -26,7 +26,7 @@
import java.util.Map;
import org.teiid.translator.TranslatorException;
-import org.teiid.translator.xml.Document;
+import org.teiid.translator.xml.StremableDocument;
import org.teiid.translator.xml.ExecutionInfo;
import org.teiid.translator.xml.SAXFilterProvider;
import org.xml.sax.SAXException;
@@ -63,7 +63,7 @@
* @return result set rows
* @throws TranslatorException
*/
- public List<Object[]> getResult(Document xml, List<String> xpaths) throws
TranslatorException {
+ public List<Object[]> getResult(StremableDocument xml, List<String>
xpaths) throws TranslatorException {
List<Object[]> rows;
try {
Modified:
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/streaming/StreamingRowCollector.java
===================================================================
---
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/streaming/StreamingRowCollector.java 2010-05-21
20:33:45 UTC (rev 2148)
+++
trunk/connectors/translator-xml/src/main/java/org/teiid/translator/xml/streaming/StreamingRowCollector.java 2010-05-22
21:57:32 UTC (rev 2149)
@@ -11,7 +11,7 @@
import nux.xom.xquery.StreamingTransform;
import org.teiid.translator.TranslatorException;
-import org.teiid.translator.xml.Document;
+import org.teiid.translator.xml.StremableDocument;
import org.xml.sax.XMLReader;
@@ -42,7 +42,7 @@
* @throws TranslatorException
* @throws InvalidPathException
*/
- public List<Object[]> getElements(Document xml, List<String> xPaths)
+ public List<Object[]> getElements(StremableDocument xml, List<String>
xPaths)
throws TranslatorException, InvalidPathException {
result.clear();
StreamingTransform myTransform = new StreamingTransform() {
@@ -61,7 +61,7 @@
} catch (Exception e) {
throw new TranslatorException(e);
}
- elemProcessor.insertResponseId(xml, result);
+ elemProcessor.insertProjectedParameters(xml, result);
return result;
}
Modified:
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/TestElementCollector.java
===================================================================
---
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/TestElementCollector.java 2010-05-21
20:33:45 UTC (rev 2148)
+++
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/TestElementCollector.java 2010-05-22
21:57:32 UTC (rev 2149)
@@ -14,8 +14,6 @@
import org.teiid.core.types.InputStreamFactory;
import org.teiid.core.types.SQLXMLImpl;
import org.teiid.language.Select;
-import org.teiid.translator.xml.Document;
-import org.teiid.translator.xml.streaming.DocumentImpl;
import org.teiid.translator.xml.streaming.ElementProcessor;
import org.teiid.translator.xml.streaming.ReaderFactory;
import org.teiid.translator.xml.streaming.StreamingRowCollector;
@@ -52,7 +50,7 @@
String path = "/po:purchaseOrders/order/items/item";
int itemCount = 5968;
try {
- Document doc = new DocumentImpl(getSQLXML(new FileInputStream(filename)),
"foo");
+ StremableDocument doc = new StremableDocument(getSQLXML(new
FileInputStream(filename)), "foo");
List result = builder.getElements(doc, Arrays.asList(path));
assertEquals(itemCount, result.size());
} catch (Exception e) {
@@ -64,7 +62,7 @@
String path = "/";
int itemCount = 1;
try {
- Document doc = new DocumentImpl(getSQLXML(new FileInputStream(filename)),
"foo");
+ StremableDocument doc = new StremableDocument(getSQLXML(new
FileInputStream(filename)), "foo");
List result = builder.getElements(doc, Arrays.asList(path));
assertEquals(itemCount, result.size());
} catch (Exception e) {
Added:
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/streaming/TestHttpExecution.java
===================================================================
---
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/streaming/TestHttpExecution.java
(rev 0)
+++
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/streaming/TestHttpExecution.java 2010-05-22
21:57:32 UTC (rev 2149)
@@ -0,0 +1,181 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.translator.xml.streaming;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.StringReader;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.resource.ResourceException;
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.ws.handler.MessageContext;
+
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.resource.spi.BasicConnection;
+import org.teiid.resource.spi.BasicConnectionFactory;
+import org.teiid.translator.ExecutionContext;
+import org.teiid.translator.xml.XMLExecutionFactory;
+import org.teiid.translator.xml.streaming.TestSoapExecution.MyDispatch;
+
+import com.metamatrix.cdk.api.ConnectorHost;
+
+@SuppressWarnings("nls")
+public class TestHttpExecution {
+
+
+ public static BasicConnectionFactory getCF() {
+ BasicConnectionFactory cf = new BasicConnectionFactory() {
+ @Override
+ public BasicConnection getConnection() throws ResourceException {
+ String usResult = "<?xml version=\"1.0\"
encoding=\"UTF-8\"?>\n" +
+ "<ns2:purchaseOrderList
xmlns:ns2=\"http://www.example.com/PO1\"
xmlns:ns3=\"http://www.example.org/PO1\">\n" +
+ " <ns3:purchaseOrders
orderDate=\"2010-05-22-04:00\">\n" +
+ " <shipTo country=\"Ship_Country_6\">\n" +
+ " <name>Ship_Name_6</name>\n" +
+ " <street>Ship_Street_6</street>\n" +
+ " <city>Ship_City_6</city>\n" +
+ " <state>Ship_State_6</state>\n" +
+ " <zip>6</zip>\n" +
+ " </shipTo>\n" +
+ " <billTo country=\"Bill_Country_6\">\n" +
+ " <name>Bill_Name_6</name>\n" +
+ " <street>Bill_Street_6</street>\n" +
+ " <city>Bill_City_6</city>\n" +
+ " <state>Bill_State_6</state>\n" +
+ " <zip>6</zip>\n" +
+ " </billTo>\n" +
+ " <items>\n" +
+ " <item partNum=\"0\">\n" +
+ " <productName>Product0</productName>\n" +
+ " <quantity>0</quantity>\n" +
+ " <USPrice>0</USPrice>\n" +
+ " <ns2:comment>Comment 0</ns2:comment>\n" +
+ " <shipDate>2010-05-22-04:00</shipDate>\n" +
+ " </item>\n" +
+ " <item partNum=\"1\">\n" +
+ " <productName>Product1</productName>\n" +
+ " <quantity>1</quantity>\n" +
+ " <USPrice>1</USPrice>\n" +
+ " <ns2:comment>Comment 1</ns2:comment>\n" +
+ " <shipDate>2010-05-22-04:00</shipDate>\n" +
+ " </item>\n" +
+ " <item partNum=\"2\">\n" +
+ " <productName>Product2</productName>\n" +
+ " <quantity>2</quantity>\n" +
+ " <USPrice>2</USPrice>\n" +
+ " <ns2:comment>Comment 2</ns2:comment>\n" +
+ " <shipDate>2010-05-22-04:00</shipDate>\n" +
+ " </item>\n" +
+ " </items>\n" +
+ " </ns3:purchaseOrders>\n" +
+ " <ns3:purchaseOrders
orderDate=\"2010-05-22-04:00\">\n" +
+ " <shipTo country=\"Ship_Country_7\">\n" +
+ " <name>Ship_Name_7</name>\n" +
+ " <street>Ship_Street_7</street>\n" +
+ " <city>Ship_City_7</city>\n" +
+ " <state>Ship_State_7</state>\n" +
+ " <zip>7</zip>\n" +
+ " </shipTo>\n" +
+ " <billTo country=\"Bill_Country_7\">\n" +
+ " <name>Bill_Name_7</name>\n" +
+ " <street>Bill_Street_7</street>\n" +
+ " <city>Bill_City_7</city>\n" +
+ " <state>Bill_State_7</state>\n" +
+ " <zip>7</zip>\n" +
+ " </billTo>\n" +
+ " <items>\n" +
+ " <item partNum=\"0\">\n" +
+ " <productName>Product0</productName>\n" +
+ " <quantity>0</quantity>\n" +
+ " <USPrice>0</USPrice>\n" +
+ " <ns2:comment>Comment 0</ns2:comment>\n" +
+ " <shipDate>2010-05-22-04:00</shipDate>\n" +
+ " </item>\n" +
+ " <item partNum=\"1\">\n" +
+ " <productName>Product1</productName>\n" +
+ " <quantity>1</quantity>\n" +
+ " <USPrice>1</USPrice>\n" +
+ " <ns2:comment>Comment 1</ns2:comment>\n" +
+ " <shipDate>2010-05-22-04:00</shipDate>\n" +
+ " </item>\n" +
+ " <item partNum=\"2\">\n" +
+ " <productName>Product2</productName>\n" +
+ " <quantity>2</quantity>\n" +
+ " <USPrice>2</USPrice>\n" +
+ " <ns2:comment>Comment 2</ns2:comment>\n" +
+ " <shipDate>2010-05-22-04:00</shipDate>\n" +
+ " </item>\n" +
+ " </items>\n" +
+ " </ns3:purchaseOrders>\n" +
+ "</ns2:purchaseOrderList>";
+
+
+ HashMap<String, String> map = new HashMap<String, String>();
+ map.put("result", usResult);
+ return new HttpDispatch(map);
+ }
+
+ };
+ return cf;
+ }
+
+ static class HttpDispatch extends MyDispatch{
+
+ public HttpDispatch(Map<String, String> result) {
+ super(result);
+ }
+
+ @Override
+ public Source invoke(Source msg) {
+ String qt = (String)this.getRequestContext().get(MessageContext.QUERY_STRING);
+ assertEquals("orderCount=2&itemCount=3&", qt);
+ return new StreamSource(new StringReader(result.get("result")));
//$NON-NLS-1$
+ }
+ }
+
+ @Test
+ public void testHttpExecution() throws Exception{
+ XMLExecutionFactory factory = new XMLExecutionFactory();
+
+ String vdbPath = UnitTestUtil.getTestDataPath()+"/xmltest.vdb";
+ ConnectorHost host = new ConnectorHost(factory, getCF(), vdbPath);
+ ExecutionContext context = Mockito.mock(ExecutionContext.class);
+ Mockito.stub(context.getExecutionCountIdentifier()).toReturn("1.1");
+ host.setExecutionContext(context);
+
+ List result = host.executeCommand("SELECT queryParams.REQUEST.ResponseOut,
queryParams.REQUEST.itemcount, queryParams.REQUEST.ordercount FROM queryParams.REQUEST
WHERE (queryParams.REQUEST.itemcount = '3') AND (queryParams.REQUEST.ordercount =
'2')", false);
+ assertEquals(1, result.size());
+ assertEquals(Arrays.asList(new Object[] {"1.1", "3",
"2"}), result.get(0));
+
+ result = host.executeCommand("SELECT queryParams.item.partNum,
queryParams.item.productName, queryParams.item.quantity, queryParams.item.USPrice,
queryParams.item.comment, queryParams.item.shipDate FROM queryParams.item WHERE
queryParams.item.ResponseIn = '1.1'");
+
+ assertEquals(6, result.size());
+ assertEquals(Arrays.asList(new Object[] {"1",
"Product1","1","1","Comment
1","2010-05-22-04:00"}), result.get(1));
+ }
+}
Modified:
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/streaming/TestSoapExecution.java
===================================================================
---
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/streaming/TestSoapExecution.java 2010-05-21
20:33:45 UTC (rev 2148)
+++
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/streaming/TestSoapExecution.java 2010-05-22
21:57:32 UTC (rev 2149)
@@ -166,7 +166,7 @@
static class MyDispatch extends BasicConnection implements Dispatch<Source>{
private Map<String, Object> requestContext = new HashMap<String,
Object>();
- private Map<String, String> result;
+ Map<String, String> result;
public MyDispatch(Map<String, String> result) {
this.result = result;
Added: trunk/connectors/translator-xml/src/test/resources/xmltest.vdb
===================================================================
(Binary files differ)
Property changes on: trunk/connectors/translator-xml/src/test/resources/xmltest.vdb
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream