cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jasonmp...@gmail.com
Subject Re: Caculate SOAP response size
Date Mon, 17 Sep 2012 12:55:26 GMT
I think that code ignores the throw Fault because of the catch Exception
auto generated code,
On Sep 11, 2012 9:46 PM, "shadowlaw" <aymen.benhmida@gmail.com> wrote:

> foud this code which respond to my need, but when throwing the exception i
> get the response which doen't make sens. Normally i would get a fault
> message.
>
> public class ResponseContentLengthValidator extends
> AbstractPhaseInterceptor<Message> {
>
>     private final static Logger log =
> Logger.getLogger(ResponseContentLengthValidator.class);
>
>     public static final int MAX_SOAP_MESSAGE_SIZE = 2 * 1024 * 1024;
>
>     final char[] buffer = new char[MAX_SOAP_MESSAGE_SIZE];
>
>     /**
>      * @deprecated
>      */
>     public ResponseContentLengthValidator() {
> //        super(Phase.PRE_STREAM);
>         super(Phase.PRE_STREAM);
>         log.debug("ResponseContentLengthValidator Started");
>         getAfter().add(SAAJOutInterceptor.class.getName());
>     }
>
>     /**
>      * Intercepts a message.
>      * Interceptors should NOT invoke handleMessage or handleFault
>      * on the next interceptor - the interceptor chain will
>      * take care of this.
>      *
>      * @param message
>      */
>     public void handleMessage(Message message) throws Fault {
>
>         log.debug("ResponseContentLengthValidator.handleMessage(..)");
>
>         OutputStream os = message.getContent(OutputStream.class);
>         CacheAndWriteOutputStream cwos = new CacheAndWriteOutputStream(os);
>         message.setContent(OutputStream.class, cwos);
>
>         cwos.registerCallback(new LoggingOutCallBack());
>     }
>
>     class LoggingOutCallBack implements CachedOutputStreamCallback {
>         public void onClose(CachedOutputStream cos) {
>             try {
>                 if (cos != null) {
>                     final int messageSize =
> IOUtils.toString(cos.getInputStream()).getBytes().length;
>                     if (messageSize > MAX_SOAP_MESSAGE_SIZE) {
>                         if (log.isDebugEnabled()) {
>                             log.debug("Message is Under 2M");
>                         }
>                     } else {
> //                        throw new Fault(new ServiceException("Max Size
> Reached"));
>                         throw new RuntimeException("Max Size Reached");
>                     }
>                 }
>
>             } catch (Exception e) {
>                 // TODO Auto-generated catch block
>                 e.printStackTrace();
>             }
>         }
>
>         public void onFlush(CachedOutputStream arg0) {
>         }
>     }
> }
>
>
>
>
>
> --
> View this message in context:
> http://cxf.547215.n5.nabble.com/Caculate-SOAP-response-size-tp5713783p5713785.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message