List of usage examples for org.springframework.web.context.request WebRequest getAttribute
@Nullable
Object getAttribute(String name, int scope);
From source file:com.springsource.greenhouse.connect.FacebookConnectInterceptor.java
private void useFacebookProfileImage(Connection<Facebook> connection, Account account, WebRequest request) { if (request.getAttribute(USE_FACEBOOK_IMAGE_ATTRIBUTE, WebRequest.SCOPE_SESSION) != null) { try {//from ww w .j av a 2 s.c o m profilePictureService.saveProfilePicture(account.getId(), connection.getApi().userOperations().getUserProfileImage()); } catch (IOException e) { NativeWebRequest nativeRequest = (NativeWebRequest) request; HttpServletRequest servletRequest = nativeRequest.getNativeRequest(HttpServletRequest.class); FlashMap flashMap = RequestContextUtils.getOutputFlashMap(servletRequest); flashMap.put("message", Message.warning("Greenhouse was unable to use your Facebook profile picture.")); } request.removeAttribute(USE_FACEBOOK_IMAGE_ATTRIBUTE, WebRequest.SCOPE_SESSION); } }
From source file:org.focusns.web.oauth.OAuthController.java
@RequestMapping("/callback") public String callback(@RequestParam String code, WebRequest webRequest) { OAuthService oAuthService = (OAuthService) webRequest.getAttribute("oAuthService", WebRequest.SCOPE_SESSION);// w w w. ja v a 2 s . com // Verifier verifier = new Verifier(code); Token accessToken = oAuthService.getAccessToken(EMPTY_TOKEN, verifier); webRequest.setAttribute("accessToken", accessToken, WebRequest.SCOPE_SESSION); // return "redirect:/register"; }
From source file:com.seajas.search.codex.social.interceptor.AbstractConnectInterceptor.java
/** * Retrieve the username-state parameter from the request. * //from w w w. j a v a 2s .c o m * @param request * @return String */ protected String getState(final WebRequest request) { return (String) request.getAttribute(REQUEST_STATE_USERNAME, RequestAttributes.SCOPE_SESSION); }
From source file:com.example.CommonModelConfiguration.java
private WebRequestInterceptor interceptor() { return new WebRequestInterceptor() { @Override//from w w w .j a va 2 s.c o m public void preHandle(WebRequest request) throws Exception { } @Override public void postHandle(WebRequest request, ModelMap model) throws Exception { if (request.getAttribute("contextPath", WebRequest.SCOPE_REQUEST) == null) { model.put("contextPath", server.getContextPath() == null ? "" : server.getContextPath()); model.put("api", cloud.getApi()); } else { // Slightly bizarre. Prevents error in template view when forwarding // to a view with the user already present. model.remove("user"); } } @Override public void afterCompletion(WebRequest request, Exception ex) throws Exception { } }; }
From source file:org.easit.core.controllers.twitter.TwitterAfterConnectInterceptor.java
@Override public void postConnect(Connection<Twitter> connection, WebRequest request) { request.setAttribute("connectedToTwitter", connection.test(), WebRequest.SCOPE_SESSION); request.setAttribute("connectedToAny", connectionRepository.findAllConnections().size() > 0, WebRequest.SCOPE_SESSION);//from w ww . j ava2 s. com if (request.getAttribute(POST_TWEET_ATTRIBUTE, WebRequest.SCOPE_SESSION) != null) { try { connection.updateStatus("Connected!"); } catch (DuplicateStatusException e) { } request.removeAttribute(POST_TWEET_ATTRIBUTE, WebRequest.SCOPE_SESSION); } }
From source file:org.easit.core.controllers.facebook.FacebookAfterConnectInterceptor.java
@Override public void postConnect(Connection<Facebook> connection, WebRequest request) { request.setAttribute("connectedToFacebook", connection.test(), WebRequest.SCOPE_SESSION); request.setAttribute("connectedToAny", connectionRepository.findAllConnections().size() > 0, WebRequest.SCOPE_SESSION);//w ww.j a v a2s . c o m if (request.getAttribute(POST_TO_WALL_ATTRIBUTE, WebRequest.SCOPE_SESSION) != null) { try { connection.updateStatus("Connected!"); } catch (ApiException e) { // Do nothing: No need to break down if the post-connect post // can't be made. } request.removeAttribute(POST_TO_WALL_ATTRIBUTE, WebRequest.SCOPE_SESSION); } }
From source file:org.jasig.schedassist.portlet.web.VisitorConflictsController.java
/** * // w ww . j a va 2 s . co m * @param request * @param response * @throws IOException */ @RequestMapping("/ajax/visitor-conflicts.json") public String getVisitorConflicts(@RequestParam("ownerId") long ownerId, @RequestParam("weekStart") int weekStart, final ModelMap model, final WebRequest request) { if (LOG.isDebugEnabled()) { LOG.debug("enter getVisitorConflicts, ownerId: " + ownerId + ", weekStart: " + weekStart); } final String visitorUsername = (String) request.getAttribute(FlowHelper.CURRENT_USER_ATTR, PortletSession.APPLICATION_SCOPE); if (LOG.isDebugEnabled()) { LOG.debug("visitorUsername: " + visitorUsername); } if (StringUtils.isBlank(visitorUsername)) { model.addAttribute("soup for you", "none"); // short-circuit for unauthenticated return "jsonView"; } List<AvailableBlock> conflicts = this.schedulingAssistantService.calculateVisitorConflicts(visitorUsername, ownerId, weekStart); Collections.sort(conflicts); List<String> conflictBlocks = new ArrayList<String>(); SimpleDateFormat df = CommonDateOperations.getDateTimeFormat(); for (AvailableBlock b : conflicts) { conflictBlocks.add(df.format(b.getStartTime())); } model.addAttribute("conflicts", conflictBlocks); if (LOG.isDebugEnabled()) { LOG.debug("exit getVisitorConflicts"); } return "jsonView"; }
From source file:org.openmrs.web.controller.patient.ShortPatientFormControllerTest.java
/** * @see ShortPatientFormController#saveShortPatient(WebRequest,PersonName,PersonAddress,Map,ShortPatientModel, BindingResult) *///ww w . j av a 2 s. c o m @Test @Verifies(value = "should not add a new person attribute with an empty value", method = "saveShortPatient(WebRequest,PersonName,PersonAddress,ShortPatientModel,BindingResult)") public void saveShortPatient_shouldNotAddANewPersonAttributeWithAnEmptyValue() throws Exception { Patient p = Context.getPatientService().getPatient(2); int originalAttributeCount = p.getAttributes().size(); ShortPatientModel patientModel = new ShortPatientModel(p); //add a new person Attribute with no value patientModel.getPersonAttributes() .add(new PersonAttribute(Context.getPersonService().getPersonAttributeType(2), null)); WebRequest mockWebRequest = new ServletWebRequest(new MockHttpServletRequest()); BindException errors = new BindException(patientModel, "patientModel"); mockWebRequest.setAttribute("personNameCache", p.getPersonName(), WebRequest.SCOPE_SESSION); mockWebRequest.setAttribute("personAddressCache", p.getPersonAddress(), WebRequest.SCOPE_SESSION); mockWebRequest.setAttribute("patientModel", patientModel, WebRequest.SCOPE_SESSION); ShortPatientFormController controller = (ShortPatientFormController) applicationContext .getBean("shortPatientFormController"); String redirectUrl = controller.saveShortPatient(mockWebRequest, (PersonName) mockWebRequest.getAttribute("personNameCache", WebRequest.SCOPE_SESSION), (PersonAddress) mockWebRequest.getAttribute("personAddressCache", WebRequest.SCOPE_SESSION), null, (ShortPatientModel) mockWebRequest.getAttribute("patientModel", WebRequest.SCOPE_SESSION), errors); Assert.assertTrue("Should pass with no validation errors", !errors.hasErrors()); Assert.assertEquals("Patient.saved", mockWebRequest.getAttribute(WebConstants.OPENMRS_MSG_ATTR, WebRequest.SCOPE_SESSION)); Assert.assertEquals("redirect:/patientDashboard.form?patientId=" + p.getPatientId(), redirectUrl); //The new blank person attribute should have been ignored Assert.assertEquals(originalAttributeCount, p.getAttributes().size()); }