List of usage examples for org.springframework.http MediaType TEXT_HTML_VALUE
String TEXT_HTML_VALUE
To view the source code for org.springframework.http MediaType TEXT_HTML_VALUE.
Click Source Link
From source file:org.cloudfoundry.identity.uaa.mock.audit.AuditCheckMvcMockTests.java
@Test public void invalidPasswordLoginFailedTest() throws Exception { MockHttpServletRequestBuilder loginPost = post("/login.do").accept(MediaType.TEXT_HTML_VALUE) .param("username", testAccounts.getUserName()).param("password", ""); //success means a 302 to / (failure is 302 to /login?error...) mockMvc.perform(loginPost).andExpect(status().is3xxRedirection()) .andExpect(header().string("Location", "/login?error=login_failure")); ArgumentCaptor<AbstractUaaEvent> captor = ArgumentCaptor.forClass(AbstractUaaEvent.class); verify(listener, atLeast(2)).onApplicationEvent(captor.capture()); UserAuthenticationFailureEvent event1 = (UserAuthenticationFailureEvent) captor.getAllValues().get(0); PrincipalAuthenticationFailureEvent event2 = (PrincipalAuthenticationFailureEvent) captor.getAllValues() .get(1);//from w w w . j a v a2 s. com assertEquals(testAccounts.getUserName(), event1.getUser().getUsername()); assertEquals(testAccounts.getUserName(), event2.getName()); }
From source file:org.cloudfoundry.identity.uaa.mock.audit.AuditCheckMvcMockTests.java
@Test public void userNotFoundLoginFailedTest() throws Exception { String username = "test1234"; MockHttpServletRequestBuilder loginPost = post("/login.do").accept(MediaType.TEXT_HTML_VALUE) .param("username", username).param("password", testAccounts.getPassword()); //success means a 302 to / (failure is 302 to /login?error...) mockMvc.perform(loginPost).andExpect(status().is3xxRedirection()) .andExpect(header().string("Location", "/login?error=login_failure")); ArgumentCaptor<AbstractUaaEvent> captor = ArgumentCaptor.forClass(AbstractUaaEvent.class); verify(listener, atLeast(2)).onApplicationEvent(captor.capture()); UserNotFoundEvent event1 = (UserNotFoundEvent) captor.getAllValues().get(0); PrincipalAuthenticationFailureEvent event2 = (PrincipalAuthenticationFailureEvent) captor.getAllValues() .get(1);//from w ww . j a v a 2s. co m assertEquals(username, ((Authentication) event1.getSource()).getName()); assertEquals(username, event2.getName()); }
From source file:org.fao.geonet.api.records.formatters.FormatterApi.java
@RequestMapping(value = { "/api/records/{metadataUuid}/formatters/{formatterId}", "/api/" + API.VERSION_0_1 + "/records/{metadataUuid}/formatters/{formatterId}" }, method = RequestMethod.GET, produces = { MediaType.TEXT_HTML_VALUE, MediaType.APPLICATION_XHTML_XML_VALUE, "application/pdf", MediaType.ALL_VALUE // TODO: PDF }) @ApiOperation(value = "Get a formatted metadata record", nickname = "getRecordFormattedBy") @ResponseBody// ww w .ja va2s .co m public void getRecordFormattedBy( @ApiParam(value = "Formatter type to use.") @RequestHeader(value = HttpHeaders.ACCEPT, defaultValue = MediaType.TEXT_HTML_VALUE) String acceptHeader, @PathVariable(value = "formatterId") final String formatterId, @ApiParam(value = API_PARAM_RECORD_UUID, required = true) @PathVariable String metadataUuid, @RequestParam(value = "width", defaultValue = "_100") final FormatterWidth width, @RequestParam(value = "mdpath", required = false) final String mdPath, @RequestParam(value = "output", required = false) FormatType formatType, @ApiIgnore final NativeWebRequest request, final HttpServletRequest servletRequest) throws Exception { ApplicationContext applicationContext = ApplicationContextHolder.get(); Locale locale = languageUtils.parseAcceptLanguage(servletRequest.getLocales()); // TODO : // if text/html > xsl_view // if application/pdf > xsl_view and PDF output // if application/x-gn-<formatterId>+(xml|html|pdf|text) // Force PDF ouutput when URL parameter is set. // This is useful when making GET link to PDF which // can not use headers. if (MediaType.ALL_VALUE.equals(acceptHeader)) { acceptHeader = MediaType.TEXT_HTML_VALUE; } if (formatType == null) { formatType = FormatType.find(acceptHeader); } if (formatType == null) { formatType = FormatType.xml; } final String language = LanguageUtils.locale2gnCode(locale.getISO3Language()); final ServiceContext context = createServiceContext(language, formatType, request.getNativeRequest(HttpServletRequest.class)); AbstractMetadata metadata = ApiUtils.canViewRecord(metadataUuid, servletRequest); Boolean hideWithheld = true; // final boolean hideWithheld = Boolean.TRUE.equals(hide_withheld) || // !context.getBean(AccessManager.class).canEdit(context, resolvedId); Key key = new Key(metadata.getId(), language, formatType, formatterId, hideWithheld, width); final boolean skipPopularityBool = false; ISODate changeDate = metadata.getDataInfo().getChangeDate(); Validator validator; if (changeDate != null) { final long changeDateAsTime = changeDate.toDate().getTime(); long roundedChangeDate = changeDateAsTime / 1000 * 1000; if (request.checkNotModified(language, roundedChangeDate) && context.getBean(CacheConfig.class).allowCaching(key)) { if (!skipPopularityBool) { context.getBean(DataManager.class).increasePopularity(context, String.valueOf(metadata.getId())); } return; } validator = new ChangeDateValidator(changeDateAsTime); } else { validator = new NoCacheValidator(); } final FormatMetadata formatMetadata = new FormatMetadata(context, key, request); byte[] bytes; if (hasNonStandardParameters(request)) { // the http headers can cause a formatter to output custom output due to the parameters. // because it is not known how the parameters may affect the output then we have two choices // 1. make a unique cache for each configuration of parameters // 2. don't cache anything that has extra parameters beyond the standard parameters used to // create the key // #1 has a major flaw because an attacker could simply make new requests always changing the parameters // and completely swamp the cache. So we go with #2. The formatters are pretty fast so it is a fine solution bytes = formatMetadata.call().data; } else { bytes = context.getBean(FormatterCache.class).get(key, validator, formatMetadata, false); } if (bytes != null) { if (!skipPopularityBool) { context.getBean(DataManager.class).increasePopularity(context, String.valueOf(metadata.getId())); } writeOutResponse(context, metadataUuid, locale.getISO3Language(), request.getNativeResponse(HttpServletResponse.class), formatType, bytes); } }
From source file:org.fao.geonet.api.records.MetadataApi.java
@ApiOperation(value = "Get a metadata record", notes = "Depending on the accept header the appropriate formatter is used. " + "When requesting a ZIP, a MEF version 2 file is returned. " + "When requesting HTML, the default formatter is used.", nickname = "getRecord") @RequestMapping(value = "/{metadataUuid:.+}", method = RequestMethod.GET, consumes = { MediaType.ALL_VALUE }, produces = { MediaType.TEXT_HTML_VALUE, MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_XHTML_XML_VALUE, MediaType.APPLICATION_JSON_VALUE, "application/pdf", "application/zip", MEF_V1_ACCEPT_TYPE, MEF_V2_ACCEPT_TYPE, MediaType.ALL_VALUE }) @ApiResponses(value = { @ApiResponse(code = 200, message = "Return the record."), @ApiResponse(code = 403, message = ApiParams.API_RESPONSE_NOT_ALLOWED_CAN_VIEW), @ApiResponse(code = 404, message = ApiParams.API_RESPONSE_RESOURCE_NOT_FOUND) }) public String getRecord( @ApiParam(value = API_PARAM_RECORD_UUID, required = true) @PathVariable String metadataUuid, @ApiParam(value = "Accept header should indicate which is the appropriate format " + "to return. It could be text/html, application/xml, application/zip, ..." + "If no appropriate Accept header found, the XML format is returned.", required = true) @RequestHeader(value = HttpHeaders.ACCEPT, defaultValue = MediaType.APPLICATION_XML_VALUE, required = false) String acceptHeader, HttpServletResponse response, HttpServletRequest request) throws Exception { try {//from w ww.ja va2 s.co m ApiUtils.canViewRecord(metadataUuid, request); } catch (SecurityException e) { Log.debug(API.LOG_MODULE_NAME, e.getMessage(), e); throw new NotAllowedException(ApiParams.API_RESPONSE_NOT_ALLOWED_CAN_VIEW); } List<String> accept = Arrays.asList(acceptHeader.split(",")); String defaultFormatter = "xsl-view"; if (accept.contains(MediaType.TEXT_HTML_VALUE) || accept.contains(MediaType.APPLICATION_XHTML_XML_VALUE) || accept.contains("application/pdf")) { return "forward:" + (metadataUuid + "/formatters/" + defaultFormatter); } else if (accept.contains(MediaType.APPLICATION_XML_VALUE) || accept.contains(MediaType.APPLICATION_JSON_VALUE)) { return "forward:" + (metadataUuid + "/formatters/xml"); } else if (accept.contains("application/zip") || accept.contains(MEF_V1_ACCEPT_TYPE) || accept.contains(MEF_V2_ACCEPT_TYPE)) { return "forward:" + (metadataUuid + "/formatters/zip"); } else { // FIXME this else is never reached because any of the accepted medias match one of the previous if conditions. response.setHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_XHTML_XML_VALUE); //response.sendRedirect(metadataUuid + "/formatters/" + defaultFormatter); return "forward:" + (metadataUuid + "/formatters/" + defaultFormatter); } }
From source file:org.geoserver.opensearch.rest.CollectionsController.java
@GetMapping(path = "{collection}/description", produces = { MediaType.TEXT_HTML_VALUE }) public void getCollectionDescription(@PathVariable(name = "collection", required = true) String collection, HttpServletResponse response) throws IOException { // query one collection and grab its OGC links Feature feature = queryCollection(collection, q -> { q.setPropertyNames(new String[] { OpenSearchAccess.DESCRIPTION }); });// w w w . ja v a 2s . co m // grab the description Property descriptionProperty = feature.getProperty(OpenSearchAccess.DESCRIPTION); if (descriptionProperty != null && descriptionProperty.getValue() instanceof String) { String value = (String) descriptionProperty.getValue(); response.setContentType("text/html"); StreamUtils.copy(value, Charset.forName("UTF-8"), response.getOutputStream()); } else { throw new ResourceNotFoundException( "Description for collection '" + collection + "' could not be found"); } }
From source file:org.geoserver.opensearch.rest.CollectionsController.java
@PutMapping(path = "{collection}/description", consumes = MediaType.TEXT_HTML_VALUE) public void putCollectionDescription(@PathVariable(name = "collection", required = true) String collection, HttpServletRequest request) throws IOException { // check the collection is there queryCollection(collection, q -> { });/*from w ww . j av a2 s .co m*/ String description = IOUtils.toString(request.getReader()); updateDescription(collection, description); }
From source file:org.geoserver.opensearch.rest.CollectionsControllerTest.java
@Test public void testPutCollectionDescription() throws Exception { MockHttpServletResponse response;//from w ww .j a va2 s . co m createTest123Collection(); // create the description response = putAsServletResponse("rest/oseo/collections/TEST123/description", getTestData("/test123-description.html"), MediaType.TEXT_HTML_VALUE); assertEquals(200, response.getStatus()); // grab and check assertTest123Description(); }
From source file:org.geoserver.opensearch.rest.ProductsController.java
@GetMapping(path = "{product:.+}/description", produces = { MediaType.TEXT_HTML_VALUE }) public void getProductDescription(@PathVariable(name = "collection", required = true) String collection, @PathVariable(name = "product", required = true) String product, HttpServletResponse response) throws IOException { // query one collection and grab its OGC links Feature feature = queryProduct(collection, product, q -> { q.setPropertyNames(new String[] { "htmlDescription" }); });/* w w w . j a va 2 s .c o m*/ // grab the description Property descriptionProperty = feature.getProperty("htmlDescription"); if (descriptionProperty != null && descriptionProperty.getValue() instanceof String) { String value = (String) descriptionProperty.getValue(); response.setContentType("text/html"); StreamUtils.copy(value, Charset.forName("UTF-8"), response.getOutputStream()); } else { throwProductNotFound(collection, product, "Product"); } }
From source file:org.geoserver.opensearch.rest.ProductsController.java
@PutMapping(path = "{product:.+}/description", consumes = MediaType.TEXT_HTML_VALUE) public void putProductDescription(@PathVariable(name = "collection", required = true) String collection, @PathVariable(name = "product", required = true) String product, HttpServletRequest request) throws IOException { // check the product exists queryProduct(collection, product, q -> { });//from www .j av a2 s . c o m String description = IOUtils.toString(request.getReader()); updateDescription(collection, product, description); }
From source file:org.geoserver.opensearch.rest.ProductsControllerTest.java
@Test public void testPutProductDescription() throws Exception { testCreateProduct();//from w w w. j a va 2 s.c o m // create the description MockHttpServletResponse response = putAsServletResponse( "rest/oseo/collections/SENTINEL2/products/S2A_OPER_MSI_L1C_TL_SGS__20180101T000000_A006640_T32TPP_N02.04/description", getTestData("/product-description.html"), MediaType.TEXT_HTML_VALUE); assertEquals(200, response.getStatus()); // grab and check assertProductDescription(); }