Previous Next JavaScript must be enabled to correctly display this content

## Using the Proxy in a non-secure data store

Starting up the Proxy

Use the following command to start up the proxy for a non-secure data store.

    java -jar lib/httpproxy.jar \
    -storeName <kvstore_name> \
    -helperHosts <kvstore_helper_host> \
    [-hostname <proxy_host>] \
    [-httpPort <proxy_http_port>]

where,

- `kvstore_name` is the data store name obtained from the data store deployment. See ping.
- `kvstore_helper_host` is the data store's helper host:port list obtained from the data store deployment. See Obtaining a KVStore Handle in the Java Direct Driver Developer's Guide.
- `proxy_host` is the hostname of the machine to host the proxy service. This parameter is optional and defaults to `localhost`. You can also specify the complete hostname of the machine running the proxy.
- `proxy_http_port` is the port on which the proxy is listening for requests. This is an optional parameter and defaults to 80.

  Note:

  Using port 80 requires root privilege. You can use port 8080 if you do not have root privilege.

Connecting an application to the non-secure data store

Description of the illustration proxy_arch.png

Oracle NoSQL Database drivers are available in various programming languages that are used in the client application. Currently, Java, Python, Go, Node.js, C#, and Rust are supported. Oracle NoSQL Database Proxy is a server that accepts requests from the client application and processes them using the Oracle NoSQL Database.

The Oracle NoSQL Database Java Driver contains the jar files that enable a Java application to communicate with the proxy.

Install the Java driver in the application's classpath and use the following code to connect to the proxy.

    String endpoint = "http://<proxy_host>:<proxy_http_port>";
    StoreAccessTokenProvider atProvider = new StoreAccessTokenProvider();
    NoSQLHandleConfig config = new NoSQLHandleConfig(endpoint);
    config.setAuthorizationProvider(atProvider);
    NoSQLHandle handle = NoSQLHandleFactory.createNoSQLHandle(config);

where,

- `proxy_host` is the hostname of the machine running the proxy service. This should match the host you configured earlier.
- `proxy_http_port` is the port on which the proxy is listening for requests. This should match the http port you configured earlier.

The on-premises configuration requires a running instance of the Oracle NoSQL database. In addition a running proxy service is required.

If the data store is not secure, an empty instance of `borneo.kv.StoreAccessTokenProvider` is used. For example:

    from borneo import NoSQLHandle, NoSQLHandleConfig
    from borneo.kv import StoreAccessTokenProvider
    endpoint = 'http://<proxy_host>:<proxy_http_port>'
    # Create the AuthorizationProvider for a not secure store:
    ap = StoreAccessTokenProvider()
    # create a configuration object
    config = NoSQLHandleConfig(endpoint).set_authorization_provider(ap)
    # create a handle from the configuration object
    handle = NoSQLHandle(config)

where,

- `proxy_host` is the hostname of the machine running the proxy service. This should match the host you configured earlier.
- `proxy_http_port` is the port on which the proxy is listening for requests. This should match the http port you configured earlier.

The on-premises configuration requires a running instance of the Oracle NoSQL database. In addition a running proxy service is required. In this case, the `Endpoint` config parameter should point to the NoSQL proxy host and port location.

Use the following code to connect to the proxy.

    ...cfg:= nosqldb.Config{
        // EDIT: set desired endpoint for the Proxy server accordingly in your environment.
        Endpoint: "http:<proxy_host>:<proxy_http_port>",
        Mode:     "onprem",
    }
    client, err:=nosqldb.NewClient(cfg)
    iferr!=nil {
        fmt.Printf("failed to create a NoSQL client: %v\n", err)
        return
    }
    deferclient.Close()
    // Perform database operations using client APIs.// ...

where,

- `proxy_host` is the hostname of the machine running the proxy service. This should match the host you configured earlier.
- `proxy_http_port` is the port on which the proxy is listening for requests. This should match the http port you configured earlier.

Your application will connect and use a running NoSQL database via the proxy service.

In non-secure mode, the driver communicates with the proxy via the HTTP protocol. The only information required is the communication `endpoint`. For on-premise NoSQL Database, the endpoint specifies the url of the proxy, in the form `http://proxy_host:proxy_http_port`

Use the following code to connect to the proxy.

    const NoSQLClient = require('oracle-nosqldb').NoSQLClient;
    const ServiceType = require('oracle-nosqldb').ServiceType;
    const client = new NoSQLClient({
        serviceType: ServiceType.KVSTORE,
        endpoint: '<proxy_host>:<proxy_http_port>'
    });

where,

- `proxy_host` is the hostname of the machine running the proxy service. This should match the host you configured earlier.
- `proxy_http_port` is the port on which the proxy is listening for requests. This should match the http port you configured earlier.

You may also choose to store the same configuration in a file. Create file config.json with following contents:

    {
        "serviceType": "KVSTORE",
        "endpoint": "<proxy_host>:<proxy_http_port>",
    }

Then you may use this file to create NoSQLClient instance:

    const NoSQLClient = require('oracle-nosqldb').NoSQLClient;
    const client = new NoSQLClient('</path/to/config.json>');

Your application will connect and use a running NoSQL database via the proxy service.

In non-secure mode, the driver communicates with the proxy via the HTTP protocol. The only information required is the communication `endpoint`. For on-premise NoSQL Database, the endpoint specifies the url of the proxy, in the form `http://proxy_host:proxy_http_port`

To connect to the proxy in non-secure mode, you need to specify communication endpoint and the service type as `ServiceType.KVStore`. You can provide an instance of NoSQLConfig either directly or in a JSON configuration file.

    var client = new NoSQLClient(
        new NoSQLConfig
        {
            ServiceType = ServiceType.KVStore,
            Endpoint = "<proxy_host>:<proxy_http_port>"
        });

where,

- `proxy_host` is the hostname of the machine running the proxy service. This should match the host you configured earlier.
- `proxy_http_port` is the port on which the proxy is listening for requests. This should match the http port you configured earlier.

You may also choose to provide the same configuration in JSON configuration file. Create file config.json with following contents:

    {
        "ServiceType": "KVStore",
        "Endpoint": "<proxy_host>:<proxy_http_port>"
    }

Then you may use this file to create NoSQLClient instance:

    var client = new NoSQLClient("</path/to/config.json>");

Your application will connect and use a running NoSQL database via the proxy service.

In non-secure mode, the driver communicates with the proxy via the HTTP protocol. The only information required is the communication endpoint. For on-premise NoSQL Database, the endpoint specifies the URL of the proxy, in the form http://proxy_host:proxy_http_port.

            let handle = Handle::builder()
            .mode(HandleMode::Onprem)?
            .endpoint("http://<proxy_host>:<proxy_http_port>")?
            .build().await?;

where

- `proxy_host` is the hostname of the machine running the proxy service. This should match the proxy host you configured earlier.
- `proxy_http_port` is the port on which the proxy is listening for requests. This should match the proxy http port configured earlier.