Konvertieren eines Java-Codes in eine Android-AnwendungAndroid

Forum für diejenigen, die für Android programmieren
Anonymous
 Konvertieren eines Java-Codes in eine Android-Anwendung

Post by Anonymous »

Ich habe einen Java-Code für eine oAuth-Anmeldung auf dem Indivo-Server. Es funktioniert gut, wenn ich es vom Terminal aus betreibe. Jetzt möchte ich es in eine Android-App konvertieren und dabei im Wesentlichen das Gleiche tun. Welche notwendigen Änderungen muss ich einarbeiten, um diesen rohen Java-Code in eine laufende Android-Anwendung zu konvertieren?

Wenn ich denselben Code kopiere und die erforderlichen Pakete importiere, wird ein Fehler in der Klassendefinition und in der Hauptdeklaration angezeigt. Es heißt: „Die Hauptmethode kann nicht als statisch deklariert werden“.

Hier ist der Java-Code:

öffentliche Klasse ChromeTest {

Code: Select all

                private Map  options = null;
private String recordId = null;
private String recordId_second = null;
private String appId = "[email protected]";
private String problemApp = "[email protected]";
private Properties properties = null;
private String sessionToken = null;
private String sessionTokenSecret = null;
private String sessionToken_second = null;
private String sessionTokenSecret_second = null;
private String pagingOrderingQuery = null;
private String extrnlRandom = null;

private XPath xpath = null;

private DatatypeFactory dtf = null;
private XMLGregorianCalendar gregCal = null;

private String demographicsDoc =
""
+ "2009-11-02T00:40:30+00:00"
+ "";

private String contactDoc =
""
+ "nameForTestDocument"
+ "[email protected]"
+ "1 one way"
+ "12345"
+ "ames"
+ "Colorado"
+ "USA"
+ "9090"
+ "";

String testDocExtrnl = "strictly for testing - external from chrome";
String testDocStatus = "strictly for testing Status from chrome";
String testDocRelate_A = "strictly for testing Relate from chrome A";
String testDocRelate_B = "strictly for testing Relate from chrome B";
String testDocAppSpecific = "strictly for testing - app specific from chrome";
String testDocAppSpecificR = "strictly for testing - app specific record specific from chrome";
String testDoc = "strictly for testing - chrome created no externalID";
//String testDocRplc = "strictly for testing - replaced by Chrome";
String testDocEstablished = "strictly for testing - Have Chrome try to delete later";
String testDocToDelete = "strictly for testing - Chrome should be able to delete this if done soon";
String testDocToReplace = "strictly for testing - Chrome will replace this version";
String testDocReplacement = "strictly for testing -  Chrome will use this to replace the other";
String testDocToShare = "share this";

String allergyDoc =
"\n" +
"  2009-05-16\n" +
"  Children's Hospital Boston\n" +
"  \n" +
"    Drugs\n" +
"    Penicillin\n" +
"  \n\n" +
"  blue rash\n" +
"  this only happens on weekends\n" +
"";

String medicationDoc =
"" +
"2009-02-05" +
"COX2 Inhibitor" +
"
Vioxx" +
"3pills" +
"By Mouth" +
"100milligram" +
"daily" +
"";

/**
* @param args the command line arguments
*/
public static void main(String[] args) throws
IndivoClientException, IOException, XPathExpressionException, javax.xml.datatype.DatatypeConfigurationException{
// TODO code application logic here
ChromeTest instance = new ChromeTest();

Properties props = new Properties();
instance.properties = props;

instance.xpath = XPathFactory.newInstance().newXPath();
instance.extrnlRandom = Integer.toString(new Random().nextInt(1000000));

instance.dtf = DatatypeFactory.newInstance();

instance.doTest();
}

private void reportKnownError(Exception ice) {
String errId = Integer.toString(new Random().nextInt(1000000));
System.err.println("\n\nerror id: " + errId);

ice.printStackTrace();
System.err.println("==============================================\n");
System.out.println("Known exception thrown, stack trace in error stream, see: " + errId + "\n");

}

private void doTest() throws IndivoClientException, XPathExpressionException, UnsupportedEncodingException {
Rest chrome = new Rest("chrome", "chrome", "http://localhost:8080", null);
String accountId = "[email protected]";
String username = "jsmith";
String password = "password.example";

String accountId_second = "[email protected]";
String username_second = "jsmith";
String password_second = "password.example";

recordId = "781a64e7-fc04-4bbc-8804-7480b0b337dc";
recordId_second = "781a64e7-fc04-4bbc-8804-7480b0b337dc";

String str = "username="+ username+ "&password="+password ;
System.out.println("testing -- oauth_internal_session_createPOST");
Map  testResultForm  =(Map) chrome.oauth_internal_session_createPOST(str, options);
System.out.println("oauth_internal_session_createPOST  once");
System.out.println(Utils.printForm(testResultForm) + "\n\n");
sessionToken = testResultForm.get("oauth_token");
sessionTokenSecret = testResultForm.get("oauth_token_secret");
String str1 = "username="+ username_second+ "&password="+password_second ;

testResultForm  =(Map)chrome.oauth_internal_session_createPOST(str1, options);

System.out.println(Utils.printForm(testResultForm) + "\n\n");
sessionToken_second = testResultForm.get("oauth_token");
sessionTokenSecret_second = testResultForm.get("oauth_token_secret");

Document testResultDoc = null;
System.out.println("testing -- records_X_documents_X_versions_GET");

System.out.println("testing -- records_X_documents_GET");
String xmlDateTime = null;
gregCal = dtf.newXMLGregorianCalendar(new GregorianCalendar());
xmlDateTime = gregCal.toXMLFormat();

String hba1cDoc = "";
System.out.println("testing -- records_X_documents_POST");
testResultDoc = (Document) chrome.records_X_documents_POST(
recordId, sessionToken, sessionTokenSecret, hba1cDoc, "application/xml", options);
System.out.println(Utils.domToString(testResultDoc) + "\n\n");
System.out.println("\n--------------------------------------\n\n");
System.out.println("testing -- records_X_documents_POST");
testResultDoc = (Document) chrome.records_X_documents_POST(
recordId, sessionToken, sessionTokenSecret,
hba1cDoc.replace("\"6.3\"", "\"7.4\""), "application/xml", options);
System.out.println(Utils.domToString(testResultDoc) + "\n\n");
System.out.println("\n--------------------------------------\n\n");

testResultDoc = (Document) chrome.records_X_documents_POST(recordId, sessionToken, sessionTokenSecret,
medicationDoc,  "application/xml", options);

System.out.println("testing -- records_X_reports_minimal_X_GET");
testResultDoc = (Document) chrome.records_X_reports_minimal_X_GET(
pagingOrderingQuery, recordId, "medications", sessionToken, sessionTokenSecret, options);
System.out.println(Utils.domToString(testResultDoc) + "\n\n");
System.out.println("\n==================================================\n\n");

System.out.println("testing -- accounts_XGET");
testResultDoc = (Document) chrome.accounts_XGET(accountId, sessionToken, sessionTokenSecret, options);
System.out.println(Utils.domToString(testResultDoc) + "\n\n");
System.out.println("\n==================================================\n\n");

System.out.println("testing -- accounts_X_infoSetPOST");
testResultDoc = (Document) chrome.accounts_X_infoSetPOST(
"new full_name [email protected]", accountId, sessionToken, sessionTokenSecret, options);
System.out.println(Utils.domToString(testResultDoc) + "\n\n");
System.out.println("\n==================================================\n\n");

System.out.println("testing -- accounts_X_authsystems_password_setUsernamePOST");
testResultDoc = (Document) chrome.accounts_X_authsystems_password_setUsernamePOST(username + "_new", accountId, sessionToken, sessionTokenSecret, options);
System.out.println(Utils.domToString(testResultDoc) + "\n\n");
System.out.println("\n------------------------------------------------\n\n");

// now set it back right away so we don't break anything
System.out.println("testing -- accounts_X_authsystems_password_setUsernamePOST");
testResultDoc = (Document) chrome.accounts_X_authsystems_password_setUsernamePOST(username, accountId, sessionToken, sessionTokenSecret, options);
System.out.println(Utils.domToString(testResultDoc) + "\n\n");
System.out.println("\n------------------------------------------------\n\n");

String str2 = "username="+ username+ "&password="+password ;
testResultForm  =(Map)chrome.oauth_internal_session_createPOST(str2, options);
System.out.println("oauth_internal_session_createPOST  twice");
System.out.println(Utils.printForm(testResultForm) + "\n\n");
sessionToken = testResultForm.get("oauth_token");
sessionTokenSecret = testResultForm.get("oauth_token_secret");
System.out.println("\n==================================================\n\n");

System.out.println("testing -- accounts_X_authsystems_password_changePOST");
testResultDoc = (Document) chrome.accounts_X_authsystems_password_changePOST(password,
password + "_new", accountId, sessionToken,  options);
System.out.println(Utils.domToString(testResultDoc) + "\n\n");
System.out.println("\n--------------------------------------------------\n\n");

// now change it right back
System.out.println("testing -- accounts_X_authsystems_password_changePOST");
testResultDoc = (Document) chrome.accounts_X_authsystems_password_changePOST(password + "_new", password, accountId, sessionToken, options);
System.out.println(Utils.domToString(testResultDoc) + "\n\n");
System.out.println("\n==================================================\n\n");

// now set it back to what it was
System.out.println("testing -- accounts_X_authsystems_password_setUsernamePOST");
try {
System.out.println("testing -- records_X_apps_XDELETE");
testResultDoc = (Document) chrome.records_X_apps_XDELETE(
recordId_second, problemApp, sessionToken_second, sessionTokenSecret_second, options);
System.out.println(Utils.domToString(testResultDoc) + "\n\n");
System.out.println("\n==================================================\n\n");
} catch (IndivoClientException ice) {
reportKnownError(ice);
}

if (false) {  // skip for now, test with OAuth dance
System.out.println("testing -- oauth_internal_request_tokens_X_claimPOST");
testResultDoc = (Document) chrome.oauth_internal_request_tokens_X_claimPOST("requestToken", sessionToken, sessionTokenSecret, options);
System.out.println(Utils.domToString(testResultDoc) + "\n\n");
System.out.println("\n==================================================\n\n");

System.out.println("testing -- oauth_internal_request_tokens_X_infoGET");
testResultDoc = (Document) chrome.oauth_internal_request_tokens_X_infoGET("requestToken", sessionToken, sessionTokenSecret, options);
System.out.println(Utils.domToString(testResultDoc) + "\n\n");
System.out.println("\n==================================================\n\n");

System.out.println("testing -- oauth_internal_request_tokens_X_approvePOST");
testResultForm = (Map) chrome.oauth_internal_request_tokens_X_approvePOST(recordId, "requestToken",
sessionToken, sessionTokenSecret, options);
System.out.println(Utils.printForm(testResultForm) + "\n\n");
System.out.println("\n==================================================\n\n");

System.out.println("testing -- oauth_internal_surlVerifyGET");
testResultDoc = (Document) chrome.oauth_internal_surlVerifyGET("/widgets/WidgetName?param1=foo&param2=bar&surl_timestamp=&surl_token=&surl_sig=", sessionToken, sessionTokenSecret, options);
System.out.println(Utils.domToString(testResultDoc) + "\n\n");
System.out.println("\n==================================================\n\n");
}
}

private List listAllDocs(String recId, Rest chrome)
throws IndivoClientException, XPathExpressionException {
List retVal = new ArrayList();

Document docsDoc = (Document) chrome.records_X_documents_GET(pagingOrderingQuery, recordId, sessionToken, sessionTokenSecret, options);

NodeList allDocs = (NodeList) xpath.evaluate("/Documents/Document/@id", docsDoc, XPathConstants.NODESET);
System.out.println("allDocs.getLength(): " + allDocs.getLength());

for (int ii = 0; ii < allDocs.getLength(); ii++) {
String idStr = ((Attr)allDocs.item(ii)).getValue();
retVal.add(idStr);
}
return retVal;
}

private void shareAllDocs(String recId, List docsList, String carenetId, Rest chrome)
throws IndivoClientException {

for (int ii = 0; ii < docsList.size();  ii++) {
String idStr = docsList.get(ii);
System.out.println("idStr: " + idStr);

System.out.println("testing -- records_X_documents_X_carenets_XPUT");
Document resltDoc = (Document) chrome.records_X_documents_X_carenets_XPUT(
recordId, idStr, carenetId, sessionToken, sessionTokenSecret, options);
System.out.println("sharing -- record:" + recordId + " doc:" + idStr + "   " + Utils.domToString(resltDoc) + "\n\n");
}

System.out.println("\n+===================++++++++++++++++++\n\n");
}
}

}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post