SAP PO EJB删除特殊Header

2 篇文章 0 订阅
1 篇文章 0 订阅
文章描述了一个在SAPPOEJB开发中遇到的问题,即动态配置Header名称过长导致的异常。为了解决这个问题,开发者创建了一个EJB项目,通过删除无用Header内容来避免Nameistoolong错误。具体步骤包括在NWDS中新建EJB项目,编写HeaderRmBean并实现处理逻辑,最后将项目发布到PO。
摘要由CSDN通过智能技术生成

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项目

  1. 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/

  2. 项目结构如图
    在这里插入图片描述

  3. 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>

在这里插入图片描述

  1. 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>

在这里插入图片描述

  1. 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>

在这里插入图片描述

  1. 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地址及账号即可发布,出现如下提示即发布成功。
在这里插入图片描述

测试案例

在这里插入图片描述
在这里插入图片描述

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zc果子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值