Example usage for org.apache.wicket.request.cycle RequestCycle getMetaData

List of usage examples for org.apache.wicket.request.cycle RequestCycle getMetaData

Introduction

In this page you can find the example usage for org.apache.wicket.request.cycle RequestCycle getMetaData.

Prototype

public final <T> T getMetaData(final MetaDataKey<T> key) 

Source Link

Document

Gets metadata for this request cycle using the given key.

Usage

From source file:com.github.javawithmarcus.wicket.cdi.DetachEventEmitter.java

License:Apache License

@Override
public void onDetach(RequestCycle cycle) {
    if (Boolean.TRUE.equals(cycle.getMetaData(DETACH_SCHEDULED_KEY))) {
        logger.debug("Firing Detach event {}", cycle.getRequest().getUrl());

        detachEvent.fire(new DetachEvent());

        cycle.setMetaData(DETACH_SCHEDULED_KEY, null);
    }/*  w  w  w  . j  av  a2 s .c  om*/
}

From source file:com.wyndhamjade.util.wicket.newrelic.NewRelicRequestCycleListener.java

License:Apache License

@Override
public void onRequestHandlerResolved(final RequestCycle cycle, final IRequestHandler handler) {
    if (cycle.getMetaData(FIRST_HANDLER)) {
        cycle.setMetaData(FIRST_HANDLER, false);

        final StringBuilder s = new StringBuilder();

        if (handler instanceof IComponentRequestHandler) {
            final IRequestableComponent c = ((IComponentRequestHandler) handler).getComponent();
            s.append('/');
            s.append(pageClassToPath(c.getPage().getClass()));
            s.append('/');
            s.append(componentToPath(c));
        } else if (handler instanceof IPageClassRequestHandler) {
            s.append('/');
            s.append(pageClassToPath(((IPageClassRequestHandler) handler).getPageClass()));
        } else {/* ww w .  j a v  a 2 s  .co  m*/
            NewRelic.ignoreTransaction();
            return;
        }

        NewRelic.setTransactionName(null, s.toString());
    }
}

From source file:fiftyfive.wicket.shiro.ShiroWicketPlugin.java

License:Apache License

/**
 * Determine what caused the unauthorized instantiation of the given
 * component. If access was denied due to being unauthenticated, and
 * the login page specified in the constructor was not {@code null},
 * call {@link #onLoginRequired} and redirect to the login page.
 * <p>//  w w w. j av  a  2 s.  c om
 * Otherwise, access was denied due to authorization failure (e.g. insufficient privileges),
 * call {@link #onUnauthorized} and render the unauthorized page (which is the home page by
 * default).
 * 
 * @param component The component that failed to initialize due to 
 *                  authorization or authentication failure
 * 
 * @throws {@link ResetResponseException} to render the login page or unauthorized page
 * 
 * @throws UnauthorizedInstantiationException the login page
 *                                            has not been configured (i.e. is {@code null})
 */
public void onUnauthorizedInstantiation(Component component) {
    AuthorizationException cause;
    RequestCycle rc = RequestCycle.get();
    cause = rc.getMetaData(EXCEPTION_KEY);

    // Show appropriate login or error page if possible
    IRequestHandler handler = onException(rc, cause);
    if (handler != null) {
        throw new ResetResponseException(handler) {
        };
    }

    // Otherwise bubble up the error
    UnauthorizedInstantiationException ex;
    ex = new UnauthorizedInstantiationException(component.getClass());
    ex.initCause(cause);
    throw ex;
}

From source file:lt.inventi.wicket.shiro.ShiroWicketPlugin.java

License:Apache License

/**
 * Determine what caused the unauthorized instantiation of the given
 * component. If access was denied due to being unauthenticated, and
 * the login page specified in the constructor was not {@code null},
 * call {@link #onLoginRequired} and redirect to the login page.
 * <p>//w  ww .j  a v  a2  s. c  om
 * Otherwise, access was denied due to authorization failure (e.g. insufficient privileges),
 * call {@link #onUnauthorized} and render the unauthorized page (which is the home page by
 * default).
 *
 * @param component The component that failed to initialize due to
 *                  authorization or authentication failure
 *
 * @throws {@link ResetResponseException} to render the login page or unauthorized page
 *
 * @throws UnauthorizedInstantiationException the login page
 *                                            has not been configured (i.e. is {@code null})
 */
@Override
public void onUnauthorizedInstantiation(Component component) {
    AuthorizationException cause;
    RequestCycle rc = RequestCycle.get();
    cause = rc.getMetaData(EXCEPTION_KEY);

    // Show appropriate login or error page if possible
    IRequestHandler handler = onException(rc, cause);
    if (handler != null) {
        throw new ResetResponseException(handler) {
        };
    }

    // Otherwise bubble up the error
    UnauthorizedInstantiationException ex;
    ex = new UnauthorizedInstantiationException(component.getClass());
    ex.initCause(cause);
    throw ex;
}

From source file:org.brixcms.web.BrixRequestCycleProcessor.java

License:Apache License

public String getWorkspace() {
    String workspace = getWorkspaceFromUrl();

    if (workspace != null) {
        return workspace;
    }//from  w  w w.ja v a  2s.co m

    RequestCycle rc = RequestCycle.get();
    workspace = rc.getMetaData(WORKSPACE_METADATA);
    if (workspace == null) {
        WebRequest req = (WebRequest) RequestCycle.get().getRequest();
        WebResponse resp = (WebResponse) RequestCycle.get().getResponse();
        Cookie cookie = req.getCookie(COOKIE_NAME);
        workspace = getDefaultWorkspaceName();
        if (cookie != null) {
            if (cookie.getValue() != null)
                workspace = cookie.getValue();
        }
        if (!checkSession(workspace)) {
            workspace = getDefaultWorkspaceName();
        }
        if (workspace == null) {
            throw new IllegalStateException("Could not resolve jcr workspace to use for this request");
        }
        Cookie c = new Cookie(COOKIE_NAME, workspace);
        c.setPath("/");
        if (workspace.toString().equals(getDefaultWorkspaceName()) == false)
            resp.addCookie(c);
        else if (cookie != null)
            resp.clearCookie(cookie);
        rc.setMetaData(WORKSPACE_METADATA, workspace);
    }
    return workspace;
}

From source file:org.brixcms.web.BrixRequestMapper.java

License:Apache License

public String getWorkspace() {
    String workspace = getWorkspaceFromUrl();

    if (workspace != null) {
        return workspace;
    }//from   w ww  . j av  a 2s . c o m

    RequestCycle rc = RequestCycle.get();
    workspace = rc.getMetaData(WORKSPACE_METADATA);
    if (workspace == null) {
        WebRequest req = (WebRequest) RequestCycle.get().getRequest();
        WebResponse resp = (WebResponse) RequestCycle.get().getResponse();
        Cookie cookie = req.getCookie(COOKIE_NAME);
        workspace = getDefaultWorkspaceName();
        if (cookie != null) {
            if (cookie.getValue() != null) {
                workspace = cookie.getValue();
            }
        }
        if (!checkSession(workspace)) {
            workspace = getDefaultWorkspaceName();
        }
        if (workspace == null) {
            throw new IllegalStateException("Could not resolve jcr workspace to use for this request");
        }
        Cookie c = new Cookie(COOKIE_NAME, workspace);
        c.setPath("/");
        if (workspace.toString().equals(getDefaultWorkspaceName()) == false) {
            resp.addCookie(c);
        } else if (cookie != null) {
            resp.clearCookie(cookie);
        }
        rc.setMetaData(WORKSPACE_METADATA, workspace);
    }
    return workspace;
}

From source file:org.brixcms.workspace.WorkspaceUtils.java

License:Apache License

public static String getWorkspace() {
    String workspace = getWorkspaceFromUrl();

    if (workspace != null) {
        return workspace;
    }//from  w  ww.  ja  v  a 2  s.c o  m

    RequestCycle rc = RequestCycle.get();
    workspace = rc.getMetaData(WORKSPACE_METADATA);
    if (workspace == null) {
        WebRequest req = (WebRequest) RequestCycle.get().getRequest();
        WebResponse resp = (WebResponse) RequestCycle.get().getResponse();
        Cookie cookie = req.getCookie(COOKIE_NAME);
        workspace = getDefaultWorkspaceName();
        if (cookie != null) {
            if (cookie.getValue() != null)
                workspace = cookie.getValue();
        }
        if (!checkSession(workspace)) {
            workspace = getDefaultWorkspaceName();
        }
        if (workspace == null) {
            throw new IllegalStateException("Could not resolve jcr workspace to use for this request");
        }
        Cookie c = new Cookie(COOKIE_NAME, workspace);
        c.setPath("/");
        if (workspace.toString().equals(getDefaultWorkspaceName()) == false)
            resp.addCookie(c);
        else if (cookie != null)
            resp.clearCookie(cookie);
        rc.setMetaData(WORKSPACE_METADATA, workspace);
    }
    return workspace;
}

From source file:org.wicketstuff.jamon.request.cycle.JamonMonitoredRequestCycleContext.java

License:Apache License

public static JamonMonitoredRequestCycleContext get(RequestCycle cycle) {
    RequestCycle requestCycle = cycle == null ? RequestCycle.get() : cycle;
    return requestCycle.getMetaData(JamonMonitoredRequestCycleContextKey.KEY);
}

From source file:org.wicketstuff.nashorn.resource.NashornResource.java

License:Apache License

/**
 * Executes the java script code received from the client and returns the response
 *///from w  w  w  .  j  av a2 s .c  o  m
@Override
protected ResourceResponse newResourceResponse(Attributes attributes) {
    RequestCycle cycle = RequestCycle.get();
    Long startbyte = cycle.getMetaData(CONTENT_RANGE_STARTBYTE);
    Long endbyte = cycle.getMetaData(CONTENT_RANGE_ENDBYTE);
    HttpServletRequest httpServletRequest = (HttpServletRequest) attributes.getRequest().getContainerRequest();
    try (InputStream inputStream = httpServletRequest.getInputStream()) {
        String script = IOUtils.toString(inputStream);
        if (script.contains("nashornResourceReferenceScriptExecutionThread")) {
            throw new IllegalAccessException(
                    "It is not allowed to gain access to the nashorn thread itself! (nashornResourceReferenceScriptExecutionThread)");
        }
        String safeScript = ensureSafetyScript(script, attributes);
        NashornScriptCallable nashornScriptCallable = new NashornScriptCallable(safeScript, attributes,
                getClassFilter(), getWriter(), getErrorWriter()) {
            @Override
            protected void setup(Attributes attributes, Bindings bindings) {
                NashornResource.this.setup(attributes, bindings);
            }
        };
        Object scriptResult = executeScript(nashornScriptCallable, true);
        ResourceResponse resourceResponse = new ResourceResponse();
        resourceResponse.setContentType("text/plain");
        resourceResponse.setWriteCallback(new PartWriterCallback(
                IOUtils.toInputStream(scriptResult != null ? scriptResult.toString() : ""),
                Long.valueOf(scriptResult != null ? scriptResult.toString().length() : 0), startbyte, endbyte));
        return resourceResponse;
    } catch (Exception e) {
        ResourceResponse errorResourceResponse = processError(e);
        if (errorResourceResponse == null) {
            throw new WicketRuntimeException("Error while reading / executing the script the script", e);
        } else {
            return errorResourceResponse;
        }

    }
}