List of usage examples for java.io UnsupportedEncodingException getMessage
public String getMessage()
From source file:mediasearch.twitter.TwitterService.java
public ArrayList<TwitterTweet> search(String query) { try {// w ww. ja va 2s. co m return searchForTweetsAndParseJson(query); } catch (UnsupportedEncodingException ex) { System.err.println(ex.getMessage()); } return null; }
From source file:de.hybris.platform.impex.jalo.ImpExImporterTest.java
@Test public void test2CycleImport() { try {/*from www .j a v a2 s . c o m*/ final InputStream inputStream = ImpExManager.class .getResourceAsStream("/impex/testfiles/product2Cycle.impex"); assertNotNull("Can not read from jar file 'product2Cycle.impex'", inputStream); final CSVReader reader = new CSVReader(inputStream, windows1252.getCode()); final Importer importer = new Importer(reader); final Product product = (Product) importer.importNext(); assertNotNull("Imported product was null", product); final Unit unit = (Unit) importer.importNext(); assertNotNull("Imported unit was null", unit); final Product product2 = (Product) importer.importNext(); assertEquals(product, product2); assertEquals(0, importer.getDumpedLineCountPerPass()); assertEquals(1, importer.getDumpedLineCountOverall()); importer.close(); } catch (final UnsupportedEncodingException e) { fail(e.getMessage()); } catch (final ImpExException e) { fail(e.getMessage()); } }
From source file:jp.alessandro.android.iab.Security.java
/** * Verifies that the data was signed with the given signature, and returns * the verified purchase. The data is in JSON format and signed * with a private key. The data also contains the purchase state * and product ID of the purchase.// w w w . j a va2 s.co m * * @param logger the logger to use for printing events * @param base64PublicKey rsa public key generated by Google Play Developer Console * @param signedData the signed JSON string (signed, not encrypted) * @param signature the signature for the data, signed with the private key */ public boolean verifyPurchase(Logger logger, String base64PublicKey, String signedData, String signature) { if (TextUtils.isEmpty(base64PublicKey) || TextUtils.isEmpty(signedData) || TextUtils.isEmpty(signature)) { // In case of tests it will return true because test purchases doesn't have a signature if (mIsDebug && !TextUtils.isEmpty(signedData) && TextUtils.isEmpty(signature)) { return isTestingStaticResponse(logger, signedData); } logger.e(Logger.TAG, "Purchase verification failed: missing data."); return false; } try { PublicKey key = generatePublicKey(base64PublicKey); return verify(logger, key, signedData, signature); } catch (UnsupportedEncodingException e) { logger.e(Logger.TAG, e.getMessage(), e); } catch (NoSuchAlgorithmException e) { logger.e(Logger.TAG, e.getMessage(), e); } catch (InvalidKeySpecException e) { logger.e(Logger.TAG, e.getMessage(), e); } catch (InvalidKeyException e) { logger.e(Logger.TAG, e.getMessage(), e); } catch (SignatureException e) { logger.e(Logger.TAG, e.getMessage(), e); } catch (IllegalArgumentException e) { logger.e(Logger.TAG, e.getMessage(), e); } return false; }
From source file:org.apache.ofbiz.accounting.thirdparty.sagepay.SagePayServices.java
public static Map<String, Object> paymentAuthentication(DispatchContext ctx, Map<String, Object> context) { Debug.logInfo("SagePay - Entered paymentAuthentication", module); Debug.logInfo("SagePay paymentAuthentication context : " + context, module); Delegator delegator = ctx.getDelegator(); Map<String, Object> resultMap = new HashMap<String, Object>(); Map<String, String> props = buildSagePayProperties(context, delegator); String vendorTxCode = (String) context.get("vendorTxCode"); String cardHolder = (String) context.get("cardHolder"); String cardNumber = (String) context.get("cardNumber"); String expiryDate = (String) context.get("expiryDate"); String cardType = (String) context.get("cardType"); String cv2 = (String) context.get("cv2"); String amount = (String) context.get("amount"); String currency = (String) context.get("currency"); String description = (String) context.get("description"); String billingSurname = (String) context.get("billingSurname"); String billingFirstnames = (String) context.get("billingFirstnames"); String billingAddress = (String) context.get("billingAddress"); String billingAddress2 = (String) context.get("billingAddress2"); String billingCity = (String) context.get("billingCity"); String billingPostCode = (String) context.get("billingPostCode"); String billingCountry = (String) context.get("billingCountry"); String billingState = (String) context.get("billingState"); String billingPhone = (String) context.get("billingPhone"); Boolean isBillingSameAsDelivery = (Boolean) context.get("isBillingSameAsDelivery"); String deliverySurname = (String) context.get("deliverySurname"); String deliveryFirstnames = (String) context.get("deliveryFirstnames"); String deliveryAddress = (String) context.get("deliveryAddress"); String deliveryAddress2 = (String) context.get("deliveryAddress2"); String deliveryCity = (String) context.get("deliveryCity"); String deliveryPostCode = (String) context.get("deliveryPostCode"); String deliveryCountry = (String) context.get("deliveryCountry"); String deliveryState = (String) context.get("deliveryState"); String deliveryPhone = (String) context.get("deliveryPhone"); String startDate = (String) context.get("startDate"); String issueNumber = (String) context.get("issueNumber"); String basket = (String) context.get("basket"); String clientIPAddress = (String) context.get("clientIPAddress"); Locale locale = (Locale) context.get("locale"); HttpHost host = SagePayUtil.getHost(props); //start - authentication parameters Map<String, String> parameters = new HashMap<String, String>(); String vpsProtocol = props.get("protocolVersion"); String vendor = props.get("vendor"); String txType = props.get("authenticationTransType"); //start - required parameters parameters.put("VPSProtocol", vpsProtocol); parameters.put("TxType", txType); parameters.put("Vendor", vendor); if (vendorTxCode != null) { parameters.put("VendorTxCode", vendorTxCode); }/*from w ww . j ava 2 s . c om*/ if (amount != null) { parameters.put("Amount", amount); } if (currency != null) { parameters.put("Currency", currency); } //GBP/USD if (description != null) { parameters.put("Description", description); } if (cardHolder != null) { parameters.put("CardHolder", cardHolder); } if (cardNumber != null) { parameters.put("CardNumber", cardNumber); } if (expiryDate != null) { parameters.put("ExpiryDate", expiryDate); } if (cardType != null) { parameters.put("CardType", cardType); } //start - billing details if (billingSurname != null) { parameters.put("BillingSurname", billingSurname); } if (billingFirstnames != null) { parameters.put("BillingFirstnames", billingFirstnames); } if (billingAddress != null) { parameters.put("BillingAddress", billingAddress); } if (billingAddress2 != null) { parameters.put("BillingAddress2", billingAddress2); } if (billingCity != null) { parameters.put("BillingCity", billingCity); } if (billingPostCode != null) { parameters.put("BillingPostCode", billingPostCode); } if (billingCountry != null) { parameters.put("BillingCountry", billingCountry); } if (billingState != null) { parameters.put("BillingState", billingState); } if (billingPhone != null) { parameters.put("BillingPhone", billingPhone); } //end - billing details //start - delivery details if (isBillingSameAsDelivery != null && isBillingSameAsDelivery) { if (billingSurname != null) { parameters.put("DeliverySurname", billingSurname); } if (billingFirstnames != null) { parameters.put("DeliveryFirstnames", billingFirstnames); } if (billingAddress != null) { parameters.put("DeliveryAddress", billingAddress); } if (billingAddress2 != null) { parameters.put("DeliveryAddress2", billingAddress2); } if (billingCity != null) { parameters.put("DeliveryCity", billingCity); } if (billingPostCode != null) { parameters.put("DeliveryPostCode", billingPostCode); } if (billingCountry != null) { parameters.put("DeliveryCountry", billingCountry); } if (billingState != null) { parameters.put("DeliveryState", billingState); } if (billingPhone != null) { parameters.put("DeliveryPhone", billingPhone); } } else { if (deliverySurname != null) { parameters.put("DeliverySurname", deliverySurname); } if (deliveryFirstnames != null) { parameters.put("DeliveryFirstnames", deliveryFirstnames); } if (deliveryAddress != null) { parameters.put("DeliveryAddress", deliveryAddress); } if (deliveryAddress2 != null) { parameters.put("DeliveryAddress2", deliveryAddress2); } if (deliveryCity != null) { parameters.put("DeliveryCity", deliveryCity); } if (deliveryPostCode != null) { parameters.put("DeliveryPostCode", deliveryPostCode); } if (deliveryCountry != null) { parameters.put("DeliveryCountry", deliveryCountry); } if (deliveryState != null) { parameters.put("DeliveryState", deliveryState); } if (deliveryPhone != null) { parameters.put("DeliveryPhone", deliveryPhone); } } //end - delivery details //end - required parameters //start - optional parameters if (cv2 != null) { parameters.put("CV2", cv2); } if (startDate != null) { parameters.put("StartDate", startDate); } if (issueNumber != null) { parameters.put("IssueNumber", issueNumber); } if (basket != null) { parameters.put("Basket", basket); } if (clientIPAddress != null) { parameters.put("ClientIPAddress", clientIPAddress); } //end - optional parameters //end - authentication parameters try (CloseableHttpClient httpClient = SagePayUtil.getHttpClient()) { String successMessage = null; HttpPost httpPost = SagePayUtil.getHttpPost(props.get("authenticationUrl"), parameters); HttpResponse response = httpClient.execute(host, httpPost); Map<String, String> responseData = SagePayUtil.getResponseData(response); String status = responseData.get("Status"); String statusDetail = responseData.get("StatusDetail"); resultMap.put("status", status); resultMap.put("statusDetail", statusDetail); //returning the below details back to the calling code, as it not returned back by the payment gateway resultMap.put("vendorTxCode", vendorTxCode); resultMap.put("amount", amount); resultMap.put("transactionType", txType); //start - transaction authorized if ("OK".equals(status)) { resultMap.put("vpsTxId", responseData.get("VPSTxId")); resultMap.put("securityKey", responseData.get("SecurityKey")); resultMap.put("txAuthNo", responseData.get("TxAuthNo")); resultMap.put("avsCv2", responseData.get("AVSCV2")); resultMap.put("addressResult", responseData.get("AddressResult")); resultMap.put("postCodeResult", responseData.get("PostCodeResult")); resultMap.put("cv2Result", responseData.get("CV2Result")); successMessage = "Payment authorized"; } //end - transaction authorized if ("NOTAUTHED".equals(status)) { resultMap.put("vpsTxId", responseData.get("VPSTxId")); resultMap.put("securityKey", responseData.get("SecurityKey")); resultMap.put("avsCv2", responseData.get("AVSCV2")); resultMap.put("addressResult", responseData.get("AddressResult")); resultMap.put("postCodeResult", responseData.get("PostCodeResult")); resultMap.put("cv2Result", responseData.get("CV2Result")); successMessage = "Payment not authorized"; } if ("MALFORMED".equals(status)) { //request not formed properly or parameters missing resultMap.put("vpsTxId", responseData.get("VPSTxId")); resultMap.put("securityKey", responseData.get("SecurityKey")); resultMap.put("avsCv2", responseData.get("AVSCV2")); resultMap.put("addressResult", responseData.get("AddressResult")); resultMap.put("postCodeResult", responseData.get("PostCodeResult")); resultMap.put("cv2Result", responseData.get("CV2Result")); } if ("INVALID".equals(status)) { //invalid information in request resultMap.put("vpsTxId", responseData.get("VPSTxId")); resultMap.put("securityKey", responseData.get("SecurityKey")); resultMap.put("avsCv2", responseData.get("AVSCV2")); resultMap.put("addressResult", responseData.get("AddressResult")); resultMap.put("postCodeResult", responseData.get("PostCodeResult")); resultMap.put("cv2Result", responseData.get("CV2Result")); } if ("REJECTED".equals(status)) { //invalid information in request resultMap.put("vpsTxId", responseData.get("VPSTxId")); resultMap.put("securityKey", responseData.get("SecurityKey")); resultMap.put("avsCv2", responseData.get("AVSCV2")); resultMap.put("addressResult", responseData.get("AddressResult")); resultMap.put("postCodeResult", responseData.get("PostCodeResult")); resultMap.put("cv2Result", responseData.get("CV2Result")); } resultMap.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS); resultMap.put(ModelService.SUCCESS_MESSAGE, successMessage); } catch (UnsupportedEncodingException uee) { //exception in encoding parameters in httpPost Debug.logError(uee, "Error occurred in encoding parameters for HttpPost (" + uee.getMessage() + ")", module); resultMap = ServiceUtil .returnError(UtilProperties.getMessage(resource, "AccountingSagePayErrorEncodingParameters", UtilMisc.toMap("errorString", uee.getMessage()), locale)); } catch (ClientProtocolException cpe) { //from httpClient execute Debug.logError(cpe, "Error occurred in HttpClient execute(" + cpe.getMessage() + ")", module); resultMap = ServiceUtil .returnError(UtilProperties.getMessage(resource, "AccountingSagePayErrorHttpClientExecute", UtilMisc.toMap("errorString", cpe.getMessage()), locale)); } catch (IOException ioe) { //from httpClient execute or getResponsedata Debug.logError(ioe, "Error occurred in HttpClient execute or getting response (" + ioe.getMessage() + ")", module); resultMap = ServiceUtil.returnError( UtilProperties.getMessage(resource, "AccountingSagePayErrorHttpClientExecuteOrGettingResponse", UtilMisc.toMap("errorString", ioe.getMessage()), locale)); } return resultMap; }
From source file:com.fatwire.dta.sscrawler.util.SSUriHelper.java
protected String decode(String value) throws DecoderException { try {// ww w . ja va 2 s . c o m return urlCodec.decode(value, getCharSet()); } catch (UnsupportedEncodingException e) { DecoderException t = new DecoderException(e.getMessage()); t.initCause(e); throw t; } }
From source file:net.jcreate.e3.templateEngine.jxp.JxpTemplateEngine.java
protected void mergeStringTemplate(Template pTemplate, Context pContext, Writer pWriter) throws MergeTemplateException { String encoding = pTemplate.getInputEncoding(); ByteArrayPageSource byteArrayPageSource = new ByteArrayPageSource(); JxpContext context = new JxpContext(byteArrayPageSource); JxpProcessor processor = new JxpProcessor(context); String templateStr = this.getStrTemplate(pTemplate); try {//from w w w. j a v a 2 s . c o m byteArrayPageSource.putPageBuffer(STR_PATH_ID, templateStr.getBytes(encoding)); } catch (UnsupportedEncodingException e) { final String MSG = "?? \"" + templateStr + "\" !" + e.getMessage(); if (log.isErrorEnabled()) { log.error(MSG, e); } throw new MergeTemplateException(MSG, e); } if (pContext == null) { pContext = new DefaultContext(); } Map params = pContext.getParameters(); try { processor.process(STR_PATH_ID, pWriter, params); } catch (Exception e) { final String MSG = "?? \"" + templateStr + "\" !" + e.getMessage(); if (log.isErrorEnabled()) { log.error(MSG, e); } throw new MergeTemplateException(MSG, e); } try { pWriter.flush(); } catch (IOException e) { final String MSG = "?? \"" + templateStr + "\" !" + e.getMessage(); if (log.isErrorEnabled()) { log.error(MSG, e); } throw new MergeTemplateException(MSG, e); } }
From source file:com.fatwire.dta.sscrawler.util.SSUriHelper.java
protected String encode(String value) throws EncoderException { try {// w w w.ja v a2s. c om return urlCodec.encode(value, getCharSet()); } catch (UnsupportedEncodingException e) { EncoderException t = new EncoderException(e.getMessage()); t.initCause(e); throw t; } }
From source file:cn.vlabs.duckling.vwb.service.login.UMT2LoginAction.java
@Override public String makeSSOLoginURL(String localURL) { String ssourl = getVwbcontext().getProperty("duckling.umt.login"); try {/*from ww w . jav a2s. co m*/ String registerURL = getVwbcontext().getProperty("duckling.umt.link.regist") + "&voName=" + getVwbcontext().getVO(); return ssourl + "?WebServerURL=" + URLEncoder.encode(localURL, "UTF-8") + "&appname=" + URLEncoder.encode(getVwbcontext().getProperty("duckling.dct.localName", "dct"), "UTF-8") + "&logoutURL=" + URLEncoder.encode(getVwbcontext().getURL("plain", "logout", "umtSsoLogout=true", true), "UTF-8") + "&" + ILoginHandle.APP_REGISTER_URL_KEY + "=" + URLEncoder.encode(registerURL, "UTF-8"); } catch (UnsupportedEncodingException e) { log.error(e.getMessage()); return ssourl; } }
From source file:de.hybris.platform.impex.jalo.ImpExImporterTest.java
@Test public void testUnresolvedImport() { Importer importer = null;//w w w. j a v a 2s. com try { final InputStream inputStream = ImpExManager.class .getResourceAsStream("/impex/testfiles/productUnresolved.impex"); assertNotNull("Can not read from jar file 'productUnresolved.impex'", inputStream); final CSVReader reader = new CSVReader(inputStream, windows1252.getCode()); importer = new Importer(reader); final Product product = (Product) importer.importNext(); assertNotNull("Imported product was null", product); final Product product2 = (Product) importer.importNext(); assertEquals(product, product2); assertEquals(1, importer.getDumpedLineCountPerPass()); final Product product3 = (Product) importer.importNext(); assertEquals(product, product3); assertEquals(1, importer.getDumpedLineCountPerPass()); importer.importNext(); fail("ImpExException expected caused by unresolved lines"); } catch (final UnsupportedEncodingException e) { fail(e.getMessage()); } catch (final ImpExException e) { if (e.getErrorCode() != ImpExException.ErrorCodes.CAN_NOT_RESOLVE_ANYMORE) { fail(e.getMessage()); } importer.close(); importer.getDumpHandler().getDumpAsFile().delete(); } }
From source file:de.hybris.platform.impex.jalo.ImpExImporterTest.java
@Test public void testUnresolvedImport2() throws JaloGenericCreationException, JaloAbstractTypeException, JaloItemNotFoundException { Importer importer = null;//w w w . j a v a2s . c om try { final InputStream inputStream = ImpExManager.class .getResourceAsStream("/impex/testfiles/productUnresolved.impex"); assertNotNull("Can not read from jar file 'productUnresolved.impex'", inputStream); final CSVReader reader = new CSVReader(inputStream, windows1252.getCode()); importer = new Importer(reader); final Product product = (Product) importer.importNext(); assertNotNull("Imported product was null", product); final Product product2 = (Product) importer.importNext(); assertEquals(product, product2); assertEquals(1, importer.getDumpedLineCountPerPass()); final Product product3 = (Product) importer.importNext(); assertEquals(product, product3); assertEquals(1, importer.getDumpedLineCountPerPass()); importer.importAll(); fail("ImpExException expected caused by unresolved lines"); } catch (final UnsupportedEncodingException e) { fail(e.getMessage()); } catch (final ImpExException e) { if (e.getErrorCode() != ImpExException.ErrorCodes.CAN_NOT_RESOLVE_ANYMORE) { fail(e.getMessage()); } importer.close(); importer.getDumpHandler().getDumpAsFile().delete(); } }