Search code examples
javakotlingoogle-oauthgoogle-api-java-clientspark-java

SparkJava cannot work together with some Google Youtube API's


We decided to use SparkJava, Kotlin and Mustache for a commercial web product. And our product needs to be integrated with Google (YouTube) API’s.

The project’s all endpoints were working properly. (Backoffice, CRUD operations etc.) And we started to implement integrations of YouTube and I had to add Google libraries into my project for kickoff. (Not to add any of extra code, just added the library google-oauth-client-jetty.)

You can find my Gradle libraries below :

dependencies {

    // Below library is a part of the requirements or YouTube Integration

    compile group: 'com.google.oauth-client', name: 'google-oauth-client-jetty', version: '1.11.0-beta'


    // And these are the others
    compile fileTree(include: ['*.jar'], dir: 'lib')
    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    compile group: 'com.sparkjava', name: 'spark-core', version: '2.7.0'
    compile 'com.google.code.gson:gson:2.8.1'
    compile group: 'commons-codec', name: 'commons-codec', version: '1.9'
    compile 'com.github.jkcclemens:khttp:0.1.0' // -SNAPSHOT
    compile 'com.beust:klaxon:0.30'
    compile group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: '1.58'
    compile group: 'org.hibernate', name: 'hibernate-gradle-plugin', version: '5.2.10.Final'
    compile group: 'org.hibernate', name: 'hibernate-core', version: '5.2.10.Final'
    compile group: 'org.hibernate', name: 'hibernate-entitymanager', version: '5.2.10.Final'
    compile group: 'org.hibernate', name: 'hibernate-validator', version: '6.0.0.CR3'
    compile group: 'mysql', name: 'mysql-connector-java', version: '6.0.6'
    compile group: 'org.hibernate', name: 'hibernate-c3p0', version: '4.1.0.Final'
    compile 'io.sentry:sentry-log4j:1.4.0'
    compile group: 'javax.mail', name: 'mail', version: '1.4.1'
    compile group: 'org.apache.commons', name: 'commons-dbcp2', version: '2.0'
    compile group: 'commons-validator', name: 'commons-validator', version: '1.4.0'
    compile "org.testng:testng:6.9.10"
    compile "org.apache.httpcomponents:httpclient:4.5.2"
    compile "org.apache.httpcomponents:httpcore:4.4.4"
    compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.0'
    compile group: 'com.sparkjava', name: 'spark-template-mustache', version: '2.5.5'
    compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.25'

    testCompile group: 'junit', name: 'junit', version: '4.11'
}

When I especially add library 'google-oauth-client-jetty', version: '1.11.0-beta’ into the project, I cannot reach the endpoints via http (GET, POST, PUT none of them). I enabled SparkJava's logs and I am facing with the logs below.

For example, I am calling

http://localhost:3000/admin

And the result is :

    [qtp1864334028-15] WARN org.eclipse.jetty.server.HttpChannel - /admin
java.lang.NoSuchMethodError: javax.servlet.http.HttpServletResponse.getHeaders(Ljava/lang/String;)Ljava/util/Collection;
    at spark.utils.GzipUtils.checkAndWrap(GzipUtils.java:67)
    at spark.http.matching.Body.serializeTo(Body.java:69)
    at spark.http.matching.MatcherFilter.doFilter(MatcherFilter.java:189)
    at spark.embeddedserver.jetty.JettyHandler.doHandle(JettyHandler.java:50)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1568)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
    at org.eclipse.jetty.server.Server.handle(Server.java:564)
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:317)
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:251)
    at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:279)
    at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:110)
    at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:124)
    at org.eclipse.jetty.util.thread.Invocable.invokePreferred(Invocable.java:128)
    at org.eclipse.jetty.util.thread.Invocable$InvocableExecutor.invoke(Invocable.java:222)
    at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:294)
    at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.produce(EatWhatYouKill.java:126)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:673)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:591)
    at java.lang.Thread.run(Thread.java:745)

As It seems, it is quite mandatory to use method "LocalServerReceiver() in the google-oauth-client-jetty library".

We need any help to move on.


Solution

  • I found the problem :

    google-oauth-client-jetty (LocalServerReceiver) was using the org.mortbay.jetty which has the old version of servlet-api. (2.5.**)

    I excluded and changed LocalServerReceiver class.. Put in my package. And changed jetty to org.eclipse.jetty.