use of org.frameworkset.elasticsearch.handler.ESStringResponseHandler in project bboss-elastic by bbossgroups.
the class ESTest method testConfig.
@Test
public void testConfig() throws ParseException {
ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("estrace/ESTracesMapper.xml");
TraceExtraCriteria traceExtraCriteria = new TraceExtraCriteria();
traceExtraCriteria.setApplication("testweb1");
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
traceExtraCriteria.setStartTime(dateFormat.parse("2017-09-02 00:00:00").getTime());
traceExtraCriteria.setEndTime(dateFormat.parse("2017-09-10 00:00:00").getTime());
String data = clientUtil.executeRequest("trace-*/_search", "queryPeriodsTopN", traceExtraCriteria, new ESStringResponseHandler());
System.out.println("------------------------------");
System.out.println(data);
System.out.println("------------------------------");
Map<String, Object> response = clientUtil.executeRequest("trace-*/_search", "queryPeriodsTopN", traceExtraCriteria, new ESMapResponseHandler());
if (response.containsKey("error")) {
return;
}
}
use of org.frameworkset.elasticsearch.handler.ESStringResponseHandler in project bboss-elastic by bbossgroups.
the class ESTest method testSearh.
@Test
public void testSearh() throws ParseException {
ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("org/frameworkset/elasticsearch/ESTracesMapper.xml");
TraceExtraCriteria traceExtraCriteria = new TraceExtraCriteria();
traceExtraCriteria.setApplication("testweb1");
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
traceExtraCriteria.setStartTime(dateFormat.parse("2017-09-02 00:00:00").getTime());
traceExtraCriteria.setEndTime(dateFormat.parse("2017-09-10 00:00:00").getTime());
String data = clientUtil.executeRequest("trace-*/_search", "queryPeriodsTopN", traceExtraCriteria, new ESStringResponseHandler());
System.out.println("------------------------------");
System.out.println(data);
System.out.println("------------------------------");
Map<String, Object> response = clientUtil.executeRequest("trace-*/_search", "queryPeriodsTopN", traceExtraCriteria, new ESMapResponseHandler());
if (response.containsKey("error")) {
return;
}
}
use of org.frameworkset.elasticsearch.handler.ESStringResponseHandler in project bboss-elastic by bbossgroups.
the class ESTest method testSearhHits.
@Test
public void testSearhHits() throws ParseException {
ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("org/frameworkset/elasticsearch/ESTracesMapper.xml");
TraceExtraCriteria traceExtraCriteria = new TraceExtraCriteria();
traceExtraCriteria.setApplication("testweb1");
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
traceExtraCriteria.setStartTime(dateFormat.parse("2017-09-02 00:00:00").getTime());
traceExtraCriteria.setEndTime(dateFormat.parse("2017-09-10 00:00:00").getTime());
String data = clientUtil.executeRequest("trace-*/_search", "queryPeriodsTopN", traceExtraCriteria, new ESStringResponseHandler());
System.out.println("------------------------------");
System.out.println(data);
System.out.println("------------------------------");
Map<String, Object> response = clientUtil.executeRequest("trace-*/_search", "queryPeriodsTopN", traceExtraCriteria, new ESMapResponseHandler());
if (response.containsKey("error")) {
return;
}
}
use of org.frameworkset.elasticsearch.handler.ESStringResponseHandler in project bboss-elastic by bbossgroups.
the class ElasticSearchRestClient method execute.
public String execute(final String entity, String options) throws ElasticSearchException {
String endpoint = BULK_ENDPOINT;
if (options != null) {
endpoint = new StringBuilder().append(endpoint).append("?").append(options).toString();
}
final ESStringResponseHandler responseHandler = new ESStringResponseHandler();
return _executeHttp(endpoint, responseHandler, new ExecuteRequest() {
@Override
public Object execute(ESAddress host, String url, int triesCount) throws Exception {
Object response = null;
if (showTemplate) {
if (logger.isInfoEnabled()) {
logger.info("ElasticSearch http request endpoint:{},retry:{},request body:\n{}", url, triesCount, entity);
}
}
response = restSeachExecutor.execute(url, entity, responseHandler);
return response;
}
});
/**
* int triesCount = 0;
* String response = null;
* Throwable e = null;
* ESAddress host = null;
* String url = null;
*
* while (true) {
*
* try {
* host = serversList.get(failAllContinue || !this.healthCheckEnabled());
* url = new StringBuilder().append(host.getAddress()).append( "/" ).append( endpoint).toString();
*
*// response = HttpRequestUtil.sendJsonBody(httpPool,entity, url, this.headers);
* if(this.showTemplate ){
* if(logger.isInfoEnabled()) {
* logger.info("ElasticSearch http request endpoint:{},retry:{},request body:\n{}",url,triesCount,entity);
* }
*
* }
* ESStringResponseHandler responseHandler = new ESStringResponseHandler();
* response = restSeachExecutor.execute(url,entity,responseHandler);
* e = getException( responseHandler );
* break;
* }
* catch (HttpHostConnectException ex) {
* host.setStatus(1);
* e = new NoServerElasticSearchException(ex);
* if (triesCount < serversList.size() - 1) {//失败尝试下一个地址
* triesCount++;
* continue;
* } else {
* break;
* }
*
* } catch (UnknownHostException ex) {
* host.setStatus(1);
* e = new NoServerElasticSearchException(ex);
* if (triesCount < serversList.size() - 1) {//失败尝试下一个地址
* triesCount++;
* continue;
* } else {
* break;
* }
*
* }
* catch (NoRouteToHostException ex) {
* host.setStatus(1);
* e = new NoServerElasticSearchException(ex);
* if (triesCount < serversList.size() - 1) {//失败尝试下一个地址
* triesCount++;
* continue;
* } else {
* break;
* }
*
* }
* catch (NoHttpResponseException ex) {
* host.setStatus(1);
* e = new NoServerElasticSearchException(ex);
* if (triesCount < serversList.size() - 1) {//失败尝试下一个地址
* triesCount++;
* continue;
* } else {
* break;
* }
*
* }
* catch (ConnectionPoolTimeoutException ex){//连接池获取connection超时,直接抛出
*
* e = handleConnectionPoolTimeOutException( ex);
* break;
* }
* catch (ConnectTimeoutException connectTimeoutException){
* host.setStatus(1);
* e = handleConnectionTimeOutException(connectTimeoutException);
* if (triesCount < serversList.size() - 1) {//失败尝试下一个地址
* triesCount++;
* continue;
* } else {
* break;
* }
* }
*// catch (IOException ex) {
*// host.setStatus(1);
*// if (triesCount < serversList.size()) {//失败尝试下一个地址
*// triesCount++;
*// e = ex;
*// continue;
*// } else {
*// e = ex;
*// break;
*// }
*//
*// }
* catch (SocketTimeoutException ex) {
* e = handleSocketTimeoutException( ex);
* break;
* }
* catch (NoServerElasticSearchException ex){
* e = ex;
*
* break;
* }
* catch (ClientProtocolException ex){
* host.setStatus(1);
* e = ex;
* if (triesCount < serversList.size() - 1) {//失败尝试下一个地址
* triesCount++;
* continue;
* } else {
* break;
* }
* //throw new ElasticSearchException(new StringBuilder().append("Request[").append(url).append("] handle failed: must use http/https protocol port such as 9200,do not use transport such as 9300.").toString(),ex);
* }
* catch (ElasticSearchException ex) {
* e = ex;
* break;
* }
* catch (Exception ex) {
* e = ex;
* break;
* }
* catch (Throwable ex) {
* e = ex;
* break;
* }
*
* }
* if (e != null){
* if(e instanceof ElasticSearchException)
* throw (ElasticSearchException)e;
* throw new ElasticSearchException(e);
* }
* return response;
*/
}
use of org.frameworkset.elasticsearch.handler.ESStringResponseHandler in project bboss-elastic by bbossgroups.
the class ElasticSearchRestClient method executeRequest.
public String executeRequest(String path, final String entity) throws ElasticSearchException {
final ESStringResponseHandler responseHandler = new ESStringResponseHandler();
return _executeHttp(path, responseHandler, new ExecuteRequest() {
@Override
public Object execute(ESAddress host, String url, int triesCount) throws Exception {
Object response = null;
if (showTemplate) {
if (logger.isInfoEnabled()) {
if (entity != null)
logger.info("ElasticSearch http request endpoint:{},retry:{},request body:\n{}", url, triesCount, entity);
else
logger.info("ElasticSearch http request endpoint:{},retry:{}", url, triesCount);
}
}
response = restSeachExecutor.executeSimpleRequest(url, entity, responseHandler);
return response;
}
});
/**
* int triesCount = 0;
* String response = null;
* Throwable e = null;
*
* ESAddress host = null;
* String url = null;
* while (true) {
*
* try {
* host = serversList.get(!healthCheckEnabled());
* url = getPath(host.getAddress(),path);
*// if (entity == null)
*// response = HttpRequestUtil.httpPostforString(url, null, this.headers);
*// else
*// response = HttpRequestUtil.sendJsonBody(entity, url, this.headers);
* if(this.showTemplate ){
* if(logger.isInfoEnabled()) {
* if(entity != null)
* logger.info("ElasticSearch http request endpoint:{},retry:{},request body:\n{}",url,triesCount,entity);
* else
* logger.info("ElasticSearch http request endpoint:{},retry:{}",url,triesCount);
* }
* }
* ESStringResponseHandler responseHandler = new ESStringResponseHandler();
* response = this.restSeachExecutor.executeSimpleRequest(url,entity,responseHandler);
* e = getException( responseHandler );
* break;
* }
*
* catch (HttpHostConnectException ex) {
* host.setStatus(1);
* e = new NoServerElasticSearchException(ex);
* if (triesCount < serversList.size() - 1) {//失败尝试下一个地址
* triesCount++;
* continue;
* } else {
* break;
* }
*
* } catch (UnknownHostException ex) {
* host.setStatus(1);
* e = new NoServerElasticSearchException(ex);
* if (triesCount < serversList.size() - 1) {//失败尝试下一个地址
* triesCount++;
* continue;
* } else {
* break;
* }
*
* }
* catch (NoRouteToHostException ex) {
* host.setStatus(1);
* e = new NoServerElasticSearchException(ex);
* if (triesCount < serversList.size() - 1) {//失败尝试下一个地址
* triesCount++;
* continue;
* } else {
* break;
* }
*
* }
*
* catch (NoHttpResponseException ex) {
* host.setStatus(1);
* e = new NoServerElasticSearchException(ex);
* if (triesCount < serversList.size() - 1) {//失败尝试下一个地址
* triesCount++;
* continue;
* } else {
* break;
* }
*
* }
* catch (ConnectionPoolTimeoutException ex){//连接池获取connection超时,直接抛出
*
* e = handleConnectionPoolTimeOutException( ex);
* break;
* }
* catch (ConnectTimeoutException connectTimeoutException){
* host.setStatus(1);
* e = handleConnectionTimeOutException(connectTimeoutException);
* if (triesCount < serversList.size() - 1) {//失败尝试下一个地址
* triesCount++;
* continue;
* } else {
* break;
* }
* }
*// catch (IOException ex) {
*// host.setStatus(1);
*// if (triesCount < serversList.size()) {//失败尝试下一个地址
*// triesCount++;
*// e = ex;
*// continue;
*// } else {
*// e = ex;
*// break;
*// }
*//
*// }
* catch (SocketTimeoutException ex) {
* e = handleSocketTimeoutException( ex);
* break;
* }
* catch (NoServerElasticSearchException ex){
* e = ex;
* break;
* }
* catch (ClientProtocolException ex){
* host.setStatus(1);
* e = ex;
* if (triesCount < serversList.size() - 1) {//失败尝试下一个地址
* triesCount++;
* continue;
* } else {
* break;
* }
*// throw new ElasticSearchException(new StringBuilder().append("Request[").append(url).append("] handle failed: must use http/https protocol port such as 9200,do not use transport such as 9300.").toString(),ex);
* }
* catch (ElasticSearchException ex) {
* throw ex;
* }
*
* catch (Exception ex) {
* e = ex;
* break;
* }
* catch (Throwable ex) {
* e = ex;
* break;
* }
* }
* if (e != null){
* throw new ElasticSearchException(e);
* }
* return response;
*/
}
Aggregations