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

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

Introduction

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

Prototype

@Override
public Request getRequest() 

Source Link

Usage

From source file:at.molindo.wicketutils.utils.WicketUtils.java

License:Apache License

/**
 * @return may return null/*ww w  . ja  v a 2 s. c om*/
 */
public static Request getRequest() {
    final RequestCycle rc = RequestCycle.get();
    return rc == null ? null : rc.getRequest();
}

From source file:com.evolveum.midpoint.web.application.AsyncWebProcessManagerImpl.java

License:Apache License

private Key createProcessIdentifier(String processId) {
    RequestCycle rc = RequestCycle.get();
    Request req = rc.getRequest();

    HttpSession session = ((ServletWebRequest) req).getContainerRequest().getSession();
    return new Key(session.getId(), processId);
}

From source file:com.evolveum.midpoint.web.page.admin.resources.PageResourceVisualizationCytoscape.java

License:Apache License

private void initLayout(PrismObject<ResourceType> resourceObject) {
    retrievalBehavior = new AbstractAjaxBehavior() {
        @Override/*  www .  j av a2s.  c  o  m*/
        public void onRequest() {
            System.out.println("retrieve CS data: starting");
            RequestCycle requestCycle = getRequestCycle();
            requestCycle.scheduleRequestHandlerAfterCurrent(null);

            MidPointApplication app = (MidPointApplication) MidPointApplication.get();
            TaskManager taskManager = app.getTaskManager();
            Task task = taskManager.createTaskInstance(PageResourceVisualizationCytoscape.class + ".onRequest");

            String jsonData;
            try {
                jsonData = app.getModelDiagnosticService().exportDataModel(resourceObject.asObjectable(),
                        DataModelVisualizer.Target.CYTOSCAPE, task, task.getResult());
                System.out.println("JSON Cytoscape Data:\n" + jsonData);
            } catch (CommonException | RuntimeException e) {
                LoggingUtils.logUnexpectedException(LOGGER, "Couldn't visualize resource {}", e,
                        resourceObject);
                jsonData = "{\"nodes\":[], \"edges\":[]}"; // TODO better error handling
            }

            IResource jsonResource = new ByteArrayResource("application/json", jsonData.getBytes());
            IRequestHandler requestHandler = new ResourceRequestHandler(jsonResource, null);
            requestHandler.respond(requestCycle);
            System.out.println("retrieve CS data: response written");
        }
    };
    add(retrievalBehavior);

    deletionBehavior = new AbstractAjaxBehavior() {
        @Override
        public void onRequest() {
            System.out.println("deleteAttribute: starting");
            RequestCycle requestCycle = getRequestCycle();
            requestCycle.scheduleRequestHandlerAfterCurrent(null);

            MidPointApplication app = (MidPointApplication) MidPointApplication.get();
            TaskManager taskManager = app.getTaskManager();
            Task task = taskManager.createTaskInstance(PageResourceVisualizationCytoscape.class + ".onRequest");

            try {
                IRequestParameters parameters = requestCycle.getRequest().getQueryParameters();
                String resourceOid = parameters.getParameterValue("resourceOid").toString();
                String kind = parameters.getParameterValue("kind").toString();
                String intent = parameters.getParameterValue("intent").toString();
                String objectClass = parameters.getParameterValue("objectClass").toString();
                String attributeName = parameters.getParameterValue("attributeName").toString();
                System.out.println("ResourceOid: " + resourceOid + ", kind: " + kind + ", intent: " + intent
                        + ", objectClass: " + objectClass + ", attributeName: " + attributeName);
            } catch (RuntimeException e) {
                LoggingUtils.logUnexpectedException(LOGGER, "Couldn't delete attribute", e);
            }

            IResource resource = new ByteArrayResource("text/plain", "OK".getBytes());
            IRequestHandler requestHandler = new ResourceRequestHandler(resource, null);
            requestHandler.respond(requestCycle);
            System.out.println("deleteAttribute: finished");
        }
    };
    add(deletionBehavior);
}

From source file:com.evolveum.midpoint.web.security.LoggingRequestCycleListener.java

License:Apache License

@Override
public void onBeginRequest(RequestCycle cycle) {
    if (REQUEST_LOGGER.isTraceEnabled()) {
        REQUEST_LOGGER.trace("REQUEST CYCLE: Begin request: '{}', handler {}",
                cycle.getRequest().getOriginalUrl(),
                WebComponentUtil.debugHandler(cycle.getActiveRequestHandler()));
    }//from  w w  w  . j a v a  2s.  c o  m
    super.onBeginRequest(cycle);
}

From source file:com.evolveum.midpoint.web.security.LoggingRequestCycleListener.java

License:Apache License

@Override
public void onEndRequest(RequestCycle cycle) {
    if (REQUEST_LOGGER.isTraceEnabled()) {
        REQUEST_LOGGER.trace("REQUEST CYCLE: End request: '{}', next handler: {}",
                cycle.getRequest().getOriginalUrl(),
                WebComponentUtil.debugHandler(cycle.getRequestHandlerScheduledAfterCurrent()));
    }/*from   w ww. j  a va 2  s. c  o m*/
    super.onBeginRequest(cycle);
}

From source file:com.evolveum.midpoint.web.security.LoggingRequestCycleListener.java

License:Apache License

@Override
public void onDetach(RequestCycle cycle) {
    if (REQUEST_LOGGER.isTraceEnabled()) {
        REQUEST_LOGGER.trace("REQUEST CYCLE: Detach, request: '{}', next handler: {}",
                cycle.getRequest().getOriginalUrl(),
                WebComponentUtil.debugHandler(cycle.getRequestHandlerScheduledAfterCurrent()));

    }//from   w  ww . j av  a2 s  . c  om
    super.onBeginRequest(cycle);
}

From source file:com.francetelecom.clara.cloud.presentation.ExecutionHandlerRequestCycle.java

License:Apache License

protected boolean isRequestAMainPage(RequestCycle cycle) {
    String requestPage = cycle.getRequest().getContextPath();
    return !requestPage.endsWith(".css") && !requestPage.endsWith(".js");
}

From source file:com.francetelecom.clara.cloud.presentation.ExecutionHandlerRequestCycle.java

License:Apache License

/**
 * Init of user for wdm-core ActionContext and call parentMethod
 *///ww w .ja v  a  2  s .com
@Override
public void onBeginRequest(RequestCycle cycle) {
    if (manageStatistics != null && manageStatistics.isStatEnable() && isRequestAMainPage(cycle)) {
        statsSnapshotId = manageStatistics.startSnapshot(cycle.getRequest().getUrl().getPath()); // request.getPath());
    }
    if (cycle.getRequest() != null) {
        try {
            WicketSession wicketSession = (WicketSession) Session.get();
            if (wicketSession.getPaasUser() != null) {
                MDC.put(LOG_KEY_USER, wicketSession.getPaasUser().getSsoId().getValue());
                MDC.put(LOG_KEY_USERNAME, wicketSession.getPaasUser().getFirstName());
                MDC.put(LOG_KEY_SESSION, wicketSession.getId());
            }
        } catch (Exception e) {
            // Ignore it
        }
        final int requestId = nextRequestId();
        logger.trace("Setting MDC-requestId param to {}", requestId);
        MDC.put("requestId", requestId + "");
        if (cycle.getRequest().getUrl() != null) {
            String urlPath = cycle.getRequest().getUrl().getPath();
            logger.trace("Setting MDC-page param to {}", urlPath);
            MDC.put("page", urlPath);
            String url = cycle.getRequest().getUrl().toString();
            logger.trace("Setting MDC-url param to {}", url);
            MDC.put("url", url);
        }
    }
}

From source file:com.francetelecom.clara.cloud.presentation.ExecutionHandlerRequestCycle.java

License:Apache License

@Override
public void onEndRequest(RequestCycle cycle) {
    logger.trace("Removing MDC-requestId");
    MDC.remove("requestId");
    logger.trace("Removing MDC-page");
    MDC.remove("page");
    logger.trace("Removing MDC-page");
    MDC.remove("page");
    if (manageStatistics != null && manageStatistics.isStatEnable() && isRequestAMainPage(cycle)) {
        try {//from  ww  w  .  ja  v  a 2s. c o  m
            PaasStats stats = manageStatistics.endSnapShot(statsSnapshotId);
            WicketSession session = WicketSession.get();
            session.addStats(stats);
        } catch (ResourceNotFoundException rnfe) {
            logger.error("stats error (url:{}): {}", cycle.getRequest().getUrl(), rnfe.getMessage());
        } catch (BusinessException be) {
            logger.error("stats error : {}", be.getMessage(), be);
        }
    }
    MDC.remove(LOG_KEY_USER);
    MDC.remove(LOG_KEY_USERNAME);
    MDC.remove(LOG_KEY_SESSION);
}

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

License:Apache License

protected HttpServletRequest getRequest(RequestCycle cycle) {
    return (HttpServletRequest) cycle.getRequest().getContainerRequest();
}