Never mind, I found the solution. If any one come across this problem using
the following to fix the issue.

            boolean isSOAP11=outMessage.isSOAP11();
            JAXBContext jaxbContext = JAXBContext.newInstance(new Class<?>[]
{response.getClass()}, properties);             
            JAXBBlockContext context = new JAXBBlockContext(jaxbContext);       
        
            BlockFactory blkFactory = (JAXBBlockFactory)
FactoryRegistry.getFactory(JAXBBlockFactory.class);
            Block block = blkFactory.createFrom(response, context, null);
            
            MessageFactory msgFactory = (MessageFactory)
FactoryRegistry.getFactory(MessageFactory.class);
            Message msg = null;
            
            if(isSOAP11){
                msg = msgFactory.create(Protocol.soap11);
            }else{
                msg = msgFactory.create(Protocol.soap12);
            }
            SOAPEnvelope soapOM = (SOAPEnvelope) msg.getAsOMElement();
           
soapOM.declareNamespace(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, new
NamespaceContext().getPrefix(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI));
            msg.setBodyBlock(block);
            msg.setMTOMEnabled(true);
            
            OMOutputFormat format = new OMOutputFormat();
            format.setDoOptimize(true);
            if(isSOAP11){
                format.setSOAP11(true);
            }else{
                format.setSOAP11(false);
            }
            
                   
            baos = new ByteArrayOutputStream();
            soapOM.serializeAndConsume(baos, format);
            return soapOM;


Thanks,
Sridhar

Sridhar Dabbeeru wrote:
> 
> 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-tp31605475p31634766.html
Sent from the Axis - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to