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:com.predic8.membrane.core.interceptor.rest.RESTInterceptor.java

private Outcome dispatchRequest(Exchange exc) throws Exception {
    String path = router.getUriFactory().create(exc.getDestinations().get(0)).getPath();
    for (Method m : getClass().getMethods()) {
        Mapping a = m.getAnnotation(Mapping.class);
        if (a == null)
            continue;
        Matcher matcher = Pattern.compile(a.value()).matcher(path);
        if (matcher.matches()) {
            Object[] parameters;/*from  w  ww .  j a  v a  2s .  co m*/
            switch (m.getParameterTypes().length) {
            case 2:
                parameters = new Object[] {
                        new QueryParameter(URLParamUtil.getParams(router.getUriFactory(), exc), matcher),
                        getRelativeRootPath(path) };
                break;
            case 3:
                parameters = new Object[] {
                        new QueryParameter(URLParamUtil.getParams(router.getUriFactory(), exc), matcher),
                        getRelativeRootPath(path), exc };
                break;
            default:
                throw new InvalidParameterException("@Mapping is supposed to annotate a 2-parameter method.");
            }
            exc.setResponse((Response) m.invoke(this, parameters));
            return Outcome.RETURN;
        }
    }
    return Outcome.CONTINUE;
}

From source file:edu.chalmers.dat255.audiobookplayer.model.Track.java

public void setSelectedTrackElapsedTime(int elapsedTime) {
    if (elapsedTime > duration) {
        Log.e(TAG, "elapsedTime (" + elapsedTime + ") set to duration (" + duration + ")");
        this.elapsedTime = duration;
    } else if (elapsedTime >= 0) {
        this.elapsedTime = elapsedTime;
    } else {/*from   w  w  w .  jav a2 s. c o  m*/
        throw new InvalidParameterException("Attempting to set elapsed time to a negative value.");
    }
}

From source file:net.nelz.simplesm.aop.InvalidateSingleCacheAdvice.java

@Around("invalidateSingle()")
public Object cacheInvalidateSingle(final ProceedingJoinPoint pjp) throws Throwable {
    // This is injected caching.  If anything goes wrong in the caching, LOG the crap outta it,
    // but do not let it surface up past the AOP injection itself.
    String cacheKey = null;/*from  w w w  .j  ava 2 s . c  om*/
    final AnnotationData annotationData;
    try {
        final Method methodToCache = getMethodToCache(pjp);
        final InvalidateSingleCache annotation = methodToCache.getAnnotation(InvalidateSingleCache.class);
        annotationData = AnnotationDataBuilder.buildAnnotationData(annotation, InvalidateSingleCache.class,
                methodToCache);
        if (annotationData.getKeyIndex() > -1) {
            final Object keyObject = getIndexObject(annotationData.getKeyIndex(), pjp, methodToCache);
            final Method keyMethod = getKeyMethod(keyObject);
            final String objectId = generateObjectId(keyMethod, keyObject);
            cacheKey = buildCacheKey(objectId, annotationData);
        }
    } catch (Throwable ex) {
        LOG.warn("Caching on " + pjp.toShortString() + " aborted due to an error.", ex);
        return pjp.proceed();
    }

    final Object result = pjp.proceed();

    // This is injected caching.  If anything goes wrong in the caching, LOG the crap outta it,
    // but do not let it surface up past the AOP injection itself.
    try {
        // If we have a -1 key index, then build the cacheKey now.
        if (annotationData.getKeyIndex() == -1) {
            final Method keyMethod = getKeyMethod(result);
            final String objectId = generateObjectId(keyMethod, result);
            cacheKey = buildCacheKey(objectId, annotationData);
        }
        if (cacheKey == null || cacheKey.trim().length() == 0) {
            throw new InvalidParameterException("Unable to find a cache key");
        }
        cache.delete(cacheKey);
    } catch (Throwable ex) {
        LOG.warn("Caching on " + pjp.toShortString() + " aborted due to an error.", ex);
    }
    return result;
}

From source file:org.teknux.jettybootstrap.test.jettybootstrap.AbstractJettyBootstrapTest.java

protected int getPort() throws JettyBootstrapException {
    if (jettyBootstrap == null) {
        throw new InvalidParameterException("Server not started!");
    }/*  w  ww  .j  a  v a  2  s.  co m*/
    // return port jetty is currently running
    return ((ServerConnector) jettyBootstrap.getServer().getConnectors()[0]).getLocalPort();
}

From source file:com.sayar.requests.impl.HttpClientRequestHandler.java

public Response execute(final RequestArguments args) throws AuthenticationException, InvalidParameterException {
    // Parse params
    final String url = args.getUrl();
    final Map<String, String> params = args.getParams();
    final HttpAuthentication httpAuth = args.getHttpAuth();

    String formattedUrl;//from   w ww . j  a  va 2 s .  com
    try {
        formattedUrl = RequestHandlerUtils.formatUrl(url, params);
    } catch (final UnsupportedEncodingException e) {
        Log.e(RequestsConstants.LOG_TAG, "Unsupported Encoding Exception in Url Parameters.", e);
        throw new InvalidParameterException("Url Parameter Encoding is invalid.");

    }

    final RequestMethod method = args.getMethod();
    HttpUriRequest request = null;
    if (method == RequestMethod.GET) {
        request = new HttpGet(formattedUrl);
    } else if (method == RequestMethod.DELETE) {
        request = new HttpDelete(formattedUrl);
    } else if (method == RequestMethod.OPTIONS) {
        request = new HttpOptions(formattedUrl);
    } else if (method == RequestMethod.HEAD) {
        request = new HttpHead(formattedUrl);
    } else if (method == RequestMethod.TRACE) {
        request = new HttpTrace(formattedUrl);
    } else if (method == RequestMethod.POST || method == RequestMethod.PUT) {
        request = method == RequestMethod.POST ? new HttpPost(formattedUrl) : new HttpPut(formattedUrl);
        if (args.getRequestEntity() != null) {
            ((HttpEntityEnclosingRequestBase) request).setEntity(args.getRequestEntity());
        }
    } else {
        throw new InvalidParameterException("Request Method is not set.");
    }

    if (httpAuth != null) {
        try {
            HttpClientRequestHandler.addAuthentication(request, httpAuth);
        } catch (final AuthenticationException e) {
            Log.e(RequestsConstants.LOG_TAG, "Adding Authentication Failed.", e);
            throw e;
        }
    }
    if (args.getHeaders() != null) {
        HttpClientRequestHandler.addHeaderParams(request, args.getHeaders());
    }

    final Response response = new Response();

    final HttpClient client = this.getHttpClient(args);

    try {
        final HttpResponse httpResponse = client.execute(request);

        response.setResponseVersion(httpResponse.getProtocolVersion());
        response.setStatusAndCode(httpResponse.getStatusLine());

        final HttpEntity entity = httpResponse.getEntity();

        if (entity != null) {
            // Convert the stream into a string and store into the RAW
            // field.
            // InputStream instream = entity.getContent();
            // response.setRaw(RequestHandlerUtils.convertStreamToString(instream));
            // instream.close(); // Closing the input stream will trigger
            // connection release

            // TODO: Perhaps we should be dealing with the charset
            response.setRaw(EntityUtils.toString(entity));

            try {
                // Get the Content Type
                final String contenttype = entity.getContentType().getValue();

                RequestParser parser = null;

                // Check if a request-specific parser was set.
                if (args.getRequestParser() == null) {
                    // Parse the request according to the user's wishes.
                    final String extractionFormat = args.getParseAs();

                    // Determine extraction format if none are set.
                    if (extractionFormat == null) {
                        // If we can not find an appropriate parser, the
                        // default one will be returned.
                        parser = RequestParserFactory.findRequestParser(contenttype);
                    } else {
                        // Try to get the requested parser. This will throw
                        // an exception if we can't get it.
                        parser = RequestParserFactory.getRequestParser(extractionFormat);
                    }
                } else {
                    // Set a request specific parser.
                    parser = args.getRequestParser();
                }

                // Parse the content.. and if it throws an exception log it.
                final Object result = parser.parse(response.getRaw());
                // Check the result of the parser.
                if (result != null) {
                    response.setContent(result);
                    response.setParsedAs(parser.getName());
                } else {
                    // If the parser returned nothing (and most likely it
                    // wasn't the default parser).

                    // We already have the raw response, user the default
                    // parser fallback.
                    response.setContent(RequestParserFactory.DEFAULT_PARSER.parse(response.getRaw()));
                    response.setParsedAs(RequestParserFactory.DEFAULT_PARSER.getName());
                }
            } catch (final InvalidParameterException e) {
                Log.e(RequestsConstants.LOG_TAG, "Parser Requested Could Not Be Found.", e);
                throw e;
            } catch (final Exception e) {
                // Catch any parsing exception.
                Log.e(RequestsConstants.LOG_TAG, "Parser Failed Exception.", e);
                // Informed it was parsed as nothing... aka look at the raw
                // string.
                response.setParsedAs(null);
            }

        } else {
            if (args.getMethod() != RequestMethod.HEAD) {
                Log.w(RequestsConstants.LOG_TAG, "Entity is empty?");
            }
        }
    } catch (final ClientProtocolException e) {
        Log.e(RequestsConstants.LOG_TAG, "Client Protocol Exception", e);
    } catch (final IOException e) {
        Log.e(RequestsConstants.LOG_TAG, "IO Exception.", e);
    } finally {
    }

    return response;
}

From source file:net.nelz.simplesm.aop.CacheBase.java

protected Object getIndexObject(final int index, final JoinPoint jp, final Method methodToCache)
        throws Exception {
    if (index < 0) {
        throw new InvalidParameterException(String.format("An index of %s is invalid", index));
    }/* ww  w . j a va  2s .c  om*/
    final Object[] args = jp.getArgs();
    if (args.length <= index) {
        throw new InvalidParameterException(
                String.format("An index of %s is too big for the number of arguments in [%s]", index,
                        methodToCache.toString()));
    }
    final Object indexObject = args[index];
    if (indexObject == null) {
        throw new InvalidParameterException(String.format("The argument passed into [%s] at index %s is null.",
                methodToCache.toString(), index));
    }
    return indexObject;
}

From source file:com.android.ddmuilib.log.event.EventDisplay.java

/**
 * Creates the appropriate EventDisplay subclass.
 *
 * @param type the type of display (DISPLAY_TYPE_LOG_ALL, etc)
 * @param name the name of the display/*from  ww  w  . j  a  va2 s  .c  om*/
 * @return the created object
 */
public static EventDisplay eventDisplayFactory(int type, String name) {
    switch (type) {
    case DISPLAY_TYPE_LOG_ALL:
        return new DisplayLog(name);
    case DISPLAY_TYPE_FILTERED_LOG:
        return new DisplayFilteredLog(name);
    case DISPLAY_TYPE_SYNC:
        return new DisplaySync(name);
    case DISPLAY_TYPE_SYNC_HIST:
        return new DisplaySyncHistogram(name);
    case DISPLAY_TYPE_GRAPH:
        return new DisplayGraph(name);
    case DISPLAY_TYPE_SYNC_PERF:
        return new DisplaySyncPerf(name);
    default:
        throw new InvalidParameterException("Unknown Display Type " + type); //$NON-NLS-1$
    }
}

From source file:gov.nasa.arc.geocam.talk.service.SiteAuthCookie.java

@Override
public ServerResponse post(String relativePath, Map<String, String> params, byte[] audioBytes)
        throws AuthenticationFailedException, IOException, ClientProtocolException, InvalidParameterException {
    if (params == null) {
        throw new InvalidParameterException("Post parameters are required");
    }//from ww w .  jav  a  2s. co  m

    ensureAuthenticated();

    httpClient = new DefaultHttpClient();

    HttpParams httpParams = httpClient.getParams();
    HttpClientParams.setRedirecting(httpParams, false);

    HttpPost post = new HttpPost(this.serverRootUrl + "/" + appPath + "/" + relativePath);
    post.setParams(httpParams);

    HttpEntity httpEntity;

    if (audioBytes != null) {
        httpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);

        for (String key : params.keySet()) {
            ((MultipartEntity) httpEntity).addPart(key, new StringBody(params.get(key)));
        }
        if (audioBytes != null) {
            ((MultipartEntity) httpEntity).addPart("audio",
                    new ByteArrayBody(audioBytes, "audio/mpeg", "audio.mp4"));
        }
    } else {
        List<BasicNameValuePair> nameValuePairs = new ArrayList<BasicNameValuePair>();

        for (String key : params.keySet()) {
            nameValuePairs.add(new BasicNameValuePair(key, params.get(key)));
        }

        httpEntity = new UrlEncodedFormEntity(nameValuePairs, HTTP.ASCII);
    }

    post.setEntity(httpEntity);
    httpClient.getCookieStore().addCookie(sessionIdCookie);
    ServerResponse sr = new ServerResponse(httpClient.execute(post));

    if (sr.getResponseCode() == 401 || sr.getResponseCode() == 403) {
        throw new AuthenticationFailedException("Server responded with code: " + sr.getResponseCode());
    }

    return sr;
}

From source file:eu.bittrade.libs.steemj.base.models.BeneficiaryRouteType.java

/**
 * Set the percentage the {@link #getAccount() account} will receive from
 * the comment payout.//from  w w  w.ja  v a  2s.  com
 * 
 * @param weight
 *            The percentage of the payout to relay.
 * @throws InvalidParameterException
 *             If the <code>weight</code> is negative.
 */
public void setWeight(short weight) {
    if (weight < 0) {
        throw new InvalidParameterException("The weight cannot be negative.");
    }

    this.weight = weight;
}

From source file:org.wise.portal.spring.impl.CustomContextLoaderListener.java

/**
 * The behaviour of this method is the same as the superclass except for
 * setting of the config locations.//from w  w w  .  j a  va2s  .c  o  m
 * 
 * @throws ClassNotFoundException
 * 
 * @see org.springframework.web.context.ContextLoader#createWebApplicationContext(javax.servlet.ServletContext,
 *      org.springframework.context.ApplicationContext)
 */
@Override
protected WebApplicationContext createWebApplicationContext(ServletContext servletContext)
        throws BeansException {

    Class<?> contextClass = determineContextClass(servletContext);
    if (!ConfigurableWebApplicationContext.class.isAssignableFrom(contextClass)) {
        throw new ApplicationContextException("Custom context class [" + contextClass.getName()
                + "] is not of type ConfigurableWebApplicationContext");
    }

    ConfigurableWebApplicationContext webApplicationContext = (ConfigurableWebApplicationContext) BeanUtils
            .instantiateClass(contextClass);
    webApplicationContext.setServletContext(servletContext);

    String configClass = servletContext.getInitParameter(CONFIG_CLASS_PARAM);
    if (configClass != null) {
        try {
            SpringConfiguration springConfig = (SpringConfiguration) BeanUtils
                    .instantiateClass(Class.forName(configClass));
            webApplicationContext.setConfigLocations(springConfig.getRootApplicationContextConfigLocations());
        } catch (ClassNotFoundException e) {
            if (LOGGER.isErrorEnabled()) {
                LOGGER.error(CONFIG_CLASS_PARAM + " <" + configClass + "> not found.", e);
            }
            throw new InvalidParameterException("ClassNotFoundException: " + configClass);
        }
    } else {
        throw new InvalidParameterException("No value defined for the required: " + CONFIG_CLASS_PARAM);
    }

    webApplicationContext.refresh();
    return webApplicationContext;
}