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.omg.PortableInterceptor.*;
024: import org.omg.IIOP.*;
025: import org.omg.IOP.*;
026:
027: import org.jacorb.orb.*;
028: import org.jacorb.orb.iiop.*;
029: import org.jacorb.orb.portableInterceptor.*;
030:
031: import org.apache.avalon.framework.logger.*;
032:
033: /**
034: * @author Nicolas Noffke
035: * @version $Id: BiDirConnectionServerInterceptor.java,v 1.15 2006/06/28 12:41:43 alphonse.bendt Exp $
036: */
037: public class BiDirConnectionServerInterceptor extends
038: DefaultServerInterceptor {
039: private static final String NAME = "BiDirConnectionServerInterceptor";
040:
041: private final ORB orb;
042: private final Logger logger;
043: private final ClientConnectionManager conn_mg;
044:
045: protected BiDirConnectionServerInterceptor(ORB orb) {
046: super ();
047:
048: this .orb = orb;
049: this .logger = orb.getConfiguration().getNamedLogger(
050: "jacorb.giop.bidir.interceptor");
051: conn_mg = orb.getClientConnectionManager();
052: }
053:
054: public String name() {
055: return NAME;
056: }
057:
058: public void destroy() {
059: // nothing to do
060: }
061:
062: public void receive_request_service_contexts(
063: ServerRequestInfo requestInfo) throws ForwardRequest {
064: if (orb.useBiDirGIOP()) {
065: try {
066: final ServiceContext context = requestInfo
067: .get_request_service_context(BI_DIR_IIOP.value);
068: addConnections(requestInfo, context);
069: } catch (org.omg.CORBA.BAD_PARAM e) {
070: logger.debug("no BiDir context present");
071: }
072: }
073: }
074:
075: private void addConnections(ServerRequestInfo requestInfo,
076: ServiceContext ctx) {
077: final BiDirIIOPServiceContext bidir_ctx = readBiDirContext(ctx);
078:
079: GIOPConnection connection = ((ServerRequestInfoImpl) requestInfo).request
080: .getConnection();
081:
082: for (int i = 0; i < bidir_ctx.listen_points.length; i++) {
083: ListenPoint listenPoint = bidir_ctx.listen_points[i];
084:
085: IIOPAddress addr = new IIOPAddress(listenPoint.host,
086: listenPoint.port);
087:
088: if (logger.isDebugEnabled()) {
089: logger.debug("Client conn. added to target " + addr);
090: }
091:
092: conn_mg.addConnection(connection, new IIOPProfile(addr,
093: null));
094: }
095: }
096:
097: private BiDirIIOPServiceContext readBiDirContext(ServiceContext ctx) {
098: final CDRInputStream cdr_in = new CDRInputStream(orb,
099: ctx.context_data);
100:
101: try {
102: cdr_in.openEncapsulatedArray();
103:
104: return BiDirIIOPServiceContextHelper.read(cdr_in);
105: } finally {
106: cdr_in.close();
107: }
108: }
109: }
|