cancel
Showing results for 
Search instead for 
Did you mean: 

Chinese Character problem for PO with attachment filename in chinese

Former Member
0 Kudos

I'm using a UDF which will take URL and file name as parameters. When i give the Chinese name for attachment. It is failing.

Output of the UDF is given to URL.

Output is coming like.

<Comments>

               <Attachment>

                  <URL>1452237793341_1969839383Copy of 诺å?Ž Lin Teng 15082403(ä¸?å?«ç¨Žï¼‰.docx</URL>              

</Comments>

Expected Output.

<Comments>

<Attachment>

                  <URL>1452079127666_Copy of 诺华 Lin Teng 15082403(不含税).docx</URL>

</Attachment>

</Comments>

Because of which It is giving the following error.

Error Message In PI System for Chinese attachment file name.

An error occurred when sending the document to Ariba Network Error: [[Code]: ERR303 [Description]: Outbound Transaction Failed [Message]: java.lang.NullPointerException: while trying to get the length of an array loaded from local variable buf] causes a XIAdapterException and can be retried.

Message could not be forwarded to the JCA adapter. Reason: Permanent error: Adapter call failed. Reason: com.sap.aii.af.lib.ra.cci.XIAdapterException:

Message could not be forwarded permantely to the JCA adapter. Reason: null

Delivery of the message to the application using connection AribaNetworkAdapterSAPNetweaver_http://ariba.com/xi/ASCAdapter failed, due to: com.sap.engine.interfaces.messaging.api.exception.MessagingException: com.sap.aii.af.lib.ra.cci.XIAdapterException:

The asynchronous message was successfully scheduled to be delivered at Wed Jan 06 16:58:48 IST 2016

Message status set to WAIT.

The content of the attachment is going as null even if the content is not null.

This works fine, if you give English file name.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

  Used one more UDF to convert Chinese Characters to equivalent ASCII. This solved my problem.

Here is code

public static String convertToASCII (String nonASCII) throws MappingException

    {

        String SIGNATURE = "convertToASCCII (String nonASCII)";

        String ascciiString = null;

        URI uri = null;

        try {

            uri = new URI(null, null, nonASCII, null);

        }

        catch (URISyntaxException e) {

            throw new MappingException(SIGNATURE + " " + e.getMessage());

        }

        if (uri != null) {

            ascciiString = uri.toASCIIString();

        }

        return ascciiString;

    }

Answers (2)

Answers (2)

stefan_grube
Active Contributor
0 Kudos

Couls you provide the source code of your UDF to have a look?

Former Member
0 Kudos

public static String readAttachmentContentURL (String url,

                                                   String fileName,

                                                   Container container,

                                                   Random randomGenerator) throws StreamTransformationException

    {

        nullOrEmptyCheck(url,URL);

        OutputAttachments outputAttachments = getOutputAttachments(container);

        String cid = System.currentTimeMillis() + "_"

            + generateRandomNum(randomGenerator);

       

        try {

            HttpClient httpClient = new HttpClient();

            GetMethod getMethod = new GetMethod(url);

            httpClient.executeMethod(getMethod);

            int status = getMethod.getStatusCode();

            if (status != HttpStatus.SC_OK) {

                throw new StreamTransformationException(

                    "OutboundAttachmentHandler Exception - Attachment Download Status Code"

                        + status);

            }

            byte[] content = getMethod.getResponseBody();

            nullOrEmptyCheck(new String(content),CONTENT);

            Header attachmentContentTypeHeader = getMethod.getResponseHeader(CONTENT_TYPE);

            String respContentType;

            if (attachmentContentTypeHeader == null) {

                respContentType = DEFAULT_OB_CONTENT_TYPE;

            }

            else {

                respContentType = attachmentContentTypeHeader.getValue();

                if (respContentType == null || respContentType == "") {

                    respContentType = DEFAULT_OB_CONTENT_TYPE;

                }

            }

           

            Header contentDispositionHeader = getMethod.getResponseHeader(CONTENT_DISPOSITION);

            cid = attachFileNameToCID(fileName, respContentType, cid, contentDispositionHeader);

            Attachment attachment = outputAttachments.create(

                cid,

                respContentType,

                content);

            outputAttachments.setAttachment(attachment);

        }

        catch (IOException e) {

            throw new StreamTransformationException("OutboundAttachmentHandler Exception"

                + e.getMessage(), e);

        }

        return cid;

    }

private static String attachFileNameToCID (String fileName,

                                               String respContentType,

                                               String cid,

                                               Header contentDispositionHeader) throws StreamTransformationException

    {

        String extention = ".";

        if (!Util.nullOrEmptyOrBlankString(fileName)) {

            cid = cid + fileName;

        }

        else {

            String[] contentTypeWithEncode = respContentType.split(";");

            String contentType = null;

            if (contentTypeWithEncode[0] != null) {

                contentType = contentTypeWithEncode[0];

            }

           

            if (contentDispositionHeader != null) {

                String dispositionContent = contentDispositionHeader.getValue();

                fileName = AttachmentUtil.getFileName(dispositionContent);

                if (!Util.nullOrEmptyOrBlankString(fileName)) {

                    cid = cid + fileName;

                }

                else {

                    extention = extention + getExtention(contentType);

                    cid = cid + extention;

                }

            }

            else {

                extention = extention + getExtention(contentType);

                cid = cid + extention;

            }

        }

        return cid;

    }

cid is the value coming in the xml for URL tag.

<Comments>

               <Attachment>

                  <URL>1452237793341_1969839383Copy of 诺å?Ž Lin Teng 15082403(ä¸?å?«ç¨Žï¼‰.docx</URL>             

</Comments>

stefan_grube
Active Contributor
0 Kudos

First of all I have compared the strings:

Copy of 诺华 Lin Teng 15082403(不含税)

Copy of 诺� Lin Teng 15082403(��税)

In principle they are identical. The first string is represented in correct UTF-8 encoding, the second string is the same byte stream, however represented as ANSI

So what happens: you receive the attachment name as byte array and convert it to a String with the wrong encoding.

I cannot see in your code, where this happens, as some methods are not included, like:

getExtention(contentType);

AttachmentUtil.getFileName(dispositionContent);


So check your code and look for transformation from byte[] to String or String to byte[]


Always use following statements and nothing else:


String str = new String (byteArray,"UTF-8");

byte[] byteArray = str.getBytes("UTF-8");


I hope that helps you, otherwise provide the mentioned methods as well.

Former Member
0 Kudos

In the above case

getExtention and getFileName will not be called Because I'm giving filename as input to the UDF. So, No where the string is getting converted to byte stream.

Still the value is coming like that, when it is passing through PI system.

And In this case, It is not reaching the destination system because content of the attachment is coming as null in the adapter.

But if you pass normal english file name it works perfectly.

stefan_grube
Active Contributor
0 Kudos

Of course an English name works perfectly, because English consists only from ASCII characters, so there would not be any difference between UTF-8 or ANSI. When you copied the Chinese text to the constant, could you still display it as Chinese? Could you provide a screen shot of the constant with the value visible?

Former Member
0 Kudos
stefan_grube
Active Contributor
0 Kudos

At the moment everything looks fine and I do not see, how the encoding of the text changes. What I am wondering is, why the constant cid: is missing in the URL. In my opinion the element URL should be filled with cid:..... Did you change something recently? Could you activate again? Do you have the issue in test and in runtime?

Former Member
0 Kudos

Yes.. Recently i added the constant cid. URL will come like cid:.. It is just mapping change. I removed cid: and run . Following result i'm getting

When i run in PI, It is giving me the correct result. When it comes to Adapter it is failing with content of attachment null. And the URL is coming as 1452513290892_1008047288Copy of 诺� Lin Teng 15082403(��税).docx

stefan_grube
Active Contributor
0 Kudos

After checking your UDF code and the constant value, I think the issue does not come from the mapping. You say that the XML after the mapping is fine. So I think there is an issue in adapter configuration. Which adapter do you use? Which adapter modules?

former_member186851
Active Contributor
0 Kudos

Hello,

Try to encode Chinese characters using Java mapping

https://scn.sap.com/thread/1618551

Former Member
0 Kudos

It was handled in Java Mapping.

As a new feature I have introduced UDFs to handle attachments.

I cannot go back to java mapping again.

Please give me other solution.

former_member186851
Active Contributor
0 Kudos

Try the below option using UDF