Search in sources :

Example 6 with DBWHandlerConfiguration

use of org.jkiss.dbeaver.model.net.DBWHandlerConfiguration in project dbeaver by serge-rider.

the class ConnectionPageNetwork method createHandlerTab.

private void createHandlerTab(final NetworkHandlerDescriptor descriptor) throws DBException {
    IObjectPropertyConfigurator<DBWHandlerConfiguration> configurator;
    try {
        configurator = descriptor.createConfigurator();
    } catch (DBException e) {
        log.error("Can't create network configurator '" + descriptor.getId() + "'", e);
        return;
    }
    TabItem tabItem = new TabItem(handlersFolder, SWT.NONE);
    tabItem.setText(descriptor.getLabel());
    tabItem.setToolTipText(descriptor.getDescription());
    Composite composite = new Composite(handlersFolder, SWT.NONE);
    tabItem.setControl(composite);
    composite.setLayout(new GridLayout(1, false));
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    final Button useHandlerCheck = UIUtils.createCheckbox(composite, NLS.bind(CoreMessages.dialog_tunnel_checkbox_use_handler, descriptor.getLabel()), false);
    useHandlerCheck.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            HandlerBlock handlerBlock = configurations.get(descriptor);
            DBWHandlerConfiguration handlerConfiguration = handlerBlock.loadedConfigs.get(wizard.getPageSettings().getActiveDataSource().getId());
            handlerConfiguration.setEnabled(useHandlerCheck.getSelection());
            enableHandlerContent(descriptor);
        }
    });
    Composite handlerComposite = UIUtils.createPlaceholder(composite, 1);
    configurations.put(descriptor, new HandlerBlock(configurator, handlerComposite, useHandlerCheck, tabItem));
    handlerComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
    configurator.createControl(handlerComposite);
}
Also used : DBException(org.jkiss.dbeaver.DBException) TabItem(org.eclipse.swt.widgets.TabItem) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) DBWHandlerConfiguration(org.jkiss.dbeaver.model.net.DBWHandlerConfiguration) Button(org.eclipse.swt.widgets.Button) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 7 with DBWHandlerConfiguration

use of org.jkiss.dbeaver.model.net.DBWHandlerConfiguration in project dbeaver by serge-rider.

the class ConnectionPageNetwork method saveConfigurations.

void saveConfigurations(DataSourceDescriptor dataSource) {
    boolean foundHandlers = false;
    java.util.List<DBWHandlerConfiguration> handlers = new ArrayList<>();
    for (HandlerBlock handlerBlock : configurations.values()) {
        DBWHandlerConfiguration configuration = handlerBlock.loadedConfigs.get(dataSource.getId());
        if (configuration != null) {
            foundHandlers = true;
            handlerBlock.configurator.saveSettings(configuration);
            handlers.add(configuration);
        }
    }
    if (foundHandlers) {
        dataSource.getConnectionConfiguration().setHandlers(handlers);
    }
}
Also used : DBWHandlerConfiguration(org.jkiss.dbeaver.model.net.DBWHandlerConfiguration) ArrayList(java.util.ArrayList)

Example 8 with DBWHandlerConfiguration

use of org.jkiss.dbeaver.model.net.DBWHandlerConfiguration in project dbeaver by serge-rider.

the class ConnectionPageNetwork method enableHandlerContent.

protected void enableHandlerContent(NetworkHandlerDescriptor descriptor) {
    HandlerBlock handlerBlock = configurations.get(descriptor);
    DBWHandlerConfiguration handlerConfiguration = handlerBlock.loadedConfigs.get(wizard.getPageSettings().getActiveDataSource().getId());
    handlerBlock.useHandlerCheck.setSelection(handlerConfiguration.isEnabled());
    if (handlerConfiguration.isEnabled()) {
        if (handlerBlock.blockEnableState != null) {
            handlerBlock.blockEnableState.restore();
            handlerBlock.blockEnableState = null;
        }
    } else if (handlerBlock.blockEnableState == null) {
        handlerBlock.blockEnableState = ControlEnableState.disable(handlerBlock.blockControl);
    }
}
Also used : DBWHandlerConfiguration(org.jkiss.dbeaver.model.net.DBWHandlerConfiguration)

Example 9 with DBWHandlerConfiguration

use of org.jkiss.dbeaver.model.net.DBWHandlerConfiguration in project dbeaver by serge-rider.

the class GlobalProxySelector method select.

@Override
public List<Proxy> select(URI uri) {
    String scheme = uri.getScheme();
    if (CommonUtils.isEmpty(scheme)) {
        return parent.select(uri);
    }
    if (scheme.startsWith("http")) {
    // 1. Check for drivers download proxy
    }
    if (SocksConstants.SOCKET_SCHEME.equals(scheme)) {
        // 2. Check for connections' proxy config
        DBCExecutionContext activeContext = DBExecUtils.findConnectionContext(uri.getHost(), uri.getPort(), uri.getPath());
        if (activeContext != null) {
            List<Proxy> proxies = null;
            DBPDataSourceContainer container = activeContext.getDataSource().getContainer();
            for (DBWHandlerConfiguration networkHandler : container.getConnectionConfiguration().getDeclaredHandlers()) {
                if (networkHandler.isEnabled() && networkHandler.getType() == DBWHandlerType.PROXY) {
                    Map<String, String> proxyProps = networkHandler.getProperties();
                    String proxyHost = proxyProps.get(SocksConstants.PROP_HOST);
                    String proxyPort = proxyProps.get(SocksConstants.PROP_PORT);
                    if (!CommonUtils.isEmpty(proxyHost)) {
                        int portNumber = SocksConstants.DEFAULT_SOCKS_PORT;
                        if (!CommonUtils.isEmpty(proxyPort)) {
                            try {
                                portNumber = Integer.parseInt(proxyPort);
                            } catch (NumberFormatException e) {
                                log.warn("Bad proxy port number", e);
                            }
                        }
                        InetSocketAddress proxyAddr = new InetSocketAddress(proxyHost, portNumber);
                        Proxy proxy = new Proxy(Proxy.Type.SOCKS, proxyAddr);
                        if (proxies == null) {
                            proxies = new ArrayList<>();
                        }
                        proxies.add(proxy);
                        log.debug("Use SOCKS proxy [" + proxyAddr + "]");
                    }
                }
            }
            if (proxies != null) {
                return proxies;
            }
        }
    }
    return parent.select(uri);
}
Also used : DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBWHandlerConfiguration(org.jkiss.dbeaver.model.net.DBWHandlerConfiguration) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Aggregations

DBWHandlerConfiguration (org.jkiss.dbeaver.model.net.DBWHandlerConfiguration)9 DBException (org.jkiss.dbeaver.DBException)5 SQLException (java.sql.SQLException)2 Composite (org.eclipse.swt.widgets.Composite)2 TabItem (org.eclipse.swt.widgets.TabItem)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)1 DBPConnectionBootstrap (org.jkiss.dbeaver.model.connection.DBPConnectionBootstrap)1 DBPConnectionConfiguration (org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration)1 DBPConnectionEventType (org.jkiss.dbeaver.model.connection.DBPConnectionEventType)1 DBCException (org.jkiss.dbeaver.model.exec.DBCException)1 DBCExecutionContext (org.jkiss.dbeaver.model.exec.DBCExecutionContext)1