axis-java-dev mailing list archives

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

Hi, 
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="http://xyz.com/",
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,
false); 
StAXOMBuilder stAXOMBuilder = 
OMXMLBuilderFactory.createStAXOMBuilder( 
OMAbstractFactory.getOMFactory(), new StreamWrapper(xr)); 
OMElement documentElement = stAXOMBuilder.getDocumentElement(); 
 if (documentElement != null) { 
     bodyContent.addChild(documentElement); 
  } 

****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
definition. 

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
string. 

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
StAXUtils.createXMLStreamReader(inStream); 


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
text 
-----------------------------------------------------------------------------------------------------------

    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
NamespacePrefixMapper()); 
            os = new ByteArrayOutputStream(); 
            writer = new XMLStreamWriterWithOS(os, "utf-8"); 
            writer.setNamespaceContext(new NamespaceContext()); 
            m.marshal(response, writer); 
            bais = new
ByteArrayInputStream(((ByteArrayOutputStream)writer.getOutputStream()).toByteArray()); 
            StAXBuilder builder = BuilderUtil.getBuilder(bais); 
            OMElement documentElement =  builder.getDocumentElement(); 


Any help really appreciated. 

Thanks, 
Sridhar

-- 
View this message in context: http://old.nabble.com/JAXB-util-creating-OMElement-based-on-annotations-tp31605487p31605487.html
Sent from the Axis - Dev mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@axis.apache.org
For additional commands, e-mail: java-dev-help@axis.apache.org


Mime
View raw message