Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Requests with param in path don't work properly and throw exception #243

Closed
alexnuts opened this issue Feb 16, 2021 · 10 comments
Closed

Requests with param in path don't work properly and throw exception #243

alexnuts opened this issue Feb 16, 2021 · 10 comments

Comments

@alexnuts
Copy link
Contributor

I use your client library to communicate with spotify api. It works well but I've caught exception with requests that contains path variables like v1/albums/{id} in request path. Library doesn't replace path variable key correctly.
The project is for android. It configured with java 8.
I've added:

  • code to test
  • line with where exception occures
  • stacktrace
  • part of gradle config

Line that fires exception:

240: builtPath = builtPath.replaceAll("\\{" + nameValuePair.getName() + "}", nameValuePair.getValue());

Code to reproduce:

import com.wrapper.spotify.SpotifyApi;
import com.wrapper.spotify.exceptions.SpotifyWebApiException;
import com.wrapper.spotify.model_objects.specification.Album;
import com.wrapper.spotify.model_objects.specification.Artist;

import org.apache.hc.core5.http.ParseException;
import org.junit.Assert;
import org.junit.Test;

import java.io.IOException;

import dagger.hilt.android.testing.HiltAndroidTest;

@HiltAndroidTest
public class FetchByIdTest extends BaseSpotifyTest {

    @Test
    public void testAlbumById() throws ParseException, SpotifyWebApiException, IOException {
        //https://developer.spotify.com/console/get-album/?id=1IVuDXU95irZD6n7veVlUs
        SpotifyApi api = dataManager.getApi();
        String albumId = "1IVuDXU95irZD6n7veVlUs";
        Album album = api.getAlbum(albumId).build().execute();
        Assert.assertNotNull(album);
    }

    @Test
    public void testArtistById() throws ParseException, SpotifyWebApiException, IOException {
        //https://developer.spotify.com/console/get-artist/?id=0LyfQWJT6nXafLPZqxe9Of
        SpotifyApi api = dataManager.getApi();
        String artistId = "0LyfQWJT6nXafLPZqxe9Of";
        Artist artist = api.getArtist(artistId).build().execute();
        Assert.assertNotNull(artist);
    }
}

Error Stack Trace:

The stacktrace is the same for both tests

2021-02-16 15:35:19.797 E/TestRunner: java.util.regex.PatternSyntaxException: Syntax error in regexp pattern near index 5
    \{id}
         ^
        at java.util.regex.Pattern.compileImpl(Native Method)
        at java.util.regex.Pattern.compile(Pattern.java:1344)
        at java.util.regex.Pattern.<init>(Pattern.java:1328)
        at java.util.regex.Pattern.compile(Pattern.java:950)
        at java.lang.String.replaceAll(String.java:2286)
        at com.wrapper.spotify.requests.AbstractRequest$Builder.setPath(AbstractRequest.java:240)
        at com.wrapper.spotify.requests.data.albums.GetAlbumRequest$Builder.build(GetAlbumRequest.java:90)
        at com.dts.conrad.automotive.spotify.FetchByIdTest.testAlbumById(FetchByIdTest.java:25)
        at java.lang.reflect.Method.invoke(Native Method)
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
        at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
        at androidx.test.internal.runner.junit4.statement.RunBefores.evaluate(RunBefores.java:80)
        at dagger.hilt.android.internal.testing.MarkThatRulesRanRule$1.evaluate(MarkThatRulesRanRule.java:92)
        at org.junit.rules.RunRules.evaluate(RunRules.java:20)
        at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
        at org.junit.runners.Suite.runChild(Suite.java:128)
        at org.junit.runners.Suite.runChild(Suite.java:27)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
        at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
        at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
        at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
        at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:395)
        at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2152)

Gradle config:

android {
//...
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
//...
}
@dargmuesli
Copy link
Member

Have you also read the bold text at the very beginning of this project's README?

@alexnuts
Copy link
Contributor Author

Have you also read the bold text at the very beginning of this project's README?

Hm... No, I've not paid attention to that bold text...
But lib works for me on android. I'm working on app that uses android sdk api from 28.
And I didn't get any issue like in #120.

P.S: I've fixed the issue java.util.regex.PatternSyntaxException: Syntax error in regexp pattern near index 5 \{id} and I would like to create PR and try to continue use your library if you don't mind ;)

@alexnuts
Copy link
Contributor Author

@dargmuesli
I've created PR #244 with fix of the issue. It contains minimal changes.

@dargmuesli
Copy link
Member

Thanks, this will be released as v6.5.2 :)
Just keep in mind that this library is not officially supporting Android.

@dargmuesli
Copy link
Member

Somehow the build fails with

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-gpg-plugin:1.6:sign (sign-artifacts) on project spotify-web-api-java: Execution sign-artifacts of goal org.apache.maven.plugins:maven-gpg-plugin:1.6:sign failed: Plugin org.apache.maven.plugins:maven-gpg-plugin:1.6 or one of its dependencies could not be resolved: The following artifacts could not be resolved: org.apache.maven:maven-project:jar:2.2.1, org.apache.maven:maven-profile:jar:2.2.1: Could not transfer artifact org.apache.maven:maven-project:jar:2.2.1 from/to central (https://repo.maven.apache.org/maven2): Transfer failed for https://repo.maven.apache.org/maven2/org/apache/maven/maven-project/2.2.1/maven-project-2.2.1.jar: Connection reset -> [Help 1]

I currently do not have enough time to look into this, but will do once that changes.

@alexnuts
Copy link
Contributor Author

Somehow the build fails with

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-gpg-plugin:1.6:sign (sign-artifacts) on project spotify-web-api-java: Execution sign-artifacts of goal org.apache.maven.plugins:maven-gpg-plugin:1.6:sign failed: Plugin org.apache.maven.plugins:maven-gpg-plugin:1.6 or one of its dependencies could not be resolved: The following artifacts could not be resolved: org.apache.maven:maven-project:jar:2.2.1, org.apache.maven:maven-profile:jar:2.2.1: Could not transfer artifact org.apache.maven:maven-project:jar:2.2.1 from/to central (https://repo.maven.apache.org/maven2): Transfer failed for https://repo.maven.apache.org/maven2/org/apache/maven/maven-project/2.2.1/maven-project-2.2.1.jar: Connection reset -> [Help 1]

I currently do not have enough time to look into this, but will do once that changes.

I didn't get the build fail. I've used maven with command line to tests and build.

➜ ~ mvn -version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /usr/local/Cellar/maven/3.6.3_1/libexec
Java version: 1.8.0_242-release, vendor: JetBrains s.r.o, runtime: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/jre
Default locale: en_UA, platform encoding: UTF-8
OS name: "mac os x", version: "10.16", arch: "x86_64", family: "mac"

@dargmuesli
Copy link
Member

It's failing on Travis when trying the gpg sign build step.

@dargmuesli
Copy link
Member

Got it fixed after countless tries. I really want to know what made it work now...

@alexnuts
Copy link
Contributor Author

Got it fixed after countless tries. I really want to know what made it work now...

Are you about the issue or sign build step?

@dargmuesli
Copy link
Member

Well, about the sign build step. The issue was fixed by you ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants