use of com.creditease.uav.helpers.connfailover.ConnectionFailoverMgr in project uavstack by uavorg.
the class EsRestServletCallBack method service.
@Override
public void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// 获取请求资源
String proName = req.getServletContext().getContextPath();
String requestSource = req.getRequestURI();
requestSource = requestSource.substring(requestSource.indexOf(proName) + proName.length());
if (requestSource.startsWith("/es")) {
requestSource = requestSource.substring(3);
}
/**
* get url
*/
Map<String, ConnectionFailoverMgr> connectionMgrPool = EsResource.getConnMgr();
String forwarUrl = connectionMgrPool.get("es.info.forwar.url").getConnection() + requestSource;
/**
* get method
*/
String method = req.getMethod();
/**
* get body
*/
ServletInputStream input = req.getInputStream();
EsResource.getHttpAsyncClient().doAsyncHttpMethodWithReqAsync(method, forwarUrl, null, input, null, null, "application/json", "utf-8", new EsRestServletCallBack(), req);
}
use of com.creditease.uav.helpers.connfailover.ConnectionFailoverMgr in project uavstack by uavorg.
the class AppHubBaseRestService method doHttpPost.
/**
* 支持普通Http Post调用和智能的带FailOver的调用
*
* @param postUrl
* @param subPath
* @param data
* @param contentType
* @param encoding
* @param callBack
*/
public void doHttpPost(String serverAddress, String subPath, byte[] data, String contentType, String encoding, HttpClientCallback callBack) {
ConnectionFailoverMgr cfm = httpConnInvokeMgr.get(serverAddress);
/**
* Step 1: if there is no ConnectionFailoverMgr, take it as normal http post
*/
if (cfm == null) {
final String postURL = (subPath != null) ? (serverAddress + subPath) : serverAddress;
httpAsyncClient.doAsyncHttpPost(postURL, data, contentType, encoding, callBack);
return;
}
/**
* Step 2: do smart http post
*/
String url = cfm.getConnection();
if (url == null) {
String msg = "No Available Address for ServerAddressList[" + serverAddress + "]";
this.getLogger().warn(this, msg);
if (callBack != null) {
HttpClientCallbackResult result = new HttpClientCallbackResult(null, null);
result.setException(new HttpAsyncException(ExceptionEvent.REPLY_ERROR, new ConnectException(msg)));
callBack.failed(result);
}
return;
}
String postURL = (subPath != null) ? (url + subPath) : url;
getLogger().info(this, "doHttpPost URL :" + postURL);
PostHttpCallback postHttpCb = new PostHttpCallback();
postHttpCb.setCallBack(callBack);
postHttpCb.setCfm(cfm);
postHttpCb.setContentType(contentType);
postHttpCb.setData(data);
postHttpCb.setEncoding(encoding);
postHttpCb.setPostURL(postURL);
postHttpCb.setServerAddress(serverAddress);
postHttpCb.setSubPath(subPath);
postHttpCb.setUrl(url);
httpAsyncClient.doAsyncHttpPost(postURL, data, contentType, encoding, postHttpCb);
}
Aggregations