List of usage examples for java.security NoSuchAlgorithmException printStackTrace
public void printStackTrace()
From source file:cn.buk.hotel.service.HotelServiceImpl.java
@Override public HotelSearchResult searchHotel(String cityCode, Date checkInDate, Date checkOutDate, String hotelName, int pageNo, String star, int districtId, int zoneId) { HotelSearchResult searchResult = new HotelSearchResult(); if (checkInDate.getTime() < DateUtil.getCurDate().getTime()) checkInDate = DateUtil.getCurDate(); if (checkInDate.getTime() >= checkOutDate.getTime()) checkOutDate = DateUtil.add(checkInDate, 1); City city = cityDao.getCityByCode(cityCode); Date baseTime = DateUtil.getCurDateTime(); int cityId = city.getOpenApiId(); List<HotelInfoDto> dtos = new ArrayList<HotelInfoDto>(); HotelSearchCriteria sc = new HotelSearchCriteria(); sc.setCityId(cityId);//from www .j a v a 2s. c o m sc.setCheckInDate(checkInDate); sc.setCheckOutDate(checkOutDate); sc.setHotelName(hotelName); sc.getPage().setPageNo(pageNo); sc.setStar(star); sc.setDistrictId(districtId); sc.setZoneId(zoneId); /** * ? */ String cacheKey = null; try { String scToString = sc.toString(); cacheKey = EncryptUtil.MD5Encoding(scToString); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } if (cacheKey != null) { logger.debug("cacheKey: " + cacheKey); net.sf.ehcache.Element cacheElement = getCache().get(cacheKey); if (cacheElement != null) { searchResult = (HotelSearchResult) cacheElement.getObjectValue(); logger.debug("Nothing for key: " + searchResult); return searchResult; } else { logger.debug("Nothing for key: " + cacheKey); } } List<HotelInfo> hotelInfos = hotelDao.searchAvailableHotel(sc); int span0 = DateUtil.getPastTime(baseTime); //????? int bookingDays = DateUtil.getPastDays(checkOutDate, checkInDate); int bookingAdvancedDays = DateUtil.getPastDays(checkInDate, DateUtil.getCurDate()); Date baseTime2 = DateUtil.getCurDateTime(); for (HotelInfo hotelInfo : hotelInfos) { // HotelInfoDto dto = new HotelInfoDto(); dtos.add(dto); dto.setHotelCode(hotelInfo.getHotelCode()); dto.setHotelName(hotelInfo.getHotelName()); dto.setHotelAddress(hotelInfo.getAddress()); dto.setHotelStarRate(hotelInfo.getHotelStarRate()); dto.setHotelUserRate(hotelInfo.getHotelUserRate()); Date baseTime1 = DateUtil.getCurDateTime(); //?? List<HotelMultimediaInfo> medias = hotelDao.getHotelMultimediaList(hotelInfo.getId()); for (HotelMultimediaInfo media : medias) { if (media.getMediaType().equalsIgnoreCase("image") && media.getCategory() == HotelMultimediaInfo.HOTEL_PICTURE_EXTERIOR_VIEW) dto.setHotelExteriorPictureUrl(media.getUrl()); else if (media.getMediaType().equalsIgnoreCase("text") && media.getCategory() == HotelMultimediaInfo.HOTEL_TEXT_DESC) dto.setHotelDesc(media.getDescription().trim()); } // List<HotelRatePlan> ratePlans = hotelDao.searchAvailableHotelRatePlan(hotelInfo.getId(), checkInDate, checkOutDate); //ratePlanCoderoomTypeCode?,invBlockCode? yfdai 2015-1-8 List<HotelGuestRoom> rooms = hotelDao.getHotelRoomInfoList(hotelInfo.getId()); for (HotelGuestRoom room : rooms) { for (HotelRatePlan rp : ratePlans) { if (rp.getHotelRatePlanRates() == null || rp.getHotelRatePlanRates().size() == 0) continue; if (!room.getRoomTypeCode().equalsIgnoreCase(Integer.toString(rp.getRatePlanCode()))) continue; //??? if (rp.getHotelRatePlanBookingRules() != null && rp.getHotelRatePlanBookingRules().size() > 0) { HotelRatePlanBookingRule rule = rp.getHotelRatePlanBookingRules().get(0); if (rule.getMinAdvancedBookingOffset() > 0 && rule.getMinAdvancedBookingOffset() > bookingAdvancedDays) continue; if (rule.getMaxAdvancedBookingOffset() > 0 && rule.getMaxAdvancedBookingOffset() > bookingAdvancedDays) continue; if (rule.getLengthOfStay() > 0 && rule.getLengthOfStay() > bookingDays) continue; } //offer?? if (rp.getHotelRatePlanOffers() != null && rp.getHotelRatePlanOffers().size() > 0) { boolean b = true; for (HotelRatePlanOffer offer : rp.getHotelRatePlanOffers()) { //1002- if (offer.getOfferCode() == 1002) continue; //1001- if (offer.getOfferCode() == 1001) { if (offer.getRatePlanOfferRules() != null && offer.getRatePlanOfferRules().size() > 0) { //<!-- ?--> //<!-- StartEnd?RestrictionTypbooking?RestrictionDateCode 501502???--> for (HotelRatePlanOfferRule rule : offer.getRatePlanOfferRules()) { for (HotelRatePlanOfferRuleDateRestriction restriction : rule .getRatePlanOfferRuleDateRestrictions()) { DateRange dateRange = restriction.getDateRange(); if (dateRange == null || dateRange.getRestrictionDateCode() == null) continue; if (!dateRange.getRestrictionType().equalsIgnoreCase("booking")) continue; if (dateRange.getRestrictionDateCode() == null) continue; if (dateRange.getRestrictionDateCode().equalsIgnoreCase("501")) { // if (DateUtil.isLowerEqualDate(dateRange.getStartTime())) b = false; if (DateUtil.isGreaterEqualDate(dateRange.getEndTime())) b = false; } else if (dateRange.getRestrictionDateCode().equalsIgnoreCase("502")) { // if (DateUtil.isLowerEqualOnlyTime(dateRange.getStartTime())) b = false; if (DateUtil.isGreaterEqualOnlyTime(dateRange.getEndTime())) b = false; } } } } } } if (!b) continue; } HotelRatePlanDto rpDto = new HotelRatePlanDto(); rpDto.setRatePlanCode(rp.getRatePlanCode()); rpDto.setRatePlanName(rp.getName()); rpDto.setInvBlockCode(room.getInvBlockCode()); rpDto.setRoomTypeCode(Integer.toString(rp.getRatePlanCode())); rpDto.setRoomTypeName(room.getRoomTypeName()); if (room.getBedTypeCode() != null) rpDto.setBedTypeCode(Integer.parseInt(room.getBedTypeCode())); for (HotelGuestRoomAmenity amenity : room.getHotelGuestRoomAmenities()) { HotelRoomAmenityDto amenityDto = new HotelRoomAmenityDto(); amenityDto.setAmenityCode(amenity.getCode()); amenityDto.setAmenityName(amenity.getDescription()); rpDto.getAmenities().add(amenityDto); } //rpDto.setRoomTypeName(rp.getName()); int price = 0; for (HotelRatePlanRate rate0 : rp.getHotelRatePlanRates()) { //price += rate.getHotelRatePlanRateBaseByGuestAmounts().get(0).getAmountBeforeTax(); HotelRatePlanRateDto rate1 = new HotelRatePlanRateDto(); rpDto.getRates().add(rate1); rate1.setStartDate(rate0.getStartDate()); rate1.setPrice(rate0.getHotelRatePlanRateBaseByGuestAmounts().get(0).getAmountBeforeTax()); rate1.setBreakfast(rate0.getBreakfast()); // if (rate0.getHotelRatePlanRatePromotions() != null && rate0.getHotelRatePlanRatePromotions().size() > 0) { rate1.setRebateAmount(rate0.getHotelRatePlanRatePromotions().get(0).getAmount()); rate1.setRebateDesc(rate0.getHotelRatePlanRatePromotions().get(0).getDescription()); } //? if (rate0.getHotelRatePlanRateGuaranteePolicies() != null && rate0.getHotelRatePlanRateGuaranteePolicies().size() > 0) { rate1.setGuaranteeCode( rate0.getHotelRatePlanRateGuaranteePolicies().get(0).getGuaranteeCode()); rate1.setHoldTime(rate0.getHotelRatePlanRateGuaranteePolicies().get(0).getHoldTime()); } //? if (rate0.getHotelRatePlanRateCancelPolicies() != null && rate0.getHotelRatePlanRateCancelPolicies().size() > 0) { HotelRatePlanRateCancelPolicy policy = rate0.getHotelRatePlanRateCancelPolicies() .get(0); rate1.setCancelPolicyStart(policy.getStartTime()); rate1.setCancelPolicyEnd(policy.getEndTime()); rate1.setCancelPenaltyAmount((int) policy.getAmount()); } } rpDto.calcAveragePrice(); int breakfast = rp.getHotelRatePlanRates().get(0).getBreakfast(); int breakfastCount = rp.getHotelRatePlanRates().get(0).getNumberOfBreakfast(); if (breakfast == 0) breakfastCount = 0; rpDto.setBreakfast(breakfastCount); dto.addRatePlan(rpDto); } } int span4 = DateUtil.getPastTime(baseTime1); logger.info("elapsed time span4: " + span4 + " ms."); } int span2 = DateUtil.getPastTime(baseTime2); int spanTotal = DateUtil.getPastTime(baseTime); logger.info("elapsed time: total=" + spanTotal + "ms, span0=" + span0 + ", span2=" + span2 + "."); searchResult.setHotels(dtos); searchResult.setPageNo(sc.getPage().getPageNo()); searchResult.setPageTotal(sc.getPage().getPageTotal()); searchResult.setRowCount(sc.getPage().getRowCount()); if (cacheKey != null) { getCache().put(new net.sf.ehcache.Element(cacheKey, searchResult)); logger.debug("Put object into cache with key " + cacheKey); } return searchResult; }
From source file:com.gnut3ll4.android.basicandroidkeystore.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.btn_create_keys: try {//from w ww. j ava2 s. com mKeyStoreHelper.createKeys(this); Log.d(TAG, "Keys created"); return true; } catch (NoSuchAlgorithmException e) { Log.w(TAG, "RSA not supported", e); } catch (InvalidAlgorithmParameterException e) { Log.w(TAG, "No such provider: AndroidKeyStore"); } catch (NoSuchProviderException e) { Log.w(TAG, "Invalid Algorithm Parameter Exception", e); } catch (KeyStoreException e) { e.printStackTrace(); } return true; case R.id.btn_sign_data: try { mSignatureStr = mKeyStoreHelper.signData(SAMPLE_INPUT); } catch (KeyStoreException e) { Log.w(TAG, "KeyStore not Initialized", e); } catch (UnrecoverableEntryException e) { Log.w(TAG, "KeyPair not recovered", e); } catch (NoSuchAlgorithmException e) { Log.w(TAG, "RSA not supported", e); } catch (InvalidKeyException e) { Log.w(TAG, "Invalid Key", e); } catch (SignatureException e) { Log.w(TAG, "Invalid Signature", e); } catch (IOException e) { Log.w(TAG, "IO Exception", e); } catch (CertificateException e) { Log.w(TAG, "Error occurred while loading certificates", e); } Log.d(TAG, "Signature: " + mSignatureStr); return true; case R.id.btn_verify_data: boolean verified = false; try { if (mSignatureStr != null) { verified = mKeyStoreHelper.verifyData(SAMPLE_INPUT, mSignatureStr); } } catch (KeyStoreException e) { Log.w(TAG, "KeyStore not Initialized", e); } catch (CertificateException e) { Log.w(TAG, "Error occurred while loading certificates", e); } catch (NoSuchAlgorithmException e) { Log.w(TAG, "RSA not supported", e); } catch (IOException e) { Log.w(TAG, "IO Exception", e); } catch (UnrecoverableEntryException e) { Log.w(TAG, "KeyPair not recovered", e); } catch (InvalidKeyException e) { Log.w(TAG, "Invalid Key", e); } catch (SignatureException e) { Log.w(TAG, "Invalid Signature", e); } if (verified) { Log.d(TAG, "Data Signature Verified"); } else { Log.d(TAG, "Data not verified."); } return true; } return false; }
From source file:com.microsoft.aad.adal.testapp.MainActivity.java
private void initContext() { Log.d(TAG, "Init authentication context based on input"); // UI automation tests will fill in these fields to test different // scenarios// w ww .ja va2s. c o m String authority = mAuthority.getText().toString(); if (authority == null || authority.isEmpty()) { authority = AUTHORITY_URL; } try { mContext = new AuthenticationContext(MainActivity.this, authority, mValidate.isChecked()); } catch (NoSuchAlgorithmException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchPaddingException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:CSVTools.CsvToolsApi.java
public CsvToolsApi() { this.logger = Logger.getLogger(this.getClass().getName()); try {/*from ww w .j a v a2 s .com*/ this.crypto = MessageDigest.getInstance("SHA-1"); } catch (NoSuchAlgorithmException e) { // TODO Auto-generated catch block e.printStackTrace(); } crypto.reset(); }
From source file:com.ctctlabs.ctctwsjavalib.CTCTConnection.java
/** * Helper to get hex string of md5 hash/* w ww. ja va 2 s.c om*/ * adapted from http://www.kospol.gr/204/create-md5-hashes-in-android/ * @param data the byte array to be hashed * @return hex string md5 hash * @author CL Kim */ String mMd5Hex(byte[] data) { try { // Create MD5 Hash MessageDigest md = MessageDigest.getInstance("MD5"); md.update(data); byte[] dataMd5 = md.digest(); // Create Hex String StringBuffer hexString = new StringBuffer(); for (int i = 0; i < dataMd5.length; i++) { String h = Integer.toHexString(0xFF & dataMd5[i]); while (h.length() < 2) h = "0" + h; hexString.append(h); } return hexString.toString(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); return ""; } }
From source file:cvut.fel.mobilevoting.murinrad.communications.Connection.java
/** * http://www.coderanch.com/t/207318/sockets/java/do-hold-Java-default-SSL a * getter method for outputting the defauld certificate validator * //from w w w . ja va 2 s. c om * @return */ private X509TrustManager getDefaultTrust() { TrustManagerFactory trustManagerFactory = null; try { trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); } catch (NoSuchAlgorithmException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { trustManagerFactory.init((KeyStore) null); } catch (KeyStoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("JVM Default Trust Managers:"); for (TrustManager trustManager : trustManagerFactory.getTrustManagers()) { System.out.println(trustManager); if (trustManager instanceof X509TrustManager) { X509TrustManager x509TrustManager = (X509TrustManager) trustManager; return x509TrustManager; } } return null; }
From source file:org.ormma.controller.OrmmaAssetController.java
/** * Write an input stream to a file wrapping it with ormma stuff * /*from w w w.j a v a 2 s . co m*/ * @param in * the input stream * @param file * the file to store it in * @param storeInHashedDirectory * use a hashed directory name * @return the path where it was stored * @throws IllegalStateException * the illegal state exception * @throws IOException * Signals that an I/O exception has occurred. */ public String writeToDiskWrap(InputStream in, String file, boolean storeInHashedDirectory, String injection, String bridgePath, String ormmaPath) throws IllegalStateException, IOException /** * writes a HTTP entity to the specified filename and location on disk */ { byte buff[] = new byte[1024]; MessageDigest digest = null; if (storeInHashedDirectory) { try { digest = java.security.MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } } // check for html tag in the input ByteArrayOutputStream fromFile = new ByteArrayOutputStream(); FileOutputStream out = null; try { do { int numread = in.read(buff); if (numread <= 0) { break; } if (storeInHashedDirectory && digest != null) { digest.update(buff); } fromFile.write(buff, 0, numread); } while (true); String wholeHTML = fromFile.toString(); Log.d("html", wholeHTML); boolean hasHTMLWrap = wholeHTML.indexOf("</html>") >= 0; // TODO cannot have injection when full html StringBuffer wholeHTMLBuffer = null; if (hasHTMLWrap) { wholeHTMLBuffer = new StringBuffer(wholeHTML); int start = wholeHTMLBuffer.indexOf("/ormma_bridge.js"); if (start <= 0) { // TODO error } wholeHTMLBuffer.replace(start, start + "/ormma_bridge.js".length(), "file:/" + bridgePath); start = wholeHTMLBuffer.indexOf("/ormma.js"); if (start <= 0) { // TODO error } wholeHTMLBuffer.replace(start, start + "/ormma.js".length(), "file:/" + ormmaPath); } out = getAssetOutputString(file); if (!hasHTMLWrap) { out.write("<html>".getBytes()); out.write("<head>".getBytes()); out.write("<meta name='viewport' content='user-scalable=no initial-scale=1.0' />".getBytes()); out.write("<title>Advertisement</title> ".getBytes()); out.write( ("<script src=\"file:/" + bridgePath + "\" type=\"text/javascript\"></script>").getBytes()); out.write( ("<script src=\"file:/" + ormmaPath + "\" type=\"text/javascript\"></script>").getBytes()); if (injection != null) { out.write("<script type=\"text/javascript\">".getBytes()); out.write(injection.getBytes()); out.write("</script>".getBytes()); } out.write("</head>".getBytes()); out.write("<body style=\"margin:0; padding:0; overflow:hidden; background-color:transparent;\">" .getBytes()); out.write("<div align=\"center\"> ".getBytes()); } if (!hasHTMLWrap) { out.write(fromFile.toByteArray()); } else { out.write(wholeHTMLBuffer.toString().getBytes()); } if (!hasHTMLWrap) { out.write("</div> ".getBytes()); out.write("</body> ".getBytes()); out.write("</html> ".getBytes()); } out.flush(); // out.close(); // in.close(); } finally { if (fromFile != null) { try { fromFile.close(); } catch (Exception e) { // TODO: handle exception } fromFile = null; } if (out != null) { try { out.close(); } catch (Exception e) { // TODO: handle exception } out = null; } } String filesDir = getFilesDir(); if (storeInHashedDirectory && digest != null) { filesDir = moveToAdDirectory(file, filesDir, asHex(digest)); } return filesDir; }
From source file:com.inovex.zabbixmobile.activities.BaseActivity.java
/** * Binds the data service and sets up the action bar. *///from w w w . j av a2 s . co m @Override protected void onCreate(Bundle savedInstanceState) { ZaxPreferences prefs = ZaxPreferences.getInstance(getApplicationContext()); if (prefs.isDarkTheme()) setTheme(R.style.AppThemeDark); else setTheme(R.style.AppTheme); super.onCreate(savedInstanceState); finishReceiver = new FinishReceiver(); registerReceiver(finishReceiver, new IntentFilter(ACTION_FINISH)); bindService(); // (re-) instantiate progress dialog mLoginProgress = (LoginProgressDialogFragment) getSupportFragmentManager() .findFragmentByTag(LoginProgressDialogFragment.TAG); if (mLoginProgress == null) { mLoginProgress = LoginProgressDialogFragment.getInstance(); } try { SSLContext sc = SSLContext.getInstance("TLS"); MemorizingTrustManager mtm = new MemorizingTrustManager(this); sc.init(null, new X509TrustManager[] { mtm }, new java.security.SecureRandom()); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); HttpsURLConnection.setDefaultHostnameVerifier( mtm.wrapHostnameVerifier(HttpsURLConnection.getDefaultHostnameVerifier())); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (KeyManagementException e) { e.printStackTrace(); } }
From source file:org.josso.selfservices.password.generator.PasswordGeneratorImpl.java
/** * Constructor of the PasswordGeneratorImpl *//* w ww. j a v a2 s . com*/ public PasswordGeneratorImpl() { try { // We don't want to expose this to spring passwordFlags |= PW_UPPERS; log.debug(Messages.getString("PwGenerator.debug_UPPERCASE_ON")); passwordFlags |= PW_DIGITS; log.debug(Messages.getString("PwGenerator.debug_DIGITS_ON")); // passwordFlags |= PW_SYMBOLS; // passwordFlags |= PW_AMBIGUOUS; randomFactory = RandomFactory.getInstance(); random = randomFactory.getSecureRandom(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); random = randomFactory.getRandom(); } catch (NoSuchProviderException e) { e.printStackTrace(); random = randomFactory.getRandom(); } }
From source file:com.dvn.vindecoder.ui.seller.AddVehicalAndPayment.java
private void getVinNumber(final String vin_code) { String sha1 = ""; String apikey = "8ba90e6aa631"; String secretkey = "262ce290f9"; //vin_code="1GCRKPEA0CZ160567"; try {/*from w ww. ja v a2 s . c o m*/ //Vin Number 1FMCU0D73BKC34466 2FMTK4J84FBB36055 //Api Key $apikey = "8ba90e6aa631"; //Secrete Key $secretkey = "262ce290f9"; //Sha1 Code 33292a4aa0 //https://api.vindecoder.eu/2.0/8ba90e6aa631/33292a4aa0/decode/1FMCU0D73BKC34466.json sha1 = AeSimpleSHA1.SHA1(vin_code + "|" + apikey + "|" + secretkey); sha1 = sha1.substring(0, 10); Log.e("SubString", sha1); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } /*getVehicalDto = new GetVehicalDto(); getVehicalDto.setVinno(vin_code); getVehicalDto.setAppid(CommonURL.APP_ID);*/ VINAPISetter vinapiSetter = new VINAPISetter(); vinapiSetter.setApikey(apikey); vinapiSetter.setDecode("decode"); vinapiSetter.setVin_code(vin_code + ".json"); vinapiSetter.setSha1(sha1); /* asyncGetTask = new AsyncGetTask(AddVehicalAndPayment.this, CallType.GET_VIN_DETAILS_API_SERVER, AddVehicalAndPayment.this, true, vinapiSetter); asyncGetTask.execute(apikey,sha1,"decode",vin_code+".json");*/ GETApiCall getApiCall = new GETApiCall(); String api_link = CommonURL.VIN_API_LINK + "/" + apikey + "/" + sha1 + "/" + "decode/" + vin_code + ".json"; getApiCall.execute(api_link); }