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:eu.bittrade.libs.steemj.protocol.operations.EscrowDisputeOperation.java

@Override
public void validate(ValidationType validationType) {
    if (!ValidationType.SKIP_VALIDATION.equals(validationType) && (!who.equals(from) || !who.equals(to))) {
        throw new InvalidParameterException(
                "The who account must be either the from account or the to account.");
    }/* w  w  w.j ava 2s  . c o  m*/
}

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

/**
 * Removes the Id property from a JsonObject
 * /*from   ww w  .  j a va  2 s.  c  o  m*/
 * @param json
 *            The JsonObject to modify
 */
private void removeIdFromJson(final JsonObject json) {
    // Remove id property if exists
    String[] idPropertyNames = new String[] { "id", "Id", "iD", "ID" };
    for (int i = 0; i < 4; i++) {
        String idProperty = idPropertyNames[i];
        if (json.has(idProperty)) {
            JsonElement idElement = json.get(idProperty);
            if (isValidTypeId(idElement) && idElement.getAsInt() != 0) {
                throw new InvalidParameterException(
                        "The entity to insert should not have " + idProperty + " property defined");
            }

            json.remove(idProperty);
        }
    }
}

From source file:org.nlp2rdf.webservice.NIFParameters.java

/**
 * Factory method/*from w  w w.j  av a  2 s  .c  o  m*/
 *
 * @param httpServletRequest
 * @return
 */
public static NIFParameters getInstance(HttpServletRequest httpServletRequest) {
    String requestUrl = httpServletRequest.getRequestURL().toString();
    try {

        //required Parameter input-type
        String input_type = requiredParameter("input-type", httpServletRequest, "text", "nif-owl");

        if (!isSet("input", httpServletRequest)) {
            throw new IllegalArgumentException("Missing parameter: input is required. ");
        }
        //optional parameters
        //note that nif=true is intentionally left out here, because it would be too late
        String prefix = "http://nlp2rdf.lod2.eu/nif/";
        String format = "rdfxml";
        String urirecipe = "offset";
        int contextLength = 10;
        //this is not in the nif 1.0 spec
        String output = "full";

        //prefix
        if (isSet("prefix", httpServletRequest)) {
            prefix = httpServletRequest.getParameter("prefix");
        }

        //format
        if (isSet("format", httpServletRequest)) {
            format = requiredParameter("format", httpServletRequest, "rdfxml", "turtle", "json", "ntriples",
                    "n3");
        }
        //urirecipe
        if (isSet("urirecipe", httpServletRequest)) {
            urirecipe = requiredParameter("urirecipe", httpServletRequest, "offset", "context-hash");
        }
        //contextLength
        if (isSet("context-length", httpServletRequest)) {
            contextLength = Integer.parseInt(httpServletRequest.getParameter("context-length"));
        }
        //output
        if (isSet("output", httpServletRequest)) {
            output = requiredParameter("output", httpServletRequest, "full", "diff");
        }

        Object input;
        //normalize input, i.e. fill the variables for text and model
        if (input_type.equals("text")) {
            log.trace("Handling type text");
            // read the text
            input = httpServletRequest.getParameter("input");
            //make a NIF model to work on
            //URIGenerator uriGenerator = ModelHelper.determineGenerator(urirecipe);
            //inputModel = new Text2RDF().processAsDocument(prefix, text, new FakeTokenizer(), uriGenerator);

            /**********************
             * NOTE that parsing another NIF model is a little bit harder than just the output so this reference implementation is not yet complete.
             * *********************/
        } else if (input_type.equals("nif-owl")) {
            // Read the model directly from the input
            OntModel inputModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM,
                    ModelFactory.createDefaultModel());
            ByteArrayInputStream bais = new ByteArrayInputStream(
                    httpServletRequest.getParameter("input").getBytes());
            try {
                inputModel.read(bais, "");
            } catch (JenaException e) {
                throw new InvalidParameterException(
                        "Jena could not read the presented nif-owl in RDF/XML format.\nFor the conversion of text \"input-type=text\" has to be set.");
            }
            input = inputModel;
        } else {
            throw new InvalidParameterException("third way in a binary path: maybe");
        }

        NIFParameters nifParameters = new NIFParameters(input, copyParameterMap(httpServletRequest), prefix,
                urirecipe, contextLength, format, output);
        log.trace("created NIFParameters instance from " + input_type + ": " + nifParameters.toString());
        return nifParameters;

    } catch (InvalidParameterException ipe) {
        throw new InvalidParameterException(ipe.getMessage() + getDocumentation(requestUrl));
    }
}

From source file:com.richtodd.android.quiltdesign.app.QuiltEditActivity.java

@Override
public void onAlertDialogPositiveClick(DialogFragment dialog, String key) throws Exception {

    if (key.equals(KEY_CONFIRM_DELETE)) {
        getQuiltEditFragment().setSaveSuppressed(true);

        Repository repository = Repository.getDefaultRepository(this);
        QuiltContainer quilts = repository.getQuilts();
        quilts.deleteQuilt(m_quiltNameArgument);

        finish();//from  ww w .j a  va 2  s .c o  m

    } else if (key.equals(KEY_FILE_EXISTS)) {
        showEditNameDialog();

    } else {
        throw new InvalidParameterException("Unknown key " + key);
    }
}

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

/**
 * Send request for file byte array// w  w  w.ja  v  a  2s  . c om
 * @param appKey String value Application key
 * @param getRowdata GetRowData object
 * @param bargraph String value for Analytics tag name
 * @param secure boolean value to set SSL communication
 * @param listener MobDBResponseListener object
 * @throws InvalidParameterException
 */
public synchronized void execute(String appKey, GetFile getFile, String bargraph, boolean secure,
        MobDBResponseListener listener) throws InvalidParameterException {

    try {
        executeFileRequest(appKey, new String[] { getFile.getQueryString() }, bargraph, secure, listener);
    } catch (Exception e) {

        throw new InvalidParameterException(e.toString());

    }

}

From source file:com.todoroo.astrid.voice.VoiceInputAssistant.java

/**
 * The param requestCode is used to differentiate between multiple
 * microphone-buttons on a single fragment.
 * Use the this constructor to specify your own requestCode in
 * this case for every additional use on a activity.
 * If you only use one microphone-button on a activity,
 * you can leave it to its default, VOICE_RECOGNITION_REQUEST_CODE.
 *
 *
 * @param activity/*from  www.  j av a  2s  .  c o m*/
 * @param voiceButton
 * @param textField
 * @param requestCode has to be unique in a single fragment-context,
 *   dont use VOICE_RECOGNITION_REQUEST_CODE, this is reserved for the other constructor
 */
public VoiceInputAssistant(Activity activity, ImageButton voiceButton, int requestCode) {
    this(activity, voiceButton);
    if (requestCode == VOICE_RECOGNITION_REQUEST_CODE)
        throw new InvalidParameterException(
                "You have to specify a unique requestCode for this VoiceInputAssistant!");
    this.requestCode = requestCode;
}

From source file:org.flite.cach3.aop.UpdateSingleCacheAdvice.java

static AnnotationInfo getAnnotationInfo(final UpdateSingleCache annotation,
        final String targetMethodName, final int jitterDefault) {
    final AnnotationInfo result = new AnnotationInfo();

    if (annotation == null) {
        throw new InvalidParameterException(
                String.format("No annotation of type [%s] found.", UpdateSingleCache.class.getName()));
    }/*  ww w  .  ja  v a 2s  . com*/

    final String namespace = annotation.namespace();
    if (AnnotationConstants.DEFAULT_STRING.equals(namespace) || namespace == null || namespace.length() < 1) {
        throw new InvalidParameterException(
                String.format("Namespace for annotation [%s] must be defined on [%s]",
                        UpdateSingleCache.class.getName(), targetMethodName));
    }
    result.add(new AType.Namespace(namespace));

    final String keyPrefix = annotation.keyPrefix();
    if (!AnnotationConstants.DEFAULT_STRING.equals(keyPrefix)) {
        if (StringUtils.isBlank(keyPrefix)) {
            throw new InvalidParameterException(String.format(
                    "KeyPrefix for annotation [%s] must not be defined as an empty string on [%s]",
                    UpdateSingleCache.class.getName(), targetMethodName));
        }
        result.add(new AType.KeyPrefix(keyPrefix));
    }

    final Integer keyIndex = annotation.keyIndex();
    if (keyIndex != AnnotationConstants.DEFAULT_KEY_INDEX && keyIndex < -1) {
        throw new InvalidParameterException(
                String.format("KeyIndex for annotation [%s] must be -1 or greater on [%s]",
                        UpdateSingleCache.class.getName(), targetMethodName));
    }
    final boolean keyIndexDefined = keyIndex >= -1;

    final String keyTemplate = annotation.keyTemplate();
    if (StringUtils.isBlank(keyTemplate)) {
        throw new InvalidParameterException(
                String.format("KeyTemplate for annotation [%s] must not be defined as an empty string on [%s]",
                        UpdateSingleCache.class.getName(), targetMethodName));
    }
    final boolean keyTemplateDefined = !AnnotationConstants.DEFAULT_STRING.equals(keyTemplate);

    if (keyIndexDefined == keyTemplateDefined) {
        throw new InvalidParameterException(String.format(
                "Exactly one of [keyIndex,keyTemplate] must be defined for annotation [%s] on [%s]",
                UpdateSingleCache.class.getName(), targetMethodName));
    }

    if (keyIndexDefined) {
        result.add(new AType.KeyIndex(keyIndex));
    }

    if (keyTemplateDefined) {
        result.add(new AType.KeyTemplate(keyTemplate));
    }

    final int dataIndex = annotation.dataIndex();
    if (dataIndex < -1) {
        throw new InvalidParameterException(
                String.format("DataIndex for annotation [%s] must be -1 or greater on [%s]",
                        UpdateSingleCache.class.getName(), targetMethodName));
    }
    result.add(new AType.DataIndex(dataIndex));

    final String dataTemplate = annotation.dataTemplate();
    if (!AnnotationConstants.DEFAULT_STRING.equals(dataTemplate)) {
        if (StringUtils.isBlank(dataTemplate)) {
            throw new InvalidParameterException(String.format(
                    "DataTemplate for annotation [%s] must not be defined as an empty string on [%s]",
                    UpdateMultiCache.class.getName(), targetMethodName));
        }
        result.add(new AType.DataTemplate(dataTemplate));
    }

    final Class dataTemplateType = annotation.dataTemplateType();
    if (!String.class.equals(dataTemplateType)) {
        result.add(new AType.DataTemplateType(dataTemplateType));
    }

    final int expiration = annotation.expiration();
    if (expiration < 0) {
        throw new InvalidParameterException(
                String.format("Expiration for annotation [%s] must be 0 or greater on [%s]",
                        UpdateSingleCache.class.getName(), targetMethodName));
    }
    result.add(new AType.Expiration(expiration));

    final int jitter = annotation.jitter();
    if (jitter < -1 || jitter > 99) {
        throw new InvalidParameterException(
                String.format("Jitter for annotation [%s] must be -1 <= jitter <= 99 on [%s]",
                        UpdateSingleCache.class.getName(), targetMethodName));
    }
    result.add(new AType.Jitter(jitter == -1 ? jitterDefault : jitter));

    return result;
}

From source file:org.apache.eagle.jpm.util.resourcefetch.RMResourceFetcher.java

private List<AppInfo> doFetchRunningApplicationsList(Constants.JobType jobType,
        Constants.CompressionType compressionType, Object... parameter) throws Exception {
    String limit = "";
    int requests = 1;
    int timeRangePerRequestInMin = 60;

    switch (parameter.length) {
    case 0://w  w w. j  a  va 2s  .c o m
        String urlString = getRunningJobURL(jobType, null, null, null);
        return doFetchApplicationsList(urlString, compressionType);
    case 1:
        limit = String.valueOf(parameter[0]);
        break;
    case 2:
        limit = String.valueOf(parameter[0]);
        requests = (int) parameter[1];
        break;
    case 3:
        limit = String.valueOf(parameter[0]);
        requests = (int) parameter[1];
        timeRangePerRequestInMin = (int) parameter[2];
        break;
    default:
        throw new InvalidParameterException("parameter list: limit, requests, requestTimeRange");
    }

    if (requests <= 1) {
        String urlString = getRunningJobURL(jobType, null, null, limit);
        return doFetchApplicationsList(urlString, compressionType);
    }

    long interval = timeRangePerRequestInMin * DateTimeUtil.ONEMINUTE;
    long currentTime = System.currentTimeMillis() - interval;

    List<String> requestUrls = new ArrayList<>();
    requestUrls.add(getRunningJobURL(jobType, String.valueOf(currentTime), null, limit));

    for (int cnt = 2; cnt < requests; cnt++) {
        long start = currentTime - interval;
        requestUrls.add(getRunningJobURL(jobType, String.valueOf(start), String.valueOf(currentTime), limit));
        currentTime -= interval;
    }

    requestUrls.add(getRunningJobURL(jobType, null, String.valueOf(currentTime), limit));
    LOG.info("{} requests to fetch running MapReduce applications: \n{}", requestUrls.size(),
            StringUtils.join(requestUrls, "\n"));

    Map<String, AppInfo> result = new HashMap();
    for (String query : requestUrls) {
        doFetchApplicationsList(query, compressionType).forEach(app -> result.put(app.getId(), app));
    }
    List<AppInfo> apps = new ArrayList<>();
    apps.addAll(result.values());
    return apps;
}

From source file:org.openanzo.jdbc.opgen.RdbStatement.java

private void initialize() {
    if (results == null)
        results = Result.NONE;/*ww w  .ja va 2 s.co  m*/
    if (results == Result.ROW && outputs.size() <= 1)
        throw new InvalidParameterException(name
                + ": ROW return type not allowed when there is zero or one outputs, use VALUE or ITERATOR instead.");
    if (results == Result.COUNTER && outputs.size() > 0)
        throw new InvalidParameterException(name
                + ": COUNTER return type not allowed when there is one our more outputs, use VALUE,ROW or ITERATOR instead.");
}

From source file:org.cloudifysource.rest.ControllerTest.java

/**
 * This method finds the handler for a given request URI. It will also ensure that the URI Parameters i.e.
 * /context/test/{name} are added to the request
 *
 * @param request/* w w  w  .j  a v  a  2 s .c  o m*/
 *            The request object to be used
 * @return The correct handler for the request
 * @throws Exception
 *             Indicates a matching handler could not be found
 */
private HandlerExecutionChain getHandlerToRequest(final MockHttpServletRequest request) throws Exception {
    HandlerExecutionChain chain = null;

    final Map<String, HandlerMapping> map = applicationContext.getBeansOfType(HandlerMapping.class);

    for (final HandlerMapping mapping : map.values()) {
        chain = mapping.getHandler(request);

        if (chain != null) {
            break;
        }
    }

    if (chain == null) {
        throw new InvalidParameterException(
                "Unable to find handler for request URI: " + request.getRequestURI());
    }
    return chain;
}