gpt4 book ai didi

java - Spring-WS 内容大小限制与 dataHandler

转载 作者:太空宇宙 更新时间:2023-11-04 11:36:26 24 4
gpt4 key购买 nike

我使用 spring-ws 4.3.3,我想知道是否可以获取包含数据处理程序参数的肥皂请求的真实内容大小。

如果请求大小似乎小于 4096 字节,则以下代码可以正常工作,否则如果 content-size 大于 4096,则 requestSize 等于 -1。然而在javadoc中它是这样写的:

Returns the length, in bytes, of the request body and made available by * the input stream, or -1 if the length is not known ir is greater than * Integer.MAX_VALUE

在我的示例中,如果肥皂请求超过 51200000,我会尝试生成错误消息,但如果我的请求大于 4096,则会出现错误。

TransportContext tc = TransportContextHolder.getTransportContext();
HttpServletConnection connection = (HttpServletConnection) tc.getConnection();
Integer requestSize = connection.getHttpServletRequest().getContentLength();
if (requestSize==-1 || requestSize > 51200000) {
response.setStatus(getStatusResponse(PricingConstants.WS_FILE_SIZE_EXCEEDED_CODE,
PricingConstants.WS_FILE_SIZE_EXCEEDED_MSG));
return response;

XSD

    <xs:complexType name="wsAddDocumentRequest">
<xs:sequence>
<xs:element name="callingAspect">
<xs:complexType>
<xs:sequence>
<xs:element name="userId" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Id" type="xs:string" />
<xs:element name="contentPath" type="xs:string" minOccurs="0" />
<xs:element name="file" type="xs:base64Binary" minOccurs="0"
xmime:expectedContentTypes="application/octet-stream" />
<xs:element name="document" type="prc:document" />
<xs:element name="authorizedUsers" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="user" type="xs:string" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>

谢谢

最佳答案

该大小的请求通常使用 HTTP 分块,并且内容长度事先未知,即 getContentLength() 将返回 -1。要禁止超过特定大小的请求,您可以配置应用程序服务器(如果它有限制请求大小的选项)或安装一个 servlet 过滤器,该过滤器在从请求读取一定数量的字节后触发错误。

关于java - Spring-WS 内容大小限制与 dataHandler,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43225368/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com