List of usage examples for org.springframework.http MediaType APPLICATION_XHTML_XML
MediaType APPLICATION_XHTML_XML
To view the source code for org.springframework.http MediaType APPLICATION_XHTML_XML.
Click Source Link
From source file:edu.mayo.trilliumbridge.webapp.TransformerController.java
protected void doTransform(HttpServletRequest request, HttpServletResponse response, String acceptHeader, String formatOverride, Transformer transformer) throws IOException { // default to XML if no Accept Header (it should at least be */*, but just in case). if (StringUtils.isBlank(acceptHeader)) { acceptHeader = MediaType.APPLICATION_ATOM_XML_VALUE; }/* w w w. j a v a2 s .c o m*/ TrilliumBridgeTransformer.Format responseFormat = null; if (StringUtils.isNotBlank(formatOverride)) { responseFormat = TrilliumBridgeTransformer.Format.valueOf(formatOverride); } else { String[] accepts = StringUtils.split(acceptHeader, ','); for (String accept : accepts) { MediaType askedForType = MediaType.parseMediaType(accept); if (askedForType.isCompatibleWith(MediaType.TEXT_XML) || askedForType.isCompatibleWith(MediaType.APPLICATION_XML)) { responseFormat = TrilliumBridgeTransformer.Format.XML; } else if (askedForType.isCompatibleWith(MediaType.TEXT_HTML) || askedForType.isCompatibleWith(MediaType.APPLICATION_XHTML_XML)) { responseFormat = TrilliumBridgeTransformer.Format.HTML; } else if (askedForType.getType().equals("application") && askedForType.getSubtype().equals("pdf")) { responseFormat = TrilliumBridgeTransformer.Format.PDF; } if (responseFormat != null) { break; } } } if (responseFormat == null) { throw new UserInputException("Cannot return type: " + acceptHeader, HttpStatus.NOT_ACCEPTABLE); } String contentType; switch (responseFormat) { case XML: contentType = MediaType.APPLICATION_XML_VALUE; break; case HTML: contentType = MediaType.TEXT_HTML_VALUE.toString(); break; case PDF: contentType = "application/pdf"; break; default: throw new IllegalStateException("Illegal Response Format"); } InputStream inputStream; if (request instanceof MultipartHttpServletRequest) { MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; MultipartFile multipartFile = multipartRequest.getFile(INPUT_FILE_NAME); inputStream = multipartFile.getInputStream(); } else { inputStream = request.getInputStream(); } inputStream = this.checkForUtf8BOMAndDiscardIfAny(this.checkStreamIsNotEmpty(inputStream)); // create a buffer so we don't use the servlet's output stream unless // we get a successful transform, because if we do use it, // we can't use the error view anymore. ByteArrayOutputStream baos = new ByteArrayOutputStream(); transformer.transform(inputStream, baos, responseFormat); try { response.setContentType(contentType); response.getOutputStream().write(baos.toByteArray()); } finally { IOUtils.closeQuietly(baos); } }
From source file:org.dawnsci.marketplace.server.MarketplaceServerTest.java
@Test public void testMvcGetRoot() throws Exception { this.mocMvc.perform(get("/").accept(MediaType.APPLICATION_XHTML_XML)).andExpect(status().isOk()) .andExpect(xpath("//div[@id='solution-1']").exists()) .andExpect(xpath("//div[@id='solution-2']").exists()); }
From source file:org.dawnsci.marketplace.server.MarketplaceServerTest.java
@Test public void testMvcSearchForTerm() throws Exception { this.mocMvc.perform(get("/search?term=sample").accept(MediaType.APPLICATION_XHTML_XML)) .andExpect(status().isOk()).andExpect(xpath("//div[@id='solution-1']").exists()); this.mocMvc.perform(get("/search?term=does_not_exist").accept(MediaType.APPLICATION_XHTML_XML)) .andExpect(status().isOk()).andExpect(xpath("//div[@id='solution-1']").doesNotExist()); }
From source file:org.dawnsci.marketplace.server.MarketplaceServerTest.java
@Test public void testMvcSearchForTag() throws Exception { this.mocMvc.perform(get("/search?tag=Common").accept(MediaType.APPLICATION_XHTML_XML)) .andExpect(status().isOk()).andExpect(xpath("//div[@id='solution-1']").exists()) .andExpect(xpath("//div[@id='solution-2']").exists()); this.mocMvc.perform(get("/search?tag=Tag for Solution 1").accept(MediaType.APPLICATION_XHTML_XML)) .andExpect(status().isOk()).andExpect(xpath("//div[@id='solution-1']").exists()) .andExpect(xpath("//div[@id='solution-2']").doesNotExist()); }
From source file:org.dawnsci.marketplace.server.MarketplaceServerTest.java
@Test @Sql("/system-test-data.sql") public void testMvcCreateSolution() throws Exception { // log in as administrator user HttpSession session = this.mocMvc .perform(formLogin("/signin/authenticate").user("admin").password("s3cret!")) .andExpect(status().is(302)).andExpect(redirectedUrl("/")).andReturn().getRequest().getSession(); // bring up the new solution form session = this.mocMvc .perform(get("/edit-solution").session((MockHttpSession) session) .accept(MediaType.APPLICATION_XHTML_XML)) .andExpect(status().is(200)).andReturn().getRequest().getSession(); // and post it, being redirected to show the details, most values will // be null.//from www . ja v a 2s . co m String url = this.mocMvc .perform(post("/edit-solution").with(csrf()).session((MockHttpSession) session) .param("name", "test name").param("supporturl", "http://dawnsci.org") .param("updateurl", "http://dawnsci.org").accept(MediaType.APPLICATION_XHTML_XML)) .andExpect(status().is3xxRedirection()).andReturn().getResponse().getRedirectedUrl(); // test some key values in the new product Integer id = Integer.decode(url.substring(url.lastIndexOf("/") + 1)); ResponseEntity<String> entity = this.restTemplate .getForEntity("http://localhost:" + this.port + "/mpc/content/" + id + "/api/p", String.class); Marketplace m = loadSerializedMarketplace(entity.getBody()); // make sure the update site URL has not changed assertEquals("http://dawnsci.org", m.getNode().getUpdateurl()); }
From source file:org.dawnsci.marketplace.server.MarketplaceServerTest.java
@Test public void testMvcReadSolution() throws Exception { this.mocMvc.perform(get("/content/1").accept(MediaType.APPLICATION_XHTML_XML)).andExpect(status().isOk()) .andExpect(xpath("//div[@id='solution-1']").exists()); this.mocMvc.perform(get("/content/2").accept(MediaType.APPLICATION_XHTML_XML)).andExpect(status().isOk()) .andExpect(xpath("//div[@id='solution-2']").exists()); }
From source file:org.dawnsci.marketplace.server.MarketplaceServerTest.java
/** * Verifies that we can open the user details form when logged in as the * administrator user and that no access is granted when logged in as a * regular user.//from w ww . j a va 2s . c o m */ @Test @Sql("/system-test-data.sql") public void testMvcReadUser() throws Exception { // administrator user HttpSession session = this.mocMvc .perform(formLogin("/signin/authenticate").user("admin").password("s3cret!")) .andExpect(status().is3xxRedirection()).andExpect(redirectedUrl("/")).andReturn().getRequest() .getSession(); this.mocMvc .perform(get("/account/user").session((MockHttpSession) session) .accept(MediaType.APPLICATION_XHTML_XML)) .andExpect(status().isOk()).andExpect(xpath("//form[@id='user']").exists()); // regular user HttpSession session2 = this.mocMvc .perform(post("/signin/authenticate").with(csrf()).param("username", "user").param("password", "password")) .andExpect(authenticated().withRoles("USER")).andExpect(status().is3xxRedirection()) .andExpect(redirectedUrl("/")).andReturn().getRequest().getSession(); this.mocMvc.perform(get("/account/user").session((MockHttpSession) session2).with(csrf()) .accept(MediaType.APPLICATION_XHTML_XML)).andExpect(status().isForbidden()); }
From source file:org.dawnsci.marketplace.server.MarketplaceServerTest.java
@Test @Sql("/system-test-data.sql") public void testMvcDeleteUser() throws Exception { // administrator user HttpSession session = this.mocMvc .perform(post("/signin/authenticate").with(csrf()).param("username", "admin").param("password", "s3cret!")) .andExpect(status().is3xxRedirection()).andExpect(redirectedUrl("/")).andReturn().getRequest() .getSession();//from w ww . j av a 2 s . c om this.mocMvc .perform(get("/delete-account/user").session((MockHttpSession) session).with(csrf()) .accept(MediaType.APPLICATION_XHTML_XML)) .andExpect(status().is3xxRedirection()).andExpect(redirectedUrl("/accounts")); // this user should no longer be able to log in this.mocMvc.perform( post("/signin/authenticate").with(csrf()).param("username", "user").param("password", "password")) .andExpect(unauthenticated()); }
From source file:org.fao.geonet.api.GlobalExceptionController.java
/** * * @param request the HTTP request object. * @return true if the content type is allowed to have a body when returning an error to the client, false if the * response should contain an empty body. */// w ww .j a v a2 s .c o m private boolean contentTypeNeedsBody(HttpServletRequest request) { boolean needsBody; List<MediaType> requestMediaTypes = resolveMediaTypes(new ServletWebRequest(request)); Set<MediaType> allowedContentTypes = Sets.newHashSet(MediaType.APPLICATION_XML, MediaType.APPLICATION_XHTML_XML, MediaType.APPLICATION_JSON); needsBody = !Collections.disjoint(allowedContentTypes, requestMediaTypes); return needsBody; }