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

org.apache.cxf.interceptor.StaxOutInterceptor uses StAX API incorrectly

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.1
    • Fix Version/s: 2.1.1
    • Component/s: Core
    • Labels:
      None

      Description

      Method StaxOutInterceptor.handleMessage(Message msg) calls javax.xml.stream.XMLStreamWriter.writeStartDocument(String) assuming that the string arg denotes the xml encoding while the StAX javadoc says it denotes the xml version. There's another variant that has two inputs javax.xml.stream.XMLStreamWriter.writeStartDocument(String encoding, String version) that should be used instead.

      The snippet below highlights the erroneous api call:

       
       public void handleMessage(Message message) {
              OutputStream os = message.getContent(OutputStream.class);
              XMLStreamWriter writer = message.getContent(XMLStreamWriter.class);
              if (os == null || writer != null) {
                  return;
              }
              // assert os != null;
      
              // TODO: where does encoding constant go?
              String encoding = getEncoding(message);
              
              try {
                  writer = getXMLOutputFactory(message).createXMLStreamWriter(os, encoding);
                  if (Boolean.TRUE.equals(message.getContextualProperty(FORCE_START_DOCUMENT))) {
                      writer.writeStartDocument(encoding);  /*<=====================================================================THIS IS THE ERRONEOUS API CALL*/
                  }
              } catch (XMLStreamException e) {
                  throw new Fault(new org.apache.cxf.common.i18n.Message("STREAM_CREATE_EXC", BUNDLE), e);
              }
              message.setContent(XMLStreamWriter.class, writer);
      
              // Add a final interceptor to write end elements
              message.getInterceptorChain().add(ending);
          }
      

        Attachments

          Activity

            People

            • Assignee:
              bmargulies Benson Margulies
              Reporter:
              lipkap Pawel Lipka
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: