Esempio n. 1
0
  @Override
  @SuppressWarnings("unchecked")
  protected void okPressed() {
    String portName = textPortName.getText().trim();
    int supportedFamily = 0;
    for (Iterator<Integer> i = ((IStructuredSelection) familyList.getSelection()).iterator();
        i.hasNext(); ) supportedFamily |= i.next();

    IConnection conn = null;

    IConnectionPolicy policy =
        client
            .getConnectionPolicyFactory()
            .createPolicy(
                client,
                portName,
                supportedFamily,
                (Integer) ((IStructuredSelection) familyList.getSelection()).getFirstElement(),
                null,
                null,
                null);
    try {
      if (chkUdp.getSelection()) {
        switch (comboProxyType.getSelectionIndex()) {
          case 0:
            conn =
                client
                    .getConnectionPool()
                    .newUDPConnection(
                        policy,
                        new InetSocketAddress(
                            textServerAddress.getText().trim(),
                            Util.getInt(textServerPort.getText().trim(), 0)),
                        true);
            break;
          case 2:
            policy.setProxy(
                new InetSocketAddress(
                    textProxyAddress.getText().trim(),
                    Util.getInt(textProxyPort.getText().trim(), 0)));
            policy.setProxyUsername(textUsername.getText().trim());
            policy.setProxyPassword(textPassword.getText());
            conn =
                client
                    .getConnectionPool()
                    .newUDPSocks5Connection(
                        policy,
                        new InetSocketAddress(
                            textServerAddress.getText().trim(),
                            Util.getInt(textServerPort.getText().trim(), 0)),
                        true);
            break;
        }
      } else {
        switch (comboProxyType.getSelectionIndex()) {
          case 0:
            conn =
                client
                    .getConnectionPool()
                    .newTCPConnection(
                        policy,
                        new InetSocketAddress(
                            textServerAddress.getText().trim(),
                            Util.getInt(textServerPort.getText().trim(), 0)),
                        true);
            break;
          case 1:
            policy.setProxy(
                new InetSocketAddress(
                    textProxyAddress.getText().trim(),
                    Util.getInt(textProxyPort.getText().trim(), 0)));
            policy.setProxyUsername(textUsername.getText().trim());
            policy.setProxyPassword(textPassword.getText());
            conn =
                client
                    .getConnectionPool()
                    .newTCPHttpConnection(
                        policy,
                        new InetSocketAddress(
                            textServerAddress.getText().trim(),
                            Util.getInt(textServerPort.getText().trim(), 0)),
                        true);
            break;
          case 2:
            policy.setProxy(
                new InetSocketAddress(
                    textProxyAddress.getText().trim(),
                    Util.getInt(textProxyPort.getText().trim(), 0)));
            policy.setProxyUsername(textUsername.getText().trim());
            policy.setProxyPassword(textPassword.getText());
            conn =
                client
                    .getConnectionPool()
                    .newTCPSocks5Connection(
                        policy,
                        new InetSocketAddress(
                            textServerAddress.getText().trim(),
                            Util.getInt(textServerPort.getText().trim(), 0)),
                        true);
            break;
        }
      }
    } catch (UnresolvedAddressException e) {
      conn = null;
    }

    if (conn == null) MessageDialog.openError(getShell(), "Failed", "Create connection failed");
    else super.okPressed();
  }