/**
   * Return a list of all the images stored in this RMS
   *
   * @param recordStore
   */
  public static Vector getImageList(String recordStore) {
    Log.debug("Getting Image list store name=[" + recordStore + "]");
    RecordStore imagesRS = null;
    Vector v = new Vector();
    try {
      imagesRS = RecordStore.openRecordStore(recordStore, true);
      RecordEnumeration re = imagesRS.enumerateRecords(null, null, true);
      if (re != null) {
        Log.debug("ImageRMSUtils: Record Enumeration was not null ");
        int numRecs = re.numRecords();
        // For each record
        for (int i = 0; i < numRecs; i++) {
          // Get the next record's ID
          int recId = re.nextRecordId(); // throws
          // InvalidRecordIDException
          // Get the record
          Log.debug("Got a record");
          byte[] rec = imagesRS.getRecord(recId);
          ByteArrayInputStream bin = new ByteArrayInputStream(rec);
          DataInputStream din = new DataInputStream(bin);
          v.addElement(din.readUTF());
          bin.close();
        }
      } else {
        Log.error("ImageRMSUtils Exception Record Enumeration was null ");
      }

      Log.debug("Retrieved " + v.size() + " images from RMS");
    } catch (InvalidRecordIDException ignore) {
      Log.error("RecordId Exception " + ignore.getMessage());
    } catch (Exception e) {
      Log.error("ImageRMSUtils Exception " + e.getMessage());
    } finally {
      try {
        // Close the Record Store
        if (imagesRS != null) imagesRS.closeRecordStore();
      } catch (Exception ignore) {
        // Ignore
      }
    }
    return v;
  }
Beispiel #2
0
  public int postViaHttpConnection(String url) { // throws IOException,
    // RecordStoreException {

    HttpConnection c = null;
    InputStream is = null;
    OutputStream os = null;
    int rc = -1;
    int recID = 0;
    RecordEnumeration recIter = null;
    SigSeg sigSeg = null;
    this.log("Test1");
    try {
      try {
        c = (HttpConnection) Connector.open(url, Connector.READ_WRITE);
      } catch (IllegalArgumentException e) {
        this.alertError("post:open IllegalArgument: parameter is invalid. " + e.getMessage());
        throw e;
      } catch (ConnectionNotFoundException e) {
        this.alertError(
            "post:open ConnectionNotFound: target not found, or protocol not supported. "
                + e.getMessage());
        throw e;
      } catch (IOException e) {
        this.alertError("post:open IOException: " + e.getMessage());
        throw e;
      } catch (SecurityException e) {
        this.alertError("post:open SecurityException: " + e.getMessage());
        throw e;
      }
      this.log("Test2");

      try {
        c.setRequestMethod(HttpConnection.POST);
      } catch (IOException e) {
        this.alertError(
            "post:setReqMethod IOException: the method cannot be reset or if the requested method isn't valid for HTTP:"
                + e.getMessage());
        throw e;
      }
      this.log("Test3");

      try {
        c.setRequestProperty("Content-type", "application/x-www-form-urlencoded");
        c.setRequestProperty("User-Agent", "Profile/MIDP-2.0 Configuration/CLDC-1.0");
        c.setRequestProperty("Accept", "text/plain");
        c.setRequestProperty("Accept-Encoding", "identity");
      } catch (IOException e) {
        this.alertError(
            "post:setReqProperty IOException: connection is in connected state." + e.getMessage());
        throw e;
      }
      this.log("Test4");

      try {
        os = c.openOutputStream();
      } catch (IOException e) {
        this.alertError(
            "post:openOutputStream IOException: maybe output stream has been closed?"
                + e.getMessage());
        throw e;
      }
      this.log("Test5");

      StringBuffer postBuf = new StringBuffer();
      postBuf.append("email=adparker%40gmail.com");
      postBuf.append("&pw=ecopda");
      postBuf.append("&type=xml");
      postBuf.append("&project_id=43");
      postBuf.append("&tableName=test2");
      postBuf.append("&data_string=");

      try {
        recIter = this.recordStore.enumerateRecords(null, null, true);
      } catch (RecordStoreNotOpenException e) {
        this.alertError("post:enumrateRecords RecordStoreNotOpenException" + e.getMessage());
        throw e;
      }
      this.log("Test6");

      try {
        recID = recIter.nextRecordId();
      } catch (InvalidRecordIDException e) {
        this.alertError("post:nextRecordId: no more records." + e.getMessage());
        throw e;
      }
      this.log("Test7");

      try {
        sigSeg = new SigSeg(this.recordStore, recID);
      } catch (RecordStoreNotOpenException e) {
        alertError("post:SigSeg RecordStoreNotOpen "); // +
        // e.getMessage());
        throw e;
      } catch (InvalidRecordIDException e) {
        alertError("post:SigSeg InvalidIDException "); // +
        // e.getMessage());
        throw e;
      } catch (RecordStoreException e) {
        alertError("post:SigSeg RecordStoreException"); // ";//+
        // e.getMessage());;
        throw e;
      } catch (IOException e) {
        alertError("post:SigSeg IOException " + e.getMessage());
        throw e;
      }
      this.log("Test8");

      postBuf.append(URLEncode.encode("<table>"));
      postBuf.append(URLEncode.encode("<row>"));

      // <field name="user">ASDFASDF</field>
      postBuf.append(URLEncode.encode("<field name=\"user\">"));
      String _userName = this.midlet.strItem_userName.getString();
      postBuf.append(URLEncode.encode(_userName));
      postBuf.append(URLEncode.encode("</field>"));

      postBuf.append(URLEncode.encode(sigSeg.toXML()));
      // postBuf.append(sigSeg.toXML());
      // sigSeg.toXML();

      postBuf.append(URLEncode.encode("</row>"));
      postBuf.append(URLEncode.encode("</table>"));

      // URL encode!

      try {
        // String urlenc = URLEncode.encode(postBuf.toString());
        // String urlenc = postBuf.toString();
        os.write(postBuf.toString().getBytes());
      } catch (IOException e) {
        alertError("post:os.write IOException " + e.getMessage());
        throw e;
      }
      this.log("Test9");

      try {
        os.flush();
      } catch (IOException e) {
        alertError("post:os.flush IOException " + e.getMessage());
        throw e;
      }
      this.log("Test10");

      try {
        rc = c.getResponseCode();
      } catch (IOException e) {
        alertError("post:c.getResponseCode IOException" + e.getMessage());
        throw e;
      }
      this.log("Test11");
      if (rc != HttpConnection.HTTP_OK) {
        this.alertError("HTTP response code: " + String.valueOf(rc));
      } else {
        ++this.int_recordsSent;
      }
      this.popRecord(recID);
      this.updateView();

    } catch (Exception e) {
    } finally {
      if (is != null)
        try {
          is.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      if (os != null)
        try {
          os.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      if (c != null)
        try {
          c.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
    }
    return rc;
  }