List of usage examples for org.apache.wicket Session getId
public final String getId()
From source file:com.evolveum.midpoint.web.security.MidPointAuthWebSession.java
License:Apache License
private void auditEvent(Authentication authentication, String username, OperationResultStatus status) { MidPointPrincipal principal = SecurityUtils.getPrincipalUser(authentication); PrismObject<UserType> user = principal != null ? principal.getUser().asPrismObject() : null; Task task = taskManager.createTaskInstance(); task.setOwner(user);//from w w w . j av a 2 s . c o m task.setChannel(SchemaConstants.CHANNEL_GUI_USER_URI); AuditEventRecord record = new AuditEventRecord(AuditEventType.CREATE_SESSION, AuditEventStage.REQUEST); record.setInitiator(user); record.setParameter(username); record.setChannel(SchemaConstants.CHANNEL_GUI_USER_URI); Url url = RequestCycle.get().getRequest().getUrl(); record.setHostIdentifier(url.getHost()); record.setTimestamp(System.currentTimeMillis()); Session session = ThreadContext.getSession(); if (session != null) { record.setSessionIdentifier(session.getId()); } record.setOutcome(status); auditService.audit(record, task); }
From source file:com.fortuityframework.wicket.WicketEventListenerLocator.java
License:Apache License
static void addSession(Session session) { if (!sessionReferences.containsKey(session)) { sessionReferences.put(session.getId(), new WeakReference<Session>(session)); }//from www . ja v a2s. com }
From source file:fiftyfive.wicket.util.LoggingUtils.java
License:Apache License
/** * Returns a Map with information associated with the following keys: * <ul>//w w w .j a v a 2 s. c om * <li>{@code ID}</li> * <li>{@code Info} (if session implements {@link ISessionLogInfo})</li> * <li>{@code Size}</li> * <li>{@code Duration} (if {@link IRequestLogger} is enabled)</li> * </ul> */ public static Map<String, Object> getSessionInfo() { Session sess = Session.get(); Object detail = "--ISessionLogInfo not implemented--"; if (sess instanceof ISessionLogInfo) { detail = ((ISessionLogInfo) sess).getSessionInfo(); } Map<String, Object> info = new LinkedHashMap<String, Object>(); if (sess != null) { info.put("ID", sess.getId()); info.put("Info", detail); info.put("Size", Bytes.bytes(sess.getSizeInBytes())); Duration dur = getSessionDuration(); if (dur != null) { info.put("Duration", getSessionDuration()); } } return info; }
From source file:fiftyfive.wicket.util.LoggingUtils.java
License:Apache License
/** * Returns the amount of time the currently session has been active. * Depends on Wicket's {@link IRequestLogger} being enabled. If it is not, * returns {@code null}./*from ww w.j av a2s . c o m*/ */ public static Duration getSessionDuration() { Date start = null; Session currSession = Session.get(); IRequestLogger log = Application.get().getRequestLogger(); if (log != null && currSession != null && currSession.getId() != null) { String sessionId = currSession.getId(); SessionData[] sessions = log.getLiveSessions(); if (sessions != null) { for (SessionData sess : sessions) { if (sessionId.equals(sess.getSessionId())) { start = sess.getStartDate(); break; } } } } return nullSafeElapsed(start); }
From source file:nl.knaw.dans.dccd.web.upload.TreeRingDataUploadProcess.java
License:Apache License
public List<File> execute(List<File> files, File destPath, Map<String, String> clientParams) throws UploadPostProcessException { logger.info("Upload Treering data file started..."); Session session = Session.get(); logger.debug("Session id: " + session.getId()); CombinedUpload combinedUpload = ((DccdSession) session).getCombinedUpload(); combinedUpload.clearTreeRingDataUploadWarnings(); int fileCounter = 0; int numFiles = files.size(); for (File file : files) { setStatus((int) Math.floor(100.0 * ((double) fileCounter) / (double) numFiles), file); try {/*from w ww. j av a 2 s .c o m*/ logger.info("Reading file: " + file.getAbsolutePath()); setStatus((int) Math.floor(100.0 * ((double) fileCounter + 0.5) / (double) numFiles), file); // get the format and convert String formatString = combinedUpload.getFormat(); DccdTreeRingData data = TreeRingDataFileService.load(file, formatString); // No store, but keep the data for later use, after uploading! combinedUpload.addDccdTreeRingData(data); logger.debug("Added to the data list");// Data converted for range period: " + data.getRange()); logger.debug("=== Request for Status after treeringdata upload === in thread: " + Thread.currentThread().getId()); combinedUpload.getStatus(); } catch (TreeRingDataFileServiceException e) { String errorMsg = "Failed loading file: " + FileUtil.getBasicFilename(file.getAbsolutePath()); errorMsg += ", Cause: " + e.getMessage(); // invalid, show an error page? // Validation failed? // Note: a reason/indication would be usefull! logger.error(errorMsg); status.setError(errorMsg); // TODO get strings from properties String warningMsg = "File '" + FileUtil.getBasicFilename(file.getAbsolutePath()) + "' was not uploaded, because it appears not to be in the correct " + combinedUpload.getFormat() + " format."; combinedUpload.appendTreeRingDataUploadWarnings(warningMsg); throw new UploadPostProcessException(e); //break; // cancel remaining files } if (canceled) { // note: no rollback implemented, nothing is stored in a repository yet! //rollBack(); break; } fileCounter++; } // end for all files status.setFinished(true); return files; }
From source file:nl.knaw.dans.dccd.web.upload.TridasXMLUploadProcess.java
License:Apache License
public List<File> execute(List<File> files, File destPath, Map<String, String> clientParams) throws UploadPostProcessException { logger.info("Upload Tridas file started..."); Session session = Session.get(); logger.debug("Session id: " + session.getId()); CombinedUpload combinedUpload = ((DccdSession) session).getCombinedUpload(); int fileCounter = 0; int numFiles = files.size(); for (File file : files) { setStatus((int) Math.floor(100.0 * ((double) fileCounter) / (double) numFiles), file); FileInputStream fis = null; try {//from ww w .ja v a 2 s . com logger.info("Reading file: " + file.getAbsolutePath()); fis = new FileInputStream(file.getAbsolutePath()); setStatus((int) Math.floor(100.0 * ((double) fileCounter + 0.5) / (double) numFiles), file); // get the user(ID) that uploaded it User user = ((DccdSession) Session.get()).getUser(); // parse TRiDaS file logger.info("Parse..."); Project newProject = XMLFilesRepositoryService.createDendroProjectFromTridasXML(fis, user.getId()); logger.info("Done"); setStatus((int) Math.floor(100.0 * ((double) fileCounter + 1.0) / (double) numFiles), file); // store the (original) xml filename newProject.setFileName(file.getName()); // Note: build the complete tree of entities, we can use for searching, // maybe this should be done by: XMLFilesRepositoryService.getDendroProjectFromTridasXML // and then copy the tree also? newProject.entityTree.buildTree(newProject.getTridas()); // store the user(ID) that uploaded it newProject.setOwnerId(user.getId()); combinedUpload.addProject(newProject); logger.debug("=== Request for Status after tridas upload === in thread: " + Thread.currentThread().getId()); //logger.debug("UUID: " + combinedUpload.getUuid()); combinedUpload.getStatus(); } catch (FileNotFoundException e) { logger.error("Could not open file", e); // Note: looks like an internal error, because it should be readable // the web user can't do anything about it // upload failed for reasons beyond the reach of the user! throw (new InternalErrorException(e)); // cancel remaining files } catch (TridasLoadException e) { // Validation failed // Give feedback about the problem String errorMsg = "Failed validating file: " + FileUtil.getBasicFilename(file.getAbsolutePath()); errorMsg += ", Cause: " + e.getMessage(); // Only two reasons: // - Not conform the TRiDaS Standard (also when not valid XML) // - More than one project in TRiDaS file // // ? linked exception ? // ? cause ? //Throwable cause = e.getCause(); //if (cause != null && cause.getMessage() != null) { // errorMsg += " Cause: " + cause.getMessage(); //} logger.error(errorMsg);//, e); status.setError(errorMsg); // Note: the error message is no localized! // Maybe use specific exceptions and - depending on the type - // construct a localized message? //TODO get the strings from properties String warningMsg = "File '" + FileUtil.getBasicFilename(file.getAbsolutePath()) + "' was not uploaded, because it contains invalid TRiDaS XML. Please correct the file and upload it again."; // Add more detail information to the problem if we have it Throwable cause = e.getCause(); if (cause instanceof JAXBException) { Throwable le = ((JAXBException) cause).getLinkedException(); warningMsg += "\n Details: " + le.getMessage(); //logger.debug("Linked: " + le.getMessage()); } combinedUpload.setTridasUploadWarnings(warningMsg); throw new UploadPostProcessException(e); //break; // cancel remaining files } finally { // free resources if (fis != null) try { fis.close(); } catch (IOException e) { logger.warn("Could not close inputstream"); } } if (canceled) { // note: no rollback implemented, because no purge implemented! //rollBack(); break; } fileCounter++; } // end for all files status.setFinished(true); return files; }
From source file:nl.knaw.dans.dccd.web.upload.UploadFilesPage.java
License:Apache License
@Override protected void onBeforeRender() { // retrieve the status, used for the UI CombinedUploadStatus status = getStatus(); logger.debug("Finish: " + status.isReadyToFinish() + ", Cancel: " + status.isReadyToCancel()); Session session = Session.get(); String sessionId = session.getId(); logger.debug("=> Session Id: " + sessionId); logger.debug("=> Page Id: " + getId()); //Note: measurements_filetype selection might be set here also // messages (Label models) uploadHintsModel.setObject(status.getMessage()); // tridas//w w w . ja va 2s . c om tridasCombinedUploadHintsModel.setObject(status.getTridasUploadHints()); tridasCombinedUploadWarningsModel.setObject(status.getTridasUploadWarnings()); tridasFilesUploadedMessageModel.setObject(status.getTridasFilesUploadedMessage()); // treeringdata treeRingDataCombinedUploadErrorsModel.setObject(status.getTreeRingDataUploadErrors()); treeRingDataCombinedUploadWarningsModel.setObject(status.getTreeRingDataUploadWarnings()); treeRingDataFilesUploadedMessageModel.setObject(status.getTreeRingDataFilesUploadedMessage()); // All switching is already done in the JS code on the client; // but when a page reload is done we need to get it right // if (getCombinedUpload().hasProject()) { // a tridas must have been succesfully uploaded // when this has happened we hide the upload for another tridas uploadTridas.setVisible(false); } // Note: Maybe make a Panel or Component group (container // for the different upload parts. // For now the wicket:enclosure makes sure the whole group is hidden if (uploadType == TridasUploadType.TRIDAS_ONLY) { // hide value files upload uploadTreeRingData.setVisible(false); treeRingDataCombinedUploadWarningsLabel.setVisible(false); treeRingDataCombinedUploadErrorsLabel.setVisible(false); treeRingDataFilesUploadedMessageLabel.setVisible(false); fileTypeSelection.setVisible(false); } else { uploadTreeRingData.setVisible(true); treeRingDataCombinedUploadWarningsLabel.setVisible(true); treeRingDataCombinedUploadErrorsLabel.setVisible(true); treeRingDataFilesUploadedMessageLabel.setVisible(true); fileTypeSelection.setVisible(true); } // Note: switching on status.isAssociatedFilesVisible() // somehow does not produce the correct results... super.onBeforeRender(); }