Search in sources :

Example 6 with WebRequest

use of org.apache.wicket.request.http.WebRequest in project wicket by apache.

the class ByteArrayResourceTest method staticResource.

/**
 * Unit test for {@link ByteArrayResource} with static byte array.
 */
@Test
public void staticResource() {
    String contentType = "application/octet-stream";
    byte[] array = new byte[] { 1, 2, 3 };
    ByteArrayResource resource = new ByteArrayResource(contentType, array) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void configureCache(ResourceResponse data, Attributes attributes) {
        // no caching is needed
        }
    };
    WebRequest request = mock(WebRequest.class);
    WebResponse response = mock(WebResponse.class);
    Attributes attributes = new Attributes(request, response);
    resource.respond(attributes);
    verify(response).write(same(array));
    verify(response).setContentLength(eq(3L));
    verify(response).setContentType(eq(contentType));
}
Also used : WebResponse(org.apache.wicket.request.http.WebResponse) WebRequest(org.apache.wicket.request.http.WebRequest) Attributes(org.apache.wicket.request.resource.IResource.Attributes) Test(org.junit.Test)

Example 7 with WebRequest

use of org.apache.wicket.request.http.WebRequest in project wicket by apache.

the class ByteArrayResourceTest method dynamicResource.

/**
 * Unit test for {@link ByteArrayResource} with dynamically generated byte array.
 */
@Test
public void dynamicResource() {
    String contentType = "application/octet-stream";
    final byte[] array = new byte[] { 1, 2, 3 };
    ByteArrayResource resource = new ByteArrayResource(contentType) {

        private static final long serialVersionUID = 1L;

        @Override
        protected byte[] getData(Attributes attributes) {
            return array;
        }

        @Override
        protected void configureCache(ResourceResponse data, Attributes attributes) {
        // no caching is needed
        }
    };
    WebRequest request = mock(WebRequest.class);
    WebResponse response = mock(WebResponse.class);
    Attributes attributes = new Attributes(request, response);
    resource.respond(attributes);
    verify(response).write(same(array));
    verify(response).setContentLength(eq(3L));
    verify(response).setContentType(eq(contentType));
}
Also used : WebResponse(org.apache.wicket.request.http.WebResponse) WebRequest(org.apache.wicket.request.http.WebRequest) Attributes(org.apache.wicket.request.resource.IResource.Attributes) Test(org.junit.Test)

Example 8 with WebRequest

use of org.apache.wicket.request.http.WebRequest in project wicket-orientdb by OrienteerBAP.

the class LazyAuthorizationRequestCycleListener method onBeginRequest.

@Override
public void onBeginRequest(RequestCycle cycle) {
    WebRequest request = (WebRequest) cycle.getRequest();
    String authorization = request.getHeader(AUTHORIZATION_HEADER);
    if (authorization != null && authorization.startsWith("Basic")) {
        String[] pair = new String(Base64.getDecoder().decode(authorization.substring(6).trim())).split(":");
        if (pair.length == 2) {
            String userName = pair[0];
            String password = pair[1];
            OrientDbWebSession session = OrientDbWebSession.get();
            if (!session.signIn(userName, password)) {
                cycle.setMetaData(LAZY_AUTHORIZED, false);
            }
        }
    }
}
Also used : WebRequest(org.apache.wicket.request.http.WebRequest)

Example 9 with WebRequest

use of org.apache.wicket.request.http.WebRequest in project wicket by apache.

the class WebPage method dirty.

/**
 * Prevents page from get dirty inside an AJAX request.
 */
@Override
public final void dirty(boolean isInitialization) {
    Request request = getRequest();
    if (isInitialization == false && request instanceof WebRequest && ((WebRequest) request).isAjax()) {
        return;
    }
    super.dirty(isInitialization);
}
Also used : WebRequest(org.apache.wicket.request.http.WebRequest) WebRequest(org.apache.wicket.request.http.WebRequest) Request(org.apache.wicket.request.Request)

Example 10 with WebRequest

use of org.apache.wicket.request.http.WebRequest in project wicket by apache.

the class CookieUtils method getCookie.

/**
 * Gets the cookie with 'name' attached to the latest WebRequest.
 *
 * @param name
 *            The name of the cookie to be looked up
 *
 * @return Any cookies for this request
 */
public Cookie getCookie(final String name) {
    String key = getSaveKey(name);
    try {
        WebRequest webRequest = getWebRequest();
        Cookie cookie = webRequest.getCookie(key);
        if (log.isDebugEnabled()) {
            if (cookie != null) {
                log.debug("Found Cookie with name=" + key + " and request URI=" + webRequest.getUrl().toString());
            } else {
                log.debug("Unable to find Cookie with name=" + key + " and request URI=" + webRequest.getUrl().toString());
            }
        }
        return cookie;
    } catch (NullPointerException ex) {
    // Ignore any app server problem here
    }
    return null;
}
Also used : Cookie(javax.servlet.http.Cookie) ServletWebRequest(org.apache.wicket.protocol.http.servlet.ServletWebRequest) WebRequest(org.apache.wicket.request.http.WebRequest)

Aggregations

WebRequest (org.apache.wicket.request.http.WebRequest)15 WebResponse (org.apache.wicket.request.http.WebResponse)5 Request (org.apache.wicket.request.Request)4 ServletWebRequest (org.apache.wicket.protocol.http.servlet.ServletWebRequest)3 RequestCycle (org.apache.wicket.request.cycle.RequestCycle)3 IOException (java.io.IOException)2 Cookie (javax.servlet.http.Cookie)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)2 Attributes (org.apache.wicket.request.resource.IResource.Attributes)2 Test (org.junit.Test)2 InputStream (java.io.InputStream)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HttpURLConnection (java.net.HttpURLConnection)1 URL (java.net.URL)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 Page (org.apache.wicket.Page)1 ThreadContext (org.apache.wicket.ThreadContext)1