我想为Java做动态转换,转换类型存储在不同的接口中。 NotifyInboundDeliveryCreatedEvent和NotifyBusinessPartnerCreatedEvent具有自己的ApplicationArea。
我正在通过SoapUI发送消息:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:typ="http://csscp.procom.us/NotifyInboundDeliveryCreated/types">
<soap:Header/>
<soap:Body>
<typ:NotifyInboundDeliveryCreatedEvent>
<typ:ApplicationArea>
<typ:Service>SAP</typ:Service>
</typ:ApplicationArea>
</typ:NotifyInboundDeliveryCreatedEvent>
</soap:Body>
</soap:Envelope>
AND / OR
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:typ="http://csscp.procom.us/NotifyBusinessPartnerCreated/types">
<soap:Header/>
<soap:Body>
<typ:NotifyBusinessPartnerCreatedEvent>
<typ:ApplicationArea>
<typ:Service>BES</typ:Service>
</typ:ApplicationArea>
</typ:NotifyBusinessPartnerCreatedEvent>
</soap:Body>
</soap:Envelope>
我在Iterceptor中设置“服务”字段:
public class AreaInterceptor extends AbstractSoapInterceptor {
private SAAJInInterceptor saajIn = new SAAJInInterceptor();
public AreaInterceptor() {
super(Phase.PRE_INVOKE);
getAfter().add(SAAJInInterceptor.class.getName());
}
@Override
public void handleMessage(SoapMessage message) throws Fault {
SOAPMessage soapMessage = getSOAPMessage(message);
MessageContentsList contents = MessageContentsList.getContentsList(message);
Object content = contents.get(0);
ApplicationAreaType applicationArea = ((NotifyInboundDeliveryCreatedType) content).getApplicationArea();
applicationArea.setService("SAP");
}
private SOAPMessage getSOAPMessage(SoapMessage smsg){
SOAPMessage soapMessage = smsg.getContent(SOAPMessage.class);
if (soapMessage == null) {
saajIn.handleMessage(smsg);
soapMessage = smsg.getContent(SOAPMessage.class);
}
return soapMessage;
}
}
它适用于一个界面。但是我不能为两个或多个接口建立通用的拦截器。
相反:
ApplicationAreaType applicationArea = ((NotifyInboundDeliveryCreatedType) content).getApplicationArea();
,应该是这样的:
ApplicationAreaType applicationArea = ((Generics) content).getApplicationArea();
您有什么想法吗? 请帮忙。
有关CXF拦截器的更多信息: http://cxf.apache.org/docs/interceptors.html