Jetty ALPN/NPN has not been properly configured — Solution

ElamParithi Arul
helloParithi
Published in
2 min readMay 30, 2017

I’ve been working on this web app where we need to upload an image from a webcam or a local file from the system and determine whether that the image is safe to be used as a profile picture.

Stack for this web app requires that it should run on Tomcat 7 and therefore we had write them as Java Servlets. We need the Google Vision API to determine whether the image is suitable by checking whether the labels returned by the API are congruous with a set of predefined tags that we have. To add the Google Vision API, we added the following to our maven ‘pom.xml’ :

<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-vision</artifactId>
<version>0.17.2-beta</version>
</dependency>

and Bam! I got the following error popping up from within the Google API on runtime:

Jetty ALPN/NPN has not been properly configured

Google API uses the HTTP/2 protocol for executing which is still not supported by the old Tomcat servers. In order to fix this, we need to configure an ALPN client that matches our JDK version for our project.

You can read more about it in the following link :

To fix our issue, we need to download the appropriate ALPN client (I downloaded a jar file) from the maven repository here (Version — 8.1.4.v20150727 as my JDK version was 1.8.0u51) :

After downloading the jar, you need to go to the Tomcat Server settings in eclipse and add the ALPN jar file as one of the bootstrap entries for your server. Find a similar way to add it to your classpath if you are using any other IDE.

That should fix the issue, you should probably getting it working after you add this.

During Deployment :

Add the alpn-client jar to a folder and add it to the $CLASSPATH of your tomcat server. I’ve set the $CLASSPATH at /usr/local/apache-tomcat-XXXX/bin folder where I’ve created a file called ‘setenv.sh’ and this is what it contains:

CATALINA_OPTS="-DGOOGLE_APPLICATION_CREDENTIALS=/home/parithi/google_credentials.json"CLASSPATH="$CLASSPATH:/home/parithi/MY_PROJECT_FOLDER/:/home/parithi/alpn-boot-7.1.3.v20150130.jar"

Thanks for your time, if you have any questions, feel free to leave a comment below. And if this article helped you out, please show your support by hitting the like button.

--

--

ElamParithi Arul
helloParithi

Loves to build beautiful products for the Internet.