Search in sources :

Example 1 with SocketConfiguration

use of org.teiid.transport.SocketConfiguration in project teiid by teiid.

the class TestEmbeddedServer method testRemoteODBCTrasport.

@Test
public void testRemoteODBCTrasport() throws Exception {
    SocketConfiguration s = new SocketConfiguration();
    InetSocketAddress addr = new InetSocketAddress(0);
    s.setBindAddress(addr.getHostName());
    s.setPortNumber(addr.getPort());
    s.setProtocol(WireProtocol.pg);
    EmbeddedConfiguration config = new EmbeddedConfiguration();
    config.addTransport(s);
    es.start(config);
    es.deployVDB(new ByteArrayInputStream("<vdb name=\"test\" version=\"1\"><model name=\"test\" type=\"VIRTUAL\"><metadata type=\"DDL\"><![CDATA[CREATE VIEW helloworld as SELECT 'HELLO WORLD';]]> </metadata></model></vdb>".getBytes()));
    Connection conn = null;
    try {
        Driver d = new Driver();
        Properties p = new Properties();
        p.setProperty("user", "testuser");
        p.setProperty("password", "testpassword");
        conn = d.connect("jdbc:postgresql://" + addr.getHostName() + ":" + es.transports.get(0).getPort() + "/test", p);
        ResultSet rs = conn.createStatement().executeQuery("select * from helloworld");
        rs.next();
        assertEquals("HELLO WORLD", rs.getString(1));
    } finally {
        if (conn != null) {
            conn.close();
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InetSocketAddress(java.net.InetSocketAddress) SocketConfiguration(org.teiid.transport.SocketConfiguration) TeiidDriver(org.teiid.jdbc.TeiidDriver) Driver(org.postgresql.Driver) Properties(java.util.Properties) Test(org.junit.Test)

Example 2 with SocketConfiguration

use of org.teiid.transport.SocketConfiguration in project teiid by teiid.

the class TestEmbeddedServer method testRemoteJDBCTrasport.

@Test
public void testRemoteJDBCTrasport() throws Exception {
    SocketConfiguration s = new SocketConfiguration();
    InetSocketAddress addr = new InetSocketAddress(0);
    s.setBindAddress(addr.getHostName());
    s.setPortNumber(addr.getPort());
    s.setProtocol(WireProtocol.teiid);
    EmbeddedConfiguration config = new EmbeddedConfiguration();
    config.addTransport(s);
    es.start(config);
    es.deployVDB(new ByteArrayInputStream("<vdb name=\"test\" version=\"1\"><model name=\"test\" type=\"VIRTUAL\"><metadata type=\"DDL\"><![CDATA[CREATE VIEW helloworld as SELECT 'HELLO WORLD';]]> </metadata></model></vdb>".getBytes()));
    Connection conn = null;
    try {
        TeiidDriver driver = new TeiidDriver();
        conn = driver.connect("jdbc:teiid:test@mm://" + addr.getHostName() + ":" + es.transports.get(0).getPort(), null);
        // trigger alternative serialization for byte count
        conn.createStatement().execute("set showplan on");
        ResultSet rs = conn.createStatement().executeQuery("select * from helloworld");
        rs.next();
        assertEquals("HELLO WORLD", rs.getString(1));
    } finally {
        if (conn != null) {
            conn.close();
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InetSocketAddress(java.net.InetSocketAddress) SocketConfiguration(org.teiid.transport.SocketConfiguration) TeiidDriver(org.teiid.jdbc.TeiidDriver) Test(org.junit.Test)

Example 3 with SocketConfiguration

use of org.teiid.transport.SocketConfiguration in project teiid by teiid.

the class TestJDBCSocketPerformance method oneTimeSetup.

@BeforeClass
public static void oneTimeSetup() throws Exception {
    SocketConfiguration config = new SocketConfiguration();
    config.setSSLConfiguration(new SSLConfiguration());
    addr = new InetSocketAddress(0);
    config.setBindAddress(addr.getHostName());
    config.setPortNumber(0);
    EmbeddedConfiguration dqpConfig = new EmbeddedConfiguration();
    dqpConfig.setMaxActivePlans(2);
    server = new FakeServer(false);
    server.start(dqpConfig);
    ModelMetaData mmd = new ModelMetaData();
    mmd.setName("x");
    mmd.setModelType(Type.PHYSICAL);
    mmd.addSourceMapping("x", "hc", null);
    mmd.setSchemaSourceType("ddl");
    StringBuffer ddl = new StringBuffer("create foreign table x (col0 string");
    for (int i = 1; i < 10; i++) {
        ddl.append(",").append(" col").append(i).append(" string");
    }
    ddl.append(");");
    mmd.setSchemaText(ddl.toString());
    server.addTranslator("hc", new HardCodedExecutionFactory() {

        @Override
        protected List<? extends List<?>> getData(QueryExpression command) {
            List<List<String>> result = new ArrayList<List<String>>();
            int size = command.getProjectedQuery().getDerivedColumns().size();
            for (int i = 0; i < 64; i++) {
                List<String> row = new ArrayList<String>(size);
                for (int j = 0; j < size; j++) {
                    row.add("abcdefghi" + j);
                }
                result.add(row);
            }
            return result;
        }
    });
    server.deployVDB("x", mmd);
    jdbcTransport = new SocketListener(addr, config, server.getClientServiceRegistry(), BufferManagerFactory.getStandaloneBufferManager());
}
Also used : FakeServer(org.teiid.jdbc.FakeServer) InetSocketAddress(java.net.InetSocketAddress) SocketConfiguration(org.teiid.transport.SocketConfiguration) EmbeddedConfiguration(org.teiid.runtime.EmbeddedConfiguration) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) SSLConfiguration(org.teiid.transport.SSLConfiguration) SocketListener(org.teiid.transport.SocketListener) HardCodedExecutionFactory(org.teiid.runtime.HardCodedExecutionFactory) ArrayList(java.util.ArrayList) List(java.util.List) QueryExpression(org.teiid.language.QueryExpression) BeforeClass(org.junit.BeforeClass)

Example 4 with SocketConfiguration

use of org.teiid.transport.SocketConfiguration in project teiid by teiid.

the class TransportAdd method buildSocketConfiguration.

private SocketConfiguration buildSocketConfiguration(final OperationContext context, ModelNode node) throws OperationFailedException {
    SocketConfiguration socket = new SocketConfiguration();
    if (isDefined(TRANSPORT_PROTOCOL_ATTRIBUTE, node, context)) {
        socket.setProtocol(asString(TRANSPORT_PROTOCOL_ATTRIBUTE, node, context));
    } else {
        // $NON-NLS-1$
        socket.setProtocol("teiid");
    }
    if (isDefined(TRANSPORT_MAX_SOCKET_THREADS_ATTRIBUTE, node, context)) {
        socket.setMaxSocketThreads(asInt(TRANSPORT_MAX_SOCKET_THREADS_ATTRIBUTE, node, context));
    }
    if (isDefined(TRANSPORT_IN_BUFFER_SIZE_ATTRIBUTE, node, context)) {
        socket.setInputBufferSize(asInt(TRANSPORT_IN_BUFFER_SIZE_ATTRIBUTE, node, context));
    }
    if (isDefined(TRANSPORT_OUT_BUFFER_SIZE_ATTRIBUTE, node, context)) {
        socket.setOutputBufferSize(asInt(TRANSPORT_OUT_BUFFER_SIZE_ATTRIBUTE, node, context));
    }
    SSLConfiguration ssl = new SSLConfiguration();
    if (isDefined(SSL_MODE_ATTRIBUTE, node, context)) {
        ssl.setMode(asString(SSL_MODE_ATTRIBUTE, node, context));
    }
    if (isDefined(SSL_SSL_PROTOCOL_ATTRIBUTE, node, context)) {
        ssl.setSslProtocol(asString(SSL_SSL_PROTOCOL_ATTRIBUTE, node, context));
    }
    if (isDefined(SSL_KEY_MANAGEMENT_ALG_ATTRIBUTE, node, context)) {
        ssl.setKeymanagementAlgorithm(asString(SSL_KEY_MANAGEMENT_ALG_ATTRIBUTE, node, context));
    }
    if (isDefined(SSL_AUTH_MODE_ATTRIBUTE, node, context)) {
        ssl.setAuthenticationMode(asString(SSL_AUTH_MODE_ATTRIBUTE, node, context));
    }
    if (isDefined(SSL_KETSTORE_NAME_ATTRIBUTE, node, context)) {
        ssl.setKeystoreFilename(asString(SSL_KETSTORE_NAME_ATTRIBUTE, node, context));
    }
    if (isDefined(SSL_KETSTORE_ALIAS_ATTRIBUTE, node, context)) {
        ssl.setKeystoreKeyAlias(asString(SSL_KETSTORE_ALIAS_ATTRIBUTE, node, context));
    }
    if (isDefined(SSL_KETSTORE_KEY_PASSWORD_ATTRIBUTE, node, context)) {
        ssl.setKeystoreKeyPassword(asString(SSL_KETSTORE_KEY_PASSWORD_ATTRIBUTE, node, context));
    }
    if (isDefined(SSL_ENABLED_CIPHER_SUITES_ATTRIBUTE, node, context)) {
        ssl.setEnabledCipherSuites(asString(SSL_ENABLED_CIPHER_SUITES_ATTRIBUTE, node, context));
    }
    if (isDefined(SSL_KETSTORE_PASSWORD_ATTRIBUTE, node, context)) {
        ssl.setKeystorePassword(asString(SSL_KETSTORE_PASSWORD_ATTRIBUTE, node, context));
    }
    if (isDefined(SSL_KETSTORE_TYPE_ATTRIBUTE, node, context)) {
        ssl.setKeystoreType(asString(SSL_KETSTORE_TYPE_ATTRIBUTE, node, context));
    }
    if (isDefined(SSL_TRUSTSTORE_NAME_ATTRIBUTE, node, context)) {
        ssl.setTruststoreFilename(asString(SSL_TRUSTSTORE_NAME_ATTRIBUTE, node, context));
    }
    if (isDefined(SSL_TRUSTSTORE_PASSWORD_ATTRIBUTE, node, context)) {
        ssl.setTruststorePassword(asString(SSL_TRUSTSTORE_PASSWORD_ATTRIBUTE, node, context));
    }
    if (isDefined(SSL_TRUSTSTORE_CHECK_EXPIRED_ATTRIBUTE, node, context)) {
        ssl.setTruststoreCheckExpired(asBoolean(SSL_TRUSTSTORE_CHECK_EXPIRED_ATTRIBUTE, node, context));
    }
    socket.setSSLConfiguration(ssl);
    return socket;
}
Also used : SSLConfiguration(org.teiid.transport.SSLConfiguration) SocketConfiguration(org.teiid.transport.SocketConfiguration)

Example 5 with SocketConfiguration

use of org.teiid.transport.SocketConfiguration in project teiid by teiid.

the class TestEmbeddedServer method testRemoteTrasportSSLFail.

@Test(expected = TeiidRuntimeException.class)
public void testRemoteTrasportSSLFail() throws Exception {
    SocketConfiguration s = new SocketConfiguration();
    InetSocketAddress addr = new InetSocketAddress(0);
    s.setBindAddress(addr.getHostName());
    s.setPortNumber(addr.getPort());
    s.setProtocol(WireProtocol.teiid);
    SSLConfiguration sslConfiguration = new SSLConfiguration();
    sslConfiguration.setSslProtocol("x");
    sslConfiguration.setMode("enabled");
    s.setSSLConfiguration(sslConfiguration);
    EmbeddedConfiguration config = new EmbeddedConfiguration();
    config.addTransport(s);
    es.start(config);
}
Also used : SSLConfiguration(org.teiid.transport.SSLConfiguration) InetSocketAddress(java.net.InetSocketAddress) SocketConfiguration(org.teiid.transport.SocketConfiguration) Test(org.junit.Test)

Aggregations

SocketConfiguration (org.teiid.transport.SocketConfiguration)6 InetSocketAddress (java.net.InetSocketAddress)5 Test (org.junit.Test)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 SSLConfiguration (org.teiid.transport.SSLConfiguration)3 Properties (java.util.Properties)2 TeiidDriver (org.teiid.jdbc.TeiidDriver)2 EmbeddedConfiguration (org.teiid.runtime.EmbeddedConfiguration)2 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 BeforeClass (org.junit.BeforeClass)1 Driver (org.postgresql.Driver)1 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)1 FakeServer (org.teiid.jdbc.FakeServer)1 QueryExpression (org.teiid.language.QueryExpression)1 HardCodedExecutionFactory (org.teiid.runtime.HardCodedExecutionFactory)1 SocketListener (org.teiid.transport.SocketListener)1