Buggy code:
public class AjaxRequestTarget implements IPageRequestHandler { public static interface IListener { public void onBeforeRespond ( Map < String , Component > map , AjaxRequestTarget target ) { } public void onAfterRespond ( Map < String , Component > map , AjaxRequestTarget . IJavascriptResponse response ) { } } public static interface IJavascriptResponse { public void addJavascript ( String script ) { } } private final class AjaxResponse extends Response { private final AppendingStringBuffer buffer = new AppendingStringBuffer ( 256 ) ; private boolean escaped = false ; private final Response originalResponse ; public AjaxResponse ( Response originalResponse ) { } @ Override public String encodeURL ( CharSequence url ) { } public CharSequence getContents ( ) { } public boolean isContentsEncoded ( ) { } @ Override public void write ( CharSequence cs ) { } @ Override public void reset ( ) { } @ Override public void write ( byte [ ] array ) { } } private static final Logger LOG = LoggerFactory . getLogger ( AjaxRequestTarget . class ) ; private final List < CharSequence > appendJavascripts = new ArrayList < CharSequence > ( ) ; private final List < CharSequence > domReadyJavascripts = new ArrayList < CharSequence > ( ) ; private final AjaxRequestTarget . AjaxResponse encodingBodyResponse ; private final AjaxRequestTarget . AjaxResponse encodingHeaderResponse ; private final Map < String , Component > markupIdToComponent = new LinkedHashMap < String , Component > ( ) ; private final List < CharSequence > prependJavascripts = new ArrayList < CharSequence > ( ) ; private List < AjaxRequestTarget . IListener > listeners = null ; private final Set < AjaxRequestTarget . ITargetRespondListener > respondListeners = new HashSet < AjaxRequestTarget . ITargetRespondListener > ( ) ; private final Page page ; public Page getPage ( ) { } public AjaxRequestTarget ( Page page ) { } public void addListener ( AjaxRequestTarget . IListener listener ) { } public final void addChildren ( MarkupContainer parent , Class < ? > childCriteria ) { } @ Deprecated public void addComponent ( Component ... components ) { } public void add ( Component ... components ) { } @ Deprecated public final void addComponent ( Component component , String markupId ) { } public final void add ( Component component , String markupId ) { } public final Collection < ? extends Component > getComponents ( ) { } public final void focusComponent ( Component component ) { } public final void appendJavascript ( CharSequence javascript ) { } public void detach ( final IRequestCycle requestCycle ) { } @ Override public boolean equals ( final Object obj ) { } @ Override public int hashCode ( ) { } public final void prependJavascript ( CharSequence javascript ) { } public static interface ITargetRespondListener { public void onTargetRespond ( AjaxRequestTarget target ) { } } public void registerRespondListener ( AjaxRequestTarget . ITargetRespondListener listener ) { } public final void respond ( final IRequestCycle requestCycle ) { boolean frozen = page . setFreezePageId ( true ) ; try { RequestCycle rc = ( ( RequestCycle ) ( requestCycle ) ) ; Url oldBaseURL = rc . getUrlRenderer ( ) . getBaseUrl ( ) ; WebRequest request = ( ( WebRequest ) ( requestCycle . getRequest ( ) ) ) ; <START_BUG> Url baseURL = Url . parse ( request . getHeader ( "Wicket-Ajax-BaseURL" ) , request . getCharset ( ) ) ; <END_BUG> rc . getUrlRenderer ( ) . setBaseUrl ( baseURL ) ; final WebResponse response = ( ( WebResponse ) ( requestCycle . getResponse ( ) ) ) ; if ( markupIdToComponent . values ( ) . contains ( page ) ) { IRequestHandler handler = new RenderPageRequestHandler ( new org . apache . wicket . request . handler . PageProvider ( page ) ) ; final String url = rc . urlFor ( handler ) . toString ( ) ; response . sendRedirect ( url ) ; return ; } for ( AjaxRequestTarget . ITargetRespondListener listener : respondListeners ) { listener . onTargetRespond ( this ) ; } final Application app = Application . get ( ) ; final String encoding = app . getRequestCycleSettings ( ) . getResponseRequestEncoding ( ) ; response . setContentType ( ( "text//xml;<seq2seq4repair_space>charset=" + encoding ) ) ; response . disableCaching ( ) ; response . write ( "<?xml<seq2seq4repair_space>version=\"1.0\"<seq2seq4repair_space>encoding=\"" ) ; response . write ( encoding ) ; response . write ( "\"?>" ) ; response . write ( "<ajax-response>" ) ; fireOnBeforeRespondListeners ( ) ; Iterator < CharSequence > it = prependJavascripts . iterator ( ) ; while ( it . hasNext ( ) ) { CharSequence js = it . next ( ) ; respondInvocation ( response , js ) ; } respondComponents ( response ) ; fireOnAfterRespondListeners ( response ) ; it = domReadyJavascripts . iterator ( ) ; while ( it . hasNext ( ) ) { CharSequence js = it . next ( ) ; respondInvocation ( response , js ) ; } it = appendJavascripts . iterator ( ) ; while ( it . hasNext ( ) ) { CharSequence js = it . next ( ) ; respondInvocation ( response , js ) ; } response . write ( "<//ajax-response>" ) ; rc . getUrlRenderer ( ) . setBaseUrl ( oldBaseURL ) ; } finally { page . setFreezePageId ( frozen ) ; } } private void fireOnBeforeRespondListeners ( ) { } private void fireOnAfterRespondListeners ( final WebResponse response ) { } private void respondComponents ( WebResponse response ) { } private String getAjaxRegionMarkupId ( Component component ) { } private boolean containsAncestorFor ( Component component ) { } @ Override public String toString ( ) { } protected String encode ( CharSequence str ) { } protected String getEncodingName ( ) { } protected boolean needsEncoding ( CharSequence str ) { } private void respondComponent ( final Response response , final String markupId , final Component component ) { }

Fix:
Url baseURL = Url . parse ( request . getAjaxBaseUrl ( ) , request . getCharset ( ) ) ;