2

On one of our pages we have added a AbstractAjaxTimerBehavior (to add potential new items to a Repeatingview). The AJAX call that is executed is the following:

https://.../home/?0-1.IBehaviorListener.0-filteredContentHandler&random=0.38872813899070024

However, because of the random part this URL is not static. I'm also not sure if ?0-1 is always the same.

Is there a way in Wicket 1.5 or Wicket 6 (which we might upgrade to) to set a static URL for a certain call?


(The reason for this requirement is to provide this URL to Siteminder (SSO) so that the SSO session is ignoring these URL's to keep the SSO session alive).

Stijn Geukens
  • 15,454
  • 8
  • 66
  • 101
  • You need to make the link stateless. See http://stackoverflow.com/questions/10582601/how-can-i-make-wickets-ajaxlink-stateless – Jonathan Dec 09 '12 at 13:43

1 Answers1

0

To answer my own question:

public class AjaxTimerBehaviorMapper extends AbstractComponentMapper {

    private final IRequestMapper wrappedMapper;

    private final String prefix;

    /**
     * @param rootRequestMapper
     */
    public AjaxTimerBehaviorMapper(IRequestMapper wrappedMapper, String prefix) {
        this.wrappedMapper = wrappedMapper;
        this.prefix = prefix;
    }

    @Override
    public IRequestHandler mapRequest(Request request) {
        Url url = request.getUrl();
        if (url.getSegments().size() >= 1 && url.getSegments().get(0).equals(this.prefix)) {
            url.removeLeadingSegments(1);
        }
        return this.wrappedMapper.mapRequest(request.cloneWithUrl(url));
    }

    @Override
    public int getCompatibilityScore(Request request) {
        return this.wrappedMapper.getCompatibilityScore(request);
    }

    @Override
    public Url mapHandler(IRequestHandler requestHandler) {
        Url url = this.wrappedMapper.mapHandler(requestHandler);
        if (requestHandler instanceof ListenerInterfaceRequestHandler) {
            ListenerInterfaceRequestHandler listenerInterfaceRequestHandler = (ListenerInterfaceRequestHandler) requestHandler;

            RequestListenerInterface requestListenerInterface = listenerInterfaceRequestHandler.getListenerInterface();
            if (requestListenerInterface != null) {
                Class<? extends IRequestListener> listenerInterfaceClass = requestListenerInterface.getListenerInterfaceClass();
                if (IBehaviorListener.class.isAssignableFrom(listenerInterfaceClass)) {
                    IRequestableComponent requestableComponent = listenerInterfaceRequestHandler.getComponent();
                    if (requestableComponent != null) {
                        Integer behaviorIndex = listenerInterfaceRequestHandler.getBehaviorIndex();
                        Behavior behavior = requestableComponent.getBehaviorById(behaviorIndex);
                        if (behavior != null) {
                            if (AbstractAjaxTimerBehavior.class.isAssignableFrom(behavior.getClass())
                                || CustomAbstractAjaxTimerBehavior.class.isAssignableFrom(behavior.getClass())) {
                                url.prependLeadingSegments(newArrayList(this.prefix));
                            }
                        }
                    }
                }
            }
        }
        return url;
    }
}

This way wicket will use the given fixed prefix in the url.

Stijn Geukens
  • 15,454
  • 8
  • 66
  • 101