Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

193
Visualizações
Hyperledger Fabric chaincode error due to wrong javascript xml to string conversion

I currently have a fully functional chaincode developed in Java. One of the transactions involves as input a string generated from an XML document. This transformation is done in a Java app and sent to the network via Java SDK. This is an extract:

Document xmlDoc = null;
String docPath = "test.xml";
File xmlDocFile = new File(docPath);
try {
            DocumentBuilder db = dbf.newDocumentBuilder();
            xmlDoc = db.parse(xmlDocFile);
            transformer = transformerFactory.newTransformer();
            DOMSource source = new DOMSource(xmlDoc);
            StringWriter strWriter = new StringWriter();
            StreamResult stResult = new StreamResult(strWriter);
            transformer.transform(source, stResult);
            String xmlString = strWriter.getBuffer().toString();
}
catch (Exception e) {
            e.printStackTrace();
        }

The generated string is fed to the transaction, which runs smoothly. In my chaincode i reconvert the string in a document and use XPATH to make some operations.

In Hyperledger Caliper there is a need to modify the workload module written in Javascript in order to run the tests. I have included a small script that should perform the same operation done in Java:

const xml2js = require('xml2js');
const fs = require('fs');
const parser = new xml2js.Parser({ attrkey: "ATTR" });
var newXmlString = "";
// this example reads the file synchronously
// you can read it asynchronously also
let xml_string = fs.readFileSync("test.xml", "utf8");

parser.parseString(xml_string, function(error, result) {
    if(error === null) {
        //console.log(result);
        const objectToXmlString = require('object-to-xml-string');
        const obj2xml = new objectToXmlString();
        newXmlString = obj2xml.convert(result);
    }
    else {
        console.log(error);
    }
});

If i use the string generated in Javascript i obtain peer0.org1.example.com:7051:chaincode response 500, Error during contract method execution So this string doesn't allow me to start chaincode. Do you have some advice on how to load and convert the XML document in an approriate way?

about 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda