KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > orb > giop > BiDirConnectionClientInterceptor


1 /*
2  * JacORB - a free Java ORB
3  *
4  * Copyright (C) 1997-2004 Gerald Brose.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */

20
21 package org.jacorb.orb.giop;
22
23 import org.jacorb.orb.*;
24 import org.jacorb.orb.portableInterceptor.*;
25
26 import org.omg.PortableInterceptor.*;
27 import org.omg.IOP.Codec JavaDoc;
28 import org.omg.IOP.*;
29 import org.omg.IIOP.*;
30
31 /**
32  * @author Nicolas Noffke
33  * @version $Id: BiDirConnectionClientInterceptor.java,v 1.9 2004/05/06 12:40:00 nicolas Exp $
34  */

35
36 public class BiDirConnectionClientInterceptor
37     extends DefaultClientInterceptor
38 {
39     private String JavaDoc name = "BiDirConnectionClientInterceptor";
40
41     private Codec JavaDoc codec = null;
42     private ORB orb = null;
43
44     private ServiceContext bidir_ctx = null;
45
46     public BiDirConnectionClientInterceptor( ORB orb, Codec JavaDoc codec )
47     {
48         this.orb = orb;
49         this.codec = codec;
50     }
51
52     public String JavaDoc name()
53     {
54         return name;
55     }
56
57     public void destroy()
58     {
59     }
60
61     public void send_request( ClientRequestInfo ri )
62         throws ForwardRequest
63     {
64         //only send a BiDir service context if our orb allows it, and
65
//the connection was initiated in this process
66

67         if( orb.useBiDirGIOP() &&
68             ((ClientRequestInfoImpl) ri).connection.isClientInitiated() )
69         {
70             if( bidir_ctx == null )
71             {
72                 BasicAdapter ba = orb.getBasicAdapter();
73                 
74                 ListenPoint lp = new ListenPoint( ba.getAddress(),
75                                                   (short) ba.getPort() );
76
77                 ListenPoint[] points = null;
78                 if( ba.hasSSLListener() )
79                 {
80                     ListenPoint ssl_lp =
81                         new ListenPoint( ba.getAddress(),
82                                          (short) ba.getSSLPort() );
83
84                     points = new ListenPoint[]{ lp, ssl_lp };
85                 }
86                 else
87                 {
88                     points = new ListenPoint[]{ lp };
89                 }
90
91                 BiDirIIOPServiceContext b =
92                     new BiDirIIOPServiceContext( points );
93                 org.omg.CORBA.Any JavaDoc any = orb.create_any();
94                 BiDirIIOPServiceContextHelper.insert( any, b );
95                 
96                 CDROutputStream cdr_out = new CDROutputStream();
97
98                 cdr_out.beginEncapsulatedArray();
99                 BiDirIIOPServiceContextHelper.write( cdr_out, b );
100
101                 bidir_ctx = new ServiceContext( BI_DIR_IIOP.value,
102                                                 cdr_out.getBufferCopy() );
103             }
104             
105             ri.add_request_service_context( bidir_ctx, true );
106
107             //if this connection isn't "bidir'ed" yet, do so now
108
GIOPConnection conn = ((ClientRequestInfoImpl) ri).connection.getGIOPConnection();
109             if(conn.getRequestListener() instanceof
110                NoBiDirClientRequestListener)
111             {
112                 conn.setRequestListener(orb.getBasicAdapter().getRequestListener());
113             }
114         }
115     }
116 } // BiDirConnectionClientInterceptor
117

118
Popular Tags