NutzCN Logo
问答 报错:java.lang.RuntimeException: java.io.IOException: Stream closed
发布于 1468天前 作者 ThxYouForComing 1382 次浏览 复制 上一个帖子 下一个帖子
标签:

主要代码成分

private String sendRequestGet(String url,Header header) {
		return Sender.create(Request.get(url, header)).setTimeout(10 *1000)
                .send()
                .getContent();
	}
public Object execStore(String timestamp,String seqNo,String transNo,String businessType) {
		//设置一下时间戳
		SimpleDateFormat df2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
		//给时间戳赋值
    	timestamp = df2.format(new Date());
    	seqNo = "4635768786756";
    	transNo = "234567845678";
    	businessType = "HOTEL";
    	
    	//调用UUIDUtils获取一个reqId
    	String reqString = UUIDUtils.creatUUID();
    	//这个Map是存的URL参数,请求头Header(sign除外)
    	Map<String, Object> params = new HashMap<String, Object>();
    	params.put("requestId", "WAC");
    	params.put("targetId", "MMS");
    	params.put("serviceId", "QueryStoreList");
    	params.put("timestamp", "2020-12-14 17:27:04");
    	params.put("seqNo", seqNo);
    	params.put("transNo", transNo);
    	params.put("businessType", businessType);
    	//这个是调用签名方法 然后用code接收一下签名串
    	String code = SignUtil.signToRequestGet(params,"BE266D8CC0","5924e0cfeb5b4214b4e448613e55bcf3");
    	
    	//获取拼接参数的长度
    	int admin = SignUtil.signToRequestmap(params).length();
    	//用SubString取一下除了第一位剩下的数据
    	String pinjie = SignUtil.signToRequestmap(params).substring(1, admin);
    	
    	//创建请求头
    	Header header = Header.create();
		header.set("x-dtyunxi-instanceId", "1260634217255523340");
		header.set("x-dtyunxi-reqId", "5924e0cfeb5b4214b4e448613e55bcf3");
		header.set("x-dtyunxi-sign", code);
		//发送Http请求 用request接收返回的数据
		String aString = sendRequestGet("http://183.63.76.163:9880/operation-service/v1/operation/item/queryStoreList?"+pinjie, header);
    	return aString;
	}

控制台错误

java.lang.RuntimeException: java.io.IOException: Stream closed
	at org.nutz.lang.Lang.wrapThrow(Lang.java:153)
	at org.nutz.lang.Streams.readAndClose(Streams.java:291)
	at org.nutz.http.Response.getContent(Response.java:148)
	at org.nutz.http.Response.getContent(Response.java:141)
	at com.bsdkj.hhd.modules.service.webservice.WebService.sendRequestGet(WebService.java:66)
	at com.bsdkj.hhd.modules.service.webservice.WebService.execStore(WebService.java:678)
	at com.bsdkj.hhd.modules.mvc.test.TestAction.GetStore(TestAction.java:80)
	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.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:25)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:33)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at com.bsdkj.hhd.common.mvc.processor.NutShiroProcessor.process(NutShiroProcessor.java:54)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at com.bsdkj.hhd.common.mvc.processor.XSSProcessor.process(XSSProcessor.java:43)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at com.bsdkj.hhd.common.mvc.processor.GlobalsSettingProcessor.process(GlobalsSettingProcessor.java:39)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at com.bsdkj.hhd.common.mvc.processor.LogTimeProcessor.process(LogTimeProcessor.java:21)
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:196)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
	at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
	at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)
	at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
	at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
	at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
	at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
	at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
	at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
	at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
	at com.bsdkj.hhd.common.mvc.filter.XssFilter.doFilter(XssFilter.java:23)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1099)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:670)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.IOException: Stream closed
	at java.io.BufferedInputStream.getInIfOpen(BufferedInputStream.java:159)
	at java.io.BufferedInputStream.read1(BufferedInputStream.java:284)
	at java.io.BufferedInputStream.read(BufferedInputStream.java:345)
	at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284)
	at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326)
	at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
	at java.io.InputStreamReader.read(InputStreamReader.java:184)
	at java.io.Reader.read(Reader.java:140)
	at org.nutz.lang.Streams.read(Streams.java:270)
	at org.nutz.lang.Streams.readAndClose(Streams.java:288)
	... 70 more

4 回复

求解,用了好几种方法都会这样

Sender sender = Sender.create(req);
        Response resp = sender.send();
        if (!resp.isOK())
            throw new IllegalStateException("resp code=" + resp.getStatus());

@Wizzercn 请问Sender.create(req)中的req是指的

   	Request req = Request.create("http://183.63.76.163:9880/operation-service/v1/operation/item/queryStoreList?"+pinjie, METHOD.GET);
 

这个吗?

添加回复
请先登陆
回到顶部