on 01-08-2016 9:02 AM
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.
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;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Couls you provide the source code of your UDF to have a look?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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>
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.
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.
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?
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?
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
9 | |
9 | |
8 | |
7 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.