我试图在wso2 ESB 4.8中实现自定义中介。 我使用this article作为参考,并且也引用了the docs,但无法让ESB识别我的中介的xml配置。
我按照文档中提到的所有步骤,将调解员的项目 .jar 移至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>
这是代理服务的一个片段,我引用自定义中介:
SELECT ItemCode, SUM(QuantityOrdered) AS Total_Quantity
FROM OrderDetail
where DateField >= dateadd(month, -4, cast(getdate() as DATE))
GROUP BY ItemCode
ORDER BY SUM(QuantityOrdered) DESC;
答案 0 :(得分:2)
我还没有尝试过自定义标记方法。但只是为了您的信息,您也可以像这样打电话给您的班级调解员。
__hash__
答案 1 :(得分:1)