001: /*
002: * JacORB - a free Java ORB
003: *
004: * Copyright (C) 1997-2004 Gerald Brose.
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Library General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Library General Public License for more details.
015: *
016: * You should have received a copy of the GNU Library General Public
017: * License along with this library; if not, write to the Free
018: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
019: */
020:
021: package org.jacorb.orb.giop;
022:
023: import org.jacorb.orb.*;
024: import org.jacorb.orb.portableInterceptor.*;
025:
026: import org.omg.PortableInterceptor.*;
027: import org.omg.IOP.*;
028: import org.omg.IIOP.*;
029:
030: /**
031: * @author Nicolas Noffke
032: * @version $Id: BiDirConnectionClientInterceptor.java,v 1.12 2006/07/11 11:48:22 alphonse.bendt Exp $
033: */
034: public class BiDirConnectionClientInterceptor extends
035: DefaultClientInterceptor {
036: private static final String name = "BiDirConnectionClientInterceptor";
037:
038: private final ORB orb;
039:
040: private ServiceContext bidir_ctx = null;
041:
042: public BiDirConnectionClientInterceptor(ORB orb) {
043: this .orb = orb;
044: }
045:
046: public String name() {
047: return name;
048: }
049:
050: public void destroy() {
051: // nothing to do
052: }
053:
054: public void send_request(ClientRequestInfo ri)
055: throws ForwardRequest {
056: //only send a BiDir service context if our orb allows it, and
057: //the connection was initiated in this process
058:
059: if (orb.useBiDirGIOP()
060: && ((ClientRequestInfoImpl) ri).connection
061: .isClientInitiated()) {
062: if (bidir_ctx == null) {
063: BasicAdapter ba = orb.getBasicAdapter();
064:
065: ListenPoint lp = new ListenPoint(ba.getAddress(),
066: (short) ba.getPort());
067:
068: ListenPoint[] points = null;
069: if (ba.hasSSLListener()) {
070: ListenPoint ssl_lp = new ListenPoint(ba
071: .getAddress(), (short) ba.getSSLPort());
072:
073: points = new ListenPoint[] { lp, ssl_lp };
074: } else {
075: points = new ListenPoint[] { lp };
076: }
077:
078: BiDirIIOPServiceContext b = new BiDirIIOPServiceContext(
079: points);
080: org.omg.CORBA.Any any = orb.create_any();
081: BiDirIIOPServiceContextHelper.insert(any, b);
082:
083: final CDROutputStream cdr_out = new CDROutputStream(orb);
084:
085: try {
086: cdr_out.beginEncapsulatedArray();
087: BiDirIIOPServiceContextHelper.write(cdr_out, b);
088:
089: bidir_ctx = new ServiceContext(BI_DIR_IIOP.value,
090: cdr_out.getBufferCopy());
091: } finally {
092: cdr_out.close();
093: }
094: }
095:
096: ri.add_request_service_context(bidir_ctx, true);
097:
098: //if this connection isn't "bidir'ed" yet, do so now
099: GIOPConnection conn = ((ClientRequestInfoImpl) ri).connection
100: .getGIOPConnection();
101: if (conn.getRequestListener() instanceof NoBiDirClientRequestListener) {
102: conn.setRequestListener(orb.getBasicAdapter()
103: .getRequestListener());
104: }
105: }
106: }
107: }
|