List of usage examples for org.apache.http.entity BasicHttpEntity getContentType
public Header getContentType()
From source file:ste.web.http.velocity.VelocityHandler.java
@Override public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException { String view = (String) context.getAttribute(ATTR_VIEW); if (view == null) { return;//w w w. ja v a 2 s. c om } view = getViewPath(request.getRequestLine().getUri(), view); ByteArrayOutputStream baos = new ByteArrayOutputStream(); Writer out = new OutputStreamWriter(baos); try { Template t = engine.getTemplate(view); t.merge(buildContext(request, (HttpSessionContext) context), out); out.flush(); } catch (ResourceNotFoundException e) { response.setStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_NOT_FOUND, "View " + view + " not found."); return; } catch (ParseErrorException e) { throw new HttpException("Parse error evaluating " + view + ": " + e, e); } catch (MethodInvocationException e) { throw new HttpException("Method invocation error evaluating " + view + ": " + e, e); } BasicHttpEntity body = (BasicHttpEntity) response.getEntity(); body.setContentLength(baos.size()); body.setContent(new ByteArrayInputStream(baos.toByteArray())); if ((body.getContentType() == null) || StringUtils.isBlank(body.getContentType().getValue())) { body.setContentType(ContentType.TEXT_HTML.getMimeType()); } }