webservice 完整 实现方式 服务端 客户端 (cxf)

来源:互联网 发布:知君本无邪by尼罗txt 编辑:程序博客网 时间:2024/05/25 05:36

服务端:

package com.thunisoft.np.fy.dwjk.akxt;

import javax.jws.WebParam;
import javax.jws.WebService;

@WebService(targetNamespace = "http://service.akxt.dwjk.fy.np.thunisoft.com")
public interface ICaseForAkxtService {

    public String bgcbrInfo(@WebParam(name="queryParam") String queryParam,
            @WebParam(name="systemId") String systemId);
}


package com.thunisoft.np.fy.dwjk.akxt.impl;

import java.util.Iterator;
import java.util.List;

import javax.jws.WebParam;
import javax.jws.WebService;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.Element;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import com.thunisoft.artery.module.organ.IUser;
import com.thunisoft.artery.module.organ.util.ArteryOrganUtil;
import com.thunisoft.np.datamodel.cases.fy.base.TFySpzzcybg;
import com.thunisoft.np.fy.dwjk.akxt.ICaseForAkxtService;
import com.thunisoft.np.fy.dwjk.dao.impl.CaseInfoDao;
import com.thunisoft.np.fy.dwjk.pub.XmlParseUtils;
import com.thunisoft.summer.util.StringUtils;

@WebService(endpointInterface = "com.thunisoft.np.fy.dwjk.akxt.ICaseForAkxtService",targetNamespace = "http://service.akxt.dwjk.fy.np.thunisoft.com")
public class CaseForAkxtService implements ICaseForAkxtService {

    @Autowired
    @Qualifier("caseInfoDao")
    private CaseInfoDao caseInfoDao;
    
    private Log log = LogFactory.getLog(this.getClass());
    
    public String bgcbrInfo(@WebParam(name ="queryParam") String queryParam, @WebParam(name="systemId")  String systemId) {
        Document resultDom = XmlParseUtils.createDocument();
        Element root = resultDom.addElement("NpfyCase");
        if (StringUtils.isEmpty(queryParam)) {
            root.addAttribute("errMsg", "参数为空!");
            log.error("systemId=" + systemId + " 参数为空 ,无法查询!");
            return resultDom.asXML();
        }
        try {
            Document paramDom = XmlParseUtils.getDomFromString(queryParam);
            Element paramEle = paramDom.getRootElement();
            Attribute fyAttr = paramEle.attribute("FY");
            Attribute ajlbAttr = paramEle.attribute("AJLB");
            Attribute sljdAttr = paramEle.attribute("SLJD");
            Attribute cxrqAttr = paramEle.attribute("CXRQ");
            
            String fyStr = fyAttr.getText();
            String ajlbStr = ajlbAttr.getText();
            String sljdStr = sljdAttr.getText();
            String cxrqStr = cxrqAttr.getText();
            
            if(org.apache.commons.lang.StringUtils.isEmpty(fyStr)
                || org.apache.commons.lang.StringUtils.isEmpty(ajlbStr)
                || org.apache.commons.lang.StringUtils.isEmpty(sljdStr)
                || org.apache.commons.lang.StringUtils.isEmpty(cxrqStr)){
                log.error("systemId=" + systemId + " 参数不全");
                root.addAttribute("errMsg", "参数不全!");
                return resultDom.asXML();
            }
            int fy = Integer.valueOf(fyStr);
            int nAjlb = Integer.valueOf(ajlbStr);
            int sljd = Integer.valueOf(sljdStr);
            List<TFySpzzcybg> list= caseInfoDao.getBgcbrInfo(fy,nAjlb,sljd,cxrqStr);
            for (Iterator iterator = list.iterator(); iterator.hasNext();) {
                TFySpzzcybg tFySpzzcybg = (TFySpzzcybg) iterator.next();
                Element ajEle = root.addElement("aj");
                ajEle.addAttribute("ajbh", tFySpzzcybg.getCBhAj());
                Integer nYcy = tFySpzzcybg.getNYcr();
                Integer nXcy = tFySpzzcybg.getNXcr();
                String cYcy = String.valueOf(nYcy);
                String cXcy = String.valueOf(nXcy);
                
                IUser ycyUser = ArteryOrganUtil.getUserById(cYcy);
                String ycyDept = (ycyUser==null?null:ycyUser.getDeptId());
                IUser xcyUser = ArteryOrganUtil.getUserById(cXcy);
                String xcyDept = (xcyUser==null?null:xcyUser.getDeptId());
                ajEle.addAttribute("oldCbr",cYcy);
                ajEle.addAttribute("newCbr", cXcy);
                ajEle.addAttribute("oldCbts", ycyDept);
                ajEle.addAttribute("newCbts", xcyDept);
            }
            return resultDom.asXML();
        } catch (Exception e) {
            root.addAttribute("errMsg", "解析参数失败!");
            log.error("systemId=" + systemId + " 解析参数失败");
            return resultDom.asXML();
        }
    }
}

spring 文件:

 <bean id="caseForAkxtService" class="com.thunisoft.np.fy.dwjk.akxt.impl.CaseForAkxtService"></bean>

<!-- 案款系统接口地址-->
    <jaxws:endpoint id="CaseForAkxtService" address="/CaseForAkxtService">
        <jaxws:implementor>
            <ref bean="caseForAkxtService" />
        </jaxws:implementor>
    </jaxws:endpoint>




客户端:

    String param = "efef";
        Service service = new Service();
        try {
            Call call = (Call) service.createCall();
            String methord = "bgcbrInfo";
            call.setTargetEndpointAddress("http://172.16.192.246:8080/np-fy-dwjk/services/CaseForAkxtService");
            call.setOperationName(methord);
            call.addParameter("queryParam", //设置要传递的参数
                org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
            call.addParameter("systemId", //设置要传递的参数
                    org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
            call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
            call.setUseSOAPAction(true);
            call.setSOAPActionURI("http://service.akxt.dwjk.fy.np.thunisoft.com/bgcbrInfo");
            String result = (String) call.invoke(new Object[] { param,"fwewef" });
            logger.info("接口返回结果:" + result);
           
            
        } catch (Exception ex) {
            logger.error("调用谈话系统接口失败",ex);
        }

0 0
原创粉丝点击