SAP PO EJB删除特殊Header
SAP PO EJB开发案例
根据特殊要求定制PO EJB项目。
问题说明
错误:Name is too long (100/50): x-ratelimit-reset-gateway-service_finance-service_00040020_113.204.103.126_sap_cwnotice_savecwnotice
at com.sap.aii.mapping.api.DynamicConfigurationKey
D
y
n
a
m
i
c
C
o
n
f
i
g
u
r
a
t
i
o
n
K
e
y
I
m
p
l
.
<
i
n
i
t
>
(
D
y
n
a
m
i
c
C
o
n
f
i
g
u
r
a
t
i
o
n
K
e
y
.
j
a
v
a
:
63
)
a
t
c
o
m
.
s
a
p
.
a
i
i
.
m
a
p
p
i
n
g
.
a
p
i
.
D
y
n
a
m
i
c
C
o
n
f
i
g
u
r
a
t
i
o
n
K
e
y
DynamicConfigurationKeyImpl.<init>(DynamicConfigurationKey.java:63) at com.sap.aii.mapping.api.DynamicConfigurationKey
DynamicConfigurationKeyImpl.<init>(DynamicConfigurationKey.java:63)atcom.sap.aii.mapping.api.DynamicConfigurationKeyDynamicConfigurationKeyImpl.(DynamicConfigurationKey.java:46)
PO动态配置Header name过长导致异常Name is too long (100/50)。
解决措施
接收到第三方响应消息后删除无用Header 内容。
打开NWDS创建EJB项目
-
File --> New --> EJB Project
参考:https://blogs.sap.com/2019/05/03/how-to-create-custom-adapter-module-in-sap-pipo-for-ejb-3.0-version/ -
项目结构如图
-
ejb-j2ee-engine.xml
<?xml version="1.0" encoding="UTF-8"?>
<ejb-j2ee-engine xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ejb-j2ee-engine_3_0.xsd">
<enterprise-beans>
<enterprise-bean>
<ejb-name>HeaderRmBean</ejb-name>
<jndi-name>HeaderRm</jndi-name>
</enterprise-bean>
</enterprise-beans>
</ejb-j2ee-engine>
- ejb-jar.xml
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd" version="3.0">
<display-name>Header_EJB </display-name>
<enterprise-beans>
<session>
<icon/>
<ejb-name>HeaderRmBean</ejb-name>
<home>com.sap.aii.af.lib.mp.module.ModuleHome</home>
<remote>com.sap.aii.af.lib.mp.module.ModuleRemote</remote>
<local-home>com.sap.aii.af.lib.mp.module.ModuleLocalHome</local-home>
<local>com.sap.aii.af.lib.mp.module.ModuleLocal</local>
<ejb-class>com.sap.pi.jxb.custom.HeaderRm</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
</ejb-jar>
- application-j2ee-engine.xml
<?xml version="1.0" encoding="UTF-8"?>
<application-j2ee-engine xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="application-j2ee-engine.xsd">
<reference reference-type="hard">
<reference-target target-type="service"
provider-name="sap.com">engine.security.facade</reference-target>
</reference>
<reference reference-type="hard">
<reference-target target-type="library"
provider-name="sap.com">engine.j2ee14.facade</reference-target>
</reference>
<reference reference-type="hard">
<reference-target target-type="service"
provider-name="sap.com">com.sap.aii.af.svc.facade</reference-target>
</reference>
<reference reference-type="hard">
<reference-target target-type="interface"
provider-name="sap.com">com.sap.aii.af.ifc.facade</reference-target>
</reference>
<reference reference-type="hard">
<reference-target target-type="library"
provider-name="sap.com">com.sap.aii.af.lib.facade</reference-target>
</reference>
<reference reference-type="hard">
<reference-target target-type="library"
provider-name="sap.com">com.sap.base.technology.facade</reference-target>
</reference>
<fail-over-enable xsi:type="fail-over-enableType_disable"
mode="disable" />
</application-j2ee-engine>
- HeaderRm.java
package com.sap.pi.jxb.custom;
import java.util.Set;
import javax.ejb.Local;
import javax.ejb.LocalHome;
import javax.ejb.Remote;
import javax.ejb.RemoteHome;
import javax.ejb.Stateless;
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.aii.af.lib.mp.module.ModuleHome;
import com.sap.aii.af.lib.mp.module.ModuleLocal;
import com.sap.aii.af.lib.mp.module.ModuleLocalHome;
import com.sap.aii.af.lib.mp.module.ModuleRemote;
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;
/**
* Session Bean implementation class HeaderRm
*/
@Stateless(name = "HeaderRmBean")
@Local(value = { ModuleLocal.class })
@Remote(value = { ModuleRemote.class })
@LocalHome(value = ModuleLocalHome.class)
@RemoteHome(value = ModuleHome.class)
public class HeaderRm implements Module {
/**
* Default constructor.
*/
@Override
public ModuleData process(ModuleContext moduleContext, ModuleData inputModuleData) throws ModuleException {
// TODO Auto-generated method stub
AuditAccess audit = null;
Message msg = null;
MessageKey msgKey = null;
String msgstr = null;
int maxLen = 20;
// String fullpload = null;
try {
// Load message:
msg = (Message) inputModuleData.getPrincipalData();
msgKey = new MessageKey(msg.getMessageId(), msg.getMessageDirection()); // msg.getMessageKey();
audit = PublicAPIAccessFactory.getPublicAPIAccess().getAuditAccess();
audit.addAuditLogEntry(msgKey, AuditLogStatus.SUCCESS,
"Edit by cg | Custom-Java-Adapter-Module (localejbs/HeaderRm)");
// Load configuration parameters:
maxLen = Integer.parseInt(moduleContext.getContextData("maxLen").toString());
audit.addAuditLogEntry(msgKey, AuditLogStatus.SUCCESS, "dc by cg | HeaderRm | input-maxLen:" + maxLen);
Set<MessagePropertyKey> msgkeys = msg.getMessagePropertyKeys();
for (MessagePropertyKey ky : msgkeys) {
if (ky.getPropertyName().length() > maxLen) {
msgstr = new String(msg.getMessageProperty(ky));
audit.addAuditLogEntry(msgKey, AuditLogStatus.SUCCESS,
"rm by cg | HeaderRm |" + ky.getPropertyName() + ":" + msgstr);
msg.removeMessageProperty(ky);
}
}
inputModuleData.setPrincipalData(msg);
} catch (Exception e) {
ModuleException me = new ModuleException(e);
throw me;
}
return inputModuleData;
}
}
发布到PO
右击EAR --> Run as --> Run on Server
填PO地址及账号即可发布,出现如下提示即发布成功。
测试案例