EMMA Coverage Report (generated Tue Feb 12 22:23:49 ICT 2008)
[all classes][net.sourceforge.hiveremoting.caucho]

COVERAGE SUMMARY FOR SOURCE FILE [CauchoProxyFactory.java]

nameclass, %method, %block, %line, %
CauchoProxyFactory.java0%   (0/1)0%   (0/2)0%   (0/99)0%   (0/21)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class CauchoProxyFactory0%   (0/1)0%   (0/2)0%   (0/99)0%   (0/21)
CauchoProxyFactory (CauchoProxyConfigurator, SerializerFactory, int, int, boo... 0%   (0/1)0%   (0/40)0%   (0/11)
createCoreServiceImplementation (ServiceImplementationFactoryParameters): Object 0%   (0/1)0%   (0/59)0%   (0/10)

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 
15package net.sourceforge.hiveremoting.caucho;
16 
17import java.lang.reflect.Proxy;
18 
19import org.apache.commons.httpclient.HttpConnectionManager;
20import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
21import org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory;
22import org.apache.commons.httpclient.protocol.Protocol;
23import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
24import org.apache.commons.logging.Log;
25import org.apache.hivemind.ServiceImplementationFactory;
26import org.apache.hivemind.ServiceImplementationFactoryParameters;
27 
28import com.caucho.hessian.io.SerializerFactory;
29 
30/**
31 * This service creates Proxys to remote services that are published through
32 * Caucho Hessian or Burlap protocols.
33 * <p>
34 * <b>ServiceModel must be singleton</b>
35 * <p>
36 * Note: how to dynamically define user/password for authentication?
37 * <p>
38 * The idea is to put them into System properties and use HiveMind
39 * <code>SystemPropertiesSymbolSource</code> to do the substitution at Registry
40 * construction time (please note this is not possible to have real dynamic user/
41 * password definition after HiveMind Registry has been built).
42 * <p>
43 * In hivemind.xml, you would have:
44 * <pre>
45 * &lt;contribution configuration-id="hivemind.SymbolSources"&gt;
46 *     &lt;source name="SystemProperties"
47 *         class="org.apache.hivemind.impl.SystemPropertiesSymbolSource"/&gt;
48 * &lt;/contribution&gt;
49 * 
50 * &lt;implementation service-id="hiveboard.shared.WhiteBoardUserService"&gt;
51 *     &lt;invoke-factory service-id="hiveremoting.caucho.CauchoProxyFactory" 
52 *                        model="singleton"&gt;
53 *     &lt;proxy url="http://server:8080/webapp/path"
54 *         protocol="Hessian" user="${user}" password="${password}" /&gt;
55 *     &lt;/invoke-factory&gt;
56 * &lt;/implementation&gt;
57 * </pre>
58 * Then in your source code, you would have something like:
59 * <pre>
60 * Properties props = System.getProperties();
61 * props.setProperty("user", "myusername");
62 * props.setProperty("password", "mypassword");
63 * Registry registry = RegistryBuilder.constructDefaultRegistry();
64 * </pre>
65 *
66 * @author        Jean-Francois Poilpret
67 */
68public class CauchoProxyFactory implements ServiceImplementationFactory
69{
70        public CauchoProxyFactory(        CauchoProxyConfigurator        configurator,
71                                                                SerializerFactory                factory,
72                                                                int                                                maxConnections,
73                                                                int                                                maxConnectionsPerHost,
74                                                                boolean                                        httpsStrictCertificateCheck)
75        {
76                _configurator = configurator;
77                _factory = factory;
78                _cnxManager = new MultiThreadedHttpConnectionManager();
79                _cnxManager.getParams().setMaxTotalConnections(maxConnections);
80                _cnxManager.getParams().setDefaultMaxConnectionsPerHost(maxConnectionsPerHost);
81                if (!httpsStrictCertificateCheck)
82                {
83                        ProtocolSocketFactory socketFactory = new EasySSLProtocolSocketFactory();
84                        Protocol protocol = new Protocol("https", socketFactory, DEFAULT_HTTPS_PORT);
85                        Protocol.registerProtocol("https", protocol);
86                }
87        }
88        
89        public Object        createCoreServiceImplementation(
90                                                ServiceImplementationFactoryParameters factoryParams)
91        {
92                Log logger = factoryParams.getLog();
93                // Read parameter
94                CauchoProxyContribution contrib = 
95                                (CauchoProxyContribution) factoryParams.getFirstParameter();
96                // Just in time update of setup with programmatically provided values
97                contrib = _configurator.getConfiguration(factoryParams.getServiceId(), contrib);
98 
99                AbstractCauchoProxy proxy = null;
100                if (contrib.getProtocol() == net.sourceforge.hiveremoting.caucho.Protocol.Hessian)
101                {
102                        proxy = new HessianProxy(contrib, _factory, _cnxManager, logger);
103                }
104                else if (contrib.getProtocol() == net.sourceforge.hiveremoting.caucho.Protocol.Burlap)
105                {
106                        proxy = new BurlapProxy(contrib, _factory, _cnxManager, logger);
107                }
108        return Proxy.newProxyInstance(
109                                                factoryParams.getInvokingModule().getClassResolver().getClassLoader(),
110                                                new Class[] {factoryParams.getServiceInterface()},
111                                                proxy);
112        }
113        
114        static private final int                                DEFAULT_HTTPS_PORT = 443;
115        
116        private final CauchoProxyConfigurator        _configurator;
117        private final HttpConnectionManager                _cnxManager;
118        private final SerializerFactory                        _factory;
119}

[all classes][net.sourceforge.hiveremoting.caucho]
EMMA 2.0.5312 (C) Vladimir Roubtsov