Skip to content

Commit

Permalink
Added content length to the image resources
Browse files Browse the repository at this point in the history
  • Loading branch information
Petr Dvorak committed Feb 24, 2013
1 parent ad9cf1d commit 3667a0e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
Expand Up @@ -206,11 +206,7 @@ public String paymentImageFromAccount(HttpServletRequest request, HttpServletRes
@RequestParam(value = "size", required = false) Integer size,
@RequestParam(value = "compress", required = false, defaultValue = "true") boolean transliterate,
@RequestParam(value = "branding", required = false, defaultValue = "true") boolean branding) throws IOException {
// flush the output
response.reset();
response.setContentType("image/png");
response.setHeader("Access-Control-Allow-Origin", "*");
String paymentString = this.paymentStringFromParameters(
String paymentString = this.paymentStringFromParameters(
iban,
bic,
amount,
Expand All @@ -222,8 +218,17 @@ public String paymentImageFromAccount(HttpServletRequest request, HttpServletRes
request.getParameterMap(),
transliterate);
BufferedImage qrCode = SpaydQRUtils.getQRCode(size, paymentString, branding);
ImageIO.write(qrCode, "PNG", response.getOutputStream());
response.setContentLength(response.getBufferSize());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(qrCode, "PNG", baos);
baos.flush();
byte[] imageInByte = baos.toByteArray();
baos.close();
// flush the output
response.reset();
response.setContentType("image/png");
response.setHeader("Access-Control-Allow-Origin", "*");
response.setContentLength(imageInByte.length);
response.getOutputStream().write(imageInByte, 0, imageInByte.length);
response.getOutputStream().flush();
return null;
}
Expand Down
Expand Up @@ -205,10 +205,6 @@ public String paymentImageFromAccountCzech(HttpServletRequest request, HttpServl
@RequestParam(value = "compress", required = false, defaultValue = "true") boolean transliterate,
@RequestParam(value = "branding", required = false, defaultValue = "true") boolean branding) throws IOException {

// flush the output
response.reset();
response.setContentType("image/png");
response.setHeader("Access-Control-Allow-Origin", "*");
String paymentString = this.paymentStringFromParameters(
accountNumber,
accountPrefix,
Expand All @@ -223,7 +219,17 @@ public String paymentImageFromAccountCzech(HttpServletRequest request, HttpServl
request.getParameterMap(),
transliterate);
BufferedImage qrCode = SpaydQRUtils.getQRCode(size, paymentString, branding);
ImageIO.write(qrCode, "PNG", response.getOutputStream());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(qrCode, "PNG", baos);
baos.flush();
byte[] imageInByte = baos.toByteArray();
baos.close();
// flush the output
response.reset();
response.setContentType("image/png");
response.setHeader("Access-Control-Allow-Origin", "*");
response.setContentLength(imageInByte.length);
response.getOutputStream().write(imageInByte, 0, imageInByte.length);
response.getOutputStream().flush();
return null;
}
Expand Down
6 changes: 3 additions & 3 deletions ShortPaymentAPI/web/WEB-INF/dispatcher-servlet.xml
Expand Up @@ -11,9 +11,9 @@
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

<mvc:annotation-driven />

<mvc:annotation-driven />

<context:component-scan base-package="org.spayd.rest"/>

</beans>

0 comments on commit 3667a0e

Please sign in to comment.