Posts

Showing posts from August, 2015

Content disposition duplicate headers solution for google chrome

Recently I had a problem while serving dynamic content in a Spring MVC application; (more details here) when attempting to open some of the dynamic content with Chrome I was having a weird error message : Duplicate headers received from server The response from the server contained duplicate headers. This problem is generally the result of a misconfigured website or proxy. Only the website or proxy administrator can fix this issue. Error 349 (net::ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION): Multiple distinct Content-Disposition headers received. This is disallowed to protect against HTTP response splitting attacks. I wasn't sure why I was having this problem, since some dynamic content was working properly and I was setting only once the Content-Disposition header on my codeSo after searching around a bit I stumbled upon the HTTP specs it turns out the Content-Disposition header should not contain a coma since it will be treated as a header separator Multiple message-…

Spring mvc send binary content from controller

Sometimes binary files such as images, documents are stored in the database; these binary files need then to be served dynamically Below I'll show a code snippet showing how to handle this easily with Spring MVCBefore we begin just in case this is the list of libraries I used when coding this example : Spring 3+Spring Data JPA Eclipselink 2.4+Apache TikaSlugify @Entity public class Resouce{ @Id @Column(name = "ID") @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @Column(name = "FILE_NAME", length = 200) private String fileName; @Column(name = "FILE") @Lob private byte[] file; //SETTERS - GETTERS OMMITED } @ResponseStatus(value = HttpStatus.NOT_FOUND) public class ResourceNotFoundException extends RuntimeException { } /** * @author ulf */ @Controller @RequestMapping("/resource") public class ResourceController{ // a basic Spring data repository @Autowired pri…