You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by Michael Ihde <mi...@randomwalking.com> on 2008/08/03 19:47:58 UTC

XMLBeans, Axiom, and Synapse/WSO2-ESB

I'm trying to see if I can use XMLBeans to deal with an Axiom SOAPBody.  The
following DeveloperWorks guide showed how to bring Axiom and XMLBeans
together:

http://www.ibm.com/developerworks/library/x-axiom/

So I tried to extend Sample 380 in WSO2-ESB and basically had this as the
first lines in my mediate() function:

XMLStreamReader reader =
mc.getEnvelope().getBody().getFirstElement().getFirstElement().getXMLStreamReaderWithoutCaching();
GetQuoteResponse resp = GetQuoteResponse.Factory.parse(reader);
System.out.println("Validate " + resp.validate());
System.out.println(resp.toString());

This is what prints out

Validate false
<ns:return type="samples.services.GetQuoteResponse" xmlns:ns="
http://services.samples/xsd">
  <ns:change>-2.8637862443067323</ns:change>
  <ns:earnings>-8.734540628084734</ns:earnings>
  <ns:high>-87.61828398040504</ns:high>
  <ns:last>89.13763928944611</ns:last>
  <ns:lastTradeTimestamp>Sun Aug 03 13:33:52 EDT
2008</ns:lastTradeTimestamp>
  <ns:low>-88.94988407359973</ns:low>
  <ns:marketCap>4141070.6717920825</ns:marketCap>
  <ns:name>IBM Company</ns:name>
  <ns:open>-88.72550360449267</ns:open>
  <ns:peRatio>25.296622152954335</ns:peRatio>
  <ns:percentageChange>-2.9624706336045223</ns:percentageChange>
  <ns:prevClose>96.6688483531829</ns:prevClose>
  <ns:symbol>IBM</ns:symbol>
  <ns:volume>5034</ns:volume>
</ns:return>

I believe the problem is because the return element is defined as having a
type of samples.services.GetQuoteResponse.  How do I get XMLBeans to accept
the return element so that I can perform a function such as resp.getLast()?

Am I completely off base?  Is there a better way to do this?

Thanks,
Michael

Re: XMLBeans, Axiom, and Synapse/WSO2-ESB

Posted by Michael Ihde <mi...@randomwalking.com>.
Radu,

mc is the MessageContext class from Apache Synapse
http://synapse.apache.org/apidocs/org/apache/synapse/MessageContext.html.
I'll try your debug steps to see if I can get any more information.

~Michael

On Tue, Aug 5, 2008 at 8:11 PM, Radu Preotiuc-Pietro <
radu.preotiuc-pietro@oracle.com> wrote:

>  Mike,
>
> What is "mc"? What Java class/API?
>
> I think you can do two things to debug this further:
> 1. Use XmlOptions.setErrorListener(Collection) to retrieve the error
> messages, then see what the specific error is (use the XmlOptions object as
> parameter to the resp.validate() call)
> 2. Capture the XML passed from the SOAP body to XMLBeans (before it gets to
> XMLBeans). Save it to a file and see if it looks ok (based on its
> Schema) and where the discrepancy is. I am thinking there are maybe some
> namespace bindings that don't make it across from the SOAP stack to
> XMLBeans, it's a possibility.
>
> Radu
>
>  ------------------------------
> *From:* mike.ihde@gmail.com [mailto:mike.ihde@gmail.com] *On Behalf Of *Michael
> Ihde
> *Sent:* Sunday, August 03, 2008 10:48 AM
> *To:* user@xmlbeans.apache.org
> *Subject:* XMLBeans, Axiom, and Synapse/WSO2-ESB
>
>  I'm trying to see if I can use XMLBeans to deal with an Axiom SOAPBody.
> The following DeveloperWorks guide showed how to bring Axiom and XMLBeans
> together:
>
> http://www.ibm.com/developerworks/library/x-axiom/
>
> So I tried to extend Sample 380 in WSO2-ESB and basically had this as the
> first lines in my mediate() function:
>
> XMLStreamReader reader =
> mc.getEnvelope().getBody().getFirstElement().getFirstElement().getXMLStreamReaderWithoutCaching();
> GetQuoteResponse resp = GetQuoteResponse.Factory.parse(reader);
> System.out.println("Validate " + resp.validate());
> System.out.println(resp.toString());
>
> This is what prints out
>
> Validate false
> <ns:return type="samples.services.GetQuoteResponse" xmlns:ns="
> http://services.samples/xsd">
>   <ns:change>-2.8637862443067323</ns:change>
>   <ns:earnings>-8.734540628084734</ns:earnings>
>   <ns:high>-87.61828398040504</ns:high>
>   <ns:last>89.13763928944611</ns:last>
>   <ns:lastTradeTimestamp>Sun Aug 03 13:33:52 EDT
> 2008</ns:lastTradeTimestamp>
>   <ns:low>-88.94988407359973</ns:low>
>   <ns:marketCap>4141070.6717920825</ns:marketCap>
>   <ns:name>IBM Company</ns:name>
>   <ns:open>-88.72550360449267</ns:open>
>   <ns:peRatio>25.296622152954335</ns:peRatio>
>   <ns:percentageChange>-2.9624706336045223</ns:percentageChange>
>   <ns:prevClose>96.6688483531829</ns:prevClose>
>   <ns:symbol>IBM</ns:symbol>
>   <ns:volume>5034</ns:volume>
> </ns:return>
>
> I believe the problem is because the return element is defined as having a
> type of samples.services.GetQuoteResponse.  How do I get XMLBeans to accept
> the return element so that I can perform a function such as resp.getLast()?
>
> Am I completely off base?  Is there a better way to do this?
>
> Thanks,
> Michael
>
>

RE: XMLBeans, Axiom, and Synapse/WSO2-ESB

Posted by Radu Preotiuc-Pietro <ra...@oracle.com>.
Mike,
 
What is "mc"? What Java class/API?
 
I think you can do two things to debug this further:
1. Use XmlOptions.setErrorListener(Collection) to retrieve the error messages, then see what the specific error is (use the XmlOptions object as parameter to the resp.validate() call)
2. Capture the XML passed from the SOAP body to XMLBeans (before it gets to XMLBeans). Save it to a file and see if it looks ok (based on its Schema) and where the discrepancy is. I am thinking there are maybe some namespace bindings that don't make it across from the SOAP stack to XMLBeans, it's a possibility.
 
Radu


________________________________

	From: mike.ihde@gmail.com [mailto:mike.ihde@gmail.com] On Behalf Of Michael Ihde
	Sent: Sunday, August 03, 2008 10:48 AM
	To: user@xmlbeans.apache.org
	Subject: XMLBeans, Axiom, and Synapse/WSO2-ESB
	
	
	I'm trying to see if I can use XMLBeans to deal with an Axiom SOAPBody.  The following DeveloperWorks guide showed how to bring Axiom and XMLBeans together:
	
	http://www.ibm.com/developerworks/library/x-axiom/
	
	So I tried to extend Sample 380 in WSO2-ESB and basically had this as the first lines in my mediate() function:
	
	XMLStreamReader reader = mc.getEnvelope().getBody().getFirstElement().getFirstElement().getXMLStreamReaderWithoutCaching();
	GetQuoteResponse resp = GetQuoteResponse.Factory.parse(reader);
	System.out.println("Validate " + resp.validate());
	System.out.println(resp.toString());
	
	This is what prints out
	
	Validate false
	<ns:return type="samples.services.GetQuoteResponse" xmlns:ns="http://services.samples/xsd">
	  <ns:change>-2.8637862443067323</ns:change>
	  <ns:earnings>-8.734540628084734</ns:earnings>
	  <ns:high>-87.61828398040504</ns:high>
	  <ns:last>89.13763928944611</ns:last>
	  <ns:lastTradeTimestamp>Sun Aug 03 13:33:52 EDT 2008</ns:lastTradeTimestamp>
	  <ns:low>-88.94988407359973</ns:low>
	  <ns:marketCap>4141070.6717920825</ns:marketCap>
	  <ns:name>IBM Company</ns:name>
	  <ns:open>-88.72550360449267</ns:open>
	  <ns:peRatio>25.296622152954335</ns:peRatio>
	  <ns:percentageChange>-2.9624706336045223</ns:percentageChange>
	  <ns:prevClose>96.6688483531829</ns:prevClose>
	  <ns:symbol>IBM</ns:symbol>
	  <ns:volume>5034</ns:volume>
	</ns:return>
	
	I believe the problem is because the return element is defined as having a type of samples.services.GetQuoteResponse.  How do I get XMLBeans to accept the return element so that I can perform a function such as resp.getLast()?
	
	Am I completely off base?  Is there a better way to do this?
	
	Thanks,
	Michael