修改服务接口应答信息的序列化处理
This commit is contained in:
@@ -18,23 +18,14 @@ import net.sf.json.JSONObject;
|
||||
import org.glassfish.jersey.media.multipart.FormDataMultiPart;
|
||||
import org.glassfish.jersey.media.multipart.file.FileDataBodyPart;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.TypeAdapter;
|
||||
import com.google.gson.internal.LinkedTreeMap;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonToken;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import com.jcraft.jsch.Logger;
|
||||
import com.nis.domain.maat.ToMaatResult;
|
||||
import com.nis.domain.maat.ToMaatResult.ResponseData;
|
||||
import com.nis.exceptions.MaatConvertException;
|
||||
import com.nis.util.httpclient.ClientUtil;
|
||||
|
||||
public class ConfigServiceUtil {
|
||||
private static Gson gson = new GsonBuilder()
|
||||
.registerTypeAdapter(new TypeToken<Map>() {}.getType(), new MapTypeAdapter())
|
||||
.registerTypeAdapter(new TypeToken<List>() {}.getType(), new MapTypeAdapter())
|
||||
.create();
|
||||
public static class MapTypeAdapter extends TypeAdapter<Object> {
|
||||
/*public static class MapTypeAdapter extends TypeAdapter<Object> {
|
||||
@Override
|
||||
public Object read(JsonReader in) throws IOException {
|
||||
JsonToken token = in.peek();
|
||||
@@ -93,7 +84,7 @@ public class ConfigServiceUtil {
|
||||
// 序列化无需实现
|
||||
}
|
||||
|
||||
}
|
||||
}*/
|
||||
/**
|
||||
* 从后台服务获取compileid,groupid,regionid
|
||||
* @param type 1是compileid,2是groupid,3是regionid
|
||||
@@ -117,11 +108,14 @@ public class ConfigServiceUtil {
|
||||
Response response= header.get();
|
||||
if( response.getStatus() == 200){
|
||||
result= response.readEntity(String.class);
|
||||
Map<String, Object> resMap = gson.fromJson(result,Map.class);
|
||||
if(!StringUtil.isEmpty(resMap)){
|
||||
Map<String, Object> dataMap = (Map<String, Object>)resMap.get("data");
|
||||
if(!StringUtil.isEmpty(dataMap)){
|
||||
list = (List<Integer>)dataMap.get("pzIdList");
|
||||
// result = "{\"status\":200,\"businessCode\":2000,\"reason\":\"数据获取操作成功\","
|
||||
// + "\"msg\":\"配置ID获取成功\",\"fromuri\":\"/galaxy/service/cfg/v1/configPzIdSources\","
|
||||
// + "\"traceCode\":\"2018052409232108368751\",\"data\":{\"sourceName\":\"CONFIG_COMPILE\",\"num\":1,\"pzIdList\":[22]}}";
|
||||
JSONObject resObject = JSONObject.fromObject(result);
|
||||
ToMaatResult bean = (ToMaatResult) JSONObject.toBean(resObject,ToMaatResult.class);
|
||||
if(!StringUtil.isEmpty(bean)){
|
||||
if(!StringUtil.isEmpty(bean.getData())){
|
||||
list = bean.getData().getPzIdList();
|
||||
}else{
|
||||
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>:"+response.readEntity(String.class));
|
||||
}
|
||||
@@ -139,8 +133,9 @@ public class ConfigServiceUtil {
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String postMaatCfg(String params) throws Exception{
|
||||
public static ToMaatResult postMaatCfg(String params) throws Exception{
|
||||
String result = null;
|
||||
ToMaatResult bean = null;
|
||||
String url = Constants.SERVICE_URL+Constants.MAAT_CFG;
|
||||
//创建连接
|
||||
WebTarget wt = ClientUtil.getWebTarger(url);
|
||||
@@ -149,11 +144,12 @@ public class ConfigServiceUtil {
|
||||
Response response= header.post(Entity.entity(params, MediaType.APPLICATION_JSON));
|
||||
if( response.getStatus() == 200){
|
||||
result= response.readEntity(String.class);
|
||||
JSONObject resObject = JSONObject.fromObject(result);
|
||||
bean = (ToMaatResult) JSONObject.toBean(resObject,ToMaatResult.class);
|
||||
}else{
|
||||
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>:"+response.readEntity(String.class));
|
||||
}
|
||||
return result;
|
||||
|
||||
return bean;
|
||||
}
|
||||
/**
|
||||
* 回调配置提交
|
||||
@@ -161,8 +157,9 @@ public class ConfigServiceUtil {
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String postCallbackCfg(String params) throws Exception{
|
||||
public static ToMaatResult postCallbackCfg(String params) throws Exception{
|
||||
String result = null;
|
||||
ToMaatResult bean = null;
|
||||
String url = Constants.SERVICE_URL+Constants.CALLBACK_CFG;
|
||||
//创建连接
|
||||
WebTarget wt = ClientUtil.getWebTarger(url);
|
||||
@@ -171,10 +168,12 @@ public class ConfigServiceUtil {
|
||||
Response response= header.post(Entity.entity(params, MediaType.APPLICATION_JSON));
|
||||
if( response.getStatus() == 200){
|
||||
result= response.readEntity(String.class);
|
||||
JSONObject resObject = JSONObject.fromObject(result);
|
||||
bean = (ToMaatResult) JSONObject.toBean(resObject,ToMaatResult.class);
|
||||
}else{
|
||||
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>:"+response.readEntity(String.class));
|
||||
}
|
||||
return result;
|
||||
return bean;
|
||||
|
||||
}
|
||||
/**
|
||||
@@ -183,8 +182,9 @@ public class ConfigServiceUtil {
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String postFileCfg(String params,File file,JSONObject fileDesc) throws Exception{
|
||||
public static ToMaatResult postFileCfg(String params,File file,JSONObject fileDesc) throws Exception{
|
||||
String result = null;
|
||||
ToMaatResult bean = null;
|
||||
String url = Constants.SERVICE_URL+Constants.FILE_UPLOAD_CFG;
|
||||
//创建连接
|
||||
WebTarget wt = ClientUtil.getWebTarger(url);
|
||||
@@ -195,10 +195,12 @@ public class ConfigServiceUtil {
|
||||
Response response= header.post(Entity.entity(formDataMultiPart, formDataMultiPart.getMediaType()));
|
||||
if( response.getStatus() == 200){
|
||||
result= response.readEntity(String.class);
|
||||
JSONObject resObject = JSONObject.fromObject(result);
|
||||
bean = (ToMaatResult) JSONObject.toBean(resObject,ToMaatResult.class);
|
||||
}else{
|
||||
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>:"+response.readEntity(String.class));
|
||||
}
|
||||
return result;
|
||||
return bean;
|
||||
|
||||
}
|
||||
/**
|
||||
@@ -207,8 +209,9 @@ public class ConfigServiceUtil {
|
||||
* @param type,1表示maat配置取消,2表示回调配置取消
|
||||
* @return
|
||||
*/
|
||||
public static String delete(String params,Integer type){
|
||||
public static ToMaatResult delete(String params,Integer type){
|
||||
String result = null;
|
||||
ToMaatResult bean = null;
|
||||
String url = Constants.SERVICE_URL;
|
||||
if(type==1){
|
||||
url = url+Constants.MAAT_CFG;
|
||||
@@ -222,10 +225,12 @@ public class ConfigServiceUtil {
|
||||
Response response= header.delete();
|
||||
if( response.getStatus() == 200){
|
||||
result= response.readEntity(String.class);
|
||||
JSONObject resObject = JSONObject.fromObject(result);
|
||||
bean = (ToMaatResult) JSONObject.toBean(resObject,ToMaatResult.class);
|
||||
}else{
|
||||
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>:"+response.readEntity(String.class));
|
||||
}
|
||||
return result;
|
||||
return bean;
|
||||
|
||||
}
|
||||
/**
|
||||
@@ -234,8 +239,9 @@ public class ConfigServiceUtil {
|
||||
* @param type,1表示maat配置取消,2表示回调配置取消
|
||||
* @return
|
||||
*/
|
||||
public static String put(String params,Integer type){
|
||||
public static ToMaatResult put(String params,Integer type){
|
||||
String result = null;
|
||||
ToMaatResult bean = null;
|
||||
String url = Constants.SERVICE_URL;
|
||||
if(type==1){
|
||||
url = url+Constants.MAAT_CFG;
|
||||
@@ -249,10 +255,12 @@ public class ConfigServiceUtil {
|
||||
Response response= header.put(Entity.entity(params, MediaType.APPLICATION_JSON));
|
||||
if( response.getStatus() == 200){
|
||||
result= response.readEntity(String.class);
|
||||
JSONObject resObject = JSONObject.fromObject(result);
|
||||
bean = (ToMaatResult) JSONObject.toBean(resObject,ToMaatResult.class);
|
||||
}else{
|
||||
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>:"+response.readEntity(String.class));
|
||||
}
|
||||
return result;
|
||||
return bean;
|
||||
}
|
||||
/**
|
||||
* 信息获取
|
||||
@@ -260,8 +268,9 @@ public class ConfigServiceUtil {
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String getFileDigest(String params,File file,Map<String, Object> fileDesc) throws Exception{
|
||||
String result = null;
|
||||
public static ToMaatResult getFileDigest(String params,File file,Map<String, Object> fileDesc) throws Exception{
|
||||
String result = null;
|
||||
ToMaatResult bean = null;
|
||||
String url = Constants.SERVICE_URL+Constants.FILE_DIGEST_CFG;
|
||||
//创建连接
|
||||
WebTarget wt = ClientUtil.getWebTarger(url);
|
||||
@@ -272,10 +281,12 @@ public class ConfigServiceUtil {
|
||||
Response response= header.post(Entity.entity(formDataMultiPart, formDataMultiPart.getMediaType()));
|
||||
if( response.getStatus() == 200){
|
||||
result= response.readEntity(String.class);
|
||||
JSONObject resObject = JSONObject.fromObject(result);
|
||||
bean = (ToMaatResult) JSONObject.toBean(resObject,ToMaatResult.class);
|
||||
}else{
|
||||
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>:"+response.readEntity(String.class));
|
||||
}
|
||||
return result;
|
||||
return bean;
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user