Search in sources :

Example 86 with TranslatorException

use of org.teiid.translator.TranslatorException in project teiid by teiid.

the class WSDLMetadataProcessor method process.

@Override
public void process(MetadataFactory mf, WSConnection connection) throws TranslatorException {
    if (this.importWSDL && connection == null) {
        throw new TranslatorException(WSExecutionFactory.UTIL.gs(Event.TEIID15007, WSExecutionFactory.UTIL.gs(Event.TEIID15007)));
    }
    if (!importWSDL || connection.getWsdl() == null) {
        return;
    }
    String wsdl = connection.getWsdl().toString();
    try {
        WSDLFactory wsdlFactory = WSDLFactory.newInstance();
        WSDLReader reader = wsdlFactory.newWSDLReader();
        this.definition = reader.readWSDL(wsdl);
    } catch (WSDLException e) {
        throw new TranslatorException(e);
    }
    Map<QName, Service> services = this.definition.getServices();
    if (services == null || services.isEmpty()) {
        throw new TranslatorException(WSExecutionFactory.UTIL.gs(WSExecutionFactory.Event.TEIID15001, connection.getServiceQName()));
    }
    Service service = services.get(connection.getServiceQName());
    if (service == null) {
        throw new TranslatorException(WSExecutionFactory.UTIL.gs(WSExecutionFactory.Event.TEIID15001, connection.getServiceQName()));
    }
    Map<String, Port> ports = service.getPorts();
    Port port = ports.get(connection.getPortQName().getLocalPart());
    if (port == null) {
        throw new TranslatorException(WSExecutionFactory.UTIL.gs(WSExecutionFactory.Event.TEIID15002, connection.getPortQName(), connection.getServiceQName()));
    }
    getPortMetadata(mf, port);
}
Also used : WSDLFactory(javax.wsdl.factory.WSDLFactory) WSDLException(javax.wsdl.WSDLException) QName(javax.xml.namespace.QName) Port(javax.wsdl.Port) Service(javax.wsdl.Service) TranslatorException(org.teiid.translator.TranslatorException) WSDLReader(javax.wsdl.xml.WSDLReader)

Example 87 with TranslatorException

use of org.teiid.translator.TranslatorException in project teiid by teiid.

the class WSProcedureExecution method getOutputParameterValues.

@Override
public List<?> getOutputParameterValues() throws TranslatorException {
    Object result = returnValue;
    if (returnValue != null && (returnValue instanceof StAXSource) && procedure.getArguments().size() > 4 && procedure.getArguments().get(4).getDirection() == Direction.IN && Boolean.TRUE.equals(procedure.getArguments().get(4).getArgumentValue().getValue())) {
        SQLXMLImpl sqlXml = new StAXSQLXML((StAXSource) returnValue);
        XMLType xml = new XMLType(sqlXml);
        xml.setType(Type.DOCUMENT);
        result = xml;
    } else if (returnValue != null && returnValue instanceof DOMSource) {
        final DOMSource xmlSource = (DOMSource) returnValue;
        SQLXMLImpl sqlXml = new SQLXMLImpl(new InputStreamFactory() {

            @Override
            public InputStream getInputStream() throws IOException {
                ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
                Result outputTarget = new StreamResult(outputStream);
                try {
                    TransformerFactory.newInstance().newTransformer().transform(xmlSource, outputTarget);
                } catch (Exception e) {
                    throw new IOException(e);
                }
                return new ByteArrayInputStream(outputStream.toByteArray());
            }
        });
        XMLType xml = new XMLType(sqlXml);
        xml.setType(Type.DOCUMENT);
        result = xml;
    }
    return Arrays.asList(result);
}
Also used : SQLXMLImpl(org.teiid.core.types.SQLXMLImpl) DOMSource(javax.xml.transform.dom.DOMSource) StreamResult(javax.xml.transform.stream.StreamResult) StAXSource(javax.xml.transform.stax.StAXSource) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) InputStreamFactory(org.teiid.core.types.InputStreamFactory) TransformerException(javax.xml.transform.TransformerException) SQLException(java.sql.SQLException) XMLStreamException(javax.xml.stream.XMLStreamException) TranslatorException(org.teiid.translator.TranslatorException) DataNotAvailableException(org.teiid.translator.DataNotAvailableException) IOException(java.io.IOException) WebServiceException(javax.xml.ws.WebServiceException) StreamResult(javax.xml.transform.stream.StreamResult) Result(javax.xml.transform.Result) XMLType(org.teiid.core.types.XMLType) ByteArrayInputStream(java.io.ByteArrayInputStream) StAXSQLXML(org.teiid.util.StAXSQLXML)

Example 88 with TranslatorException

use of org.teiid.translator.TranslatorException in project teiid by teiid.

the class WSWSDLProcedureExecution method execute.

public void execute() throws TranslatorException {
    List<Argument> arguments = this.procedure.getArguments();
    XMLType docObject = (XMLType) arguments.get(0).getArgumentValue().getValue();
    StAXSource source = null;
    try {
        source = convertToSource(docObject);
        Dispatch<StAXSource> dispatch = conn.createDispatch(StAXSource.class, executionFactory.getDefaultServiceMode());
        String operation = this.procedure.getProcedureName();
        if (this.procedure.getMetadataObject() != null && this.procedure.getMetadataObject().getNameInSource() != null) {
            operation = this.procedure.getMetadataObject().getNameInSource();
        }
        QName opQName = new QName(conn.getServiceQName().getNamespaceURI(), operation);
        dispatch.getRequestContext().put(MessageContext.WSDL_OPERATION, opQName);
        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 = dispatch.invoke(source);
    } catch (SQLException e) {
        throw new TranslatorException(e);
    } catch (WebServiceException e) {
        throw new TranslatorException(e);
    } catch (XMLStreamException e) {
        throw new TranslatorException(e);
    } catch (IOException e) {
        throw new TranslatorException(e);
    } finally {
        Util.closeSource(source);
    }
}
Also used : Argument(org.teiid.language.Argument) WebServiceException(javax.xml.ws.WebServiceException) SQLException(java.sql.SQLException) QName(javax.xml.namespace.QName) StAXSource(javax.xml.transform.stax.StAXSource) IOException(java.io.IOException) XMLType(org.teiid.core.types.XMLType) XMLStreamException(javax.xml.stream.XMLStreamException) StringReader(java.io.StringReader) TranslatorException(org.teiid.translator.TranslatorException)

Example 89 with TranslatorException

use of org.teiid.translator.TranslatorException in project teiid by teiid.

the class SwaggerTypeManager method formTimestamp.

static Timestamp formTimestamp(String value) throws TranslatorException {
    Matcher m = timestampPattern.matcher((String) value);
    if (m.matches()) {
        Calendar cal = null;
        String timeZone = m.group(8);
        if (timeZone.equalsIgnoreCase("Z")) {
            cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
        } else {
            cal = Calendar.getInstance(TimeZone.getTimeZone("GMT" + m.group(9)));
        }
        cal.set(Integer.valueOf(m.group(1)), Integer.valueOf(m.group(2)) - 1, Integer.valueOf(m.group(3)), Integer.valueOf(m.group(4)), Integer.valueOf(m.group(5)), Integer.valueOf(m.group(6)));
        Timestamp ts = new Timestamp(cal.getTime().getTime());
        if (m.group(7) != null) {
            String fraction = m.group(7).substring(1);
            ts.setNanos(Integer.parseInt(fraction));
        } else {
            ts.setNanos(0);
        }
        return ts;
    } else {
        throw new TranslatorException(SwaggerPlugin.Util.gs(SwaggerPlugin.Event.TEIID28011, timestampPattern));
    }
}
Also used : Matcher(java.util.regex.Matcher) Calendar(java.util.Calendar) TranslatorException(org.teiid.translator.TranslatorException) Timestamp(java.sql.Timestamp)

Example 90 with TranslatorException

use of org.teiid.translator.TranslatorException in project teiid by teiid.

the class TestSwaggerMetadataProcessor method getMetadata.

private static MetadataFactory getMetadata(SwaggerExecutionFactory ef, final String file) throws TranslatorException {
    SwaggerMetadataProcessor processor = new SwaggerMetadataProcessor(ef) {

        protected Swagger getSchema(WSConnection conn) throws TranslatorException {
            File f = new File(file);
            ObjectMapper objectMapper = new ObjectMapper();
            try (FileInputStream fis = new FileInputStream(f)) {
                JsonNode rootNode = objectMapper.readTree(fis);
                return new SwaggerParser().read(rootNode, true);
            } catch (IOException e) {
                throw new TranslatorException(e);
            }
        }
    };
    processor.setPreferredProduces("application/json");
    processor.setPreferredConsumes("application/json");
    processor.setPreferredScheme("http");
    Properties props = new Properties();
    MetadataFactory mf = new MetadataFactory("vdb", 1, "swagger", SystemMetadata.getInstance().getRuntimeTypeMap(), props, null);
    processor.process(mf, null);
    return mf;
}
Also used : SwaggerParser(io.swagger.parser.SwaggerParser) WSConnection(org.teiid.translator.WSConnection) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) JsonNode(com.fasterxml.jackson.databind.JsonNode) TranslatorException(org.teiid.translator.TranslatorException) IOException(java.io.IOException) Properties(java.util.Properties) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FileInputStream(java.io.FileInputStream)

Aggregations

TranslatorException (org.teiid.translator.TranslatorException)227 ArrayList (java.util.ArrayList)51 Column (org.teiid.metadata.Column)47 List (java.util.List)32 Table (org.teiid.metadata.Table)30 IOException (java.io.IOException)26 SQLException (java.sql.SQLException)26 ResourceException (javax.resource.ResourceException)26 Test (org.junit.Test)16 Expression (org.teiid.language.Expression)16 Literal (org.teiid.language.Literal)16 DataNotAvailableException (org.teiid.translator.DataNotAvailableException)16 Blob (java.sql.Blob)15 Argument (org.teiid.language.Argument)13 DBObject (com.mongodb.DBObject)11 HashMap (java.util.HashMap)11 ColumnReference (org.teiid.language.ColumnReference)11 ExecutionContext (org.teiid.translator.ExecutionContext)11 BasicDBObject (com.mongodb.BasicDBObject)10 RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)10