AXIS2 开发示例

实体类:

package com.mport.entity;

import javax.persistence.Entity;
import javax.persistence.Table;

@Entity
@Table(name = "comic_classify")
public class ComicClassify extends ClassifyBase {

	private static final long serialVersionUID = -6295918636095140391L;

}

 

package abeop.service.bean;

public class SubInfo implements java.io.Serializable {

	private static final long serialVersionUID = -8961532006519378167L;

	private java.lang.String accessCode;

	private java.lang.String command;

	private NamedParameter[] extensionInfo;

	private java.lang.Integer isAutoExtend;

	private java.lang.String operCode;

	private int payType;

	private java.lang.String productID;

	private int subType;

	public java.lang.String getAccessCode() {
		return accessCode;
	}

	public void setAccessCode(java.lang.String accessCode) {
		this.accessCode = accessCode;
	}

	public java.lang.String getCommand() {
		return command;
	}

	public void setCommand(java.lang.String command) {
		this.command = command;
	}

	public NamedParameter[] getExtensionInfo() {
		return extensionInfo;
	}

	public void setExtensionInfo(NamedParameter[] extensionInfo) {
		this.extensionInfo = extensionInfo;
	}

	public java.lang.Integer getIsAutoExtend() {
		return isAutoExtend;
	}

	public void setIsAutoExtend(java.lang.Integer isAutoExtend) {
		this.isAutoExtend = isAutoExtend;
	}

	public java.lang.String getOperCode() {
		return operCode;
	}

	public void setOperCode(java.lang.String operCode) {
		this.operCode = operCode;
	}

	public int getPayType() {
		return payType;
	}

	public void setPayType(int payType) {
		this.payType = payType;
	}

	public java.lang.String getProductID() {
		return productID;
	}

	public void setProductID(java.lang.String productID) {
		this.productID = productID;
	}

	public int getSubType() {
		return subType;
	}

	public void setSubType(int subType) {
		this.subType = subType;
	}

}

 

package abeop.service.bean;

public class NamedParameter implements java.io.Serializable {

	private static final long serialVersionUID = -9076491524279015792L;

	private java.lang.String key;

	private java.lang.String value;

	public java.lang.String getKey() {
		return key;
	}

	public void setKey(java.lang.String key) {
		this.key = key;
	}

	public java.lang.String getValue() {
		return value;
	}

	public void setValue(java.lang.String value) {
		this.value = value;
	}
}

 获取spring bean 的工具类:

package com.mport.common;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class ApplicationContextUtils implements ApplicationContextAware {

	private static ApplicationContext context = null;

	public void setApplicationContext(ApplicationContext context) throws BeansException {
		this.context = context;
	}

	public static ApplicationContext getContext() {
		return context;
	}

}

配置到spring.xml中:

<bean class="com.mport.common.ApplicationContextUtils"/>

 WEB SERVICE接口代码:

package abeop.service;

import java.util.HashMap;
import java.util.Map;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebParam.Mode;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.xml.bind.annotation.XmlSeeAlso;

import net.sf.json.JSONSerializer;

import org.apache.commons.lang.StringUtils;

import abeop.service.bean.NamedParameter;
import abeop.service.bean.SeriesType;
import abeop.service.bean.SubInfo;
import abeop.service.req.AbstractRequest;
import abeop.service.req.GenerateUrlListRequest;
import abeop.service.req.GetClassifyListRequest;
import abeop.service.req.GetOpusListRequest;
import abeop.service.req.SubscribeHistoryRequest;
import abeop.service.req.SubscribeProductRequest;
import abeop.service.req.UnsubscribeProductRequest;
import abeop.service.req.ViewChapterDetailRequest;
import abeop.service.req.ViewOpusDetailRequest;
import abeop.service.rsp.GenerateUrlListResponse;
import abeop.service.rsp.GetClassifyListResponse;
import abeop.service.rsp.GetOpusListResponse;
import abeop.service.rsp.SubscribeHistoryResponse;
import abeop.service.rsp.SubscribeProductResponse;
import abeop.service.rsp.UnsubscribeProductResponse;
import abeop.service.rsp.ViewChapterDetailResponse;
import abeop.service.rsp.ViewOpusDetailResponse;

import com.huawei.portalone.storefront.service.bean.UserID;
import com.huawei.portalone.storefront.service.response.AuthSubscriptionRsp;
import com.mport.common.ApplicationContextUtils;
import com.mport.common.ServiceInterfaceUtils;
import com.mport.entity.ComicClassify;
import com.mport.service.ComicClassifyService;
import com.mport.service.LoggerService;

/**
 * 接口入口
 * 
 * @author lzq
 * 
 */
@WebService(name = "portalService", serviceName = "PortalService", targetNamespace = "http://abeop/service")
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT, use = SOAPBinding.Use.LITERAL, parameterStyle = SOAPBinding.ParameterStyle.BARE)
@XmlSeeAlso({ ComicClassify.class, SubInfo.class, NamedParameter.class })
public class PortalService {

	private ComicClassifyService comicClassifyService;
	private LoggerService loggerService;
	private boolean toLog = false;

	public PortalService() {
		init();
	}

	private synchronized void init() {
		if (comicClassifyService == null) {
			comicClassifyService = (com.mport.service.ComicClassifyService) ApplicationContextUtils.getContext().getBean("comicClassifyService");
		}
		if (loggerService == null) {
			loggerService = (com.mport.service.LoggerService) ApplicationContextUtils.getContext().getBean("loggerService");
		}

	}

	/**
	 * 取得分类列表
	 * 
	 * @param req
	 * @return
	 */
	@WebMethod(operationName = "getClassifyList", action = "urn:getClassifyList")
	@WebResult(name = "GetClassifyListResponse", targetNamespace = "http://abeop/service/rsp")
	public GetClassifyListResponse getClassifyList(@WebParam(mode = Mode.IN, targetNamespace = "http://abeop/service/req") GetClassifyListRequest req) {
		GetClassifyListResponse rsp = new GetClassifyListResponse();
		if (CheckParams.checkSeriesTypeParam(req, rsp) & CheckParams.checkPageParam(req, rsp)) {
			SeriesType seriesType = SeriesType.valueOf(req.getSeriesType().toUpperCase());
			switch (seriesType) {
			case COMIC:
				rsp.setClassifyList(comicClassifyService.getComicClassifyList((req.getPageNum() - 1) * req.getPageSize(), req.getPageSize()));
				break;
			default:
				break;
			}
		}
		return rsp;
	}

	/**
	 * 取得作品列表
	 * 
	 * @param req
	 * @return
	 */
	public GetOpusListResponse getOpusList(GetOpusListRequest req) {

		return null;
	}

	/**
	 * 取得作品详情
	 * 
	 * @param req
	 * @return
	 */
	public ViewOpusDetailResponse viewOpusDetail(ViewOpusDetailRequest req) {
		return null;
	}

	/**
	 * 查看章节详情
	 * 
	 * @param req
	 * @return
	 */
	public ViewChapterDetailResponse viewChapterDetail(ViewChapterDetailRequest req) {

		return null;
	}

	/**
	 * 订购产品
	 * 
	 * @param req
	 * @return
	 */
	@WebMethod(operationName = "subscribeProduct", action = "urn:subscribeProduct")
	@WebResult(name = "SubscribeProductResponse", targetNamespace = "http://abeop/service/rsp")
	public SubscribeProductResponse subscribeProduct(@WebParam(mode = Mode.IN, targetNamespace = "http://abeop/service/req") SubscribeProductRequest req) {
		UserID userID = new UserID();
		userID.setID(req.getPhoneNum());
		userID.setType(req.getUserType());
		try {
			AuthSubscriptionRsp rsp = ServiceInterfaceUtils.authSubscription(loggerService, toLog, recLog(req), req.getContentCode(), req.getObjectType(), userID, req.getLang(), 1);
			System.out.println(JSONSerializer.toJSON(rsp).toString(2));

		} catch (Exception e) {
			e.printStackTrace();
		}

		// SubscribeProductRsp rsp = ServiceInterfaceUtils.subscribeProduct(loggerService, toLog, columnAndValuesPart, userID, subInfoArray, 1);

		return null;
	}

	/**
	 * 退购产品
	 * 
	 * @param req
	 * @return
	 */
	public UnsubscribeProductResponse unsubscribeProduct(UnsubscribeProductRequest req) {

		return null;
	}

	/**
	 * 订购历史
	 * 
	 * @param req
	 * @return
	 */
	public SubscribeHistoryResponse subscribeHistory(SubscribeHistoryRequest req) {

		return null;
	}

	/**
	 * 生成地址
	 * 
	 * @param req
	 * @return
	 */
	public GenerateUrlListResponse generateUrlList(GenerateUrlListRequest req) {

		return null;
	}

	@WebMethod(exclude = true)
	public Map<String, Object> recLog(AbstractRequest req) throws Exception {
		Map<String, Object> columnAndValuesPart = new HashMap<String, Object>();
		columnAndValuesPart.put("channel_id", StringUtils.isNotBlank(req.getChid()) ? req.getChid() : null);
		columnAndValuesPart.put("ua", StringUtils.isNotBlank(req.getUa()) ? req.getUa() : null);
		columnAndValuesPart.put("plantform", StringUtils.isNotBlank(req.getP()) ? req.getP() : null);
		columnAndValuesPart.put("plantform_version", StringUtils.isNotBlank(req.getPv()) ? req.getPv() : null);
		columnAndValuesPart.put("client_version", StringUtils.isNotBlank(req.getCv()) ? req.getCv() : null);
		return columnAndValuesPart;
	}

	public static void main(String[] args) {
		PortalService p = new PortalService();
		GetClassifyListRequest req = new GetClassifyListRequest();
		req.setSeriesType("comic");
		req.setPageNum(1);
		req.setPageSize(1);
		GetClassifyListResponse rsp = p.getClassifyList(req);
		System.out.println(JSONSerializer.toJSON(rsp).toString(2));
	}
}

 

package abeop.service;

import java.util.ResourceBundle;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;

import abeop.service.bean.SubInfo;
import abeop.service.req.ContentRequest;
import abeop.service.req.PageRequest;
import abeop.service.req.ProductRequest;
import abeop.service.req.SeriesTypeRequest;
import abeop.service.req.UserRequest;
import abeop.service.rsp.AbstractResponse;

public class CheckParams {
	private static ResourceBundle bundle;
	static {
		if (bundle == null) {
			bundle = ResourceBundle.getBundle("abeop_code");
		}
	}

	public static boolean checkPageParam(PageRequest req, AbstractResponse rsp) {
		boolean bool = false;
		if (req.getPageNum() == null || req.getPageNum() <= 0) {
			rsp.setResultCode(NumberUtils.toInt(bundle.getString("code_page_num")));
			rsp.setResultMsg(bundle.getString("msg_page_num"));
		} else if (req.getPageSize() == null || req.getPageSize() <= 0) {
			rsp.setResultCode(NumberUtils.toInt(bundle.getString("code_page_size")));
			rsp.setResultMsg(bundle.getString("msg_page_size"));
		} else {
			bool = true;
		}
		return bool;
	}

	/**
	 * 检查动漫画分类
	 * 
	 * @param req
	 * @param rsp
	 * @return
	 */
	public static boolean checkSeriesTypeParam(SeriesTypeRequest req, AbstractResponse rsp) {
		boolean bool = false;
		if (StringUtils.isBlank(req.getSeriesType())) {
			rsp.setResultCode(NumberUtils.toInt(bundle.getString("code_series_type")));
			rsp.setResultMsg(bundle.getString("msg_series_type"));
		} else {
			bool = true;
		}
		return bool;
	}

	/**
	 * 检查手机号码
	 * 
	 * @param req
	 * @param rsp
	 * @return
	 */
	public static boolean checkPhoneNumParam(UserRequest req, AbstractResponse rsp) {
		boolean bool = false;
		if (StringUtils.isBlank(req.getPhoneNum())) {
			rsp.setResultCode(NumberUtils.toInt(bundle.getString("code_phone_num")));
			rsp.setResultMsg(bundle.getString("msg_phone_num"));
		} else {
			bool = true;
		}
		return bool;
	}

	/**
	 * 检查用户类型
	 * 
	 * @param req
	 * @param rsp
	 * @return
	 */
	public static boolean checkUserTypeParam(UserRequest req, AbstractResponse rsp) {
		boolean bool = false;
		if (req.getUserType() <= 0) {
			rsp.setResultCode(NumberUtils.toInt(bundle.getString("code_user_type")));
			rsp.setResultMsg(bundle.getString("msg_user_type"));
		} else {
			bool = true;
		}
		return bool;
	}

	/**
	 * 检查content_code
	 * 
	 * @param req
	 * @param rsp
	 * @return
	 */
	public static boolean checkContentCodeParam(ContentRequest req, AbstractResponse rsp) {
		boolean bool = false;
		if (StringUtils.isBlank(req.getContentCode())) {
			rsp.setResultCode(NumberUtils.toInt(bundle.getString("code_content_code_not_exists")));
			rsp.setResultMsg(bundle.getString("msg_content_code_not_exists"));
		} else {
			bool = true;
		}
		return bool;
	}

	/**
	 * 检查内容类型
	 * 
	 * @param req
	 * @param rsp
	 * @return
	 */
	public static boolean checkObjectTypeParam(ContentRequest req, AbstractResponse rsp) {
		boolean bool = false;
		if (req.getObjectType() <= 0) {
			rsp.setResultCode(NumberUtils.toInt(bundle.getString("code_object_type_not_exists")));
			rsp.setResultMsg(bundle.getString("msg_object_type_not_exists"));
		} else {
			bool = true;
		}
		return bool;
	}

	/**
	 * 检查内容类型
	 * 
	 * @param req
	 * @param rsp
	 * @return
	 */
	public static boolean checkProductCodeParam(ProductRequest req, AbstractResponse rsp) {
		boolean bool = false;
		if (checkSubInfoList(req.getSubInfoList())) {
			rsp.setResultCode(NumberUtils.toInt(bundle.getString("code_sub_info_illgal")));
			rsp.setResultMsg(bundle.getString("msg_product_code_not_exists"));
		} else {
			bool = true;
		}
		return bool;
	}

	public static boolean checkSubInfoList(SubInfo[] subInfos) {
		boolean bool = true;
		if (subInfos != null && subInfos.length > 0) {
			for (SubInfo subinfo : subInfos) {
				if (StringUtils.isBlank(subinfo.getProductID())) {
					bool = false;
				}
			}
		} else {
			bool = false;
		}
		return bool;
	}

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值