218d94dd85531cb159d8be325f7ed0b0473df27c
[taxeditor.git] / eu.etaxonomy.taxeditor.cdmlib / src / main / java / eu / etaxonomy / taxeditor / service / CdmServiceRequestExecutor.java
1 package eu.etaxonomy.taxeditor.service;
2
3 import java.io.IOException;
4 import java.io.OutputStream;
5
6 import org.springframework.remoting.httpinvoker.HttpInvokerClientConfiguration;
7 import org.springframework.remoting.support.RemoteInvocation;
8 import org.springframework.remoting.support.RemoteInvocationResult;
9
10 public abstract class CdmServiceRequestExecutor extends CdmAuthenticatedHttpInvokerRequestExecutor {
11
12 private RemoteInvocation currentRemoteInvocation;
13
14 @Override
15 protected void writeRemoteInvocation(RemoteInvocation invocation, OutputStream os) throws IOException {
16 currentRemoteInvocation = invocation;
17 super.writeRemoteInvocation(invocation, os);
18 }
19
20 @Override
21 protected RemoteInvocationResult doExecuteRequest(HttpInvokerClientConfiguration config,
22 java.io.ByteArrayOutputStream baos)
23 throws java.io.IOException,
24 java.lang.ClassNotFoundException {
25 RemoteInvocationResult rir = fromCache(currentRemoteInvocation);
26
27 if(rir == null) {
28 rir = super.doExecuteRequest(config, baos);
29 cache(currentRemoteInvocation, rir);
30 }
31
32 currentRemoteInvocation = null;
33 return rir;
34 }
35
36 public abstract void cache(RemoteInvocation ri, RemoteInvocationResult rir);
37
38 public abstract RemoteInvocationResult fromCache(RemoteInvocation ri);
39 }