refactored client constructor to support class dependancy injection
This commit is contained in:
parent
87681bc0e4
commit
c599902ad5
3 changed files with 24 additions and 23 deletions
|
|
@ -48,23 +48,10 @@ public class JobServClient {
|
|||
|
||||
/*
|
||||
* Constructor
|
||||
* Creates an SslContext from cert, key, and trust store
|
||||
* Creates a ManagedChannel object from SSL Parameters
|
||||
* Spawns a new blockingStub for network operations with the server
|
||||
*/
|
||||
public JobServClient(String host,
|
||||
int port,
|
||||
String trustStore,
|
||||
String clientCert,
|
||||
String clientPrivateKey) throws SSLException {
|
||||
SslContextBuilder builder = GrpcSslContexts.forClient();
|
||||
builder.trustManager(new File(trustStore));
|
||||
builder.keyManager(new File(clientCert), new File(clientPrivateKey));
|
||||
|
||||
this.channel = NettyChannelBuilder.forAddress(host, port)
|
||||
.sslContext(builder.build())
|
||||
.build();
|
||||
|
||||
public JobServClient(ManagedChannel channel) {
|
||||
this.channel = channel;
|
||||
blockingStub = ShellServerGrpc.newBlockingStub(this.channel);
|
||||
}
|
||||
|
||||
|
|
@ -210,7 +197,7 @@ public class JobServClient {
|
|||
/*
|
||||
* main()
|
||||
* Client entrypoint
|
||||
* Parses arguments and calls the correct function
|
||||
* Parses arguments, initializes client, and calls the correct functions
|
||||
*/
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
|
|
@ -224,7 +211,15 @@ public class JobServClient {
|
|||
|
||||
JobServClient client;
|
||||
try {
|
||||
client = new JobServClient(args[3], Integer.parseInt(args[4]), args[2], args[1], args[0]);
|
||||
SslContextBuilder builder = GrpcSslContexts.forClient();
|
||||
builder.trustManager(new File(args[2]));
|
||||
builder.keyManager(new File(args[1]), new File(args[0]));
|
||||
|
||||
ManagedChannel channel = NettyChannelBuilder.forAddress(args[3], Integer.parseInt(args[4]))
|
||||
.sslContext(builder.build())
|
||||
.build();
|
||||
|
||||
client = new JobServClient(channel);
|
||||
|
||||
// Likely bad port
|
||||
} catch (NumberFormatException e) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue