implement XMLWriter e.g. look at this example for XMLStreamReader
org.apache.axis2.jibx.JibxDataSource
public XMLStreamReader getReader() throws XMLStreamException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
serialize(bos, null);
return StAXUtils.createXMLStreamReader(new
ByteArrayInputStream(bos.toByteArray()));
}
//the cast from bos to XML happens here
public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException {
try {
//get the ctx
IMarshallingContext ctx = bindingFactory.createMarshallingContext();
//get the response from supplied ctx
HttpServletResponse res = (HttpServletResponse)ctx
.getProperty(HTTPConstants.MC_HTTP_SERVLETRESPONSE);
//assume the writer is the outputStream from Response
OutputStream writer=response.getOutputStream();
boolean full=false;
// marshal with all namespace declarations, since external state
unknown
String[] nss = bindingFactory.getNamespaces();
IXMLWriter writer = new StAXWriter(nss, xmlWriter);
//set output writer for context
ctx.setXmlWriter(writer);
marshal(full, ctx);
..
}
private void marshal(boolean full, IMarshallingContext ctx) throws
JiBXException {
try {
//get the XMLWriter from ctx
IXMLWriter wrtr = ctx.getXmlWriter();
String name = elementName;
int nsidx = 0;
//all namespaces?
if (full)
{
// declare all namespaces on start tag
nsidx = elementNamespaceIndex;
wrtr.startTagNamespaces(nsidx, name, openNamespaceIndexes,
openNamespacePrefixes);
}
else
{ //get individual namespace
// configure writer with namespace declared in enclosing
scope
wrtr.openNamespaces(openNamespaceIndexes,
openNamespacePrefixes);
if (!"".equals(elementNamespacePrefix)) {
name = elementNamespacePrefix + ':' + name;
}
//only 1 so write at 0th position
wrtr.startTagOpen(0, name);
}
IMarshaller mrsh = ctx.getMarshaller(marshallerName);
// marshal object representation (may include attributes) into element
mrsh.marshal(dataObject, ctx);
wrtr.endTag(nsidx, name);
}
//at this point the data is there
ctx.getXmlWriter().flush();
} catch (IOException e)
{
throw new JiBXException("Error marshalling XML representation: " +
e.getMessage(), e);
}
}
but the client is not guaranteed to be able to parse either BOS or XML without
knowing the expected datatype you may want to consider receiving a ByteStream
in your xsd e.g.
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:ns1="http://org.apache.axis2/xsd"
xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl"
xmlns:ns="http://tempuri.org" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
targetNamespace="http://tempuri.org">
<wsdl:types>
<xs:schema attributeFormDefault="qualified"
elementFormDefault="qualified" targetNamespace="http://tempuri.org">
...........
<xs:element name="retByteArrayResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" nillable="true"
type="xs:base64Binary"/>
</xs:sequence>
</xs:complexType>
</xs:element>
...............
</xs:schema>
<wsdl:message name="retByteArrayResponse">
<wsdl:part name="parameters" element="ns:retByteArrayResponse"/>
</wsdl:message>
...
</wsdl:types>
ciao
Martin
______________________________________________
Verzicht und Vertraulichkeitanmerkung
Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger
sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung
oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem
Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung.
Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung
fuer den Inhalt uebernehmen.
Subject: set body message with xml file content
Date: Wed, 5 Aug 2009 12:01:04 +0200
From: [email protected]
To: [email protected]
Hi ,
I'm not able to set body of soap message with a xml file content previously
saved !!
I must save body content to re-send,in fault case ... Can I set body message,
directly, without use setXxxx method of object ?
HEEEEEEELLLLP.... .
Thank in advance !!
Alex
==================
code used to get body serialized (xml) from message.
ConfirmOpResponse confirm = new ConfirmOpResponse ();
confirm.setCodiceEsito(new CodiceEsito_type1(esito, true));
DescrizioneEsito_type1 descr = new DescrizioneEsito_type1();
descr.setDescrizioneEsito_type0(descrizione);
confirm.setDescrizioneEsito(descr);
try {
OMElement confOp = confirm.getOMElement(ConfirmOpResponse .MY_QNAME,
OMAbstractFactory.getOMFactory());
serializedObj= confOp.toString();
System.out.println(serializedObj); ---- print xml
} catch (ADBException e) {
e.printStackTrace();
}
_________________________________________________________________
Get your vacation photos on your phone!
http://windowsliveformobile.com/en-us/photos/default.aspx?&OCID=0809TL-HM