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(); }
相關文章
- 3.2.2 Opening a Closed DatabaseDatabase
- Spider closed (finished) 沒完成IDE
- java.lang.IllegalStateException: Service id not legal hostnameJavaException
- Vultr賬號被封:Your account is currently closed
- python程式碼錯誤RuntimeError: Session is closedPythonErrorSession
- Caused by: java.lang.IllegalStateException: getWriter() has already been called for this responseJavaException
- Caused by: java.lang.IllegalStateException: Only single-level inheritance supported: XxxxServiceJavaException
- error: RPC failed; curl 18 transfer closed with outstanding read data remainingErrorRPCAIREM
- Oracle 12c RMAN Cross-Platform Transport of a Closed PDBOracleROSPlatform
- 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
- ViewPager內使用FragmentPagerAdapter時滑動出現 java.lang.IllegalStateException: The specified child already hViewpagerFragmentAPTJavaException
- Mysql異常刨析:Could not commit JDBC transaction;No operations allowed after statement closedMySqlMITJDBC
- SAP MM 採購申請單據ITEM資料裡的Closed標記
- prettier Unexpected closing tag "p". It may happen when the tag has already been closed by another tag.APP
- 支付寶轉賬介面HTTP/2 stream 0 was not closed close cleanly報錯解決HTTP
- 求助:移動端登入測試,報錯 RemoteDisconnected Remote end closed connection without response。REM
- IgniteFAQ-10-使用hikariDataSource資料來源偶現日誌報錯load資料包connection is closed
- dotnet 委託的實現解析(2)開放委託和封閉委託 (Open Delegates vs. Closed Delegates)