import javax.ejb.CreateException;
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.MessagePropertyKey;
import com.sap.engine.interfaces.messaging.api.PublicAPIAccessFactory;
import com.sap.engine.interfaces.messaging.api.auditlog.AuditAccess;
import com.sap.engine.interfaces.messaging.api.auditlog.AuditLogStatus;
public class DynamicContentTypeBean implements SessionBean, Module {
private static final long serialVersionUID = 1L;
private SessionContext myContext;
@Override
public ModuleData process(ModuleContext moduleContext, ModuleData inputModuleData) throws ModuleException {
String CLASS_NAME = getClass().getSimpleName();
try {
Message msg = (Message) inputModuleData.getPrincipalData();
MessageKey key = new MessageKey(msg.getMessageId(), msg.getMessageDirection());
AuditAccess audit = PublicAPIAccessFactory.getPublicAPIAccess().getAuditAccess();
audit.addAuditLogEntry(key, AuditLogStatus.SUCCESS, CLASS_NAME + ": Module Called");
String source = moduleContext.getContextData("source");
if (source == null) {
throw new ModuleException("Parameter source is missing");
}
audit.addAuditLogEntry(key, AuditLogStatus.SUCCESS, "Read parameter source: " + source);
String target = moduleContext.getContextData("target");
if (target == null) {
throw new ModuleException("Parameter target is missing");
}
audit.addAuditLogEntry(key, AuditLogStatus.SUCCESS, "Read parameter newString: " + target);
MessagePropertyKey KEY_FILENAME = new MessagePropertyKey("FileName", "http://sap.com/xi/XI/System/File");
String fileName = msg.getMessageProperty(KEY_FILENAME);
audit.addAuditLogEntry(key, AuditLogStatus.SUCCESS, "FileName read successfully. fileName: " + fileName);
fileName = fileName.replace(source, target);
String contentType = "text/plain;charset=\"utf-8\";name=\"" + fileName + "\"";
msg.getMainPayload().setContentType(contentType);
audit.addAuditLogEntry(key, AuditLogStatus.SUCCESS, "ContentType was set to: " + contentType);
} catch (Exception e) {
throw new ModuleException(e.getClass() + ": " + e.getMessage());
}
return inputModuleData;
}
@Override
public void ejbRemove() {
}
@Override
public void ejbActivate() {
}
@Override
public void ejbPassivate() {
}
@Override
public void setSessionContext(SessionContext context) {
setMyContext(context);
}
public void setMyContext(SessionContext myContext) {
this.myContext = myContext;
}
public SessionContext getMyContext() {
return myContext;
}
public void ejbCreate() throws CreateException {
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
11 | |
10 | |
7 | |
6 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 |