01: /*
02: * Copyright 2002-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.springframework.remoting.caucho;
18:
19: import java.io.InputStream;
20: import java.io.OutputStream;
21: import java.lang.reflect.Method;
22:
23: import com.caucho.hessian.io.HessianInput;
24: import com.caucho.hessian.io.HessianOutput;
25: import com.caucho.hessian.io.SerializerFactory;
26: import com.caucho.hessian.server.HessianSkeleton;
27:
28: import org.springframework.util.ClassUtils;
29:
30: /**
31: * Concrete HessianSkeletonInvoker for the Hessian 1 protocol
32: * (version 3.0.19 or lower).
33: *
34: * @author Juergen Hoeller
35: * @since 2.0
36: */
37: class Hessian1SkeletonInvoker extends HessianSkeletonInvoker {
38:
39: private static final Method invokeMethod;
40:
41: private static final boolean applySerializerFactoryToOutput;
42:
43: static {
44: invokeMethod = ClassUtils.getMethodIfAvailable(
45: HessianSkeleton.class, "invoke", new Class[] {
46: HessianInput.class, HessianOutput.class });
47: applySerializerFactoryToOutput = ClassUtils.hasMethod(
48: HessianOutput.class, "setSerializerFactory",
49: new Class[] { SerializerFactory.class });
50: }
51:
52: public Hessian1SkeletonInvoker(HessianSkeleton skeleton,
53: SerializerFactory serializerFactory) {
54: super (skeleton, serializerFactory);
55: if (invokeMethod == null) {
56: throw new IllegalStateException(
57: "Hessian 1 (version 3.0.19-) not present");
58: }
59: }
60:
61: public void invoke(InputStream inputStream,
62: OutputStream outputStream) throws Throwable {
63: HessianInput in = new HessianInput(inputStream);
64: HessianOutput out = new HessianOutput(outputStream);
65: if (this .serializerFactory != null) {
66: in.setSerializerFactory(this .serializerFactory);
67: if (applySerializerFactoryToOutput) {
68: out.setSerializerFactory(this .serializerFactory);
69: }
70: }
71: invokeMethod.invoke(this .skeleton, new Object[] { in, out });
72: }
73:
74: }
|