SparkJava 无法与一些 Google Youtube API 一起工作

SparkJava cannot work together with some Google Youtube API's

我们决定将 SparkJava、Kotlin 和 Mustache 用于商业 web 产品。我们的产品需要与 Google (YouTube) API 的产品集成。

该项目的所有端点均正常运行。 (后台、CRUD 操作等)我们开始实施 YouTube 的集成,我不得不将 Google 库添加到我的项目中以启动。 (不添加任何额外代码,只是添加了库 google-oauth-client-jetty。)

您可以在下面找到我的 Gradle 库:

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'
}

当我 特别添加库 'google-oauth-client-jetty',版本:'1.11.0-beta' 到项目中时,我无法通过 http (GET, POST, PUT none 个)。我启用了 SparkJava 的日志,我正面临着下面的日志。

比如我打电话给

http://localhost:3000/admin

结果是:

    [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.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.run(QueuedThreadPool.java:591)
    at java.lang.Thread.run(Thread.java:745)

看来,使用方法"LocalServerReceiver() in the google-oauth-client-jetty library"是相当强制的。

我们需要任何帮助才能继续前进。

我发现了问题:

google-oauth-client-jetty (LocalServerReceiver) 正在使用具有旧版本 servlet-api 的 org.mortbay.jetty。 (2.5.**)

我排除并更改了 LocalServerReceiver class.. 放入我的包中。并将码头更改为 org.eclipse.jetty.