java.lang.IllegalStateException: closed
java.lang.IllegalStateException: closed
at okio.RealBufferedSource.rangeEquals(RealBufferedSource.java:408)
at okio.RealBufferedSource.rangeEquals(RealBufferedSource.java:402)
at okhttp3.internal.Util.bomAwareCharset(Util.java:432)
at okhttp3.ResponseBody.string(ResponseBody.java:174)
at com.nextop.controller.EBayController.getOrders(EBayController.java:151)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:106)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:879)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:793)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:109)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:367)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1639)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
OkHttpClient的返回值呼叫兩次導致流已經關閉 response.body().string();
原因是流已經關閉,所以無法再進行操作。
@PostMapping(value = "getOrders", produces = {"application/json"}) public String getOrders(@RequestBody final String token) throws IOException { final OkHttpClient okHttpClient = new OkHttpClient(); final Request request = new Request.Builder() // .url("https://api.sandbox.ebay.com/sell/fulfillment/v1/order/04-05321-94491") .url("https://api.sandbox.ebay.com/sell/fulfillment/v1/order?filter=creationdate:%5B2020-11-01T15:05:43.026Z..%5D&limit=50&offset=0") // .url("https://api.ebay.com/sell/fulfillment/v1/order/04-05321-94491") .get() .addHeader("Authorization", "Bearer " + token) .addHeader("Content-Language", "EBAY_US") .addHeader("Content-Type", "application/json") .addHeader("X-EBAY-C-MARKETPLACE-ID", "EBAY_US") .build(); final Response response = okHttpClient.newCall(request).execute(); log.info("請求是否成功: " + response.isSuccessful()); log.info("response" + response.body().string()); return response.body().string(); }
OkHttp請求回撥中response.body().string()只能有效呼叫一次,呼叫response.body().string()的時候資料流已經關閉了,再次呼叫就是提示已經closed。然後我把程式碼修改完之後就可以了,只呼叫一次response.body().string();
@PostMapping(value = "getOrders", produces = {"application/json"}) public String getOrders(@RequestBody final String token) throws IOException { final OkHttpClient okHttpClient = new OkHttpClient(); final Request request = new Request.Builder() // .url("https://api.sandbox.ebay.com/sell/fulfillment/v1/order/04-05321-94491") .url("https://api.sandbox.ebay.com/sell/fulfillment/v1/order?filter=creationdate:%5B2020-11-01T15:05:43.026Z..%5D&limit=50&offset=0") // .url("https://api.ebay.com/sell/fulfillment/v1/order/04-05321-94491") .get() .addHeader("Authorization", "Bearer " + token) .addHeader("Content-Language", "EBAY_US") .addHeader("Content-Type", "application/json") .addHeader("X-EBAY-C-MARKETPLACE-ID", "EBAY_US") .build(); final Response response = okHttpClient.newCall(request).execute(); log.info("請求是否成功: " + response.isSuccessful()); // log.info("response" + response.body().string()); return response.body().string(); }
相關文章
- 解決okhttp報java.lang.IllegalStateException: closed,java.lang.IllegalStateException: closedHTTPJavaException
- android java.lang.IllegalStateException: trying to requery an already closed cursorAndroidJavaException
- [求助]SQLException: ResultSet is closedSQLException
- java.lang.IllegalStateException: getWriteableDatabase called recursivelyJavaExceptionDatabase
- 3.2.2 Opening a Closed DatabaseDatabase
- java.lang.IllegalStateException: Service id not legal hostnameJavaException
- Spider closed (finished) 沒完成IDE
- java.lang.IllegalStateException: getOutputStream() has already been called for this responseJavaException
- java.lang.IllegalStateException:YouneedtouseaTheme.AppCompatthemeJavaExceptionAPP
- Caused by: java.lang.IllegalStateException: getWriter() has already been called for this responseJavaException
- python程式碼錯誤RuntimeError: Session is closedPythonErrorSession
- Oracle 12c RMAN Cross-Platform Transport of a Closed PDBOracleROSPlatform
- java.lang.IllegalStateException: getOutputStream() has already been called for this response解決方案JavaException
- java.lang.IllegalStateException: Cannot call sendError() after the response has been committed解讀JavaExceptionErrorMIT
- Idea啟動專案報{dataSource-1} closed錯誤Idea
- Unable to unwrap data, invalid status [CLOSED]-服務端webSocket報錯服務端Web
- 解決Hibernate session is closed的一種可行性方案Session
- ssh問題:ssh_exchange_identification: Connection closed by remote hostIDEREM
- 設計模式筆記:開閉原則(OCP,The Open-Closed Principle)設計模式筆記
- ORA-12537: TNS:connection closed問題解決
- client backup was not attempted because backup window closed 錯誤解決一例client
- /dev/root filesystem full-unable to log into server-This thread has been closeddevServerthread
- 一個異常org.apache.jasper.JasperException: java.lang.IllegalStateException: No output folder:的解決...ApacheExceptionJava
- error: RPC failed; curl 18 transfer closed with outstanding read data remainingErrorRPCAIREM
- Mysql異常刨析:Could not commit JDBC transaction;No operations allowed after statement closedMySqlMITJDBC
- 【Oracle】ORA-12537: TNS:connection closed 問題處理Oracle
- ora-12537 TNS:connection closed的問題處理
- Emily Dickinson的詩歌《My Life Closed Twice Before Its Close》
- ViewPager內使用FragmentPagerAdapter時滑動出現 java.lang.IllegalStateException: The specified child already hViewpagerFragmentAPTJavaException
- Caused by: java.lang.IllegalStateException: Only single-level inheritance supported: XxxxServiceJavaException
- SAP MM 採購申請單據ITEM資料裡的Closed標記
- 支付寶轉賬介面HTTP/2 stream 0 was not closed close cleanly報錯解決HTTP
- rhel5上配置vsftpd_421 Service not available, remote server has closed connectionFTPAIREMServer
- 求助:移動端登入測試,報錯 RemoteDisconnected Remote end closed connection without response。REM
- FI-AA Capitalization date 2012.08.01 not before closed FY 2012API
- 解決11gR2 Rac ORA-12537: TNS:connection closed 一例
- prettier Unexpected closing tag "p". It may happen when the tag has already been closed by another tag.APP
- 使用mgo框架,mongo每次重啟,依賴它的服務都會出現Closed explicitly錯誤?Go框架