You are viewing a plain text version of this content. The canonical link for it is here.
Posted to rampart-dev@ws.apache.org by prashantp <pr...@four-soft.com> on 2007/08/08 08:54:22 UTC

WSHandler: cannot create instance of password callback

Hi,
      I am a new bie to axis2 and rampart. I am using tomcat and axis2-1.2.
I am trying to secure a web service using username token
 
My service is as follows:
 
public class MyHello {
    public String sayHello(String s){
        return "HELLO"+" "+s;
    } }
 
CallbackHandler is as follows :
 
public class PwdCallBackHandler implements CallbackHandler{
        public void handle(Callback[] callbacks) throws
IOException,UnsupportedCallbackException {
                for (int i = 0; i < callbacks.length; i++) {
                         WSPasswordCallback pwcb =
(WSPasswordCallback)callbacks[i];
                                  String id = pwcb.getIdentifer();
                                           if("myname".equals(id)) {
 
pwcb.setPassword("password");
                                                                 } } }
 
service.xml looks as follows:
 
<service name="MyHello" >
 <description>
  Sample Web Service for Username Token
 </description>
 <operation name="sayHello">
  <messageReceiver
class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
 </operation>
 <parameter name="ServiceClass" locked="false">testpack.MyHello</parameter>
 <module ref="rampart" />
 <parameter name="InflowSecurity">
      <action>
        <items>UsernameToken Timestamp</items>
 
<passwordCallbackClass>testpack.PwdCallBackHandler</passwordCallbackClass>
  <passwordType>passwordDigest</passwordType>
      </action>
    </parameter>
</service>

I also created client.axis2.xml similar to given in samples where i changed
the existing values to:

<module ref="rampart" />
  <parameter name="OutflowSecurity">
     <action>
         <items>UsernameToken Timestamp</items>
         <user>myname</user>
 
<passwordCallbackClass>testpack.PwdCallBackHandler</passwordCallbackClass>
       </action>
    </parameter>

I created stubs for my service. my Client is as follows:

public class MyHelloClient{
 public static void main(String[] args) {
  try{
        MyHelloMyHelloSOAP11PortStub stub = new
MyHelloMyHelloSOAP11PortStub("
<http://localhost:8080/axis2/services/MyHello>
http://localhost:8080/axis2/services/MyHello");
       MyHelloMyHelloSOAP11PortStub.SayHello sayHello = new
MyHelloMyHelloSOAP11PortStub.SayHello();
       sayHello.setS("bob");
       MyHelloMyHelloSOAP11PortStub.SayHelloResponse resp =
stub.sayHello(sayHello);
       System.out.println("Response from Web Service
-->"+resp.get_return());
}catch(Exception ex){
    ex.printStackTrace();
   }}


I get the following exception when i run the client :

org.apache.axis2.AxisFault: WSHandler: cannot create instance of password
callback: testpack.PwdCallBackHandler; nested exception is: 

java.lang.ClassCastException: testpack.PwdCallBackHandler

at
org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:434
)

at
org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperatio
n.java:373)

at
org.apache.axis2.description.OutInAxisOperationClient.execute(OutInAxisOpera
tion.java:294)

at
testpack.MyHelloMyHelloSOAP11PortStub.sayHello(MyHelloMyHelloSOAP11PortStub.
java:151)

at testpack.MyHelloClient.main(MyHelloClient.java:28)
 
 
"The information contained in this communication is intended solely for the use of the individual or entity to whom it is addressed and others authorized to receive it. It may contain confidential or legally privileged information and may not be disclosed to anyone else. If you are not the intended recipient you are hereby notified that any disclosure, copying, distribution or taking any action in reliance on the contents of this information is strictly prohibited and may be unlawful. If you have received this communication in error, please notify us immediately by responding to the sender of this email and then delete it from your system. Four Soft is neither liable for the proper and complete transmission of the information contained in this communication nor for any delay in its receipt".