users@jaxb.java.net

RE: RE: How to marshal hexBinary correctly?

From: Liu, Jervis <jliu_at_iona.com>
Date: Tue, 31 Jul 2007 11:54:33 -0400

Actually the hexBinary is a type defined in my WSDL file, e.g.;

<wsdl:message name="inoutSimpleTypesRequest">
    <wsdl:part name="varHexBinary" type="xsd:hexBinary" />
</wsdl:message>
<wsdl:message name="inoutSimpleTypesResponse">
    <wsdl:part name="varBase64Binary" type="xsd:base64Binary" />
</wsdl:message>
  
<wsdl:portType name="GreeterRPCLit">
    <wsdl:operation name="echoInOutSimpleTypes">
        <wsdl:input message="tns:inoutSimpleTypesRequest" />
        <wsdl:output message="tns:inoutSimpleTypesResponse" />
    </wsdl:operation>
</wsdl:portType>

When I call
byte arg[] = {-128, 0, 127};
greeter.echoInOutSimpleTypes(arg);

I need to marshal arg into a XML element wrapped with SOAP envelop like this:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns1:echoInOutSimpleTypes xmlns:ns1="http://apache.org/hello_world_rpclit
<varHexBinary xmlns:ns2="http://apache.org/hello_world_rpclit/types">gAB/</varHexBinary>
</ns1:echoInOutSimpleTypes></soap:Body></soap:Envelope>
 
Obviously there is no such a class called Bytes available anywhere. I guess using new HexBinaryAdapter().marshal(arg); should work, but it would look very weird, and I have to generate the <varHexBinary xmlns:ns2="http://apache.org/hello_world_rpclit/types"> element by myself, doesn't sound like the right way to go. It must some JAXB APIs I can use so that when I call jm.marshal(new JAXBElement(new QName("myns", "myHexBinary"), arg.getClass(), arg), System.out); I can tell JAXB my input is a byte array and expected XML type is hexBinary, so please do the correct marshal for me.

Thanks,
Jervis

-----Original Message-----
From: Ernst, Matthias [mailto:matthias.ernst_at_coremedia.com]
Sent: 2007?7?31? 23:03
To: users_at_jaxb.dev.java.net
Subject: RE: How to marshal hexBinary correctly?


Jervis,

> However in my case, I do not have any Java type classes,
> thus there is no way to have an annotation.

Then what kind of output do you expect? A string? Then
It's no XML and you can just use:

  new HexBinaryAdapter().marshal(arg);

Otherwise, you need a class where you can annotate the hexbinary child/attribute.

public class Bytes {
  @XmlValue @XmlJavaTypeAdapter(HexBinaryAdapter.class) public byte[] value;
}

Matthias
-- 
matthias.ernst_at_coremedia.com
software architect
+49.40.32 55 87.503
CoreMedia AG
Executive Board: Sören Stamer (CEO), Dr. Klemens Kleiminger (CFO)
Supervisory Board: Prof. Dr. Joachim Schmidt (Chairman)
Trade Register: Amtsgericht Hamburg, HR B 76277
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net
----------------------------
IONA Technologies PLC (registered in Ireland)
Registered Number: 171387
Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland