on 02-17-2016 3:42 PM
Hi Blue,
Did you add this java mapping after the messages mapping in the operation mapping?
Regards,
Praveen.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Blue,
If you are using standard File adapter, test without content conversion first, see if the BOM characters appear in Notepad++?
The working solution I developed before for seeburger SFTP adapter, is build a custom module for BOM, similar to your code.
Don't use built-in FCC, instead use MessageTransformationBean, then followed by BOM module, it should work.
Regards,
Yee Loon
Hi Blue,
This example is very similar to your java mapping code but fits the adapter module API:
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.rmi.RemoteException;
import javax.ejb.Stateless;
import javax.ejb.EJBException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import com.sap.aii.af.lib.mp.module.Module;
import com.sap.aii.af.lib.mp.module.ModuleContext;
import com.sap.aii.af.lib.mp.module.ModuleData;
import com.sap.aii.af.lib.mp.module.ModuleException;
import com.sap.engine.interfaces.messaging.api.Message;
import com.sap.engine.interfaces.messaging.api.MessageKey;
import com.sap.engine.interfaces.messaging.api.PublicAPIAccess;
import com.sap.engine.interfaces.messaging.api.PublicAPIAccessFactory;
import com.sap.engine.interfaces.messaging.api.XMLPayload;
import com.sap.engine.interfaces.messaging.api.auditlog.AuditAccess;
import com.sap.engine.interfaces.messaging.api.auditlog.AuditLogStatus;
import com.sap.engine.interfaces.messaging.api.exception.InvalidParamException;
import com.sap.engine.interfaces.messaging.api.exception.MessagingException;
@Stateless
public class BOMBean implements SessionBean, Module{
private static final long serialVersionUID = 1883263307825505561L;
private MessageKey amk;
private AuditAccess audit;
private Message msg;
@Override
public ModuleData process(ModuleContext mc, ModuleData md)
throws ModuleException {
// Get message data and audit access
msg = (Message) md.getPrincipalData();
XMLPayload payload = msg.getDocument();
amk = new MessageKey(msg.getMessageId(), msg.getMessageDirection());
PublicAPIAccess pa;
try {
pa = PublicAPIAccessFactory.getPublicAPIAccess();
} catch (MessagingException e) {
throw new ModuleException(e.getMessage());
}
audit = pa.getAuditAccess();
// Write BOM mark followed by full unaltered input stream
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] bytes = new byte[4096];
baos.write(0xEF);
baos.write(0xBB);
baos.write(0xBF);
InputStream is = payload.getInputStream();
while(is.read(bytes) != -1)
{
baos.write(bytes);
}
payload.setContent(baos.toByteArray());
is.close();
baos.close();
} catch (IOException e) {
audit.addAuditLogEntry(amk, AuditLogStatus.ERROR, e.getMessage());
throw new ModuleException(e);
} catch (InvalidParamException e) {
audit.addAuditLogEntry(amk, AuditLogStatus.ERROR, e.getMessage());
throw new ModuleException(e);
}
// Pass updated module data back
return md;
}
@Override
public void ejbActivate() throws EJBException, RemoteException {
}
@Override
public void ejbPassivate() throws EJBException, RemoteException {
}
@Override
public void ejbRemove() throws EJBException, RemoteException {
}
@Override
public void setSessionContext(SessionContext arg0) throws EJBException,
RemoteException{
}
}
If you observe that you see multiples of 4096 bytes in the output file then the read/writing to the byte array can be adjusted to be more dynamic. I forget which streams behave that way in Java but that's easy to adjust should you find that it does not trim trailing spaces.
P.S. - this is a very basic implementation with no parameters so it's not flexible. If you wanted to make it be a bit more flexible you could look into usage of the key/value parameters to add functionality to the module.
Regards,
Ryan Crosby
Hi Blue,
Once you have the Bean deployed to your system then you would just go into the receiver channel and add it after the MessageTransformBean but before the ModuleProcessorExitBean and you don't need to add any parameters. So the sequence would be like this:
localejbs/MessageTransformBean
localejbs/BOMBean
localejbs/ModuleProcessorExitBean
Regards,
Ryan Crosby
Hi Blue,
In order to do the deployment I would follow a guide like this as you have to first package up the .jar and then generate and .ear file for the application which is what would get deployed to your system. I've inserted a link to a blog on how to deploy (I have a more detailed hard copy that it won't let me attach and I cannot find that link).
Regards,
Ryan Crosby
Thank you Ryan.
I followed the link in your post PI 7.4 - Adapter Module Creation using EJB 3.0
but in step 11, I put my PI host and instance number then I got error message as below, so I am stuck at step 11. Any suggestions?
Hi Ryan,
Basis helped imported the EAR file, tested in PI and got error as below:
Message processing failed. Cause: com.sap.engine.interfaces.messaging.api.exception.MessagingException: java.lang.Exception: Exception in XML Parser (format problem?):'org.xml.sax.SAXParseException: The markup in the document following the root element must be well-formed.
Don't think the Module Bean touched the format. Not sure what is the problem
Blue
Hi Blue,
Did you make sure to place the MessageTransformBean before the BOMBean? If you have them reversed in order then you would get that SAXException possibly as the parser would may not handle the characters before the xml root node properly. Make sure the order is way I had mentioned on one of the previous posts.
Regards,
Ryan Crosby
Hi Blue,
You won't be able to test that way because the FCC is part of the adapter processing and that means you have that happening after the BOMBean processing. You would need to test it the way you described before with the MessageTransformBean instead of FCC - in fact you can still use MessageTransformBean in the File/FTP adapter.
Regards,
Ryan Crosby
Hi Blue,
I could reproduce this in a sample on my Eclipse so this is one of the streams where you have to be sure to specify length. The following should also work if you cannot get the IOUtils to work for you.
Change this:
byte[] bytes = new byte[4096];
Inputstream is = payload.getInputStream();
while(is.read(bytes) != -1)
{
baos.write(bytes);
}
To this:
byte[] bytes = new byte[4096];
int len = -1;
Inputstream is = payload.getInputStream();
while((len = is.read(bytes)) != -1)
{
baos.write(bytes, 0, len);
}
Regards,
Ryan Crosby
Hi Ryan,
I used the code IOUtils.toByteArray, the file is generated properly with BOM. But when the EAR file is deployed in PI, it got a warning, I am just wondering is there a guide on how to generate EJB bean using 2.1
The warning is as below:
"BOMJavaBean is exposed as 3.0 local business interface and as 2.1. local component interface."
Hi Blue,
I wouldn't be super worried about the warning if it's doing what you need. I have never faced that warning before when deploying a module but my guess is you are using a newer IDE that defaults to EJB 3.0 while your system is older and running a framework that supports 2.1. Likely since it is only a warning and backwards compatibility is always an aim to achieve with any new systems I would bet that you can ignore it.
Regards,
Ryan Crosby
Regards,
Ryan Crosby
User | Count |
---|---|
84 | |
25 | |
12 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.