Search in sources :

Example 11 with XMLType

use of org.teiid.core.types.XMLType in project teiid by teiid.

the class WSWSDLProcedureExecution method getOutputParameterValues.

@Override
public List<?> getOutputParameterValues() throws TranslatorException {
    Object result = returnValue;
    if (returnValue != null && procedure.getArguments().size() > 1 && Boolean.TRUE.equals(procedure.getArguments().get(1).getArgumentValue().getValue())) {
        SQLXMLImpl sqlXml = new StAXSQLXML(returnValue);
        XMLType xml = new XMLType(sqlXml);
        xml.setType(Type.DOCUMENT);
        result = xml;
    }
    return Arrays.asList(result);
}
Also used : XMLType(org.teiid.core.types.XMLType) SQLXMLImpl(org.teiid.core.types.SQLXMLImpl) StAXSQLXML(org.teiid.util.StAXSQLXML)

Example 12 with XMLType

use of org.teiid.core.types.XMLType in project teiid by teiid.

the class SaxonXQueryExpression method createXMLType.

public XMLType createXMLType(final SequenceIterator iter, BufferManager bufferManager, boolean emptyOnEmpty, CommandContext context) throws XPathException, TeiidComponentException, TeiidProcessingException {
    final Item item = iter.next();
    if (item == null && !emptyOnEmpty) {
        return null;
    }
    XMLType.Type type = Type.CONTENT;
    if (item instanceof NodeInfo) {
        NodeInfo info = (NodeInfo) item;
        type = getType(info);
    }
    final Item next = iter.next();
    if (next != null) {
        type = Type.CONTENT;
    }
    SQLXMLImpl xml = XMLSystemFunctions.saveToBufferManager(bufferManager, new XMLTranslator() {

        @Override
        public void translate(Writer writer) throws TransformerException, IOException {
            QueryResult.serializeSequence(new PushBackSequenceIterator(iter, item, next), config, writer, DEFAULT_OUTPUT_PROPERTIES);
        }
    }, context);
    XMLType value = new XMLType(xml);
    value.setType(type);
    return value;
}
Also used : Item(net.sf.saxon.om.Item) NamespaceItem(org.teiid.query.sql.symbol.XMLNamespaces.NamespaceItem) XMLType(org.teiid.core.types.XMLType) SQLXMLImpl(org.teiid.core.types.SQLXMLImpl) NodeInfo(net.sf.saxon.om.NodeInfo) Type(org.teiid.core.types.XMLType.Type) IOException(java.io.IOException) XMLTranslator(org.teiid.core.types.XMLTranslator) Writer(java.io.Writer) TransformerException(javax.xml.transform.TransformerException)

Example 13 with XMLType

use of org.teiid.core.types.XMLType in project teiid by teiid.

the class XQueryEvaluator method evaluate.

public static Object evaluate(XMLType value, XMLCast expression, CommandContext context) throws ExpressionEvaluationException {
    Configuration config = new Configuration();
    Type t = value.getType();
    try {
        Item i = null;
        switch(t) {
            case CONTENT:
            // content could map to an array value, but we aren't handling that case here yet - only in xmltable
            case COMMENT:
            case PI:
                throw new FunctionExecutionException();
            case TEXT:
                i = new StringValue(value.getString());
                break;
            case UNKNOWN:
            case DOCUMENT:
            case ELEMENT:
                StreamSource ss = value.getSource(StreamSource.class);
                try {
                    i = config.buildDocument(ss);
                } finally {
                    if (ss.getInputStream() != null) {
                        ss.getInputStream().close();
                    }
                    if (ss.getReader() != null) {
                        ss.getReader().close();
                    }
                }
                break;
            default:
                // $NON-NLS-1$
                throw new AssertionError("Unknown xml value type " + t);
        }
        return XMLTableNode.getValue(expression.getType(), i, config, context);
    } catch (IOException e) {
        throw new FunctionExecutionException(e);
    } catch (ValidationException e) {
        throw new FunctionExecutionException(e);
    } catch (TransformationException e) {
        throw new FunctionExecutionException(e);
    } catch (XPathException e) {
        throw new FunctionExecutionException(e);
    } catch (SQLException e) {
        throw new FunctionExecutionException(e);
    }
}
Also used : Item(net.sf.saxon.om.Item) BinaryType(org.teiid.core.types.BinaryType) XMLType(org.teiid.core.types.XMLType) DocType(nu.xom.DocType) Type(org.teiid.core.types.XMLType.Type) TransformationException(org.teiid.core.types.TransformationException) FunctionExecutionException(org.teiid.api.exception.query.FunctionExecutionException) ValidationException(net.sf.saxon.type.ValidationException) Configuration(net.sf.saxon.Configuration) XPathException(net.sf.saxon.trans.XPathException) SQLException(java.sql.SQLException) StreamSource(javax.xml.transform.stream.StreamSource) IOException(java.io.IOException) StringValue(net.sf.saxon.value.StringValue)

Example 14 with XMLType

use of org.teiid.core.types.XMLType in project teiid by teiid.

the class WSProcedureExecution method execute.

@SuppressWarnings("unchecked")
public void execute() throws TranslatorException {
    List<Argument> arguments = this.procedure.getArguments();
    String style = (String) arguments.get(0).getArgumentValue().getValue();
    String action = (String) arguments.get(1).getArgumentValue().getValue();
    XMLType docObject = (XMLType) arguments.get(2).getArgumentValue().getValue();
    Source source = null;
    try {
        Class type = StAXSource.class;
        if (executionFactory.getDefaultServiceMode() == Mode.MESSAGE) {
            type = DOMSource.class;
        }
        source = convertToSource(type, docObject);
        String endpoint = (String) arguments.get(3).getArgumentValue().getValue();
        if (style == null) {
            style = executionFactory.getDefaultBinding().getBindingId();
        } else {
            try {
                style = Binding.valueOf(style.toUpperCase()).getBindingId();
            } catch (IllegalArgumentException e) {
                // $NON-NLS-1$
                throw new TranslatorException(WSExecutionFactory.UTIL.getString("invalid_invocation", Arrays.toString(Binding.values())));
            }
        }
        Dispatch dispatch = conn.createDispatch(style, endpoint, type, executionFactory.getDefaultServiceMode());
        if (Binding.HTTP.getBindingId().equals(style)) {
            if (action == null) {
                // $NON-NLS-1$
                action = "POST";
            }
            dispatch.getRequestContext().put(MessageContext.HTTP_REQUEST_METHOD, action);
            if (source != null && !"POST".equalsIgnoreCase(action)) {
                // $NON-NLS-1$
                if (this.executionFactory.getXMLParamName() == null) {
                    // $NON-NLS-1$
                    throw new WebServiceException(WSExecutionFactory.UTIL.getString("http_usage_error"));
                }
                try {
                    Transformer t = TransformerFactory.newInstance().newTransformer();
                    StringWriter writer = new StringWriter();
                    // TODO: prevent this from being too large
                    t.transform(source, new StreamResult(writer));
                    // $NON-NLS-1$
                    String param = Util.httpURLEncode(this.executionFactory.getXMLParamName()) + "=" + Util.httpURLEncode(writer.toString());
                    endpoint = WSConnection.Util.appendQueryString(endpoint, param);
                } catch (TransformerException e) {
                    throw new WebServiceException(e);
                }
            }
        } else {
            if (action != null) {
                dispatch.getRequestContext().put(Dispatch.SOAPACTION_USE_PROPERTY, Boolean.TRUE);
                dispatch.getRequestContext().put(Dispatch.SOAPACTION_URI_PROPERTY, action);
            }
        }
        if (source == null) {
            // JBoss Native DispatchImpl throws exception when the source is null
            // $NON-NLS-1$
            source = new StAXSource(XMLType.getXmlInputFactory().createXMLEventReader(new StringReader("<none/>")));
        }
        this.returnValue = (Source) dispatch.invoke(source);
    } catch (SQLException e) {
        throw new TranslatorException(e);
    } catch (WebServiceException e) {
        throw new TranslatorException(e);
    } catch (XMLStreamException e) {
        throw new TranslatorException(e);
    } finally {
        Util.closeSource(source);
    }
}
Also used : Transformer(javax.xml.transform.Transformer) Argument(org.teiid.language.Argument) WebServiceException(javax.xml.ws.WebServiceException) StreamResult(javax.xml.transform.stream.StreamResult) SQLException(java.sql.SQLException) Dispatch(javax.xml.ws.Dispatch) StAXSource(javax.xml.transform.stax.StAXSource) DOMSource(javax.xml.transform.dom.DOMSource) Source(javax.xml.transform.Source) StAXSource(javax.xml.transform.stax.StAXSource) XMLType(org.teiid.core.types.XMLType) StringWriter(java.io.StringWriter) XMLStreamException(javax.xml.stream.XMLStreamException) StringReader(java.io.StringReader) TranslatorException(org.teiid.translator.TranslatorException) TransformerException(javax.xml.transform.TransformerException)

Example 15 with XMLType

use of org.teiid.core.types.XMLType in project teiid by teiid.

the class LobWorkItem method createLobStream.

/**
 * Create a object which can create a sequence of LobChunk objects on a given
 * LOB object
 * @throws SQLException
 */
private ByteLobChunkStream createLobStream(String referenceStreamId) throws TeiidComponentException, SQLException {
    // get the reference object in the buffer manager, and try to stream off
    // the original sources.
    Streamable<?> streamable = parent.resultsBuffer.getLobReference(referenceStreamId);
    if (streamable instanceof XMLType) {
        XMLType xml = (XMLType) streamable;
        return new ByteLobChunkStream(xml.getBinaryStream(), chunkSize);
    } else if (streamable instanceof ClobType) {
        ClobType clob = (ClobType) streamable;
        return new ByteLobChunkStream(new ReaderInputStream(clob.getCharacterStream(), Charset.forName(Streamable.ENCODING)), chunkSize);
    }
    BlobType blob = (BlobType) streamable;
    return new ByteLobChunkStream(blob.getBinaryStream(), chunkSize);
}
Also used : ClobType(org.teiid.core.types.ClobType) XMLType(org.teiid.core.types.XMLType) ReaderInputStream(org.teiid.core.util.ReaderInputStream) BlobType(org.teiid.core.types.BlobType)

Aggregations

XMLType (org.teiid.core.types.XMLType)25 SQLException (java.sql.SQLException)9 IOException (java.io.IOException)8 Test (org.junit.Test)7 SQLXMLImpl (org.teiid.core.types.SQLXMLImpl)7 Clob (java.sql.Clob)6 BlobType (org.teiid.core.types.BlobType)6 StringReader (java.io.StringReader)5 StAXSource (javax.xml.transform.stax.StAXSource)5 ClobType (org.teiid.core.types.ClobType)4 TranslatorException (org.teiid.translator.TranslatorException)4 XMLStreamException (javax.xml.stream.XMLStreamException)3 TransformerException (javax.xml.transform.TransformerException)3 StreamResult (javax.xml.transform.stream.StreamResult)3 WebServiceException (javax.xml.ws.WebServiceException)3 Item (net.sf.saxon.om.Item)3 InputStreamFactory (org.teiid.core.types.InputStreamFactory)3 TransformationException (org.teiid.core.types.TransformationException)3 Type (org.teiid.core.types.XMLType.Type)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2