List of usage examples for org.apache.wicket.protocol.http.servlet ServletWebRequest getContainerRequest
@Override
public HttpServletRequest getContainerRequest()
From source file:dk.teachus.frontend.TeachUsApplication.java
License:Apache License
public String getServerUrl() { String serverUrl = getConfiguration().getConfiguration(ApplicationConfiguration.SERVER_URL); /*/* www.j a v a2 s. com*/ * If the server URL is empty, then the administrator have misconfigured the system (forgot to set the * server URL in the settings). We will get the server URL from the current server, but we will also * warn the administrator by adding an entry to the log. */ if (Strings.isEmpty(serverUrl)) { log.error("No server url is set for the system. It's very important that you set it."); //$NON-NLS-1$ RequestCycle cycle = RequestCycle.get(); ServletWebRequest request = (ServletWebRequest) cycle.getRequest(); HttpServletRequest httpServletRequest = request.getContainerRequest(); StringBuilder b = new StringBuilder(); b.append(httpServletRequest.getScheme()).append("://"); //$NON-NLS-1$ b.append(httpServletRequest.getServerName()); if (httpServletRequest.getServerPort() != 80 && httpServletRequest.getServerPort() != 443) { b.append(":").append(httpServletRequest.getServerPort()); //$NON-NLS-1$ } serverUrl = b.toString(); } return serverUrl; }
From source file:guru.mmp.application.web.pages.WebPage.java
License:Apache License
/** * Returns the IP address of the remote client associated with the request. * * @return the IP address of the remote client associated with the request *///from w w w. j a va2 s . co m public String getRemoteAddress() { ServletWebRequest servletWebRequest = (ServletWebRequest) RequestCycle.get().getRequest(); return servletWebRequest.getContainerRequest().getRemoteAddr(); }
From source file:net.databinder.auth.hib.AuthDataApplication.java
License:Open Source License
/** * Get the restricted token for a user, using IP addresses as location parameter. This implementation * combines the "X-Forwarded-For" header with the remote address value so that unique * values result with and without proxying. (The forwarded header is not trusted on its own * because it can be most easily spoofed.) * @param user source of token/*from w w w . ja v a 2 s . c om*/ * @return restricted token */ public String getToken(DataUser user) { ServletWebRequest request = ((ServletWebRequest) RequestCycle.get().getRequest()); HttpServletRequest req = request.getContainerRequest(); String fwd = req.getHeader("X-Forwarded-For"); if (fwd == null) fwd = "nil"; MessageDigest digest = getDigest(); user.getPassword().update(digest); digest.update((fwd + "-" + req.getRemoteAddr()).getBytes()); byte[] hash = digest.digest(user.getUsername().getBytes()); return new String(Base64.encodeBase64(hash)); }
From source file:net.jawr.web.wicket.AbstractJawrImageReference.java
License:Apache License
protected void onRender() { MarkupStream markupStream = findMarkupStream(); try {/*from www . j a v a 2s . c o m*/ final ComponentTag openTag = markupStream.getTag(); final ComponentTag tag = openTag.mutable(); final IValueMap attributes = tag.getAttributes(); String src = (String) attributes.get("src"); boolean base64 = Boolean.valueOf((String) attributes.get("base64")).booleanValue(); // src is mandatory if (null == src) { throw new IllegalStateException("The src attribute is mandatory for this Jawr tag. "); } // Retrieve the image resource handler ServletWebRequest servletWebRequest = (ServletWebRequest) getRequest(); HttpServletRequest request = servletWebRequest.getContainerRequest(); BinaryResourcesHandler binaryRsHandler = (BinaryResourcesHandler) WebApplication.get() .getServletContext().getAttribute(JawrConstant.BINARY_CONTEXT_ATTRIBUTE); if (null == binaryRsHandler) throw new IllegalStateException( "You are using a Jawr image tag while the Jawr Image servlet has not been initialized. Initialization of Jawr Image servlet either failed or never occurred."); final Response response = getResponse(); src = ImageTagUtils.getImageUrl(src, base64, binaryRsHandler, request, getHttpServletResponseUrlEncoder(response)); Writer writer = new RedirectWriter(response); this.renderer = RendererFactory.getImgRenderer(binaryRsHandler.getConfig(), isPlainImage()); this.renderer.renderImage(src, attributes, writer); } catch (IOException ex) { LOGGER.error("onRender() error : ", ex); } finally { // Reset the Thread local for the Jawr context ThreadLocalJawrContext.reset(); } markupStream.skipComponent(); }
From source file:net.jawr.web.wicket.AbstractJawrReference.java
License:Apache License
@Override protected void onRender() { MarkupStream markupStream = findMarkupStream(); try {//from w ww . j a va2 s . c om final ComponentTag openTag = markupStream.getTag(); final ComponentTag tag = openTag.mutable(); final IValueMap attributes = tag.getAttributes(); // Initialize attributes String src = getReferencePath(attributes); // src is mandatory if (null == src) { throw new IllegalStateException("The src attribute is mandatory for this Jawr reference tag. "); } ServletWebRequest servletWebRequest = (ServletWebRequest) getRequest(); HttpServletRequest request = servletWebRequest.getContainerRequest(); // Get an instance of the renderer. ResourceBundlesHandler rsHandler = (ResourceBundlesHandler) request.getSession().getServletContext() .getAttribute(getResourceHandlerAttributeName()); if (null == rsHandler) { throw new IllegalStateException( "ResourceBundlesHandler not present in servlet context. Initialization of Jawr either failed or never occurred."); } // Refresh the config if needed if (RendererRequestUtils.refreshConfigIfNeeded(request, rsHandler.getConfig())) { rsHandler = (ResourceBundlesHandler) request.getSession().getServletContext() .getAttribute(getResourceHandlerAttributeName()); } Boolean useRandomFlag = null; if (StringUtils.isNotEmpty(useRandomParam)) { useRandomFlag = Boolean.valueOf(useRandomParam); } BundleRenderer renderer = createRenderer(rsHandler, useRandomFlag, tag); // set the debug override RendererRequestUtils.setRequestDebuggable(request, renderer.getBundler().getConfig()); final Response response = getResponse(); Writer writer = new RedirectWriter(response); BundleRendererContext ctx = RendererRequestUtils.getBundleRendererContext(request, renderer); renderer.renderBundleLinks(src, ctx, writer); } catch (IOException ex) { LOGGER.error("onRender() error : ", ex); } finally { // Reset the Thread local for the Jawr context ThreadLocalJawrContext.reset(); } markupStream.skipComponent(); }
From source file:org.alienlabs.hatchetharry.view.page.HomePage.java
License:Open Source License
@SuppressFBWarnings(value = "EC_UNRELATED_TYPES", justification = "If we put 'test'.equals(pp.get('test').toString()) it breaks everything!") public HomePage(final PageParameters pp) throws Exception { this.session = HatchetHarrySession.get(); final ServletWebRequest servletWebRequest = (ServletWebRequest) this.getRequest(); final HttpServletRequest request = servletWebRequest.getContainerRequest(); final String req = request.getQueryString(); if ((req != null) && req.contains("endMatch=true")) { HomePage.LOGGER.info("restart match for player: " + this.session.getPlayer().getId() + " & match: " + this.session.getGameId()); final ConsoleLogStrategy logger = AbstractConsoleLogStrategy.chooseStrategy(ConsoleLogType.GAME, null, null, null, null, this.session.getPlayer().getName(), null, null, null, Boolean.FALSE, this.session.getGameId()); final NotifierCometChannel ncc = new NotifierCometChannel(NotifierAction.END_GAME_ACTION, null, null, this.session.getPlayer().getName(), null, null, null, ""); final List<BigInteger> allPlayersInGameExceptMe = this.persistenceService .giveAllPlayersFromGameExceptMe(this.session.getGameId(), this.session.getPlayer().getId()); EventBusPostService.post(allPlayersInGameExceptMe, new ConsoleLogCometChannel(logger), ncc); request.getSession(false).invalidate(); throw new RestartResponseException(HomePage.class); }/*w w w . ja va 2s . c om*/ if ((pp != null) && (pp.get("displayTooltips") != null) && ("true".equals(pp.get("displayTooltips").toString()))) { this.session.setDisplayTooltips(Boolean.TRUE); } // Resources this.addHeadResources(); final FacebookSdk fsdk = new FacebookSdk("fb-root", "1398596203720626"); fsdk.setFbAdmins("goupilpierre@wanadoo.fr"); this.add(fsdk); if (this.session.isGameCreated().booleanValue()) { this.gameId = new Label("matchId", "Match id: " + this.session.getGameId().longValue()); this.gameId.setOutputMarkupId(true); } else { this.gameId = new Label("matchId", "No match at the moment"); this.gameId.setOutputMarkupId(true); } this.gameIdParent = new WebMarkupContainer("matchIdParent"); this.gameIdParent.setOutputMarkupId(true); this.gameIdParent.add(this.gameId); this.add(this.gameIdParent); this.galleryParent = new WebMarkupContainer("galleryParent"); this.galleryParent.setMarkupId("galleryParent"); this.galleryParent.setOutputMarkupId(true); this.add(this.galleryParent); this.galleryRevealParent = new WebMarkupContainer("galleryRevealParent"); this.galleryRevealParent.setMarkupId("galleryRevealParent"); this.galleryRevealParent.setOutputMarkupId(true); this.galleryReveal = new WebMarkupContainer("galleryReveal"); this.galleryReveal.setOutputMarkupId(true); this.galleryRevealParent.add(this.galleryReveal); this.add(this.galleryRevealParent); this.parentPlaceholder = new WebMarkupContainer("parentPlaceholder"); this.parentPlaceholder.setOutputMarkupId(true); this.add(this.parentPlaceholder); this.opponentParentPlaceholder = new WebMarkupContainer("opponentParentPlaceholder"); this.opponentParentPlaceholder.setOutputMarkupId(true); this.add(this.opponentParentPlaceholder); if (!this.session.isGameCreated().booleanValue()) { this.dataGenerator.afterPropertiesSet(); this.createPlayer(); this.buildHandCards(); this.buildHandMarkup(); this.buildDataBox(this.player.getGame().getId().longValue()); } else { if (this.session.getPlayer() == null) { this.createPlayer(); } else { this.restoreBattlefieldState(); } this.player = this.session.getPlayer(); this.buildHandCards(); this.buildDataBox(this.player.getGame().getId().longValue()); } // Side this.sideParent = new WebMarkupContainer("sideParent"); this.sideParent.setOutputMarkupId(true); this.allPlayerSidesInGame = this.persistenceService .getAllPlayersOfGame(this.session.getGameId().longValue()); final ListDataProvider<Player> data = new ListDataProvider<>(this.allPlayerSidesInGame); this.allSidesInGame = this.populateSides(data); this.sideParent.add(this.allSidesInGame); this.add(this.sideParent); this.graveyardParent = new WebMarkupContainer("graveyardParent"); this.graveyardParent.setMarkupId("graveyardParent"); this.graveyardParent.setOutputMarkupId(true); this.add(this.graveyardParent); this.exileParent = new WebMarkupContainer("exileParent"); this.exileParent.setMarkupId("exileParent"); this.exileParent.setOutputMarkupId(true); this.add(this.exileParent); // Welcome message final Label message1 = new Label("message1", "version 0.24.0 (release Battlefield),"); final Label message2 = new Label("message2", "built on Monday, 19th of January 2015."); this.add(message1, message2); // Comet clock channel this.clockPanel = new ClockPanel("clockPanel", Model.of("###")); this.clockPanel.setOutputMarkupId(true); this.clockPanel.setMarkupId("clock"); this.add(this.clockPanel); // Sides this.secondSidePlaceholderParent = new WebMarkupContainer("secondSidePlaceholderParent"); this.secondSidePlaceholderParent.setOutputMarkupId(true); this.secondSidePlaceholderParent.setMarkupId("secondSidePlaceholderParent"); final WebMarkupContainer secondSidePlaceholder = new WebMarkupContainer("secondSidePlaceholder"); secondSidePlaceholder.setOutputMarkupId(true); secondSidePlaceholder.setMarkupId("secondSidePlaceholder"); this.secondSidePlaceholderParent.add(secondSidePlaceholder); this.firstSidePlaceholderParent = new WebMarkupContainer("firstSidePlaceholderParent"); this.firstSidePlaceholderParent.setOutputMarkupId(true); this.firstSidePlaceholderParent.setMarkupId("firstSidePlaceholderParent"); final WebMarkupContainer firstSidePlaceholder = new WebMarkupContainer("firstSidePlaceholder"); firstSidePlaceholder.setOutputMarkupId(true); this.firstSidePlaceholderParent.add(firstSidePlaceholder); this.add(this.secondSidePlaceholderParent, this.firstSidePlaceholderParent); // Placeholders for CardPanel-adding with AjaxRequestTarget this.createCardPanelPlaceholders(); this.buildGraveyardMarkup(); this.buildExileMarkup(); this.buildDock(); // Links from the menubar this.aboutWindow = new ModalWindow("aboutWindow"); this.aboutWindow = this.generateAboutLink("aboutLink", this.aboutWindow); this.teamInfoWindow = new ModalWindow("teamInfoWindow"); this.teamInfoWindow = this.generateTeamInfoLink("teamInfoLink", this.teamInfoWindow); /* * Links from the drop-down menu, which appears when the width of the * view port is < than its height. (AKA a little bit of responsive Web * design) */ this.aboutWindow = this.generateAboutLink("aboutLinkResponsive", this.aboutWindow); this.mulliganWindow = new ModalWindow("mulliganWindow"); this.generateMulliganLink("mulliganLink", this.mulliganWindow); this.generateMulliganLink("mulliganLinkResponsive", this.mulliganWindow); this.askMulliganWindow = new ModalWindow("askMulliganWindow"); this.askMulliganWindow.setInitialWidth(500); this.askMulliganWindow.setInitialHeight(100); this.askMulliganWindow.setCssClassName(ModalWindow.CSS_CLASS_GRAY); this.askMulliganWindow.setMaskType(ModalWindow.MaskType.SEMI_TRANSPARENT); this.add(this.askMulliganWindow); this.teamInfoWindow = this.generateTeamInfoLink("teamInfoLinkResponsive", this.teamInfoWindow); final GameNotifierBehavior notif = new GameNotifierBehavior(this); this.add(notif); this.createGameWindow = new ModalWindow("createMatchWindow"); this.add(this.createGameWindow = this.generateCreateGameModalWindow("createMatchLink", this.player, this.createGameWindow)); this.add(this.createGameWindow = this.generateCreateGameModalWindow("createMatchLinkResponsive", this.player, this.createGameWindow)); this.joinGameWindow = new ModalWindow("joinMatchWindow"); this.add(this.joinGameWindow = this.generateJoinGameModalWindow("joinMatchLink", this.player, this.joinGameWindow)); this.add(this.joinGameWindow = this.generateJoinGameModalWindow("joinMatchLinkResponsive", this.player, this.joinGameWindow)); this.joinGameWithoutIdWindow = new ModalWindow("joinMatchWithoutIdWindow"); this.add(this.joinGameWithoutIdWindow = this.generateJoinGameWithoutIdModalWindow("joinMatchWithoutIdLink", this.player, this.joinGameWithoutIdWindow)); this.add(this.joinGameWithoutIdWindow = this.generateJoinGameWithoutIdModalWindow( "joinMatchWithoutIdLinkResponsive", this.player, this.joinGameWithoutIdWindow)); this.generatePlayCardLink(); this.add(this.generatePlayCardFromGraveyardLink("playCardFromGraveyardLinkDesktop")); this.add(this.generatePlayCardFromGraveyardLink("playCardFromGraveyardLinkResponsive")); this.generateCardPanels(); this.generateDrawCardLink(); final RedrawArrowsBehavior rab = new RedrawArrowsBehavior(this.player.getGame().getId()); this.add(rab); // Comet chat channel this.add(new ChatPanel("chatPanel")); this.buildEndTurnLink(); this.buildInResponseLink(); this.buildFineForMeLink(); this.buildUntapAllLink(); this.buildUntapAndDrawLink(); this.buildCombatLink(); this.importDeckDialog = new ImportDeckDialog("importDeckDialog"); this.add(this.importDeckDialog); this.generateImportDeckLink("importDeckLink"); this.generateImportDeckLink("importDeckLinkResponsive"); this.allOpenRevealTopLibraryCardWindows = new ArrayList<>(); this.generateRevealTopLibraryCardLink("revealTopLibraryCardLink", "revealTopLibraryCardWindow"); this.generateRevealTopLibraryCardLink("revealTopLibraryCardLinkResponsive", "revealTopLibraryCardWindowResponsive"); this.createTokenWindow = new ModalWindow("createTokenWindow"); this.generateCreateTokenLink("createTokenLink", this.createTokenWindow); this.generateCreateTokenLink("createTokenLinkResponsive", this.createTokenWindow); this.countCardsWindow = new ModalWindow("countCardsWindow"); this.generateCountCardsLink("countCardsLink", this.countCardsWindow); this.generateCountCardsLink("countCardsLinkResponsive", this.countCardsWindow); this.generateDiscardAtRandomLink("discardAtRandomLink"); this.generateDiscardAtRandomLink("discardAtRandomLinkResponsive"); this.generateInsertDivisionLink("insertDivisionLink"); this.generateInsertDivisionLink("insertDivisionLinkResponsive"); this.generateShuffleLibraryLink("shuffleLibraryLink"); this.generateShuffleLibraryLink("shuffleLibraryLinkResponsive"); this.loginWindow = new ModalWindow("loginWindow"); this.generateLoginLink("loginLink", this.loginWindow); this.generateLoginLink("loginLinkResponsive", this.loginWindow); final FacebookLoginBehavior flb = new FacebookLoginBehavior(); this.add(flb); this.preferencesWindow = new ModalWindow("preferencesWindow"); this.generatePreferencesLink("preferencesLink", this.preferencesWindow); this.generatePreferencesLink("preferencesLinkResponsive", this.preferencesWindow); this.generateEndMatchLink("endMatchLink"); this.generateEndMatchLink("endMatchLinkResponsive"); this.generateHideAllTooltipsLink("hideAllTooltipsLink"); this.generateHideAllTooltipsLink("hideAllTooltipsLinkResponsive"); this.conferenceParent = new WebMarkupContainer("conferenceParent"); this.conferenceParent.setOutputMarkupId(true); final ConferencePanel conference = new ConferencePanel("conference"); conference.setOutputMarkupId(true); this.conferenceParent.add(conference); this.add(this.conferenceParent); this.generateOpenConferenceLink("conferenceOpener"); this.generateOpenConferenceLink("conferenceOpenerResponsive"); this.generateRevealHandLink("revealHandLink"); this.generateRevealHandLink("revealHandLinkResponsive"); // For console logs & chat messages this.add(new MessageRedisplayBehavior(this.session.getGameId())); this.drawModeParent = new WebMarkupContainer("drawModeParent"); this.drawModeParent.setOutputMarkupId(true); if (this.session.getPlayer().getGame().isDrawMode().booleanValue()) { this.drawModeParent.add(new ExternalImage("drawModeOn", "image/draw_mode_on.png")); } else { this.drawModeParent.add(new WebMarkupContainer("drawModeOn").setVisible(false)); } this.add(this.drawModeParent); if (this.session.isLoggedIn().booleanValue()) { this.username = new Label("username", "Logged in as " + this.session.getUsername()); this.username.setOutputMarkupId(true); } else { this.username = new Label("username", "Not logged in"); this.username.setOutputMarkupId(true); } this.usernameParent = new WebMarkupContainer("usernameParent"); this.usernameParent.setOutputMarkupId(true); this.usernameParent.add(this.username); this.add(this.usernameParent); }
From source file:org.cyclop.web.webapp.CyclopWebSession.java
License:Apache License
private void bindExpirationListener() { ServletWebRequest webRequest = (ServletWebRequest) RequestCycle.get().getRequest(); HttpServletRequest servRequest = webRequest.getContainerRequest(); HttpSession session = servRequest.getSession(); session.setMaxInactiveInterval(conf.httpSession.expirySeconds); }
From source file:org.hippoecm.frontend.util.WebApplicationHelper.java
License:Apache License
public static int getMaxInactiveIntervalMinutes() { final ServletWebRequest servletRequest = (ServletWebRequest) RequestCycle.get().getRequest(); final HttpSession httpSession = servletRequest.getContainerRequest().getSession(); // round seconds down to minutes return httpSession.getMaxInactiveInterval() / 60; }
From source file:org.projectforge.web.imagecropper.ImageCropperPage.java
License:Open Source License
/** * See list of constants PARAM_* for supported parameters. * @param parameters/* w w w . ja v a 2s .c om*/ */ public ImageCropperPage(final PageParameters parameters) { super(parameters); if (WicketUtils.contains(parameters, PARAM_SHOW_UPLOAD_BUTTON) == true) { setEnableWhiteBoardFilter(WicketUtils.getAsBoolean(parameters, PARAM_SHOW_UPLOAD_BUTTON)); } if (WicketUtils.contains(parameters, PARAM_ENABLE_WHITEBOARD_FILTER) == true) { setEnableWhiteBoardFilter(WicketUtils.getAsBoolean(parameters, PARAM_ENABLE_WHITEBOARD_FILTER)); } if (WicketUtils.contains(parameters, PARAM_LANGUAGE) == true) { setDefaultLanguage(WicketUtils.getAsString(parameters, PARAM_LANGUAGE)); } if (WicketUtils.contains(parameters, PARAM_RATIOLIST) == true) { setRatioList(WicketUtils.getAsString(parameters, PARAM_RATIOLIST)); } if (WicketUtils.contains(parameters, PARAM_DEFAULT_RATIO) == true) { setDefaultRatio(WicketUtils.getAsString(parameters, PARAM_DEFAULT_RATIO)); } if (WicketUtils.contains(parameters, PARAM_FILE_FORMAT) == true) { setFileFormat(WicketUtils.getAsString(parameters, PARAM_FILE_FORMAT)); } final ServletWebRequest req = (ServletWebRequest) this.getRequest(); final HttpServletRequest hreq = req.getContainerRequest(); String domain; if (StringUtils.isNotBlank(ConfigXml.getInstance().getDomain()) == true) { domain = ConfigXml.getInstance().getDomain(); } else { domain = hreq.getScheme() + "://" + hreq.getLocalName() + ":" + hreq.getLocalPort(); } final String url = domain + hreq.getContextPath() + "/secure/"; final StringBuffer buf = new StringBuffer(); appendVar(buf, "serverURL", url); // TODO: Wird wohl nicht mehr gebraucht. appendVar(buf, "uploadImageFileTemporaryServlet", url + "UploadImageFileTemporary"); appendVar(buf, "uploadImageFileTemporaryServletParams", "filedirectory=tempimages;filename=image"); appendVar(buf, "downloadImageFileServlet", url + "DownloadImageFile"); appendVar(buf, "downloadImageFileServletParams", "filedirectory=tempimages;filename=image"); appendVar(buf, "uploadImageFileServlet", url + "UploadImageFile"); appendVar(buf, "uploadImageFileServletParams", "filedirectory=images;filename=image;croppedname=cropped"); appendVar(buf, "upAndDownloadImageFileAsByteArrayServlet", url + "UpAndDownloadImageFileAsByteArray"); appendVar(buf, "upAndDownloadImageFileAsByteArrayServletParams", "filename=image;croppedname=cropped"); final HttpSession httpSession = hreq.getSession(); appendVar(buf, "sessionid", httpSession.getId()); appendVar(buf, "ratioList", ratioList); appendVar(buf, "defaultRatio", defaultRatio); appendVar(buf, "isUploadBtn", showUploadButton); appendVar(buf, "whiteBoardFilter", enableWhiteBoardFilter); appendVar(buf, "language", getDefaultLanguage()); appendVar(buf, "fileFormat", fileFormat); appendVar(buf, "flashFile", WicketUtils.getAbsoluteUrl("/imagecropper/MicromataImageCropper")); add(new Label("javaScriptVars", buf.toString()).setEscapeModelStrings(false)); }