I've got an Axis webservice that I've been charged with moving to CXF.
The one thing that is confounding me is how to get the authentication info.
For example, this is the existing snippet in the Axis version:
MessageContext mc = MessageContext.getCurrentContext();
try {
authenticator.authenticate(mc.getUsername(),mc.getPassword());
...
operation=mc.getOperation().getName();
} catch(Exception e){
logger.warn("User authentication error - " + mc.getUsername());
throw new AxisFault(new QName(""),"User Authentication Error",
"getUser",new Element[]{});
}
Now as far as I've been able to find online, the "new" version should look
like:
@Resource private WebServiceContext context; // In the class definition
....
MessageContext mc = context.getMessageContext();
AuthorizationPolicy policy =
(AuthorizationPolicy)mc.get(AuthorizationPolicy.class);
try {
authenticator.authenticate(policy.getUsername(),policy.getPassword());
...
operation = ((QName)mc.get(Message.WSDL_OPERATION)).toString();
} catch(Exception e){
logger.warn("User authentication error - " + mc.getUsername());
throw new AxisFault(new QName(""),"User Authentication Error",
"getUser",new Element[]{});
}
But I am getting an exception thrown when getting the AuthorizationPolicy
like this:
AuthorizationPolicy policy =
(AuthorizationPolicy)mc.get(AuthorizationPolicy.class);
saying that "java.lang.Class cannot be cast to java.lang.String".
All of the examples I've seen online have the exact same code...what am I
doing wrong? I'm new to CXF so I'm sure it's something stupid. I'm using CXF
2.2.10.
--
View this message in context:
http://cxf.547215.n5.nabble.com/Moving-from-Axis-to-CXF-tp2653453p2653453.html
Sent from the cxf-user mailing list archive at Nabble.com.