axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sridhar Dabbeeru <>
Subject JAXB util creating OMElement based on annotations
Date Thu, 12 May 2011 19:09:53 GMT

We are enabling MTOM capability to our software using axis2 webservice
stack. Having said that, we have situation where our service POJO contains
mixed attributes some of them are JAXB annotated like
(@XmlElement(name="serialNumber", namespace="",
type=String.class, nillable=true, required=false) and rest of them are plain
simple attributes, utility methods etc.. 

Among these attributes we have also a datahanlder attribute to send MTOM
attachment on webservice response. 

*******In axis2 RPCUtil processResponse operation we use the following the
code snippet to create the response 

OMElement.XMLStreamReader xr =
BeanUtil.getPullParser(resObject,returnWrapper, typeTable, qualified,
StAXOMBuilder stAXOMBuilder = 
OMAbstractFactory.getOMFactory(), new StreamWrapper(xr)); 
OMElement documentElement = stAXOMBuilder.getDocumentElement(); 
 if (documentElement != null) { 

****Now when I use this, the response POJO object MTOM attachments are going
fine on webservice response but it is also including all attributes which
are not annotated with @XmlElement and these are not included in the WSDL

If understand this correct, getPullParser doesn't understand JaxB
annotations so that's why it is not distinguishing between these different
attributes though they are JAXB annotated. 

If use our plain old JAXB marshall approach, the generated stream contains
expected annotated XML elements but flattens file attachment as Base64 text

Now I need to create an OMElement using this stream to enable the axis2
transport layer to create appropriate webservice response with all Mime
headers and respective parts. 

*****This is where I am having problem. Since the object is already
marshalled, the generated XML is doesn't have the context of base64 vs
normal string. 

I tried using StAXBuilder builder = BuilderUtil.getBuilder(bais); but this
doesn't create OMTextImpl with binary option it treats everthing as text
because underneath we use the following

Long story short. 

I don't want to use jaxb marshalling in between, without doing that do we
have any utility that can understand various JAXB annoations and create an
OMElment that can distinguish between binary vs text. Essentially
CommonsHtttpTransportSender should be able create the response with all MIME
headers, parts with XOP include. 

Following is the JAXB Marshalling Approach, but sends attachment as bas64

    JAXBContext jaxbContext = JAXBContext.newInstance(new Class<?>[]
{response.getClass()}, properties); 
            Marshaller m = jaxbContext.createMarshaller();             
            m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); 
            m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.FALSE); 
            m.setProperty("com.sun.xml.bind.namespacePrefixMapper", new
            os = new ByteArrayOutputStream(); 
            writer = new XMLStreamWriterWithOS(os, "utf-8"); 
            writer.setNamespaceContext(new NamespaceContext()); 
            m.marshal(response, writer); 
            bais = new
            StAXBuilder builder = BuilderUtil.getBuilder(bais); 
            OMElement documentElement =  builder.getDocumentElement(); 

Any help really appreciated. 


View this message in context:
Sent from the Axis - Dev mailing list archive at

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message