java中DESKeySpec .net用什么代替
发布网友
发布时间:2022-04-27 11:59
我来回答
共1个回答
热心网友
时间:2023-05-22 06:49
/**
* AmesbHelper.java
* com.pingan.emall.util
*
* Function: TODO
*
* ver date author
* ──────────────────────────────────
* 2014-12-17 LUOHANBIN084
*
* Copyright (c) 2014, PingAn All Rights Reserved.
*/
package com.paic.toa.core.biz.util;
import java.rmi.RemoteException;
import java.text.ParseException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONObject;
import com.paic.pafa.app.biz.ac.ApplicationController;
import com.paic.pafa.app.biz.ac.ApplicationControllerException;
import com.paic.pafa.app.dto.ServiceRequest;
import com.paic.pafa.app.dto.ServiceResponse;
import com.paic.toa.core.common.ResSwitchUtil;
/**
* ClassName:AmesbHelper Function: 对每个调用外部方的amesb进行解耦
*/
public class AmesbHelper {
private static Log log = LogFactory.getLog(AmesbHelper.class);
private static long timeOut = 15 * 1000; // 15秒
private static final TimeUnit TIME_UNIT = TimeUnit.MILLISECONDS;
private static final ExecutorService POOL = new ThreadPoolExecutor(5, 20, 60, TimeUnit.SECONDS, //最大20个执行amesb
new ArrayBlockingQueue<Runnable>(1), Executors.defaultThreadFactory(), new ThreadPoolExecutor.AbortPolicy());
private final static String requestedServiceID ="dispatcherESA";
private static String operationType = "querySharelist";
/**
* send: amesb client 消息执行主方法, 同步发送当前message并等待响应结果 默认超时时间为10分钟
* @param message amesb message对象
* @return Otc amesb 返回结果, 超时时返回null
*/
public static Map send(Map requestMap, ApplicationController ac) throws CallException {
return send(requestMap, ac, timeOut, TIME_UNIT);
}
/**
* send: amesb client 消息执行主方法, 同步发送当前message并等待响应结果
*
* @param message amesb message对象
* @param timeout 超时时间
* @param timeUnit 超时时间单位
* @return Otc amesb 返回结果, 超时时返回null
* @throws TimeoutException
* @throws ExecutionException
* @throws InterruptedException
*/
public static Map send(Map requestMap, ApplicationController ac, long timeout, TimeUnit timeUnit) throws CallException {
if (requestMap == null) {
log.error("target message is null");
return null;
}
long startMills = System.currentTimeMillis();
if (!ResSwitchUtil.isOff("toasa.operationtype.change.event")){
operationType="superMoneyCashQuery";
}
String url = requestedServiceID+"|"+operationType;
log.info("start call amesb " + url);
Future<Map> future = null;
try {
future = POOL.submit(new EsbCallable(requestMap,ac));
return future.get(timeout, timeUnit);
} catch (TimeoutException e) {
future.cancel(true);
log.error("Thread timeout after " + timeout + timeUnit , e);
throw new CallException(e);
}catch(Exception e){
if(future != null){
future.cancel(true);
}
log.error("end call amesb " + url + ", use time " + (System.currentTimeMillis()-startMills), e);
throw new CallException(e);
}finally{
log.info("end call amesb " + url + ", use time " + (System.currentTimeMillis()-startMills));
}
}
/**
*
* 设置超时时间
*/
public static void setTimeOut(long timeOut) {
AmesbHelper.timeOut = timeOut;
}
public static class CallException extends RuntimeException {
private static final long serialVersionUID = -1305988804021493057L;
public CallException() {
super();
}
public CallException(String message) {
super(message);
}
public CallException(Throwable cause) {
super(cause);
}
public CallException(String message, Throwable cause) {
super(message, cause);
}
}
private static final class EsbCallable implements Callable<Map> {
private Map requestMap;
private ApplicationController ac;
public EsbCallable(Map requestMap, ApplicationController ac) {
this.requestMap = requestMap;
this.ac = ac;
}
public Map call() throws ApplicationControllerException, RemoteException, ParseException {
ServiceRequest serviceRequest1 = new ServiceRequest();
if (!ResSwitchUtil.isOff("toasa.operationtype.change.event")){
operationType="superMoneyCashQuery";
}
serviceRequest1.setParameter("operationType", operationType);
serviceRequest1.setParameter("param",requestMap);
serviceRequest1.setRequestedServiceID(requestedServiceID);
Map resultMap1 = null;
ServiceResponse serviceResponse1 = null;
Map resultMap = new HashMap();
serviceResponse1 = ac.handleRequest(serviceRequest1);
resultMap1 = serviceResponse1.getModel();
log.info("IdNo:"+requestMap.get("FUNDLOGINNUMBER") +"调用接口获取一账通宝数据返回状态码:" +resultMap1.get("resultCode"));
if("00".equals(resultMap1.get("resultCode"))){
JSONObject jsonObj=new JSONObject((String)resultMap1.get("resultBusinessData"));
JSONObject accountDetail=jsonObj.getJSONObject("accountDetail");
resultMap.put("currentremainshare", String.valueOf(accountDetail.get("currentremainshare")));
resultMap.put("dayincome", String.valueOf(accountDetail.get("dayincome")));
JSONObject fundIncomeDetail=jsonObj.getJSONObject("fundIncomeDetail");
resultMap.put("incomeratio", String.valueOf(fundIncomeDetail.get("incomeratio")));
}
return resultMap;
}
}
}