Spring integration 处理法语应答需要时间
我有一个流,如下所示。我从http api得到了法语响应,我看到了很大的时差。我正在为utf-8使用一些消息转换器 如果http的响应是英文的,我看到它在5分钟内处理,而法文是20分钟。不确定http客户端或json处理器是否需要时间,或者json创建是否需要时间 文件| xml解析器处理器|自定义http客户端| json处理器>队列 队列>http客户端|处理器|>队列2 我的http客户端如下所示Spring integration 处理法语应答需要时间,spring-integration,spring-xd,Spring Integration,Spring Xd,我有一个流,如下所示。我从http api得到了法语响应,我看到了很大的时差。我正在为utf-8使用一些消息转换器 如果http的响应是英文的,我看到它在5分钟内处理,而法文是20分钟。不确定http客户端或json处理器是否需要时间,或者json创建是否需要时间 文件| xml解析器处理器|自定义http客户端| json处理器>队列 队列>http客户端|处理器|>队列2 我的http客户端如下所示 </beans:bean> <beans:bean id="batc
</beans:bean>
<beans:bean id="batchRestTemplate" class="test.batch.httpclient.BatchRestTemplate" >
<beans:constructor-arg name="requestTimeOut" value="${requestTimeOut}"/>
<beans:constructor-arg name="maxConnectionPerRoute" value="${maxConnectionPerRoute}"/>
<beans:constructor-arg name="totalMaxConnections" ref="${totalMaxConnections}"/>
公共BatchRestTemplate(Integer requestTimeOut、Integer totalMaxConnections、Integer maxConnectionPerRoute)抛出NoSuchAlgorithmException{
super(createBatchHttpRequestFactory());
列表>();
addAll(getMessageConverters());
添加(0,新的StringHttpMessageConverter(Charset.forName(“UTF-8”)));
设置消息转换器(messageConverters);
}
我的处理器
JSONObject jsonData = new JSONObject(payload.getPayload());
byte[] msgCont = convertMsgContToBytes(jsonData);
String emailRequest = new JSONObject(
generateEMailRequest(payload, actualRecord))
.toString();
result = MessageBuilder.withPayload(emailRequest)
.copyHeaders(payload.getHeaders())
.setHeader(MESSAGE_TEXT, msgCont).build();
private byte[] convertMsgContToBytes(JSONObject jsonData)
throws EmailSMSProcessorException {
byte[] msgCont = null;
if (null != jsonData) {
try {
msgCont = jsonData.getJSONObject(MSG_CONTENT).toString()
.getBytes(UTF_8);
} catch (UnsupportedEncodingException e) {
LOGGER.error("Error in converting Msg Content to Byte[]", e);
throw new EmailSMSProcessorException(e);
} catch (JSONException e) {
LOGGER.error("Error in converting Msg Content to Byte[]", e);
throw new EmailSMSProcessorException(e);
}
}
return msgCont;
}
private void validatePayload(Message<String> payload, String actualRecord)
throws EmailSMSProcessorException {
if (null != actualRecord) {
JSONObject jsonData = null;
try{
jsonData = new JSONObject(payload.getPayload());
}catch(Exception e){
throw new EmailSMSProcessorException(
"payload/mandatory data is missing",CONST_SYS_EXPTN);
}
validateErrorIdText(jsonData);
} else {
throw new EmailSMSProcessorException(
"payload/mandatory data is missing",CONST_SYS_EXPTN);
}
}
private EmailRequest generateEMailRequest(Message<String> payload,
String actualRecord) throws EmailSMSProcessorException {
EmailRequest emailReq = null;
if (null != actualRecord) {
JSONObject jsonPayload = new JSONObject(payload.getPayload());
JSONObject actualJSON = new JSONObject(actualRecord);
emailReq = new EmailRequest();
MessageRecipients messageRecipients = new MessageRecipients();
if (jsonPayload.has(MSG_CONTENT)) {
JSONObject msgCntJson = jsonPayload.getJSONObject(MSG_CONTENT);
if (msgCntJson.has(SUBSTI_CONTENT)) {
String substitutionContent = jsonPayload
.getJSONObject(MSG_CONTENT).get(SUBSTI_CONTENT)
.toString();
JSONObject substitutionContentJSONObj = new JSONObject(
substitutionContent);
messageRecipients.setSubstitutionKeyValueData(
substitutionContentJSONObj);
}
}
Recipient recipient = new Recipient();
recipient.setEmailAddress(isNullCheckMandatoryFields(
actualJSON.getString(CNTCT_PNT_ADR_TXT),
CNTCT_PNT_ADR_TXT));
messageRecipients.setRecipient(recipient);
MessageKeyValueData messageKeyValData = new MessageKeyValueData();
messageKeyValData.setAlertType(isNullCheckMandatoryFields(
actualJSON.getString(ALRT_TYPE_CD), ALRT_TYPE_CD));
messageKeyValData.setAlertTrackingId(isNullCheckMandatoryFields(
actualJSON.getString(DLVRY_ID), DLVRY_ID));
messageKeyValData.setIsDraft((getMessageProperties()!=null && getMessageProperties().getEnvironmentVar()!=null && !getMessageProperties().getEnvironmentVar().equalsIgnoreCase(ENVIORNMENT_PROD))?true:false);
messageRecipients.setMessageKeyValueData(messageKeyValData);
MessageEml message = new MessageEml();
String templId = actualJSON.getString(TMPL_ID);
String chnlType = actualJSON.getString(CHNL_TYPE);
String msgFormat = jsonPayload.getJSONObject(MSG_ATTRIBUTE)
.get(MSG_FORMAT).toString();
message.setTemplateId(
templId + UNDER_SCORE + chnlType + UNDER_SCORE + msgFormat);
message.setUseDraftTemplate((getMessageProperties()!=null && getMessageProperties().getEnvironmentVar()!=null && !getMessageProperties().getEnvironmentVar().equalsIgnoreCase(ENVIORNMENT_PROD))?true:false);
MessageRecipients[] messageRecipientsAry = new MessageRecipients[1];
messageRecipientsAry[0] = messageRecipients;
String substitutionKeyValueData = jsonPayload
.getJSONObject(MSG_CONTENT).get(TMPL_CONTENT).toString();
JSONObject substitutionKeyValueDataObj = new JSONObject(
substitutionKeyValueData);
emailReq.setMessageRecipients(messageRecipientsAry);
emailReq.setMessage(message);
emailReq.setSubstitutionKeyValueData(substitutionKeyValueDataObj);
}
return emailReq;
}
JSONObject jsonData=newjsonobject(payload.getPayload());
字节[]msgCont=转换MSGContToBytes(jsonData);
字符串emailRequest=newjsonobject(
generateEMailRequest(有效负载、实际记录))
.toString();
结果=MessageBuilder.withPayload(emailRequest)
.copyHeaders(payload.getHeaders())
.setHeader(消息文本,msgCont).build();
专用字节[]转换MSGContToBytes(JSONObject jsonData)
抛出EmailSMSProcessorException{
字节[]msgCont=null;
if(null!=jsonData){
试一试{
msgCont=jsonData.getJSONObject(MSG_CONTENT.toString())
.getBytes(UTF_8);
}捕获(不支持的编码异常e){
LOGGER.error(“将消息内容转换为字节[]时出错”,e);
抛出新的EmailsProcessorException(e);
}捕获(JSONException e){
LOGGER.error(“将消息内容转换为字节[]时出错”,e);
抛出新的EmailsProcessorException(e);
}
}
返回msgCont;
}
私有void validatePayload(消息负载、字符串实际记录)
抛出EmailSMSProcessorException{
如果(空!=实际记录){
JSONObject jsonData=null;
试一试{
jsonData=新的JSONObject(payload.getPayload());
}捕获(例外e){
抛出新的EmailsProcessorException(
“有效载荷/强制数据丢失”,CONST_SYS_EXPTN);
}
validateErrorIdText(jsonData);
}否则{
抛出新的EmailsProcessorException(
“有效载荷/强制数据丢失”,CONST_SYS_EXPTN);
}
}
专用EmailRequest generateEMailRequest(邮件有效负载,
字符串实际记录)引发EmailSMSProcessorException{
EmailRequest emailReq=null;
如果(空!=实际记录){
JSONObject jsonPayload=新的JSONObject(payload.getPayload());
JSONObject actualJSON=新的JSONObject(actualRecord);
emailReq=新的EmailRequest();
MessageRecipients MessageRecipients=新的MessageRecipients();
if(jsonPayload.has(MSG_内容)){
JSONObject msgCntJson=jsonPayload.getJSONObject(MSG_CONTENT);
if(msgCntJson.has(SUBSTI_内容)){
String substitutionContent=jsonPayload
.getJSONObject(消息内容).get(子内容)
.toString();
JSONObject替换内容JSONObject=新JSONObject(
替换内容);
messageRecipients.setSubstitutionKeyValueData(
替换内容(Jsonobj);
}
}
收件人=新收件人();
recipient.setEmailAddress(isNullCheckMandatoryFields(
获取字符串(CNTCT\u PNT\u ADR\u TXT),
CNTCT_PNT_ADR_TXT);
messageRecipients.setRecipient(收件人);
MessageKeyValueData messageKeyValData=newmessagekeyvaluedata();
messageKeyValData.setAlertType(isNullCheckMandatoryFields(
getString(ALRT_TYPE_CD),ALRT_TYPE_CD);
messageKeyValData.setAlertTrackingId(isNullCheckMandatoryFields(
getString(DLVRY_ID),DLVRY_ID);
messageKeyValData.setIsDraft((getMessageProperties()!=null&&getMessageProperties().getEnvironmentVar()!=null&&getMessageProperties().getEnvironmentVar().equalsIgnoreCase(Environment_PROD))?真:假);
messageRecipients.setMessageKeyValueData(messageKeyValData);
MessageEml message=newmessageeml();
String templId=actualJSON.getString(TMPL\u ID);
字符串chnlType=actualJSON.getString(CHNL_类型);
字符串msgFormat=jsonPayload.getJSONObject(MSG_属性)
.get(MSG_格式).toString();
message.setTemplateId(
templId+UNDER_SCORE+chnlType+UNDER_SCORE+msgFormat);
message.setUseDraftTemplate((getMessageProperties()!=null&&getMessageProperties().getEnvironmentVar()!=null&&getMessageProperties().getEnvironmentVar().equalsIgnoreCase(Environment_PROD))?真:假);
MessageRecipients[]messageRecipientsAry=新的MessageRecipients[1];
messagerecipientsry[0]=messageRecipients;
字符串替换KeyValueData=jsonPayload
.getJSONObject(MSG_CONTENT).get(TMPL_CONTENT.toString();
JSONObject substitutionKeyValueDataObj=新JSONObject(
替换键值数据);
JSONObject jsonData = new JSONObject(payload.getPayload());
byte[] msgCont = convertMsgContToBytes(jsonData);
String emailRequest = new JSONObject(
generateEMailRequest(payload, actualRecord))
.toString();
result = MessageBuilder.withPayload(emailRequest)
.copyHeaders(payload.getHeaders())
.setHeader(MESSAGE_TEXT, msgCont).build();
private byte[] convertMsgContToBytes(JSONObject jsonData)
throws EmailSMSProcessorException {
byte[] msgCont = null;
if (null != jsonData) {
try {
msgCont = jsonData.getJSONObject(MSG_CONTENT).toString()
.getBytes(UTF_8);
} catch (UnsupportedEncodingException e) {
LOGGER.error("Error in converting Msg Content to Byte[]", e);
throw new EmailSMSProcessorException(e);
} catch (JSONException e) {
LOGGER.error("Error in converting Msg Content to Byte[]", e);
throw new EmailSMSProcessorException(e);
}
}
return msgCont;
}
private void validatePayload(Message<String> payload, String actualRecord)
throws EmailSMSProcessorException {
if (null != actualRecord) {
JSONObject jsonData = null;
try{
jsonData = new JSONObject(payload.getPayload());
}catch(Exception e){
throw new EmailSMSProcessorException(
"payload/mandatory data is missing",CONST_SYS_EXPTN);
}
validateErrorIdText(jsonData);
} else {
throw new EmailSMSProcessorException(
"payload/mandatory data is missing",CONST_SYS_EXPTN);
}
}
private EmailRequest generateEMailRequest(Message<String> payload,
String actualRecord) throws EmailSMSProcessorException {
EmailRequest emailReq = null;
if (null != actualRecord) {
JSONObject jsonPayload = new JSONObject(payload.getPayload());
JSONObject actualJSON = new JSONObject(actualRecord);
emailReq = new EmailRequest();
MessageRecipients messageRecipients = new MessageRecipients();
if (jsonPayload.has(MSG_CONTENT)) {
JSONObject msgCntJson = jsonPayload.getJSONObject(MSG_CONTENT);
if (msgCntJson.has(SUBSTI_CONTENT)) {
String substitutionContent = jsonPayload
.getJSONObject(MSG_CONTENT).get(SUBSTI_CONTENT)
.toString();
JSONObject substitutionContentJSONObj = new JSONObject(
substitutionContent);
messageRecipients.setSubstitutionKeyValueData(
substitutionContentJSONObj);
}
}
Recipient recipient = new Recipient();
recipient.setEmailAddress(isNullCheckMandatoryFields(
actualJSON.getString(CNTCT_PNT_ADR_TXT),
CNTCT_PNT_ADR_TXT));
messageRecipients.setRecipient(recipient);
MessageKeyValueData messageKeyValData = new MessageKeyValueData();
messageKeyValData.setAlertType(isNullCheckMandatoryFields(
actualJSON.getString(ALRT_TYPE_CD), ALRT_TYPE_CD));
messageKeyValData.setAlertTrackingId(isNullCheckMandatoryFields(
actualJSON.getString(DLVRY_ID), DLVRY_ID));
messageKeyValData.setIsDraft((getMessageProperties()!=null && getMessageProperties().getEnvironmentVar()!=null && !getMessageProperties().getEnvironmentVar().equalsIgnoreCase(ENVIORNMENT_PROD))?true:false);
messageRecipients.setMessageKeyValueData(messageKeyValData);
MessageEml message = new MessageEml();
String templId = actualJSON.getString(TMPL_ID);
String chnlType = actualJSON.getString(CHNL_TYPE);
String msgFormat = jsonPayload.getJSONObject(MSG_ATTRIBUTE)
.get(MSG_FORMAT).toString();
message.setTemplateId(
templId + UNDER_SCORE + chnlType + UNDER_SCORE + msgFormat);
message.setUseDraftTemplate((getMessageProperties()!=null && getMessageProperties().getEnvironmentVar()!=null && !getMessageProperties().getEnvironmentVar().equalsIgnoreCase(ENVIORNMENT_PROD))?true:false);
MessageRecipients[] messageRecipientsAry = new MessageRecipients[1];
messageRecipientsAry[0] = messageRecipients;
String substitutionKeyValueData = jsonPayload
.getJSONObject(MSG_CONTENT).get(TMPL_CONTENT).toString();
JSONObject substitutionKeyValueDataObj = new JSONObject(
substitutionKeyValueData);
emailReq.setMessageRecipients(messageRecipientsAry);
emailReq.setMessage(message);
emailReq.setSubstitutionKeyValueData(substitutionKeyValueDataObj);
}
return emailReq;
}