Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9145171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:26:52+00:00 2026-06-17T10:26:52+00:00

i have got a java code for a oAuth login in the Indivo server.

  • 0

i have got a java code for a oAuth login in the Indivo server. It is working good when I’m running it from the terminal. Now, I would like to convert it to an Android app, doing pretty much the same thing. What are the necessary changes that I need to incorporate, in order to convert this raw java code into a running Android application?

When I copy the same code, and import the necessary packages, it gives an error in the class definition, and in the main declaration. it says “the main method cannot be declared static”.

Here is the java code:

public class ChromeTest {

                private Map<String, Object> options = null;
                private String recordId = null;
                private String recordId_second = null;
                private String appId = "chrome@apps.indivo.org";
                private String problemApp = "problems@apps.indivo.org";
                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 =
            "<Demographics xmlns=\"Demographics\">"
            + "<dateOfBirth>2009-11-02T00:40:30+00:00</dateOfBirth>"
            + "</Demographics>";

                private String contactDoc =
            "<Contact  xmlns=\"Contact\">"
            + "<name><fullname>nameForTestDocument</fullname><givenName/><familyName/></name>"
            + "<email type=\"work\">nathan.finstein@childrens.harvard.edu</email>"
            + "<address type=\"home\"><streetAddress>1 one way</streetAddress>"
            + "<postalCode>12345</postalCode>"
            + "<locality>ames</locality>"
            + "<region>Colorado</region>"
            + "<country>USA</country></address>"
            + "<location type=\"home\"><latitude>90</latitude><longitude>90</longitude></location>"
            + "</Contact>";

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

                String allergyDoc =
            "<Allergy xmlns=\"http://indivo.org/vocab/xml/documents#\">\n" +
            "  <dateDiagnosed>2009-05-16</dateDiagnosed>\n" +
            "  <diagnosedBy>Children's Hospital Boston</diagnosedBy>\n" +
            "  <allergen>\n" +
            "    <type type=\"http://codes.indivo.org/codes/allergentypes/\" value=\"drugs\">Drugs</type>\n" +
            "    <name type=\"http://codes.indivo.org/codes/allergens/\" value=\"penicillin\">Penicillin</name>\n" +
            "  </allergen>\n\n" +
            "  <reaction>blue rash</reaction>\n" +
            "  <specifics>this only happens on weekends</specifics>\n" +
            "</Allergy>";


                String medicationDoc =
            "<Medication xmlns=\"http://indivo.org/vocab/xml/documents#\">" +
              "<dateStarted>2009-02-05</dateStarted>" +
              "<name type=\"http://indivo.org/codes/meds#\" abbrev=\"c2i\" value=\"cox2-inhibitor\">COX2 Inhibitor</name>" +
              "<brandName type=\"http://indivo.org/codes/meds#\" abbrev=\"vioxx\" value=\"Vioxx\">Vioxx</brandName>" +
              "<dose><value>3</value><unit type=\"http://indivo.org/codes/units#\" value=\"pills\" abbrev=\"p\">pills</unit></dose>" +
              "<route type=\"http://indivo.org/codes/routes#\" value=\"PO\">By Mouth</route>" +
              "<strength><value>100</value><unit type=\"http://indivo.org/codes/units#\" value=\"mg\" abbrev=\"mg\">milligram</unit></strength>" +
              "<frequency type=\"http://indivo.org/codes/frequency#\" value=\"daily\">daily</frequency>" +
              "</Medication>";


                /**
                 * @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 = "johnsmith@example.org";
                    String username = "jsmith";
                    String password = "password.example";


                    String accountId_second = "johnsmith@example.org";
                    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<String,String> testResultForm  =(Map<String,String>) 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<String,String>)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 = "<HBA1C xmlns=\"http://indivo.org/vocab#\" value=\"6.3\""
                        + " unit=\"mg/dL\" datetime=\"" + xmlDateTime + "\" />"; 
                    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 nathan.finstein@childrens.harvard.edu", 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<String,String>)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<String,String>) 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=<TIMESTAMP>&surl_token=<TOKEN>&surl_sig=<SIGNATURE>", sessionToken, sessionTokenSecret, options);
                    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
                    System.out.println("\n==================================================\n\n");
                    }
                }   

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

                    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<String> 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");
                }
            }


    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T10:26:54+00:00Added an answer on June 17, 2026 at 10:26 am

    Firstly, you need an Android component to launch your class – it can be either Activity, Service or Application.

    Secondly, you need to launch a thread with your code, as network calls are not ok to be executed on the UI thread.

    Begin with android development here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got problem with sending int from Java Client to C++ server. I
I have got this code, and I get an error incomparable types: java.lang.String and
I've got WebView, JS code inside it. Also I have interface to allow Java
I have a multithreaded Java code in which: several threads read stateful objects from
I got the following assignment - I have a certain java code for a
if i have got such java code: public static void main(String[] args) { for(int
I'm currently translating an application from actionscript-3 to Java code and got stuck with
I have used the following Java code from Yahoo to get search results response
I have got the following code in a file called test.java which is located
I have a java code for copy file from one folder to another folder.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.