List of usage examples for org.springframework.mock.web MockHttpServletResponse getContentAsString
public String getContentAsString() throws UnsupportedEncodingException
From source file:springfox.documentation.staticdocs.Swagger2MarkupResultHandler.java
/** * Apply the action on the given result. * * @param result the result of the executed request * @throws Exception if a failure occurs *//* ww w . j av a 2 s. c o m*/ @Override public void handle(MvcResult result) throws Exception { MockHttpServletResponse response = result.getResponse(); response.setCharacterEncoding(encoding); String swaggerJson = response.getContentAsString(); Swagger2MarkupConverter.fromString(swaggerJson).withMarkupLanguage(markupLanguage) .withPathsGroupedBy(this.pathsGroupedBy).withExamples(examplesFolderPath).build() .intoFolder(outputDir); }
From source file:uk.ac.abdn.fits.support.thymeleaf.springmail.web.MailController.java
@RequestMapping(value = "/sendMailSimple", method = RequestMethod.POST) public @ResponseBody RESTFulRequest sendSimpleMail(HttpSession session, HttpServletRequest request, // HttpServletResponse response, Model model, final Locale locale) throws MessagingException { String recipientName = "Cheng Zeng"; String recipientEmail = "c.zeng@abdn.ac.uk"; String fname = (String) session.getAttribute("fname"); String lname = (String) session.getAttribute("lname"); String email = (String) session.getAttribute("email"); if (fname != null && lname != null) { recipientName = fname + " " + lname; System.out.println("recipientName: " + recipientName); }/* ww w. j a v a 2 s .c o m*/ if (email != null && !email.equals("")) { recipientEmail = email; System.out.println("recipientEmail: " + recipientEmail); } List<TOption> not_relaxed = (List<TOption>) session.getAttribute("options"); List<TOption> relaxed_options = (List<TOption>) session.getAttribute("relaxed_options"); String date_of_travel = (String) session.getAttribute("date_of_travel"); String origin_postcode = (String) session.getAttribute("origin_postcode"); List<TOption> not_relaxed_rtn = (List<TOption>) session.getAttribute("options_rtn"); List<TOption> relaxed_options_rtn = (List<TOption>) session.getAttribute("relaxed_options_rtn"); String origin_postcode_rtn = (String) session.getAttribute("origin_postcode_rtn"); String url = null; View resolvedView; try { model.addAttribute("date_of_travel", date_of_travel); model.addAttribute("origin_postcode", origin_postcode); model.addAttribute("options", not_relaxed); model.addAttribute("relaxed_options", relaxed_options); model.addAttribute("caption", "Transport options ranked using preferences"); model.addAttribute("origin_postcode_rtn", origin_postcode_rtn); model.addAttribute("options_rtn", not_relaxed_rtn); model.addAttribute("relaxed_options_rtn", relaxed_options_rtn); model.addAttribute("email_view", "email_view"); resolvedView = this.viewResolver.resolveViewName("matching", Locale.UK); MockHttpServletResponse mockResp = new MockHttpServletResponse(); resolvedView.render(model.asMap(), request, mockResp); // System.out.println("rendered html : " + mockResp.getContentAsString()); url = saveAsHtml(request, mockResp.getContentAsString()); emailService.sendRichMail(recipientName, recipientEmail, locale, url); } catch (Exception e) { e.printStackTrace(); } return new RESTFulRequest(1, "mail sent to " + recipientEmail); }
From source file:uk.ac.cam.caret.sakai.rwiki.component.service.impl.test.XSLTEntityHandlerTest.java
public void xtestXSLT() throws Exception { String[] test = { "/uk/ac/cam/caret/sakai/rwiki/component/service/impl/null.xslt", "/uk/ac/cam/caret/sakai/rwiki/component/service/impl/toatom03.xslt", "/uk/ac/cam/caret/sakai/rwiki/component/service/impl/tohtml.xslt", "/uk/ac/cam/caret/sakai/rwiki/component/service/impl/torss091.xslt", "/uk/ac/cam/caret/sakai/rwiki/component/service/impl/torss10.xslt", "/uk/ac/cam/caret/sakai/rwiki/component/service/impl/torss20.xslt", "/uk/ac/cam/caret/sakai/rwiki/component/service/impl/xhtml2fo.xslt" };/* w w w . j a va 2 s. c om*/ RWikiCurrentObjectImpl rwco = new RWikiCurrentObjectImpl(); RWikiEntity rwe = new RWikiEntityImpl(rwco); rwco.setContent("Some Content"); rwco.setGroupAdmin(false); rwco.setId("/site/sdf-sdf-sdf-sdf-sdf-sfd/SomePage/sdfgsfd/Home"); rwco.setId("/site/sdf-sdf-sdf-sdf-sdf-sfd/SomePage/sdfgsfd/Home"); rwco.setOwner("The Owner"); rwco.setUser("The User"); rwco.setVersion(new Date()); rwco.setRevision(Integer.valueOf(5)); MockHttpServletRequest request = new MockHttpServletRequest(); for (int i = 0; i < test.length; i++) { MockHttpServletResponse response = new MockHttpServletResponse(); eh.setXslt(test[i]); eh.init(); eh.outputContent(rwe, rwe, request, response); logger.info(response.getContentAsString()); } long start = System.currentTimeMillis(); int iters = 10; for (int j = 0; j < iters; j++) { for (int i = 0; i < test.length; i++) { MockHttpServletResponse response = new MockHttpServletResponse(); eh.outputContent(rwe, rwe, request, response); } } float timet = (float) 1.0 * (System.currentTimeMillis() - start); float tper = (float) (timet / (1.0 * iters)); logger.info("Transform and Serialize Call Cost = " + tper + " ms"); }
From source file:uk.ac.cam.caret.sakai.rwiki.component.test.ComponentIntegrationTest.java
/** * Load a set of pages, and process a set of URLS * //from w w w .ja v a 2 s.c om * @throws Exception */ public void xtestURLAccess() throws Exception { assertEquals("pageNames and pageContent must be the same length ", pageNames.length, pageContent.length); for (int i = 0; i < pageNames.length; i++) { rwikiObjectservice.update(pageNames[i], site.getReference(), new Date(), pageContent[i]); } Collection copy = new ArrayList(); String siteID = site.getId(); for (int i = 0; i < accessPaths.length; i++) { String testURL = accessPaths[i]; int ix = testURL.indexOf("SITEID"); if (ix != -1) { testURL = testURL.substring(0, ix) + siteID + testURL.substring(ix + "SITEID".length()); } logger.info("Testing " + testURL); Reference ref = EntityManager.newReference(testURL); logger.info("Got " + ref); EntityProducer service = ref.getEntityProducer(); if (service != null) { MockHttpServletRequest req = new MockHttpServletRequest(); MockHttpServletResponse res = new MockHttpServletResponse(); HttpAccess ha = service.getHttpAccess(); ha.handleAccess(req, res, ref, copy); logger.info("URL " + testURL + "Got response of " + res.getContentAsString()); Collection authZGroups = service.getEntityAuthzGroups(ref, null); logger.info("Reference " + ref.getReference()); for (Iterator ic = authZGroups.iterator(); ic.hasNext();) { String authZGroupID = (String) ic.next(); logger.info(" AuthZGroup " + authZGroupID); try { AuthzGroup azg = authzGroupService.getAuthzGroup(authZGroupID); printFunction(azg, RWikiSecurityService.SECURE_ADMIN); printFunction(azg, RWikiSecurityService.SECURE_CREATE); printFunction(azg, RWikiSecurityService.SECURE_DELETE); printFunction(azg, RWikiSecurityService.SECURE_READ); printFunction(azg, RWikiSecurityService.SECURE_SUPER_ADMIN); printFunction(azg, RWikiSecurityService.SECURE_UPDATE); } catch (GroupNotDefinedException iduex) { logger.info(" Does not exist " + iduex.getMessage()); } } } else { logger.info("Rejected URL " + testURL + ""); } } }
From source file:uk.ac.cam.caret.sakai.rwiki.component.test.ComponentIntegrationTest.java
/** * Test the entity access based on a URL, also fully tests the functions * associated with the URL, need inspection to verify 100% * /*w w w .j a v a 2 s . co m*/ * @throws Exception */ public void xtestEntityAccess() throws Exception { rwikiObjectservice.update("HomeTestPageENTITY", site.getReference(), new Date(), content[0]); RWikiObject rwo = rwikiObjectservice.getRWikiObject("HomeTestPageENTITY", site.getReference()); RWikiEntity rwe = (RWikiEntity) rwikiObjectservice.getEntity(rwo); logger.info("Reference is " + rwe.getReference()); Reference r = EntityManager.newReference(rwe.getReference() + "html"); logger.info("Reference found as " + r); logger.info("Reference Container " + r.getContainer()); logger.info("Reference Contex " + r.getContext()); logger.info("Reference Description " + r.getDescription()); logger.info("Reference Type " + r.getType()); Entity e = rwikiObjectservice.getEntity(r); assertNotNull("Entity is Null should not be", e); logger.info(" Got Entity from getEntity " + e); Collection c = rwikiObjectservice.getEntityAuthzGroups(r, null); assertNotNull("AuthZGroups should not be null ", c); logger.info("getAuthZGroups gave " + c); String description = rwikiObjectservice.getEntityDescription(r); assertNotNull("description should not be null ", description); logger.info("description gave " + description); ResourceProperties rp = rwikiObjectservice.getEntityResourceProperties(r); assertNotNull("ResourceProperties should not be null ", rp); logger.info("ResourceProperties gave " + rp); String url = rwikiObjectservice.getEntityUrl(r); assertNotNull("URL should not be null ", url); logger.info("URL gave " + url); // try and get the content Entity entity = rwikiObjectservice.getEntity(r); RWikiEntity rwentity = (RWikiEntity) entity; RWikiObject rwo2 = rwentity.getRWikiObject(); logger.info("Got Object " + rwo2.getName()); // try and get the access content HttpAccess ha = rwikiObjectservice.getHttpAccess(); Collection copy = new ArrayList(); MockHttpServletRequest req = new MockHttpServletRequest(); MockHttpServletResponse res = new MockHttpServletResponse(); ha.handleAccess(req, res, r, copy); logger.info("Got response of " + res.getContentAsString()); }