Establish network connection to remote mBean server.
@return
558698
private MBeanServerConnection getNetworkConnection() {
        try {
            JMXServiceURL url = new JMXServiceURL(getEndpointConfiguration().getServerUrl());
            String[] creds = {getEndpointConfiguration().getUsername(), getEndpointConfiguration().getPassword()};
            JMXConnector networkConnector = JMXConnectorFactory.connect(url, Collections.singletonMap(JMXConnector.CREDENTIALS, creds));
            connectionId = networkConnector.getConnectionId();

            networkConnector.addConnectionNotificationListener(this, null, null);
            return networkConnector.getMBeanServerConnection();
        } catch (IOException e) {
            throw new CitrusRuntimeException("Failed to connect to network MBean server", e);
        }
    }
760582
public Connection connect() throws IOException {
        Connection connection;
        synchronized (this) {
            if(shutdown) throw ProtocolLogger.ROOT_LOGGER.channelClosed();
            connection = this.connection;
            if(connection == null) {
                connection = connectTask.connect();
                if(connection == null) {
                    throw ProtocolLogger.ROOT_LOGGER.channelClosed();
                }
                boolean ok = false;
                try {
                    // Connection opened notification
                    final ConnectionOpenHandler openHandler = connectTask.getConnectionOpenedHandler();
                    openHandler.connectionOpened(connection);
                    ok = true;
                    this.connection = connection;
                    connection.addCloseHandler(new CloseHandler<Connection>() {
                        @Override
                        public void handleClose(Connection closed, IOException exception) {
                            onConnectionClose(closed);
                        }
                    });
                } finally {
                    if(!ok) {
                        StreamUtils.safeClose(connection);
                    }
                }
            }
        }
        return connection;
    }
57755
public ServerSocket createServerSocket() throws IOException {
        final ServerSocket socket = getServerSocketFactory().createServerSocket(name);
        socket.bind(getSocketAddress());
        return socket;
    }
1114875
public Connection createDBConnection() {
        if (mDBConnInfo != null) {
            return getConnectionViaDriverMangaer(mDBConnInfo.DBDriver, mDBConnInfo.DBUrl, mDBConnInfo.DBUser, mDBConnInfo.DBPassword);
        } else {
            return null;
        }
    }
598537
private MBeanServerConnection createServerConnection(String host, int port) throws IOException {
            jmxServiceURL = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/jmxrmi");
            JMXConnector jmxc = JMXConnectorFactory.connect(jmxServiceURL, null);
            return jmxc.getMBeanServerConnection();            
    }
1268978
@Override
    protected Object createPoolOrConnection()
    {
        try
        {
            this.connection = ConnectionFactory.createConnection(conf);
            return connection;
        }
        catch (IOException e)
        {
            logger.error("Connection could not be established", e);
            throw new KunderaException("Connection could not be established", e);
        }
    }
204071
protected Connection createConnection(Dsn dsn) {
        String protocol = dsn.getProtocol();
        Connection connection;

        if (protocol.equalsIgnoreCase("http") || protocol.equalsIgnoreCase("https")) {
            logger.debug("Using an {} connection to Sentry.", protocol.toUpperCase());
            connection = createHttpConnection(dsn);
        } else if (protocol.equalsIgnoreCase("out")) {
            logger.debug("Using StdOut to send events.");
            connection = createStdOutConnection(dsn);
        } else if (protocol.equalsIgnoreCase("noop")) {
            logger.debug("Using noop to send events.");
            connection = new NoopConnection();
        } else {
            throw new IllegalStateException("Couldn't create a connection for the protocol '" + protocol + "'");
        }

        BufferedConnection bufferedConnection = null;
        if (getBufferEnabled(dsn)) {
            Buffer eventBuffer = getBuffer(dsn);
            if (eventBuffer != null) {
                long flushtime = getBufferFlushtime(dsn);
                boolean gracefulShutdown = getBufferedConnectionGracefulShutdownEnabled(dsn);
                Long shutdownTimeout = getBufferedConnectionShutdownTimeout(dsn);
                bufferedConnection = new BufferedConnection(connection, eventBuffer, flushtime, gracefulShutdown,
                    shutdownTimeout);
                connection = bufferedConnection;
            }
        }

        // Enable async unless its value is 'false'.
        if (getAsyncEnabled(dsn)) {
            connection = createAsyncConnection(dsn, connection);
        }

        // If buffering is enabled, wrap connection with synchronous disk buffering "connection"
        if (bufferedConnection != null) {
            connection = bufferedConnection.wrapConnectionWithBufferWriter(connection);
        }

        return connection;
    }
730094
protected void remoteInit() throws JMSException
    {
        CreateBrowserQuery query = new CreateBrowserQuery();
        query.setBrowserId(id);
        query.setSessionId(session.getId());
        query.setQueue(queue);
        query.setMessageSelector(messageSelector);
        transportEndpoint.blockingRequest(query);
    }
703101
public ServerBase build()
  {
    EnvLoader.init();
    
    SystemManager systemManager = createSystemManager();
    
    Thread thread = Thread.currentThread();
    ClassLoader oldLoader = thread.getContextClassLoader();
    
    boolean isValid = false;
    try {
      thread.setContextClassLoader(systemManager.getClassLoader());
      
      Vfs.setPwd(getRootDirectory());
      
      if (! isEmbedded()) {
        logCopyright();
      }

      preConfigureInit();
      
      configureRootDirectory();
      
      _serverSelf = initNetwork();
      Objects.requireNonNull(_serverSelf);
      
      addServices(_serverSelf);

      initHttpSystem(systemManager, _serverSelf);
      
      ServerBase server = build(systemManager,
                                _serverSelf);

      init(server);
      
      isValid = true;
      
      systemManager.start();
      
      return server;
    } catch (RuntimeException e) {
      throw e;
    } catch (Exception e) {
      throw ConfigException.wrap(e);
    } finally {
      thread.setContextClassLoader(oldLoader);
      
      if (! isValid) {
        systemManager.shutdown(ShutdownModeAmp.IMMEDIATE);
      }
    }
  }
94493
@Override
	public Socket connect(final String sessionId, final InetAddress remoteServerAddress, final int remoteServerPort)
			throws IOException {
		return proxyConfig.requiresAuthentication() ?
				createSocketAuthenticated(sessionId, remoteServerAddress, remoteServerPort) :
				createSocketPlainAnonymous(sessionId, remoteServerAddress, remoteServerPort);
	}
505996
private HttpURLConnection createConnection() {
        String urlString = getRequestInfo().getRequestUrl().toString();
        if( getRequestInfo().requestMethod == null ) {
            throw new KieServerHttpRequestException("Please specify (and execute?) a HTTP method first.");
        }
        try {
            final HttpURLConnection connection;
            if( this.httpProxyHost != null ) {
                Proxy proxy = new Proxy(HTTP, new InetSocketAddress(this.httpProxyHost, this.httpProxyPort));
                connection = CONNECTION_FACTORY.create(getRequestInfo().getRequestUrl(), proxy);
            } else {
                connection = CONNECTION_FACTORY.create(getRequestInfo().getRequestUrl());
            }
            // support for localhost and https
            if (getRequestInfo().getRequestUrl().getProtocol().equalsIgnoreCase("https") && getRequestInfo().getRequestUrl().getHost().equalsIgnoreCase("localhost")) {
                ((HttpsURLConnection) connection).setHostnameVerifier(new HostnameVerifier(){

                    public boolean verify(String hostname, javax.net.ssl.SSLSession sslSession) {
                        if (hostname.equalsIgnoreCase("localhost")) {
                            return true;
                        }
                        return false;
                    }
                });
            }

            connection.setRequestMethod(getRequestInfo().requestMethod);
            return connection;
        } catch( IOException ioe ) {
            throw new KieServerHttpRequestException("Unable to create (" + getRequestInfo().requestMethod + ") connection to '"
                    + urlString + "'", ioe);
        }
    }
559493
@Override
	public final MBeanInfo getMBeanInfo() {
		final MBeanOperationInfo[] opers = createMBeanOperationInfo();
		return new MBeanInfo(remoteProgram.getAdapterClass().getCanonicalName(), null, null, null, opers, null);
	}
220223
Collection<MBeanServer> getMBeanServers() {
        Collection<MBeanServer> mbeanServers = new HashSet<MBeanServer>();
        mbeanServers.add(ManagementFactory.getPlatformMBeanServer());
        mbeanServers.addAll(MBeanServerFactory.findMBeanServer(null));
        return mbeanServers;
    }
1249244
void establishConnection () throws IOException {
        synchronized (operationOnConnectionMonitor) {
            if (state == State.CLOSED) {
                throw new IOException("Attempt to establish a connection with a closed connection factory");
            } else if (state == State.CONNECTED) {
                LOGGER.warn("Establishing new connection although a connection is already established");
            }
            try {
                LOGGER.info("Trying to establish connection to {}:{}", getHost(), getPort());
                connection = super.newConnection(executorService);
                connection.addShutdownListener(connectionShutdownListener);
                LOGGER.info("Established connection to {}:{}", getHost(), getPort());
                changeState(State.CONNECTED);
            } catch (IOException e) {
                LOGGER.error("Failed to establish connection to {}:{}", getHost(), getPort());
                throw e;
            }
        }
    }
182032
public static ServerConnector createSocketConnector(Server server, String host, int port) {
        Assert.notNull(server, "'server' must not be null");
        Assert.notNull(host, "'host' must not be null");

        HttpConnectionFactory httpConnectionFactory = createHttpConnectionFactory();
        ServerConnector connector = new ServerConnector(server, httpConnectionFactory);
        initializeConnector(connector, host, port);
        return connector;
    }
1000941
private ServerConnector configureConnector() {
        ServerConnector connector = null;
        if (m_tls) {
            connector = createSSLConnector();
        } else {
            // Unsecured connector
            connector = new ServerConnector(m_jettyServer);
        }
        if (m_restaddr != null) {
            connector.setHost(m_restaddr);
        }
        connector.setPort(m_restport);
        connector.setIdleTimeout(SOCKET_TIMEOUT_MILLIS);
        connector.addBean(new ConnListener());  // invokes registered callbacks, if any
        return connector;
    }
1061986
@Override
  public String getRemoteHost()
  {
    if (_remoteName == null) {
      byte []remoteAddrBuffer = _remoteAddrBuffer;
      char []remoteAddrCharBuffer = _remoteAddrCharBuffer;

      if (_remoteAddrLength <= 0) {
        _remoteAddrLength = InetAddressUtil.createIpAddress(remoteAddrBuffer,
                                            remoteAddrCharBuffer);
      }

      _remoteName = new String(remoteAddrCharBuffer, 0, _remoteAddrLength);
    }

    return _remoteName;
  }