org.apache.calcite.avatica.remote.Driver Java Examples

The following examples show how to use org.apache.calcite.avatica.remote.Driver. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HandlerFactory.java    From calcite-avatica with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs the desired implementation for the given serialization method and server
 * configuration with metrics.
 *
 * @param service The underlying {@link Service}
 * @param serialization The serializatio mechanism to use
 * @param metricsConfig Configuration for the {@link MetricsSystem}.
 * @param serverConfig Avatica server configuration or null
 * @return An {@link AvaticaHandler}
 */
public AvaticaHandler getHandler(Service service, Driver.Serialization serialization,
    MetricsSystemConfiguration<?> metricsConfig, AvaticaServerConfiguration serverConfig) {
  if (null == metricsConfig) {
    metricsConfig = NoopMetricsSystemConfiguration.getInstance();
  }
  MetricsSystem metrics = MetricsSystemLoader.load(metricsConfig);

  switch (serialization) {
  case JSON:
    return new AvaticaJsonHandler(service, metrics, serverConfig);
  case PROTOBUF:
    return new AvaticaProtobufHandler(service, metrics, serverConfig);
  default:
    throw new IllegalArgumentException("Unknown Avatica handler for " + serialization.name());
  }
}
 
Example #2
Source File: HttpServerCustomizerTest.java    From calcite-avatica with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked") // needed for the mocked customizers, not the builder
@Test public void serverCustomizersInvoked() {
  ServerCustomizer<Server> mockCustomizer1 =
      (ServerCustomizer<Server>) mock(ServerCustomizer.class);
  ServerCustomizer<Server> mockCustomizer2 =
      (ServerCustomizer<Server>) mock(ServerCustomizer.class);
  Service service = new LocalService(mockMeta);
  HttpServer server =
      HttpServer.Builder.<Server>newBuilder().withHandler(service, Driver.Serialization.PROTOBUF)
          .withServerCustomizers(Arrays.asList(mockCustomizer1, mockCustomizer2), Server.class)
          .withPort(0).build();
  try {
    server.start();
    verify(mockCustomizer2).customize(any(Server.class));
    verify(mockCustomizer1).customize(any(Server.class));
  } finally {
    server.stop();
  }
}
 
Example #3
Source File: DigestAuthHttpServerTest.java    From calcite-avatica with Apache License 2.0 6 votes vote down vote up
@BeforeClass public static void startServer() throws Exception {
  final String userPropertiesFile = URLDecoder.decode(BasicAuthHttpServerTest.class
      .getResource("/auth-users.properties").getFile(), "UTF-8");
  assertNotNull("Could not find properties file for digest auth users", userPropertiesFile);

  // Create a LocalService around HSQLDB
  final JdbcMeta jdbcMeta = new JdbcMeta(CONNECTION_SPEC.url,
      CONNECTION_SPEC.username, CONNECTION_SPEC.password);
  LocalService service = new LocalService(jdbcMeta);

  server = new HttpServer.Builder()
      .withDigestAuthentication(userPropertiesFile, new String[] { "users" })
      .withHandler(service, Driver.Serialization.PROTOBUF)
      .withPort(0)
      .build();
  server.start();

  url = "jdbc:avatica:remote:url=http://localhost:" + server.getPort()
      + ";authentication=DIGEST;serialization=PROTOBUF";

  // Create and grant permissions to our users
  createHsqldbUsers();
}
 
Example #4
Source File: CustomAuthHttpServerTest.java    From calcite-avatica with Apache License 2.0 6 votes vote down vote up
@Override public void customize(Server server) {
  HttpServer avaticaServer = getAvaticaServer();

  HandlerFactory factory = new HandlerFactory();
  Handler avaticaHandler = factory.getHandler(service,
          Driver.Serialization.PROTOBUF, null, configuration);

  if (isBasicAuth) {
    ConstraintSecurityHandler securityHandler =
            avaticaServer.configureBasicAuthentication(server, configuration);
    securityHandler.setHandler(avaticaHandler);
    avaticaHandler = securityHandler;
  }

  HandlerList handlerList = new HandlerList();
  handlerList.setHandlers(new Handler[] { avaticaHandler, new DefaultHandler()});
  server.setHandler(handlerList);
}
 
Example #5
Source File: BasicAuthHttpServerTest.java    From calcite-avatica with Apache License 2.0 6 votes vote down vote up
@BeforeClass public static void startServer() throws Exception {
  final String userPropertiesFile = URLDecoder.decode(BasicAuthHttpServerTest.class
      .getResource("/auth-users.properties").getFile(), "UTF-8");
  assertNotNull("Could not find properties file for basic auth users", userPropertiesFile);

  // Create a LocalService around HSQLDB
  final JdbcMeta jdbcMeta = new JdbcMeta(CONNECTION_SPEC.url,
      CONNECTION_SPEC.username, CONNECTION_SPEC.password);
  LocalService service = new LocalService(jdbcMeta);

  server = new HttpServer.Builder()
      .withBasicAuthentication(userPropertiesFile, new String[] { "users" })
      .withHandler(service, Driver.Serialization.PROTOBUF)
      .withPort(0)
      .build();
  server.start();

  url = "jdbc:avatica:remote:url=http://localhost:" + server.getPort()
      + ";authentication=BASIC;serialization=PROTOBUF";

  // Create and grant permissions to our users
  createHsqldbUsers();
}
 
Example #6
Source File: Main.java    From quark with Apache License 2.0 6 votes vote down vote up
/**
 * Instantiates the Handler for use by the Avatica (Jetty) server.
 *
 * @param service The Avatica Service implementation
 * @param handlerFactory Factory used for creating a Handler
 * @return The Handler to use.
 */
Handler getHandler(Service service, HandlerFactory handlerFactory) {
  String serializationName = "PROTOBUF";
  Driver.Serialization serialization;
  try {
    serialization = Driver.Serialization.valueOf(serializationName);
  } catch (Exception e) {
    LOG.error("Unknown message serialization type for " + serializationName);
    throw e;
  }

  Handler handler = handlerFactory.getHandler(service, serialization);
  LOG.info("Instantiated " + handler.getClass() + " for Quark Server");

  return handler;
}
 
Example #7
Source File: DruidJdbcClientModule.java    From presto with Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
@ForBaseJdbc
public static ConnectionFactory createConnectionFactory(BaseJdbcConfig config, CredentialProvider credentialProvider)
{
    Properties connectionProperties = new Properties();
    return new DriverConnectionFactory(
            new Driver(),
            config.getConnectionUrl(),
            connectionProperties,
            credentialProvider);
}
 
Example #8
Source File: HttpServerCustomizerTest.java    From calcite-avatica with Apache License 2.0 5 votes vote down vote up
@Test public void onlyJettyCustomizersAllowed() {
  Service service = new LocalService(mockMeta);
  List<ServerCustomizer<UnsupportedServer>> unsupportedCustomizers = new ArrayList<>();
  unsupportedCustomizers.add(new ServerCustomizer<UnsupportedServer>() {
    @Override public void customize(UnsupportedServer server) {
    }
  });
  thrown.expect(IllegalArgumentException.class);
  thrown.expectMessage("Only Jetty Server customizers are supported");
  HttpServer.Builder.<UnsupportedServer>newBuilder()
      .withHandler(service, Driver.Serialization.PROTOBUF)
      .withServerCustomizers(unsupportedCustomizers, UnsupportedServer.class).withPort(0).build();
}
 
Example #9
Source File: ChinookAvaticaServer.java    From calcite with Apache License 2.0 4 votes vote down vote up
public String getURL() {
  return "jdbc:avatica:remote:url=http://localhost:" + server.getPort()
      + ";serialization=" + Driver.Serialization.PROTOBUF.name();
}
 
Example #10
Source File: HandlerFactory.java    From calcite-avatica with Apache License 2.0 2 votes vote down vote up
/**
 * Constructs the desired implementation for the given serialization method with metrics.
 *
 * @param service The underlying {@link Service}.
 * @param serialization The desired message serialization.
 * @return The {@link AvaticaHandler}.
 */
public AvaticaHandler getHandler(Service service, Driver.Serialization serialization) {
  return getHandler(service, serialization, NoopMetricsSystemConfiguration.getInstance());
}
 
Example #11
Source File: HandlerFactory.java    From calcite-avatica with Apache License 2.0 2 votes vote down vote up
/**
 * Constructs the desired implementation for the given serialization method and server
 * configuration with metrics.
 *
 * @param service The underlying {@link Service}.
 * @param serialization The desired message serialization.
 * @param serverConfig Avatica server configuration or null.
 * @return The {@link AvaticaHandler}.
 */
public AvaticaHandler getHandler(Service service, Driver.Serialization serialization,
    AvaticaServerConfiguration serverConfig) {
  return getHandler(service, serialization, NoopMetricsSystemConfiguration.getInstance(),
      serverConfig);
}
 
Example #12
Source File: HandlerFactory.java    From calcite-avatica with Apache License 2.0 2 votes vote down vote up
/**
 * Constructs the desired implementation for the given serialization method with metrics.
 *
 * @param service The underlying {@link Service}.
 * @param serialization The desired message serialization.
 * @param metricsConfig Configuration for the {@link MetricsSystem}.
 * @return The {@link AvaticaHandler}.
 */
public AvaticaHandler getHandler(Service service, Driver.Serialization serialization,
    MetricsSystemConfiguration<?> metricsConfig) {
  return getHandler(service, serialization, metricsConfig, null);
}