01: /*
02: * $Id: ObjectToRemoteInvocationResultTransformer.java 10789 2008-02-12 20:04:43Z dfeist $
03: * --------------------------------------------------------------------------------------
04: * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
05: *
06: * The software in this package is published under the terms of the CPAL v1.0
07: * license, a copy of which has been included with this distribution in the
08: * LICENSE.txt file.
09: */
10:
11: package org.mule.module.spring.remoting;
12:
13: import org.mule.api.transformer.TransformerException;
14: import org.mule.transformer.AbstractTransformer;
15:
16: import java.io.ObjectOutputStream;
17:
18: import org.apache.commons.io.output.ByteArrayOutputStream;
19: import org.springframework.remoting.support.RemoteInvocationResult;
20:
21: public class ObjectToRemoteInvocationResultTransformer extends
22: AbstractTransformer {
23:
24: public ObjectToRemoteInvocationResultTransformer() {
25: super ();
26: setReturnClass(byte[].class);
27: }
28:
29: protected Object doTransform(Object src, String encoding)
30: throws TransformerException {
31: try {
32: if (logger.isDebugEnabled()) {
33: logger
34: .debug("ObjectToRemoteInvocationResult.doTransform("
35: + src + ")");
36: }
37:
38: RemoteInvocationResult rval;
39:
40: if (src instanceof RemoteInvocationResult) {
41: rval = (RemoteInvocationResult) src;
42: } else {
43: rval = new RemoteInvocationResult(src);
44: }
45:
46: ByteArrayOutputStream baos = new ByteArrayOutputStream();
47: ObjectOutputStream oos = new ObjectOutputStream(baos);
48: oos.writeObject(rval);
49: oos.close();
50: return baos.toByteArray();
51: } catch (Exception e) {
52: throw new TransformerException(this, e);
53: }
54: }
55:
56: }
|