parent
d07a4457bb
commit
5a7bb65c0b
@ -0,0 +1,14 @@
|
||||
package com.platform.http;
|
||||
|
||||
/** http请求常量
|
||||
* @author chen
|
||||
*
|
||||
*/
|
||||
public class HttpClientConstant {
|
||||
|
||||
/**
|
||||
* gfs的 web 服务的 IP、端口
|
||||
*/
|
||||
public static String URL_IP_PORT = "http://192.168.0.110:9001/";
|
||||
|
||||
}
|
||||
@ -1,7 +0,0 @@
|
||||
package com.platform.http.gfs;
|
||||
|
||||
public class HttpClientConstant {
|
||||
|
||||
public static String URL_IP_PORT = "http://192.168.0.110:8088/jfinal/";
|
||||
|
||||
}
|
||||
@ -1,90 +0,0 @@
|
||||
package com.platform.http.gfs;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.sf.json.JSONObject;
|
||||
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.platform.controller.DataModelController;
|
||||
import com.platform.utils.Bean2MapUtils;
|
||||
import com.platform.utils.Configs;
|
||||
|
||||
public class HttpUtils {
|
||||
|
||||
public static Logger log = Configs.DAILY_ROLLING_LOGGER.getLogger(HttpUtils.class);
|
||||
|
||||
public String sendPost(String subUrl, Object data) {
|
||||
String resultStr = "";
|
||||
HttpClient client = new DefaultHttpClient();
|
||||
HttpPost post = new HttpPost(HttpClientConstant.URL_IP_PORT + subUrl);
|
||||
try {
|
||||
// 传参
|
||||
List<NameValuePair> parameters = new ArrayList<NameValuePair>();
|
||||
|
||||
if (null != data) {
|
||||
// 转 map
|
||||
Map<String, Object> map = Bean2MapUtils.convertBean(data);
|
||||
// 转json
|
||||
JSONObject jsondata = JSONObject.fromObject(map);
|
||||
// 封装数据
|
||||
parameters.add(new BasicNameValuePair("jsondata", jsondata
|
||||
.toString()));
|
||||
parameters.add(new BasicNameValuePair("type", data.getClass()
|
||||
.getName()));
|
||||
// 传参 放入 url的 form中
|
||||
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(parameters,
|
||||
"UTF-8");
|
||||
post.setEntity(entity);
|
||||
}
|
||||
|
||||
// 发送
|
||||
HttpResponse respone = client.execute(post);
|
||||
HttpEntity result = respone.getEntity();
|
||||
if (null != result) {
|
||||
resultStr = EntityUtils.toString(result);
|
||||
}
|
||||
// resultMap = Bean2MapUtils.convertBean(result);
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
return resultStr;
|
||||
}
|
||||
|
||||
// public static void main(String[] args) {
|
||||
// Date d = new Date();
|
||||
// HttpUtils ht = new HttpUtils();
|
||||
// BaseForm1 bas = new BaseForm1();
|
||||
// bas.setId("12");
|
||||
// bas.setName("n12");
|
||||
// String rest = ht.sendPost("gfs/getAllvolume", null);
|
||||
// if (null != rest) {
|
||||
// System.out.println(rest);
|
||||
// JSONArray jsondata = JSONArray.fromObject(rest);
|
||||
// ArrayList<VolumeEntity> fo = (ArrayList<VolumeEntity>) JSONArray.toCollection(jsondata, VolumeEntity.class);
|
||||
// System.err.println(fo);
|
||||
// try {
|
||||
// System.err.println(Bean2MapUtils.convertBean(fo));
|
||||
// } catch (IllegalAccessException | InvocationTargetException
|
||||
// | IntrospectionException e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// Date r = new Date();
|
||||
// System.err.println(r.getTime() - d.getTime());
|
||||
// }
|
||||
|
||||
}
|
||||
@ -0,0 +1,84 @@
|
||||
package com.platform.http.gfs;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.base.MyException;
|
||||
import com.base.PostData;
|
||||
import com.google.gson.Gson;
|
||||
import com.platform.http.HttpUtils;
|
||||
|
||||
/** 迁移数据
|
||||
* @author chen
|
||||
*
|
||||
*/
|
||||
public class RemoveData {
|
||||
|
||||
public static Logger log = Logger.getLogger ( RemoveData.class);
|
||||
HttpUtils ht = new HttpUtils();
|
||||
|
||||
/**
|
||||
* -1 :error; 0: the filename is not exists ; 1: right
|
||||
* @param folderName
|
||||
* @param fileName
|
||||
* @return
|
||||
*/
|
||||
public int deleteFolder(String folderName) throws Exception{
|
||||
int reslut = 0;
|
||||
log.info("start delete "+folderName);
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("removePath", folderName);
|
||||
//请求 web sendPost
|
||||
String rest = ht.sendPost("data/removeData", map);
|
||||
if (null == rest || "".equals(rest)) {
|
||||
log.error(" --- gluster is disconnect ! \n");
|
||||
return 0;
|
||||
}
|
||||
Gson gs = new Gson();
|
||||
PostData data = gs.fromJson(rest, PostData.class);
|
||||
// 1 : 成功
|
||||
double copyResult = (double) data.getData();
|
||||
reslut = (int) copyResult;
|
||||
getExcept(data);
|
||||
return reslut;
|
||||
}
|
||||
|
||||
public int abortcopyFolder(String sourceFolderName, String destFolderName) throws Exception{
|
||||
int reslut = 0;
|
||||
log.info(" abortcopyFolder " + sourceFolderName + " --> " + destFolderName);
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("sourcePath", sourceFolderName);
|
||||
map.put("destPath", destFolderName);
|
||||
//请求web
|
||||
String rest = ht.sendPost("data/abortCopyData", map);
|
||||
if (null == rest || "".equals(rest)) {
|
||||
log.error(" --- gluster is disconnect ! \n");
|
||||
return 0;
|
||||
}
|
||||
Gson gs = new Gson();
|
||||
PostData data = gs.fromJson(rest, PostData.class);
|
||||
// 1 : 成功
|
||||
double copyResult = (double) data.getData();
|
||||
reslut = (int) copyResult;
|
||||
getExcept(data);
|
||||
return reslut;
|
||||
}
|
||||
|
||||
/** 记录异常信息
|
||||
* @param pd
|
||||
*/
|
||||
private void getExcept(PostData pd) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for ( MyException object : pd.getExceptionsStack()) {
|
||||
sb.append(object.getMess()).append(",");
|
||||
}
|
||||
if (!"".equals(sb.toString())) {
|
||||
log.error(sb.toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue