Search in sources :

Example 1 with Request

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);
    }
}
Also used : WebRequest(org.apache.wicket.request.http.WebRequest) WebRequest(org.apache.wicket.request.http.WebRequest) Request(org.apache.wicket.request.Request)

Example 2 with Request

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 &lt;input type="file" <strong>multiple</strong> /&gt; 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;
}
Also used : FileItem(org.apache.commons.fileupload.FileItem) IMultipartWebRequest(org.apache.wicket.protocol.http.IMultipartWebRequest) Request(org.apache.wicket.request.Request) IMultipartWebRequest(org.apache.wicket.protocol.http.IMultipartWebRequest)

Example 3 with Request

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;
}
Also used : FileItem(org.apache.commons.fileupload.FileItem) IMultipartWebRequest(org.apache.wicket.protocol.http.IMultipartWebRequest) Request(org.apache.wicket.request.Request) IMultipartWebRequest(org.apache.wicket.protocol.http.IMultipartWebRequest) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with Request

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;
                }
            };
        }
    });
}
Also used : Response(org.apache.wicket.request.Response) WebSession(org.apache.wicket.protocol.http.WebSession) MockApplication(org.apache.wicket.mock.MockApplication) Request(org.apache.wicket.request.Request) WicketTester(org.apache.wicket.util.tester.WicketTester) IAuthorizationStrategy(org.apache.wicket.authorization.IAuthorizationStrategy) Before(org.junit.Before)

Example 5 with Request

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);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Request(org.apache.wicket.request.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest)

Aggregations

Request (org.apache.wicket.request.Request)63 Test (org.junit.Test)28 IRequestHandler (org.apache.wicket.request.IRequestHandler)26 Url (org.apache.wicket.request.Url)23 WebRequest (org.apache.wicket.request.http.WebRequest)9 Response (org.apache.wicket.request.Response)8 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)8 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 RenderPageRequestHandler (org.apache.wicket.core.request.handler.RenderPageRequestHandler)6 IRequestablePage (org.apache.wicket.request.component.IRequestablePage)6 RequestCycle (org.apache.wicket.request.cycle.RequestCycle)6 IPageRequestHandler (org.apache.wicket.core.request.handler.IPageRequestHandler)5 ResourceReferenceRequestHandler (org.apache.wicket.request.handler.resource.ResourceReferenceRequestHandler)5 MockApplication (org.apache.wicket.mock.MockApplication)4 MockHttpServletRequest (org.apache.wicket.protocol.http.mock.MockHttpServletRequest)4 ServletWebRequest (org.apache.wicket.protocol.http.servlet.ServletWebRequest)3 Attributes (org.apache.wicket.request.resource.IResource.Attributes)3 PackageResourceReference (org.apache.wicket.request.resource.PackageResourceReference)3 UrlAttributes (org.apache.wicket.request.resource.ResourceReference.UrlAttributes)3 ByteArrayResponse (org.apache.wicket.response.ByteArrayResponse)3