org.springframework.http.converter.ResourceRegionHttpMessageConverter Java Examples
The following examples show how to use
org.springframework.http.converter.ResourceRegionHttpMessageConverter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ResourceHttpRequestHandler.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public void afterPropertiesSet() throws Exception { if (logger.isWarnEnabled() && CollectionUtils.isEmpty(this.locations)) { logger.warn("Locations list is empty. No resources will be served unless a " + "custom ResourceResolver is configured as an alternative to PathResourceResolver."); } if (this.resourceResolvers.isEmpty()) { this.resourceResolvers.add(new PathResourceResolver()); } initAllowedLocations(); if (this.resourceHttpMessageConverter == null) { this.resourceHttpMessageConverter = new ResourceHttpMessageConverter(); } if (this.resourceRegionHttpMessageConverter == null) { this.resourceRegionHttpMessageConverter = new ResourceRegionHttpMessageConverter(); } this.contentNegotiationStrategy = initContentNegotiationStrategy(); }
Example #2
Source File: ResourceHttpRequestHandler.java From spring-analysis-note with MIT License | 5 votes |
@Override public void afterPropertiesSet() throws Exception { resolveResourceLocations(); if (logger.isWarnEnabled() && CollectionUtils.isEmpty(this.locations)) { logger.warn("Locations list is empty. No resources will be served unless a " + "custom ResourceResolver is configured as an alternative to PathResourceResolver."); } if (this.resourceResolvers.isEmpty()) { this.resourceResolvers.add(new PathResourceResolver()); } initAllowedLocations(); // Initialize immutable resolver and transformer chains this.resolverChain = new DefaultResourceResolverChain(this.resourceResolvers); this.transformerChain = new DefaultResourceTransformerChain(this.resolverChain, this.resourceTransformers); if (this.resourceHttpMessageConverter == null) { this.resourceHttpMessageConverter = new ResourceHttpMessageConverter(); } if (this.resourceRegionHttpMessageConverter == null) { this.resourceRegionHttpMessageConverter = new ResourceRegionHttpMessageConverter(); } this.contentNegotiationStrategy = initContentNegotiationStrategy(); }
Example #3
Source File: ResourceHttpRequestHandler.java From java-technology-stack with MIT License | 5 votes |
@Override public void afterPropertiesSet() throws Exception { resolveResourceLocations(); if (logger.isWarnEnabled() && CollectionUtils.isEmpty(this.locations)) { logger.warn("Locations list is empty. No resources will be served unless a " + "custom ResourceResolver is configured as an alternative to PathResourceResolver."); } if (this.resourceResolvers.isEmpty()) { this.resourceResolvers.add(new PathResourceResolver()); } initAllowedLocations(); // Initialize immutable resolver and transformer chains this.resolverChain = new DefaultResourceResolverChain(this.resourceResolvers); this.transformerChain = new DefaultResourceTransformerChain(this.resolverChain, this.resourceTransformers); if (this.resourceHttpMessageConverter == null) { this.resourceHttpMessageConverter = new ResourceHttpMessageConverter(); } if (this.resourceRegionHttpMessageConverter == null) { this.resourceRegionHttpMessageConverter = new ResourceRegionHttpMessageConverter(); } this.contentNegotiationStrategy = initContentNegotiationStrategy(); }
Example #4
Source File: ResourceHttpRequestHandler.java From spring-analysis-note with MIT License | 4 votes |
/** * Return the configured resource region converter. * @since 4.3 */ @Nullable public ResourceRegionHttpMessageConverter getResourceRegionHttpMessageConverter() { return this.resourceRegionHttpMessageConverter; }
Example #5
Source File: ResourceHttpRequestHandler.java From java-technology-stack with MIT License | 4 votes |
/** * Return the configured resource region converter. * @since 4.3 */ @Nullable public ResourceRegionHttpMessageConverter getResourceRegionHttpMessageConverter() { return this.resourceRegionHttpMessageConverter; }
Example #6
Source File: ResourceConverterInitializer.java From spring-fu with Apache License 2.0 | 4 votes |
@Override public void initialize(GenericApplicationContext context) { context.registerBean("resourceHttpMessageConverter", HttpMessageConverter.class, (Supplier<HttpMessageConverter>) ResourceHttpMessageConverter::new); context.registerBean("resourceRegionHttpMessageConverter", HttpMessageConverter.class, ResourceRegionHttpMessageConverter::new); }
Example #7
Source File: StoreByteRangeHttpRequestHandler.java From spring-content with Apache License 2.0 | 4 votes |
@Override public void afterPropertiesSet() throws Exception { this.setResourceHttpMessageConverter(new ResourceHttpMessageConverter()); this.setResourceRegionHttpMessageConverter(new ResourceRegionHttpMessageConverter()); }
Example #8
Source File: ProfileEntityProvider.java From sakai with Educational Community License v2.0 | 4 votes |
@EntityCustomAction(action="pronunciation",viewKey=EntityView.VIEW_SHOW) public Object getNamePronunciation(OutputStream out, EntityView view, Map<String,Object> params, EntityReference ref) { if (!sakaiProxy.isLoggedIn()) { throw new SecurityException("You must be logged in to get the name pronunciation of the student."); } String uuid = sakaiProxy.ensureUuid(ref.getId()); if(StringUtils.isBlank(uuid)) { throw new EntityNotFoundException("Invalid user.", ref.getId()); } MimeTypeByteArray mtba = profileLogic.getUserNamePronunciation(uuid); if(mtba != null && mtba.getBytes() != null) { try { HttpServletResponse response = requestGetter.getResponse(); HttpServletRequest request = requestGetter.getRequest(); response.setHeader("Expires", "0"); response.setHeader("Pragma", "no-cache"); response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); response.setContentType(mtba.getMimeType()); // Are we processing a Range request if (request.getHeader(HttpHeaders.RANGE) == null) { // Not a Range request byte[] bytes = mtba.getBytes(); response.setContentLengthLong(bytes.length); out.write(bytes); return new ActionReturn(Formats.UTF_8, mtba.getMimeType() , out); } else { // A Range request - we use springs HttpRange class Resource resource = new ByteArrayResource(mtba.getBytes()); response.setHeader(HttpHeaders.ACCEPT_RANGES, "bytes"); response.setContentLengthLong(resource.contentLength()); response.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT); try { ServletServerHttpRequest inputMessage = new ServletServerHttpRequest(request); ServletServerHttpResponse outputMessage = new ServletServerHttpResponse(response); List<HttpRange> httpRanges = inputMessage.getHeaders().getRange(); ResourceRegionHttpMessageConverter messageConverter = new ResourceRegionHttpMessageConverter(); if (httpRanges.size() == 1) { ResourceRegion resourceRegion = httpRanges.get(0).toResourceRegion(resource); messageConverter.write(resourceRegion, null, outputMessage); } else { messageConverter.write(HttpRange.toResourceRegions(httpRanges, resource), null, outputMessage); } } catch (IllegalArgumentException iae) { response.setHeader("Content-Range", "bytes */" + resource.contentLength()); response.sendError(HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE); log.warn("Name pronunciation request failed to send the requested range for {}, {}", ref.getReference(), iae.getMessage()); } } } catch (Exception e) { throw new EntityException("Name pronunciation request failed, " + e.getMessage(), ref.getReference()); } } return null; }
Example #9
Source File: ProfileEntityProvider.java From sakai with Educational Community License v2.0 | 4 votes |
@EntityCustomAction(action="pronunciation",viewKey=EntityView.VIEW_SHOW) public Object getNamePronunciation(OutputStream out, EntityView view, Map<String,Object> params, EntityReference ref) { if (!sakaiProxy.isLoggedIn()) { throw new SecurityException("You must be logged in to get the name pronunciation of the student."); } String uuid = sakaiProxy.ensureUuid(ref.getId()); if(StringUtils.isBlank(uuid)) { throw new EntityNotFoundException("Invalid user.", ref.getId()); } MimeTypeByteArray mtba = profileLogic.getUserNamePronunciation(uuid); if(mtba != null && mtba.getBytes() != null) { try { HttpServletResponse response = requestGetter.getResponse(); HttpServletRequest request = requestGetter.getRequest(); response.setHeader("Expires", "0"); response.setHeader("Pragma", "no-cache"); response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); response.setContentType(mtba.getMimeType()); // Are we processing a Range request if (request.getHeader(HttpHeaders.RANGE) == null) { // Not a Range request byte[] bytes = mtba.getBytes(); response.setContentLengthLong(bytes.length); out.write(bytes); return new ActionReturn(Formats.UTF_8, mtba.getMimeType() , out); } else { // A Range request - we use springs HttpRange class Resource resource = new ByteArrayResource(mtba.getBytes()); response.setHeader(HttpHeaders.ACCEPT_RANGES, "bytes"); response.setContentLengthLong(resource.contentLength()); response.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT); try { ServletServerHttpRequest inputMessage = new ServletServerHttpRequest(request); ServletServerHttpResponse outputMessage = new ServletServerHttpResponse(response); List<HttpRange> httpRanges = inputMessage.getHeaders().getRange(); ResourceRegionHttpMessageConverter messageConverter = new ResourceRegionHttpMessageConverter(); if (httpRanges.size() == 1) { ResourceRegion resourceRegion = httpRanges.get(0).toResourceRegion(resource); messageConverter.write(resourceRegion, null, outputMessage); } else { messageConverter.write(HttpRange.toResourceRegions(httpRanges, resource), null, outputMessage); } } catch (IllegalArgumentException iae) { response.setHeader("Content-Range", "bytes */" + resource.contentLength()); response.sendError(HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE); log.warn("Name pronunciation request failed to send the requested range for {}, {}", ref.getReference(), iae.getMessage()); } } } catch (Exception e) { throw new EntityException("Name pronunciation request failed, " + e.getMessage(), ref.getReference()); } } return null; }
Example #10
Source File: ResourceHttpRequestHandler.java From spring-analysis-note with MIT License | 2 votes |
/** * Configure the {@link ResourceRegionHttpMessageConverter} to use. * <p>By default a {@link ResourceRegionHttpMessageConverter} will be configured. * @since 4.3 */ public void setResourceRegionHttpMessageConverter(@Nullable ResourceRegionHttpMessageConverter messageConverter) { this.resourceRegionHttpMessageConverter = messageConverter; }
Example #11
Source File: ResourceHttpRequestHandler.java From java-technology-stack with MIT License | 2 votes |
/** * Configure the {@link ResourceRegionHttpMessageConverter} to use. * <p>By default a {@link ResourceRegionHttpMessageConverter} will be configured. * @since 4.3 */ public void setResourceRegionHttpMessageConverter(@Nullable ResourceRegionHttpMessageConverter messageConverter) { this.resourceRegionHttpMessageConverter = messageConverter; }
Example #12
Source File: ResourceHttpRequestHandler.java From lams with GNU General Public License v2.0 | 2 votes |
/** * Configure the {@link ResourceRegionHttpMessageConverter} to use. * <p>By default a {@link ResourceRegionHttpMessageConverter} will be configured. * @since 4.3 */ public void setResourceRegionHttpMessageConverter(ResourceRegionHttpMessageConverter resourceRegionHttpMessageConverter) { this.resourceRegionHttpMessageConverter = resourceRegionHttpMessageConverter; }
Example #13
Source File: ResourceHttpRequestHandler.java From lams with GNU General Public License v2.0 | 2 votes |
/** * Return the configured resource region converter. * @since 4.3 */ public ResourceRegionHttpMessageConverter getResourceRegionHttpMessageConverter() { return this.resourceRegionHttpMessageConverter; }