I am invokeing jsr181 service 'A' from another jsr181 service 'B' via
servicemix-http provider BC. The request parameter classes are generated by
JAX-WS wsimport tool, and marshaling generates xml string with imcomplete
namespace assignment as below, and service 'A' didn't get these request
values.
marshaling code is
JAXBContext jaxbCtx = JAXBContext.newInstance(new
Class[]{GetItemPriceForQty.class});
Marshaller marshaller = jaxbCtx.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
StringWriter writer = new StringWriter();
marshaller.marshal(req, writer);
String xmlStr = writer.toString();
marshaled string is:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:getItemPriceForQty
xmlns:ns2="http://v1.americas.priceinquiry.partnercontract.master.optionzero.sf.net">
<in>
<item>
<itemCode>555AAA888</itemCode>
</item>
<partner>
<partnerCode>ZZZ-111</partnerCode>
</partner>
<qty>10</qty>
</in>
</ns2:getItemPriceForQty>
I thing all the elements should have namespace, so I wrote another
invocation with static string with namespace as below, then service 'A' got
the request values properly.
String xmlStr = "<q0:getItemPriceForQty
xmlns:q0=\"http://v1.americas.priceinquiry.partnercontract.master.optionzero.sf.net\"><q0:itemPrice><q0:item><q0:itemCode>1111A222BB</q0:itemCode></q0:item><q0:partner><q0:partnerCode>BH01</q0:partnerCode></q0:partner><q0:qty>100</q0:qty></q0:itemPrice></q0:getItemPriceForQty>"
The invocation code I wrote is:
QName serviceQName = new QName(serviceNS, serviceName);
DeliveryChannel channel = context.getDeliveryChannel();
MessageExchangeFactory factory =
channel.createExchangeFactoryForService(serviceQName);
InOut inOutExch = factory.createInOutExchange();
NormalizedMessage reqMsg = inOutExch.createMessage();
reqMsg.setContent(new StreamSource(new StringReader(xmlStr)));
inOutExch.setInMessage(reqMsg);
boolean result = channel.sendSync(inOutExch);
Also, even service 'B' got appropriate result by getting static XML string I
mentioned above, JAXB unmarshaler cannot map it to Object tree, only the
outermost object was created.
Here is the code to unmarshal:
jaxbCtx = JAXBContext.newInstance(new
Class[]{GetItemPriceForQtyResponse.class});
Unmarshaller unmarshaller = jaxbCtx.createUnmarshaller();
GetItemPriceForQtyResponse resp = (GetItemPriceForQtyResponse)
unmarshaller.unmarshal(strReader);
Am I doing something wrong?
Since no JAXB marshal/unmarshal example is in the distribution,
I was wondering how people are doing this XML-Object mapping task?
Tak
--
View this message in context:
http://www.nabble.com/JAXB-marshal-unmarshal-doesn%27t-work-properly-tf2017370.html#a5546401
Sent from the ServiceMix - User forum at Nabble.com.