短信网关发送接受平台。
源代码在线查看: cmppresponse.java
import java.lang.*;
import java.net.*;
import java.io.*;
import CMPPLog;
import CMPPException;
import CMPPThread;
import CMPPConnect;
import CMPPConnectResponse;
import CMPPActiveTest;
import CMPPActiveTestResponse;
import CMPPTerminate;
import CMPPTerminateResponse;
import CMPPSubmit;
import CMPPSubmitResponse;
import CMPPDeliver;
import CMPPDeliverResponse;
import CMPPQuery;
import CMPPQueryResponse;
import CMPPCancel;
import CMPPCancelResponse;
public class CMPPResponse extends CMPPThread
{
//通讯层
protected CMPPSynchronizedIO m_synio = null;
protected CMPPAsynchronizedIO m_asynio = null;
public CMPPResponse(CMPPSynchronizedIO synio,CMPPAsynchronizedIO asynio)
throws CMPPException
{
if(synio == null)
{
throw new CMPPException("CMPPResponse.CMPPResponse : null synchronized io !");
}
m_synio = synio;
if(asynio == null)
{
throw new CMPPException("CMPPResponse.CMPPResponse : null asynchronized io !");
}
m_asynio = asynio;
}
protected void OnTerminateResponse(CMPPTerminateResponse response,CMPPTerminate terminate)
{
}
protected void OnConnectResponse(CMPPConnectResponse response,CMPPConnect connect)
{
}
protected void OnSubmitResponse(CMPPSubmitResponse response,CMPPSubmit sbumit)
{
}
protected void OnCancelResponse(CMPPCancelResponse response,CMPPCancel cancel)
{
}
protected void OnQueryResponse(CMPPQueryResponse response,CMPPQuery query)
{
}
protected void OnDeliverResponse(CMPPDeliverResponse response,CMPPDeliver deliver)
{
}
protected void OnActiveTestResponse(CMPPActiveTestResponse response,CMPPActiveTest activetest)
{
}
public CMPPTerminateResponse response(CMPPTerminate terminate)
{
CMPPTerminateResponse response = null;
try
{
//解开数据包
terminate.unwrap();
//检查有效性
if(!terminate.isValid())
{
throw new CMPPException("CMPPResponse.response : invalid terminate request !");
}
response = new CMPPTerminateResponse(terminate.sequence_id);
//设置响应数据
OnTerminateResponse(response,terminate);
//检查输出包的有效性
if(!response.isValid())
{
throw new CMPPException("CMPPResponse.response : invalid terminate response !");
}
//将数据打包
response.wrap();
return response;
}
catch(Exception e)
{
CMPPLog.log(e.getMessage(),
CMPPLog.LOG_CMPP_RESPONSE | LogRequest.LOG_EXCEPTION);
CMPPLog.log("CMPPResponse.response : unexpected exit !",
CMPPLog.LOG_CMPP_RESPONSE | LogRequest.LOG_EXCEPTION);
}
return null;
}
public CMPPConnectResponse response(CMPPConnect connect)
{
CMPPConnectResponse response = null;
try
{
//解开数据包
connect.unwrap();
//检查有效性
if(!connect.isValid())
{
throw new CMPPException("CMPPResponse.response : invalid connect request !");
}
//生成一个响应
response = new CMPPConnectResponse(connect.sequence_id);
//设置响应数据
OnConnectResponse(response,connect);
//检查输出包的有效性
if(!response.isValid())
{
throw new CMPPException("CMPPResponse.response : invalid connect response !");
}
//将数据打包
response.wrap();
return response;
}
catch(Exception e)
{
CMPPLog.log(e.getMessage(),
CMPPLog.LOG_CMPP_RESPONSE | LogRequest.LOG_EXCEPTION);
CMPPLog.log("CMPPResponse.response : unexpected exit !",
CMPPLog.LOG_CMPP_RESPONSE | LogRequest.LOG_EXCEPTION);
}
return null;
}
public CMPPActiveTestResponse response(CMPPActiveTest activetest)
{
CMPPActiveTestResponse response = null;
try
{
//解开数据包
activetest.unwrap();
//检查有效性
if(!activetest.isValid())
{
throw new CMPPException("CMPPResponse.response : invalid activetest request !");
}
response = new CMPPActiveTestResponse(activetest.sequence_id);
//设置响应数据
OnActiveTestResponse(response,activetest);
//检查输出包的有效性
if(!response.isValid())
{
throw new CMPPException("CMPPResponse.response : invalid activetest response !");
}
//将数据打包
response.wrap();
return response;
}
catch(Exception e)
{
CMPPLog.log(e.getMessage(),
CMPPLog.LOG_CMPP_RESPONSE | LogRequest.LOG_EXCEPTION);
CMPPLog.log("CMPPResponse.response : unexpected exit !",
CMPPLog.LOG_CMPP_RESPONSE | LogRequest.LOG_EXCEPTION);
}
return null;
}
public CMPPSubmitResponse response(CMPPSubmit submit)
{
CMPPSubmitResponse response = null;
try
{
//解开数据包
submit.unwrap();
if(!submit.isValid())
{
throw new CMPPException("CMPPResponse.response : invalid submit request !");
}
response = new CMPPSubmitResponse(submit.sequence_id);
//设置响应数据
OnSubmitResponse(response,submit);
//检查输出包的有效性
if(!response.isValid())
{
throw new CMPPException("CMPPResponse.response : invalid submit response !");
}
//将数据打包
response.wrap();
return response;
}
catch(Exception e)
{
CMPPLog.log(e.getMessage(),
CMPPLog.LOG_CMPP_RESPONSE | LogRequest.LOG_EXCEPTION);
CMPPLog.log("CMPPResponse.response : unexpected exit !",
CMPPLog.LOG_CMPP_RESPONSE | LogRequest.LOG_EXCEPTION);
}
return null;
}
public CMPPDeliverResponse response(CMPPDeliver deliver)
{
CMPPDeliverResponse response = null;
try
{
//解开数据包
deliver.unwrap();
if(!deliver.isValid())
{
throw new CMPPException("CMPPResponse.response : invalid deliver request !");
}
response = new CMPPDeliverResponse(deliver.sequence_id);
//设置响应数据
OnDeliverResponse(response,deliver);
//检查输出包的有效性
if(!response.isValid())
{
throw new CMPPException("CMPPResponse.response : invalid deliver response !");
}
//将数据打包
response.wrap();
return response;
}
catch(Exception e)
{
CMPPLog.log(e.getMessage(),
CMPPLog.LOG_CMPP_RESPONSE | LogRequest.LOG_EXCEPTION);
CMPPLog.log("CMPPResponse.response : unexpected exit !",
CMPPLog.LOG_CMPP_RESPONSE | LogRequest.LOG_EXCEPTION);
}
return null;
}
public CMPPCancelResponse response(CMPPCancel cancel)
{
CMPPCancelResponse response = null;
try
{
//解开数据包
cancel.unwrap();
//检查有效性
if(!cancel.isValid())
{
throw new CMPPException("CMPPResponse.response : invalid cancel request !");
}
response = new CMPPCancelResponse(cancel.sequence_id);
//设置响应数据
OnCancelResponse(response,cancel);
//检查输出包的有效性
if(!response.isValid())
{
throw new CMPPException("CMPPResponse.response : invalid cancel response !");
}
//将数据打包
response.wrap();
return response;
}
catch(Exception e)
{
CMPPLog.log(e.getMessage(),
CMPPLog.LOG_CMPP_RESPONSE | LogRequest.LOG_EXCEPTION);
CMPPLog.log("CMPPResponse.response : unexpected exit !",
CMPPLog.LOG_CMPP_RESPONSE | LogRequest.LOG_EXCEPTION);
}
return null;
}
public CMPPQueryResponse response(CMPPQuery query)
{
CMPPQueryResponse response = null;
try
{
//解开数据包
query.unwrap();
//检查有效性
if(!query.isValid())
{
throw new CMPPException("CMPPResponse.response : invalid query request !");
}
response = new CMPPQueryResponse(query.sequence_id);
//设置响应数据
OnQueryResponse(response,query);
//检查输出包的有效性
if(!response.isValid())
{
throw new CMPPException("CMPPResponse.response : invalid query response !");
}
//将数据打包
response.wrap();
return response;
}
catch(Exception e)
{
CMPPLog.log(e.getMessage(),
CMPPLog.LOG_CMPP_RESPONSE | LogRequest.LOG_EXCEPTION);
CMPPLog.log("CMPPResponse.response : unexpected exit !",
CMPPLog.LOG_CMPP_RESPONSE | LogRequest.LOG_EXCEPTION);
}
return null;
}
}