Authored by ping

检查不通过,不再打印异常

... ... @@ -2,6 +2,7 @@ package com.yoho.unions.common.utils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
... ... @@ -35,6 +36,20 @@ public class HttpUtils {
return httpPost(url, param, "UTF-8");
}
public static void main(String[] args) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("appid", "490655927");
map.put("udid", "12345678901123asfadsf");
map.put("apptype", "iOS");
try {
Pair<Integer, String> pair = httpPost("http://preservice.yoho.cn/union/UnionRest/activeUnion", map);
System.out.println(pair.toString());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* 发送http请求,传递参数
* @param url
... ...
... ... @@ -9,7 +9,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.fastjson.JSON;
import com.yoho.error.exception.ServiceException;
import com.yoho.service.model.union.request.ActiveUnionRequestBO;
import com.yoho.service.model.union.request.AddUnionRequestBO;
import com.yoho.service.model.union.response.ActiveUnionResponseBO;
... ... @@ -29,12 +28,20 @@ public class UnionRest {
* 添加顶当
* @param req
* @return
* @throws ServiceException
*/
@RequestMapping(value = "/addUnion")
@ResponseBody public UnionResponseBO addUnion(AddUnionRequestBO req) throws ServiceException {
@ResponseBody public UnionResponseBO addUnion(AddUnionRequestBO req) {
log.info("enter unionsRest.addunions with param is {}", req);
return dingdangService.addUnion(req);
UnionResponseBO bo = null;
try {
bo = dingdangService.addUnion(req);
} catch (Exception e) {
log.error("addunions error with param is {}", req, e);
bo = new UnionResponseBO();
bo.setIsSuccess(false);
bo.setMsg("error");
}
return bo;
}
... ... @@ -42,33 +49,31 @@ public class UnionRest {
* 激活顶当
* @param req
* @return
* @throws ServiceException
*/
@RequestMapping(value = "/activeUnion")
@ResponseBody public ActiveUnionResponseBO activeUnion(ActiveUnionRequestBO req) throws ServiceException {
@ResponseBody public ActiveUnionResponseBO activeUnion(ActiveUnionRequestBO req) {
log.info("enter unionsRest.activeunions with param is {}", req);
ActiveUnionResponseBO response = new ActiveUnionResponseBO();
try {
UnionResponseBO bo = dingdangService.activeUnion(req);
response.setCode(200);
response.setMessage("success");
response.setData(bo);
} catch (Exception e) {
log.error("", e);
if (e instanceof ServiceException) {
ServiceException ee = (ServiceException) e;
response.setCode(ee.getCode());
response.setMessage(ee.getErrorMessage());
} else {
if (!bo.getIsSuccess()) {
response.setCode(500);
response.setMessage(e.getMessage());
response.setMessage(bo.getMsg());
} else {
response.setCode(200);
response.setMessage("success");
response.setData(bo);
}
} catch (Exception e) {
log.error("", e);
response.setCode(500);
response.setMessage("error");
}
return response;
}
@RequestMapping(value = "/test")
@ResponseBody public UnionResponseBO test() throws ServiceException {
@ResponseBody public UnionResponseBO test() {
log.info("enter unionsRest.test");
UnionResponseBO response = new UnionResponseBO();
response.setMsg("success");
... ...
package com.yoho.unions.server.service;
import com.yoho.error.exception.ServiceException;
import com.yoho.service.model.union.request.ActiveUnionRequestBO;
import com.yoho.service.model.union.request.AddUnionRequestBO;
import com.yoho.service.model.union.response.UnionResponseBO;
... ... @@ -16,15 +15,15 @@ public interface DingdangService {
* 用户首次下载时,联盟调用接口
* @param request
* @return
* @throws ServiceException
* @throws Exception
*/
public UnionResponseBO addUnion(AddUnionRequestBO request) throws ServiceException;
public UnionResponseBO addUnion(AddUnionRequestBO request) throws Exception;
/**
* 联盟激活接口
* @param request
* @return
* @throws ServiceException
* @throws Exception
*/
public UnionResponseBO activeUnion(ActiveUnionRequestBO request) throws ServiceException;
public UnionResponseBO activeUnion(ActiveUnionRequestBO request) throws Exception;
}
... ...
... ... @@ -13,8 +13,6 @@ import com.alibaba.fastjson.JSONObject;
import com.netflix.config.DynamicIntProperty;
import com.netflix.config.DynamicPropertyFactory;
import com.yoho.core.cache.CacheClient;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yoho.service.model.union.request.ActiveUnionRequestBO;
import com.yoho.service.model.union.request.AddUnionRequestBO;
import com.yoho.service.model.union.response.UnionResponseBO;
... ... @@ -42,26 +40,39 @@ public class DingdangServiceImpl implements DingdangService {
private static final String unions_KEY = "unions_KEY_";
@Override
public UnionResponseBO addUnion(AddUnionRequestBO request) throws ServiceException {
public UnionResponseBO addUnion(AddUnionRequestBO request) throws Exception {
log.debug("addunions with param is {}", request);
UnionResponseBO bo = new UnionResponseBO();
if (StringUtils.isEmpty(request.getApp())) {
log.warn("addunions error app is null with param is {}", request);
throw new ServiceException(ServiceError.APP_IS_NULL);
bo.setIsSuccess(false);
bo.setMsg("APP_IS_NULL");
return bo;
// throw new ServiceException(ServiceError.APP_IS_NULL);
}
if (StringUtils.isEmpty(request.getUdid())) {
log.warn("addunions error udid is null with param is {}", request);
throw new ServiceException(ServiceError.UDID_IS_NULL);
bo.setIsSuccess(false);
bo.setMsg("UDID_IS_NULL");
return bo;
// throw new ServiceException(ServiceError.UDID_IS_NULL);
}
if (StringUtils.isEmpty(request.getCallbackurl())) {
log.warn("addunions error callbackurl is null with param is {}", request);
throw new ServiceException(ServiceError.CALLBACKURL_IS_NULL);
bo.setIsSuccess(false);
bo.setMsg("CALLBACKURL_IS_NULL");
return bo;
// throw new ServiceException(ServiceError.CALLBACKURL_IS_NULL);
}
//检查memcached中是否已经有该udid
AddUnionRequestBO cacheBO = cacheClient.get(unions_KEY + request.getApp() + "_" + request.getUdid(), AddUnionRequestBO.class);
if (cacheBO != null) {
log.warn("addunions error app and udid is added with param is {}", request);
throw new ServiceException(ServiceError.APP_UDID_IS_EXISTS);
bo.setIsSuccess(false);
bo.setMsg("APP_UDID_IS_EXISTS");
return bo;
// throw new ServiceException(ServiceError.APP_UDID_IS_EXISTS);
}
//保存到memcached,时间,一个小时
... ... @@ -82,22 +93,28 @@ public class DingdangServiceImpl implements DingdangService {
}
log.info("addunions success with param is {}", request);
addDingdang.info("addunions success with param is {}", request);
UnionResponseBO bo = new UnionResponseBO();
bo.setMsg("成功");
bo.setIsSuccess(true);
return bo;
}
@Override
public UnionResponseBO activeUnion(ActiveUnionRequestBO request) throws ServiceException {
public UnionResponseBO activeUnion(ActiveUnionRequestBO request) throws Exception {
log.debug("activeunions with param is {}", request);
UnionResponseBO bo = new UnionResponseBO();
if (StringUtils.isEmpty(request.getAppid())) {
log.warn("activeunions error app is null with param is {}", request);
throw new ServiceException(500, "APP_IS_NULL");
bo.setIsSuccess(false);
bo.setMsg("APP_IS_NULL");
return bo;
//throw new ServiceException(500, "APP_IS_NULL");
}
if (StringUtils.isEmpty(request.getUdid())) {
log.warn("activeunions error udid is null with param is {}", request);
throw new ServiceException(500, "UDID_IS_NULL");
bo.setIsSuccess(false);
bo.setMsg("UDID_IS_NULL");
return bo;
// throw new ServiceException(500, "UDID_IS_NULL");
}
String memKey = unions_KEY + request.getAppid() + "_" + request.getUdid();
... ... @@ -106,7 +123,10 @@ public class DingdangServiceImpl implements DingdangService {
AddUnionRequestBO cacheBO = cacheClient.get(memKey, AddUnionRequestBO.class);
if (cacheBO == null) {
log.warn("activeunions error app and udid is not exists with param is {}", request);
throw new ServiceException(500, "APP_UDID_IS_NOT_EXISTS");
bo.setIsSuccess(false);
bo.setMsg("APP_UDID_IS_NOT_EXISTS");
return bo;
// throw new ServiceException(500, "APP_UDID_IS_NOT_EXISTS");
}
//检查该app和udid是否已经激活
... ... @@ -118,13 +138,19 @@ public class DingdangServiceImpl implements DingdangService {
if (u == null) {
log.warn("activeunions error app and udid is not exists with param is {}", request);
throw new ServiceException(500, "APP_UDID_IS_NOT_EXISTS");
bo.setIsSuccess(false);
bo.setMsg("APP_UDID_IS_NOT_EXISTS");
return bo;
// throw new ServiceException(500, "APP_UDID_IS_NOT_EXISTS");
}
//已经激活
if ("1".equals(u.getIsActive())) {
log.warn("activeunions error app is actived with param is {}", request);
throw new ServiceException(500, "APP_UDID_IS_ACTIVED");
bo.setIsSuccess(false);
bo.setMsg("APP_UDID_IS_ACTIVED");
return bo;
// throw new ServiceException(500, "APP_UDID_IS_ACTIVED");
}
//调用联盟激活接口
... ... @@ -152,7 +178,7 @@ public class DingdangServiceImpl implements DingdangService {
repeatCount++;
}
log.info("call " + u.getCallbackurl() + " url return message is {}", pair.getRight());
UnionResponseBO bo = new UnionResponseBO();
//更新数据库
if (isSuccess) {
unions.setIsActive("1");
... ...
... ... @@ -14,6 +14,6 @@
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="java-output-path" value="/yoho-unions-web/target/classes"/>
<property name="context-root" value="yoho-unions-web"/>
<property name="context-root" value="union"/>
</wb-module>
</project-modules>
... ...