今天在接入阿里巴巴平台和qqSDK时出了个意想不到的错,下面分享一下
java.lang.reflect.UndeclaredThrowableException at com.alibaba.openapi.client.$Proxy5.getToken(Unknown Source) at com.alibaba.openapi.client.AlibabaClient.getToken(AlibabaClient.java:468) at com.zhigu.common.alibaba.AlibabaUtil.getToken(AlibabaUtil.java:75) at com.zhigu.service.alibaba.impl.AliItemCategoryServiceImpl.test(AliItemCategoryServiceImpl.java:87) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) Caused by: java.util.concurrent.ExecutionException: com.alibaba.openapi.client.exception.AuthServiceException: auth service exception:wrong authorizationCode:0cef72ce-d577-4cb2-9183-bc15dfa1e966 at com.alibaba.openapi.client.AlibabaClient.send(AlibabaClient.java:158) at com.alibaba.openapi.client.AlibabaClient$APIProxy.invoke(AlibabaClient.java:413) ... 27 more Caused by: com.alibaba.openapi.client.exception.AuthServiceException: auth service exception:wrong authorizationCode:0cef72ce-d577-4cb2-9183-bc15dfa1e966 at com.alibaba.openapi.client.util.ExceptionParser.buildException(ExceptionParser.java:80) at com.alibaba.openapi.client.util.ExceptionParser.buildException4OAuth2(ExceptionParser.java:71) at com.alibaba.openapi.client.rpc.BasicHttpResponseParser.buildException(BasicHttpResponseParser.java:100) at com.alibaba.openapi.client.rpc.AbstractHttpResponseParser.parseResponse(AbstractHttpResponseParser.java:90) at com.alibaba.openapi.client.rpc.AliNHttpRequstExecutionHandler$1.finished(AliNHttpRequstExecutionHandler.java:86) at org.apache.http.nio.entity.ConsumingNHttpEntityTemplate.finish(ConsumingNHttpEntityTemplate.java:88) at org.apache.http.nio.protocol.AsyncNHttpClientHandler$ClientConnState.resetInput(AsyncNHttpClientHandler.java:502) at org.apache.http.nio.protocol.AsyncNHttpClientHandler$ClientConnState.reset(AsyncNHttpClientHandler.java:517) at org.apache.http.nio.protocol.AsyncNHttpClientHandler.closed(AsyncNHttpClientHandler.java:138) at org.apache.http.impl.nio.DefaultClientIOEventDispatch.onClosed(DefaultClientIOEventDispatch.java:137) at org.apache.http.impl.nio.DefaultClientIOEventDispatch.onClosed(DefaultClientIOEventDispatch.java:53) at org.apache.http.impl.nio.reactor.AbstractIODispatch.disconnected(AbstractIODispatch.java:102) at com.alibaba.openapi.client.rpc.io.AutoSSLClientIOEventDispatch.disconnected(AutoSSLClientIOEventDispatch.java:216) at org.apache.http.impl.nio.reactor.BaseIOReactor.sessionClosed(BaseIOReactor.java:281) at org.apache.http.impl.nio.reactor.AbstractIOReactor.processClosedSessions(AbstractIOReactor.java:442) at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:285) at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:106) at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:590) at java.lang.Thread.run(Thread.java:745)
以上报错,仔细一看,是oauth2的授权码失效了,这个没啥重新授权,运行代码授权
call...Starts the reactor and initiates the dispatch SessionRequestCallbackTrigger completed。。。 AutoSSLClientIOEventDispatch connected... AutoSSLClientIOEventDispatch outputReady... AutoSSLClientIOEventDispatch inputReady... AutoSSLClientIOEventDispatch outputReady... AutoSSLClientIOEventDispatch outputReady... AutoSSLClientIOEventDispatch outputReady... AutoSSLClientIOEventDispatch inputReady... AutoSSLClientIOEventDispatch outputReady... AutoSSLClientIOEventDispatch inputReady... AutoSSLClientIOEventDispatch inputReady... Exception in thread "I/O dispatcher 1" java.lang.NoSuchMethodError: org.codehaus.jackson.map.SerializationConfig.with([Lorg/codehaus/jackson/map/SerializationConfig$Feature;)Lorg/codehaus/jackson/map/SerializationConfig; at com.alibaba.openapi.client.util.JsonMapper.<clinit>(JsonMapper.java:57) at com.alibaba.openapi.client.rpc.BasicHttpResponseParser.parseBody(BasicHttpResponseParser.java:59) at com.alibaba.openapi.client.rpc.BasicHttpResponseParser.buildException(BasicHttpResponseParser.java:99) at com.alibaba.openapi.client.rpc.AbstractHttpResponseParser.parseResponse(AbstractHttpResponseParser.java:90) at com.alibaba.openapi.client.rpc.AliNHttpRequstExecutionHandler$1.finished(AliNHttpRequstExecutionHandler.java:86) at org.apache.http.nio.entity.ConsumingNHttpEntityTemplate.finish(ConsumingNHttpEntityTemplate.java:88) at org.apache.http.nio.protocol.AsyncNHttpClientHandler$ClientConnState.resetInput(AsyncNHttpClientHandler.java:502) at org.apache.http.nio.protocol.AsyncNHttpClientHandler$ClientConnState.reset(AsyncNHttpClientHandler.java:517) at org.apache.http.nio.protocol.AsyncNHttpClientHandler.closed(AsyncNHttpClientHandler.java:138) at org.apache.http.impl.nio.DefaultClientIOEventDispatch.onClosed(DefaultClientIOEventDispatch.java:137) at org.apache.http.impl.nio.DefaultClientIOEventDispatch.onClosed(DefaultClientIOEventDispatch.java:53) at org.apache.http.impl.nio.reactor.AbstractIODispatch.disconnected(AbstractIODispatch.java:102) at com.alibaba.openapi.client.rpc.io.AutoSSLClientIOEventDispatch.disconnected(AutoSSLClientIOEventDispatch.java:216) at org.apache.http.impl.nio.reactor.BaseIOReactor.sessionClosed(BaseIOReactor.java:281) at org.apache.http.impl.nio.reactor.AbstractIOReactor.processClosedSessions(AbstractIOReactor.java:442) at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:285) at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:106) at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:590) at java.lang.Thread.run(Thread.java:745) 三月 21, 2015 10:31:11 上午 com.alibaba.openapi.client.AlibabaClient send 警告: Synchronous API [ namespace=system.oauth2,name=getToken] send request timeout.
从上面的分析来看是说那个类
SerializationConfig
里面没有
with() 参数:是一个Feature的数组 [Lorg/codehaus/jackson/map/SerializationConfig$Feature;]
从整个项目来看,项目中并没有这样的包目录(org.codehaus.jackson.map)存在,可以确定是第三方包出现了问题,于是开始在项目搜索这个类
SerializationConfig
操作步骤如下:
1.选中你的项目
2.ctr+h 打开搜索对话框
在containing text 下面的对话框中输入检索内容。
在filename pattern 下面的对话框中输入匹配的文件格式。
然后在选中scope (检索范围)下面选中 selected resources
开始检索,结果如下
从上面的结果可以看出确实存在好几个这个名称的类,但是还得看包结构,复合出错提示的只有两个;
一个是jackson-mapper-asl-19.13.jar,另一个是Sdk4J.jar(其它的包为什么不是:sdk4j.jar,这个jar包是我重新对Sdk4J.jar打的包删除里面的自带的jackson-mapper-asl-19.13.jar包)就是这个自带的jar出现了问题)
由于版本过低的问题,里面的类SerializationConfig缺少了新的方法(此处是with(Fearture...fearture)),而且项目运行时会先去用这个jar里面的class,(原因就是先找到先用谁,结果是类找到了,方法却找不到,却又不继续往下找,所以即使是你加入了最新的jackson-mapper-asl的jar包,也没有用),上几个解图,看看结构
这个是Sdk4J.jar里面的
可以看到确实没有with(Fearture...f)方法
在上个jackson-mapper-asl.jar
这个里面,却引用不到,真是坑啊
所以解决方法有三个
1.让项目先找到最新的jar(比较困难,不易实现,不做进一步的深究了,毕竟项目赶时间)
2.将又问题的改个名字在引用,这个最方便,但是没有解决掉根本问题
3.解压有问题的jar把里面的低版本的jar删除,或替换为最新的,然后在打包回去
jar cvf sdk4j.jar(打包后的名称) file(解压后删除低版本引用的文件目录)
最后一步检查是否可行运行代码测试结果如下:
取到数据,成功。问题解决了。