将MimeUnmarshaller代码迁移到Spring 5

问题描述 投票:0回答:1

我有实现org.springframework.oxm.mimeMimeUnmarshaller的旧代码:

import javax.xml.bind.attachment.AttachmentUnmarshaller;
import javax.xml.transform.Source;
import org.springframework.oxm.UnmarshallingFailureException;
import org.springframework.oxm.XmlMappingException;
import org.springframework.oxm.mime.MimeContainer;
import org.springframework.oxm.mime.MimeUnmarshaller;
import org.springframework.xml.transform.StaxSource;

public class MISMarshaller implements MimeUnmarshaller {
    .
    .
    .
    public Object unmarshal(Source source, MimeContainer mimeContainer) throws XmlMappingException {
        AttachmentUnmarshaller au = null;
        if (this.mtomEnabled && mimeContainer != null) {
            au = new MISMarshaller.MISAttachmentUnmarshaller(mimeContainer);
        }

        if (source instanceof StaxSource && ((StaxSource)source).getXMLStreamReader() != null) {
            try {
                return this.context.unmarshal(au, ((StaxSource)source).getXMLStreamReader());
            } catch (Exception var5) {
                throw new UnmarshallingFailureException(var5.getMessage(), var5);
            }
        } else {
            throw new IllegalStateException(
                "Only StAX is supported for MIS marshaller.  Use AXIOM message factory.");
        }
    }
    .
    .
    .
}

我正在将该代码升级到Spring 5,并且类StaxSource不在Spring 5中。如何将其重写为在Spring 5中工作?

spring javax.xml
1个回答
0
投票
import org.springframework.util.xml.StaxUtils;
    .
    .
    .
            return this.context.unmarshal(au, StaxUtils.getXMLStreamReader(source));
© www.soinside.com 2019 - 2024. All rights reserved.