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. If the proxy is to be accessed from machines other than the one on which it is started this should be the hostname of the machine running the proxy. This parameter is optional and defaults tolocalhost
.proxy_http_port
is the port on which the proxy is watching for requests on its host machine. This is an optional parameter and defaults to 80.Note:
Use of port 80 may require additional privileges, depending on your machine.
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 to host the proxy service. This should match the host you configured earlier.proxy_http_port
is the port on which the proxy is watching for requests on its host machine. This should match the http port you configured earlier.
The onPremises configuration requires a running instance of the Oracle NoSQL database. In addition a running proxy service is required.
borneo.kv.StoreAccessTokenProvider
is used. For
example:from borneo import NoSQLHandle, NoSQLHandleConfig
from borneo.kv import StoreAccessTokenProvider
#
# Assume the proxy is running on localhost:8080
#
endpoint = 'http://localhost:8080'
#
# 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)
The onPremises 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.
...cfg:= nosqldb.Config{
// EDIT: set desired endpoint for the Proxy server accordingly in your environment.
Endpoint: "http://localhost:8080",
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.// ...
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
const NoSQLClient = require('oracle-nosqldb').NoSQLClient;
const ServiceType = require('oracle-nosqldb').ServiceType;
const client = new NoSQLClient({
serviceType: ServiceType.KVSTORE,
endpoint: 'myhost:8080'
});
{
"serviceType": "KVSTORE",
"endpoint": "myhost:8080",
}
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
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 = "myhost:8080"
});
You
may also choose to provide the same configuration in JSON configuration file.
Create file config.json with following
contents:{
"ServiceType": "KVStore",
"Endpoint": "myhost:8080"
}
Then
you may use this file to create NoSQLClient
instance:var client = new NoSQLClient("/path/to/config.json");
The Oracle NoSQL Database Spring Data SDK contains the files that enable a Spring Data application to communicate with the proxy.
Install the Java driver in the application's classpath. Use the following code to connect to the proxy.
configuration
Spring bean provides a
NosqlDbConfig
object. You can use the
StoreAccessTokenProvider
class to configure the Spring Data
Framework to connect to an Oracle NoSQL Database
store.
import com.oracle.nosql.spring.data.config.AbstractNosqlConfiguration;
import com.oracle.nosql.spring.data.config.NosqlDbConfig;
import com.oracle.nosql.spring.data.repository.config.EnableNosqlRepositories;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import oracle.nosql.driver.kv.StoreAccessTokenProvider;
@Configuration
@EnableNosqlRepositories
public class AppConfig extends AbstractNosqlConfiguration {
@Bean
public NosqlDbConfig nosqlDbConfig() {
AuthorizationProvider authorizationProvider;
authorizationProvider = new StoreAccessTokenProvider();
return new NosqlDbConfig("http://<proxy_host:proxy_http_port>", authorizationProvider);
}
}
proxy_host
is the hostname of the machine to host the proxy service.proxy_http_port
is the port on which the proxy is watching for requests on its host machine.