1 package eu
.etaxonomy
.taxeditor
.service
;
3 import java
.io
.IOException
;
4 import java
.io
.OutputStream
;
6 import org
.apache
.log4j
.Logger
;
7 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
8 import org
.springframework
.remoting
.httpinvoker
.HttpInvokerClientConfiguration
;
9 import org
.springframework
.remoting
.support
.RemoteInvocation
;
10 import org
.springframework
.remoting
.support
.RemoteInvocationResult
;
11 import org
.springframework
.stereotype
.Component
;
13 import eu
.etaxonomy
.cdm
.api
.service
.UpdateResult
;
14 import eu
.etaxonomy
.taxeditor
.session
.ICdmEntitySessionManager
;
17 public class CdmServiceRequestExecutor
extends CdmAuthenticatedHttpInvokerRequestExecutor
{
19 private static final Logger logger
= Logger
.getLogger(CdmServiceRequestExecutor
.class);
22 private ICdmEntitySessionManager cdmEntitySessionManager
;
24 private RemoteInvocation currentRemoteInvocation
;
27 protected void writeRemoteInvocation(RemoteInvocation invocation
, OutputStream os
) throws IOException
{
28 currentRemoteInvocation
= invocation
;
29 super.writeRemoteInvocation(invocation
, os
);
33 protected RemoteInvocationResult
doExecuteRequest(HttpInvokerClientConfiguration config
,
34 java
.io
.ByteArrayOutputStream baos
)
35 throws java
.io
.IOException
,
36 java
.lang
.ClassNotFoundException
{
37 RemoteInvocationResult rir
= fromCache(currentRemoteInvocation
);
39 // if rir is not null at this point we assume that the
40 // the object has already been loaded in the cache and
41 // does not need to be reloaded
44 logger
.info("Remote invoking : " + currentRemoteInvocation
.getMethodName() + "@" + config
.getServiceUrl());
45 rir
= super.doExecuteRequest(config
, baos
);
46 if(rir
.getValue() != null && !rir
.hasException()) {
47 if("merge".equals(currentRemoteInvocation
.getMethodName()) || "save".equals(currentRemoteInvocation
.getMethodName())) {
48 rir
= new RemoteInvocationResult(cdmEntitySessionManager
.load(rir
.getValue(), true));
49 } else if(rir
.getValue() instanceof UpdateResult
){
50 UpdateResult result
= (UpdateResult
)rir
.getValue();
52 cdmEntitySessionManager
.load(result
, true);
55 rir
= new RemoteInvocationResult(cdmEntitySessionManager
.load(rir
.getValue(), false));
58 cache(currentRemoteInvocation
, rir
);
60 currentRemoteInvocation
= null;
65 public void cache(RemoteInvocation ri
, RemoteInvocationResult rir
) {
69 public RemoteInvocationResult
fromCache(RemoteInvocation ri
) {