2017-04-05 17 views
1

私はspring-ws 4.3.3を使用していますが、データハンドラパラメータを含むSOAP要求の実際のコンテンツサイズを取得できるかどうかを知りたいと思います。Spring-WS content-dataHandlerのサイズ制限

次のコードは、要求サイズが4096バイト未満の場合は正常に機能します。そうでない場合は、content-sizeが4096より大きい場合、requestSizeは-1になります。しかし、それが書かれてjavadocの:

リクエストボディの長さをバイト単位で返します によって使用可能になる*入力ストリームを、または-1長さがIRが * より大きい知られていない場合私の例では

Integer.MAX_VALUEのSOAP要求が5120万を超えた場合、私はエラーメッセージを生成しようとするが、私の要求は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

要求典型的にはチャンクHTTPを使用して、コンテンツの長さが予め知られていない、すなわちgetContentLength()が返す-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; 
} 
関連する問題