Skip to content
Permalink
Browse files
Merge branch 'ExtendedConnectionHelper' into 'ibm-trunk'
Extended connection helper

Add the ability to pass arbitrary arguments to an ExtendedConnectionHelper; this can be used to pass the TLS supports/requires-relevant flags to be used selecting a cipher suite.
  • Loading branch information
David Jencks committed Nov 13, 2014
2 parents 69641f3 + a40b367 commit 106683473d2b94e57fcbd9525361db9fa3224335
Show file tree
Hide file tree
Showing 7 changed files with 187 additions and 96 deletions.
@@ -20,6 +20,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import org.apache.yoko.orb.OB.Assert;
import org.apache.yoko.orb.OCI.IIOP.PLUGIN_ID;

final class AccFactory_impl extends org.omg.CORBA.LocalObject implements
@@ -37,6 +38,7 @@ final class AccFactory_impl extends org.omg.CORBA.LocalObject implements
private ConnectionHelper connectionHelper_; // client connection helper

private ListenerMap listenMap_;
private ExtendedConnectionHelper extendedConnectionHelper_;

// ------------------------------------------------------------------
// Standard IDL to Java Mapping
@@ -142,9 +144,11 @@ public org.apache.yoko.orb.OCI.Acceptor create_acceptor(String[] params)
throw new org.apache.yoko.orb.OCI.InvalidParam(
"invalid port");
i += 2;
} else {
} else if (connectionHelper_ != null){
throw new org.apache.yoko.orb.OCI.InvalidParam(
"unknown parameter: " + params[i]);
} else {
i++;
}
}

@@ -155,14 +159,7 @@ public org.apache.yoko.orb.OCI.Acceptor create_acceptor(String[] params)

logger.fine("Creating acceptor for port=" + port);

if (bind == null) {
return new Acceptor_impl(hosts, multiProfile, port, backlog,
keepAlive, connectionHelper_, listenMap_);
}
else {
return new Acceptor_impl(bind, hosts, multiProfile, port, backlog,
keepAlive, connectionHelper_, listenMap_);
}
return new Acceptor_impl(bind, hosts, multiProfile, port, backlog, keepAlive, connectionHelper_, extendedConnectionHelper_, listenMap_, params);
}

public void change_key(org.omg.IOP.IORHolder ior, byte[] key) {
@@ -233,10 +230,13 @@ public void change_key(org.omg.IOP.IORHolder ior, byte[] key) {
// Application programs must not use these functions directly
// ------------------------------------------------------------------

public AccFactory_impl(org.omg.CORBA.ORB orb, ListenerMap lm, ConnectionHelper helper) {
public AccFactory_impl(org.omg.CORBA.ORB orb, ListenerMap lm, ConnectionHelper helper, ExtendedConnectionHelper extendedHelper) {
Assert._OB_assert((helper == null) ^ (extendedHelper == null));
orb_ = orb;
info_ = new AccFactoryInfo_impl();
listenMap_ = lm;
connectionHelper_ = helper;
extendedConnectionHelper_ = extendedHelper;
}

}
@@ -21,6 +21,7 @@
import java.util.logging.Logger;

import org.apache.yoko.orb.CORBA.OutputStream;
import org.apache.yoko.orb.OB.Assert;
import org.apache.yoko.orb.OCI.IIOP.PLUGIN_ID;

final class Acceptor_impl extends org.omg.CORBA.LocalObject implements
@@ -48,6 +49,8 @@ final class Acceptor_impl extends org.omg.CORBA.LocalObject implements

private ConnectionHelper connectionHelper_; // plugin for managing connection config/creation

private ExtendedConnectionHelper extendedConnectionHelper_;

// ------------------------------------------------------------------
// Standard IDL to Java Mapping
// ------------------------------------------------------------------
@@ -190,7 +193,11 @@ public org.apache.yoko.orb.OCI.Transport connect_self() {
//
java.net.Socket socket = null;
try {
socket = connectionHelper_.createSelfConnection(localAddress_, port_);
if (connectionHelper_ != null) {
socket = connectionHelper_.createSelfConnection(localAddress_, port_);
} else {
socket = extendedConnectionHelper_.createSelfConnection(localAddress_, port_);
}
} catch (java.net.ConnectException ex) {
logger.log(Level.FINE, "Failure making self connection for host=" + localAddress_ + ", port=" + port_, ex);
throw new org.omg.CORBA.TRANSIENT(
@@ -429,81 +436,15 @@ public org.apache.yoko.orb.OCI.AcceptorInfo get_info() {
// Application programs must not use these functions directly
// ------------------------------------------------------------------

public Acceptor_impl(String[] hosts, boolean multiProfile, int port,
int backlog, boolean keepAlive, ConnectionHelper helper, ListenerMap lm) {
hosts_ = hosts;
multiProfile_ = multiProfile;
keepAlive_ = keepAlive;
connectionHelper_ = helper;
info_ = new AcceptorInfo_impl(this);
listenMap_ = lm;

if (backlog == 0)
backlog = 50; // 50 is the JDK's default value

//
// Get the local address for use by connect_self. Since we are
// binding to all network interfaces, we'll use the loopback
// address.
//
try {
localAddress_ = java.net.InetAddress.getLocalHost();
} catch (java.net.UnknownHostException ex) {
logger.log(Level.FINE, "Host resolution failure", ex);
throw (org.omg.CORBA.COMM_FAILURE)new org.omg.CORBA.COMM_FAILURE(
org.apache.yoko.orb.OB.MinorCodes
.describeCommFailure(org.apache.yoko.orb.OB.MinorCodes.MinorGethostbyname)
+ ": " + ex.getMessage(),
org.apache.yoko.orb.OB.MinorCodes.MinorGethostbyname,
org.omg.CORBA.CompletionStatus.COMPLETED_NO).initCause(ex);
}

//
// Create socket and bind to all network interfaces
//
try {
socket_ = connectionHelper_.createServerSocket(port, backlog);

//
// Read back the port. This is needed if the port was selected by
// the operating system.
//
port_ = socket_.getLocalPort();
logger.fine("Acceptor created using socket " + socket_);
} catch (java.net.BindException ex) {
logger.log(Level.FINE, "Failure creating server socket for host=" + localAddress_ + ", port=" + port, ex);
throw (org.omg.CORBA.COMM_FAILURE)new org.omg.CORBA.COMM_FAILURE(
org.apache.yoko.orb.OB.MinorCodes
.describeCommFailure(org.apache.yoko.orb.OB.MinorCodes.MinorBind)
+ ": " + ex.getMessage(),
org.apache.yoko.orb.OB.MinorCodes.MinorBind,
org.omg.CORBA.CompletionStatus.COMPLETED_NO).initCause(ex);
} catch (java.io.IOException ex) {
logger.log(Level.FINE, "Failure creating server socket for host=" + localAddress_ + ", port=" + port, ex);
throw (org.omg.CORBA.COMM_FAILURE)new org.omg.CORBA.COMM_FAILURE(
org.apache.yoko.orb.OB.MinorCodes
.describeCommFailure(org.apache.yoko.orb.OB.MinorCodes.MinorSocket)
+ ": " + ex.getMessage(),
org.apache.yoko.orb.OB.MinorCodes.MinorSocket,
org.omg.CORBA.CompletionStatus.COMPLETED_NO).initCause(ex);
}

//
// add these endpoints to the listenMap_
//
synchronized (listenMap_) {
for (int i = 0; i < hosts_.length; i++)
listenMap_.add(hosts_[i], (short) port_);
}
}

public Acceptor_impl(String address, String[] hosts, boolean multiProfile,
int port, int backlog, boolean keepAlive, ConnectionHelper helper, ListenerMap lm) {
int port, int backlog, boolean keepAlive, ConnectionHelper helper, ExtendedConnectionHelper extendedConnectionHelper, ListenerMap lm, String[] params) {
// System.out.println("Acceptor_impl");
Assert._OB_assert((helper == null) ^ (extendedConnectionHelper == null));
hosts_ = hosts;
multiProfile_ = multiProfile;
keepAlive_ = keepAlive;
connectionHelper_ = helper;
extendedConnectionHelper_ = extendedConnectionHelper;
info_ = new AcceptorInfo_impl(this);
listenMap_ = lm;

@@ -514,7 +455,14 @@ public Acceptor_impl(String address, String[] hosts, boolean multiProfile,
// Get the local address for use by connect_self
//
try {
localAddress_ = java.net.InetAddress.getByName(address);
if (address == null) {
//Since we are
// binding to all network interfaces, we'll use the loopback
// address.
localAddress_ = java.net.InetAddress.getLocalHost();
} else {
localAddress_ = java.net.InetAddress.getByName(address);
}
} catch (java.net.UnknownHostException ex) {
logger.log(Level.FINE, "Host resolution failure", ex);
throw (org.omg.CORBA.COMM_FAILURE)new org.omg.CORBA.COMM_FAILURE(
@@ -529,7 +477,19 @@ public Acceptor_impl(String address, String[] hosts, boolean multiProfile,
// Create socket and bind to requested network interface
//
try {
socket_ = connectionHelper_.createServerSocket(port, backlog, localAddress_);
if (address == null) {
if (connectionHelper_ != null) {
socket_ = connectionHelper_.createServerSocket(port, backlog);
} else {
socket_ = extendedConnectionHelper_.createServerSocket(port, backlog, params);
}
} else {
if (connectionHelper_ != null) {
socket_ = connectionHelper_.createServerSocket(port, backlog, localAddress_);
} else {
socket_ = extendedConnectionHelper_.createServerSocket(port, backlog, localAddress_, params);
}
}

//
// Read back the port. This is needed if the port was selected by
@@ -37,6 +37,8 @@ final class ConFactory_impl extends org.omg.CORBA.LocalObject implements

private ConnectionHelper connectionHelper_; // plugin for making ssl transport decisions.

private ExtendedConnectionHelper extendedConnectionHelper_;

// ------------------------------------------------------------------
// Standard IDL to Java Mapping
// ------------------------------------------------------------------
@@ -150,9 +152,15 @@ public org.apache.yoko.orb.OCI.Connector[] create_connectors(
org.apache.yoko.orb.OCI.ConnectCB[] cbs = info_
._OB_getConnectCBSeq();
logger.fine("Creating connector to host=" + body.host +", port=" + port);
seq.addElement(new Connector_impl(ior, policies, body.host, port, keepAlive_,
cbs, listenMap_, connectionHelper_));

if (connectionHelper_ != null) {
seq.addElement(new Connector_impl(ior, policies, body.host,
port, keepAlive_, cbs, listenMap_,
connectionHelper_));
} else {
seq.addElement(new Connector_impl(ior, policies, body.host,
port, keepAlive_, cbs, listenMap_,
extendedConnectionHelper_));
}
//
// If this is a 1.1 profile, check for
// TAG_ALTERNATE_IIOP_ADDRESS in the components
@@ -232,6 +240,15 @@ public ConFactory_impl(org.omg.CORBA.ORB orb, boolean keepAlive, ListenerMap lm,
connectionHelper_ = helper;
}

public ConFactory_impl(org.omg.CORBA.ORB orb, boolean keepAlive, ListenerMap lm, ExtendedConnectionHelper helper) {
// System.out.println("ConFactory");
orb_ = orb;
keepAlive_ = keepAlive;
info_ = new ConFactoryInfo_impl();
listenMap_ = lm;
extendedConnectionHelper_ = helper;
}

public void finalize() throws Throwable {
// System.out.println("~ConFactory");
super.finalize();
@@ -56,6 +56,8 @@ final class Connector_impl extends org.omg.CORBA.LocalObject implements

private byte[] transportInfo;

private ExtendedConnectionHelper extendedConnectionHelper_;


// ------------------------------------------------------------------
// Private and protected functions
@@ -117,7 +119,11 @@ public org.apache.yoko.orb.OCI.Transport connect() {
//
try {
logger.fine("Connecting to host=" + address + ", port=" + port_);
socket_ = connectionHelper_.createSocket(ior_, policies_, address, port_);
if (connectionHelper_ != null) {
socket_ = connectionHelper_.createSocket(ior_, policies_, address, port_);
} else {
socket_ = extendedConnectionHelper_.createSocket(ior_, policies_, address, port_);
}
logger.fine("Connection created with socket " + socket_);
} catch (java.net.ConnectException ex) {
logger.log(Level.FINE, "Error connecting to host=" + address + ", port=" + port_, ex);
@@ -213,7 +219,11 @@ private class ConnectTimeout extends Thread {

public void run() {
try {
so_ = connectionHelper_.createSocket(ior_, policies_, address_, port_);
if (connectionHelper_ != null) {
so_ = connectionHelper_.createSocket(ior_, policies_, address_, port_);
} else {
so_ = extendedConnectionHelper_.createSocket(ior_, policies_, address_, port_);
}
} catch (java.io.IOException ex) {
logger.log(Level.FINE, "Socket creation error", ex);
ex_ = ex;
@@ -491,6 +501,20 @@ public Connector_impl(org.omg.IOP.IOR ior, org.omg.CORBA.Policy[] policies, Stri
transportInfo = extractTransportInfo(ior);
}

public Connector_impl(org.omg.IOP.IOR ior, org.omg.CORBA.Policy[] policies, String host, int port, boolean keepAlive,
org.apache.yoko.orb.OCI.ConnectCB[] cb, ListenerMap lm, ExtendedConnectionHelper helper) {
// System.out.println("Connector_impl");
ior_ = ior;
policies_ = policies;
host_ = host;
port_ = port;
keepAlive_ = keepAlive;
info_ = new ConnectorInfo_impl(this, cb);
listenMap_ = lm;
extendedConnectionHelper_ = helper;
transportInfo = extractTransportInfo(ior);
}

public void finalize() throws Throwable {
// System.out.println("~Connector_impl");
if (socket_ != null)
@@ -0,0 +1,61 @@
/**
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


/**
* @version $Rev: 491396 $ $Date: 2006-12-30 22:06:13 -0800 (Sat, 30 Dec 2006) $
*/

package org.apache.yoko.orb.OCI.IIOP;

import java.io.IOException;
import java.net.ConnectException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.ServerSocket;

import org.omg.CORBA.ORB;
import org.omg.CORBA.Policy;
import org.omg.IOP.IOR;

//
// IDL:orb.yoko.apache.org/OCI/IIOP/AcceptorInfo:1.0
//
/**
*
* Information on an IIOP OCI Acceptor object.
*
* @see Acceptor
* @see AcceptorInfo
*
**/

public interface ExtendedConnectionHelper
{
public void init(ORB orb, String parms);

public Socket createSocket(IOR ior, Policy[] policies, InetAddress address, int port) throws IOException, ConnectException;

public Socket createSelfConnection(InetAddress address, int port) throws IOException, ConnectException;

public ServerSocket createServerSocket(int port, int backlog, String[] params) throws IOException, ConnectException;

public ServerSocket createServerSocket(int port, int backlog, InetAddress address, String[] params) throws IOException, ConnectException;

}

0 comments on commit 1066834

Please sign in to comment.