简体   繁体   中英

Spring boot WS: Is posible remove all attachments from a instance of MessageContext class?

I have developed a WS with Spring boot. In the interceptor I want to modify the request and delete all attachments. I have tried the following:

public boolean handleRequest(MessageContext messageContext, Object endpoint) throws Exception {
    WebServiceMessage requestReceived = messageContext.getRequest();
    if (requestReceived instanceof SaajSoapMessage) {
        SaajSoapMessage message = ((SaajSoapMessage) requestReceived);
        message.getAttachments().remove();
    }
    return true;
}

but remove() is not supported in that iterator.

Is it possible to delete all attachments?

Cheers

I haven't tried this myself, but the way you are trying to remove the attachments does not seem to be right. Ideally you get an iterator and use it to iterate over the elements and deleting the ones you desire (in your case 'all' elements). Something like below:

if (requestReceived instanceof SaajSoapMessage) {
    SaajSoapMessage message = ((SaajSoapMessage) requestReceived);
    Iterator<Attachment> itr = message.getAttachments();

    while(itr.hasNext()) {
        itr.next();
        itr.remove();
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM