cancel
Showing results for 
Search instead for 
Did you mean: 

How to get a reference to CallbackHandler?

Former Member
0 Kudos

I'm trying you use code from example in the manual to read Cookie from HttpRequest but it has and error, CallbackHandler is an interface. How can I get reference to CallbackHandler?

Thanks,

Andrei.

HttpGetterCallback getterCallback = new HttpGetterCallback ();

getterCallback.setTypeHttpGetterCallback.COOKIE);

getterCallback.setName("ticket");

<b>// the string below is not right CallbackHandler is an interface

</b> CallbackHandler.handle(new Callback[] getterCallback});

// Gets the ticket that is in the cookies

Object value = getterCallback.getValue();

Accepted Solutions (0)

Answers (1)

Answers (1)

0 Kudos

Hi Andrei,

Each implementation of LoginModule interface has an initialize method. This method is called by the LoginContext in order to initialize the LoginModule with the relevant information. One of the parameters passed to this method is the CallbackHandler. What you can do is to use this handler. For example:

private CallbackHandler callbackHandler = null;

public void initialize(Subject subject, CallbackHandler callbackHandler, Map sharedState, Map options) {

….

this.callbackHandler = callbackHandler;

….

}

And afterwards you can use callbackHandler like you wish:

HttpGetterCallback getterCallback = new HttpGetterCallback();

getterCallback.setType(HttpGetterCallback.COOKIE);

getterCallback.setName("ticket");

try{

callbackHandler.handle(new Callback[]

getterCallback});

} catch (Exception e) {

e.printStackTrace();

throw new LoginException("Callbacks invokation failed! " + e);

}

Object value = getterCallback.getValue();

Best regards,

Diyan