问题描述
restAPI中提供的demo有时候运行没有问题,有时候又会抛异常,代码都没动 获取token HttpClient.execute(httppost)就会捕获异常 ,问题是有时候测试又没问题
解决方案
抛出的异常是什么? 贴出来看看
解决方案二:
直接运行demo main方法中的实例 在获取token时候 返回的,tokenResponse对象为HTTP/1.0 302 Moved Temporarily [Location: http://10.16.248.2/auth_entry. ... b.com, Content-Type: text/html;, Content-Length: 0],token为null异常就是空指针异常java.lang.RuntimeException: java.lang.NullPointerException at com.easemob.server.example.httpclient.utils.HTTPClientUtils.sendHTTPRequest(HTTPClientUtils.java:123) at com.easemob.server.example.httpclient.apidemo.EasemobIMUsers.createNewIMUserSingle(EasemobIMUsers.java:179) at com.easemob.server.example.httpclient.apidemo.EasemobIMUsers.main(EasemobIMUsers.java:45)Caused by: java.lang.NullPointerException at com.easemob.server.example.httpclient.vo.Token.applyAuthentication(Token.java:29) at com.easemob.server.example.httpclient.vo.Token.applyAuthentication(Token.java:25) at com.easemob.server.example.httpclient.utils.HTTPClientUtils.sendHTTPRequest(HTTPClientUtils.java:78) ... 2 more 我把demo中的代码拷贝到我的工程,接收前台的注册信息时候,也是 HttpResponse tokenResponse = client.execute(httpPost); HttpEntity entity = tokenResponse.getEntity();这两句代码直接就抛异常 ,tokenResponse 对象都没接受到 。异常如下:java.lang.RuntimeException: java.lang.RuntimeException: Some errors occurred while fetching a token by username and password . at iaf.im.httpclient.utils.HTTPClientUtils.sendHTTPRequest(HTTPClientUtils.java:123) at iaf.im.web.UserController.createNewIMUserSingle(UserController.java:152) at iaf.im.web.UserController.register(UserController.java:52) 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:601) at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176) at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:426) at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560) at javax.servlet.http.HttpServlet.service(HttpServlet.java:650) at javax.servlet.http.HttpServlet.service(HttpServlet.java:731) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:722)Caused by: java.lang.RuntimeException: Some errors occurred while fetching a token by username and password . at iaf.im.httpclient.vo.ClientSecretCredential.getToken(ClientSecretCredential.java:103) at iaf.im.httpclient.vo.Token.applyAuthentication(Token.java:25) at iaf.im.httpclient.utils.HTTPClientUtils.sendHTTPRequest(HTTPClientUtils.java:78) ... 39 more 最最关键的是前天这些代码就报这些错,而 昨天这些代码运行的好好的,今天一开机,运行,又挂了 !!!