How to get response size from Spring 2.5 HTTP remote call?

I stuck in a package org.springframework.remoting.httpinvokerin Spring 2.5, trying to find a way to get visibility in the size of the response, but I keep walking in circles.

On another question that I saw here, I think I want to get a handle InputStreamthat represents the response from the server, and then wrap it using apost commons-io CountingInputStream. What is the best way to do this?

At the moment, I would be happy to just print the response size to stdout, but in the end I want to save it in a known place in my application for additional display.

+3
source share
2 answers

You think about the correct lines, it just needs to be specified. Pick yourself up, I'm going to hit you with a bunch of long class names ...

Client Side factory, which creates a plug, which is talking to the remote service HttpInvokerProxyFactoryBean. The superclass ( HttpInvokerClientInterceptor) has a property called httpInvokerRequestExecutor, which by default corresponds to the instance SimpleHttpInvokerRequestExecutor.

It is ripe for subclass and expansion; in particular, it has a method decorateInputStreamthat you can use:

public class CountingHttpInvokerRequestExecutor extends SimpleHttpInvokerRequestExecutor {
   @Override
   protected InputStream decorateInputStream(InputStream is) throws IOException {
      return new CountingInputStream(super.decorateInputStream(is));
   }
}

And then enter this in the proxy factory:

<bean class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
    <property name="httpInvokerRequestExecutor">
        <bean class="com.mycompany.CountingHttpInvokerRequestExecutor"/>
    </property>
      <!-- Plus the various other properties required by HttpInvokerProxyFactoryBean  -->
      <!-- URL, proxy interface, etc -->
</bean>

Then the trick becomes available for this information, which will require some creative rewriting. For example, you can get new instances CountingInputStreamfrom another factory, which then displays the number of bytes in your user interface.

+2

, , Input/OutputStreams. , , commons-io CountingStreams close(), , / . , , ! , , , , SimpleHttpInvokerRequestExecutor , , , .

+1

Source: https://habr.com/ru/post/1738090/


All Articles