Cannot resolve okhttp request.builder()

Viewed 3054

I have added my maven dependency as in my pom.xml file.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.bioID.app</groupId>
  <artifactId>my-app</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>my-app</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.squareup.okhttp3</groupId>
      <artifactId>okhttp</artifactId>
      <version>3.11.0</version>
    </dependency>
    <dependency>
        <groupId>com.squareup.okio</groupId>
        <artifactId>okio</artifactId>
        <version>2.0.0</version>
    </dependency>
  </dependencies>
</project>

I want to give a request to BioID to receive a Web Token API. The application identifier and secret is of course omitted.

package com.bioID.app;

import okhttp3.Request;
import okhttp3.Response;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import okhttp3.Credentials;

public class App 
{   
    public static void main( String[] args )
    {
        System.out.println( "Hello World!" );
    }

    public static String returntoken() {
        // using OkHttpClient from the OkHttp library
        HttpUrl url = HttpUrl.parse("https://bws.bioid.com/extension/token").newBuilder()
                .addQueryParameter("id", APP_IDENTIFIER)
                .build();
        Request request = new Request.Builder()
                .url(url)
                .addHeader("Authorization", Credentials.basic(APP_IDENTIFIER, APP_SECERET))
                .build();
        OkHttpClient client = new OkHttpClient();
        Response response = client.newCall(request).execute();
        String token = response.body().string();
        if (response.code() == 200) {
            System.out.println("token=" + token);
        }
        return token;
    }
}

This ended with an error Request.Builder cannot be resolved as a type despite adding the class from the dependency and referring to documentation. Is this due to a wrong version used of either okio or okhttp libraries.

The error message when compiled with

mvn clean install

Build Failure Message

0 Answers
Related