Skip to Content

Unable to display tree view Error when parsing an XML (Premature end of file)

Dear All.

Scenario: File to File using java mapping in SAP PI 7.4.

we are converting a raw text file into an xml file. For this purpose, we are using Java mapping in ESR.

Case 1:

When we run the scenario in Eclipse I can get the desired output

Case 2:

ESR when I test the Java mapping in OM, we are getting the below error:

Unable to display tree view; Error when parsing an XML document (Premature end of file.)

Below is the processing log:

Loaded class com.iaatech.TredsEnvelope
Loaded class org.bouncycastle.jce.interfaces.ConfigurableProvider
Loaded class org.bouncycastle.jce.provider.BouncyCastleProvider
Call method execute of the application Java mapping com.iaatech.TredsEnvelope
Loaded class org.bouncycastle.asn1.DERTags
Loaded class org.bouncycastle.asn1.DEREncodable
Loaded class org.bouncycastle.asn1.ASN1Encodable
Loaded class org.bouncycastle.asn1.DERObject
Loaded class org.bouncycastle.asn1.ASN1Object
Loaded class org.bouncycastle.asn1.DERObjectIdentifier
Loaded class org.bouncycastle.asn1.ASN1ObjectIdentifier
Loaded class org.bouncycastle.jce.provider.BouncyCastleProvider$1
Loaded class org.bouncycastle.jce.provider.symmetric.AES$Mappings
Loaded class org.bouncycastle.asn1.nist.NISTObjectIdentifiers
Loaded class org.bouncycastle.jce.provider.symmetric.ARC4$Mappings
Loaded class org.bouncycastle.jce.provider.symmetric.Blowfish$Mappings
Loaded class org.bouncycastle.jce.provider.symmetric.Camellia$Mappings
Loaded class org.bouncycastle.asn1.ntt.NTTObjectIdentifiers
Loaded class org.bouncycastle.jce.provider.symmetric.CAST5$Mappings
Loaded class org.bouncycastle.jce.provider.symmetric.CAST6$Mappings
Loaded class org.bouncycastle.jce.provider.symmetric.DESede$Mappings
Loaded class org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers
Loaded class org.bouncycastle.asn1.oiw.OIWObjectIdentifiers
Loaded class org.bouncycastle.jce.provider.symmetric.Grainv1$Mappings
Loaded class org.bouncycastle.jce.provider.symmetric.Grain128$Mappings
Loaded class org.bouncycastle.jce.provider.symmetric.HC128$Mappings
Loaded class org.bouncycastle.jce.provider.symmetric.HC256$Mappings
Loaded class org.bouncycastle.jce.provider.symmetric.IDEA$Mappings
Loaded class org.bouncycastle.jce.provider.symmetric.Noekeon$Mappings
Loaded class org.bouncycastle.jce.provider.symmetric.RC5$Mappings
Loaded class org.bouncycastle.jce.provider.symmetric.RC6$Mappings
Loaded class org.bouncycastle.jce.provider.symmetric.Rijndael$Mappings
Loaded class org.bouncycastle.jce.provider.symmetric.Salsa20$Mappings
Loaded class org.bouncycastle.jce.provider.symmetric.SEED$Mappings
Loaded class org.bouncycastle.asn1.kisa.KISAObjectIdentifiers
Loaded class org.bouncycastle.jce.provider.symmetric.Serpent$Mappings
Loaded class org.bouncycastle.jce.provider.symmetric.Skipjack$Mappings
Loaded class org.bouncycastle.jce.provider.symmetric.TEA$Mappings
Loaded class org.bouncycastle.jce.provider.symmetric.Twofish$Mappings
Loaded class org.bouncycastle.jce.provider.symmetric.VMPC$Mappings
Loaded class org.bouncycastle.jce.provider.symmetric.VMPCKSA3$Mappings
Loaded class org.bouncycastle.jce.provider.symmetric.XTEA$Mappings
Loaded class org.bouncycastle.jce.provider.asymmetric.EC$Mappings
Loaded class org.bouncycastle.asn1.x9.X9ObjectIdentifiers
Loaded class org.bouncycastle.asn1.cryptopro.CryptoProObjectIdentifiers
Loaded class org.bouncycastle.asn1.teletrust.TeleTrusTObjectIdentifiers
Loaded class org.bouncycastle.asn1.eac.EACObjectIdentifiers
Loaded class org.bouncycastle.asn1.bc.BCObjectIdentifiers
Loaded class org.bouncycastle.asn1.iana.IANAObjectIdentifiers
Loaded class org.bouncycastle.cms.CMSSignedGenerator
Loaded class org.bouncycastle.cms.CMSSignedDataGenerator
Loaded class org.bouncycastle.asn1.InMemoryRepresentable
Loaded class org.bouncycastle.asn1.ASN1OctetStringParser
Loaded class org.bouncycastle.asn1.ASN1OctetString
Loaded class org.bouncycastle.asn1.DEROctetString
Loaded class org.bouncycastle.cms.CMSException
Loaded class org.bouncycastle.asn1.ASN1Set
Loaded class org.bouncycastle.asn1.DERSet
Loaded class org.bouncycastle.cms.CMSProcessable
Loaded class org.bouncycastle.cms.CMSTypedData
Loaded class org.bouncycastle.cms.CMSAttributeTableGenerator
Loaded class org.bouncycastle.asn1.cms.CMSObjectIdentifiers
Loaded class org.bouncycastle.asn1.ASN1Choice
Loaded class org.bouncycastle.asn1.cms.SignerIdentifier
Loaded class org.bouncycastle.cms.CMSUtils
Loaded class org.bouncycastle.cms.NullOutputStream
Loaded class org.bouncycastle.asn1.BERSet
Loaded class org.bouncycastle.util.io.TeeOutputStream
Loaded class org.bouncycastle.cms.DigOutputStream
Loaded class org.bouncycastle.util.io.TeeInputStream
Loaded class org.bouncycastle.asn1.ASN1InputStream
Loaded class org.bouncycastle.asn1.DERApplicationSpecific
Loaded class org.bouncycastle.asn1.LimitedInputStream
Loaded class org.bouncycastle.asn1.DefiniteLengthInputStream
Loaded class org.bouncycastle.asn1.BERConstructedOctetString
Loaded class org.bouncycastle.asn1.ASN1Sequence
Loaded class org.bouncycastle.asn1.DERSequence
Loaded class org.bouncycastle.asn1.LazyDERSequence
Loaded class org.bouncycastle.asn1.DERExternal
Loaded class org.bouncycastle.asn1.DERUnknownTag
Loaded class org.bouncycastle.asn1.ASN1String
Loaded class org.bouncycastle.asn1.DERString
Loaded class org.bouncycastle.asn1.DERBitString
Loaded class org.bouncycastle.asn1.DERBMPString
Loaded class org.bouncycastle.asn1.DERBoolean
Loaded class org.bouncycastle.asn1.ASN1Boolean
Loaded class org.bouncycastle.asn1.DEREnumerated
Loaded class org.bouncycastle.asn1.ASN1Enumerated
Loaded class org.bouncycastle.asn1.DERGeneralizedTime
Loaded class org.bouncycastle.asn1.ASN1GeneralizedTime
Loaded class org.bouncycastle.asn1.DERGeneralString
Loaded class org.bouncycastle.asn1.DERIA5String
Loaded class org.bouncycastle.asn1.DERInteger
Loaded class org.bouncycastle.asn1.ASN1Integer
Loaded class org.bouncycastle.asn1.ASN1Null
Loaded class org.bouncycastle.asn1.DERNull
Loaded class org.bouncycastle.asn1.DERNumericString
Loaded class org.bouncycastle.asn1.DERPrintableString
Loaded class org.bouncycastle.asn1.DERT61String
Loaded class org.bouncycastle.asn1.DERUniversalString
Loaded class org.bouncycastle.asn1.DERUTCTime
Loaded class org.bouncycastle.asn1.ASN1UTCTime
Loaded class org.bouncycastle.asn1.DERUTF8String
Loaded class org.bouncycastle.asn1.DERVisibleString
Loaded class org.bouncycastle.asn1.IndefiniteLengthInputStream
Loaded class org.bouncycastle.asn1.ASN1Exception
Loaded class org.bouncycastle.asn1.DEREncodableVector
Loaded class org.bouncycastle.asn1.ASN1EncodableVector
Loaded class org.bouncycastle.asn1.ASN1StreamParser
Loaded class org.bouncycastle.asn1.ASN1TaggedObjectParser
Loaded class org.bouncycastle.asn1.ASN1TaggedObject
Loaded class org.bouncycastle.asn1.DERTaggedObject
Loaded class org.bouncycastle.asn1.BERTaggedObject
Loaded class org.bouncycastle.util.io.Streams
Loaded class org.bouncycastle.util.io.StreamOverflowException
Loaded class org.bouncycastle.asn1.DERFactory
Loaded class org.bouncycastle.asn1.ASN1SequenceParser
Loaded class org.bouncycastle.asn1.BERSequence
Loaded class org.bouncycastle.asn1.ASN1SetParser
Loaded class org.bouncycastle.asn1.DERSequenceParser
Loaded class org.bouncycastle.asn1.DEROctetStringParser
Loaded class org.bouncycastle.asn1.ASN1ParsingException
Loaded class org.bouncycastle.asn1.x509.X509ObjectIdentifiers
Loaded class org.bouncycastle.asn1.x509.TBSCertificateStructure
Loaded class org.bouncycastle.asn1.x509.AlgorithmIdentifier
Loaded class org.bouncycastle.asn1.x509.X509Name
Loaded class org.bouncycastle.asn1.x509.X509NameEntryConverter
Loaded class org.bouncycastle.asn1.x509.X509DefaultEntryConverter
Loaded class org.bouncycastle.asn1.x500.X500Name
Loaded class org.bouncycastle.asn1.x509.Time
Loaded class org.bouncycastle.asn1.x509.SubjectPublicKeyInfo
Loaded class org.bouncycastle.asn1.x509.X509Extensions
Loaded class org.bouncycastle.asn1.x509.X509Extension
Loaded class org.bouncycastle.asn1.cms.IssuerAndSerialNumber
Loaded class org.bouncycastle.asn1.x500.RDN
Loaded class org.bouncycastle.asn1.x500.X500NameStyle
Loaded class org.bouncycastle.asn1.x500.style.BCStyle
Loaded class org.bouncycastle.asn1.x500.AttributeTypeAndValue
Loaded class org.bouncycastle.cms.DefaultSignedAttributeTableGenerator
Loaded class org.bouncycastle.cms.CMSSignedDataGenerator$SignerInf
Loaded class org.bouncycastle.cms.SigOutputStream
Loaded class org.bouncycastle.util.encoders.Base64
Loaded class org.bouncycastle.util.encoders.Encoder
Loaded class org.bouncycastle.util.encoders.Base64Encoder
Java mapping com/iatech/TredsEnvelope completed. (executeStep() of com.iaatech.TredsEnvelope

please find the java code which taken from Eclipse:

package com.arteriatech;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.security.KeyStore;
import java.security.PrivateKey;
import java.security.Security;
import java.security.Signature;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.HashMap;
import java.util.Map;

import org.bouncycastle.cms.CMSSignedDataGenerator;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.util.encoders.Base64;

import sun.nio.cs.StandardCharsets;

import com.sap.aii.mapping.api.StreamTransformation;
import com.sap.aii.mapping.api.StreamTransformationException;

public class TredsEnvelope implements StreamTransformation
{
    private Map paramMap = null;
    public static void main(String[] args)
    {
        try
        {
            InputStream in = new FileInputStream(new File("C:\\Users\\E10373\\Desktop\\AtredsInput\\26102016_0001.txt"));
            OutputStream out = new FileOutputStream(new File("C:\\Users\\E10373\\Desktop\\AtredsInput\\Output\\26102016_0001_Out.xml"));
            TredsEnvelope tredsEnvelope = new TredsEnvelope();
            tredsEnvelope.execute(in, out);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }    
    }
    
//    @Override
    public void execute(InputStream arg0, OutputStream arg1) throws StreamTransformationException
    {
         try
         {
             Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
            BufferedReader br = null;
            String payloadData= "", initialTags="", endingTags="", signatureAlgorithm = "SHA256WithRSA", alias = "Arteria_Certificate", sCurrentLine;
            KeyStore keyStore = KeyStore.getInstance("PKCS12");
            keyStore.load(new FileInputStream("//aprins04/PI share/NPCI/INP/Arteria_Certificate.p12"), "arteria".toCharArray());
            PrivateKey privateKey = (PrivateKey)keyStore.getKey(alias, "arteria".toCharArray());
            CertificateFactory factory = CertificateFactory.getInstance("X.509");
            X509Certificate certificate = (X509Certificate) factory.generateCertificate(new FileInputStream("//aprins04/PI share/NPCI/INP/Arteria_Certificate-cert.cert"));
            br = new BufferedReader(new InputStreamReader(arg0));
            initialTags = initialTags 
                          +"<Envelope>\n"
                          +"<OrgContent>\n";
            while ((sCurrentLine = br.readLine()) != null)
            {
                String str = sCurrentLine;
                payloadData = payloadData
                              +str
                              +"\n";
            }

            CMSSignedDataGenerator cmsSignedDataGenerator = new CMSSignedDataGenerator();
            cmsSignedDataGenerator.addSigner(privateKey, certificate, signatureAlgorithm);
            Signature signature = Signature.getInstance(signatureAlgorithm, BouncyCastleProvider.PROVIDER_NAME);
            signature.initSign(privateKey);
            signature.update(payloadData.getBytes());
            byte[] signedData = signature.sign();
            byte[] base64EncodedSignature = Base64.encode(signedData);
            String encodedStringSign = new String(new String(base64EncodedSignature).getBytes("UTF-8"));
            FileInputStream inputStream  =  new FileInputStream("D:/Sujai/Implementation Team/PI/Axis Treds/Certificates/PI_7.5_Cert/Arteria_Certificate-cert.cert");
            CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
            X509Certificate cert = (X509Certificate)certFactory.generateCertificate(inputStream);
            String encodedCertString = new String(Base64.encode(cert.getEncoded()));
            String encodedStringData = new String(Base64.encode(payloadData.getBytes("UTF-8")));
            
            endingTags = endingTags + "\n"
                                        +"</OrgContent>"
                                        +"\n"+"<Signature>\n"
                                        +encodedStringSign
                                        +"\n</Signature>"
                                        +"\n"
                                        +"<Certificate>\n"
                                        +encodedCertString
                                        +"\n</Certificate> \n"
                                        +"</Envelope>";
         
            String xmlFormat = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
            xmlFormat = xmlFormat + initialTags + encodedStringData + endingTags;
            System.out.println("xmlFormat: "+xmlFormat);
            
            arg1.write(xmlFormat.getBytes());
            arg1.flush();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
    
//    @Override

    public void setParameter(Map arg0)
    {
        this.paramMap = paramMap;
        if (paramMap == null)
        {
            this.paramMap = new HashMap();
        }
    }
    
}

Case 3:

when i place the file in source directory, the message getting delivered sucessfully but i can see empty file in target directory.

Please note: here i did't see any exception in processing log as mention below.

please note:SAP PI java version is: 1.6, and same jre used in eclipse project as well. in eclipse output xml is looks perfect.

please do needful where we did mistake, we've seen few blog which is refres tjhe same issue in message mapping, but we are facing this issue in java mapping.

Reagrds

ramesh

capture.png (43.9 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Jan 06, 2017 at 05:33 PM

    Ramesh,

    What I see is you are trying to read private key and Certificate from a particular location so check if these locations are available at PI server or not .

    In you java mapping, add a trace to print the the output of those reterivals.

    And also as soon as you get that unable to trace in OM close that popup and click on 'src' button in OM after mapping to check how the output looks in ESR after execution of this code.

    Br,

    Manoj

    Add comment
    10|10000 characters needed characters exceeded