Axis1.4 实例
一、调用WSRaw生成Web Service的接口,拷贝到WS工程,实现在这个类实现StationHandlerSoapBindingImpl.java(下面提到)。
?
二、WebApp部分StationClient类,调用web servie:
?
package com.abmoc.omc.web.ws;import org.apache.axis.AxisFault;import org.apache.log4j.Logger; import com.abmoc.omc.Station;import com.abmoc.omc.web.data.SystemConfigData;import com.abmoc.omc.ws.core.bean.StationEntity;import com.abmoc.omc.ws.core.service.StationHandler;import com.abmoc.omc.ws.core.service.StationHandlerServiceLocator;public class StationClient extends WSClient {private static Logger logger = Logger.getLogger(StationClient.class);private String url = SystemConfigData.wsUrl + "stationHandler";public StationEntity getStationEntity(Station st) {StationEntity station = new StationEntity();station.setCityId(st.getRegion().getCityId());station.setCityName(st.getRegion().getCity().getName());station.setRegionId(st.getRegionId());station.setRegionName(st.getRegion().getName());station.setStateId(st.getId());station.setStationName(st.getName());station.setStationNumber(st.getNumber());station.setVindicId(station.getVindicId());station.setVindicName(st.getVindic().getVindicName());station.setCrtlLevelId(station.getCrtlLevelId());station.setCrtlLevelName(st.getCrtlLevel().getName());station.setLatitude(st.getLatitude());station.setLongitude(st.getLongitude());station.setLinkmanTel(st.getLinkmanTel());station.setLinkman(st.getLinkman());station.setSpreadTypeId(st.getSpreadTypeId());station.setSpreadTypeName(st.getSpreadType().getTypeName());station.setStateId(st.getStateId());station.setStateName(st.getState().getStateName());return station;}// 添加站点public int addStationEx(String logonCredit, StationEntity station) {int result = 0;try {StationHandlerServiceLocator ssl = new StationHandlerServiceLocator();StationHandler handler = ssl.getstationHandler(new java.net.URL(url));this.setParams(logonCredit);result = handler.addStationEx(station, params);logger.info("addStation:" + station.getStationName()+ " resault=" + result);} catch (AxisFault e) {logger.error(e.getMessage(), e);logger.info("faultCode:" + e.getFaultCode());} catch (Exception e) {logger.error(e.getMessage(), e);result = 66;}return result;}// 修改站点public int modifyStationEx(String logonCredit, StationEntity newStation,StationEntity oldStation) {int result = 0;try {StationHandlerServiceLocator ssl = new StationHandlerServiceLocator();StationHandler handler = ssl.getstationHandler(new java.net.URL(url));this.setParams(logonCredit);result = handler.modifyStationEx(newStation, oldStation, params);logger.info("modifyStation:" + newStation.getStationName()+ " resault=" + result);} catch (AxisFault e) {logger.error(e.getMessage(), e);logger.info("faultCode:" + e.getFaultCode());} catch (Exception e) {logger.error(e.getMessage(), e);result = 66;}return result;}// 删除站点public int deleteStationEx(String logonCredit, StationEntity station) {int result = 0;try {StationHandlerServiceLocator ssl = new StationHandlerServiceLocator();StationHandler handler = ssl.getstationHandler(new java.net.URL(url));this.setParams(logonCredit);result = handler.deleteStationEx(station, params);logger.info("deleteStation:stationId="+ station.getStationId() + " resault=" + result);} catch (AxisFault e) {logger.error(e.getMessage(), e);logger.info("faultCode:" + e.getFaultCode());} catch (Exception e) {logger.error(e.getMessage(), e);result = 66;}return result;}}
?
?
WebApp部分StationClient类关键代码:
?
public int addStationEx(String logonCredit, StationEntity station) {int result = 0;try {StationHandlerServiceLocator ssl = new StationHandlerServiceLocator();StationHandler handler = ssl.getstationHandler(new java.net.URL(url));this.setParams(logonCredit);result = handler.addStationEx(station, params);logger.info("addStation:" + station.getStationName() + " resault=" + result);} catch (AxisFault e) {logger.error(e.getMessage(), e);logger.info("faultCode:" + e.getFaultCode());} catch (Exception e) {logger.error(e.getMessage(), e);result = 66;}return result;}
?
?
WS部分:
StationHandlerSoapBindingImpl.java
关键代码一:
?
public int addStationEx(com.abmoc.omc.ws.core.bean.StationEntity in0,com.abmoc.omc.ws.core.bean.WSParam[] in1)throws java.rmi.RemoteException,com.abmoc.omc.ws.core.exception.LogonException {// debuglogger.info("Call addStationEx() Start.");try {UserManager.getInstance().isLogon(in1);updatePinYin(in0.getStationId(), in0.getStationName());// 其他数据库操作暂时没做} catch (LogonException logonEx) {throw logonEx;} catch (Exception ex) {logger.error(ex);} finally {}// debuglogger.info("Call addStationEx() End.");return 0;}
?
关键代码二:
?
private void updatePinYin(int stationId, String stationName)throws LogonException {// debuglogger.info("Call updatePinYin() Start.");String sql = null;try {sql = "update STATION_INFO set PINYIN = :pinYin where INT_ID = :intId";List<ParamModel> paramModelList = new ArrayList<ParamModel>();paramModelList.add(new ParamModel("pinYin", _pinyinTool.createPinyinLowCase(stationName)));paramModelList.add(new ParamModel("intId", stationId));AbstractSQLHelper.updateBySql(sql, paramModelList);} catch (Exception e) {logger.error(e);LogonException logonEx = new LogonException();logonEx.setErrorCode(ConstantLogonException.DATABASE_OPERATION);logonEx.setFaultReason(ConstantLogonException.DATABASE_OPERATION+ "#" + "站点修改异常:数据库操作异常");throw logonEx;}// debuglogger.info("Call updatePinYin() End.");}