2011-03-15 11 views
0

tomcat 6에 배포 된 웹 서비스가 있으며 apache-cxf 2.3.3을 통해 공개됩니다. 생성 된 소스 스텁이 wsdl2java를 사용하여이 서비스를 호출 할 수 있습니다.큰 비누 요청을 보낼 때 예외가 발생했습니다.

큰 요청 (~ 1Mb)을 보낼 때까지 상황이 정상적으로 보였습니다. 이 요청이 처리 및 예외로 실패하지 않은 :

Interceptor for {http://localhost/}ResourceAllocationServiceSoapService has thrown  
exception, unwinding now org.apache.cxf.binding.soap.SoapFault: 
Error reading XMLStreamReader. 
... 
com.ctc.wstx.exc.WstxEOFException: Unexpected EOF in prolog 
at [row,col {unknown-source}]: [1,0] 

여기에 최대 요청 길이의 일종인가, 나는 그것으로 완전히 붙어있어.

답변

2

나는 무엇이 잘못되었는지 알아 냈습니다. 내가

CachedOutputStream requestStream = new CachedOutputStream(1000000); 

일이 잘 작동을 시작으로이 교체 할 때

CachedOutputStream requestStream = new CachedOutputStream() 

: 사실은 인터셉터의 코드 내부 버그이었다.

따라서 스트림을 복사하는 동안 요청이 트렁크되었습니다.

+0

어디에서 CachedOutputStream을 추가 했습니까? requestStream = new CachedOutputStream (1000000); 나도 같은 문제에 직면하고있다. –

3

Vladimir's suggestion이 처리되었습니다. CachedOutputStream 클래스를 사용하면 "프롤로그에서 예기치 않은 EOF com.ctc.wstx.exc.WstxEOFException을"나는에 geting의 동일한 문제로 실행 1000000

public void handleMessage(SoapMessage message) throws Fault { 
     // Get message content for dirty editing... 

    InputStream inputStream = message.getContent(InputStream.class); 

    if (inputStream != null) 
    { 
     String processedSoapEnv = ""; 
     // Cache InputStream so it can be read independently 
     CachedOutputStream cachedInputStream = new CachedOutputStream(1000000); 
     try { 
      IOUtils.copy(inputStream,cachedInputStream); 
      inputStream.close(); 
      cachedInputStream.close(); 

      InputStream tmpInputStream = cachedInputStream.getInputStream(); 
      try{ 
       String inputBuffer = ""; 
       int data; 
       while((data = tmpInputStream.read()) != -1){ 
        byte x = (byte)data; 
        inputBuffer += (char)x; 
       } 
       /** 
        * At this point you can choose to reformat the SOAP 
        * envelope or simply view it just make sure you put 
        * an InputStream back when you done (see below) 
        * otherwise CXF will complain. 
        */ 
       processedSoapEnv = fixSoapEnvelope(inputBuffer); 
      } 
      catch(IOException e){ 

      } 
     } 
     catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 


     // Re-set the SOAP InputStream with the new envelope 

     message.setContent(InputStream.class,new ByteArrayInputStream(processedSoapEnv.getBytes())); 

     /** 
     * If you just want to read the InputStream and not 
     * modify it then you just need to put it back where 
     * it was using the CXF cached inputstream 
     * 
     * message.setContent(InputStream.class,cachedInputStream.getInputStream()); 
     */ 
    }  


} 
2

을 넣어 곳이 코드는 아래의 이해를 다른 사람을 도움이 될 것입니다.

CachedOutputStream 클래스의 소스를 보면 임계 값은 스트림의 데이터를 "메모리"에서 "파일"로 전환하는 데 사용됩니다.
가정 스트림이 따라서 다음 코드 파일에 저장됩니다 임계 값을 초과하는 데이터에서 작동이

IOUtils.copy(inputStream,cachedInputStream); 
inputStream.close(); 
cachedInputStream.close(); //closes the stream, the file on disk gets deleted 
InputStream tmpInputStream = cachedInputStream.getInputStream(); //returned tmpInputStream is brand *empty* one 
// ... reading tmpInputStream here will produce WstxEOFException 

모든 스트림 데이터로 도움이 되는가 '임계 값을'증가를 깰려고하는 메모리와 같은 시나리오를 호출 cachedInputStream에 저장됩니다 .close()는 기본 스트림 구현을 정말로 닫지 않아 나중에 나중에 읽을 수 있습니다. 여기

IOUtils.copy(inputStream,cachedInputStream); 
inputStream.close(); 
InputStream tmpInputStream = cachedInputStream.getInputStream(); 
cachedInputStream.close(); 
// reading from tmpInputStream here works fine 

임시 파일() 확대가 tmpInputStream에 호출 될 때 삭제하고 더 이상 다른 참조가됩니다 (나를 위해 예외없이 일을 적어도) 위의 코드의 '고정'버전입니다 CachedOutputStream.maybeDeleteTempFile()의 소스 코드를 참조하십시오.

+0

이것은 나를 위해 일했다. 감사합니다. – hsnkhrmn

관련 문제