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));
}
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));
}
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);
}
}
}
}
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);
}
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;
}
Aggregations