Grails JSON最大长度 [英] Grails JSON max length

查看:125
本文介绍了Grails JSON最大长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道JSON字符串通常在PHP上的Apache中定义了一个最大长度,但是在Grails中使用TomCat定义的JSON字符串的最大长度是多少?



我发送的JSON字符串长度为13,636个字符,但我可以缩短很多(尽管我不想在测试时) - 也是,我们将来可能会通过JSON发送图片,这些图片需要base64编码,因此会产生相当大的开销。如果我们要做这样的事情,那么我担心如果这个限制造成了问题,那么我们现在应该克服这个问题。



如果没有限制,那么也许我做错了什么。我使用 domainInstance作为grails.converters.deep.JSON 编码为JSON的有限数量的域对象 - 这是使用完成的循环,每当JSON字符串附加到 StringBuilder



时,在视图中使用 render(stringBuilder.toString())的StringBuilder,并且第一个JSON字符串很好,但是第二个JSON字符串被截断到接近尾声。如果我对此感到不解,我会说我已经获得了StringBuilder总长度的80%左右。



编辑/解决方案:道歉伙计&女孩,我注意到,当我在页面上查看源代码时,我得到完整的JSON字符串,但是当我查看页面时,它被截断。这是一个奇怪的错误,但我会接受为什么它被截断的答案。感谢。

解决方案 是Tomcat中POST请求的最大大小,您可能会担心以后如果你开始发送巨大的JSON / Base64映像请求(就像你提到的那样)。

在tomcat中的默认值是2,097,152字节(2 MB);它可以通过在server.xml中设置< Connector> maxPostSize 属性进行更改。



来自文档(对于Tomcat 7中的 maxPostSize ):

lockquote

最大字节数POST将由
容器FORM URL参数解析处理。限制可以通过
禁用,将此属性设置为小于或等于0的值。如果未指定
,则此属性设置为2097152(2兆字节)。


如果您将Grails战争部署到独立的Tomcat实例,则配置非常简单。不过,如果您使用tomcat 插件。如果是我,我可能会使用war而不是grails run-app来运行大文件测试。


I am aware that JSON strings often have a max length defined in either Apache on PHP, however where is the max length for JSON strings defined in Grails using TomCat?

The JSON string I am sending is 13,636 characters in length, however I can shorten it a lot (although I don't want to while we're testing) - also, we may be sending images via JSON in the future which I've read requires base64 encoding and thus a considerable overhead. If we were to do such a thing then I am worried that if this limit is causing problems, it's something we should overcome now.

If there is no limit, then perhaps I am doing something wrong. I have a finite amount of domain objects that I am encoding as JSON using domainInstance as grails.converters.deep.JSON - this is done using a for loop and each time the JSON string is appended to a StringBuilder

I then render the StringBuilder in a view using render(stringBuilder.toString()) and the first JSON string is fine, however the second is truncated near to the end. If I were to guestimate I'd say I am getting around 80% of the total length of the StringBuilder.

EDIT/SOLUTION: Apologies guys & girls, I've noticed that when I view source on the page I get the complete JSON string, however when I just view the page it's truncated. It's an odd error, I'll accept answers on why it's truncated, though. Thanks.

解决方案

There is a maximum size in Tomcat for POST requests, which you may be concerned with later if you start sending huge JSON / Base64 image requests (like you mentioned).

The default value in tomcat is 2,097,152 bytes (2 MB); it can be changed by setting the maxPostSize attribute of the <Connector> in server.xml.

From the docs (for maxPostSize in Tomcat 7):

The maximum size in bytes of the POST which will be handled by the container FORM URL parameter parsing. The limit can be disabled by setting this attribute to a value less than or equal to 0. If not specified, this attribute is set to 2097152 (2 megabytes).

This is pretty straightforward to configure if you're deploying a Grails war to a standalone Tomcat instance. However, I can't find much about actually configuring server.xml if you're using the tomcat plugin. If it were me, I'd probably just run large-file tests using the war instead of with grails run-app.

这篇关于Grails JSON最大长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆