Search in sources :

Example 16 with TeiidProcessingException

use of org.teiid.core.TeiidProcessingException in project teiid by teiid.

the class ODataFilter method internalDoFilter.

public void internalDoFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException, TeiidProcessingException {
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    String proxyURI = this.proxyBaseURI;
    if (proxyURI != null) {
        httpRequest = new ProxyHttpServletRequest(httpRequest, proxyURI);
    }
    VDBKey key = null;
    String vdbName = null;
    String version = null;
    String modelName = null;
    String uri = ((HttpServletRequest) request).getRequestURI().toString();
    String fullURL = ((HttpServletRequest) request).getRequestURL().toString();
    if (uri.startsWith("/odata4/static/") || uri.startsWith("/odata4/keycloak/")) {
        // $NON-NLS-1$ //$NON-NLS-2$
        chain.doFilter(httpRequest, response);
        return;
    }
    String contextPath = httpRequest.getContextPath();
    String baseURI = fullURL.substring(0, fullURL.indexOf(contextPath));
    int endIdx = uri.indexOf('/', contextPath.length() + 1);
    int beginIdx = contextPath.length() + 1;
    if (contextPath.equals("/odata4")) {
        // $NON-NLS-1$
        if (endIdx == -1) {
            throw new TeiidProcessingException(ODataPlugin.Event.TEIID16020, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16020));
        }
        // $NON-NLS-1$
        baseURI = baseURI + "/odata4";
        vdbName = uri.substring(beginIdx, endIdx);
        int modelIdx = uri.indexOf('/', endIdx + 1);
        if (modelIdx == -1) {
            modelName = uri.substring(endIdx + 1).trim();
            if (modelName.isEmpty()) {
                throw new TeiidProcessingException(ODataPlugin.Event.TEIID16019, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16019));
            }
        } else {
            modelName = uri.substring(endIdx + 1, modelIdx);
        }
        // $NON-NLS-1$ //$NON-NLS-2$
        contextPath = contextPath + "/" + vdbName + "/" + modelName;
        vdbName = vdbName.trim();
        if (vdbName.isEmpty()) {
            throw new TeiidProcessingException(ODataPlugin.Event.TEIID16008, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16008));
        }
    } else {
        if (this.initProperties.getProperty("vdb-name") == null) {
            // $NON-NLS-1$
            throw new TeiidProcessingException(ODataPlugin.Event.TEIID16018, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16018));
        }
        // $NON-NLS-1$
        vdbName = this.initProperties.getProperty("vdb-name");
        // $NON-NLS-1$
        version = this.initProperties.getProperty("vdb-version");
        if (endIdx == -1) {
            modelName = uri.substring(beginIdx).trim();
            if (modelName.isEmpty()) {
                throw new TeiidProcessingException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16021));
            }
        } else {
            modelName = uri.substring(beginIdx, endIdx);
        }
        // $NON-NLS-1$
        contextPath = contextPath + "/" + modelName;
    }
    ContextAwareHttpSerlvetRequest contextAwareRequest = new ContextAwareHttpSerlvetRequest(httpRequest);
    contextAwareRequest.setContextPath(contextPath);
    httpRequest = contextAwareRequest;
    key = new VDBKey(vdbName, version);
    if (key.isAtMost()) {
        if (key.getVersion() != null) {
            throw new TeiidProcessingException(ODataPlugin.Event.TEIID16044, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16044, key));
        }
        // $NON-NLS-1$ //legacy behavior, default to version 1
        key = new VDBKey(vdbName, "1");
    }
    SoftReference<OlingoBridge> ref = this.contextMap.get(key);
    OlingoBridge context = null;
    if (ref != null) {
        context = ref.get();
    }
    if (context == null) {
        context = new OlingoBridge();
        ref = new SoftReference<OlingoBridge>(context);
        this.contextMap.put(key, ref);
    }
    Client client = buildClient(key.getName(), key.getVersion(), this.initProperties);
    try {
        Connection connection = client.open();
        registerVDBListener(client, connection);
        ODataHttpHandler handler = context.getHandler(baseURI, client, modelName);
        httpRequest.setAttribute(ODataHttpHandler.class.getName(), handler);
        httpRequest.setAttribute(Client.class.getName(), client);
        chain.doFilter(httpRequest, response);
    } catch (SQLException e) {
        throw new TeiidProcessingException(e);
    } finally {
        try {
            client.close();
        } catch (SQLException e) {
        // ignore
        }
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) LocalServerConnection(org.teiid.transport.LocalServerConnection) OlingoBridge(org.teiid.olingo.service.OlingoBridge) ODataHttpHandler(org.apache.olingo.server.api.ODataHttpHandler) TeiidProcessingException(org.teiid.core.TeiidProcessingException) HttpServletRequest(javax.servlet.http.HttpServletRequest) VDBKey(org.teiid.vdb.runtime.VDBKey) Client(org.teiid.odata.api.Client) LocalClient(org.teiid.olingo.service.LocalClient)

Example 17 with TeiidProcessingException

use of org.teiid.core.TeiidProcessingException in project teiid by teiid.

the class TestSQLException method testCreateThrowable_01.

/*
	 * Test method for 'com.metamatrix.jdbc.MMSQLException.create(Throwable)'
	 * 
	 * Tests various simple exceptions to see if the expected SQLState is
	 * returend.
	 */
@Test
public void testCreateThrowable_01() {
    testCreateThrowable(new CommunicationException(// $NON-NLS-1$
    "A test MM Communication Exception"), SQLStates.CONNECTION_EXCEPTION_STALE_CONNECTION);
    testCreateThrowable(// $NON-NLS-1$
    new ConnectException("A test connection attempt exception"), SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
    testCreateThrowable(// $NON-NLS-1$
    new ConnectionException("A test MM Connection Exception"), SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
    testCreateThrowable(new IOException(// $NON-NLS-1$
    "A test Generic java.io.IOException"), SQLStates.CONNECTION_EXCEPTION_STALE_CONNECTION);
    testCreateThrowable(new MalformedURLException(// $NON-NLS-1$
    "A test java.net.MalformedURLException"), SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
    testCreateThrowable(new TeiidException("A test Generic MM Core Exception"), // $NON-NLS-1$
    SQLStates.DEFAULT);
    testCreateThrowable(// $NON-NLS-1$
    new TeiidException("A test MM Exception"), SQLStates.DEFAULT);
    testCreateThrowable(new TeiidProcessingException(// $NON-NLS-1$
    "A test Generic MM Query Processing Exception"), SQLStates.USAGE_ERROR);
    testCreateThrowable(new TeiidRuntimeException("A test MM Runtime Exception"), // $NON-NLS-1$
    SQLStates.DEFAULT);
    testCreateThrowable(new TeiidSQLException("A test Generic MM SQL Exception"), // $NON-NLS-1$
    SQLStates.DEFAULT);
    testCreateThrowable(new NoRouteToHostException(// $NON-NLS-1$
    "A test java.net.NoRouteToHostException"), SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
    testCreateThrowable(// $NON-NLS-1$
    new NullPointerException("A test NPE"), SQLStates.DEFAULT);
    testCreateThrowable(new ProcedureErrorInstructionException(// $NON-NLS-1$
    "A test SQL Procedure Error exception"), SQLStates.VIRTUAL_PROCEDURE_ERROR);
    testCreateThrowable(new SocketTimeoutException(// $NON-NLS-1$
    "A test socket timeout exception"), SQLStates.CONNECTION_EXCEPTION_STALE_CONNECTION);
    testCreateThrowable(// $NON-NLS-1$
    new UnknownHostException("A test connection attempt exception"), SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
}
Also used : MalformedURLException(java.net.MalformedURLException) CommunicationException(org.teiid.net.CommunicationException) UnknownHostException(java.net.UnknownHostException) ProcedureErrorInstructionException(org.teiid.client.ProcedureErrorInstructionException) IOException(java.io.IOException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) NoRouteToHostException(java.net.NoRouteToHostException) TeiidException(org.teiid.core.TeiidException) TeiidProcessingException(org.teiid.core.TeiidProcessingException) SocketTimeoutException(java.net.SocketTimeoutException) ConnectionException(org.teiid.net.ConnectionException) ConnectException(java.net.ConnectException) Test(org.junit.Test)

Example 18 with TeiidProcessingException

use of org.teiid.core.TeiidProcessingException in project teiid by teiid.

the class TestSubqueryPushdown method testSubqueryProducingBuffer.

@Test
public void testSubqueryProducingBuffer() throws Exception {
    TransformationMetadata tm = RealMetadataFactory.example1Cached();
    String sql = "SELECT e1, (select e2 from pm2.g1 where e1 = pm1.g1.e1 order by e2 limit 1) from pm1.g1 limit 1";
    BasicSourceCapabilities bsc = getTypicalCapabilities();
    bsc.setCapabilitySupport(Capability.QUERY_ORDERBY, false);
    ProcessorPlan plan = // $NON-NLS-1$
    TestOptimizer.helpPlan(// $NON-NLS-1$
    sql, tm, null, new DefaultCapabilitiesFinder(bsc), new String[] { "SELECT g_0.e1 FROM pm1.g1 AS g_0" }, // $NON-NLS-1$
    ComparisonMode.EXACT_COMMAND_STRING);
    HardcodedDataManager hdm = new HardcodedDataManager(tm) {

        @Override
        public TupleSource registerRequest(CommandContext context, Command command, String modelName, RegisterRequestParameter parameterObject) throws TeiidComponentException {
            if (command.toString().equals("SELECT g_0.e2 FROM pm2.g1 AS g_0 WHERE g_0.e1 = 'a'")) {
                return new TupleSource() {

                    @Override
                    public List<?> nextTuple() throws TeiidComponentException, TeiidProcessingException {
                        throw new TeiidProcessingException("something's wrong");
                    }

                    @Override
                    public void closeSource() {
                    }
                };
            }
            return super.registerRequest(context, command, modelName, parameterObject);
        }
    };
    hdm.addData("SELECT g_0.e1 FROM g1 AS g_0", Arrays.asList("a"));
    hdm.setBlockOnce(true);
    CommandContext cc = TestProcessor.createCommandContext();
    cc.setMetadata(tm);
    try {
        TestProcessor.helpProcess(plan, cc, hdm, new List[] { Arrays.asList(2) });
        fail();
    } catch (TeiidProcessingException e) {
        assert (e.getMessage().contains("something's wrong"));
    }
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) CommandContext(org.teiid.query.util.CommandContext) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) HardcodedDataManager(org.teiid.query.processor.HardcodedDataManager) Command(org.teiid.query.sql.lang.Command) TupleSource(org.teiid.common.buffer.TupleSource) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) RegisterRequestParameter(org.teiid.query.processor.RegisterRequestParameter) TeiidProcessingException(org.teiid.core.TeiidProcessingException) Test(org.junit.Test)

Example 19 with TeiidProcessingException

use of org.teiid.core.TeiidProcessingException in project teiid by teiid.

the class TextTableNode method processHeader.

private void processHeader(List<String> line) throws TeiidProcessingException {
    nameIndexes = new HashMap<String, Integer>();
    this.lineWidth = DataTypeManager.MAX_STRING_LENGTH * line.size();
    for (String string : line) {
        if (string == null) {
            continue;
        }
        nameIndexes.put(string.toUpperCase(), nameIndexes.size());
    }
    for (TextColumn col : table.getColumns()) {
        if (col.isOrdinal()) {
            continue;
        }
        String name = col.getName().toUpperCase();
        if (col.getHeader() != null) {
            name = col.getHeader().toUpperCase();
        }
        Integer index = nameIndexes.get(name);
        if (index == null) {
            throw new TeiidProcessingException(QueryPlugin.Event.TEIID30181, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30181, col.getName(), systemId));
        }
        nameIndexes.put(col.getName(), index);
    }
}
Also used : TextColumn(org.teiid.query.sql.lang.TextTable.TextColumn) TeiidProcessingException(org.teiid.core.TeiidProcessingException)

Example 20 with TeiidProcessingException

use of org.teiid.core.TeiidProcessingException in project teiid by teiid.

the class TextTableNode method process.

private void process() throws TeiidProcessingException {
    while (true) {
        synchronized (this) {
            if (isBatchFull()) {
                return;
            }
            StringBuilder line = readLine(lineWidth, table.isFixedWidth());
            if (line == null) {
                terminateBatches();
                break;
            }
            String parentSelector = null;
            if (table.getSelector() != null) {
                if (line.length() < table.getSelector().length()) {
                    continue;
                }
                if (!line.substring(0, table.getSelector().length()).equals(table.getSelector())) {
                    if (parentLines == null) {
                        // doesn't match any selector
                        continue;
                    }
                    parentSelector = line.substring(0, table.getSelector().length());
                    if (!parentLines.containsKey(parentSelector)) {
                        // doesn't match any selector
                        continue;
                    }
                }
            }
            List<String> vals = parseLine(line);
            if (parentSelector != null) {
                this.parentLines.put(parentSelector, vals);
                continue;
            } else if (table.getSelector() != null && !table.getSelector().equals(vals.get(0))) {
                continue;
            }
            rowNumber++;
            List<Object> tuple = new ArrayList<Object>(projectionIndexes.length);
            for (int output : projectionIndexes) {
                TextColumn col = table.getColumns().get(output);
                String val = null;
                int index = output;
                if (col.isOrdinal()) {
                    if (rowNumber > Integer.MAX_VALUE) {
                        throw new TeiidRuntimeException(new TeiidProcessingException(QueryPlugin.Event.TEIID31174, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31174)));
                    }
                    tuple.add((int) rowNumber);
                    continue;
                }
                if (col.getSelector() != null) {
                    vals = this.parentLines.get(col.getSelector());
                    index = col.getPosition() - 1;
                } else if (nameIndexes != null) {
                    index = nameIndexes.get(col.getName());
                }
                if (vals == null || index >= vals.size()) {
                    // throw new TeiidProcessingException(QueryPlugin.Util.getString("TextTableNode.no_value", col.getName(), textLine, systemId)); //$NON-NLS-1$
                    tuple.add(null);
                    continue;
                }
                val = vals.get(index);
                try {
                    tuple.add(DataTypeManager.transformValue(val, table.getColumns().get(output).getSymbol().getType()));
                } catch (TransformationException e) {
                    throw new TeiidProcessingException(QueryPlugin.Event.TEIID30176, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30176, col.getName(), textLine, systemId));
                }
            }
            addBatchRow(tuple);
            if (rowNumber == limit) {
                terminateBatches();
                break;
            }
        }
    }
}
Also used : TransformationException(org.teiid.core.types.TransformationException) ArrayList(java.util.ArrayList) LanguageObject(org.teiid.query.sql.LanguageObject) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) TextColumn(org.teiid.query.sql.lang.TextTable.TextColumn) TeiidProcessingException(org.teiid.core.TeiidProcessingException)

Aggregations

TeiidProcessingException (org.teiid.core.TeiidProcessingException)92 TeiidComponentException (org.teiid.core.TeiidComponentException)30 IOException (java.io.IOException)17 ArrayList (java.util.ArrayList)17 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)17 SQLException (java.sql.SQLException)16 BlockedException (org.teiid.common.buffer.BlockedException)16 Test (org.junit.Test)14 CommandContext (org.teiid.query.util.CommandContext)14 LanguageObject (org.teiid.query.sql.LanguageObject)13 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)13 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)12 List (java.util.List)11 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)10 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)10 QueryPlannerException (org.teiid.api.exception.query.QueryPlannerException)9 TupleSource (org.teiid.common.buffer.TupleSource)9 TupleBatch (org.teiid.common.buffer.TupleBatch)8 CollectionTupleSource (org.teiid.query.processor.CollectionTupleSource)7 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)6