Example usage for org.json JSONException toString

List of usage examples for org.json JSONException toString

Introduction

In this page you can find the example usage for org.json JSONException toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:com.reecedunn.espeak.test.VoiceSettingsTest.java

public void espeakVolumeTest(int prefValue, int settingValue, SpeechSynthesis synth) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
    SharedPreferences.Editor editor = prefs.edit();
    editor.clear();// w ww. jav a 2  s  .c  om
    editor.putString("espeak_volume", Integer.toString(prefValue));
    editor.commit();

    VoiceSettings settings = new VoiceSettings(prefs, synth);
    assertThat(settings.getVoiceVariant().toString(), is("male"));
    assertThat(settings.getRate(), is(synth.Rate.getDefaultValue()));
    assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue()));
    assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
    assertThat(settings.getVolume(), is(settingValue));
    assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE));
    assertThat(settings.getPunctuationCharacters(), is(nullValue()));

    try {
        JSONObject json = settings.toJSON();
        assertThat(json.opt(VoiceSettings.PRESET_VARIANT), is(instanceOf(String.class)));
        assertThat((String) json.opt(VoiceSettings.PRESET_VARIANT), is("male"));
        assertThat(json.opt(VoiceSettings.PRESET_RATE), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_RATE), is(synth.Rate.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_PITCH), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_PITCH), is(synth.Pitch.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_PITCH_RANGE), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_PITCH_RANGE),
                is(synth.PitchRange.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_VOLUME), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_VOLUME), is(settingValue));
        assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is(instanceOf(String.class)));
        assertThat((String) json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is("none"));
        assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_CHARACTERS), is(nullValue()));
    } catch (JSONException e) {
        assertThat(e.toString(), is(nullValue())); // This will be false; used to report exception.
    }
}

From source file:com.reecedunn.espeak.test.VoiceSettingsTest.java

public void espeakPunctuationLevelTest(int prefValue, int settingValue, String jsonValue,
        SpeechSynthesis synth) {/*from   w  ww .  ja  va  2  s.  co  m*/
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
    SharedPreferences.Editor editor = prefs.edit();
    editor.clear();
    editor.putString("espeak_punctuation_level", Integer.toString(prefValue));
    editor.commit();

    VoiceSettings settings = new VoiceSettings(prefs, synth);
    assertThat(settings.getVoiceVariant().toString(), is("male"));
    assertThat(settings.getRate(), is(synth.Rate.getDefaultValue()));
    assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue()));
    assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
    assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
    assertThat(settings.getPunctuationLevel(), is(settingValue));
    assertThat(settings.getPunctuationCharacters(), is(nullValue()));

    try {
        JSONObject json = settings.toJSON();
        assertThat(json.opt(VoiceSettings.PRESET_VARIANT), is(instanceOf(String.class)));
        assertThat((String) json.opt(VoiceSettings.PRESET_VARIANT), is("male"));
        assertThat(json.opt(VoiceSettings.PRESET_RATE), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_RATE), is(synth.Rate.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_PITCH), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_PITCH), is(synth.Pitch.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_PITCH_RANGE), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_PITCH_RANGE),
                is(synth.PitchRange.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_VOLUME), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_VOLUME), is(synth.Volume.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is(instanceOf(String.class)));
        assertThat((String) json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is(jsonValue));
        assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_CHARACTERS), is(nullValue()));
    } catch (JSONException e) {
        assertThat(e.toString(), is(nullValue())); // This will be false; used to report exception.
    }
}

From source file:com.reecedunn.espeak.test.VoiceSettingsTest.java

public void testEspeakPunctuationCharacters() {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
    SharedPreferences.Editor editor = prefs.edit();
    editor.clear();/*from  w  w w.  j av  a 2 s. c  o m*/
    editor.putString("espeak_punctuation_characters", ".?!");
    editor.commit();

    SpeechSynthesis synth = new SpeechSynthesis(getContext(), mCallback);
    VoiceSettings settings = new VoiceSettings(prefs, synth);
    assertThat(settings.getVoiceVariant().toString(), is("male"));
    assertThat(settings.getRate(), is(synth.Rate.getDefaultValue()));
    assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue()));
    assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
    assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
    assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE));
    assertThat(settings.getPunctuationCharacters(), is(".?!"));

    try {
        JSONObject json = settings.toJSON();
        assertThat(json.opt(VoiceSettings.PRESET_VARIANT), is(instanceOf(String.class)));
        assertThat((String) json.opt(VoiceSettings.PRESET_VARIANT), is("male"));
        assertThat(json.opt(VoiceSettings.PRESET_RATE), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_RATE), is(synth.Rate.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_PITCH), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_PITCH), is(synth.Pitch.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_PITCH_RANGE), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_PITCH_RANGE),
                is(synth.PitchRange.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_VOLUME), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_VOLUME), is(synth.Volume.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is(instanceOf(String.class)));
        assertThat((String) json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is("none"));
        assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_CHARACTERS), is(instanceOf(String.class)));
        assertThat((String) json.opt(VoiceSettings.PRESET_PUNCTUATION_CHARACTERS), is(".?!"));
    } catch (JSONException e) {
        assertThat(e.toString(), is(nullValue())); // This will be false; used to report exception.
    }
}

From source file:com.reecedunn.espeak.test.VoiceSettingsTest.java

public void testEspeakVariantWithDefaultGenderFemale() {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
    SharedPreferences.Editor editor = prefs.edit();
    editor.clear();// w  w  w .  j  a va  2 s.  co m
    editor.putString("default_gender", Integer.toString(SpeechSynthesis.GENDER_FEMALE));
    editor.putString("espeak_variant", "klatt4");
    editor.commit();

    SpeechSynthesis synth = new SpeechSynthesis(getContext(), mCallback);
    VoiceSettings settings = new VoiceSettings(prefs, synth);
    assertThat(settings.getVoiceVariant().toString(), is("klatt4"));
    assertThat(settings.getRate(), is(synth.Rate.getDefaultValue()));
    assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue()));
    assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
    assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
    assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE));
    assertThat(settings.getPunctuationCharacters(), is(nullValue()));

    try {
        JSONObject json = settings.toJSON();
        assertThat(json.opt(VoiceSettings.PRESET_VARIANT), is(instanceOf(String.class)));
        assertThat((String) json.opt(VoiceSettings.PRESET_VARIANT), is("klatt4"));
        assertThat(json.opt(VoiceSettings.PRESET_RATE), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_RATE), is(synth.Rate.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_PITCH), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_PITCH), is(synth.Pitch.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_PITCH_RANGE), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_PITCH_RANGE),
                is(synth.PitchRange.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_VOLUME), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_VOLUME), is(synth.Volume.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is(instanceOf(String.class)));
        assertThat((String) json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is("none"));
        assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_CHARACTERS), is(nullValue()));
    } catch (JSONException e) {
        assertThat(e.toString(), is(nullValue())); // This will be false; used to report exception.
    }
}

From source file:com.reecedunn.espeak.test.VoiceSettingsTest.java

public void testEspeakRateWithDefaultRate() {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
    SharedPreferences.Editor editor = prefs.edit();
    editor.clear();/*from  ww w .ja va  2  s.  c  o  m*/
    editor.putString("default_rate", Integer.toString(50));
    editor.putString("espeak_rate", Integer.toString(200));
    editor.commit();

    SpeechSynthesis synth = new SpeechSynthesis(getContext(), mCallback);
    VoiceSettings settings = new VoiceSettings(prefs, synth);
    assertThat(settings.getVoiceVariant().toString(), is("male"));
    assertThat(settings.getRate(), is(200));
    assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue()));
    assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
    assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
    assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE));
    assertThat(settings.getPunctuationCharacters(), is(nullValue()));

    try {
        JSONObject json = settings.toJSON();
        assertThat(json.opt(VoiceSettings.PRESET_VARIANT), is(instanceOf(String.class)));
        assertThat((String) json.opt(VoiceSettings.PRESET_VARIANT), is("male"));
        assertThat(json.opt(VoiceSettings.PRESET_RATE), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_RATE), is(200));
        assertThat(json.opt(VoiceSettings.PRESET_PITCH), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_PITCH), is(synth.Pitch.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_PITCH_RANGE), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_PITCH_RANGE),
                is(synth.PitchRange.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_VOLUME), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_VOLUME), is(synth.Volume.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is(instanceOf(String.class)));
        assertThat((String) json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is("none"));
        assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_CHARACTERS), is(nullValue()));
    } catch (JSONException e) {
        assertThat(e.toString(), is(nullValue())); // This will be false; used to report exception.
    }
}

From source file:com.reecedunn.espeak.test.VoiceSettingsTest.java

public void testEspeakPitchWithDefaultPitch() {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
    SharedPreferences.Editor editor = prefs.edit();
    editor.clear();/*from   www  .j a  v  a  2s .  c  o  m*/
    editor.putString("default_pitch", Integer.toString(50));
    editor.putString("espeak_pitch", Integer.toString(75));
    editor.commit();

    SpeechSynthesis synth = new SpeechSynthesis(getContext(), mCallback);
    VoiceSettings settings = new VoiceSettings(prefs, synth);
    assertThat(settings.getVoiceVariant().toString(), is("male"));
    assertThat(settings.getRate(), is(synth.Rate.getDefaultValue()));
    assertThat(settings.getPitch(), is(75));
    assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
    assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
    assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE));
    assertThat(settings.getPunctuationCharacters(), is(nullValue()));

    try {
        JSONObject json = settings.toJSON();
        assertThat(json.opt(VoiceSettings.PRESET_VARIANT), is(instanceOf(String.class)));
        assertThat((String) json.opt(VoiceSettings.PRESET_VARIANT), is("male"));
        assertThat(json.opt(VoiceSettings.PRESET_RATE), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_RATE), is(synth.Rate.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_PITCH), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_PITCH), is(75));
        assertThat(json.opt(VoiceSettings.PRESET_PITCH_RANGE), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_PITCH_RANGE),
                is(synth.PitchRange.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_VOLUME), is(instanceOf(Integer.class)));
        assertThat((Integer) json.opt(VoiceSettings.PRESET_VOLUME), is(synth.Volume.getDefaultValue()));
        assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is(instanceOf(String.class)));
        assertThat((String) json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is("none"));
        assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_CHARACTERS), is(nullValue()));
    } catch (JSONException e) {
        assertThat(e.toString(), is(nullValue())); // This will be false; used to report exception.
    }
}

From source file:com.qbcps.sifterclient.SifterReader.java

/** Method to pass project names to list adapter. */
private void fillData() {
    int pNum = mAllProjects.length;
    String[] p = new String[pNum];
    try {//from ww  w. j a  v  a 2 s. co m
        for (int j = 0; j < pNum; j++)
            p[j] = mAllProjects[j].getString(PROJECT_NAME);
    } catch (JSONException e) {
        e.printStackTrace();
        mSifterHelper.onException(e.toString());
        return;
    }
    setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, p));
}

From source file:com.qbcps.sifterclient.SifterReader.java

/** start project details activities (milestones, categories, people, issues) */
private void getProjDetail(long id, String PROJ_DETAIL_URL, String PROJ_DETAIL, Class<?> cls) {
    String projDetailURL = null;/*ww w. j  a v  a 2 s .  c  om*/
    try {
        projDetailURL = mAllProjects[(int) id].getString(PROJ_DETAIL_URL);
        // TODO use safe long typecast to int
    } catch (JSONException e) {
        e.printStackTrace();
        mSifterHelper.onException(e.toString());
        return;
    }
    String issuesURL = projDetailURL;
    if (PROJ_DETAIL.equals(ISSUES)) {
        projDetailURL += getFilterSlug();
    }
    URLConnection sifterConnection = mSifterHelper.getSifterConnection(projDetailURL);
    if (sifterConnection == null)
        return;
    mDialog = ProgressDialog.show(this, "", "Loading ...", true);
    new DownloadSifterDetailTask().execute(sifterConnection, issuesURL, PROJ_DETAIL, cls);
}

From source file:org.esgf.globusonline.GOauthView3Controller.java

@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.POST)
public ModelAndView doPost(final HttpServletRequest request) {
    /* get model params here */
    String userCertificate = null;
    String goUserName = null;//ww  w .  ja  va  2  s . c  o m
    String target = request.getParameter("path");
    String label = request.getParameter("label");
    String folder = request.getParameter("folder[0]");

    //System.out.println("path from Parameters is: " + target);
    //System.out.println("folder from Parameters is: " + folder);

    String[] endpointInfos = null;
    String endpoint = request.getParameter("endpoint");
    String createdSrcEndpoint = null, createdDestEndpoint = null;

    //if this request comes via go form view 3 we can then obtain the request parameters for myproxy username
    String srcMyproxyUserName = request.getParameter("srcmyproxyuser");
    String srcMyproxyUserPass = request.getParameter("myProxyUserPass");
    String myProxyServerStr = request.getParameter("srcmyproxyserver");

    StringBuffer errorStatus = new StringBuffer("Steps leading up to the error are shown below:<br><br>");

    String auth_code = request.getParameter("code");
    String[] file_urls = null;
    String[] file_names;

    String myproxyServerStr = null;
    String myproxyUserName = null;
    JSONObject goAccessTokenObj = null;
    String goAccessToken = null;
    String userCertificateFile = null;

    Map<String, Object> model = new HashMap<String, Object>();
    //Get the session, so we can retrieve state.
    HttpSession session = request.getSession(false);
    if (session == null) {
    } else {
        if (!(endpoint == null)) {
            session.setAttribute("endpoint", endpoint);
        } else {
            endpoint = (String) session.getAttribute("endpoint");
        }
        if (!(target == null)) {
            session.setAttribute("target", target);
        } else {
            target = (String) session.getAttribute("target");
        }
        if (!(folder == null)) {
            session.setAttribute("folder", folder);
        } else {
            folder = (String) session.getAttribute("folder");
        }
        file_urls = (String[]) session.getAttribute("fileUrls");
        String dataset_id = (String) session.getAttribute("datasetName");
        //System.out.println("Auth3, session id is:" + session.getId());
        //System.out.println("Your dataset name is: " + dataset_id);

        userCertificateFile = (String) session.getAttribute("usercertificatefile");
        if (userCertificateFile.equals("undefined")) {
            userCertificateFile = null;
        }
        goUserName = (String) session.getAttribute("gousername");
        goAccessTokenObj = (JSONObject) session.getAttribute("goaccesstoken");
        try {
            goAccessToken = goAccessTokenObj.getString("access_token");
        } catch (JSONException e) {
            //logger.error("Error getting access_token", e);
            //throw new ValueErrorException();
        }

        myproxyServerStr = (String) session.getAttribute("myproxyServerStr");
        myproxyUserName = (String) session.getAttribute("myproxyUserName");
        //if (!(myproxyUserName == null)){System.out.println("Auth3, myproxyUserName is:" +myproxyUserName);}
        if (srcMyproxyUserPass == null) {
            srcMyproxyUserPass = (String) session.getAttribute("MyproxyUserPass");
        }
    }
    String esg_user = "";
    String esg_password = "";

    try {
        //get the openid here from the cookie
        Cookie[] cookies = request.getCookies();
        String openId = "";
        for (int i = 0; i < cookies.length; i++) {
            if (cookies[i].getName().equals("esgf.idp.cookie")) {
                openId = cookies[i].getValue();
            }
        }

        LOG.debug("Got User OpenID: " + openId);
        model.put(GOFORMVIEW_OPENID, openId);
        myproxyServerStr = Utils.resolveMyProxyViaOpenID(openId);
        LOG.debug("Using MyProxy Server: " + myproxyServerStr);
        System.out.println("Using MyProxy Server: " + myproxyServerStr);

        ESGFProperties esgfProperties = new ESGFProperties();
        UserInfoDAO uid = new UserInfoDAO(esgfProperties);
        UserInfo userInfo = uid.getUserByOpenid(openId);
        myproxyUserName = userInfo.getUserName();

        LOG.debug("Got MyProxy Username: " + myproxyUserName);
        System.out.println("Got MyProxy Username: " + myproxyUserName);

        if (request.getParameter(GOFORMVIEW_MODEL) != null) {
            //it should never come here...
        } else {
            //do we need this at all?  I don't think so
        }
    } catch (YadisException ye) {
        String eMsg = ye.toString();
        if (eMsg.indexOf("0x702") != -1) {
            model.put(GOFORMVIEW_ERROR, "error");
            model.put(GOFORMVIEW_ERROR_MSG,
                    "Please <a href=\"login\">Login</a>" + " before trying to download data!");
        } else {
            String errorMsg = "Failed to resolve OpenID: " + ye;
            LOG.error("Failed to resolve OpenID: " + ye);
            model.put(GOFORMVIEW_ERROR, "error");
            model.put(GOFORMVIEW_ERROR_MSG, errorMsg + "<br><br>Please make sure that you're"
                    + " logged in as a valid user before trying to download data!<br><br>");
        }
    } catch (Exception e) {
        String errorMsg = "Failed to resolve OpenID: " + e;
        LOG.error("Failed to resolve OpenID: " + e);
        model.put(GOFORMVIEW_ERROR, "error");
        model.put(GOFORMVIEW_ERROR_MSG, errorMsg + "<br><br>Please make sure that you're"
                + " logged in as a valid user before trying to download data!<br><br>");
    }

    if ((userCertificateFile == null || userCertificateFile.isEmpty()) && (srcMyproxyUserPass == null)) {
        //System.out.println("Auth3, srcMyproxyUserPass is null");
        return new ModelAndView("goauthview3", model);
    } else {
        //System.out.println("Auth3, srcMyproxyUserPass is:"); // +srcMyproxyUserPass);
    }
    //LOG.debug("GOFORMView4Controller got Certificate " + userCertificate);
    //LOG.debug("GOFORMView4Controller got Target " + target);
    //LOG.debug("GOFORMView4Controller got selected endpoint " + endpoint);
    //LOG.debug("GOFORMView4Controller got Src Myproxy User " + srcMyproxyUserName);
    //LOG.debug("GOFORMView4Controller got Src Myproxy Pass ******");
    //LOG.debug("GOFORMView4Controller got Src Myproxy Server " + myproxyServerStr);

    //System.out.println("GOFORMView4Controller got Certificate " + userCertificate);
    //System.out.println("GOFORMView4Controller got Target " + target);
    //System.out.println("GOFORMView4Controller got selected endpoint " + endpoint);
    //System.out.println("GOauthView3Controller got Src Myproxy User " + myproxyUserName);
    //System.out.println("GOauthView3Controller got go User " + goUserName);
    //System.out.println("GOFORMView4Controller got Src Myproxy Pass ******");
    // +srcMyproxyUserPass);
    //System.out.println("GOauthView4Controller got Src Myproxy Server " + myproxyServerStr);

    if ((srcMyproxyUserPass != null) || (userCertificateFile == null || userCertificateFile.isEmpty())) {
        try {
            JGOTransfer un = new JGOTransfer(goUserName, myproxyServerStr, myproxyUserName, srcMyproxyUserPass,
                    CA_CERTIFICATE_FILE);
            un.setVerbose(true);
            un.initialize();

            LOG.debug("Globus Online Transfer object Initialize complete");

            //errorStatus.append("Globus Online Transfer object Initialize complete<br>");

            userCertificateFile = un.getUserCertificateFile();
            LOG.debug("Retrieved user credential file: " + userCertificateFile);
            //   System.out.println("Retrieved user credential file: " + userCertificateFile);
            model.put(GOFORMVIEW_USER_CERTIFICATE, userCertificateFile);
        } catch (Exception e) {
            LOG.error("Failed to initialize transfer object to get user cert: " + e);

            //TODO: Iterate back to password page w/ invalid password error
            model.put(GOFORMVIEW_ERROR, "autherror");
            System.out.println("Failed to initialize transfer object to get user cert: " + e);
            return new ModelAndView("goauthview3", model);
        }
    }
    //System.out.println("Retrieved user credential file: " + goUserName + goAccessToken + userCertificateFile + CA_CERTIFICATE_FILE);

    JGOTransfer transfer = new JGOTransfer(goUserName, goAccessToken, CA_CERTIFICATE_FILE);
    transfer.setVerbose(true);
    //If we need to set vs. testing:
    //transfer.setBaseUrl("https://transfer.test.api.globusonline.org/v0.10");

    try {
        String newURL = null, goEP = null;
        String[] pieces = null;

        String[] urlParts = null;
        String urlHost = null;
        int filePathIndex;

        Vector<String> fileList = null;
        HashMap<String, String> sourceEpToGFTPMap = new HashMap<String, String>();
        HashMap<String, Vector<String>> sourceMap = new HashMap<String, Vector<String>>();
        transfer.initialize();

        LOG.debug("About to retrieve available endpoints");
        Vector<EndpointInfo> endpoints = transfer.listEndpoints();
        LOG.debug("We pulled down " + endpoints.size() + " endpoints");
        //System.out.println("We pulled down " + endpoints.size() + " endpoints");
        errorStatus.append("Endpoints retrieved<br>");
        endpointInfos = constructEndpointInfos(endpoints);
        // find the endpointInfo line that matches the endpoint the user selected
        String endpointInfo = Utils.getEndpointInfoFromEndpointStr(endpoint, endpointInfos);
        //System.out.println("User selected endpoint that has the info: " + endpointInfo);
        LOG.debug("User selected endpoint that has the info: " + endpointInfo);

        //boolean isGlobusConnect = endpointInfo.endsWith("true");

        // FIXME: Cache from previous time we called this?
        // or reconstruct from the other format of them that we have?
        Vector<EndpointInfo> goEndpointInfos = transfer.listEndpoints();
        LOG.debug("Got endpointinfo again");

        // first pass, find all sources
        // we create a mapping of GO endpoints to Filelists

        for (String curURL : file_urls) {
            LOG.debug("curURL is:" + curURL);
            //pieces = curURL.split("//");
            pieces = curURL.split("://");
            //splite on :// instead, then the first / will separate host:port from path
            if ((pieces != null) && (pieces.length > 1)) {
                //goEP = Utils.lookupGOEPBasedOnGridFTPURL(pieces[1], goEndpointInfos, true);
                filePathIndex = pieces[1].indexOf("/");
                urlHost = pieces[1].substring(0, filePathIndex);
                LOG.debug("urlHost is " + urlHost + "\n");
                goEP = Utils.lookupGOEPBasedOnGridFTPURL(urlHost, goEndpointInfos, true);

                if (goEP == null) {
                    //goEP = Utils.lookupGOEPBasedOnGridFTPURL(pieces[1], goEndpointInfos, false);
                    goEP = Utils.lookupGOEPBasedOnGridFTPURL(urlHost, goEndpointInfos, true);
                }

                if (!sourceMap.containsKey(goEP)) {
                    //LOG.debug("Mapped GridFTP Server " + pieces[1] + " to GO EP " + goEP);
                    LOG.debug("Mapped GridFTP Server " + pieces[1] + " to GO EP " + goEP);
                    //System.out.println("Mapped GridFTP Server " + pieces[1] + " to GO EP " + goEP);
                    sourceEpToGFTPMap.put(goEP, pieces[1]);
                    sourceMap.put(goEP, new Vector<String>());
                }

                fileList = sourceMap.get(goEP);
                //newURL = "//" + pieces[2];
                //if(pieces.length = 2)
                //newUrl = "//" + pieces[2];
                //shouldn't need to add any leading slashes
                //newURL = "/" + pieces[1].substring(filePathIndex);
                newURL = pieces[1].substring(filePathIndex);

                LOG.debug("Transformed " + curURL + " into " + newURL);
                //System.out.println("Transformed " + curURL + " into " + newURL);
                fileList.add(newURL);
            } else {
                LOG.debug("Failed to split URL on //: " + curURL);
                //System.out.println("Failed to split URL on //: " + curURL);
            }
        }

        // For now we always just grab the first endpoint since we
        // can only handle a single source endpoint (per transfer)
        // ... break up into multiple transfers later when we
        // support transfers of multiple data sets at once
        LOG.debug("Finished Endpoint URL manipulation");
        Map.Entry<String, Vector<String>> entry = sourceMap.entrySet().iterator().next();
        String goSourceEndpoint = entry.getKey();
        Map.Entry<String, String> gftpEntry = sourceEpToGFTPMap.entrySet().iterator().next();
        String gftpServer = gftpEntry.getValue();

        LOG.debug("Got GO Source EP: " + goSourceEndpoint);
        LOG.debug("Got GFTP Server: " + gftpServer);
        if (goSourceEndpoint != null) {
            fileList = entry.getValue();
        } else {
            // create new endpoint using known information
            String srcEndpointInfo = "D^^" + gftpServer + "^^" + myproxyServerStr + "^^false";
            goSourceEndpoint = Utils.createGlobusOnlineEndpointFromEndpointInfo(transfer, goUserName,
                    srcEndpointInfo);
            createdSrcEndpoint = goSourceEndpoint;
        }

        LOG.debug("Using GO Source EP: " + goSourceEndpoint);
        //System.out.println("Using GO Source EP: " + goSourceEndpoint);

        errorStatus.append("Source endpoint resolved as \"");
        errorStatus.append(goSourceEndpoint);
        errorStatus.append("\".<br>");

        // first activate the source endpoint
        LOG.debug("Activating source endpoint " + goSourceEndpoint);
        //System.out.println("Activating source endpoint " + goSourceEndpoint);
        errorStatus.append("Attempting to activate Source Endpoint " + goSourceEndpoint + " ...<br>");
        try {
            // try the activation with the userCertificateFile
            transfer.activateEndpoint(goSourceEndpoint, userCertificateFile);
        } catch (Exception e) {
            //System.out.println("activation w/ userCert failed because:" + e.toString());
            //System.out.println("userCertificateFile:" +userCertificateFile);
            //
            model.put(GOFORMVIEW_ERROR, "crederror");
            //model.put(GOFORMVIEW_ERROR_MSG, error);
            //System.out.println("Failed to initialize transfer object to get user cert: " + e);
            return new ModelAndView("goauthview3", model);
        }
        errorStatus.append("Source Endpoint activated properly!<br>");
        //System.out.println("pSource Endpoint activated properly!<br>");

        String[] endpointPieces = endpointInfo.split("\\^\\^");
        String destEPName = endpointPieces[0];

        // kick off the transfer here!
        errorStatus.append("Attempting to start Globus Online Transfer ...<br>");

        String destpath = target + folder;
        //System.out.println("destpath is" + destpath);
        //System.out.println("goSourceEndpoint is" + goSourceEndpoint);
        //System.out.println("destEPName is" + destEPName);
        //System.out.println("fileList is" + fileList);

        //Need to modify JGOClient to pass label along
        String taskID = transfer.transfer(goSourceEndpoint, destEPName, fileList, destpath);
        if (taskID != null) {
            errorStatus.append("Globus Online Transfer got TaskID " + taskID + ".<br>");
            String transferInfo1 = "The transfer has been accepted and a task has been "
                    + "created and queued for execution.";
            String transferInfo2 = "Globus Online TaskID: " + taskID;
            LOG.debug("Started Globus Online transfer with TaskID: " + taskID);

            if (request.getParameter(GOFORMVIEW_MODEL) != null) {
            } else {
                model.put(GOFORMVIEW_TRANSFER_INFO1, transferInfo1);
                model.put(GOFORMVIEW_TRANSFER_INFO2, transferInfo2);
            }
        } else {
            String error = errorStatus.toString() + "<br><b>Main Error:</b><br><br>Transfer failed";
            model.put(GOFORMVIEW_ERROR, "error");
            model.put(GOFORMVIEW_ERROR_MSG, error);
            LOG.error("Failed to initiate Globus Online transfer.");
        }
    } catch (Exception e) {
        String error = errorStatus.toString() + "<br><b>Main Error:</b><br><br>" + e.toString();
        model.put(GOFORMVIEW_ERROR, "error");
        model.put(GOFORMVIEW_ERROR_MSG, error);
        LOG.error("Failed to initialize Globus Online: " + e);

        System.out.println("Trying to teardown created source endpoints ...");
        if (createdSrcEndpoint != null) {
            try {
                transfer.removeEndpoint(createdSrcEndpoint);
            } catch (Exception e1) {
            }
        }
        if (createdDestEndpoint != null) {
            try {
                transfer.removeEndpoint(createdDestEndpoint);
            } catch (Exception e2) {
            }
        }
        System.out.println("Attempted endpoint removal complete");
    }
    //make sure we put the cert back in the model so we can reuse it
    model.put(GOFORMVIEW_USER_CERTIFICATE, userCertificateFile);
    return new ModelAndView("goauth_transfer", model);
}

From source file:com.ChatEndpoint.java

@OnMessage
public void onMessage(final Session session, String msg) throws IOException {
    System.out.println(msg);//from www . ja  va  2  s .  com
    SesionWeb sesion = new SesionWeb(session);
    try {
        JSONObject objetoJSON = new JSONObject(msg);
        switch (getTipo(objetoJSON.getString("tipo"))) {
        /**
         * Inciar sesion por parte del cliente.
         */
        case LOGIN: {
            this.logear(session, objetoJSON);
        }
            break;
        /**
         * Al recibir algun mensaje(chat) del cliente.
         */
        case MENSAJE: {
            this.mensaje(session, objetoJSON);
        }
            break;
        /**
         * Cuando alguien toca el codigo js y el tipo mensaje no es uno
         * de los posibles.
         */
        case ERROR: {
            sesion.notificarError(TipoMensaje.ERROR, "Okey... Que intentas hacer? :(");
        }
            break;
        }
    } catch (JSONException e) {
        log.log(Level.INFO, "{0}Error de json ", e.toString());
        sesion.notificarError(TipoMensaje.ERROR, "Error sintaxis JSON. Mira la consola.");
    }
}