I've hacked around with JaxbTypeto force it to work. It's ugly, but works.
Basically, needed
1) new QName(part.getName().getLocalPart()) in order to forget the
targetNamespace
2) Use DOM to modify the element
3) StaxUtils to dump DOM tree to the writer.
cheers,
Jamie
Here's the writeObject method:
@SuppressWarnings("unchecked")
public void writeObject(Object object, MessageWriter writer,
MessageContext context)
throws XFireFault
{
try
{
JAXBContext jc = getJAXBContext(context);
Marshaller m = jc.createMarshaller();
m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
m.setAttachmentMarshaller(new AttachmentMarshaller(context));
// check if validation is enabled
boolean validationEnabled = Boolean.valueOf((String)
context.getContextualProperty(ENABLE_VALIDATION));
boolean responseValidation = Boolean.valueOf((String)
context.getContextualProperty(ENABLE_RESPONSE_VALIDATION));
if (validationEnabled || responseValidation) {
m.setSchema(getValidationSchema(context, jc));
}
if (isAbstract())
{
MessagePartInfo part = (MessagePartInfo)
context.getProperty(
AegisBindingProvider.CURRENT_MESSAGE_PART);
object = new JAXBElement(new
QName(part.getName().getLocalPart()),
getTypeClass(), object);
}
XMLStreamWriter xsw = ((ElementWriter)
writer).getXMLStreamWriter();
OutputStream os = (OutputStream) context.getOutMessage
().getProperty(Channel.OUTPUTSTREAM);
if (os != null && !(xsw instanceof DOMStreamWriter))
{
xsw.writeCharacters("");
xsw.flush();
m.setProperty(Marshaller.JAXB_ENCODING,
context.getOutMessage().getEncoding());
m.marshal(object, os);
}
else
{
xsw = ((ElementWriter) writer).getXMLStreamWriter();
Document doc = dbf.newDocumentBuilder().newDocument();
m.marshal(object,doc);
org.w3c.dom.Element el = (org.w3c.dom.Element)
doc.getFirstChild();
el.setAttribute("xmlns", "");
STAXUtils.writeDocument(doc, xsw, Boolean.TRUE.equals(
context.getProperty(SoapSerializer.SERIALIZE_PROLOG)), false);
}
}
catch (JAXBException e)
{
throw new XFireFault("Could not marshall type.", e,
XFireFault.RECEIVER);
}
catch (XMLStreamException e)
{
throw new XFireFault("Could not marshall type.", e,
XFireFault.RECEIVER);
}
catch (Exception e)
{
throw new XFireFault("Could not marshall type.", e,
XFireFault.RECEIVER);
}
}
On 1/17/07, Benson Margulies <[EMAIL PROTECTED]> wrote:
I've filed a JIRA or two. It's very difficult to control the namespace
prefixes in Xfire.
Why do you want to? So long as they correspond correctly to their
definitions in the header, no compliant implementation should care.
------------------------------
*From:* Jamie Lister [mailto:[EMAIL PROTECTED]
*Sent:* Tuesday, January 16, 2007 6:36 PM
*To:* [email protected]
*Subject:* [xfire-user] Re: Namespace in Soap body breaks client
Further to previous post.
I use RPC/Literal/Bare style, annotated service. The JSR181 specification
on WebParam namespaces indicate there should not be any WebParam namespace
for my style (only for document, or if parameter is header). Could my
problem be a bug? Also, If I explicitly annotate with targetNamespace=""
then it still puts a namespace on the "demand" parameter (see example
Soap:Body). The demand parameter is an ArrayOfDemand type.
i also tried binding XmlBeans, with almost identical results.
cheers,
Jamie
targetNamespace (Web Services Metadata for the
JavaTM Platform - JSR181 PDF)
The XML namespace for the
parameter.
Only used if the operation is
document style or the paramater
maps to a header.
If the target namespace is set to "",
this represents the empty
namespace.
The empty namespace,
if the operation is
document style, the
parameter style is
WRAPPED, and the
parameter does not map
to a header.
Otherwise, the default is
the targetNamespace for
the Web Service.
On 1/16/07, *Jamie Lister* <[EMAIL PROTECTED]> wrote:
Hi,
I have an Xfire-client that connects to a .NET service.
Xfire/JAXB produces the following soap body, is the embedded namespace
"ns2" necessary? Or even correct?
<soap:Body>
<GetBestAvailable xmlns="http://services.softix.com/nlsr/">
<performanceId xmlns="">EBEC2007637</performanceId>
<categoryId xmlns="">@0</categoryId>
<ns2:demand xmlns:ns2=" http://services.softix.com/nlsr/">
<Demand>
<typeId>A</typeId>
<quantity>2</quantity>
</Demand>
</ns2:demand>
</GetBestAvailable>
</soap:Body>
This request breaks the .NET service.
Whereas the .NET client produces this:
<soap:Body>
<GetBestAvailable xmlns=" http://services.softix.com/nlsr/">
<performanceId xmlns="">EBEC2007637</performanceId>
<categoryId xmlns="">@0</categoryId>
<demand xmlns="">
<Demand>
<typeId>A</typeId>
<quantity>2</quantity>
</Demand>
</demand>
</GetBestAvailable>
</soap:Body>
cheers,
Jamie