javax.xml.bind.MarshalException - リンクされた例外: [javax.xml.stream.XMLStreamException: Can not output XML definition, after other output has already done.] .write(MarshallerImpl.java:330) at com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:178)
ここに私のコードスニペットがあります:
OutputStream output = new ByteArrayOutputStream();
XMLOutputFactory xof = XMLOutputFactory.newInstance();
XMLStreamWriter xsw = xof.createXMLStreamWriter(output);
QName root = new QName("return");
JAXBElement<Customer> je = new JAXBElement<Customer>(root, Customer.class, customer);
xsw.writeStartDocument();
xsw.setDefaultNamespace("S");
xsw.writeStartElement("S", "Envelope", "http://schemas.xmlsoap.org/soap/envelope/");
xsw.writeStartElement("S", "Body", "http://schemas.xmlsoap.org/soap/envelope/");
xsw.writeStartElement("ns0", "findCustomerResponse", "http://service.jaxws.blog/");
context = JAXBContext.newInstance(Customer.class);
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.marshal(je, xsw);
xsw.writeEndDocument();
xsw.close();
if(output != null)
return output.toString();
これが発生する理由はありますか?前もって感謝します