| 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.InputStream; |
| 18 | import java.io.OutputStream; |
| 19 | |
| 20 | import org.apache.commons.httpclient.HttpConnectionManager; |
| 21 | import org.apache.commons.logging.Log; |
| 22 | |
| 23 | import com.caucho.hessian.client.HessianRuntimeException; |
| 24 | import com.caucho.hessian.io.AbstractHessianInput; |
| 25 | import com.caucho.hessian.io.AbstractHessianOutput; |
| 26 | import com.caucho.hessian.io.Hessian2Input; |
| 27 | import com.caucho.hessian.io.Hessian2Output; |
| 28 | import com.caucho.hessian.io.HessianInput; |
| 29 | import com.caucho.hessian.io.HessianOutput; |
| 30 | import com.caucho.hessian.io.SerializerFactory; |
| 31 | |
| 32 | /** |
| 33 | * Dynamic proxy for Caucho Hessian protocol on client side. |
| 34 | * |
| 35 | * @author Jean-Francois Poilpret |
| 36 | */ |
| 37 | public class HessianProxy extends AbstractCauchoProxy |
| 38 | { |
| 39 | public HessianProxy( CauchoProxyContribution contrib, |
| 40 | SerializerFactory factory, |
| 41 | HttpConnectionManager cnxManager, |
| 42 | Log logger) |
| 43 | { |
| 44 | super(contrib, factory, cnxManager, logger); |
| 45 | _version = contrib.getProtocolVersion(); |
| 46 | } |
| 47 | |
| 48 | //CSOFF: IllegalThrowsCheck |
| 49 | @Override protected Object getReturnValue(InputStream is, Class type) |
| 50 | throws Throwable |
| 51 | { |
| 52 | AbstractHessianInput in; |
| 53 | if (_version == 2) |
| 54 | { |
| 55 | in = new Hessian2Input(is); |
| 56 | } |
| 57 | else |
| 58 | { |
| 59 | in = new HessianInput(is); |
| 60 | } |
| 61 | // Set special Serializer Factory |
| 62 | in.setSerializerFactory(_factory); |
| 63 | //####in.setRemoteResolver(getRemoteResolver()); |
| 64 | return in.readReply(type); |
| 65 | } |
| 66 | //CSON: IllegalThrowsCheck |
| 67 | |
| 68 | //CSOFF: IllegalThrowsCheck |
| 69 | @Override protected void callMethod(OutputStream os, String method, Object[] args) |
| 70 | throws Throwable |
| 71 | { |
| 72 | AbstractHessianOutput out; |
| 73 | if (_version == 2) |
| 74 | { |
| 75 | out = new Hessian2Output(os); |
| 76 | } |
| 77 | else |
| 78 | { |
| 79 | out = new HessianOutput(os); |
| 80 | } |
| 81 | // Set special Serializer Factory |
| 82 | out.setSerializerFactory(_factory); |
| 83 | out.call(method, args); |
| 84 | } |
| 85 | //CSON: IllegalThrowsCheck |
| 86 | |
| 87 | @Override protected RuntimeException createException(String message) |
| 88 | { |
| 89 | return new HessianRuntimeException(message); |
| 90 | } |
| 91 | |
| 92 | @Override protected RuntimeException createException(Throwable cause) |
| 93 | { |
| 94 | return new HessianRuntimeException(cause); |
| 95 | } |
| 96 | |
| 97 | protected final int _version; |
| 98 | } |