I have a tomcat web service that accepts opentravel.org OTA XML requests and responds accordingly. It uses the JibX OTA classes.
So far the users of the service have used POX, and it works really well, but a new user wants to use SOAP and add security credentials to the SOAP Header like this (instead of putting them the POS xml fragment)...
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<wsse:Security soap:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org /wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>USERNAME</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401- wss-username-token-profile-1.0#PasswordText">SECRET</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soap:Header>
So to authenticate the request I think I need to access the headers from within the service implementation class.
I checked out the SOAP Headers example, which I think tells me that I can access the headers by also including a inContext, e.g.
public RoomListRS list(RoomListRQ roomListRQ, InContext inCtx){
....
}
so within this method I can do this...
Security security = (Security ) inCtx.getAttribute("security");
so I can access the username token within,
...having specified this in the service...
<service name="OTAService">
<service-class>com.xx.webservice.ota.HotelServiceImpl</service-class>
<operation method="list"/>
<handler-class class="org.jibx.ws.io.handler.ContextAttributeUnmarshallingInHandler">
<constructor-arg value="com.xx.shared.soap.security.Security"/>
<constructor-arg value="security"/>
</handler-class>
</service>
Have I got that right?
So I created the Security class, but left out all the namespace stuff to start with just to get going and prove that I can access something in the header. Based on having a fragment like this...
<Security>
<UsernameToken>
<Username>USERNAME</Username>
<Password>SECRET</Password>
</UsernameToken>
</Security>
So I created the binding with bindgen, then compiled, then called it with soapUI
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.opentravel.org/OTA/2003/05">
<soapenv:Header>
<Security>
<UsernameToken>
<Username>USERNAME</Username>
<Password>SECRET</Password>
</UsernameToken>
</Security>
</soapenv:Header>
<soapenv:Body>
<OTA_HotelRoomListRQ xmlns="http://www.opentravel.org/OTA/2003/05" Version="2.0">
....
</OTA_HotelRoomListRQ>
</soapenv:Body>
</soapenv:Envelope>
but when I try to get the Security object from the context it is null.
Have I got the wrong end of the stick?
Should I just create another service with a different endpoint using something more SOAPY?
Is what I am trying to do not possible with JibX WS and the inHandler?
Any comments most welcome.
thank you so much for taking the trouble to answer my question.
I am trying to go through what you have added. I used your customisation and the xsd to create the java source and binding.xml.
I have compiled the classes and I am now trying to bind them, but I am getting this error:
C:\Java\wsse>java org.jibx.binding.generator.BindGen org.oasisopen.docs.wss.oasis200401wsswssecuritysecext1.SecurityHeaderType
Exception in thread "main" java.lang.IllegalStateException: No way to handle type java.lang.Object, referenced from org.oasisopen.docs.wss.oasis200401wsswssecuritysecext1.SecurityHeaderType
at org.jibx.binding.generator.BindGen.expandReferences(BindGen.java:227)
at org.jibx.binding.generator.BindGen.findReferences(BindGen.java:1010)
at org.jibx.binding.generator.BindGen.generate(BindGen.java:1124)
at org.jibx.binding.generator.BindGen.main(BindGen.java:1302)
I am going to take a look at bindgen customisations to see if that sheds any light, as that's the only clue given in response to this issue. Could you tell me how you got around this?
Thanks again.