List of usage examples for java.security InvalidParameterException InvalidParameterException
public InvalidParameterException(String msg)
From source file:squash.booking.lambdas.GetBookingsLambda.java
/** * Returns all bookings for the specified date. * /*from www . j av a 2 s. c om*/ * @param request specifying, e.g., the date for which to return bookings. * @param context provided by AWS Lambda. * @return response containing the bookings. * @throws AmazonServiceException when the method fails owing to an error in an AWS service. * @throws AmazonClientException when the method fails owing to a client error. * @throws Exception when the method fails for some other reason. */ public GetBookingsLambdaResponse getBookings(GetBookingsLambdaRequest request, Context context) throws Exception { LambdaLogger logger = context.getLogger(); String redirectUrl = request.getRedirectUrl(); try { logger.log("ApiGateway request Id: " + request.getRequestId()); // Validate the date that bookings are being requested for String requestedDate = request.getDate(); logger.log("About to get bookings for date: " + requestedDate + ". Checking if date is valid..."); if (!getValidDates().contains(requestedDate)) { logger.log("Date is not valid"); throw new InvalidParameterException("The booking date is outside the valid range"); } logger.log("Date is valid"); // Query for bookings (if any) for the requested day logger.log("About to call booking manager to get bookings"); GetBookingsLambdaResponse response = new GetBookingsLambdaResponse(); IBookingManager bookingManager = getBookingManager(logger); response.setBookings(bookingManager.getBookings(requestedDate, true)); response.setDate(request.getDate()); ILifecycleManager lifecycleManager = getLifecycleManager(logger); ImmutablePair<ILifecycleManager.LifecycleState, Optional<String>> lifecycleState = lifecycleManager .getLifecycleState(); response.setLifecycleState(lifecycleState.left.name()); // N.B. getBookings will have thrown already if state is RETIRED, but // fill in the url anyway. response.setForwardingUrl(lifecycleState.right.orElse("")); logger.log("Called booking manager to get bookings"); return response; } catch (AmazonServiceException ase) { ExceptionUtils.logAmazonServiceException(ase, logger); throw new Exception("Apologies - something has gone wrong. Please try again." + redirectUrl, ase); } catch (AmazonClientException ace) { ExceptionUtils.logAmazonClientException(ace, logger); throw new Exception("Apologies - something has gone wrong. Please try again." + redirectUrl, ace); } catch (Exception e) { if ((e.getMessage() != null) && e.getMessage().contains( "Cannot access bookings or rules - there is an updated version of the booking service.") && !e.getMessage().contains("UrlNotPresent")) { // In case where service is RETIRED and we have a valid forwarding url, // use that url instead of our generic redirectUrl. If we have no valid // forwarding url (which should never happen), we fall through to // showing the user a general error message. throw new Exception(e.getMessage().replace(" Forwarding Url:", ""), e); } switch (e.getMessage()) { // For now, we add the request.redirectUrl to the message. ApiGateway will // parse this out. case "The booking date is outside the valid range": throw new Exception("The booking date is outside the valid range. Please try again." + redirectUrl, e); default: throw new Exception("Apologies - something has gone wrong. Please try again." + redirectUrl, e); } } }
From source file:org.moe.cli.manager.PrebuildCocoaPodsManager.java
public IExecutor processCocoapods(String source, SpecObject spec, String packageName, String[] javaSource, String outputJar) throws IOException, CompressorException, ArchiveException, InvalidParameterSpecException, InterruptedException, URISyntaxException, UnsupportedTypeException { File tmpFolder = NatJFileUtils.getNewTempDirectory(); File download = new File(tmpFolder, "download/"); if (!download.exists()) { download.mkdirs();/*from w w w . j av a2 s. c o m*/ } int nameIdx = source.lastIndexOf("/"); File outFile = new File(download, source.substring(nameIdx + 1)); GrabUtils.download(new URI(source), outFile); int extIdx = outFile.getName().lastIndexOf("."); String folderUnzip = outFile.getName().substring(0, extIdx); File destination = new File(download, folderUnzip); if (!destination.exists()) { destination.mkdirs(); } String type = spec.getSource().get("type"); if (outFile.getName().endsWith(".zip") || (type != null && type.equals("zip"))) { ZipFile apachZip = new ZipFile(outFile); ArchiveUtils.unzipArchive(apachZip, destination); } else if (outFile.getName().endsWith("tar.bzip2") || outFile.getName().endsWith("tar.gz") || outFile.getName().endsWith("tar.bz2") || type.equals("tgz")) { InputStream inputC = null; int extArchIdx = outFile.getName().lastIndexOf("."); String ext = outFile.getName().substring(extArchIdx + 1); if (ext.equals("tar")) { inputC = new FileInputStream(outFile); } else if (ext.equals("bzip2") || ext.equals("gz") || ext.equals("bz2")) { InputStream fin = new FileInputStream(outFile); String compressorType = null; if (ext.equals("bzip2") || ext.equals("bz2")) { compressorType = CompressorStreamFactory.BZIP2; } else if (ext.equals("gz") || type.equals("tgz")) { compressorType = CompressorStreamFactory.GZIP; } inputC = new CompressorStreamFactory().createCompressorInputStream(compressorType, fin); } else { throw new InvalidParameterException("Unsupported archive type"); } ArchiveInputStream input = new ArchiveStreamFactory().createArchiveInputStream(ArchiveStreamFactory.TAR, inputC); ArchiveUtils.untarArchive(input, destination); } //update destination for git repo if (spec.getSource().containsKey("git")) { String git = spec.getSource().get("git"); String tag = spec.getSource().get("tag"); int gitNameIdx = git.lastIndexOf("/"); String gitName = git.substring(gitNameIdx + 1); if (gitName.endsWith(".git")) { gitName = gitName.substring(0, gitName.length() - 4); } if (!Character.isDigit(tag.charAt(0)) && Character.isDigit(tag.charAt(1))) { tag = tag.substring(1); } String zipSubfolder = String.format("%s-%s", gitName, tag); destination = new File(destination, zipSubfolder); } List<String> commandList = spec.getPreparedCommands(); for (String command : commandList) { if (command != null && !command.isEmpty()) { executePrepareCommands(destination, command); } } IExecutor executor = null; //find all bundles Set<String> bundleContent = new HashSet<String>(); List<String> resources = spec.getResources(); if (resources != null && resources.size() > 0) { for (String bundle : resources) { Set<String> bundleWildCard = getBundleResources(bundle, destination); bundleContent.addAll(bundleWildCard); } } String[] bundleRes = bundleContent.toArray(new String[0]); //get additional linker flags String ldFlags = spec.getLdFlags(); //create Set<String> headersContent = new HashSet<String>(); List<String> headerList = spec.getSourceFiles(); if (headerList != null && headerList.size() > 0) { for (String header : headerList) { int recursivIdx = header.indexOf("**"); if (recursivIdx >= 0) { File headerFile = new File(destination, header.substring(0, recursivIdx)); headersContent.add(headerFile.getPath()); } else { Set<String> bundleWildCard = getBundleResources(header, destination); headersContent.addAll(bundleWildCard); } } } if (spec.getVendoredFrameworks() != null && spec.getVendoredFrameworks().size() > 0) { List<File> frameworkList = new ArrayList<>(); Set<String> frameworkContent = new HashSet<String>(); for (String vFramework : spec.getVendoredFrameworks()) { Set<String> frName = getBundleResources(vFramework, destination); if (frName.size() != 1) throw new RuntimeException( "Something wrong with this code. Refactor it! And the same with libraries"); File frameworkFile = new File(frName.toArray(new String[0])[0]); if (frameworkFile.exists()) { frameworkList.add(frameworkFile); frameworkContent.add(frameworkFile.getPath()); int frameworkNameIdx = frameworkFile.getName().lastIndexOf("."); if (frameworkNameIdx >= 0) { ldFlags = ldFlags + "-framework " + frameworkFile.getName().substring(0, frameworkNameIdx) + ";"; } } } if (headersContent.isEmpty()) { for (File framework : frameworkList) { File headerFile = new File(framework, "Headers"); headersContent.add(headerFile.getPath()); } } executor = new ThirdPartyFrameworkLinkExecutor(packageName, frameworkContent.toArray(new String[0]), javaSource, headersContent.toArray(new String[0]), bundleRes, outputJar, ldFlags); } else if (spec.getVendoredLibraries() != null && spec.getVendoredLibraries().size() > 0) { Set<String> libContent = new HashSet<String>(); for (String lib : spec.getVendoredLibraries()) { Set<String> libName = getBundleResources(lib, destination); if (libName.size() != 1) throw new RuntimeException( "Something wrong with this code. Refactor it! And the same with libraries"); File library = new File(libName.toArray(new String[0])[0]); if (library.exists()) { libContent.add(library.getPath()); int libNameIdx = library.getName().lastIndexOf("."); if (libNameIdx >= 0) { String libShortName = library.getName().substring(0, libNameIdx); ldFlags = ldFlags + "-l" + (libShortName.startsWith("lib") ? libShortName.substring(3) : libShortName) + ";"; } } } executor = new ThirdPartyLibraryLinkExecutor(packageName, libContent.toArray(new String[0]), javaSource, headersContent.toArray(new String[0]), bundleRes, outputJar, ldFlags); } return executor; }
From source file:org.flite.cach3.aop.L2ReadThroughAssignCacheAdvice.java
static AnnotationInfo getAnnotationInfo(final L2ReadThroughAssignCache annotation, final String targetMethodName) { final AnnotationInfo result = new AnnotationInfo(); if (annotation == null) { throw new InvalidParameterException( String.format("No annotation of type [%s] found.", L2ReadThroughAssignCache.class.getName())); }//from ww w . j a v a 2 s.c o m 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]", L2ReadThroughAssignCache.class.getName(), targetMethodName)); } result.add(new AType.Namespace(namespace)); final String assignKey = annotation.assignedKey(); if (AnnotationConstants.DEFAULT_STRING.equals(assignKey) || assignKey == null || assignKey.length() < 1) { throw new InvalidParameterException( String.format("AssignedKey for annotation [%s] must be defined on [%s]", L2ReadThroughAssignCache.class.getName(), targetMethodName)); } result.add(new AType.AssignKey(assignKey)); final Duration window = annotation.window(); if (window == Duration.UNDEFINED) { throw new InvalidParameterException( String.format("Window for annotation [%s] must be a defined value on [%s]", L2ReadThroughAssignCache.class.getName(), targetMethodName)); } result.add(new AType.Window(window)); return result; }
From source file:com.mobdb.android.MobDB.java
/** * Send's INSERT SQL request to mobDB /*from w w w .jav a 2 s .co m*/ * @param appKey String value Application key * @param insertRowdata InsertRowData 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, InsertRowData insertRowdata, String bargraph, boolean secure, MobDBResponseListener listener) throws InvalidParameterException { try { execute(appKey, new String[] { insertRowdata.getQueryString() }, insertRowdata.getParameters(), bargraph, secure, listener); } catch (Exception e) { // TODO: handle exception throw new InvalidParameterException(e.toString()); } }
From source file:org.flite.cach3.aop.L2InvalidateAssignCacheAdvice.java
private void doInvalidate(final JoinPoint jp, final Object retVal) throws Throwable { if (isCacheDisabled()) { LOG.debug("Caching is disabled."); return;/*from ww w. j ava2 s. com*/ } final Method methodToCache = getMethodToCache(jp); List<L2InvalidateAssignCache> lAnnotations; // if (methodToCache.getAnnotation(InvalidateAssignCache.class) != null) { lAnnotations = Arrays.asList(methodToCache.getAnnotation(L2InvalidateAssignCache.class)); // } else { // lAnnotations = Arrays.asList(methodToCache.getAnnotation(InvalidateAssignCaches.class).value()); // } for (int i = 0; i < lAnnotations.size(); i++) { // 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 { final AnnotationInfo info = getAnnotationInfo(lAnnotations.get(i), methodToCache.getName()); final String cacheKey = buildCacheKey(info.getAsString(AType.ASSIGN_KEY), info.getAsString(AType.NAMESPACE), info.getAsString(AType.KEY_PREFIX)); if (cacheKey == null || cacheKey.trim().length() == 0) { throw new InvalidParameterException("Unable to find a cache key"); } getCache().invalidateBulk(Arrays.asList(cacheKey)); } catch (Throwable ex) { if (LOG.isDebugEnabled()) { LOG.warn("Caching on " + jp.toShortString() + " aborted due to an error.", ex); } else { LOG.warn("Caching on " + jp.toShortString() + " aborted due to an error: " + ex.getMessage()); } } } }
From source file:th.in.ffc.person.visit.VisitAncPregnancyActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); super.onCreate(savedInstanceState); setContentView(R.layout.visit_pragnancy_activity); setSupportProgressBarIndeterminateVisibility(false); mAction = getIntent().getAction();//w w w . j a v a2 s . c o m if (TextUtils.isEmpty(mAction)) throw new IllegalStateException("VisitAncPregnancyActivity not support null Action Intent"); doInitializeView(savedInstanceState); if (savedInstanceState == null) { //do by request action if (mAction.equals(Action.INSERT)) getSupportLoaderManager().initLoader(LOAD_LAST_PREG, null, this); else if (mAction.equals(Action.EDIT)) { mPregNo = getIntent().getStringExtra(PregnancyColumns._PREGNO); if (TextUtils.isEmpty(mPregNo)) throw new InvalidParameterException("Edit Action must have \'pregno\'"); if (!TextUtils.isDigitsOnly(mPregNo)) throw new InvalidParameterException("pregno must be digits only"); PregNo.setEnabled(false); PregNo.setText(mPregNo); getSupportLoaderManager().initLoader(LOAD_PREG, null, this); getSupportLoaderManager().initLoader(LOAD_RISK, null, this); } } else { mAction = savedInstanceState.getString("action"); mMinPregNo = savedInstanceState.getInt("min"); Hint.setText(savedInstanceState.getCharSequence("hint")); mPregNo = savedInstanceState.getString("pregno"); PregNo.setEnabled(savedInstanceState.getBoolean("enable")); RiskLayout.setVisibility(savedInstanceState.getBoolean("showRisk") ? View.VISIBLE : View.GONE); } }
From source file:net.sf.zekr.engine.addonmgr.AddOnManagerUtils.java
private static String getSharedInstallationFolder(Resource resource) { if (AudioData.class.equals(resource.getType())) return Naming.getAudioDir(); else if (TranslationData.class.equals(resource.getType())) return Naming.getTransDir(); else// www. j av a 2 s .c o m throw new InvalidParameterException("ResourceType not handled"); }
From source file:com.predic8.membrane.core.transport.ssl.SSLContext.java
public SSLContext(SSLParser sslParser, ResolverMap resourceResolver, String baseLocation) { this.sslParser = sslParser; try {// w w w . j a v a2s . c o m String algorihm = KeyManagerFactory.getDefaultAlgorithm(); if (sslParser.getAlgorithm() != null) algorihm = sslParser.getAlgorithm(); KeyManagerFactory kmf = null; String keyStoreType = "JKS"; if (sslParser.getKeyStore() != null) { if (sslParser.getKeyStore().getKeyAlias() != null) throw new InvalidParameterException("keyAlias is not yet supported."); char[] keyPass = "changeit".toCharArray(); if (sslParser.getKeyStore().getKeyPassword() != null) keyPass = sslParser.getKeyStore().getKeyPassword().toCharArray(); if (sslParser.getKeyStore().getType() != null) keyStoreType = sslParser.getKeyStore().getType(); KeyStore ks = openKeyStore(sslParser.getKeyStore(), "JKS", keyPass, resourceResolver, baseLocation); kmf = KeyManagerFactory.getInstance(algorihm); kmf.init(ks, keyPass); Enumeration<String> aliases = ks.aliases(); while (aliases.hasMoreElements()) { String alias = aliases.nextElement(); if (ks.isKeyEntry(alias)) { // first key is used by the KeyManagerFactory Certificate c = ks.getCertificate(alias); if (c instanceof X509Certificate) { X509Certificate x = (X509Certificate) c; dnsNames = new ArrayList<String>(); Collection<List<?>> subjectAlternativeNames = x.getSubjectAlternativeNames(); if (subjectAlternativeNames != null) for (List<?> l : subjectAlternativeNames) { if (l.get(0) instanceof Integer && ((Integer) l.get(0) == 2)) dnsNames.add(l.get(1).toString()); } } break; } } } TrustManagerFactory tmf = null; if (sslParser.getTrustStore() != null) { String trustAlgorithm = TrustManagerFactory.getDefaultAlgorithm(); if (sslParser.getTrustStore().getAlgorithm() != null) trustAlgorithm = sslParser.getTrustStore().getAlgorithm(); KeyStore ks = openKeyStore(sslParser.getTrustStore(), keyStoreType, null, resourceResolver, baseLocation); tmf = TrustManagerFactory.getInstance(trustAlgorithm); tmf.init(ks); } TrustManager[] tms = tmf != null ? tmf.getTrustManagers() : null /* trust anyone: new TrustManager[] { new NullTrustManager() } */; if (sslParser.isIgnoreTimestampCheckFailure()) tms = new TrustManager[] { new TrustManagerWrapper(tms, true) }; if (sslParser.getProtocol() != null) sslc = javax.net.ssl.SSLContext.getInstance(sslParser.getProtocol()); else sslc = javax.net.ssl.SSLContext.getInstance("TLS"); sslc.init(kmf != null ? kmf.getKeyManagers() : null, tms, null); if (sslParser.getCiphers() != null) { ciphers = sslParser.getCiphers().split(","); Set<String> supportedCiphers = Sets.newHashSet(sslc.getSocketFactory().getSupportedCipherSuites()); for (String cipher : ciphers) { if (!supportedCiphers.contains(cipher)) throw new InvalidParameterException("Unknown cipher " + cipher); if (cipher.contains("_RC4_")) log.warn("Cipher " + cipher + " uses RC4, which is deprecated."); } } else { // use all default ciphers except those using RC4 String supportedCiphers[] = sslc.getSocketFactory().getDefaultCipherSuites(); ArrayList<String> ciphers = new ArrayList<String>(supportedCiphers.length); for (String cipher : supportedCiphers) if (!cipher.contains("_RC4_")) ciphers.add(cipher); sortCiphers(ciphers); this.ciphers = ciphers.toArray(new String[ciphers.size()]); } if (setUseCipherSuitesOrderMethod == null) log.warn( "Cannot set the cipher suite order before Java 8. This prevents Forward Secrecy with some SSL clients."); if (sslParser.getProtocols() != null) { protocols = sslParser.getProtocols().split(","); } else { protocols = null; } if (sslParser.getClientAuth() == null) { needClientAuth = false; wantClientAuth = false; } else if (sslParser.getClientAuth().equals("need")) { needClientAuth = true; wantClientAuth = true; } else if (sslParser.getClientAuth().equals("want")) { needClientAuth = false; wantClientAuth = true; } else { throw new RuntimeException("Invalid value '" + sslParser.getClientAuth() + "' in clientAuth: expected 'want', 'need' or not set."); } } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.gdo.util.XmlWriter.java
/** * @param name//from w w w.ja v a2 s . c om * tag's name. * @param indent * <tt>true</tt> if tag closed is indented (not the case for * CDATA). * @throws IOException */ public void endElement(String name, boolean indent) throws IOException { if (StringUtils.isEmpty(name)) { throw new NullPointerException("XML tag name must not be null"); } _indent--; // tag on a single line if (_tag != null) { // _tag should be equals to name if (!_tag.equals(name)) { throw new InvalidParameterException("Ending a tag which is not opened"); } // closing directly open tag _writer.write("/>\n"); _tag = null; return; } // close tag if (indent) { writeIndent(); } _writer.write("</"); _writer.write(name); _writer.write(">\n"); }
From source file:org.flite.cach3.aop.InvalidateAssignCacheAdvice.java
private void doInvalidate(final JoinPoint jp, final Object retVal) throws Throwable { if (isCacheDisabled()) { LOG.debug("Caching is disabled."); return;/*w ww. jav a2s. c o m*/ } final MemcachedClientIF cache = getMemcachedClient(); final Method methodToCache = getMethodToCache(jp); List<InvalidateAssignCache> lAnnotations; if (methodToCache.getAnnotation(InvalidateAssignCache.class) != null) { lAnnotations = Arrays.asList(methodToCache.getAnnotation(InvalidateAssignCache.class)); } else { lAnnotations = Arrays.asList(methodToCache.getAnnotation(InvalidateAssignCaches.class).value()); } for (int i = 0; i < lAnnotations.size(); i++) { // 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 { final AnnotationInfo info = getAnnotationInfo(lAnnotations.get(i), methodToCache.getName()); final String cacheKey = buildCacheKey(info.getAsString(AType.ASSIGN_KEY), info.getAsString(AType.NAMESPACE), info.getAsString(AType.KEY_PREFIX)); if (cacheKey == null || cacheKey.trim().length() == 0) { throw new InvalidParameterException("Unable to find a cache key"); } cache.delete(cacheKey); // Notify the observers that a cache interaction happened. final List<InvalidateAssignCacheListener> listeners = getPertinentListeners( InvalidateAssignCacheListener.class, info.getAsString(AType.NAMESPACE)); if (listeners != null && !listeners.isEmpty()) { for (final InvalidateAssignCacheListener listener : listeners) { try { listener.triggeredInvalidateAssignCache(info.getAsString(AType.NAMESPACE), info.getAsString(AType.ASSIGN_KEY), retVal, jp.getArgs()); } catch (Exception ex) { LOG.warn("Problem when triggering a listener.", ex); } } } } catch (Throwable ex) { if (LOG.isDebugEnabled()) { LOG.warn("Caching on " + jp.toShortString() + " aborted due to an error.", ex); } else { LOG.warn("Caching on " + jp.toShortString() + " aborted due to an error: " + ex.getMessage()); } } } }