Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-6062

Interceptors added in Spring Bus configuration are ignored

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 3.0.2
    • Fix Version/s: 3.0.3
    • Component/s: Bus
    • Labels:
      None
    • Estimated Complexity:
      Unknown

      Description

      Given a basic spring bus configuration like the following:

      ...
      <bean id="logInbound" class="org.apache.cxf.interceptor.LoggingInInterceptor"/>
      <bean id="logOutbound" class="org.apache.cxf.interceptor.LoggingOutInterceptor"/>
       
          <cxf:bus>
              <cxf:inInterceptors>
                  <ref bean="logInbound"/>
              </cxf:inInterceptors>
              <cxf:outInterceptors>
                  <ref bean="logOutbound"/>
              </cxf:outInterceptors>
              <cxf:outFaultInterceptors>
                  <ref bean="logOutbound"/>
              </cxf:outFaultInterceptors>
              <cxf:inFaultInterceptors>
                  <ref bean="logInbound"/>
              </cxf:inFaultInterceptors>
          </cxf:bus> 
      ...
      

      the logInbound and logOutbound interceptors are not added to the bus, when the spring configuration is parsed.

      I think the problem is in BusDefinitionParser.java, more specifically in the setBus method of BusConfig class.

      public void setBus(Bus bb) {
          if (bus == bb) {
              return;
          }
          bus = bb;
          if (properties != null) {
              bus.setProperties(properties);
              properties = null;
          }
          if (!getInInterceptors().isEmpty()) {
              bus.getInInterceptors().addAll(getInInterceptors());
          }
          if (!getOutInterceptors().isEmpty()) {
              bus.getOutInterceptors().addAll(getOutInterceptors());
          }
          if (!getInFaultInterceptors().isEmpty()) {
              bus.getInFaultInterceptors().addAll(getInFaultInterceptors());
          }
          if (!getOutFaultInterceptors().isEmpty()) {
              bus.getOutFaultInterceptors().addAll(getOutFaultInterceptors());
          }
          if (!StringUtils.isEmpty(id)) {
              bus.setId(id);
          }
          if (features != null) {
              bus.setFeatures(features);
              features = null;
          }
      }
      

      If the bus is assigned at the beginning of the method (bus = bb) no new Interceptor will be added as the getXYZInterceptors methods will return the interceptors already included in the bus.

      public List<Interceptor<? extends Message>> getXYZInterceptors() {
                  if (bus != null) {
                      return bus.getXYZInterceptors();
                  }
                  return super.getXYZInterceptors();
      }
      

      A fix could be something along the line of:

      public void setBus(Bus bb) {
          if (bus == bb) {
              return;
          }
          
          if (properties != null) {
              bb.setProperties(properties);
              properties = null;
          }
          if (!getInInterceptors().isEmpty()) {
              bb.getInInterceptors().addAll(getInInterceptors());
          }
          if (!getOutInterceptors().isEmpty()) {
              bb.getOutInterceptors().addAll(getOutInterceptors());
          }
          if (!getInFaultInterceptors().isEmpty()) {
              bb.getInFaultInterceptors().addAll(getInFaultInterceptors());
          }
          if (!getOutFaultInterceptors().isEmpty()) {
              bb.getOutFaultInterceptors().addAll(getOutFaultInterceptors());
          }
          if (!StringUtils.isEmpty(id)) {
              bb.setId(id);
          }
          if (features != null) {
              bb.setFeatures(features);
              features = null;
          }
          bus = bb;
      }
      

        Attachments

          Activity

            People

            • Assignee:
              dkulp Daniel Kulp
              Reporter:
              stojil Andrea Silva
            • Votes:
              2 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: