java webservice超时时间设置方法

02-27 阅读 0评论

一、前言

之前遇到过rabbitmq队列卡死的问题,有消费者,但是就不消费队列里的消息;

java webservice超时时间设置方法,java webservice超时时间设置方法,词库加载错误:未能找到文件“C:\Users\Administrator\Desktop\火车头9.8破解版\Configuration\Dict_Stopwords.txt”。,设置,方法,设置方法,第1张
(图片来源网络,侵删)

后来发现是消费者执行webservice方法时,没有设置超时时间,默认永不超时,然后赶上对端系统出问题,方法就一直执行不完,队列消息也就一直卡住不动。(加try-catch是没有用的,catch不到,就是没有执行完一直卡住,因为超时时间默认永不超时)

在此总结下java webservice设置超时时间的方法。

二、代码

		try {
			JaxWsDynamicClientFactory dcf=JaxWsDynamicClientFactory.newInstance();
			
			//这里有2种方法,不确定到底是哪种,就都写上了
            dcf.getJaxbContextProperties().put("com.sun.xml.ws.request.timeout", 10000);
            dcf.getJaxbContextProperties().put("com.sun.xml.ws.connect.timeout", 10000);
            dcf.getJaxbContextProperties().put("com.sun.xml.internal.ws.connection.timeout", 10000);//建立连接的超时时间为10秒
            dcf.getJaxbContextProperties().put("com.sun.xml.internal.ws.request.timeout", 10000);//指定请求的响应超时时间为10秒
			LOGGER.info("设置超时时间");
			Client client= dcf.createClient("http://128.0.0.1/A/services/BService?wsdl");
            //这里再设置超时时间好像也行
			//client.getRequestContext().put("com.sun.xml.ws.request.timeout", 10000);
			//client.getRequestContext().put("com.sun.xml.ws.connect.timeout", 10000);
            //client.getRequestContext().put("com.sun.xml.internal.ws.connection.timeout", 10000);//建立连接的超时时间为10秒
            //client.getRequestContext().put("com.sun.xml.internal.ws.request.timeout", 10000);//指定请求的响应超时时间为10秒
			//如果不设置超时时间,那么如果连接不通,就会卡在这一步
			Object[] resultObj = client.invoke("createOrenableAccount", new Object[] { accountToXML("abc") });
			String retXML = resultObj[0].toString();
			StringReader read = new StringReader(retXML);
			InputSource source = new InputSource(read);
			SAXBuilder sb = new SAXBuilder();
			Document doc = sb.build(source);
			Element root = doc.getRootElement();
		    LOGGER.info(root.getChildText("code"));// 0  成功
			LOGGER.info(root.getChildText("code") + ", " + root.getChildText("message"));
		} catch (Exception e) {
			LOGGER.error((new StringBuilder("invokeWS Exception:")).append(e).toString(),e);
		}
		
------------------
	public static String accountToXML(String userName) {
		Document document = null;
		Element et = new Element("account");
		document = new Document(et);
		document = addNode(document, "appname", "AI");
		document = addNode(document, "uid", userName);
		document = addNode(document, "eruid", userName);
		return documentStr(document);
	}
-------------------
	public static String documentStr(Document document) {
		XMLOutputter xop = new XMLOutputter();
		String xmlStr = xop.outputString(document);
		return xmlStr;
	}	
------------------------
pom.xml是这样:
		
		
			org.apache.cxf
			cxf-rt-rs-client
			3.0.0
		
		
		  org.apache.cxf
		  cxf-rt-frontend-jaxws
		  3.0.0
		
java webservice超时时间设置方法,java webservice超时时间设置方法,词库加载错误:未能找到文件“C:\Users\Administrator\Desktop\火车头9.8破解版\Configuration\Dict_Stopwords.txt”。,设置,方法,设置方法,第2张
(图片来源网络,侵删)
java webservice超时时间设置方法,java webservice超时时间设置方法,词库加载错误:未能找到文件“C:\Users\Administrator\Desktop\火车头9.8破解版\Configuration\Dict_Stopwords.txt”。,设置,方法,设置方法,第3张
(图片来源网络,侵删)

免责声明
本网站所收集的部分公开资料来源于AI生成和互联网,转载的目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。
文章版权声明:除非注明,否则均为主机测评原创文章,转载或复制请以超链接形式并注明出处。

发表评论

快捷回复: 表情:
评论列表 (暂无评论,人围观)

还没有评论,来说两句吧...

目录[+]