2017-04-05 18 views
1

스프링 - 4.3.3에서 작업하고 데이터 핸들러 매개 변수가 포함 된 SOAP 요청에 대한 실제 콘텐츠 크기를 얻을 수 있는지 알고 싶습니다.Spring-WS content-dataHandler의 크기 제한

다음 코드는 content-size가 4096보다 크거나 requestSize가 -1 인 경우 요청 크기가 4096 바이트 미만인 것으로 보이는 경우 잘 작동합니다. 그러나, 자바 독에 기입 같습니다

는 길이가 IR을 알 수없는 경우 * 입력 스트림 -1 * 보다 큰 요청 본문의 길이 (바이트 단위)를 돌려 하여 사용할 내 예에서

에 Integer.MAX_VALUE 비누 요청이 51,200,000을 초과하면 나는 오류 메시지를 생성하려고하지만 내 요청이 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> 

감사 그 크기

답변

0

요청은 통상적으로, 즉 getContentLength() 반환되며, HTTP는 청크와 콘텐츠 길이는 사전에 공지되지 않은 사용 -1. 특정 크기를 초과하는 요청을 허용하지 않으려면 응용 프로그램 서버 (요청 크기를 제한하는 옵션이있는 경우)를 구성하거나 요청에서 특정 바이트 수를 읽은 후에 오류를 트리거하는 서블릿 필터를 설치하십시오. 내 마음 나는 해결책을 발견

을 여는

0

감사는 안드레아스

/** 
* Returns true if content size exceeds the max file size 
* 
* @param dataHandler content 
* @param maxSize the max size allowed 
* @return true if contentSize greater than maxSize, false otherwise 
* @throws IOException 
*/ 
public static boolean isTooBigContent(DataHandler dataHandler, long maxSize) throws IOException { 
    long contentSize = 0; 

    try (InputStream input = dataHandler.getInputStream()) { 
     int n; 
     while (IOUtils.EOF != (n = input.read(new byte[4096]))) { 
      contentSize += n; 
      if (Long.compare(contentSize, maxSize) > 0) 
       return true; 
     } 
    } 

    return false; 
}