Как я могу сделать динамическое приведение от одного типа к другому в Apache CXF Interceptor? Джава - PullRequest
0 голосов
/ 23 апреля 2019

Я хотел бы сделать динамическое приведение для 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>

И / ИЛИ

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

Я установил поле Сервис в итерцепторе:

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

...