Ejemplo n.º 1
0
    def postJsonMessage(self, jsonMessage, uri):
        httpPost = HttpPost(uri)
        httpPost.addHeader("Content-Type", "application/json")
        response = None
        try:
            httpPost.setEntity(StringEntity(jsonMessage, "UTF-8"))

            try:
                response = self.__class__.httpClient.execute(httpPost)
            except JavaException, e:
                logger.error(
                    '>>>>>>>>>>>httpClient.execute error <<<<<<<<<<<<<<<<<< ')
                raise Exception(e)

            res_code = response.getStatusLine().getStatusCode()

            if res_code != 200:
                logger.error(
                    'postJsonMessage - Error calling "%s" with content "%s"' %
                    (uri, jsonMessage))
                raise Exception(
                    'postJsonMessage - Error calling "%s" with content "%s"' %
                    (uri, jsonMessage))
FixedLoggers.MAXIMOLOGGER.info("json obj")
FixedLoggers.MAXIMOLOGGER.info(obj)

# post json to chaincode
handler = HTTPHandler()
map = HashMap()
url = "http://c1dfe6f7.ngrok.io"
map.put("URL", url + "/api/chaincode")
map.put("HTTPMETHOD", "POST")
map.put("body", jsonStr)
map.put("headers", "Content-Type: application/json")

# init HTTP Client, post JSON to blockchain server
client = DefaultHttpClient()
request = HttpPost(url + "/api/chaincode")
request.addHeader(HttpHeaders.CONTENT_TYPE, "application/json")
request.addHeader(HttpHeaders.ACCEPT, "application/json")
entity = StringEntity(jsonStr, "UTF-8")
request.setEntity(entity)
response = client.execute(request)
status = response.getStatusLine().getStatusCode()

# location = mboSet.getString("LOCATION")
# FixedLoggers.MAXIMOLOGGER.info(location)

# site = mbo.getString("SITE")
# FixedLoggers.MAXIMOLOGGER.info(site)

# using WO 1393