Example usage for org.apache.wicket.protocol.http.mock MockHttpServletRequest getCharacterEncoding

List of usage examples for org.apache.wicket.protocol.http.mock MockHttpServletRequest getCharacterEncoding

Introduction

In this page you can find the example usage for org.apache.wicket.protocol.http.mock MockHttpServletRequest getCharacterEncoding.

Prototype

@Override
public String getCharacterEncoding() 

Source Link

Document

Get the current character encoding.

Usage

From source file:sk.drunkenpanda.leaflet.AbstractLeafletTest.java

License:Apache License

/**
 * Prepares request that triggers AJAX behavior and contains parameter with given name and value.
 *
 * @param tester the wicket tester which triggers behavior
 * @param behavior the behavior that should be triggered
 * @param parameterName the name of parameter
 * @param parameterValue the value of parameter
 * @return mock HTTP request that triggers given behavior
 */// w  ww .  j  a  v a  2 s .  co m
protected MockHttpServletRequest prepareRequest(WicketTester tester, AbstractAjaxBehavior behavior,
        String parameterName, String parameterValue) {
    MockHttpServletRequest request = new MockHttpServletRequest(tester.getApplication(),
            tester.getHttpSession(), tester.getServletContext());

    Url url = Url.parse(behavior.getCallbackUrl().toString(), Charset.forName(request.getCharacterEncoding()));

    // make url suitable for wicket tester use. usually this involves stripping any leading ..
    // segments to make the url absolute
    for (Iterator<String> segments = url.getSegments().iterator(); segments.hasNext();) {
        String segment = segments.next();
        if (segment.equals("..") || segment.equals(".")) {
            segments.remove();
        }
    }

    request.addHeader("Wicket-Ajax", "true");
    request.addHeader("Wicket-Ajax-BaseURL", url.toString());
    request.setUrl(url);

    request.setParameter(parameterName, parameterValue);

    return request;
}