cancel
Showing results for 
Search instead for 
Did you mean: 

Character conversion error: "Unconvertible UTF-8 character beginning with 0

Former Member
0 Kudos

Hi All,

I developed an Adapter Module and added to Adapter Framework.

package sample;

import java.io.InputStream;

import java.text.SimpleDateFormat;

import java.util.Date;

import javax.ejb.CreateException;

import javax.ejb.SessionBean;

import javax.ejb.SessionContext;

import javax.xml.parsers.DocumentBuilder;

import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;

import org.w3c.dom.Element;

import org.w3c.dom.NodeList;

import com.sap.aii.af.mp.module.Module;

import com.sap.aii.af.mp.module.ModuleContext;

import com.sap.aii.af.mp.module.ModuleData;

import com.sap.aii.af.mp.module.ModuleException;

import com.sap.aii.af.ra.ms.api.Message;

import com.sap.aii.af.ra.ms.api.XMLPayload;

/**

  • @ejbHome <{com.sap.aii.af.mp.module.ModuleHome}>

  • @ejbLocal <{com.sap.aii.af.mp.module.ModuleLocal}>

  • @ejbLocalHome <{com.sap.aii.af.mp.module.ModuleLocalHome}>

  • @ejbRemote <{com.sap.aii.af.mp.module.ModuleRemote}>

  • @stateless

*/

public class SetAttachmentName implements SessionBean, Module {

private SessionContext myContext;

private String mailFileName = "UStN";

public void ejbRemove() {

}

public void ejbActivate() {

}

public void ejbPassivate() {

}

public void setSessionContext(SessionContext context) {

myContext = context;

}

public void ejbCreate() throws CreateException {

}

public ModuleData process(

ModuleContext moduleContext,

ModuleData inputModuleData)

throws ModuleException {

// create a second attachment for the receiver mail adapter

try {

// get the XI message from the environment

Message msg = (Message) inputModuleData.getPrincipalData();

// creating parsable XML document

InputStream XIStreamData = null;

XMLPayload xmlpayload = msg.getDocument();

XIStreamData = xmlpayload.getInputStream();

DocumentBuilderFactory docBuilderFactory =

DocumentBuilderFactory.newInstance();

DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();

Document doc = docBuilder.parse(XIStreamData);

// finding the tag's name from the Modules tab in the Directory that will hold the attachment's name

String absenderIDTag = null;

absenderIDTag = moduleContext.getContextData("<RCVPRN>");

// finding the content of the tag that will be used as the attachment's name (assuming it's the only tag with this name)

Element element = doc.getDocumentElement();

NodeList list = doc.getElementsByTagName(absenderIDTag);

mailFileName += "_" + list.item(0).getFirstChild().toString();

String anIDTag = null;

anIDTag = moduleContext.getContextData("<CREDAT>");

element = doc.getDocumentElement();

list = doc.getElementsByTagName(anIDTag);

mailFileName += "_" + list.item(0).getFirstChild().toString();

Date date = new Date(System.currentTimeMillis());

// Add date to the Message

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");

mailFileName += "_" + dateFormat.format(date);

String belegNummerTag = null;

belegNummerTag = moduleContext.getContextData("<BULK_REF>");

element = doc.getDocumentElement();

list = doc.getElementsByTagName(belegNummerTag);

mailFileName += "_" + list.item(0).getFirstChild().toString();

// creating the attachment

byte by[] = xmlpayload.getText().getBytes();

XMLPayload attachmentPDF = msg.createXMLPayload();

attachmentPDF.setName(mailFileName);

attachmentPDF.setContentType("application/pdf");

attachmentPDF.setContent(by);

//adding the message to the attachment

msg.addAttachment(attachmentPDF);

// provide the XI message for returning

inputModuleData.setPrincipalData(msg);

} catch (Exception e) {

// raise exception, when an error occurred

ModuleException me = new ModuleException(e);

throw me;

}

// return XI message

return inputModuleData;

}

}

I get the following error

Character conversion error: "Unconvertible UTF-8 character beginning with 0xaa" (line number may be too low).

Any tips, pointers ?

Thanks in Advance

Mukhtar

Accepted Solutions (0)

Answers (1)

Answers (1)

stefan_grube
Active Contributor
0 Kudos

This line is wrong:

list.item(0).getFirstChild().toString();

you cannot use toString() here. See the Javadoc for useable methods.

henrique_pinto
Active Contributor
0 Kudos

yep.

use .getNodeValue() instead.

Regards,

Henrique.

Former Member
0 Kudos

Hi Henrique,

I am using .getNodeValue()

import java.io.InputStream;

import java.text.SimpleDateFormat;

import java.util.Date;

import javax.ejb.CreateException;

import javax.ejb.SessionBean;

import javax.ejb.SessionContext;

import javax.xml.parsers.DocumentBuilder;

import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;

import org.w3c.dom.Element;

import org.w3c.dom.NodeList;

import com.sap.aii.af.mp.module.*;

import com.sap.aii.af.ra.ms.api.*;

/**

  • @ejbHome <{com.sap.aii.af.mp.module.ModuleHome}>

  • @ejbLocal <{com.sap.aii.af.mp.module.ModuleLocal}>

  • @ejbLocalHome <{com.sap.aii.af.mp.module.ModuleLocalHome}>

  • @ejbRemote <{com.sap.aii.af.mp.module.ModuleRemote}>

  • @stateless

*/

public class UStNAttachmentName3 implements SessionBean, Module {

private SessionContext myContext;

private String mailFileName = "UStN";

public void ejbRemove() {

}

public void ejbActivate() {

}

public void ejbPassivate() {

}

public void setSessionContext(SessionContext context) {

myContext = context;

}

public void ejbCreate() throws CreateException {

}

public ModuleData process(

ModuleContext moduleContext,

ModuleData inputModuleData)

throws ModuleException {

// create a second attachment for the receiver mail adapter

try {

// get the XI message from the environment

Message msg = (Message) inputModuleData.getPrincipalData();

// creating parsable XML document

InputStream XIStreamData = null;

XMLPayload xmlpayload = msg.getDocument();

XIStreamData = xmlpayload.getInputStream();

DocumentBuilderFactory docBuilderFactory =

DocumentBuilderFactory.newInstance();

DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();

Document doc = docBuilder.parse(XIStreamData);

// finding the tag's name from the Modules tab in the Directory that will hold the attachment's name

String absenderIDTag = null;

absenderIDTag = moduleContext.getContextData("<RCVPRN>");

// finding the content of the tag that will be used as the attachment's name (assuming it's the only tag with this name)

Element element = doc.getDocumentElement();

NodeList list = doc.getElementsByTagName(absenderIDTag);

mailFileName += "_" + list.item(0).getFirstChild().getNodeValue();

String anIDTag = null;

anIDTag = moduleContext.getContextData("<CREDAT>");

element = doc.getDocumentElement();

list = doc.getElementsByTagName(anIDTag);

mailFileName += "_" + list.item(0).getFirstChild().getNodeValue();

Date date = new Date(System.currentTimeMillis());

// Add date to the Message

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");

mailFileName += "_" + dateFormat.format(date);

String belegNummerTag = null;

belegNummerTag = moduleContext.getContextData("<BULK_REF>");

element = doc.getDocumentElement();

list = doc.getElementsByTagName(belegNummerTag);

mailFileName += "_" + list.item(0).getFirstChild().getNodeValue();

// creating the attachment

byte by[] = xmlpayload.getText().getBytes();

XMLPayload attachmentPDF = msg.createXMLPayload();

attachmentPDF.setName(mailFileName);

attachmentPDF.setContentType("application/pdf");

attachmentPDF.setContent(by);

//adding the message to the attachment

msg.addAttachment(attachmentPDF);

// provide the XI message for returning

inputModuleData.setPrincipalData(msg);

} catch (Exception e) {

// raise exception, when an error occurred

ModuleException me = new ModuleException(e);

throw me;

}

// return XI message

return inputModuleData;

}

}

Still I get the same error.

org.xml.sax.SAXParseException: Character conversion error: "Unconvertible UTF-8 character beginning with 0xaa" (line number may be too low).

Adapter-Framework: Character conversion error: "Unconvertible UTF-8 character beginning with 0xaa" (line number may be too low).

Regards,

Mukhtar