1 | // Copyright 2004-2007 Jean-Francois Poilpret |
2 | // |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | // you may not use this file except in compliance with the License. |
5 | // You may obtain a copy of the License at |
6 | // |
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | // |
9 | // Unless required by applicable law or agreed to in writing, software |
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | // See the License for the specific language governing permissions and |
13 | // limitations under the License. |
14 | |
15 | package net.sourceforge.hiveremoting.caucho; |
16 | |
17 | import java.io.IOException; |
18 | import java.io.InputStream; |
19 | import java.io.OutputStream; |
20 | |
21 | import org.apache.hivemind.internal.ServicePoint; |
22 | |
23 | import com.caucho.hessian.io.AbstractHessianOutput; |
24 | import com.caucho.hessian.io.Hessian2Input; |
25 | import com.caucho.hessian.io.Hessian2Output; |
26 | import com.caucho.hessian.io.HessianOutput; |
27 | import com.caucho.hessian.io.SerializerFactory; |
28 | import com.caucho.hessian.server.HessianSkeleton; |
29 | |
30 | /** |
31 | * @author Jean-Francois Poilpret |
32 | */ |
33 | public class HessianRemoteServiceInvoker extends AbstractRemoteServiceInvoker |
34 | { |
35 | public HessianRemoteServiceInvoker( PublishServiceContribution contrib, |
36 | SerializerFactory factory) |
37 | { |
38 | super(contrib, factory); |
39 | ServicePoint service = contrib.getServiceId(); |
40 | Class intf = service.getServiceInterface(); |
41 | _skeleton = new HessianSkeleton(service.getService(intf), intf); |
42 | } |
43 | |
44 | //CSOFF: IllegalThrowsCheck |
45 | @Override protected void invoke(InputStream is, OutputStream os) |
46 | throws Throwable |
47 | { |
48 | // Create in stream from HTTP request |
49 | Hessian2Input in = new Hessian2Input(is); |
50 | |
51 | // Check version of Hessian protocol used |
52 | int code = in.read(); |
53 | if (code != 'c') |
54 | { |
55 | throw new IOException("expected 'c' in hessian input at " + code); |
56 | } |
57 | int major = in.read(); |
58 | int minor = in.read(); |
59 | |
60 | // Create out stream for HTTP response |
61 | AbstractHessianOutput out; |
62 | if (major >= 2) |
63 | { |
64 | out = new Hessian2Output(os); |
65 | } |
66 | else |
67 | { |
68 | out = new HessianOutput(os); |
69 | } |
70 | |
71 | // Set special Serializer Factory |
72 | in.setSerializerFactory(_factory); |
73 | out.setSerializerFactory(_factory); |
74 | // Proceed with invocation |
75 | _skeleton.invoke(in, out); |
76 | } |
77 | //CSON: IllegalThrowsCheck |
78 | |
79 | protected final HessianSkeleton _skeleton; |
80 | } |