Beispiel #1
0
  public static void main(String[] args) throws Exception {

    System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol");
    /**
     * This test does not establish any connection to the specified URL, hence a dummy URL is used.
     */
    URL foobar = new URL("https://example.com/");

    HttpsURLConnection urlc = (HttpsURLConnection) foobar.openConnection();

    try {
      urlc.getCipherSuite();
    } catch (IllegalStateException e) {
      System.out.print("Caught proper exception: ");
      System.out.println(e.getMessage());
    }

    try {
      urlc.getServerCertificateChain();
    } catch (IllegalStateException e) {
      System.out.print("Caught proper exception: ");
      System.out.println(e.getMessage());
    }

    try {
      urlc.setDefaultHostnameVerifier(null);
    } catch (IllegalArgumentException e) {
      System.out.print("Caught proper exception: ");
      System.out.println(e.getMessage());
    }

    try {
      urlc.setHostnameVerifier(null);
    } catch (IllegalArgumentException e) {
      System.out.print("Caught proper exception: ");
      System.out.println(e.getMessage());
    }

    try {
      urlc.setDefaultSSLSocketFactory(null);
    } catch (IllegalArgumentException e) {
      System.out.print("Caught proper exception: ");
      System.out.println(e.getMessage());
    }

    try {
      urlc.setSSLSocketFactory(null);
    } catch (IllegalArgumentException e) {
      System.out.print("Caught proper exception");
      System.out.println(e.getMessage());
    }
    System.out.println("TESTS PASSED");
  }
 protected synchronized Message receiveMessage() throws IOException {
   if (messageBuffer.size() > 0) {
     Message m = (Message) messageBuffer.get(0);
     messageBuffer.remove(0);
     return m;
   }
   try {
     InetSocketAddress remoteAddress = (InetSocketAddress) channel.receive(receiveBuffer);
     if (remoteAddress != null) {
       int len = receiveBuffer.position();
       receiveBuffer.rewind();
       receiveBuffer.get(buf, 0, len);
       try {
         IP address = IP.fromInetAddress(remoteAddress.getAddress());
         int port = remoteAddress.getPort();
         extractor.appendData(buf, 0, len, new SocketDescriptor(address, port));
         receiveBuffer.clear();
         extractor.updateAvailableMessages();
         return extractor.nextMessage();
       } catch (EOFException exc) {
         exc.printStackTrace();
         System.err.println(buf.length + ", " + len);
       } catch (InvocationTargetException exc) {
         exc.printStackTrace();
       } catch (IllegalAccessException exc) {
         exc.printStackTrace();
       } catch (InstantiationException exc) {
         exc.printStackTrace();
       } catch (IllegalArgumentException e) {
         e.printStackTrace();
       } catch (InvalidCompressionMethodException e) {
         e.printStackTrace();
       }
     }
   } catch (ClosedChannelException exc) {
     if (isKeepAlive()) {
       throw exc;
     }
   }
   return null;
 }
        public void handleMessage(Message msg) {
          super.handleMessage(msg);

          try {
            prog.dismiss();
          } catch (
              IllegalArgumentException
                  e) { // this may happen due to race conditions on activity shutdown?
            e.printStackTrace();
          }
          switch (msg.what) {
            case QH_OK:
              buildView();
              break;
            case QH_EMPTY:
              doAlert(null, "Server gave an unexpected response (no signon acknowledgement?)");
              break;
            case QH_ERR_OFX:
              {
                OfxError e = (OfxError) msg.obj;
                switch (e.getErrorCode()) {
                    // case StatusResponse.STATUS_ERROR: // General error (ERROR)
                    // case StatusResponse.STATUS_MFA_REQUIRED: // User credentials are correct, but
                    // further authentication required (ERROR)
                    // case StatusResponse.STATUS_MFA_INVALID: // MFACHALLENGEA contains invalid
                    // information (ERROR)
                  case StatusResponse
                      .STATUS_FI_INVALID: // <FI> Missing or Invalid in <SONRQ> (ERROR)
                    doAlert(e, "Server is rejecting connection details (FI_ID or FI_ORG)");
                    break;
                    // case StatusResponse.STATUS_PINCH_NEEDED: // Must change USERPASS (INFO)
                  case StatusResponse
                      .STATUS_AUTHTOKEN_REQUIRED: // OFX server requires AUTHTOKEN in signon during
                                                  // the next session (ERROR)
                  case StatusResponse
                      .STATUS_BAD_LOGIN: // Signon invalid (see section 2.5.1) (ERROR)
                  case StatusResponse.STATUS_AUTHTOKEN_INVALID: // AUTHTOKEN invalid (ERROR)
                    loginFailure();
                    break;
                  case StatusResponse.STATUS_ACCT_BUSY: // Customer account already in use (ERROR)
                    doAlert(e, "Your account is currently in use");
                    break;
                  case StatusResponse.STATUS_ACCT_LOCKED: // USERPASS Lockout (ERROR)
                    doAlert(e, "Your account has been locked");
                    break;
                    // case StatusResponse.STATUS_EMPTY_REQUEST: // Empty signon transaction not
                    // supported (ERROR)
                    // case StatusResponse.STATUS_PINCH_REQUIRED: // Signon invalid without
                    // supporting pin change request (ERROR)
                    // case StatusResponse.STATUS_CLIENTUID_REJECTED: // CLIENTUID error (ERROR)
                  case StatusResponse
                      .STATUS_CALL_US: // User should contact financial institution (ERROR)
                    doAlert(e, "Please contact your financial institution");
                    break;
                  default:
                    doAlert(e, "Server refused the login");
                    break;
                }
              }

            case QH_ERR_HTTP:
            case QH_ERR_TIMEOUT:
            case QH_ERR_CONN:
            case QH_ERR_SSL:
              doRetryableAlert((Exception) msg.obj, "Unable to connect to server");
              break;

            default:
              doAlert((Exception) msg.obj, OfxProfile.exceptionComment((Exception) msg.obj));
              break;
          }
        }
Beispiel #4
0
  /**
   * try to connect, produce valid DataInputStream
   *
   * @return true on success
   */
  private boolean open() {
    // TODO Auto-generated method stub
    int triesleft = 3;

    final int randmillis = 200;
    //		conntim.purge(); //?
    closetimertask.cancel();

    status = "connect: start";
    if (null == mysock) {
      mysock = new Socket();
    }

    while ((null == mysock) || !mysock.isConnected()) {
      try {
        mysock.connect(
            new InetSocketAddress(lsip, lsport)); // reconnect the same socket will fail after close

        //			mysock = new Socket(lsip, lsport);

        inStream = new DataInputStream(mysock.getInputStream());
        outStream = new DataOutputStream(mysock.getOutputStream());
      } catch (IllegalArgumentException e) {
        triesleft--;
        //			e.printStackTrace();
        System.err.printf("%d tries left: %s\n", triesleft, e.toString());
        if (triesleft <= 0) {
          status = String.format("conn failed: %s", e.toString());
          return false;
        }
      } catch (IOException e) {
        triesleft--;
        System.err.printf("%d tries left: %s", triesleft, e.toString());
        //			System.err.print(e.toString());
        e.printStackTrace();

        if (triesleft <= 0) {
          status = String.format("conn failed: %s", e.toString());
          return false;
        }
      }

      try {

        Thread.sleep((int) (100 + randmillis * Math.random()), 1);
        //			Thread.sleep(500,1);
      } catch (InterruptedException e) {
        // auch egal
      }
    }
    status = "connected";

    closetimertask =
        new TimerTask() {
          @Override
          public void run() {
            close();
          }
        };
    //		conntim.schedule(closetimertask, 10000);

    return true;
  }