EMMA Coverage Report (generated Wed Jun 08 12:10:57 KST 2005)
[all classes][org.apache.mina.examples.echoserver.ssl]

COVERAGE SUMMARY FOR SOURCE FILE [SSLSocketFactory.java]

nameclass, %method, %block, %line, %
SSLSocketFactory.java100% (1/1)70%  (7/10)39%  (40/103)59%  (17/29)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SSLSocketFactory100% (1/1)70%  (7/10)39%  (40/103)59%  (17/29)
createSocket (InetAddress, int, InetAddress, int): Socket 0%   (0/1)0%   (0/18)0%   (0/3)
createSocket (String, int): Socket 0%   (0/1)0%   (0/14)0%   (0/3)
createSocket (String, int, InetAddress, int): Socket 0%   (0/1)0%   (0/18)0%   (0/3)
getSSLFactory (): SSLSocketFactory 100% (1/1)56%  (9/16)67%  (4/6)
createSocket (InetAddress, int): Socket 100% (1/1)57%  (8/14)67%  (2/3)
<static initializer> 100% (1/1)100% (7/7)100% (3/3)
SSLSocketFactory (): void 100% (1/1)100% (3/3)100% (2/2)
getSocketFactory (): SocketFactory 100% (1/1)100% (8/8)100% (3/3)
isSslEnabled (): boolean 100% (1/1)100% (2/2)100% (1/1)
setSslEnabled (boolean): void 100% (1/1)100% (3/3)100% (2/2)

1/*
2 *   @(#) $Id: SSLSocketFactory.java 156507 2005-03-08 07:34:43Z trustin $
3 *
4 *   Copyright 2004 The Apache Software Foundation
5 *
6 *   Licensed under the Apache License, Version 2.0 (the "License");
7 *   you may not use this file except in compliance with the License.
8 *   You may obtain a copy of the License at
9 *
10 *       http://www.apache.org/licenses/LICENSE-2.0
11 *
12 *   Unless required by applicable law or agreed to in writing, software
13 *   distributed under the License is distributed on an "AS IS" BASIS,
14 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 *   See the License for the specific language governing permissions and
16 *   limitations under the License.
17 *
18 */
19package org.apache.mina.examples.echoserver.ssl;
20 
21import java.io.IOException;
22import java.net.InetAddress;
23import java.net.Socket;
24import java.net.UnknownHostException;
25import java.security.GeneralSecurityException;
26 
27import javax.net.SocketFactory;
28 
29/**
30 * Simple Socket factory to create sockets with or without SSL enabled.
31 * If SSL enabled a "bougus" SSL Context is used (suitable for test purposes)
32 * 
33 * @version $Rev: 156507 $, $Date: 2005-03-08 16:34:43 +0900 $
34 */
35public class SSLSocketFactory extends SocketFactory
36{
37    private static boolean sslEnabled = false;
38 
39    private static javax.net.ssl.SSLSocketFactory sslFactory = null;
40 
41    private static javax.net.SocketFactory factory = null;
42 
43    public SSLSocketFactory()
44    {
45        super();
46    }
47 
48    public Socket createSocket( String arg1, int arg2 ) throws IOException,
49            UnknownHostException
50    {
51        if( isSslEnabled() )
52        {
53            return getSSLFactory().createSocket( arg1, arg2 );
54        }
55        else
56        {
57            return new Socket( arg1, arg2 );
58        }
59    }
60 
61    public Socket createSocket( String arg1, int arg2, InetAddress arg3,
62                               int arg4 ) throws IOException,
63            UnknownHostException
64    {
65        if( isSslEnabled() )
66        {
67            return getSSLFactory().createSocket( arg1, arg2, arg3, arg4 );
68        }
69        else
70        {
71            return new Socket( arg1, arg2, arg3, arg4 );
72        }
73    }
74 
75    public Socket createSocket( InetAddress arg1, int arg2 )
76            throws IOException
77    {
78        if( isSslEnabled() )
79        {
80            return getSSLFactory().createSocket( arg1, arg2 );
81        }
82        else
83        {
84            return new Socket( arg1, arg2 );
85        }
86    }
87 
88    public Socket createSocket( InetAddress arg1, int arg2, InetAddress arg3,
89                               int arg4 ) throws IOException
90    {
91        if( isSslEnabled() )
92        {
93            return getSSLFactory().createSocket( arg1, arg2, arg3, arg4 );
94        }
95        else
96        {
97            return new Socket( arg1, arg2, arg3, arg4 );
98        }
99    }
100 
101    public static javax.net.SocketFactory getSocketFactory()
102    {
103        if( factory == null )
104        {
105            factory = new SSLSocketFactory();
106        }
107        return factory;
108    }
109 
110    private javax.net.ssl.SSLSocketFactory getSSLFactory()
111    {
112        if( sslFactory == null )
113        {
114            try
115            {
116                sslFactory = BogusSSLContextFactory.getInstance( false )
117                        .getSocketFactory();
118            }
119            catch( GeneralSecurityException e )
120            {
121                throw new RuntimeException( "could not create SSL socket", e );
122            }
123        }
124        return sslFactory;
125    }
126 
127    public static boolean isSslEnabled()
128    {
129        return sslEnabled;
130    }
131 
132    public static void setSslEnabled( boolean newSslEnabled )
133    {
134        sslEnabled = newSslEnabled;
135    }
136 
137}

[all classes][org.apache.mina.examples.echoserver.ssl]
EMMA 2.0.4217 (C) Vladimir Roubtsov