cas工作

cas4.2.7添加更多返回信息

2017-07-14  本文已影响912人  sweetMemories

服务端修改内容

修改工程

修改类

修改方法

修改内容

DataSource dataSource = ApplicationContextProvider.getApplicationContext().getBean("dataSource", DataSource.class);
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
//获取用户信息
CsUser csUser = getUserInfo(id,jdbcTemplate);
List<CsOrgan> list = null;
if(csUser!=null){
    //获取所属机构信息
    list = getOrganInfo(csUser.getUserId(),jdbcTemplate);
}
WdimInfo wdimInfo = new WdimInfo(csUser,list);
if(wdimInfo!=null){
    String wdim = null ;
    try {
        wdim = Marshal.marshal(wdimInfo);
    } catch (Exception e) {
        e.printStackTrace();
    }
    attributes.put("wdim",wdim);
}

客户端修改内容

修改工程

修改类

修改方法

修改内容

try {
    if(attributes.get("wdim")!=null){
        this.wdimInfo = (WdimInfo) Unmarshal.unmarshal(WdimInfo.class,(String)attributes.get("wdim"));
    }
} catch (Exception e) {
    this.wdimInfo = null;
    e.printStackTrace();
}

添加方法

public WdimInfo getWdimInfo() {
    return wdimInfo;
}

额外说明

Marshal

/**
 * bean 转xml
 */
public class Marshal {
    public static String marshal(Object object)throws Exception{
        String returnValue=null;
        Class<?> clazz=null;
        JAXBContext context=null;
        Marshaller marshaller=null;
        StringWriter writer=null;
        try{
            clazz=object.getClass();
            writer=new StringWriter();
            context=JAXBContext.newInstance(clazz);
            marshaller=context.createMarshaller();
            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,true);
            marshaller.setProperty(Marshaller.JAXB_FRAGMENT,true);
            marshaller.marshal(object,writer);
            returnValue=writer.toString();
        }finally{
            if(writer!=null){
                try{
                    writer.close();
                }catch(Exception e){
                }
                writer=null;
            }
        }
        return returnValue;
    }
}

Unmarshal

public class Unmarshal {
    public static Object unmarshal(Class<?> clazz, String xml)throws Exception {
        Object returnValue=null;
        JAXBContext context=null;
        StringReader reader=null;
        Unmarshaller unmarshaller=null;
        try{
            reader=new StringReader(xml);
            context= JAXBContext.newInstance(clazz);
            unmarshaller=context.createUnmarshaller();
            returnValue=unmarshaller.unmarshal(reader);
        }finally{
            if(reader!=null){
                try{
                    reader.close();
                }catch(Exception e){
                }
                reader=null;
            }
        }
        return returnValue;
    }
}
上一篇 下一篇

猜你喜欢

热点阅读