Search in sources :

Example 1 with MtomStreamWriter

use of org.jvnet.staxex.util.MtomStreamWriter in project metro-jax-ws by eclipse-ee4j.

the class JAXBMessage method writePayloadTo.

@Override
public void writePayloadTo(XMLStreamWriter sw) throws XMLStreamException {
    try {
        // MtomCodec sets its own AttachmentMarshaller
        AttachmentMarshaller am = (sw instanceof MtomStreamWriter) ? ((MtomStreamWriter) sw).getAttachmentMarshaller() : new AttachmentMarshallerImpl(attachmentSet);
        // Get the encoding of the writer
        String encoding = XMLStreamWriterUtil.getEncoding(sw);
        // Get output stream and use JAXB UTF-8 writer
        OutputStream os = bridge.supportOutputStream() ? XMLStreamWriterUtil.getOutputStream(sw) : null;
        if (rawContext != null) {
            Marshaller m = rawContext.createMarshaller();
            m.setProperty("jaxb.fragment", Boolean.TRUE);
            m.setAttachmentMarshaller(am);
            if (os != null) {
                m.marshal(jaxbObject, os);
            } else {
                m.marshal(jaxbObject, sw);
            }
        } else {
            if (os != null && encoding != null && encoding.equalsIgnoreCase(SOAPBindingCodec.UTF8_ENCODING)) {
                bridge.marshal(jaxbObject, os, sw.getNamespaceContext(), am);
            } else {
                bridge.marshal(jaxbObject, sw, am);
            }
        }
    // cleanup() is not needed since JAXB doesn't keep ref to AttachmentMarshaller
    // am.cleanup();
    } catch (JAXBException e) {
        // bug 6449684, spec 4.3.4
        throw new WebServiceException(e);
    }
}
Also used : AttachmentMarshaller(jakarta.xml.bind.attachment.AttachmentMarshaller) Marshaller(jakarta.xml.bind.Marshaller) AttachmentMarshaller(jakarta.xml.bind.attachment.AttachmentMarshaller) WebServiceException(jakarta.xml.ws.WebServiceException) OutputStream(java.io.OutputStream) JAXBException(jakarta.xml.bind.JAXBException) MtomStreamWriter(org.jvnet.staxex.util.MtomStreamWriter)

Example 2 with MtomStreamWriter

use of org.jvnet.staxex.util.MtomStreamWriter in project metro-jax-ws by eclipse-ee4j.

the class JAXBDispatchMessage method writeTo.

@Override
@SuppressWarnings("unchecked")
public void writeTo(XMLStreamWriter sw) throws XMLStreamException {
    try {
        // MtomCodec sets its own AttachmentMarshaller
        AttachmentMarshaller am = (sw instanceof MtomStreamWriter) ? ((MtomStreamWriter) sw).getAttachmentMarshaller() : new AttachmentMarshallerImpl(attachmentSet);
        // Get the encoding of the writer
        String encoding = XMLStreamWriterUtil.getEncoding(sw);
        // Get output stream and use JAXB UTF-8 writer
        OutputStream os = bridge.supportOutputStream() ? XMLStreamWriterUtil.getOutputStream(sw) : null;
        if (rawContext != null) {
            Marshaller m = rawContext.createMarshaller();
            m.setProperty("jaxb.fragment", Boolean.FALSE);
            m.setAttachmentMarshaller(am);
            if (os != null) {
                m.marshal(jaxbObject, os);
            } else {
                m.marshal(jaxbObject, sw);
            }
        } else {
            if (os != null && encoding != null && encoding.equalsIgnoreCase(SOAPBindingCodec.UTF8_ENCODING)) {
                bridge.marshal(jaxbObject, os, sw.getNamespaceContext(), am);
            } else {
                bridge.marshal(jaxbObject, sw, am);
            }
        }
    // cleanup() is not needed since JAXB doesn't keep ref to AttachmentMarshaller
    } catch (JAXBException e) {
        // bug 6449684, spec 4.3.4
        throw new WebServiceException(e);
    }
}
Also used : AttachmentMarshaller(jakarta.xml.bind.attachment.AttachmentMarshaller) Marshaller(jakarta.xml.bind.Marshaller) AttachmentMarshaller(jakarta.xml.bind.attachment.AttachmentMarshaller) WebServiceException(jakarta.xml.ws.WebServiceException) OutputStream(java.io.OutputStream) JAXBException(jakarta.xml.bind.JAXBException) MtomStreamWriter(org.jvnet.staxex.util.MtomStreamWriter)

Aggregations

JAXBException (jakarta.xml.bind.JAXBException)2 Marshaller (jakarta.xml.bind.Marshaller)2 AttachmentMarshaller (jakarta.xml.bind.attachment.AttachmentMarshaller)2 WebServiceException (jakarta.xml.ws.WebServiceException)2 OutputStream (java.io.OutputStream)2 MtomStreamWriter (org.jvnet.staxex.util.MtomStreamWriter)2