diff --git a/source/deployment/deployment-gateway/src/main/resources/config/gateway.conf b/source/deployment/deployment-gateway/src/main/resources/config/gateway.conf index 1fc0594c..66c460f0 100644 --- a/source/deployment/deployment-gateway/src/main/resources/config/gateway.conf +++ b/source/deployment/deployment-gateway/src/main/resources/config/gateway.conf @@ -20,6 +20,7 @@ peer.providers=com.jd.blockchain.consensus.bftsmart.BftsmartConsensusProvider #若该值不配置或配置不正确,则浏览器模糊查询部分无法正常显示 #数据检索服务模块(Argus)需单独部署,若不部署其他功能仍可正常使用 data.retrieval.url=http://127.0.0.1:10001 +schema.retrieval.url=http://192.168.151.39:8082 #默认公钥的内容(Base58编码数据); keys.default.pubkey= diff --git a/source/gateway/src/main/java/com/jd/blockchain/gateway/GatewayConfigProperties.java b/source/gateway/src/main/java/com/jd/blockchain/gateway/GatewayConfigProperties.java index ba16e829..5a836a41 100644 --- a/source/gateway/src/main/java/com/jd/blockchain/gateway/GatewayConfigProperties.java +++ b/source/gateway/src/main/java/com/jd/blockchain/gateway/GatewayConfigProperties.java @@ -32,6 +32,7 @@ public class GatewayConfigProperties { // 数据检索服务URL地址 public static final String DATA_RETRIEVAL_URL="data.retrieval.url"; + public static final String SCHEMA_RETRIEVAL_URL="schema.retrieval.url"; // 密钥相关配置项的键的前缀; public static final String KEYS_PREFIX = "keys."; @@ -54,6 +55,7 @@ public class GatewayConfigProperties { private NetworkAddress masterPeerAddress; private String dataRetrievalUrl; + private String schemaRetrievalUrl; private KeysConfig keys = new KeysConfig(); @@ -73,6 +75,14 @@ public class GatewayConfigProperties { this.dataRetrievalUrl = dataRetrievalUrl; } + public String getSchemaRetrievalUrl() { + return schemaRetrievalUrl; + } + + public void setSchemaRetrievalUrl(String schemaRetrievalUrl) { + this.schemaRetrievalUrl = schemaRetrievalUrl; + } + public ProviderConfig providerConfig() { return providerConfig; } @@ -120,6 +130,9 @@ public class GatewayConfigProperties { String dataRetrievalUrl = getProperty(props, DATA_RETRIEVAL_URL, true); configProps.dataRetrievalUrl = dataRetrievalUrl; + String schemaRetrievalUrl = getProperty(props, SCHEMA_RETRIEVAL_URL, true); + configProps.schemaRetrievalUrl = schemaRetrievalUrl; + String providers = getProperty(props, PEER_PROVIDERS, true); if (providers == null || providers.length() <= 0) { throw new IllegalArgumentException("Miss peer providers!"); diff --git a/source/gateway/src/main/java/com/jd/blockchain/gateway/GatewayServerBooter.java b/source/gateway/src/main/java/com/jd/blockchain/gateway/GatewayServerBooter.java index 3b9604f3..2cee0d27 100644 --- a/source/gateway/src/main/java/com/jd/blockchain/gateway/GatewayServerBooter.java +++ b/source/gateway/src/main/java/com/jd/blockchain/gateway/GatewayServerBooter.java @@ -115,6 +115,7 @@ public class GatewayServerBooter { ConsoleUtils.info("\r\n\r\nStart connecting to peer ...."); BlockBrowserController blockBrowserController = appCtx.getBean(BlockBrowserController.class); blockBrowserController.setDataRetrievalUrl(config.dataRetrievalUrl()); + blockBrowserController.setSchemaRetrievalUrl(config.getSchemaRetrievalUrl()); PeerConnector peerConnector = appCtx.getBean(PeerConnector.class); peerConnector.connect(config.masterPeerAddress(), defaultKeyPair, config.providerConfig().getProviders()); ConsoleUtils.info("Peer[%s] is connected success!", config.masterPeerAddress().toString()); diff --git a/source/gateway/src/main/java/com/jd/blockchain/gateway/service/DataRetrievalService.java b/source/gateway/src/main/java/com/jd/blockchain/gateway/service/DataRetrievalService.java index d891bf83..522f8a20 100644 --- a/source/gateway/src/main/java/com/jd/blockchain/gateway/service/DataRetrievalService.java +++ b/source/gateway/src/main/java/com/jd/blockchain/gateway/service/DataRetrievalService.java @@ -18,4 +18,5 @@ package com.jd.blockchain.gateway.service; public interface DataRetrievalService { String retrieval(String url) throws Exception; + String retrievalPost(String url, String queryString) throws Exception; } \ No newline at end of file diff --git a/source/gateway/src/main/java/com/jd/blockchain/gateway/service/DataRetrievalServiceHandler.java b/source/gateway/src/main/java/com/jd/blockchain/gateway/service/DataRetrievalServiceHandler.java index d7dd0baf..79d9ebe3 100644 --- a/source/gateway/src/main/java/com/jd/blockchain/gateway/service/DataRetrievalServiceHandler.java +++ b/source/gateway/src/main/java/com/jd/blockchain/gateway/service/DataRetrievalServiceHandler.java @@ -8,6 +8,7 @@ */ package com.jd.blockchain.gateway.service; +import com.alibaba.fastjson.JSONObject; import com.jd.blockchain.utils.http.agent.HttpClientPool; import org.springframework.stereotype.Component; @@ -24,4 +25,9 @@ public class DataRetrievalServiceHandler implements DataRetrievalService { public String retrieval(String url) throws Exception { return HttpClientPool.get(url); } + + @Override + public String retrievalPost(String url, String queryString) throws Exception { + return HttpClientPool.jsonPost(url,queryString); + } } \ No newline at end of file diff --git a/source/gateway/src/main/java/com/jd/blockchain/gateway/web/BlockBrowserController.java b/source/gateway/src/main/java/com/jd/blockchain/gateway/web/BlockBrowserController.java index 91c498aa..00884770 100644 --- a/source/gateway/src/main/java/com/jd/blockchain/gateway/web/BlockBrowserController.java +++ b/source/gateway/src/main/java/com/jd/blockchain/gateway/web/BlockBrowserController.java @@ -1,5 +1,6 @@ package com.jd.blockchain.gateway.web; +import com.alibaba.fastjson.JSONObject; import com.jd.blockchain.crypto.AddressEncoding; import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.crypto.PubKey; @@ -37,6 +38,7 @@ public class BlockBrowserController implements BlockchainExtendQueryService { private GatewayQueryService gatewayQueryService; private String dataRetrievalUrl; + private String schemaRetrievalUrl; private static final long BLOCK_MAX_DISPLAY = 3L; @@ -479,10 +481,41 @@ public class BlockBrowserController implements BlockchainExtendQueryService { return result; } + /** + * querysql; + * @param request + * @return + */ + @RequestMapping(method = RequestMethod.POST, value = "schema/querysql") + public Object queryBySql(HttpServletRequest request,@RequestBody String queryString) { + String result; + if (schemaRetrievalUrl == null || schemaRetrievalUrl.length() <= 0) { + result = "{'message':'OK','data':'" + "schema.retrieval.url is empty" + "'}"; + } else { + String queryParams = request.getQueryString() == null ? "": request.getQueryString(); + String fullQueryUrl = new StringBuffer(schemaRetrievalUrl) + .append(request.getRequestURI()) + .append(BaseConstant.DELIMETER_QUESTION) + .append(queryParams) + .toString(); + try { + result = dataRetrievalService.retrievalPost(fullQueryUrl,queryString); + ConsoleUtils.info("request = {%s} \r\n result = {%s} \r\n", fullQueryUrl, result); + } catch (Exception e) { + result = "{'message':'error','data':'" + e.getMessage() + "'}"; + } + } + return result; + } + public void setDataRetrievalUrl(String dataRetrievalUrl) { this.dataRetrievalUrl = dataRetrievalUrl; } + public void setSchemaRetrievalUrl(String schemaRetrievalUrl) { + this.schemaRetrievalUrl = schemaRetrievalUrl; + } + /** * get all ledgers count; */ diff --git a/source/gateway/src/main/resources/gateway.conf b/source/gateway/src/main/resources/gateway.conf index c0caa7c9..6b1a723e 100644 --- a/source/gateway/src/main/resources/gateway.conf +++ b/source/gateway/src/main/resources/gateway.conf @@ -19,6 +19,7 @@ peer.providers=com.jd.blockchain.consensus.bftsmart.BftsmartConsensusProvider #数据检索服务对应URL,格式:http://{ip}:{port},例如:http://127.0.0.1:10001 #若该值不配置或配置不正确,则浏览器模糊查询部分无法正常显示 data.retrieval.url=http://127.0.0.1:10001 +schema.retrieval.url=http://192.168.151.39:8082 #默认公钥的内容(Base58编码数据); keys.default.pubkey=3snPdw7i7PjVKiTH2VnXZu5H8QmNaSXpnk4ei533jFpuifyjS5zzH9 diff --git a/source/pom.xml b/source/pom.xml index 2e93f9ba..47a5d750 100644 --- a/source/pom.xml +++ b/source/pom.xml @@ -42,7 +42,7 @@ 0.8.1-SNAPSHOT 0.0.8.RELEASE - 0.7.0.RELEASE + 0.8.0-SNAPSHOT 1.0.0-SNAPSHOT 2.4 diff --git a/source/test/test-integration/src/main/resources/ledger_init_test_web2.init b/source/test/test-integration/src/main/resources/ledger_init_test_web2.init index 5d64bdb6..00fc9da1 100644 --- a/source/test/test-integration/src/main/resources/ledger_init_test_web2.init +++ b/source/test/test-integration/src/main/resources/ledger_init_test_web2.init @@ -2,7 +2,7 @@ ledger.seed=932dfe23-fe23232f-283f32fa-dd32aa76-8322ca2f-56236cda-7136b322-cb323ffe #账本的描述名称;此属性不参与共识,仅仅在当前参与方的本地节点用于描述用途; -#ledger.name= +ledger.name= #共识服务提供者;必须; consensus.service-provider=com.jd.blockchain.consensus.bftsmart.BftsmartConsensusProvider diff --git a/source/utils/utils-http/src/main/java/com/jd/blockchain/utils/http/agent/HttpClientPool.java b/source/utils/utils-http/src/main/java/com/jd/blockchain/utils/http/agent/HttpClientPool.java index 6fe29a5c..54f9842e 100644 --- a/source/utils/utils-http/src/main/java/com/jd/blockchain/utils/http/agent/HttpClientPool.java +++ b/source/utils/utils-http/src/main/java/com/jd/blockchain/utils/http/agent/HttpClientPool.java @@ -25,6 +25,7 @@ import org.apache.http.conn.socket.ConnectionSocketFactory; import org.apache.http.conn.socket.LayeredConnectionSocketFactory; import org.apache.http.conn.socket.PlainConnectionSocketFactory; import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; @@ -37,6 +38,7 @@ import java.io.IOException; import java.io.InterruptedIOException; import java.io.UnsupportedEncodingException; import java.net.UnknownHostException; +import java.nio.charset.Charset; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -267,4 +269,19 @@ public class HttpClientPool { EntityUtils.consume(entity); return result; } + + public static String jsonPost(String url, String json) throws IOException { + HttpPost httpPost = new HttpPost(url); + config(httpPost); + setJsonPostParams(httpPost, json); + try (CloseableHttpResponse response = httpPost(url, httpPost)) { + return parseResponse(response); + } + } + + private static void setJsonPostParams(HttpPost httpPost, String json) { + httpPost.addHeader("Content-type","application/json; charset=utf-8"); + httpPost.setHeader("Accept", "application/json"); + httpPost.setEntity(new StringEntity(json, Charset.forName("UTF-8"))); + } } \ No newline at end of file