Skip to Content
avatar image
Former Member

Inbound - get a file into a xml (base64)

Hi experts,

I am trying get a zip file in base64 format that is into of this xml.

<?xml version="1.0" encoding="UTF-8" ?>

- empresa.com:OU030:csa-fi">

- <rset>

- <row>

<FIELD>UEsDBAoAAAAAANZzOUJ1Y8G+GwAAABsAAAAKAAAAYXR0YWNoLnR4dEluZm9ybWF6aW9uZQ0KSW5mb3JtYXppb25lMlBLAQI/AAoAAAAAANZzOUJ1Y8G+GwAAABsAAAAKACQAAAAAAAAAIAAAAAAAAABhdHRhY2gudHh0CgAgAAAAAAABABgAwHajjgj7zQHAdqOOCPvNARiqbMkQ+s0BUEsFBgAAAAABAAEAXAAAAEMAAAAAAA==</FIELD>

</row>

</rset>

</ns0:mt_csa_source>

I can get the content and I decoded it and I put into a byte array, but the logs show me this error:

Adapter Framework caught exception: Exception in XML Parser (format problem?):'org.xml.sax.SAXParseException: Character reference "&#3" is an invalid XML character.'

I tryed chand the xml version for 1.1, but this show me another error

Someone can help me?

Thanks

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Feb 02, 2013 at 09:54 AM

    Hi Devaney,

    After reading base64 content from XML and then decoding to binary (bytes) to which message structure you are passing this information? I mean, are you using graphical mapping with UDF which decodes base64 to bytes for target XML tag?

    XML parsers can not handle binary content in XML tags. So, use java/ABAP mapping to achieve your requirement.

    By the by, I can see the below content from your base64 zip content,

    Informazione

    Informazione2

    Regards,

    Praveen Gujjeti

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Praveen Gujjeti
      I implemtn the SessionBean and into the process method I call the receiver process or sender process. Into the receiver process I have this code: private Message receiveProcess(Message msg,
         MessageKey key,
         String encoding,
         String fileName,
         String fileNameKey,
         String pathDir)
         throws ModuleException {
       
        // extract payload
        byte by[] = msg.getDocument().getContent();
        byte[] newContent = null;
        XMLPayload xmlpayload = msg.getDocument();
       
        // *** Switch on encoding types *** //
        // Base64
        if (encoding.equalsIgnoreCase("base64")) {
        
         byte[] decodedBinary = null;
         String decodedText = null;
         DocumentBuilderFactory factory;
         factory = DocumentBuilderFactory.newInstance();
         DocumentBuilder builder=null;
         Document document=null;
         try {
          builder = factory.newDocumentBuilder();
          document = builder.parse(
            (InputStream) xmlpayload.getInputStream());
         } catch (ParserConfigurationException e) {
          audit.addAuditLogEntry(key, AuditLogStatus.ERROR, M_NAME
            + e.getMessage());
         } catch (SAXException e) {
          audit.addAuditLogEntry(key, AuditLogStatus.ERROR, M_NAME
            + e.getMessage());
         } catch (IOException e) {
          audit.addAuditLogEntry(key, AuditLogStatus.ERROR, M_NAME
            + e.getMessage());
         }
        
         Element root = document.getDocumentElement();
        
         Node child = root.getChildNodes().item(0);
         while (child.hasChildNodes()){
          child = child.getChildNodes().item(0);
         }
        
         /* Decode Base64 in String*/
         decodedBinary = Base64.decode(child.getNodeValue());    decodedText = new String(decodedBinary);
         audit.addAuditLogEntry(key, AuditLogStatus.SUCCESS, M_NAME
           + "This is the content "
           + decodedText);
        
         /*
         TransformerFactory tfactory = TransformerFactory.newInstance();
         Transformer transformer;
         try {
          transformer = tfactory.newTransformer();
          DOMSource src = new DOMSource(docNew);
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          StreamResult dest = new StreamResult(baos);
          transformer.transform(src, dest);
          newContent = baos.toByteArray();
         
          Result dbg =
           new StreamResult(
             new File("/usr/sap/mydirectory/tmp/Sample.zip"));
          transformer.transform(src, dbg);
         
         } catch (TransformerConfigurationException e){
          audit.addAuditLogEntry(key, AuditLogStatus.ERROR, mName
            + " " + e.getMessage());
         }catch (TransformerException e) {
          audit.addAuditLogEntry(key, AuditLogStatus.ERROR, mName
            + " " + e.getMessage());
         }
         */
        
         File f1 = new File(pathDir + File.separator + fileName);    FileOutputStream fos=null;
         try {
          fos = new FileOutputStream(f1);
          fos.write(decodedBinary);
         } catch (FileNotFoundException e) {
          audit.addAuditLogEntry(key, AuditLogStatus.ERROR, M_NAME
            + " " + e.getMessage());
         } catch (IOException e) {
          audit.addAuditLogEntry(key, AuditLogStatus.ERROR, M_NAME
            + " " + e.getMessage());
         }finally{
          try {
           fos.close();
          } catch (IOException e) {
           audit.addAuditLogEntry(key, AuditLogStatus.ERROR, M_NAME
             + e.getMessage());
          }
         }
        } else
        // Zip
         if (encoding.equalsIgnoreCase("zip")) {
          //ZIP ALL FILES AND SEND IT
         }   // Change old message content with the new one
        try {    if (newContent != null) {
          xmlpayload.setContent(newContent);
         }
         audit.addAuditLogEntry(key, AuditLogStatus.SUCCESS, M_NAME
           + "Content was correctly dencoded "
           + encoding.toLowerCase());
        } catch (Exception e) {
         ModuleException me = new ModuleException(e);
         throw me;
        }   return msg;
      } the return Message I use this way: inputModuleData.setPrincipalData(msg); The PI verison is 7.11 I don't know where I did the mistake. Thank you