use of org.apache.wicket.request.Request in project wicket by apache.
the class AbstractResource method setRequestMetaData.
/**
* Reads the plain request header information and applies enriched information as meta data to
* the current request. Those information are available for the whole request cycle.
*
* @param attributes
* the attributes to get the plain request header information
*/
protected void setRequestMetaData(Attributes attributes) {
Request request = attributes.getRequest();
if (request instanceof WebRequest) {
WebRequest webRequest = (WebRequest) request;
setRequestRangeMetaData(webRequest);
}
}
use of org.apache.wicket.request.Request in project wicket by apache.
the class FileUploadField method getFileUploads.
/**
* @return a list of all uploaded files. The list is empty if no files were selected. It will return more than one files if:
* <ul>
* <li>HTML5 <input type="file" <strong>multiple</strong> /> is used</li>
* <li>the browser supports <em>multiple</em> attribute</li>
* <li>the user has selected more than one files from the <em>Select file</em> dialog</li>
* </ul>
*/
public List<FileUpload> getFileUploads() {
if (fileUploads != null) {
return fileUploads;
}
fileUploads = new ArrayList<>();
// Get request
final Request request = getRequest();
// If we successfully installed a multipart request
if (request instanceof IMultipartWebRequest) {
// Get the item for the path
final List<FileItem> fileItems = ((IMultipartWebRequest) request).getFile(getInputName());
if (fileItems != null) {
for (FileItem item : fileItems) {
// WICKET-6270 detect empty field by missing file name
if (Strings.isEmpty(item.getName()) == false) {
fileUploads.add(new FileUpload(item));
}
}
}
}
return fileUploads;
}
use of org.apache.wicket.request.Request in project wicket by apache.
the class MultiFileUploadField method getInputAsArray.
/**
* @see org.apache.wicket.markup.html.form.FormComponent#getInputAsArray()
*/
@Override
public String[] getInputAsArray() {
if (inputArrayCache == null) {
// this array will aggregate all input names
ArrayList<String> names = null;
final Request request = getRequest();
if (request instanceof IMultipartWebRequest) {
// retrieve the filename->FileItem map from request
final Map<String, List<FileItem>> itemNameToItem = ((IMultipartWebRequest) request).getFiles();
for (Entry<String, List<FileItem>> entry : itemNameToItem.entrySet()) {
// iterate over the map and build the list of filenames
final String name = entry.getKey();
final List<FileItem> fileItems = entry.getValue();
if (!Strings.isEmpty(name) && name.startsWith(getInputName() + MAGIC_SEPARATOR) && !fileItems.isEmpty() && !Strings.isEmpty(fileItems.get(0).getName())) {
// make sure the fileitem belongs to this component and
// is not empty
names = (names != null) ? names : new ArrayList<String>();
names.add(name);
}
}
}
if (names != null) {
inputArrayCache = names.toArray(new String[names.size()]);
}
}
return inputArrayCache;
}
use of org.apache.wicket.request.Request in project wicket by apache.
the class AjaxBehaviorEnabledTest method before.
/**
*/
@Before
public void before() {
final IAuthorizationStrategy strategy = new CustomStrategy();
tester = new WicketTester(new MockApplication() {
@Override
public Session newSession(Request request, Response response) {
return new WebSession(request) {
private static final long serialVersionUID = 1L;
@Override
public IAuthorizationStrategy getAuthorizationStrategy() {
return strategy;
}
};
}
});
}
use of org.apache.wicket.request.Request in project wicket by apache.
the class UndertowPushBuilder method push.
@Override
public void push(HttpServletRequest httpServletRequest, PushItem... pushItems) {
Request request = RequestCycle.get().getRequest();
HttpServletRequest httpRequest = (HttpServletRequest) request.getContainerRequest();
io.undertow.servlet.spec.HttpServletRequestImpl undertowRequest = (io.undertow.servlet.spec.HttpServletRequestImpl) httpRequest;
// Added explicit cast here to ensure this is the implementation of undertow
io.undertow.servlet.spec.PushBuilderImpl pushBuilder = (io.undertow.servlet.spec.PushBuilderImpl) undertowRequest.getPushBuilder();
if (pushBuilder != null) {
for (PushItem pushItem : pushItems) {
pushBuilder.path(pushItem.getUrl());
pushItem.getHeaders().entrySet().stream().forEach(pushHeader -> {
String key = pushHeader.getKey();
PushItemHeaderValue value = pushHeader.getValue();
if (value.getOperation() == HeaderOperation.ADD) {
pushBuilder.addHeader(key, value.getValue());
} else {
pushBuilder.setHeader(key, value.getValue());
}
});
pushBuilder.push();
}
} else {
LOG.warn("Attempted to use HTTP2 Push but it is not supported for the current request: {}!", httpRequest);
}
}
Aggregations