Exemple #1
0
 /** @param recordStore */
 private void updateRecordsRemaining(RecordStore recordStore) {
   try {
     this.int_recordsRemaining = recordStore.getNumRecords();
   } catch (RecordStoreNotOpenException e) {
     this.alertError("RecordStoreNotOpenException: " + e.getMessage());
   }
   this.strItem_recordsRemaining.setText(String.valueOf(this.int_recordsRemaining));
 }
Exemple #2
0
 public void popRecord(int recID)
     throws RecordStoreNotOpenException, InvalidRecordIDException, RecordStoreException {
   try {
     this.recordStore.deleteRecord(recID);
   } catch (RecordStoreNotOpenException e) {
     this.alertError("popRecord:deleteRecord RecordStoreNotOpen");
     e.printStackTrace();
     throw e;
   } catch (InvalidRecordIDException e) {
     this.alertError("popRecord:deleteRecord InvalidRecordID");
     e.printStackTrace();
     throw e;
   } catch (RecordStoreException e) {
     this.alertError("popRecord:deleteRecord RecordStoreException");
     e.printStackTrace();
     throw e;
   }
 }
Exemple #3
0
 /**
  * [EF] Add in scenario 05
  *
  * @param photoname
  * @param imageData
  * @param albumname
  * @throws InvalidImageDataException
  * @throws PersistenceMechanismException
  */
 public void addMediaData(MediaData mediaData, String albumname)
     throws InvalidImageDataException, PersistenceMechanismException {
   try {
     mediaRS = RecordStore.openRecordStore(album_label + albumname, true);
     mediaInfoRS = RecordStore.openRecordStore(info_label + albumname, true);
     int rid2; // new record ID for ImageData (metadata)
     rid2 = mediaInfoRS.getNextRecordID();
     mediaData.setRecordId(rid2);
     byte[] data1 = getByteFromMediaInfo(mediaData);
     mediaInfoRS.addRecord(data1, 0, data1.length);
   } catch (RecordStoreException e) {
     throw new PersistenceMechanismException();
   } finally {
     try {
       mediaRS.closeRecordStore();
       mediaInfoRS.closeRecordStore();
     } catch (RecordStoreNotOpenException e) {
       e.printStackTrace();
     } catch (RecordStoreException e) {
       e.printStackTrace();
     }
   }
 }
Exemple #4
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;
  }