This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
k18-ntcs-web-ntc/src/main/java/com/nis/util/ConfigServiceUtil.java
2018-05-21 09:46:49 +08:00

180 lines
5.2 KiB
Java

package com.nis.util;
import java.io.File;
import java.util.Map;
import javax.ws.rs.client.Invocation.Builder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.glassfish.jersey.media.multipart.FormDataMultiPart;
import org.glassfish.jersey.media.multipart.file.FileDataBodyPart;
import com.nis.util.httpclient.ClientUtil;
public class ConfigServiceUtil {
/**
* 从后台服务获取compileid,groupid,regionid
* @param type 1是compileid,2是groupid,3是regionid
* @return
*/
public static String getId(int type,int num) throws Exception {
String result = null;
String url = "";
if (type == 1) {
url = Constants.SERVICE_URL+Constants.CONFIG_ID_SOURCES+"?sourceName=CONFIG_COMPILE&num="+num;
} else if (type == 2) {
url = Constants.SERVICE_URL+Constants.CONFIG_ID_SOURCES+"?sourceName=CONFIG_GROUP&num="+num;
} else if (type == 3) {
url = Constants.SERVICE_URL+Constants.CONFIG_ID_SOURCES+"?sourceName=CONFIG_REGION&num="+num;
}
//创建连接
WebTarget wt = ClientUtil.getWebTarger(url);
//获取响应结果
Builder header = wt.request(MediaType.APPLICATION_JSON).header("Content-Type", MediaType.APPLICATION_JSON);
Response response= header.get();
if( response.getStatus() == 200){
result= response.readEntity(String.class);
}
if(result == null){
return "0";
}else{
return result;
}
}
/**
* MAAT配置提交
* @param params
* @return
* @throws Exception
*/
public static String postMaatCfg(String params) throws Exception{
String result = null;
String url = Constants.SERVICE_URL+Constants.MAAT_CFG;
//创建连接
WebTarget wt = ClientUtil.getWebTarger(url);
//获取响应结果
Builder header = wt.request(MediaType.APPLICATION_JSON).header("Content-Type", MediaType.APPLICATION_JSON);
Response response= header.get();
if( response.getStatus() == 200){
result= response.readEntity(String.class);
}else{
}
return result;
}
/**
* 回调配置提交
* @param params
* @return
* @throws Exception
*/
public static String postCallbackCfg(String params) throws Exception{
String result = null;
String url = Constants.SERVICE_URL+Constants.CALLBACK_CFG;
//创建连接
WebTarget wt = ClientUtil.getWebTarger(url);
//获取响应结果
Builder header = wt.request(MediaType.APPLICATION_JSON).header("Content-Type", MediaType.APPLICATION_JSON);
Response response= header.get();
if( response.getStatus() == 200){
result= response.readEntity(String.class);
}else{
}
return result;
}
/**
* 文件配置提交
* @param params
* @return
* @throws Exception
*/
public static String postFileCfg(String params,File file,Map<String, Object> fileDesc) throws Exception{
String result = null;
String url = Constants.SERVICE_URL+Constants.FILE_UPLOAD_CFG;
//创建连接
WebTarget wt = ClientUtil.getWebTarger(url);
FormDataMultiPart formDataMultiPart=new FormDataMultiPart();
FileDataBodyPart bodyPart=new FileDataBodyPart("file",file);
formDataMultiPart.bodyPart(bodyPart);
Builder header = wt.request(MediaType.APPLICATION_JSON).header("File-Desc",ClientUtil.formatFileDesc(fileDesc) );
Response response= header.post(Entity.entity(formDataMultiPart, formDataMultiPart.getMediaType()));
if( response.getStatus() == 200){
result= response.readEntity(String.class);
}else{
}
return result;
}
/**
* 配置删除
* @param params
* @return
*/
public static String delete(String params){
String result = "";
return result;
}
/**
* 配置文件上传
* @param params
* @return
*/
public static String put(String params){
String result = "";
return result;
}
/**
* 信息获取
* @param params
* @return
* @throws Exception
*/
public static String getFileDigest(String params,File file,Map<String, Object> fileDesc) throws Exception{
String result = null;
String url = Constants.SERVICE_URL+Constants.FILE_DIGEST_CFG;
//创建连接
WebTarget wt = ClientUtil.getWebTarger(url);
FormDataMultiPart formDataMultiPart=new FormDataMultiPart();
FileDataBodyPart bodyPart=new FileDataBodyPart("file",file);
formDataMultiPart.bodyPart(bodyPart);
Builder header = wt.request(MediaType.APPLICATION_JSON).header("File-Desc",ClientUtil.formatFileDesc(fileDesc) );
Response response= header.post(Entity.entity(formDataMultiPart, formDataMultiPart.getMediaType()));
if( response.getStatus() == 200){
result= response.readEntity(String.class);
}else{
}
return result;
}
public static void main(String[] args) {
try {
//创建连接
WebTarget wt = ClientUtil.getWebTarger("http://10.0.6.30:8080/maatRest/service/cfg/v1/getCompileId?sourceName=CONFIG_COMPILE&num=1");
//获取响应结果
Builder header = wt.request(MediaType.APPLICATION_JSON).header("Content-Type", MediaType.APPLICATION_JSON);
Response response= header.get();
if( response.getStatus() == 200){
String result= response.readEntity(String.class);
}else{
}
} catch (Exception e) {
e.printStackTrace();
}
}
}