gpt4 book ai didi

java - 部署自定义调解器时出现 WSO2 ESB 错误

转载 作者:行者123 更新时间:2023-11-30 07:56:37 25 4
gpt4 key购买 nike

我正在尝试在 wso2 ESB 4.8 中实现自定义调解器。我用了this article作为引用,引用the docs同样,但无法让 ESB 识别我的调解器的 xml 配置。

我按照文档中提到的所有步骤,将调解员的项目.jar 移动到<ESB_HOME>/ repository/components/lib并重新启动服务器,但我在部署期间不断收到以下错误:

ERROR - MediatorFactoryFinder Unknown mediator referenced by configuration element : {http://ws.apache.org/ns/synapse}currencyMediator 

中介代码如下:

package org.wso2.esb.tutorial.custom;

import java.util.Iterator;

import javax.xml.namespace.QName;

import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMNode;
import org.apache.axiom.soap.SOAPBody;
import org.apache.synapse.MessageContext;
import org.apache.synapse.mediators.AbstractMediator;


public class CurrencyMedXML extends AbstractMediator {
private String symbol = "$";

public boolean mediate(MessageContext synCtx) {

// get symbol, last elements of SOAP envelope
SOAPBody body = synCtx.getEnvelope().getBody();
OMElement firstElement = body.getFirstElement();

//Iterator it = firstElement.getChildren();
Iterator it = firstElement.getChildrenWithName(new QName( "return"));
while (it.hasNext()) {
OMNode node = (OMNode)it.next();
if (node.getType()==OMNode.ELEMENT_NODE) {
OMElement ele=(OMElement)node;
String text = ele.getText();
ele.setText(symbol+text);
}
}


return true;
}

public void setSymbol(String sym){
symbol=sym;
}

public String getSymbol(){
return symbol;
}
}

序列化器实现:

package org.wso2.esb.tutorial.custom;

import org.apache.axiom.om.OMElement;
import org.apache.synapse.Mediator;
import org.apache.synapse.config.xml.AbstractMediatorSerializer;

public class CurrencyMedXMLSerializer extends AbstractMediatorSerializer {

public String getMediatorClassName() {
return CurrencyMedXML.class.getName();
}

@Override
protected OMElement serializeSpecificMediator(Mediator m) {
if (!(m instanceof CurrencyMedXML)) {
handleException("Unsupported mediator passed in for serialization : "
+ m.getType());
}

CurrencyMedXML mediator = (CurrencyMedXML) m;
OMElement CurrencyMediatorElement = fac
.createOMElement(CurrencyMedXMLFactory.CURRENCY_MEDIATOR_Q);

saveTracingState(CurrencyMediatorElement, mediator);

OMElement symbolElement = fac.createOMElement(CurrencyMedXMLFactory.SYMBOL_Q, CurrencyMediatorElement);
symbolElement.setText(mediator.getSymbol());

return CurrencyMediatorElement;
}
}

以及工厂实现:

package org.wso2.esb.tutorial.custom;

import java.util.Properties;

import javax.xml.namespace.QName;

import org.apache.axiom.om.OMElement;
import org.apache.synapse.Mediator;
import org.apache.synapse.SynapseException;
import org.apache.synapse.config.xml.AbstractMediatorFactory;
import org.apache.synapse.config.xml.XMLConfigConstants;

public class CurrencyMedXMLFactory extends AbstractMediatorFactory {

static final QName CURRENCY_MEDIATOR_Q = new QName(
XMLConfigConstants.SYNAPSE_NAMESPACE, "currencyMediator");

static final QName SYMBOL_Q = new QName(
XMLConfigConstants.SYNAPSE_NAMESPACE, "symbol");

public QName getTagQName() {
return CURRENCY_MEDIATOR_Q;
}

@Override
protected Mediator createSpecificMediator(OMElement elem, Properties properties) {
// create new mediator
CurrencyMedXML newMediator = new CurrencyMedXML();

// setup initial settings
processAuditStatus(newMediator, elem);

OMElement symbolElement = elem.getFirstChildWithName(SYMBOL_Q);
if (symbolElement != null) {
String symbol = symbolElement.getText();
newMediator.setSymbol(symbol);
} else {
throw new SynapseException("default percentage element missing");
}

return newMediator;
}
}

这是代理服务的一个片段,我在其中引用了自定义调解器:

<outSequence>
<currencyMediator>
<symbol>$</symbol>
</currencyMediator>
<send/>
</outSequence>

最佳答案

我还没有尝试过那种自定义标签的方法。但仅供引用,您也可以这样称呼您的类(class)调解员。

<class name="samples.mediators.DiscountQuoteMediator">
<property name="discountFactor" value="10"/>
<property name="bonusFor" value="5"/>
</class>

关于java - 部署自定义调解器时出现 WSO2 ESB 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41966268/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com