3
回答
TOMCAT启动后,执行POS交易,显示连接超时
终于搞明白,存储TCO原来是这样算的>>>   

@红薯 你好,想跟你请教个问题:

基本环境:

系统:Ubuntu9.10server

编程语言:java

中间件、连接池:TOMCAT5.5

数据库:Mysql 5.0.96

我在ubuntu 9.10server 系统下部署了一个测试平台(关于用户会员卡积分累计相关的系统),启动后,进行POS交易操作。POS机签到成功!

执行积分累计,显示连接超时的异常!

2012-08-14 15:17:58 (BeappClient.java:85) 连接超时
2012-08-14 15:17:58 (MessageHandler.java:96) 处理报文异常
cn.com.beapp.common.exception.SystemException
        at cn.com.beapp.pos.http.BeappClient.callMethodSynchrone(BeappClient.java:86)
        at cn.com.beapp.pos.http.RequestService.callRemoteMethod(RequestService.java:47)
        at cn.com.beapp.pos.http.RequestService.process(RequestService.java:63)
        at cn.com.beapp.pos.parse.MessageHandler.process(MessageHandler.java:82)
        at cn.com.beapp.pos.Receiver.run(Receiver.java:98)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
        at java.lang.Thread.run(Thread.java:662)
2012-08-14 15:17:58 (MessageHandler.java:130) 错误码:1000

以下是代码片段:

//部分源代码

/**
 * 与Beapp发布的服务端进行数据通讯的包装类
 * 
 */
public class BeappClient {
	
	private static final Logger logger = Logger.getLogger(BeappClient.class);

	private static final int STATUS_OK = 0;
	
	private static final int STATUS_ERROR = 1;
	
	private static final int timout = 60;

	private String serverUrl;

	private String cookie;	
	
	public Object callMethodSynchrone(Object parameter) {
		DataOutputStream out = null;
		DataInputStream in = null;
		URLConnection connection = null;
		URL url;
		try {
			url = new URL(serverUrl);
			if (connection == null) {
				connection = url.openConnection();
				connection.setUseCaches(false);
				connection.setDoOutput(true);
				connection.setDoInput(true);
				connection.setConnectTimeout(timout *1000); 
				connection.setReadTimeout(timout*1000); 
			}
			if (this.cookie != null) {
				connection.setRequestProperty("cookie", this.cookie);
			}
			out = new DataOutputStream(connection.getOutputStream());

			serialize(parameter,out);

			// send request and read return values:
			in = new DataInputStream(connection.getInputStream());

			out.flush();

			String newCookie = connection.getHeaderField("Set-cookie");
			logger.debug("newCookie is:" + newCookie);
			if (newCookie != null) {
				int index = newCookie.indexOf(";");
				if (index != -1) {
					this.cookie = newCookie.substring(0, index);
				} else {
					this.cookie = newCookie;
				}
			}
			


			byte status = in.readByte();
			if (STATUS_OK == status) {
				Object object =  deserialize(in);
				return object;
			}
			else if(STATUS_ERROR == status){
				logger.error("服务器处理异常");
				throw new SystemException(ErrorCode.SERVER_ERROR);
			}
		} catch (java.net.ConnectException e) {
			logger.error("连接超时");
			throw new SystemException(ErrorCode.CONNNECT_TIMOUT);
			
		} catch (Exception e) {
			logger.error("服务器处理异常",e);
			throw new SystemException(ErrorCode.SERVER_ERROR);
		}
			
		return this.cookie;
	}

若能解惑,不胜感激!

举报
顶部