SparkJava无法与某些Google Youtube API一起使用。



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

该项目的所有端点都正常工作。(后台、CRUD运营等)我们开始实现YouTube的集成,我不得不将谷歌库添加到我的项目中以启动(不添加任何额外的代码,只是添加了库googleoauth客户端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都没有)到达端点。我启用了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$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)

看起来,在googleoauth客户端jetty库中使用方法"LocalServerReceiver()"是非常强制性的。

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

我发现了问题:

googleoauth客户端jetty(LocalServerReceiver)使用的是org.portbay.getty,它有旧版本的servlet api。(2.5.**)

我排除并更改了LocalServerReceiver类。。放在我的包裹里。并将jetty更改为org.eclipse.jjetty.

最新更新