Received fatal alert: protocol_version when using java-algorand-sdk with PureStake API

[This is in relation to doing in Java]

This is odd:

Looking at the PureStake sample code, and with a PureStake account set up, and after trying some things in their Swagger Playground, I tried simply plugging in appropriate PureStake values on a copy of the GettingStarted class from the Java “Your First Transaction” demo:

    private AlgodClient connectToNetwork() {
        final String ALGOD_API_ADDR = "";
        final String ALGOD_API_TOKEN = <REDACTED>;
        final String ALGOD_API_TOKEN_KEY = "X-API-Key";
        final Integer ALGOD_PORT = 443;
. . .

It sat there for quite a few seconds, and then I got this:

Exception in thread "main" Received fatal alert: protocol_version
        at com.squareup.okhttp.internal.http.StreamAllocation.findConnection(
        at com.squareup.okhttp.internal.http.StreamAllocation.findHealthyConnection(
        at com.squareup.okhttp.internal.http.StreamAllocation.newStream(
        at com.squareup.okhttp.internal.http.HttpEngine.connect(
        at com.squareup.okhttp.internal.http.HttpEngine.sendRequest(
        at com.squareup.okhttp.Call.getResponse(
        at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(
        at com.squareup.okhttp.Call.getResponseWithInterceptorChain(
        at com.squareup.okhttp.Call.execute(
        at com.algorand.algosdk.v2.client.common.Client.executeCall(
        at com.algorand.algosdk.v2.client.common.Query.baseExecute(
        at com.algorand.algosdk.v2.client.common.Query.baseExecute(
        at com.algorand.algosdk.v2.client.algod.AccountInformation.execute(
        at com.algorand.javatest.firsttransaction.GettingStartedPS.printBalance(
        at com.algorand.javatest.firsttransaction.GettingStartedPS.firstTransaction(
        at com.algorand.javatest.firsttransaction.GettingStartedPS.main(

Clearly, something is not on speaking terms . . . .

Your Java version looks too old and does not support the TLS version of PureStake.
PureStake only supports TLS 1.2 and 1.3 (which is now industry standard as previous versions are essentially insecure).
Which version of Java are you using?

You definitely need at the very least Java 1.8.

If you’re using Maven, set the Java version using

From a command line, I get:

Jamess-iMac:~ jameslampert$ java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

Since I’m still following the “Your First Transaction” demo, I’m still doing it in M$ :face_vomiting: Visual Studio Code. Tomorrow, I’ll have time to see what compiler VS Code is using.

In VS Code, here is what I get if I try to launch the main method in the debugger:

Jamess-iMac:demo jameslampert$ /usr/bin/env /Library/Java/JavaVirtualMachines/jdk1.7.0_09.jdk/Contents/Home/bin/java -agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=localhost:51366 -cp /var/folders/cn/vsn822092lqdlp8g6psy47380000gn/T/cp_d5h4ttloymsdzpdxi8v929i8q.jar com.algorand.javatest.firsttransaction.GettingStartedPS

(notice the explicit call to Java 7, which I’ve bolded). But if I do a java -version, I get the same as I get doing a java -version from any other command line:

Jamess-iMac:demo jameslampert$ java -version
java version “1.8.0_121
Java™ SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot™ 64-Bit Server VM (build 25.121-b13, mixed mode)

This is the issue.
Java 1.7 will not work with PureStake.

If you’re using maven see comment above.
Otherwise, see Java project management in Visual Studio Code

Yes. I gathered that the problem was that VS Code was using Java 7, even though Java 8 is not only installed, but is the default Java. Thanks for the link: I’ve got it open in the next browser tab, and hopefully it will solve the problem. VS Code is as new to me as Algorand is.

That solved the problem. And I’d completely forgotten that the project does use Maven (new to that, too: whaddya expect, I’m used to doing everything manually, from a 5250 terminal session on an IBM Midrange box), and so following the instructions given in the “Java project management . . .” link took me right to the POM file. It sync’d correctly on the second try, and started using Java 8.

The first time I tried running my doctored-up version of “GettingStarted” after that, it still blew up on

        Response < com.algorand.algosdk.v2.client.model.Account > respAcct = client.AccountInformation(myAccount.getAddress()).execute();

only this time with some kind of EOF error (I lost the stacktrace, unfortunately), but the second and third times, it successfully transferred a “Monopoly Algo” between two of my test accounts, using the PureStake node.

Thanks once again for your patience.