📄 adccaller.java
字号:
package mcm.adc.client;
import mcm.adc.ADCOption;
import mcm.adc.ADCConst.ActionCode;
import mcm.adc.ADCConst.BizCode;
import mcm.adc.ADCConst.ResultCode;
import mcm.adc.response.SSOAuthResponse;
public class ADCCaller {
/** ADC设定信息 */
ADCOption option = ADCOption.getInstance();
/** ADC的回馈信息 */
private AdcSiResponse response;
/** 访问ADC时的出错信息 */
private Throwable error;
/**
* 构造函数
*/
public ADCCaller() {
}
/**
* @return the error
*/
public Throwable getError() {
return error;
}
/**
* @return the response
*/
public AdcSiResponse getResponse() {
return response;
}
/**
* SSO鉴权
* @param token
* @return
*/
public boolean SSOAuth(String token){
//组建Request
AdcSiRequest aRequest = new AdcSiRequest();
aRequest.setBizCode(BizCode.SSO_AUTH);
aRequest.setSIAppID(option.getSICode());
aRequest.setActionCode(ActionCode.REQUEST);
String ssoMessage = "<AuthenRequest><BODY><SICode>" + option.getSICode() +"</SICode><TOKEN>" + token + "</TOKEN><ACTION>" + option.getSIActUrl() + "</ACTION></BODY></AuthenRequest>";
aRequest.setSvcCont(ssoMessage);
return sendRequest(aRequest);
}
/**
* SSO心跳
* @param token
* @return
*/
public boolean SSOHeartBeat(String token){
//组建Request
AdcSiRequest aRequest = new AdcSiRequest();
aRequest.setBizCode(BizCode.SSO_HEART);
aRequest.setSIAppID(option.getSICode());
aRequest.setActionCode(ActionCode.REQUEST);
String ssoMessage = "<PulseRequest><BODY><TOKEN>" + token + "</TOKEN></BODY></PulseRequest>";
aRequest.setSvcCont(ssoMessage);
return sendRequest(aRequest);
}
/**
* 调用ADC服务
* @param request
* @return
*/
private boolean sendRequest(AdcSiRequest request){
try{
//初始化
response = null;
error = null;
ADCInterfaceForSILocator locator = new ADCInterfaceForSILocator();
locator.setADCInterfaceForSISoapEndpointAddress(option.getADCSrvUrl());
locator.setADCInterfaceForSISoap12EndpointAddress(option.getADCSrvUrl());
ADCInterfaceForSISoap adcService = locator.getADCInterfaceForSISoap();
//System.out.println(locator.getADCInterfaceForSISoap12Address());
response = adcService.adcSiInterface(request);
return true;
}
catch(Throwable ex){
error = ex;
return false;
}
}
/**
* @param args
*/
public static void main(String[] args) throws Exception {
ADCCaller caller = new ADCCaller();
if(caller.SSOAuth("aa0b8083-9a53-44a5-8e90-ce2959c253dd")){
AdcSiResponse response = caller.getResponse();
System.out.println(response.getSvcCont());
System.out.println(response.getResultMsg());
if(ResultCode.SUCCESS.equals(response.getResultCode())){
//鉴权成功
SSOAuthResponse resInfo = new SSOAuthResponse(response.getSvcCont());
System.out.println("集团客户帐号:" + resInfo.getCORPACCOUNT());
System.out.println("用户ID:" + resInfo.getUFID());
}
else{
//鉴权失败
}
}
else{
System.out.println("访问失败!");
Throwable ex = caller.getError();
if(ex != null){
ex.printStackTrace(System.err);
}
}
if(caller.SSOHeartBeat("aa0b8083-9a53-44a5-8e90-ce2959c253dd")){
AdcSiResponse response = caller.getResponse();
if(ResultCode.SUCCESS.equals(response.getResultCode())){
//成功
}
else{
//失败
}
}
else{
System.out.println("访问失败!");
Throwable ex = caller.getError();
if(ex != null){
ex.printStackTrace(System.err);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -