Example usage for java.security InvalidParameterException InvalidParameterException

List of usage examples for java.security InvalidParameterException InvalidParameterException

Introduction

In this page you can find the example usage for java.security InvalidParameterException InvalidParameterException.

Prototype

public InvalidParameterException(String msg) 

Source Link

Document

Constructs an InvalidParameterException with the specified detail message.

Usage

From source file:org.lsc.SimpleSynchronize.java

/**
 * Launch a task. Call this for once each task type and task mode.
 *
 * @param taskName/*from  ww w  .  ja  va  2 s .c  om*/
 *                the task name (historically the LDAP object class name, but can be any string)
 * @param taskMode
 *                the task mode (clean or sync)
 *
 * @return boolean true on success, false if an error occurred
 * @throws Exception
 */
private boolean launchTask(final Task task, final Task.Mode taskMode) throws Exception {
    boolean status = true;

    addScriptingContext(task);

    try {
        LSCStructuralLogger.DESTINATION.info("Starting {} for {}", taskMode.name(), task.getName());
        // Do the work!
        switch (taskMode) {
        case clean:
            status = clean2Ldap(task);
            break;
        case sync:
            status = synchronize2Ldap(task);
            break;
        case async:
            if (task.getSourceService() instanceof IAsynchronousService
                    || task.getDestinationService() instanceof IAsynchronousService) {
                startAsynchronousSynchronize2Ldap(task);
            } else {
                LOGGER.error("Requested asynchronous source service does not implement IAsynchronousService ! ("
                        + task.getSourceService().getClass().getName() + ")");
            }
            break;
        default:
            //Should not happen
            LOGGER.error("Unknown task mode type {}", taskMode.toString());
            throw new InvalidParameterException("Unknown task mode type " + taskMode.toString());
        }

        // Manage exceptions
    } catch (Exception e) {
        Class<?>[] exceptionsCaught = { InstantiationException.class, IllegalAccessException.class,
                ClassNotFoundException.class, SecurityException.class, NoSuchMethodException.class,
                IllegalArgumentException.class, InvocationTargetException.class };

        if (ArrayUtils.contains(exceptionsCaught, e.getClass())) {
            String errorDetail;
            if (e instanceof InvocationTargetException && e.getCause() != null) {
                errorDetail = e.getCause().toString();
            } else {
                errorDetail = e.toString();
            }

            LOGGER.error("Error while launching task \"{}\". Please check your configuration! ({})",
                    task.getName(), errorDetail);
            LOGGER.debug(e.toString(), e);
            return false;
        }
        throw e;
    }

    return status;
}

From source file:com.azure.webapi.MobileServiceTableBase.java

/**
 * Gets the id property from a given element
 * //from w w w .j a  v  a  2  s  .  c  o  m
 * @param element
 *            The element to use
 * @return The id of the element
 */
protected int getObjectId(Object element) {
    if (element == null) {
        throw new InvalidParameterException("Element cannot be null");
    } else if (element instanceof Integer) {
        return ((Integer) element).intValue();
    }

    JsonObject jsonObject;
    if (element instanceof JsonObject) {
        jsonObject = (JsonObject) element;
    } else {
        jsonObject = mClient.getGsonBuilder().create().toJsonTree(element).getAsJsonObject();
    }

    updateIdProperty(jsonObject);

    JsonElement idProperty = jsonObject.get("id");
    if (idProperty instanceof JsonNull || idProperty == null) {
        throw new InvalidParameterException("Element must contain id property");
    }

    return idProperty.getAsInt();
}

From source file:net.blogracy.controller.MediaController.java

/**
 * Gets the images from recordDb given the userId and the associated
 * albumId. Attempts to download the images from DHT. If successful, set's
 * the URL with the cached image link/*from ww  w .ja v a  2  s  .co  m*/
 * 
 * @param userId
 * @param albumId
 * @return
 */
public List<MediaItem> getMediaItemsWithCachedImages(String userId, String albumId) {

    if (userId == null)
        throw new InvalidParameterException("userId cannot be null");

    if (albumId == null)
        throw new InvalidParameterException("albumId cannot be null");

    List<MediaItem> mediaItems = this.getMediaItems(userId, albumId);

    for (MediaItem item : mediaItems) {
        String itemMagneUri = item.getUrl();
        sharing.download(itemMagneUri);
        item.setUrl("cache/" + sharing.getHashFromMagnetURI(itemMagneUri));
    }

    return mediaItems;
}

From source file:com.mobdb.android.MobDB.java

/**
 * Send request for file byte array/*  ww w  . jav a2s .  c om*/
 * @param appKey Application key
 * @param sql_query SQL string array 
 * @param bargraph Analytics tag name
 * @param boolean value to set for SSL communication
 * @param listener MobDBResponseListener class object     
 * @throws InvalidParameterException
 */
public synchronized void execute(String appKey, String[] sql_query, Object[] parameter, String bargraph,
        boolean secure, MobDBResponseListener listener) throws InvalidParameterException {
    try {

        JSONObject req = new JSONObject();

        if (appKey == null) {
            throw new InvalidParameterException("Application key required");
        }

        req.put(SDKConstants.KEY, appKey);

        if (bargraph != null) {
            req.put(SDKConstants.BAR_GRAPH, bargraph);
        }

        JSONObject sql = new JSONObject();
        JSONArray quary = new JSONArray();

        if (sql_query == null) {
            throw new InvalidParameterException("SQL query required");
        }

        for (int i = 0; i < sql_query.length; i++) {
            quary.put(sql_query[i]);
        }

        if (sql_query.length == 1 && parameter != null) {

            JSONArray param = new JSONArray();

            for (int i = 0; i < parameter.length; i++) {

                if (MobDBJSONHandler.getDataType(parameter[i]) == SDKConstants.STRING) {

                    param.put(String.valueOf(parameter[i]));

                } else if (MobDBJSONHandler.getDataType(parameter[i]) == SDKConstants.INTEGER) {

                    param.put((Integer) parameter[i]);

                } else if (MobDBJSONHandler.getDataType(parameter[i]) == SDKConstants.FLOAT) {

                    param.put((Float) parameter[i]);

                } else if (MobDBJSONHandler.getDataType(parameter[i]) == SDKConstants.FILE) {

                    param.put((JSONObject) parameter[i]);

                }

            }

            sql.put(SDKConstants.PARAM, param);

        } else if (sql_query.length > 1 && parameter != null) {

            throw new InvalidParameterException("In multi query request parameter is not allowed");

        }

        sql.put(SDKConstants.QUERY, quary);
        req.put(SDKConstants.SQL, sql);

        MobDBRequest request = new MobDBRequest(secure, listener);
        request.setParams(req.toString());
        requestQueue.add(request);
        executeRequest();

    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:no.barentswatch.fiskinfo.MyPageActivity.java

private int getSubscriptionIconId(String subscriptionName) {
    int retVal = 0;

    switch (subscriptionName) {
    case "Redskap":
        retVal = R.drawable.ikon_kystfiske;
        break;//from   w  w w .j a v a2 s.  c  om
    case "Iskant":
        retVal = R.drawable.ikon_is_tjenester;
        break;
    case "Havbunnsinstallasjoner":
        retVal = R.drawable.ikon_kart_til_din_kartplotter;
        break;
    case "Seismikk, planlagt":
        retVal = R.drawable.ikon_olje_og_gass;
        break;
    case "Seismikk, pgende":
        retVal = R.drawable.ikon_olje_og_gass;
        break;
    default:
        throw new InvalidParameterException("Parameter '" + subscriptionName + "' is not recognised.");
    }

    return retVal;
}

From source file:org.moe.cli.manager.SourceCocoaPodsManager.java

private void extractXCodeProject() throws IOException {
    InputStream resStream = null;
    ZipInputStream zis = null;//from   w w w.j ava 2  s.co m
    try {
        ClassLoader cl = this.getClass().getClassLoader();
        resStream = cl.getResourceAsStream("template.xcodeproj.zip");
        if (resStream != null) {
            zis = new ZipInputStream(resStream);
            ZipEntry entry;
            while ((entry = zis.getNextEntry()) != null) {
                if (entry.isDirectory()) {
                    File newDir = new File(JPod, entry.getName());
                    if (!newDir.exists()) {
                        newDir.mkdirs();
                    }
                } else {
                    File newDest = new File(JPod, entry.getName());
                    FileOutputStream output = null;
                    try {
                        output = new FileOutputStream(newDest);
                        byte[] buffer = new byte[1024];
                        int len = 0;
                        while ((len = zis.read(buffer)) > 0) {
                            output.write(buffer, 0, len);
                        }
                    } finally {
                        if (output != null) {
                            output.close();
                        }
                    }

                }
            }
        } else {
            throw new InvalidParameterException("Could not find Xcode project in resources");
        }
    } finally {
        if (resStream != null) {
            resStream.close();
        }

        if (zis != null) {
            zis.close();
        }
    }
}

From source file:eisene.riskspeedtools.BattleFrag.java

/**
 * Sets the correct dice picture to the ImageView.
 * @param view The dice imageview.//from  w w w.j a  va2  s . c  o  m
 * @param value The dice value.
 * @param isRed Whether the dice lost or won.
 */
private void setDiceValue(ImageView view, int value, boolean isRed) {
    int toDraw;
    switch (value) {
    case 0:
        toDraw = R.drawable.blank_die;
        break;
    case 1:
        toDraw = (isRed) ? R.drawable.red_die1 : R.drawable.die1;
        break;
    case 2:
        toDraw = (isRed) ? R.drawable.red_die2 : R.drawable.die2;
        break;
    case 3:
        toDraw = (isRed) ? R.drawable.red_die3 : R.drawable.die3;
        break;
    case 4:
        toDraw = (isRed) ? R.drawable.red_die4 : R.drawable.die4;
        break;
    case 5:
        toDraw = (isRed) ? R.drawable.red_die5 : R.drawable.die5;
        break;
    case 6:
        toDraw = (isRed) ? R.drawable.red_die6 : R.drawable.die6;
        break;
    default:
        throw new InvalidParameterException("Invalid dice value");
    }

    view.setImageResource(toDraw);
}

From source file:org.zaproxy.zap.extension.ascan.ExtensionActiveScan.java

@Override
public int startScan(String name, Target target, User user, Object[] contextSpecificObjects) {
    if (name == null) {
        name = target.getDisplayName();//from   w w w.j av a2s.c om
    }

    switch (Control.getSingleton().getMode()) {
    case safe:
        throw new InvalidParameterException("Scans are not allowed in Safe mode");
    case protect:
        List<StructuralNode> nodes = target.getStartNodes();
        if (nodes != null) {
            for (StructuralNode node : nodes) {
                if (node instanceof StructuralSiteNode) {
                    SiteNode siteNode = ((StructuralSiteNode) node).getSiteNode();
                    if (!siteNode.isIncludedInScope()) {
                        throw new InvalidParameterException(
                                "Scans are not allowed on nodes not in scope Protected mode "
                                        + target.getStartNode().getHierarchicNodeName());
                    }
                }
            }
        }
        // No problem
        break;
    case standard:
        // No problem
        break;
    case attack:
        // No problem
        break;
    }

    int id = this.ascanController.startScan(name, target, user, contextSpecificObjects);
    if (View.isInitialised()) {
        ActiveScan scanner = this.ascanController.getScan(id);
        scanner.addScannerListener(getActiveScanPanel()); // So the UI get updated
        this.getActiveScanPanel().scannerStarted(scanner);
        this.getActiveScanPanel().switchView(scanner);
        this.getActiveScanPanel().setTabFocus();
    }
    return id;
}

From source file:com.kimbrelk.da.oauth2.OAuth2.java

public final Response requestAuthToken(AuthGrantType grantType, String code, String redirectUri) {
    Map<String, String> params = new HashMap<String, String>();
    params.put("client_id", mClientCredentials.getId() + "");
    params.put("client_secret", mClientCredentials.getSecret());
    params.put("grant_type", grantType.toString().toLowerCase());
    switch (grantType) {
    case CLIENT_CREDENTIALS: {
        break;//from   w ww.  j ava2 s . com
    }
    case AUTHORIZATION_CODE: {
        if (code == null) {
            throw new InvalidParameterException("Parameter code cannot be null when using the CODE grantType.");
        }
        if (redirectUri == null) {
            throw new InvalidParameterException(
                    "Parameter redirectUri cannot be null when using the CODE grantType.");
        }
        params.put("code", code);
        params.put("redirect_uri", redirectUri);
        break;
    }
    case REFRESH_TOKEN: {
        if (code == null) {
            throw new InvalidParameterException(
                    "Parameter code cannot be null when using the REFRESH_TOKEN grantType.");
        }
        params.put("refresh_token", code);
        break;
    }
    default: {
        throw new InvalidParameterException("Unsupported grantType: " + grantType);
    }
    }

    JSONObject json = requestJSON(Verb.GET, createURL(ENDPOINTS.OAUTH2_TOKEN, params));
    Response response = null;
    try {
        if (json.getString("status").equalsIgnoreCase("error")) {
            response = new RespError(json);
        } else {
            if (grantType == AuthGrantType.CLIENT_CREDENTIALS) {
                response = new RespToken(json.getInt("expires_in"), json.getString("access_token"), null);
            } else {
                String[] parse = json.getString("scope").replace(".", "_").toUpperCase().split("[ ]+");
                Scope scopes[] = new Scope[parse.length];
                for (int a = 0; a < parse.length; a++) {
                    try {
                        scopes[a] = Scope.valueOf(parse[a]);
                    } catch (IllegalArgumentException e) {
                        scopes[a] = null;
                        e.printStackTrace();
                    }
                }
                response = new RespToken(json.getInt("expires_in"), json.getString("access_token"),
                        json.getString("refresh_token"), scopes);
            }
            mToken = (RespToken) response;
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return response;
}

From source file:net.blogracy.controller.MediaController.java

/***
 * Add multiple MediaItems to an album. It updates the user's recordDb and
 * notifies the action in the user's Activity Stream (verb: add)
 * /*from  ww  w.j av a 2s.c  om*/
 * @param userId
 * @param albumId
 * @param photos
 * @return
 */
public synchronized List<String> addMediaItemsToAlbum(String userId, String albumId, Map<File, String> photos) {
    if (photos == null)
        return null;

    if (userId == null)
        throw new InvalidParameterException("userId cannot be null");

    if (albumId == null)
        throw new InvalidParameterException("albumId cannot be null");

    Album album = null;
    for (Album a : this.getAlbums(userId)) {
        if (a.getId().equals(albumId)) {
            album = a;
            break;
        }
    }

    if (album == null)
        throw new InvalidParameterException(
                "AlbumId " + albumId + " does not match to a valid album for the user " + userId);

    List<String> hashList = new ArrayList<String>();
    List<MediaItem> listOfMediaItems = new ArrayList<MediaItem>();

    final List<ActivityEntry> feed = activities.getFeed(userId);
    final String publishedDate = ISO_DATE_FORMAT.format(new Date());

    try {

        for (Entry<File, String> mapEntry : photos.entrySet()) {
            File photo = mapEntry.getKey();
            String mimeType = mapEntry.getValue();
            String fileHash = sharing.hash(photo);

            final File photoCachedFile = new File(CACHE_FOLDER + File.separator + fileHash);

            FileUtils.copyFile(photo, photoCachedFile);
            photo.delete();

            final String fileUrl = sharing.seed(photoCachedFile);

            final ActivityEntry entry = new ActivityEntryImpl();
            entry.setVerb("add");
            entry.setPublished(publishedDate);
            entry.setContent(sharing.getHashFromMagnetURI(fileUrl));

            ActivityObject mediaItemObject = new ActivityObjectImpl();
            mediaItemObject.setObjectType("image");
            mediaItemObject.setContent(sharing.getHashFromMagnetURI(fileUrl));
            mediaItemObject.setUrl(fileUrl);
            entry.setObject(mediaItemObject);

            ActivityObject mediaAlbumObject = new ActivityObjectImpl();
            mediaAlbumObject.setObjectType("collection");
            mediaAlbumObject.setContent(album.getTitle());
            mediaAlbumObject.setId(album.getId());
            entry.setTarget(mediaAlbumObject);

            feed.add(0, entry);

            MediaItem mediaItem = new MediaItemImpl();
            mediaItem.setAlbumId(albumId);
            mediaItem.setId(sharing.getHashFromMagnetURI(fileUrl));
            mediaItem.setUrl(fileUrl);
            mediaItem.setLastUpdated(publishedDate);
            mediaItem.setMimeType(mimeType);

            if (album.getMediaMimeType() == null)
                album.setMediaMimeType(new ArrayList<String>());

            List<String> albumMimeTypes = album.getMediaMimeType();

            if (!albumMimeTypes.contains(mimeType))
                albumMimeTypes.add(mimeType);

            listOfMediaItems.add(mediaItem);
            hashList.add(sharing.getHashFromMagnetURI(fileUrl));
        }

        album.setMediaItemCount(album.getMediaItemCount() + photos.size());

        String feedUri = activities.seedActivityStream(userId, feed);

        // Update the album accordingly
        JSONObject recordDb = DistributedHashTable.getSingleton().getRecord(userId);

        if (recordDb == null)
            recordDb = new JSONObject();

        JSONArray albums = recordDb.optJSONArray("albums");

        for (int i = 0; i < albums.length(); ++i) {
            JSONObject singleAlbumObject = albums.getJSONObject(i);
            Album entry1 = (Album) CONVERTER.convertToObject(singleAlbumObject, Album.class);

            if (entry1.getId().equals(albumId)) {
                albums.put(i, new JSONObject(CONVERTER.convertToString(album)));
                break;
            }
        }

        // Add all the newly created mediaItems
        JSONArray mediaItems = recordDb.optJSONArray("mediaItems");

        if (mediaItems == null)
            mediaItems = new JSONArray();

        for (MediaItem mediaItem : listOfMediaItems) {
            // Simply append new album
            mediaItems.put(new JSONObject(CONVERTER.convertToString(mediaItem)));
        }

        DistributedHashTable.getSingleton().store(userId, feedUri, publishedDate, albums, mediaItems);

        return hashList;

    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}