Search in sources :

Example 26 with Request

use of org.apache.wicket.request.Request in project wicket by apache.

the class ContextRelativeResourceCachingTest method mapHandler.

/**
 */
@Test
public void mapHandler() {
    ContextRelativeResource resource = new ContextRelativeResource("/style.css");
    init(resource, "/test/resource");
    Request request = createRequest("test/resource-version-123?bla=4567");
    final IRequestHandler handler = tester.getApplication().getRootRequestMapper().mapRequest(request);
    assertThat(handler, instanceOf(ResourceReferenceRequestHandler.class));
    assertEquals(((ResourceReferenceRequestHandler) handler).getResource(), resource);
}
Also used : ResourceReferenceRequestHandler(org.apache.wicket.request.handler.resource.ResourceReferenceRequestHandler) IRequestHandler(org.apache.wicket.request.IRequestHandler) Request(org.apache.wicket.request.Request) ContextRelativeResource(org.apache.wicket.request.resource.ContextRelativeResource) Test(org.junit.Test)

Example 27 with Request

use of org.apache.wicket.request.Request in project wicket by apache.

the class PackageResourceReferenceTest method testContentRangeHeaders.

/**
 * See WICKET-5819 - Media tags
 */
@Test
public void testContentRangeHeaders() {
    // Test header fields
    ResourceReference reference = new PackageResourceReference(scope, "resource.txt", locales[1], styles[1], variations[1]);
    Request request = tester.getRequestCycle().getRequest();
    Response response = tester.getRequestCycle().getResponse();
    MockHttpServletResponse mockHttpServletResponse = (MockHttpServletResponse) response.getContainerResponse();
    Attributes mockAttributes = new Attributes(request, response);
    reference.getResource().respond(mockAttributes);
    Assert.assertEquals(ContentRangeType.BYTES.getTypeName(), mockHttpServletResponse.getHeader("Accept-Range"));
    // For normal: If a resource supports content range no content is delivered
    // if no "Range" header is given, but we have to deliver it, because
    // other resources then media should get the content. (e.g. CSS, JS, etc.) Browsers
    // detecting media requests and automatically add the "Range" header for
    // partial content and they don't make an initial request to detect if a media
    // resource supports Content-Range (by the Accept-Range header)
    Assert.assertEquals("resource_var_style_en.txt", new String(mockHttpServletResponse.getBinaryContent()));
}
Also used : MockHttpServletResponse(org.apache.wicket.protocol.http.mock.MockHttpServletResponse) Response(org.apache.wicket.request.Response) ByteArrayResponse(org.apache.wicket.response.ByteArrayResponse) MockHttpServletRequest(org.apache.wicket.protocol.http.mock.MockHttpServletRequest) Request(org.apache.wicket.request.Request) Attributes(org.apache.wicket.request.resource.IResource.Attributes) UrlAttributes(org.apache.wicket.request.resource.ResourceReference.UrlAttributes) MockHttpServletResponse(org.apache.wicket.protocol.http.mock.MockHttpServletResponse) Test(org.junit.Test)

Example 28 with Request

use of org.apache.wicket.request.Request in project wicket by apache.

the class PackageResourceReferenceTest method makeRangeRequestToBigResource.

private String makeRangeRequestToBigResource(String range) {
    ResourceReference reference = new PackageResourceReference(scope, "resource_gt_4096.txt", null, null, null);
    ByteArrayResponse byteResponse = new ByteArrayResponse();
    Request request = tester.getRequestCycle().getRequest();
    MockHttpServletRequest mockHttpServletRequest = (MockHttpServletRequest) request.getContainerRequest();
    mockHttpServletRequest.setHeader("range", range);
    Attributes mockAttributes = new Attributes(request, byteResponse);
    reference.getResource().respond(mockAttributes);
    return new String(byteResponse.getBytes());
}
Also used : MockHttpServletRequest(org.apache.wicket.protocol.http.mock.MockHttpServletRequest) MockHttpServletRequest(org.apache.wicket.protocol.http.mock.MockHttpServletRequest) Request(org.apache.wicket.request.Request) Attributes(org.apache.wicket.request.resource.IResource.Attributes) UrlAttributes(org.apache.wicket.request.resource.ResourceReference.UrlAttributes) ByteArrayResponse(org.apache.wicket.response.ByteArrayResponse)

Example 29 with Request

use of org.apache.wicket.request.Request in project wicket by apache.

the class PackageResourceReferenceTest method makeRangeRequest.

private String makeRangeRequest(String range) {
    ResourceReference reference = new PackageResourceReference(scope, "resource.txt", locales[1], styles[1], variations[1]);
    ByteArrayResponse byteResponse = new ByteArrayResponse();
    Request request = tester.getRequestCycle().getRequest();
    MockHttpServletRequest mockHttpServletRequest = (MockHttpServletRequest) request.getContainerRequest();
    mockHttpServletRequest.setHeader("range", range);
    Attributes mockAttributes = new Attributes(request, byteResponse);
    reference.getResource().respond(mockAttributes);
    return new String(byteResponse.getBytes());
}
Also used : MockHttpServletRequest(org.apache.wicket.protocol.http.mock.MockHttpServletRequest) MockHttpServletRequest(org.apache.wicket.protocol.http.mock.MockHttpServletRequest) Request(org.apache.wicket.request.Request) Attributes(org.apache.wicket.request.resource.IResource.Attributes) UrlAttributes(org.apache.wicket.request.resource.ResourceReference.UrlAttributes) ByteArrayResponse(org.apache.wicket.response.ByteArrayResponse)

Example 30 with Request

use of org.apache.wicket.request.Request in project webanno by webanno.

the class AnnotationFeatureForm method createForwardAnnotationTextField.

private TextField<String> createForwardAnnotationTextField() {
    TextField<String> textfield = new TextField<>("forwardAnno");
    textfield.setOutputMarkupId(true);
    textfield.add(new AjaxFormComponentUpdatingBehavior("keyup") {

        private static final long serialVersionUID = 4554834769861958396L;

        @Override
        protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
            super.updateAjaxAttributes(attributes);
            IAjaxCallListener listener = new AjaxCallListener() {

                private static final long serialVersionUID = -7968540662654079601L;

                @Override
                public CharSequence getPrecondition(Component component) {
                    return "var keycode = Wicket.Event.keyCode(attrs.event);    return true;";
                }
            };
            attributes.getAjaxCallListeners().add(listener);
            attributes.getDynamicExtraParameters().add("var eventKeycode = Wicket.Event" + ".keyCode(attrs.event);return {keycode: eventKeycode};");
            attributes.setPreventDefault(false);
        }

        @Override
        protected void onUpdate(AjaxRequestTarget aTarget) {
            final Request request = RequestCycle.get().getRequest();
            final String jsKeycode = request.getRequestParameters().getParameterValue("keycode").toString("");
            if (jsKeycode.equals("32")) {
                try {
                    JCas jCas = editorPanel.getEditorCas();
                    editorPanel.actionCreateForward(aTarget, jCas);
                    selectedTag = "";
                } catch (Exception e) {
                    handleException(textfield, aTarget, e);
                }
                return;
            }
            if (jsKeycode.equals("13")) {
                selectedTag = "";
                return;
            }
            selectedTag = (textfield.getModelObject() == null ? "" : textfield.getModelObject().charAt(0)) + selectedTag;
            Map<String, String> bindTags = getBindTags();
            if (!bindTags.isEmpty()) {
                List<FeatureState> featureStates = getModelObject().getFeatureStates();
                featureStates.get(0).value = getKeyBindValue(selectedTag, bindTags);
            }
            aTarget.add(textfield);
            aTarget.add(featureEditorPanelContent.get(0));
        }
    });
    textfield.add(new AttributeAppender("style", "opacity:0", ";"));
    // forwardAnno.add(new AttributeAppender("style", "filter:alpha(opacity=0)", ";"));
    return textfield;
}
Also used : AjaxFormComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior) IAjaxCallListener(org.apache.wicket.ajax.attributes.IAjaxCallListener) Request(org.apache.wicket.request.Request) JCas(org.apache.uima.jcas.JCas) AnnotationDetailEditorPanel.handleException(de.tudarmstadt.ukp.clarin.webanno.ui.annotation.detail.AnnotationDetailEditorPanel.handleException) AnnotationException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException) IOException(java.io.IOException) AjaxRequestAttributes(org.apache.wicket.ajax.attributes.AjaxRequestAttributes) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) TextField(com.googlecode.wicket.kendo.ui.form.TextField) List(java.util.List) ArrayList(java.util.ArrayList) Component(org.apache.wicket.Component) IAjaxCallListener(org.apache.wicket.ajax.attributes.IAjaxCallListener) AjaxCallListener(org.apache.wicket.ajax.attributes.AjaxCallListener) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) AttributeAppender(org.apache.wicket.behavior.AttributeAppender)

Aggregations

Request (org.apache.wicket.request.Request)61 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 RenderPageRequestHandler (org.apache.wicket.core.request.handler.RenderPageRequestHandler)6 IRequestablePage (org.apache.wicket.request.component.IRequestablePage)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 IPageRequestHandler (org.apache.wicket.core.request.handler.IPageRequestHandler)5 RequestCycle (org.apache.wicket.request.cycle.RequestCycle)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 Session (org.apache.wicket.Session)3 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