Example usage for org.apache.wicket.protocol.http.servlet ServletWebRequest getHeader

List of usage examples for org.apache.wicket.protocol.http.servlet ServletWebRequest getHeader

Introduction

In this page you can find the example usage for org.apache.wicket.protocol.http.servlet ServletWebRequest getHeader.

Prototype

@Override
    public String getHeader(String name) 

Source Link

Usage

From source file:org.hippoecm.frontend.plugins.jquery.upload.behaviors.AjaxFileUploadBehavior.java

License:Apache License

/**
 * Create a multi-part request containing uploading files that supports disk caching.
 *
 * @param request/*  w ww  . ja v  a  2  s  .  co m*/
 * @return the multi-part request or exception thrown if there's any error.
 * @throws FileUploadException
 */
private MultipartServletWebRequest createMultipartWebRequest(final ServletWebRequest request)
        throws FileUploadException {
    DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory(
            Application.get().getResourceSettings().getFileCleaner()) {
        @Override
        public FileItem createItem(String fieldName, String contentType, boolean isFormField, String fileName) {
            FileItem item = super.createItem(fieldName, contentType, isFormField, fileName);
            return new TemporaryFileItem(item);
        }
    };

    try {
        long contentLength = Long.valueOf(request.getHeader("Content-Length"));
        if (contentLength > 0) {
            return request.newMultipartWebRequest(Bytes.bytes(contentLength), container.getPage().getId(),
                    diskFileItemFactory);
        } else {
            throw new FileUploadException("Invalid file upload content length");
        }
    } catch (NumberFormatException e) {
        throw new FileUploadException("Invalid file upload content length", e);
    }
}

From source file:org.hippoecm.frontend.plugins.jquery.upload.behaviors.AjaxFileUploadBehavior.java

License:Apache License

/**
 * Decides what should be the response's content type depending on the 'Accept' request header. HTML5 browsers
 * work with "application/json", older ones use IFrame to make the upload and the response should be HTML. Read
 * http://blueimp.github.com/jQuery-File-Upload/ docs for more info.
 *
 * @param request// w  w w .  j  a  v a  2  s  . c  om
 */
protected boolean wantsHtml(ServletWebRequest request) {
    String acceptHeader = request.getHeader("Accept");
    return !Strings.isEmpty(acceptHeader) && acceptHeader.contains("text/html");
}

From source file:sk.opendatanode.ui.results.ResultMenuPanel.java

License:Open Source License

public ResultMenuPanel(String id) {
    super(id);/*from   ww w. j a  va 2s .c  om*/

    ServletWebRequest request = (ServletWebRequest) RequestCycle.get().getRequest();
    String referrer = request.getHeader("referer");

    if (referrer != null
            && referrer.startsWith(request.getUrl().getProtocol() + "://" + request.getUrl().getHost())) {
        add(new ExternalLink("backLink", "javascript:history.go(-1)", getString("back")));
    } else {
        add(new ExternalLink("backLink", "../", getString("back")));
    }
}

From source file:sk.opendatanode.utils.http.ContentNegotiablePage.java

License:Open Source License

private ContentTypes negotiateContent() {
    RequestCycle requestCycle = RequestCycle.get();
    ServletWebRequest request = (ServletWebRequest) requestCycle.getRequest();

    return ContentNegotiation.parseHttpContext(request.getHeader("Accept"),
            defineAvailableContent(new ArrayList<ContentTypes>()));
}