3

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

user2724026
  • 31
  • 1
  • 3
  • Can you post exact text of error? And line where it happens (You can edit your question to add this information). – talex Sep 06 '18 at 09:05
  • your use of the dependency is correct, 3.11.0 version is working. seems to be some (wrong) error message in your IDE. what are you using? you can build your maven project with `mvn clean install` and refresh your sources, this will maybe help. – bucky Sep 06 '18 at 11:50
  • btw: your import statement `import okhttp3.Credentials;` seems to be missing your src-file. – bucky Sep 06 '18 at 11:58
  • @bucky I have done both stated in your comments and the error log is at the end of the recently edited post. – user2724026 Sep 07 '18 at 03:08
  • @talex it has been recently added – user2724026 Sep 07 '18 at 03:08
  • @user2724026 This error mean that some of methods you call may throw checked exceptions. Wrap your code in `try { ... } catch (Exception e) { ... }`. – talex Sep 07 '18 at 03:12
  • @user2724026 Also I suggest you to post text of error, not image. It is easier to read, search and copy. – talex Sep 07 '18 at 03:14
  • @user2724026 it doesn't seem to solve the problem. Will do in the future! – user2724026 Sep 10 '18 at 00:22
  • @user2724026 according to the error you posted, the JAR file seems to be corrupted, so you should remove it from your ".m2\repository" folder (see full path in the error message). After that, the compilation should be successful – user2340612 Nov 03 '18 at 18:14

0 Answers0