Search in sources :

Example 26 with ClientException

use of edu.umass.cs.gnscommon.exceptions.client.ClientException in project GNS by MobilityFirst.

the class GroupSingleAddTest method test_210_GroupCreate.

/**
   *
   */
@Test
public void test_210_GroupCreate() {
    String mygroupName = "mygroup" + RandomString.randomString(12);
    try {
        try {
            clientCommands.lookupGuid(mygroupName);
            Utils.failWithStackTrace(mygroupName + " entity should not exist");
        } catch (ClientException e) {
        }
        mygroupEntry = clientCommands.guidCreate(masterGuid, mygroupName);
    } catch (IOException | ClientException e) {
        Utils.failWithStackTrace("Exception while creating guids: ", e);
    }
}
Also used : RandomString(edu.umass.cs.gnscommon.utils.RandomString) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) IOException(java.io.IOException) Test(org.junit.Test) DefaultGNSTest(edu.umass.cs.gnsserver.utils.DefaultGNSTest)

Example 27 with ClientException

use of edu.umass.cs.gnscommon.exceptions.client.ClientException in project GNS by MobilityFirst.

the class AccountDelete method parse.

@Override
public void parse(String commandText) throws Exception {
    StringTokenizer st = new StringTokenizer(commandText.trim());
    if ((st.countTokens() != 1)) {
        wrongArguments();
        return;
    }
    String aliasName = st.nextToken();
    try {
        GNSClientCommands gnsClient = module.getGnsClient();
        try {
            gnsClient.lookupGuid(aliasName);
        } catch (IOException | ClientException expected) {
            printString("Alias " + aliasName + " doesn't exist.\n");
            return;
        }
        GuidEntry myGuid = KeyPairUtils.getGuidEntry(module.getGnsInstance(), aliasName);
        if (myGuid == null) {
            printString("Unable to retrieve GUID for alias " + aliasName + "\n");
            return;
        }
        gnsClient.accountGuidRemove(myGuid);
        KeyPairUtils.removeKeyPair(module.getGnsInstance(), aliasName);
        module.setCurrentGuidAndCheckForVerified(null);
        module.setPromptString(ConsoleModule.CONSOLE_PROMPT + ">");
        if (!module.isSilent()) {
            printString("Removed account GUID " + myGuid.getGuid() + "\n");
        }
    } catch (ClientException | IOException e) {
        printString("Failed to delete guid ( " + e + ")\n");
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) GNSClientCommands(edu.umass.cs.gnsclient.client.GNSClientCommands) IOException(java.io.IOException) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) GuidEntry(edu.umass.cs.gnsclient.client.util.GuidEntry)

Example 28 with ClientException

use of edu.umass.cs.gnscommon.exceptions.client.ClientException in project GNS by MobilityFirst.

the class GuidLookup method parse.

@Override
public void parse(String commandText) throws Exception {
    try {
        StringTokenizer st = new StringTokenizer(commandText.trim());
        if (st.countTokens() != 1) {
            wrongArguments();
            return;
        }
        String alias = st.nextToken();
        GNSClientCommands gnsClient = module.getGnsClient();
        String value = gnsClient.lookupGuid(alias);
        console.printString(alias + " has GUID " + value);
        console.printNewline();
    } catch (IOException | ClientException e) {
        console.printString("Failed to access GNS ( " + e + ")\n");
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) GNSClientCommands(edu.umass.cs.gnsclient.client.GNSClientCommands) IOException(java.io.IOException) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException)

Example 29 with ClientException

use of edu.umass.cs.gnscommon.exceptions.client.ClientException in project GNS by MobilityFirst.

the class GroupMemberAdd method parse.

@Override
public void parse(String commandText) throws Exception {
    GNSClientCommands gnsClient = module.getGnsClient();
    try {
        StringTokenizer st = new StringTokenizer(commandText.trim());
        String groupGuid;
        switch(st.countTokens()) {
            case 1:
                groupGuid = module.getCurrentGuid().getGuid();
                break;
            case 2:
                groupGuid = st.nextToken();
                if (!StringUtil.isValidGuidString(groupGuid)) {
                    // We probably have an alias, lookup the GUID
                    groupGuid = gnsClient.lookupGuid(groupGuid);
                }
                break;
            default:
                wrongArguments();
                return;
        }
        String guidToAdd = st.nextToken();
        gnsClient.groupAddGuid(groupGuid, guidToAdd, module.getCurrentGuid());
        printString("GUID " + guidToAdd + " added to group " + groupGuid + "\n");
    } catch (IOException | ClientException e) {
        printString("Failed to access GNS ( " + e + ")\n");
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) GNSClientCommands(edu.umass.cs.gnsclient.client.GNSClientCommands) IOException(java.io.IOException) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException)

Example 30 with ClientException

use of edu.umass.cs.gnscommon.exceptions.client.ClientException in project GNS by MobilityFirst.

the class GroupMemberList method parse.

@Override
public void parse(String commandText) throws Exception {
    GNSClientCommands gnsClient = module.getGnsClient();
    try {
        StringTokenizer st = new StringTokenizer(commandText.trim());
        String groupGuid;
        switch(st.countTokens()) {
            case 0:
                groupGuid = module.getCurrentGuid().getGuid();
                break;
            case 1:
                groupGuid = st.nextToken();
                if (!StringUtil.isValidGuidString(groupGuid)) {
                    // We probably have an alias, lookup the GUID
                    groupGuid = gnsClient.lookupGuid(groupGuid);
                }
                break;
            default:
                wrongArguments();
                return;
        }
        console.printString("Members in group " + groupGuid);
        console.printNewline();
        JSONArray members = gnsClient.groupGetMembers(groupGuid, module.getCurrentGuid());
        for (int i = 0; i < members.length(); i++) {
            console.printString(i + ": " + members.getString(i));
            console.printNewline();
        }
    } catch (IOException | ClientException | JSONException e) {
        console.printString("Failed to access GNS ( " + e + ")\n");
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) GNSClientCommands(edu.umass.cs.gnsclient.client.GNSClientCommands) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) IOException(java.io.IOException) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException)

Aggregations

ClientException (edu.umass.cs.gnscommon.exceptions.client.ClientException)239 IOException (java.io.IOException)215 Test (org.junit.Test)134 JSONException (org.json.JSONException)126 DefaultGNSTest (edu.umass.cs.gnsserver.utils.DefaultGNSTest)125 RandomString (edu.umass.cs.gnscommon.utils.RandomString)113 JSONArray (org.json.JSONArray)74 GuidEntry (edu.umass.cs.gnsclient.client.util.GuidEntry)71 JSONObject (org.json.JSONObject)59 GNSClientCommands (edu.umass.cs.gnsclient.client.GNSClientCommands)40 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)37 StringTokenizer (java.util.StringTokenizer)30 EncryptionException (edu.umass.cs.gnscommon.exceptions.client.EncryptionException)23 BasicGuidEntry (edu.umass.cs.gnsclient.client.util.BasicGuidEntry)20 FieldNotFoundException (edu.umass.cs.gnscommon.exceptions.client.FieldNotFoundException)19 FileNotFoundException (java.io.FileNotFoundException)18 InternalRequestException (edu.umass.cs.gnscommon.exceptions.server.InternalRequestException)15 ResponseCode (edu.umass.cs.gnscommon.ResponseCode)13 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)13 InvalidKeyException (java.security.InvalidKeyException)12