示例#1
0
 /** ** Main client thread loop */
 public void run() {
   this.setRunStatus(THREAD_RUNNING);
   this.threadStarted();
   try {
     this.openSocket();
     this.inputThread = new InputThread(this.socket, this.readTimeout, this.ioThreadLock);
     this.outputThread = new OutputThread(this.socket, this.ioThreadLock);
     this.inputThread.start();
     this.outputThread.start();
     synchronized (this.ioThreadLock) {
       while (this.inputThread.isRunning() || this.outputThread.isRunning()) {
         try {
           this.ioThreadLock.wait();
         } catch (Throwable t) {
         }
       }
     }
   } catch (NoRouteToHostException nrthe) {
     Print.logInfo("Client:ControlThread - Unable to reach " + this.host + ":" + this.port);
     nrthe.printStackTrace();
   } catch (Throwable t) {
     Print.logInfo("Client:ControlThread - " + t);
     t.printStackTrace();
   } finally {
     this.closeSocket();
   }
   this.setRunStatus(THREAD_STOPPED);
   this.threadStopped();
 }
示例#2
0
  @Test
  public void testTypes() throws IOException, NoSuchElementException {
    if (url == null) return;
    WFS_1_0_0_DataStore wfs;
    try {
      wfs = WFSDataStoreReadTest.getDataStore(url);
    } catch (ConnectException e) {
      e.printStackTrace(System.err);
      return;
    } catch (UnknownHostException e) {
      e.printStackTrace(System.err);
      return;
    } catch (NoRouteToHostException e) {
      e.printStackTrace(System.err);
      return;
    }
    String types[] = wfs.getTypeNames();
    String typeName = "unknown";
    for (int i = 0; i < types.length; i++) {
      typeName = types[i];
      if (typeName.equals("topp:geometrytype")) continue;
      SimpleFeatureType type = wfs.getSchema(typeName);
      type.getTypeName();
      type.getName().getNamespaceURI();

      SimpleFeatureSource source = wfs.getFeatureSource(typeName);
      source.getBounds();

      SimpleFeatureCollection features = source.getFeatures();
      features.getBounds();
      features.getSchema();
      // features.getFeatureType();

      Query query = new Query(typeName, Filter.INCLUDE, 20, Query.ALL_NAMES, "work already");
      features = source.getFeatures(query);
      features.size();
      SimpleFeatureIterator iterator = features.features();
      try {
        while (iterator.hasNext()) {
          SimpleFeature feature = (SimpleFeature) iterator.next();
        }
      } finally {
        iterator.close();
      }
    }
  }
  protected boolean execStreamConnect(Properties props) {
    try {
      if (props == null) {
        notifyStreamResult(true, "I2P_ERROR", "No parameters specified in STREAM CONNECT message");
        _log.debug("No parameters specified in STREAM CONNECT message");
        return false;
      }
      boolean verbose = props.getProperty("SILENT", "false").equals("false");

      String dest = props.getProperty("DESTINATION");
      if (dest == null) {
        notifyStreamResult(verbose, "I2P_ERROR", "Destination not specified in RAW SEND message");
        _log.debug("Destination not specified in RAW SEND message");
        return false;
      }
      props.remove("DESTINATION");

      try {
        streamSession.connect(this, dest, props);
        return true;
      } catch (DataFormatException e) {
        _log.debug("Invalid destination in STREAM CONNECT message");
        notifyStreamResult(verbose, "INVALID_KEY", null);
      } catch (ConnectException e) {
        _log.debug("STREAM CONNECT failed: " + e.getMessage());
        notifyStreamResult(verbose, "CONNECTION_REFUSED", null);
      } catch (NoRouteToHostException e) {
        _log.debug("STREAM CONNECT failed: " + e.getMessage());
        notifyStreamResult(verbose, "CANT_REACH_PEER", null);
      } catch (InterruptedIOException e) {
        _log.debug("STREAM CONNECT failed: " + e.getMessage());
        notifyStreamResult(verbose, "TIMEOUT", null);
      } catch (I2PException e) {
        _log.debug("STREAM CONNECT failed: " + e.getMessage());
        notifyStreamResult(verbose, "I2P_ERROR", e.getMessage());
      }
    } catch (IOException e) {
    }
    return false;
  }
示例#4
0
  @Test
  public void testSingleType() throws IOException, NoSuchElementException {
    if (url == null) return;
    WFS_1_0_0_DataStore wfs;
    try {
      wfs = WFSDataStoreReadTest.getDataStore(url);
    } catch (ConnectException e) {
      e.printStackTrace(System.err);
      return;
    } catch (UnknownHostException e) {
      e.printStackTrace(System.err);
      return;
    } catch (NoRouteToHostException e) {
      e.printStackTrace(System.err);
      return;
    }
    String typeName = "tiger:poi";
    SimpleFeatureType type = wfs.getSchema(typeName);
    type.getTypeName();
    type.getName().getNamespaceURI();

    SimpleFeatureSource source = wfs.getFeatureSource(typeName);
    source.getBounds();

    SimpleFeatureCollection features = source.getFeatures();
    features.getBounds();
    features.getSchema();
    // features.getFeatureType();

    Query query = new Query(typeName, Filter.INCLUDE, 20, Query.ALL_NAMES, "work already");
    features = source.getFeatures(query);
    features.size();

    SimpleFeatureIterator iterator = features.features();
    while (iterator.hasNext()) {
      SimpleFeature feature = iterator.next();
    }
    iterator.close();
  }
示例#5
0
  protected boolean execStreamConnect(Properties props) {
    if (props == null) {
      _log.debug("No parameters specified in STREAM CONNECT message");
      return false;
    }

    int id;
    {
      String strid = props.getProperty("ID");
      if (strid == null) {
        _log.debug("ID not specified in STREAM SEND message");
        return false;
      }
      try {
        id = Integer.parseInt(strid);
      } catch (NumberFormatException e) {
        _log.debug("Invalid STREAM CONNECT ID specified: " + strid);
        return false;
      }
      if (id < 1) {
        _log.debug("Invalid STREAM CONNECT ID specified: " + strid);
        return false;
      }
      props.remove("ID");
    }

    String dest = props.getProperty("DESTINATION");
    if (dest == null) {
      _log.debug("Destination not specified in RAW SEND message");
      return false;
    }
    props.remove("DESTINATION");

    try {
      try {
        if (!getStreamSession().connect(id, dest, props)) {
          _log.debug("STREAM connection failed");
          return false;
        }
      } catch (DataFormatException e) {
        _log.debug("Invalid destination in STREAM CONNECT message");
        notifyStreamOutgoingConnection(id, "INVALID_KEY", null);
      } catch (SAMInvalidDirectionException e) {
        _log.debug("STREAM CONNECT failed: " + e.getMessage());
        notifyStreamOutgoingConnection(id, "INVALID_DIRECTION", null);
      } catch (ConnectException e) {
        _log.debug("STREAM CONNECT failed: " + e.getMessage());
        notifyStreamOutgoingConnection(id, "CONNECTION_REFUSED", null);
      } catch (NoRouteToHostException e) {
        _log.debug("STREAM CONNECT failed: " + e.getMessage());
        notifyStreamOutgoingConnection(id, "CANT_REACH_PEER", null);
      } catch (InterruptedIOException e) {
        _log.debug("STREAM CONNECT failed: " + e.getMessage());
        notifyStreamOutgoingConnection(id, "TIMEOUT", null);
      } catch (I2PException e) {
        _log.debug("STREAM CONNECT failed: " + e.getMessage());
        notifyStreamOutgoingConnection(id, "I2P_ERROR", null);
      }
    } catch (IOException e) {
      return false;
    }

    return true;
  }
示例#6
0
  /**
   * Test to see if the passed host-port pair is the endpoint for an SMTP server. If there is an
   * SMTP server at that destination then a value of true is returned from the method. Otherwise a
   * false value is returned to the caller.
   *
   * @param host The remote host to connect to.
   * @param port The remote port on the host.
   * @return True if server supports SMTP on the specified port, false otherwise
   */
  private boolean isServer(InetAddress host, int port, int retries, int timeout) {
    // get a log to send errors
    //
    ThreadCategory log = ThreadCategory.getInstance(getClass());

    boolean isAServer = false;
    for (int attempts = 0; attempts <= retries && !isAServer; attempts++) {
      Socket socket = null;
      try {
        socket = new Socket();
        socket.connect(new InetSocketAddress(host, port), timeout);
        socket.setSoTimeout(timeout);
        log.debug("SmtpPlugin: connected to host: " + host + " on port: " + port);

        // Allocate a line reader
        //
        BufferedReader lineRdr = new BufferedReader(new InputStreamReader(socket.getInputStream()));

        // Read responses from the server. The initial line should just
        // be a banner, but go ahead and check for multiline response.
        //
        String result = null;
        do {
          result = lineRdr.readLine();

        } while (result != null && result.length() > 0 && MULTILINE_RESULT.match(result));

        if (result == null || result.length() == 0) {
          log.info("Received truncated response from SMTP server " + InetAddressUtils.str(host));
          continue;
        }

        // Tokenize the last line result
        //
        StringTokenizer t = new StringTokenizer(result);
        int rc = Integer.parseInt(t.nextToken());
        if (rc == 220) {
          //
          // Send the HELO command
          //
          String cmd = "HELO " + LOCALHOST_NAME + "\r\n";
          socket.getOutputStream().write(cmd.getBytes());

          // Response from HELO command may be a multi-line response
          // (but
          // most likely will be single-line)..
          // We are expecting to get a response with an integer return
          // code in the first token. We can't ge sure that the first
          // response will give us what we want. Consider the
          // following
          // reponse for example:
          //
          // 250-First line
          // 250-Second line
          // 250 Requested mail action okay, completed
          //
          // In this case the final line of the response contains the
          // return
          // code we are looking for.
          do {
            result = lineRdr.readLine();

          } while (result != null && result.length() > 0 && MULTILINE_RESULT.match(result));

          if (result == null || result.length() == 0) {
            log.info("Received truncated response from SMTP server " + InetAddressUtils.str(host));
            continue;
          }

          t = new StringTokenizer(result);
          rc = Integer.parseInt(t.nextToken());
          if (rc == 250) {
            //
            // Send the QUIT command
            //
            cmd = "QUIT\r\n";
            socket.getOutputStream().write(cmd.getBytes());

            // Response from QUIT command may be a multi-line
            // response.
            // We are expecting to get a response with an integer
            // return
            // code in the first token. We can't ge sure that the
            // first
            // response will give us what we want. Consider the
            // following
            // reponse for example:
            //
            // 221-First line
            // 221-Second line
            // 221 <domain> Service closing transmission channel.
            //
            // In this case the final line of the response contains
            // the return
            // code we are looking for.
            do {
              result = lineRdr.readLine();

            } while (result != null && result.length() > 0 && MULTILINE_RESULT.match(result));

            if (result == null || result.length() == 0) {
              log.info(
                  "Received truncated response from SMTP server " + InetAddressUtils.str(host));
              continue;
            }

            t = new StringTokenizer(result);
            rc = Integer.parseInt(t.nextToken());

            if (rc == 221) isAServer = true;
          }
        }
      } catch (NumberFormatException e) {
        log.info(
            "SmtpPlugin: received invalid result code from server " + InetAddressUtils.str(host),
            e);
        isAServer = false;
      } catch (ConnectException cE) {
        // Connection refused!! Continue to retry.
        //
        log.debug("SmtpPlugin: connection refused to " + InetAddressUtils.str(host) + ":" + port);
        isAServer = false;
      } catch (NoRouteToHostException e) {
        // No route to host!! No need to perform retries.
        e.fillInStackTrace();
        log.info(
            "SmtpPlugin: Unable to test host "
                + InetAddressUtils.str(host)
                + ", no route available",
            e);
        isAServer = false;
        throw new UndeclaredThrowableException(e);
      } catch (InterruptedIOException e) {
        log.debug(
            "SmtpPlugin: did not connect to host within timeout: "
                + timeout
                + " attempt: "
                + attempts);
        isAServer = false;
      } catch (IOException e) {
        log.info("SmtpPlugin: Error communicating with host " + InetAddressUtils.str(host), e);
        isAServer = false;
      } catch (Throwable t) {
        log.warn(
            "SmtpPlugin: Undeclared throwable exception caught contacting host "
                + InetAddressUtils.str(host),
            t);
        isAServer = false;
      } finally {
        try {
          if (socket != null) socket.close();
        } catch (IOException e) {
        }
      }
    }

    //
    // return the success/failure of this
    // attempt to contact an SMTP server.
    //
    return isAServer;
  }
示例#7
0
  /**
   * Test to see if the passed host-port pair is the endpoint for a TCP server. If there is a TCP
   * server at that destination then a value of true is returned from the method. Otherwise a false
   * value is returned to the caller. In order to return true the remote host must generate a banner
   * line which contains the text from the bannerMatch argument.
   *
   * @param host The remote host to connect to.
   * @param port The remote port on the host.
   * @param bannerResult Banner line generated by the remote host must contain this text.
   * @return True if a connection is established with the host and the banner line contains the
   *     bannerMatch text.
   */
  private boolean isServer(
      InetAddress host, int port, int retries, int timeout, RE regex, StringBuffer bannerResult) {
    ThreadCategory log = ThreadCategory.getInstance(getClass());

    boolean isAServer = false;
    for (int attempts = 0; attempts <= retries && !isAServer; attempts++) {
      Socket socket = null;
      try {
        // create a connected socket
        //
        socket = new Socket();
        socket.connect(new InetSocketAddress(host, port), timeout);
        socket.setSoTimeout(timeout);
        log.debug("TcpPlugin: connected to host: " + host + " on port: " + port);

        // If banner matching string is null or wildcard ("*") then we
        // only need to test connectivity and we've got that!
        //
        if (regex == null) {
          isAServer = true;
        } else {
          // get a line reader
          //
          BufferedReader lineRdr =
              new BufferedReader(new InputStreamReader(socket.getInputStream()));

          // Read the server's banner line ouptput and validate it
          // against
          // the bannerMatch parameter to determine if this interface
          // supports the
          // service.
          //
          String response = lineRdr.readLine();
          if (regex.match(response)) {
            if (log.isDebugEnabled()) log.debug("isServer: matching response=" + response);
            isAServer = true;
            if (bannerResult != null) bannerResult.append(response);
          } else {
            // Got a response but it didn't match...no need to
            // attempt retries
            isAServer = false;
            if (log.isDebugEnabled()) log.debug("isServer: NON-matching response=" + response);
            break;
          }
        }
      } catch (ConnectException e) {
        // Connection refused!! Continue to retry.
        //
        log.debug("TcpPlugin: Connection refused to " + InetAddressUtils.str(host) + ":" + port);
        isAServer = false;
      } catch (NoRouteToHostException e) {
        // No Route to host!!!
        //
        e.fillInStackTrace();
        log.info(
            "TcpPlugin: Could not connect to host "
                + InetAddressUtils.str(host)
                + ", no route to host",
            e);
        isAServer = false;
        throw new UndeclaredThrowableException(e);
      } catch (InterruptedIOException e) {
        // This is an expected exception
        //
        log.debug(
            "TcpPlugin: did not connect to host within timeout: "
                + timeout
                + " attempt: "
                + attempts);
        isAServer = false;
      } catch (IOException e) {
        log.info(
            "TcpPlugin: An expected I/O exception occured connecting to host "
                + InetAddressUtils.str(host)
                + " on port "
                + port,
            e);
        isAServer = false;
      } catch (Throwable t) {
        isAServer = false;
        log.warn(
            "TcpPlugin: An undeclared throwable exception was caught connecting to host "
                + InetAddressUtils.str(host)
                + " on port "
                + port,
            t);
      } finally {
        try {
          if (socket != null) socket.close();
        } catch (IOException e) {
        }
      }
    }

    //
    // return the success/failure of this
    // attempt to contact an ftp server.
    //
    return isAServer;
  }