List of usage examples for org.springframework.http MediaType TEXT_HTML
MediaType TEXT_HTML
To view the source code for org.springframework.http MediaType TEXT_HTML.
Click Source Link
From source file:dk.nsi.haiba.minipasconverter.status.StatusReporter.java
@RequestMapping(value = "/status") public ResponseEntity<String> reportStatus() { String manual = request.getParameter("manual"); if (manual == null || manual.trim().length() == 0) { // no value set, use default set in the import executor manual = "" + minipasPreprocessor.isManualOverride(); } else {// w w w . j av a 2 s . c o m // manual flag is set on the request if (manual.equalsIgnoreCase("true")) { // flag is true, start the importer in a new thread minipasPreprocessor.setManualOverride(true); Runnable importer = new Runnable() { public void run() { minipasPreprocessor.doManualProcess(); } }; importer.run(); } else { minipasPreprocessor.setManualOverride(false); } } HttpHeaders headers = new HttpHeaders(); String body = "OK"; HttpStatus status = HttpStatus.INTERNAL_SERVER_ERROR; body = "OK"; try { if (!statusRepo.isHAIBADBAlive()) { body = "HAIBA Database is _NOT_ running correctly"; } else if (statusRepo.isOverdue()) { // last run information is applied to body later body = "Is overdue"; } else { status = HttpStatus.OK; } } catch (Exception e) { body = e.getMessage(); } body += "</br>"; body = addLastRunInformation(body); body += "</br>------------------</br>"; String importProgress = currentImportProgress.getStatus(); body += importProgress; body += "</br>------------------</br>"; String url = request.getRequestURL().toString(); body += "<a href=\"" + url + "?manual=true\">Manual start importer</a>"; body += "</br>"; body += "<a href=\"" + url + "?manual=false\">Scheduled start importer</a>"; body += "</br>"; if (manual.equalsIgnoreCase("true")) { body += "status: MANUAL"; } else { // default body += "status: SCHEDULED - " + cron; } headers.setContentType(MediaType.TEXT_HTML); return new ResponseEntity<String>(body, headers, status); }
From source file:org.apigw.util.OAuthTestHelper.java
public String loginAndGetConfirmationPage(String clientId, String redirectUri, String scope) { String cookie = loginAndGrabCookie(); HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); headers.set("Cookie", cookie); ServerRunning.UriBuilder uri = serverRunning.buildUri("/apigw-auth-server-web/oauth/authorize") .queryParam("response_type", "code").queryParam("state", "gzzFqB!!!").queryParam("scope", scope); if (clientId != null) { uri.queryParam("client_id", clientId); }//from ww w. j a v a 2 s .com if (redirectUri != null) { uri.queryParam("redirect_uri", redirectUri); } ResponseEntity<String> response = serverRunning.getForString(uri.pattern(), headers, uri.params()); // The confirm access page should be returned assertTrue(response.getBody().contains("API Test")); return cookie; }
From source file:org.makersoft.mvc.unit.RESTfulMappingHanderMappingTests.java
@Test public void testUpdate() throws Exception { HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setContentType(MediaType.TEXT_HTML); mockMvc.perform(put("/account/dept/1").accept(MediaType.TEXT_HTML).headers(httpHeaders)).andDo(print()) .andExpect(status().isMovedTemporarily()).andExpect(redirectedUrl("/account/dept")); }
From source file:edu.sjsu.cmpe275.lab2.service.ManageOrgController.java
/** (6) Get a organization<br> Path:org/{id}?format={json | xml | html} <br> Method: GET <br>//ww w.ja v a 2 s . c o m This returns a full organization object with the given ID in the given format. All existing fields, including the optional organization and list of friends should be returned. If the organization of the given user ID does not exist, the HTTP return code should be 404; otherwise, 200. The format parameter is optional, and the value is case insensitive. If missing, JSON is assumed. * @param id Description of a * @param format Description of b * @return Description of c */ @RequestMapping(value = "/{id}", method = RequestMethod.GET) public ResponseEntity getOrganization(@PathVariable("id") long id, @RequestParam(value = "format", required = true) String format) { Session session = null; Transaction transaction = null; Organization organization = null; HttpHeaders httpHeaders = new HttpHeaders(); if ("json".equals(format)) { httpHeaders.setContentType(MediaType.APPLICATION_JSON); } else if ("xml".equals(format)) { httpHeaders.setContentType(MediaType.APPLICATION_XML); } else if ("html".equals(format)) { httpHeaders.setContentType(MediaType.TEXT_HTML); } else { httpHeaders.setContentType(MediaType.APPLICATION_JSON); } try { session = sessionFactory.openSession(); transaction = session.beginTransaction(); organization = (Organization) session.get(Organization.class, id); if (organization == null) { throw new HibernateException("can't find record with id = " + id); } transaction.commit(); } catch (HibernateException e) { if (transaction != null) { transaction.rollback(); } return new ResponseEntity("can't find record with id = " + id, httpHeaders, HttpStatus.NOT_FOUND); } finally { if (session != null) { session.close(); } } return new ResponseEntity(organization, httpHeaders, HttpStatus.OK); }
From source file:com.init.MvcConfiguration.java
@Override public void configureContentNegotiation(ContentNegotiationConfigurer configurer) { configurer.defaultContentType(MediaType.TEXT_HTML).mediaType("json", MediaType.APPLICATION_JSON) .mediaType("xml", MediaType.APPLICATION_XML).favorPathExtension(true); // default is true. just for clarity }
From source file:org.makersoft.mvc.unit.RESTfulMappingHanderMappingTests.java
@Test public void testDestroy() throws Exception { HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setContentType(MediaType.TEXT_HTML); mockMvc.perform(delete("/account/dept/1").accept(MediaType.TEXT_HTML).headers(httpHeaders)).andDo(print()) .andExpect(status().isMovedTemporarily()).andExpect(redirectedUrl("/account/dept")); }
From source file:org.apigw.util.OAuthTestHelper.java
private String loginAndGrabCookie() { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); MultiValueMap<String, String> formData = new LinkedMultiValueMap<String, String>(); formData.add("j_username", username); formData.add("j_password", password); // Should be redirected to the original URL, but now authenticated ResponseEntity<Void> result = serverRunning.postForStatus("/apigw-auth-server-web/login.do", headers, formData);/*from w ww .j av a 2 s .c o m*/ assertEquals(HttpStatus.FOUND, result.getStatusCode()); assertTrue(result.getHeaders().containsKey("Set-Cookie")); return result.getHeaders().getFirst("Set-Cookie"); }
From source file:org.wcy123.ProtobufMessageConverter.java
/** * This method overrides the parent implementation, since this HttpMessageConverter can also * produce {@code MediaType.HTML "text/html"} ContentType. */// w w w. j ava2 s. c om @Override protected boolean canWrite(MediaType mediaType) { return super.canWrite(mediaType) || MediaType.TEXT_HTML.isCompatibleWith(mediaType); }
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 av a 2 s. co 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); } }