if (null != accept) { if (S.eq("json", accept, S.IGNORECASE)) { accept = H.Format.JSON.contentType(); } else { H.Format format = H.Format.of(accept); if (null == format) { format = H.Format.resolve(accept); accept = format.contentType(); byte[] content = $.convert(fileUrl).to(byte[].class); String checksum = IO.checksum(content); RequestBody fileBody = RequestBody.create(MediaType.parse(fileFormat.contentType()), content); formBuilder.addFormDataPart(key, S.cut(filePath).afterLast("/"), fileBody); cache("checksum-last", checksum);
msg.setText(content, config().encoding(), accept().name()); } else { Multipart mp = new MimeMultipart(); MimeBodyPart bp = new MimeBodyPart(); mp.addBodyPart(bp); bp.setText(content, config().encoding(), accept().name()); for (ISObject sobj : attachments) { String fileName = sobj.getAttribute(ISObject.ATTR_FILE_NAME);
if (null != accept) { if (S.eq("json", accept, S.IGNORECASE)) { accept = H.Format.JSON.contentType(); } else { H.Format format = H.Format.of(accept); if (null == format) { format = H.Format.resolve(accept); accept = format.contentType(); byte[] content = $.convert(fileUrl).to(byte[].class); String checksum = IO.checksum(content); RequestBody fileBody = RequestBody.create(MediaType.parse(fileFormat.contentType()), content); formBuilder.addFormDataPart(key, S.cut(filePath).afterLast("/"), fileBody); cache("checksum-last", checksum);
result.status(context.successStatus()).apply(context.req(), resp); } else { throw E.unexpected("Unknown accept content type: %s", fmt.contentType());
if (null != accept) { if (S.eq("json", accept, S.IGNORECASE)) { accept = H.Format.JSON.contentType(); } else { H.Format format = H.Format.of(accept); if (null == format) { format = H.Format.resolve(accept); accept = format.contentType();
result.status(context.successStatus()).apply(context.req(), resp); } else { throw E.unexpected("Unknown accept content type: %s", fmt.contentType());
ctx.prepareRespForResultEvaluation().addHeaderIfNotAdded(H.Header.Names.CONTENT_TYPE, fmt.contentType()); r.apply(req, ctx.prepareRespForResultEvaluation()); } catch (IllegalStateException e) {
ctx.prepareRespForResultEvaluation().addHeaderIfNotAdded(H.Header.Names.CONTENT_TYPE, fmt.contentType()); r.apply(req, ctx.prepareRespForResultEvaluation()); } catch (IllegalStateException e) {
H.Format fmt = actionContext.accept(); String s = v instanceof String ? (String) v : $$.toString(v, shouldUseToString); if (fmt.isText()) { return RenderText.of(status, fmt, s);
msg.setText(content, config().encoding(), accept().name()); } else { Multipart mp = new MimeMultipart(); MimeBodyPart bp = new MimeBodyPart(); mp.addBodyPart(bp); bp.setText(content, config().encoding(), accept().name()); for (ISObject sobj : attachments) { String fileName = sobj.getAttribute(ISObject.ATTR_FILE_NAME);
H.Format fmt = actionContext.accept(); String s = v instanceof String ? (String) v : $$.toString(v, shouldUseToString); if (fmt.isText()) { return RenderText.of(status, fmt, s);
private Template getTemplate(int statusCode, ActionContext context) { H.Format format = context.accept(); String key = statusCode + "" + format; $.Var<Template> templateBag = templateCache.get(key); if (null == templateBag) { ViewManager vm = Act.viewManager(); if (null == vm) { // unit testing return null; } context.templatePath(templatePath(statusCode, context)); Template t = vm.load(context); if (null == t) { // try default one if (Act.isDev()) { context.templatePath("/error/dev/errorPage." + context.accept().name()); } else { context.templatePath("/error/errorPage." + context.accept().name()); } t = vm.load(context); } templateBag = $.var(t); templateCache.put(key, templateBag); } return templateBag.get(); }
private Template getTemplate(int statusCode, ActionContext context) { H.Format format = context.accept(); String key = statusCode + "" + format; $.Var<Template> templateBag = templateCache.get(key); if (null == templateBag) { ViewManager vm = Act.viewManager(); if (null == vm) { // unit testing return null; } context.templatePath(templatePath(statusCode, context)); Template t = vm.load(context); if (null == t) { // try default one if (Act.isDev()) { context.templatePath("/error/dev/errorPage." + context.accept().name()); } else { context.templatePath("/error/errorPage." + context.accept().name()); } t = vm.load(context); } templateBag = $.var(t); templateCache.put(key, templateBag); } return templateBag.get(); }
private void setRenderJsonContenTypeIE(final String contentType) { if (H.Format.JSON.contentType().equalsIgnoreCase(contentType)) { renderJsonIeFix = false; return; } renderJsonIeFix = true; jsonIE = H.Format.of("json_ie", contentType); jsonContentTypeProvider = new $.Func0<H.Format>() { @Override public H.Format apply() throws NotAppliedException, $.Break { ActionContext context = ActionContext.current(); if (null != context) { UserAgent ua = context.userAgent(); if (ua.isIE()) { return jsonIE; } } return H.Format.JSON; } }; }
protected String amendSuffix(String path, ActContext context) { if (path.contains(".")) { return path; } H.Format fmt = context.accept(); if (UNKNOWN == fmt) { fmt = HTML; } if (isAcceptFormatSupported(fmt)) { return S.concat(path, ".", fmt.name()); } if (context instanceof ActionContext) { ActionContext actionContext = $.cast(context); H.Request req = actionContext.req(); throw E.unsupport("Error handling %s request to %s - Request accept not supported: %s", req.method(), req.url(), fmt); } throw E.unsupport("Request accept not supported: %s", fmt); }
private void setRenderJsonContenTypeIE(final String contentType) { if (H.Format.JSON.contentType().equalsIgnoreCase(contentType)) { renderJsonIeFix = false; return; } renderJsonIeFix = true; jsonIE = H.Format.of("json_ie", contentType); jsonContentTypeProvider = new $.Func0<H.Format>() { @Override public H.Format apply() throws NotAppliedException, $.Break { ActionContext context = ActionContext.current(); if (null != context) { UserAgent ua = context.userAgent(); if (ua.isIE()) { return jsonIE; } } return H.Format.JSON; } }; }
private H.Format getContentTypeConfig(Map<String, String> properties) { String s = getProperty(CONTENT_TYPE, properties); if (null == s) { return null; } try { H.Format fmt = H.Format.valueOf(s); if (H.Format.HTML == fmt || H.Format.TXT == fmt) { return fmt; } throw E.invalidConfiguration("Content type not supported by mailer: %s", fmt); } catch (ConfigurationException e) { throw e; } catch (Exception e) { throw E.invalidConfiguration("Invalid mailer config content type: %s", s); } }
@Override public void render(Object result, ActionContext context) { MimeType mimeType = MimeType.findByContentType(context.accept().contentType()); E.illegalStateIfNot(mimeType.test(MimeType.Trait.excel)); H.Response resp = context.resp(); resp.contentDisposition(context.attachmentName(), false); ExcelWriter.Builder builder = ExcelWriter.builder() .dateFormat(context.dateFormatPattern(true)) .filter(filter(context)) .headerMap(headerMapping(context)) .fieldStylePatterns(excelDataFormatManager().fieldStyleLookup) .headerTransformer(Keyword.Style.READABLE.asTransformer()); if (mimeType.test(MimeType.Trait.xlsx)) { builder.asXlsx(); } builder.build().write(result, context.resp().outputStream()); }
@Override public void handle(ActionContext context) { Object ticket = secureTicketCodec.createTicket(context.session()); H.Format accept = context.accept(); H.Response resp = context.prepareRespForResultEvaluation(); resp.contentType(accept.contentType()); String content; if (H.Format.JSON == accept) { Map<String, Object> map = C.Map("ticket", ticket); content = JSON.toJSONString(map); } else if (H.Format.XML == accept) { content = S.concat("<?xml version=\"1.0\" ?><ticket>", ticket.toString(), "</ticket>"); } else { content = ticket.toString(); } resp.writeContent(content); }
protected String amendSuffix(String path, ActContext context) { if (path.contains(".")) { return path; } H.Format fmt = context.accept(); if (UNKNOWN == fmt) { fmt = HTML; } if (isAcceptFormatSupported(fmt)) { return S.concat(path, ".", fmt.name()); } if (context instanceof ActionContext) { ActionContext actionContext = $.cast(context); H.Request req = actionContext.req(); throw E.unsupport("Error handling %s request to %s - Request accept not supported: %s", req.method(), req.url(), fmt); } throw E.unsupport("Request accept not supported: %s", fmt); }