I apologize if this seems like a trivial question and will be quite happy if
there is a document that I overlooked....

First, some background. I have a wsdl and associated schemas for use in
creating a WS client. I have used wsgen to create the appropriate service
objects and objects from the schemas (via JAXB).
No problems getting the client and SOAP and calling the service (and passing
in the JAXB-generated objects).

Now, as part of the service security, the service provider is asking that I
add an element to the SOAP header. The element is in the schema I was
provided and the objects are included in the JAXB-generated objects.

So now I come to the question. Is there a way to add a JAXBElement to the
SOAP headers?\

I've gone down the path of creating an OutHandler and registering it with
the Service. I pass the data needed for the element into the Handler
constructor. Inside the OutHandler, I use the ObjectFactory class (from the
JAXB generated code) to give me appropariate object that holds my data
(populated with what I passed in). From there I can get a JAXBElement from
the Factory, as well.


Here is what the final SOAP header should look like:

<soap:Header xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/04/secext";>
   <wsse:Security>
       <gen:Data xmlns gen=" http://myschemas.org/generic";>
           <gen:DateTime>2006-12-02T10:10:10</gen:DateTime>
           <gen:Application>web</gen:Application>
           <gen:MoreData>blahblahblah</gen:MoreData>
           ....
       </gen:Data>
   </wsse:Security>
</soap:Header>

And here is the code I have so far:

public class DataOutHandler extends AbstractHandler {

   private DataType dataType = null;

   public DataOutHandler(DataType myDataType) {
       this.dataType = myDataType;
   }

    public void invoke(MessageContext ctx) throws Exception {
       Element header = ctx.getOutMessage().getHeader();
       Element secHeader = new Element("Security",
"http://schemas.xmlsoap.org/ws/2002/04/secext
");
       ObjectFactory genericFactory = new ObjectFactory();
       JAXBElement sender = commonFactory.createData(this.DataType);
   }
}

And that's where I'm stuck. Is there a way, short of manipulating a lot of
JDOM Elements, to use the JAXB classes/objects I already have to put this
content in the header?

Thanks in advance for any assistance,
Bubba

Reply via email to